winlin

merge from 2.0

@@ -1046,6 +1046,7 @@ Winlin @@ -1046,6 +1046,7 @@ Winlin
1046 [bug #471]: https://github.com/simple-rtmp-server/srs/issues/471 1046 [bug #471]: https://github.com/simple-rtmp-server/srs/issues/471
1047 [bug #380]: https://github.com/simple-rtmp-server/srs/issues/380 1047 [bug #380]: https://github.com/simple-rtmp-server/srs/issues/380
1048 [bug #475]: https://github.com/simple-rtmp-server/srs/issues/475 1048 [bug #475]: https://github.com/simple-rtmp-server/srs/issues/475
  1049 +[bug #458]: https://github.com/simple-rtmp-server/srs/issues/458
1049 [bug #454]: https://github.com/simple-rtmp-server/srs/issues/454 1050 [bug #454]: https://github.com/simple-rtmp-server/srs/issues/454
1050 [bug #442]: https://github.com/simple-rtmp-server/srs/issues/442 1051 [bug #442]: https://github.com/simple-rtmp-server/srs/issues/442
1051 [bug #169]: https://github.com/simple-rtmp-server/srs/issues/169 1052 [bug #169]: https://github.com/simple-rtmp-server/srs/issues/169
@@ -496,8 +496,9 @@ int SrsFlvSegment::on_reload_vhost_dvr(std::string /*vhost*/) @@ -496,8 +496,9 @@ int SrsFlvSegment::on_reload_vhost_dvr(std::string /*vhost*/)
496 return ret; 496 return ret;
497 } 497 }
498 498
499 -SrsDvrAsyncCallOnDvr::SrsDvrAsyncCallOnDvr(SrsRequest* r, string p) 499 +SrsDvrAsyncCallOnDvr::SrsDvrAsyncCallOnDvr(int c, SrsRequest* r, string p)
500 { 500 {
  501 + cid = c;
501 req = r->copy(); 502 req = r->copy();
502 path = p; 503 path = p;
503 } 504 }
@@ -534,7 +535,7 @@ int SrsDvrAsyncCallOnDvr::call() @@ -534,7 +535,7 @@ int SrsDvrAsyncCallOnDvr::call()
534 535
535 for (int i = 0; i < (int)hooks.size(); i++) { 536 for (int i = 0; i < (int)hooks.size(); i++) {
536 std::string url = hooks.at(i); 537 std::string url = hooks.at(i);
537 - if ((ret = SrsHttpHooks::on_dvr(url, req, path)) != ERROR_SUCCESS) { 538 + if ((ret = SrsHttpHooks::on_dvr(cid, url, req, path)) != ERROR_SUCCESS) {
538 srs_error("hook client on_dvr failed. url=%s, ret=%d", url.c_str(), ret); 539 srs_error("hook client on_dvr failed. url=%s, ret=%d", url.c_str(), ret);
539 return ret; 540 return ret;
540 } 541 }
@@ -638,7 +639,8 @@ int SrsDvrPlan::on_reap_segment() @@ -638,7 +639,8 @@ int SrsDvrPlan::on_reap_segment()
638 { 639 {
639 int ret = ERROR_SUCCESS; 640 int ret = ERROR_SUCCESS;
640 641
641 - if ((ret = async->execute(new SrsDvrAsyncCallOnDvr(req, segment->get_path()))) != ERROR_SUCCESS) { 642 + int cid = _srs_context->get_id();
  643 + if ((ret = async->execute(new SrsDvrAsyncCallOnDvr(cid, req, segment->get_path()))) != ERROR_SUCCESS) {
642 return ret; 644 return ret;
643 } 645 }
644 646
@@ -181,10 +181,11 @@ public: @@ -181,10 +181,11 @@ public:
181 class SrsDvrAsyncCallOnDvr : public ISrsAsyncCallTask 181 class SrsDvrAsyncCallOnDvr : public ISrsAsyncCallTask
182 { 182 {
183 private: 183 private:
  184 + int cid;
184 std::string path; 185 std::string path;
185 SrsRequest* req; 186 SrsRequest* req;
186 public: 187 public:
187 - SrsDvrAsyncCallOnDvr(SrsRequest* r, std::string p); 188 + SrsDvrAsyncCallOnDvr(int c, SrsRequest* r, std::string p);
188 virtual ~SrsDvrAsyncCallOnDvr(); 189 virtual ~SrsDvrAsyncCallOnDvr();
189 public: 190 public:
190 virtual int call(); 191 virtual int call();
@@ -177,9 +177,10 @@ void SrsHlsSegment::update_duration(int64_t current_frame_dts) @@ -177,9 +177,10 @@ void SrsHlsSegment::update_duration(int64_t current_frame_dts)
177 return; 177 return;
178 } 178 }
179 179
180 -SrsDvrAsyncCallOnHls::SrsDvrAsyncCallOnHls(SrsRequest* r, string p, string t, string m, string mu, int s, double d) 180 +SrsDvrAsyncCallOnHls::SrsDvrAsyncCallOnHls(int c, SrsRequest* r, string p, string t, string m, string mu, int s, double d)
181 { 181 {
182 req = r->copy(); 182 req = r->copy();
  183 + cid = c;
183 path = p; 184 path = p;
184 ts_url = t; 185 ts_url = t;
185 m3u8 = m; 186 m3u8 = m;
@@ -220,7 +221,7 @@ int SrsDvrAsyncCallOnHls::call() @@ -220,7 +221,7 @@ int SrsDvrAsyncCallOnHls::call()
220 221
221 for (int i = 0; i < (int)hooks.size(); i++) { 222 for (int i = 0; i < (int)hooks.size(); i++) {
222 std::string url = hooks.at(i); 223 std::string url = hooks.at(i);
223 - if ((ret = SrsHttpHooks::on_hls(url, req, path, ts_url, m3u8, m3u8_url, seq_no, duration)) != ERROR_SUCCESS) { 224 + if ((ret = SrsHttpHooks::on_hls(cid, url, req, path, ts_url, m3u8, m3u8_url, seq_no, duration)) != ERROR_SUCCESS) {
224 srs_error("hook client on_hls failed. url=%s, ret=%d", url.c_str(), ret); 225 srs_error("hook client on_hls failed. url=%s, ret=%d", url.c_str(), ret);
225 return ret; 226 return ret;
226 } 227 }
@@ -235,8 +236,9 @@ string SrsDvrAsyncCallOnHls::to_string() @@ -235,8 +236,9 @@ string SrsDvrAsyncCallOnHls::to_string()
235 return "on_hls: " + path; 236 return "on_hls: " + path;
236 } 237 }
237 238
238 -SrsDvrAsyncCallOnHlsNotify::SrsDvrAsyncCallOnHlsNotify(SrsRequest* r, string u) 239 +SrsDvrAsyncCallOnHlsNotify::SrsDvrAsyncCallOnHlsNotify(int c, SrsRequest* r, string u)
239 { 240 {
  241 + cid = c;
240 req = r->copy(); 242 req = r->copy();
241 ts_url = u; 243 ts_url = u;
242 } 244 }
@@ -274,7 +276,7 @@ int SrsDvrAsyncCallOnHlsNotify::call() @@ -274,7 +276,7 @@ int SrsDvrAsyncCallOnHlsNotify::call()
274 int nb_notify = _srs_config->get_vhost_hls_nb_notify(req->vhost); 276 int nb_notify = _srs_config->get_vhost_hls_nb_notify(req->vhost);
275 for (int i = 0; i < (int)hooks.size(); i++) { 277 for (int i = 0; i < (int)hooks.size(); i++) {
276 std::string url = hooks.at(i); 278 std::string url = hooks.at(i);
277 - if ((ret = SrsHttpHooks::on_hls_notify(url, req, ts_url, nb_notify)) != ERROR_SUCCESS) { 279 + if ((ret = SrsHttpHooks::on_hls_notify(cid, url, req, ts_url, nb_notify)) != ERROR_SUCCESS) {
278 srs_error("hook client on_hls_notify failed. url=%s, ret=%d", url.c_str(), ret); 280 srs_error("hook client on_hls_notify failed. url=%s, ret=%d", url.c_str(), ret);
279 return ret; 281 return ret;
280 } 282 }
@@ -724,7 +726,8 @@ int SrsHlsMuxer::segment_close(string log_desc) @@ -724,7 +726,8 @@ int SrsHlsMuxer::segment_close(string log_desc)
724 segments.push_back(current); 726 segments.push_back(current);
725 727
726 // use async to call the http hooks, for it will cause thread switch. 728 // use async to call the http hooks, for it will cause thread switch.
727 - if ((ret = async->execute(new SrsDvrAsyncCallOnHls(req, 729 + if ((ret = async->execute(new SrsDvrAsyncCallOnHls(
  730 + _srs_context->get_id(), req,
728 current->full_path, current->uri, m3u8, m3u8_url, 731 current->full_path, current->uri, m3u8, m3u8_url,
729 current->sequence_no, current->duration))) != ERROR_SUCCESS) 732 current->sequence_no, current->duration))) != ERROR_SUCCESS)
730 { 733 {
@@ -732,7 +735,7 @@ int SrsHlsMuxer::segment_close(string log_desc) @@ -732,7 +735,7 @@ int SrsHlsMuxer::segment_close(string log_desc)
732 } 735 }
733 736
734 // use async to call the http hooks, for it will cause thread switch. 737 // use async to call the http hooks, for it will cause thread switch.
735 - if ((ret = async->execute(new SrsDvrAsyncCallOnHlsNotify(req, current->uri))) != ERROR_SUCCESS) { 738 + if ((ret = async->execute(new SrsDvrAsyncCallOnHlsNotify(_srs_context->get_id(), req, current->uri))) != ERROR_SUCCESS) {
736 return ret; 739 return ret;
737 } 740 }
738 741
@@ -167,6 +167,7 @@ public: @@ -167,6 +167,7 @@ public:
167 class SrsDvrAsyncCallOnHls : public ISrsAsyncCallTask 167 class SrsDvrAsyncCallOnHls : public ISrsAsyncCallTask
168 { 168 {
169 private: 169 private:
  170 + int cid;
170 std::string path; 171 std::string path;
171 std::string ts_url; 172 std::string ts_url;
172 std::string m3u8; 173 std::string m3u8;
@@ -175,7 +176,7 @@ private: @@ -175,7 +176,7 @@ private:
175 SrsRequest* req; 176 SrsRequest* req;
176 double duration; 177 double duration;
177 public: 178 public:
178 - SrsDvrAsyncCallOnHls(SrsRequest* r, std::string p, std::string t, std::string m, std::string mu, int s, double d); 179 + SrsDvrAsyncCallOnHls(int c, SrsRequest* r, std::string p, std::string t, std::string m, std::string mu, int s, double d);
179 virtual ~SrsDvrAsyncCallOnHls(); 180 virtual ~SrsDvrAsyncCallOnHls();
180 public: 181 public:
181 virtual int call(); 182 virtual int call();
@@ -188,10 +189,11 @@ public: @@ -188,10 +189,11 @@ public:
188 class SrsDvrAsyncCallOnHlsNotify : public ISrsAsyncCallTask 189 class SrsDvrAsyncCallOnHlsNotify : public ISrsAsyncCallTask
189 { 190 {
190 private: 191 private:
  192 + int cid;
191 std::string ts_url; 193 std::string ts_url;
192 SrsRequest* req; 194 SrsRequest* req;
193 public: 195 public:
194 - SrsDvrAsyncCallOnHlsNotify(SrsRequest* r, std::string u); 196 + SrsDvrAsyncCallOnHlsNotify(int c, SrsRequest* r, std::string u);
195 virtual ~SrsDvrAsyncCallOnHlsNotify(); 197 virtual ~SrsDvrAsyncCallOnHlsNotify();
196 public: 198 public:
197 virtual int call(); 199 virtual int call();
@@ -258,11 +258,11 @@ void SrsHttpHooks::on_stop(string url, SrsRequest* req) @@ -258,11 +258,11 @@ void SrsHttpHooks::on_stop(string url, SrsRequest* req)
258 return; 258 return;
259 } 259 }
260 260
261 -int SrsHttpHooks::on_dvr(string url, SrsRequest* req, string file) 261 +int SrsHttpHooks::on_dvr(int cid, string url, SrsRequest* req, string file)
262 { 262 {
263 int ret = ERROR_SUCCESS; 263 int ret = ERROR_SUCCESS;
264 264
265 - int client_id = _srs_context->get_id(); 265 + int client_id = cid;
266 std::string cwd = _srs_config->cwd(); 266 std::string cwd = _srs_config->cwd();
267 267
268 SrsAmf0Object* obj = SrsAmf0Any::object(); 268 SrsAmf0Object* obj = SrsAmf0Any::object();
@@ -294,11 +294,11 @@ int SrsHttpHooks::on_dvr(string url, SrsRequest* req, string file) @@ -294,11 +294,11 @@ int SrsHttpHooks::on_dvr(string url, SrsRequest* req, string file)
294 return ret; 294 return ret;
295 } 295 }
296 296
297 -int SrsHttpHooks::on_hls(string url, SrsRequest* req, string file, string ts_url, string m3u8, string m3u8_url, int sn, double duration) 297 +int SrsHttpHooks::on_hls(int cid, string url, SrsRequest* req, string file, string ts_url, string m3u8, string m3u8_url, int sn, double duration)
298 { 298 {
299 int ret = ERROR_SUCCESS; 299 int ret = ERROR_SUCCESS;
300 300
301 - int client_id = _srs_context->get_id(); 301 + int client_id = cid;
302 std::string cwd = _srs_config->cwd(); 302 std::string cwd = _srs_config->cwd();
303 303
304 SrsAmf0Object* obj = SrsAmf0Any::object(); 304 SrsAmf0Object* obj = SrsAmf0Any::object();
@@ -335,11 +335,11 @@ int SrsHttpHooks::on_hls(string url, SrsRequest* req, string file, string ts_url @@ -335,11 +335,11 @@ int SrsHttpHooks::on_hls(string url, SrsRequest* req, string file, string ts_url
335 return ret; 335 return ret;
336 } 336 }
337 337
338 -int SrsHttpHooks::on_hls_notify(std::string url, SrsRequest* req, std::string ts_url, int nb_notify) 338 +int SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* req, std::string ts_url, int nb_notify)
339 { 339 {
340 int ret = ERROR_SUCCESS; 340 int ret = ERROR_SUCCESS;
341 341
342 - int client_id = _srs_context->get_id(); 342 + int client_id = cid;
343 std::string cwd = _srs_config->cwd(); 343 std::string cwd = _srs_config->cwd();
344 344
345 if (srs_string_starts_with(ts_url, "http://") || srs_string_starts_with(ts_url, "https://")) { 345 if (srs_string_starts_with(ts_url, "http://") || srs_string_starts_with(ts_url, "https://")) {
@@ -90,32 +90,35 @@ public: @@ -90,32 +90,35 @@ public:
90 */ 90 */
91 static void on_stop(std::string url, SrsRequest* req); 91 static void on_stop(std::string url, SrsRequest* req);
92 /** 92 /**
93 - * on_dvr hook, when reap a dvr file.  
94 - * @param url the api server url, to process the event.  
95 - * ignore if empty.  
96 - * @param file the file path, can be relative or absolute path.  
97 - */  
98 - static int on_dvr(std::string url, SrsRequest* req, std::string file); 93 + * on_dvr hook, when reap a dvr file.
  94 + * @param url the api server url, to process the event.
  95 + * ignore if empty.
  96 + * @param file the file path, can be relative or absolute path.
  97 + * @param cid the source connection cid, for the on_dvr is async call.
  98 + */
  99 + static int on_dvr(int cid, std::string url, SrsRequest* req, std::string file);
99 /** 100 /**
100 - * when hls reap segment, callback.  
101 - * @param url the api server url, to process the event.  
102 - * ignore if empty.  
103 - * @param file the ts file path, can be relative or absolute path.  
104 - * @param ts_url the ts url, which used for m3u8.  
105 - * @param m3u8 the m3u8 file path, can be relative or absolute path.  
106 - * @param m3u8_url the m3u8 url, which is used for the http mount path.  
107 - * @param sn the seq_no, the sequence number of ts in hls/m3u8.  
108 - * @param duration the segment duration in seconds.  
109 - */  
110 - 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); 101 + * when hls reap segment, callback.
  102 + * @param url the api server url, to process the event.
  103 + * ignore if empty.
  104 + * @param file the ts file path, can be relative or absolute path.
  105 + * @param ts_url the ts url, which used for m3u8.
  106 + * @param m3u8 the m3u8 file path, can be relative or absolute path.
  107 + * @param m3u8_url the m3u8 url, which is used for the http mount path.
  108 + * @param sn the seq_no, the sequence number of ts in hls/m3u8.
  109 + * @param duration the segment duration in seconds.
  110 + * @param cid the source connection cid, for the on_dvr is async call.
  111 + */
  112 + 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);
111 /** 113 /**
112 * when hls reap segment, callback. 114 * when hls reap segment, callback.
113 * @param url the api server url, to process the event. 115 * @param url the api server url, to process the event.
114 * ignore if empty. 116 * ignore if empty.
115 * @param ts_url the ts uri, used to replace the variable [ts_url] in url. 117 * @param ts_url the ts uri, used to replace the variable [ts_url] in url.
116 * @param nb_notify the max bytes to read from notify server. 118 * @param nb_notify the max bytes to read from notify server.
  119 + * @param cid the source connection cid, for the on_dvr is async call.
117 */ 120 */
118 - static int on_hls_notify(std::string url, SrsRequest* req, std::string ts_url, int nb_notify); 121 + static int on_hls_notify(int cid, std::string url, SrsRequest* req, std::string ts_url, int nb_notify);
119 private: 122 private:
120 static int do_post(std::string url, std::string req, int& code, std::string& res); 123 static int do_post(std::string url, std::string req, int& code, std::string& res);
121 }; 124 };