Skip to content

Commit

Permalink
support url with query. variant m3u8
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Aug 31, 2016
1 parent a85b10f commit ef56f4a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
14 changes: 11 additions & 3 deletions src/app/htl_app_hls_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@ int StHlsTask::ProcessTask(){

Trace("start to process HLS task #%d, schema=%s, host=%s, port=%d, path=%s, startup=%.2f, delay=%.2f, error=%.2f, count=%d",
GetId(), url.GetSchema(), url.GetHost(), url.GetPort(), url.GetPath(), startup_seconds, delay_seconds, error_seconds, count);

StHttpClient client;

// if count is zero, infinity loop.
for(int i = 0; count == 0 || i < count; i++){
statistic->OnTaskStart(GetId(), url.GetUrl());

StHttpClient client;
if((ret = ProcessM3u8(client)) != ERROR_SUCCESS){
statistic->OnTaskError(GetId(), 0);

Expand All @@ -101,12 +100,21 @@ int StHlsTask::ProcessM3u8(StHttpClient& client){
}
Trace("[HLS] get m3u8 %s get success, length=%"PRId64, url.GetUrl(), (int64_t)m3u8.length());

string variant;
vector<M3u8TS> ts_objects;
if((ret = HlsM3u8Parser::ParseM3u8Data(&url, m3u8, ts_objects, target_duration)) != ERROR_SUCCESS){
if((ret = HlsM3u8Parser::ParseM3u8Data(&url, m3u8, ts_objects, target_duration, variant)) != ERROR_SUCCESS){
Error("http client parse m3u8 content failed. ret=%d", ret);
return ret;
}

if (!variant.empty()) {
if ((ret = url.Initialize(variant)) != ERROR_SUCCESS) {
Error("parse variant=%s failed, ret=%d", variant.c_str(), ret);
return ret;
}
return ret;
}

if((ret = ProcessTS(client, ts_objects)) != ERROR_SUCCESS){
Error("http client download m3u8 ts file failed. ret=%d", ret);
return ret;
Expand Down
9 changes: 8 additions & 1 deletion src/app/htl_app_m3u8_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ HlsM3u8Parser::HlsM3u8Parser(){
HlsM3u8Parser::~HlsM3u8Parser(){
}

int HlsM3u8Parser::ParseM3u8Data(HttpUrl* url, string m3u8, vector<M3u8TS>& ts_objects, int& target_duration){
int HlsM3u8Parser::ParseM3u8Data(HttpUrl* url, string m3u8, vector<M3u8TS>& ts_objects, int& target_duration, string& variant){
int ret = ERROR_SUCCESS;

String data(m3u8);
Expand Down Expand Up @@ -158,6 +158,13 @@ int HlsM3u8Parser::ParseM3u8Data(HttpUrl* url, string m3u8, vector<M3u8TS>& ts_o
continue;
}

// #EXT-X-STREAM-INF:BANDWIDTH=3000000
// http://192.168.13.108:28080/gh.b0.upaiyun.com/app01/stream01.m3u8
if (line.startswith("#EXT-X-STREAM-INF:", &value)) {
variant = data.strip().getline();
return ret;
}

// http://tools.ietf.org/html/draft-pantos-http-live-streaming-08#section-3.3.2
// #EXTINF:<duration>,<title>
// "duration" is an integer or floating-point number in decimal
Expand Down
2 changes: 1 addition & 1 deletion src/app/htl_app_m3u8_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class HlsM3u8Parser
HlsM3u8Parser();
virtual ~HlsM3u8Parser();
public:
static int ParseM3u8Data(HttpUrl* url, std::string m3u8, std::vector<M3u8TS>& ts_objects, int& target_duration);
static int ParseM3u8Data(HttpUrl* url, std::string m3u8, std::vector<M3u8TS>& ts_objects, int& target_duration, std::string& variant);
};

#endif
13 changes: 12 additions & 1 deletion src/core/htl_core_uri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ int ProtocolUrl::Initialize(std::string http_url){

path = Get(UF_PATH);

if (Get(UF_QUERY) != "") {
query = Get(UF_QUERY);
}

return ret;
}

Expand Down Expand Up @@ -163,7 +167,11 @@ HttpUrl* HttpUrl::Copy(){
}

const char* HttpUrl::GetPath(){
return path.c_str();
path_query = path;
if (!query.empty()) {
path_query += "?" + query;
}
return path_query.c_str();
}

RtmpUrl::RtmpUrl(){
Expand Down Expand Up @@ -194,6 +202,9 @@ int RtmpUrl::Initialize(std::string http_url){

stream = app.substr(pos + 1);
app = app.substr(0, pos);
if (!query.empty()) {
stream += "?" + query;
}

stringstream ss;
ss << schema << "://" << vhost << ":" << port << "/" << app;
Expand Down
3 changes: 3 additions & 0 deletions src/core/htl_core_uri.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ProtocolUrl : public Uri
std::string host;
int port;
std::string path;
std::string query;
public:
ProtocolUrl();
virtual ~ProtocolUrl();
Expand All @@ -72,6 +73,8 @@ class ProtocolUrl : public Uri

class HttpUrl : public ProtocolUrl
{
private:
std::string path_query;
public:
HttpUrl();
virtual ~HttpUrl();
Expand Down

0 comments on commit ef56f4a

Please sign in to comment.