1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

HLS: Rebuild m3u8 to make ts with id, for stat.

This commit is contained in:
winlin 2022-08-29 09:07:34 +08:00
parent bc569d91a0
commit c1df280211
5 changed files with 161 additions and 76 deletions

View file

@ -574,25 +574,7 @@ std::string SrsHttpMessage::parse_rest_id(string pattern)
srs_error_t SrsHttpMessage::body_read_all(string& body)
{
srs_error_t err = srs_success;
// cache to read.
char* buf = new char[SRS_HTTP_READ_CACHE_BYTES];
SrsAutoFreeA(char, buf);
// whatever, read util EOF.
while (!_body->eof()) {
ssize_t nb_read = 0;
if ((err = _body->read(buf, SRS_HTTP_READ_CACHE_BYTES, &nb_read)) != srs_success) {
return srs_error_wrap(err, "read body");
}
if (nb_read > 0) {
body.append(buf, nb_read);
}
}
return err;
return srs_ioutil_read_all(_body, body);
}
ISrsHttpResponseReader* SrsHttpMessage::body_reader()

View file

@ -41,6 +41,7 @@ using namespace std;
#include <srs_kernel_log.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_http_stack.hpp>
#include <srs_core_autofree.hpp>
void srs_discovery_tc_url(string tcUrl, string& schema, string& host, string& vhost, string& app, string& stream, int& port, string& param)
{
@ -900,3 +901,33 @@ string srs_get_system_hostname()
return _srs_system_hostname;
}
srs_error_t srs_ioutil_read_all(ISrsReader* in, std::string& content)
{
srs_error_t err = srs_success;
// Cache to read, it might cause coroutine switch, so we use local cache here.
char* buf = new char[SRS_HTTP_READ_CACHE_BYTES];
SrsAutoFreeA(char, buf);
// Whatever, read util EOF.
while (true) {
ssize_t nb_read = 0;
if ((err = in->read(buf, SRS_HTTP_READ_CACHE_BYTES, &nb_read)) != srs_success) {
int code = srs_error_code(err);
if (code == ERROR_SYSTEM_FILE_EOF || code == ERROR_HTTP_RESPONSE_EOF || code == ERROR_HTTP_REQUEST_EOF
|| code == ERROR_HTTP_STREAM_EOF
) {
srs_freep(err);
return err;
}
return srs_error_wrap(err, "read body");
}
if (nb_read > 0) {
content.append(buf, nb_read);
}
}
return err;
}

View file

@ -32,6 +32,7 @@ class SrsMessageHeader;
class SrsSharedPtrMessage;
class SrsCommonMessage;
class ISrsProtocolReadWriter;
class ISrsReader;
/**
* parse the tcUrl, output the schema, host, vhost, app and port.
@ -183,5 +184,8 @@ extern std::string srs_get_original_ip(ISrsHttpMessage* r);
// Get hostname
extern std::string srs_get_system_hostname(void);
// Read all content util EOF.
extern srs_error_t srs_ioutil_read_all(ISrsReader* in, std::string& content);
#endif