From 0d57ef93732489db0aec6a0e85d9f2f53352ce5b Mon Sep 17 00:00:00 2001 From: winlin Date: Mon, 14 Sep 2015 13:47:25 +0800 Subject: [PATCH] fix #458, http hooks use source thread cid. 2.0.188 --- README.md | 2 ++ trunk/src/app/srs_app_dvr.cpp | 8 +++--- trunk/src/app/srs_app_dvr.hpp | 3 ++- trunk/src/app/srs_app_hls.cpp | 15 ++++++----- trunk/src/app/srs_app_hls.hpp | 6 +++-- trunk/src/app/srs_app_http_hooks.cpp | 12 ++++----- trunk/src/app/srs_app_http_hooks.hpp | 39 +++++++++++++++------------- trunk/src/core/srs_core.hpp | 2 +- 8 files changed, 50 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index b37b303b7..ae0c46e3a 100755 --- a/README.md +++ b/README.md @@ -343,6 +343,7 @@ Remark: ## History +* v2.0, 2015-09-14, for [#458][bug #458] http hooks use source thread cid. 2.0.188 * v2.0, 2015-09-14, for [#475][bug #475] fix http hooks crash for st context switch. 2.0.187 * v2.0, 2015-09-09, support reload utc_time. 2.0.186 * v2.0, 2015-08-23, [2.0 alpha(2.0.185)][r2.0a0] released. 89022 lines. @@ -1026,6 +1027,7 @@ Winlin [bug #92]: https://github.com/simple-rtmp-server/srs/issues/92 [bug #380]: https://github.com/simple-rtmp-server/srs/issues/380 [bug #475]: https://github.com/simple-rtmp-server/srs/issues/475 +[bug #458]: https://github.com/simple-rtmp-server/srs/issues/458 [bug #454]: https://github.com/simple-rtmp-server/srs/issues/454 [bug #442]: https://github.com/simple-rtmp-server/srs/issues/442 [bug #169]: https://github.com/simple-rtmp-server/srs/issues/169 diff --git a/trunk/src/app/srs_app_dvr.cpp b/trunk/src/app/srs_app_dvr.cpp index 3aca55f50..e2d1716da 100644 --- a/trunk/src/app/srs_app_dvr.cpp +++ b/trunk/src/app/srs_app_dvr.cpp @@ -496,8 +496,9 @@ int SrsFlvSegment::on_reload_vhost_dvr(std::string /*vhost*/) return ret; } -SrsDvrAsyncCallOnDvr::SrsDvrAsyncCallOnDvr(SrsRequest* r, string p) +SrsDvrAsyncCallOnDvr::SrsDvrAsyncCallOnDvr(int c, SrsRequest* r, string p) { + cid = c; req = r->copy(); path = p; } @@ -534,7 +535,7 @@ int SrsDvrAsyncCallOnDvr::call() for (int i = 0; i < (int)hooks.size(); i++) { std::string url = hooks.at(i); - if ((ret = SrsHttpHooks::on_dvr(url, req, path)) != ERROR_SUCCESS) { + if ((ret = SrsHttpHooks::on_dvr(cid, url, req, path)) != ERROR_SUCCESS) { srs_error("hook client on_dvr failed. url=%s, ret=%d", url.c_str(), ret); return ret; } @@ -638,7 +639,8 @@ int SrsDvrPlan::on_reap_segment() { int ret = ERROR_SUCCESS; - if ((ret = async->execute(new SrsDvrAsyncCallOnDvr(req, segment->get_path()))) != ERROR_SUCCESS) { + int cid = _srs_context->get_id(); + if ((ret = async->execute(new SrsDvrAsyncCallOnDvr(cid, req, segment->get_path()))) != ERROR_SUCCESS) { return ret; } diff --git a/trunk/src/app/srs_app_dvr.hpp b/trunk/src/app/srs_app_dvr.hpp index 42e3521a1..3fcfdaeb1 100644 --- a/trunk/src/app/srs_app_dvr.hpp +++ b/trunk/src/app/srs_app_dvr.hpp @@ -181,10 +181,11 @@ public: class SrsDvrAsyncCallOnDvr : public ISrsAsyncCallTask { private: + int cid; std::string path; SrsRequest* req; public: - SrsDvrAsyncCallOnDvr(SrsRequest* r, std::string p); + SrsDvrAsyncCallOnDvr(int c, SrsRequest* r, std::string p); virtual ~SrsDvrAsyncCallOnDvr(); public: virtual int call(); diff --git a/trunk/src/app/srs_app_hls.cpp b/trunk/src/app/srs_app_hls.cpp index f85c5478d..d8437bae3 100644 --- a/trunk/src/app/srs_app_hls.cpp +++ b/trunk/src/app/srs_app_hls.cpp @@ -177,9 +177,10 @@ void SrsHlsSegment::update_duration(int64_t current_frame_dts) return; } -SrsDvrAsyncCallOnHls::SrsDvrAsyncCallOnHls(SrsRequest* r, string p, string t, string m, string mu, int s, double d) +SrsDvrAsyncCallOnHls::SrsDvrAsyncCallOnHls(int c, SrsRequest* r, string p, string t, string m, string mu, int s, double d) { req = r->copy(); + cid = c; path = p; ts_url = t; m3u8 = m; @@ -220,7 +221,7 @@ int SrsDvrAsyncCallOnHls::call() for (int i = 0; i < (int)hooks.size(); i++) { std::string url = hooks.at(i); - if ((ret = SrsHttpHooks::on_hls(url, req, path, ts_url, m3u8, m3u8_url, seq_no, duration)) != ERROR_SUCCESS) { + if ((ret = SrsHttpHooks::on_hls(cid, url, req, path, ts_url, m3u8, m3u8_url, seq_no, duration)) != ERROR_SUCCESS) { srs_error("hook client on_hls failed. url=%s, ret=%d", url.c_str(), ret); return ret; } @@ -235,8 +236,9 @@ string SrsDvrAsyncCallOnHls::to_string() return "on_hls: " + path; } -SrsDvrAsyncCallOnHlsNotify::SrsDvrAsyncCallOnHlsNotify(SrsRequest* r, string u) +SrsDvrAsyncCallOnHlsNotify::SrsDvrAsyncCallOnHlsNotify(int c, SrsRequest* r, string u) { + cid = c; req = r->copy(); ts_url = u; } @@ -274,7 +276,7 @@ int SrsDvrAsyncCallOnHlsNotify::call() int nb_notify = _srs_config->get_vhost_hls_nb_notify(req->vhost); for (int i = 0; i < (int)hooks.size(); i++) { std::string url = hooks.at(i); - if ((ret = SrsHttpHooks::on_hls_notify(url, req, ts_url, nb_notify)) != ERROR_SUCCESS) { + if ((ret = SrsHttpHooks::on_hls_notify(cid, url, req, ts_url, nb_notify)) != ERROR_SUCCESS) { srs_error("hook client on_hls_notify failed. url=%s, ret=%d", url.c_str(), ret); return ret; } @@ -724,7 +726,8 @@ int SrsHlsMuxer::segment_close(string log_desc) segments.push_back(current); // use async to call the http hooks, for it will cause thread switch. - if ((ret = async->execute(new SrsDvrAsyncCallOnHls(req, + if ((ret = async->execute(new SrsDvrAsyncCallOnHls( + _srs_context->get_id(), req, current->full_path, current->uri, m3u8, m3u8_url, current->sequence_no, current->duration))) != ERROR_SUCCESS) { @@ -732,7 +735,7 @@ int SrsHlsMuxer::segment_close(string log_desc) } // use async to call the http hooks, for it will cause thread switch. - if ((ret = async->execute(new SrsDvrAsyncCallOnHlsNotify(req, current->uri))) != ERROR_SUCCESS) { + if ((ret = async->execute(new SrsDvrAsyncCallOnHlsNotify(_srs_context->get_id(), req, current->uri))) != ERROR_SUCCESS) { return ret; } diff --git a/trunk/src/app/srs_app_hls.hpp b/trunk/src/app/srs_app_hls.hpp index 27ab1da01..dd9f8953c 100644 --- a/trunk/src/app/srs_app_hls.hpp +++ b/trunk/src/app/srs_app_hls.hpp @@ -167,6 +167,7 @@ public: class SrsDvrAsyncCallOnHls : public ISrsAsyncCallTask { private: + int cid; std::string path; std::string ts_url; std::string m3u8; @@ -175,7 +176,7 @@ private: SrsRequest* req; double duration; public: - SrsDvrAsyncCallOnHls(SrsRequest* r, std::string p, std::string t, std::string m, std::string mu, int s, double d); + SrsDvrAsyncCallOnHls(int c, SrsRequest* r, std::string p, std::string t, std::string m, std::string mu, int s, double d); virtual ~SrsDvrAsyncCallOnHls(); public: virtual int call(); @@ -188,10 +189,11 @@ public: class SrsDvrAsyncCallOnHlsNotify : public ISrsAsyncCallTask { private: + int cid; std::string ts_url; SrsRequest* req; public: - SrsDvrAsyncCallOnHlsNotify(SrsRequest* r, std::string u); + SrsDvrAsyncCallOnHlsNotify(int c, SrsRequest* r, std::string u); virtual ~SrsDvrAsyncCallOnHlsNotify(); public: virtual int call(); diff --git a/trunk/src/app/srs_app_http_hooks.cpp b/trunk/src/app/srs_app_http_hooks.cpp index 3a361201d..261ffb1b2 100644 --- a/trunk/src/app/srs_app_http_hooks.cpp +++ b/trunk/src/app/srs_app_http_hooks.cpp @@ -257,11 +257,11 @@ void SrsHttpHooks::on_stop(string url, SrsRequest* req) return; } -int SrsHttpHooks::on_dvr(string url, SrsRequest* req, string file) +int SrsHttpHooks::on_dvr(int cid, string url, SrsRequest* req, string file) { int ret = ERROR_SUCCESS; - int client_id = _srs_context->get_id(); + int client_id = cid; std::string cwd = _srs_config->cwd(); std::stringstream ss; @@ -293,11 +293,11 @@ int SrsHttpHooks::on_dvr(string url, SrsRequest* req, string file) return ret; } -int SrsHttpHooks::on_hls(string url, SrsRequest* req, string file, string ts_url, string m3u8, string m3u8_url, int sn, double duration) +int SrsHttpHooks::on_hls(int cid, string url, SrsRequest* req, string file, string ts_url, string m3u8, string m3u8_url, int sn, double duration) { int ret = ERROR_SUCCESS; - int client_id = _srs_context->get_id(); + int client_id = cid; std::string cwd = _srs_config->cwd(); std::stringstream ss; @@ -334,11 +334,11 @@ int SrsHttpHooks::on_hls(string url, SrsRequest* req, string file, string ts_url return ret; } -int SrsHttpHooks::on_hls_notify(std::string url, SrsRequest* req, std::string ts_url, int nb_notify) +int SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* req, std::string ts_url, int nb_notify) { int ret = ERROR_SUCCESS; - int client_id = _srs_context->get_id(); + int client_id = cid; std::string cwd = _srs_config->cwd(); if (srs_string_starts_with(ts_url, "http://") || srs_string_starts_with(ts_url, "https://")) { diff --git a/trunk/src/app/srs_app_http_hooks.hpp b/trunk/src/app/srs_app_http_hooks.hpp index 47b27431b..4f912109b 100644 --- a/trunk/src/app/srs_app_http_hooks.hpp +++ b/trunk/src/app/srs_app_http_hooks.hpp @@ -90,32 +90,35 @@ public: */ static void on_stop(std::string url, SrsRequest* req); /** - * on_dvr hook, when reap a dvr file. - * @param url the api server url, to process the event. - * ignore if empty. - * @param file the file path, can be relative or absolute path. - */ - static int on_dvr(std::string url, SrsRequest* req, std::string file); + * on_dvr hook, when reap a dvr file. + * @param url the api server url, to process the event. + * ignore if empty. + * @param file the file path, can be relative or absolute path. + * @param cid the source connection cid, for the on_dvr is async call. + */ + static int on_dvr(int cid, std::string url, SrsRequest* req, std::string file); /** - * when hls reap segment, callback. - * @param url the api server url, to process the event. - * ignore if empty. - * @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 duration the segment duration in seconds. - */ - 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. + * @param url the api server url, to process the event. + * ignore if empty. + * @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 duration the segment duration in seconds. + * @param cid the source connection cid, for the on_dvr is async call. + */ + static int on_hls(int cid, 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. * @param url the api server url, to process the event. * ignore if empty. * @param ts_url the ts uri, used to replace the variable [ts_url] in url. * @param nb_notify the max bytes to read from notify server. + * @param cid the source connection cid, for the on_dvr is async call. */ - static int on_hls_notify(std::string url, SrsRequest* req, std::string ts_url, int nb_notify); + static int on_hls_notify(int cid, std::string url, SrsRequest* req, std::string ts_url, int nb_notify); private: static int do_post(std::string url, std::string req, int& code, std::string& res); }; diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index b249e26b2..940b7e81d 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // current release version #define VERSION_MAJOR 2 #define VERSION_MINOR 0 -#define VERSION_REVISION 187 +#define VERSION_REVISION 188 // server info. #define RTMP_SIG_SRS_KEY "SRS"