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

update on_hls, add ts_url, m3u8 and m3u8_url.

This commit is contained in:
winlin 2015-04-23 12:05:24 +08:00
parent 7b157b0678
commit 0acb942c3a
5 changed files with 28 additions and 9 deletions

View file

@ -780,7 +780,10 @@ vhost hooks.callback.srs.com {
# "stream": "livestream", # "stream": "livestream",
# "duration": 9.36, // in seconds # "duration": 9.36, // in seconds
# "cwd": "/usr/local/srs", # "cwd": "/usr/local/srs",
# "file": "./objs/nginx/html/live/livestream.1420254068776-100.ts", # "file": "./objs/nginx/html/live/livestream/2015-04-23/01/476584165.ts",
# "url": "live/livestream/2015-04-23/01/476584165.ts",
# "m3u8": "./objs/nginx/html/live/livestream/live.m3u8",
# "m3u8_url": "live/livestream/live.m3u8",
# "seq_no": 100 # "seq_no": 100
# } # }
# if valid, the hook must return HTTP code 200(Stauts OK) and response # if valid, the hook must return HTTP code 200(Stauts OK) and response

View file

@ -170,10 +170,13 @@ void SrsHlsSegment::update_duration(int64_t current_frame_dts)
return; return;
} }
SrsDvrAsyncCallOnHls::SrsDvrAsyncCallOnHls(SrsRequest* r, string p, int s, double d) SrsDvrAsyncCallOnHls::SrsDvrAsyncCallOnHls(SrsRequest* r, string p, string t, string m, string mu, int s, double d)
{ {
req = r; req = r;
path = p; path = p;
ts_url = t;
m3u8 = m;
m3u8_url = mu;
seq_no = s; seq_no = s;
duration = d; duration = d;
} }
@ -200,7 +203,7 @@ int SrsDvrAsyncCallOnHls::call()
int sn = seq_no; int sn = seq_no;
for (int i = 0; i < (int)on_hls->args.size(); i++) { for (int i = 0; i < (int)on_hls->args.size(); i++) {
std::string url = on_hls->args.at(i); std::string url = on_hls->args.at(i);
if ((ret = SrsHttpHooks::on_hls(url, req, file, sn, duration)) != ERROR_SUCCESS) { if ((ret = SrsHttpHooks::on_hls(url, req, file, ts_url, m3u8, m3u8_url, sn, duration)) != ERROR_SUCCESS) {
srs_error("hook client on_hls failed. url=%s, ret=%d", url.c_str(), ret); srs_error("hook client on_hls failed. url=%s, ret=%d", url.c_str(), ret);
return ret; return ret;
} }
@ -361,8 +364,8 @@ int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix,
deviation_ts = 0; deviation_ts = 0;
// generate the m3u8 dir and path. // generate the m3u8 dir and path.
m3u8 = path + "/" + m3u8_file; m3u8_url = srs_path_build_stream(m3u8_file, req->vhost, req->app, req->stream);
m3u8 = srs_path_build_stream(m3u8, req->vhost, req->app, req->stream); m3u8 = path + "/" + m3u8_url;
// we always keep the target duration increasing. // we always keep the target duration increasing.
int max_td = srs_max(target_duration, (int)(fragment * _srs_config->get_hls_td_ratio(r->vhost))); int max_td = srs_max(target_duration, (int)(fragment * _srs_config->get_hls_td_ratio(r->vhost)));
@ -664,7 +667,10 @@ int SrsHlsMuxer::segment_close(string log_desc)
segments.push_back(current); segments.push_back(current);
// use async to call the http hooks, for it will cause thread switch. // use async to call the http hooks, for it will cause thread switch.
if ((ret = async->call(new SrsDvrAsyncCallOnHls(req, current->full_path, current->sequence_no, current->duration))) != ERROR_SUCCESS) { if ((ret = async->call(new SrsDvrAsyncCallOnHls(req,
current->full_path, current->uri, m3u8, m3u8_url,
current->sequence_no, current->duration))) != ERROR_SUCCESS)
{
return ret; return ret;
} }

View file

@ -163,11 +163,14 @@ class SrsDvrAsyncCallOnHls : public ISrsDvrAsyncCall
{ {
private: private:
std::string path; std::string path;
std::string ts_url;
std::string m3u8;
std::string m3u8_url;
int seq_no; int seq_no;
SrsRequest* req; SrsRequest* req;
double duration; double duration;
public: public:
SrsDvrAsyncCallOnHls(SrsRequest* r, std::string p, int s, double d); SrsDvrAsyncCallOnHls(SrsRequest* r, std::string p, std::string t, std::string m, std::string mu, int s, double d);
virtual ~SrsDvrAsyncCallOnHls(); virtual ~SrsDvrAsyncCallOnHls();
public: public:
virtual int call(); virtual int call();
@ -227,6 +230,7 @@ private:
int _sequence_no; int _sequence_no;
int target_duration; int target_duration;
std::string m3u8; std::string m3u8;
std::string m3u8_url;
private: private:
ISrsHlsHandler* handler; ISrsHlsHandler* handler;
// TODO: FIXME: supports reload. // TODO: FIXME: supports reload.

View file

@ -292,7 +292,7 @@ int SrsHttpHooks::on_dvr(string url, SrsRequest* req, string file)
return ret; return ret;
} }
int SrsHttpHooks::on_hls(string url, SrsRequest* req, string file, int sn, double duration) int SrsHttpHooks::on_hls(string url, SrsRequest* req, string file, string ts_url, string m3u8, string m3u8_url, int sn, double duration)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
@ -310,6 +310,9 @@ int SrsHttpHooks::on_hls(string url, SrsRequest* req, string file, int sn, doubl
<< SRS_JFIELD_ORG("duration", duration) << SRS_JFIELD_CONT << SRS_JFIELD_ORG("duration", duration) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("cwd", cwd) << SRS_JFIELD_CONT << SRS_JFIELD_STR("cwd", cwd) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("file", file) << SRS_JFIELD_CONT << SRS_JFIELD_STR("file", file) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("url", ts_url) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("m3u8", m3u8) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("m3u8_url", m3u8_url) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("seq_no", sn) << SRS_JFIELD_ORG("seq_no", sn)
<< SRS_JOBJECT_END; << SRS_JOBJECT_END;

View file

@ -101,10 +101,13 @@ public:
* @param url the api server url, to process the event. * @param url the api server url, to process the event.
* ignore if empty. * ignore if empty.
* @param file the ts file path, can be relative or absolute path. * @param file the ts file path, can be relative or absolute path.
* @param ts_url the ts url, which used for m3u8.
* @param m3u8 the m3u8 file path, can be relative or absolute path.
* @param m3u8_url the m3u8 url, which is used for the http mount path.
* @param sn the seq_no, the sequence number of ts in hls/m3u8. * @param sn the seq_no, the sequence number of ts in hls/m3u8.
* @param duration the segment duration in seconds. * @param duration the segment duration in seconds.
*/ */
static int on_hls(std::string url, SrsRequest* req, std::string file, int sn, double duration); static int on_hls(std::string url, SrsRequest* req, std::string file, std::string ts_url, std::string m3u8, std::string m3u8_url, int sn, double duration);
/** /**
* when hls reap segment, callback. * when hls reap segment, callback.
* @param url the api server url, to process the event. * @param url the api server url, to process the event.