zhengfl

refine code:优化edge模式回源播放线程启动流程

@@ -1210,15 +1210,6 @@ int SrsHttpStreamServer::hijack(ISrsHttpMessage* request, ISrsHttpHandler** ph) @@ -1210,15 +1210,6 @@ int SrsHttpStreamServer::hijack(ISrsHttpMessage* request, ISrsHttpHandler** ph)
1210 srs_trace("hstrs: source url=%s, is_edge=%d, source_id=%d[%d]", 1210 srs_trace("hstrs: source url=%s, is_edge=%d, source_id=%d[%d]",
1211 r->get_stream_url().c_str(), vhost_is_edge, s->source_id(), s->source_id()); 1211 r->get_stream_url().c_str(), vhost_is_edge, s->source_id(), s->source_id());
1212 1212
1213 - // TODO: FIXME: disconnect when all connection closed.  
1214 - if (vhost_is_edge) {  
1215 - // notice edge to start for the first client.  
1216 - if ((ret = s->on_edge_start_play()) != ERROR_SUCCESS) {  
1217 - srs_error("notice edge start play stream failed. ret=%d", ret);  
1218 - return ret;  
1219 - }  
1220 - }  
1221 -  
1222 return ret; 1213 return ret;
1223 } 1214 }
1224 1215
@@ -537,14 +537,6 @@ int SrsRtmpConn::playing(SrsSource* source) @@ -537,14 +537,6 @@ int SrsRtmpConn::playing(SrsSource* source)
537 SrsAutoFree(SrsConsumer, consumer); 537 SrsAutoFree(SrsConsumer, consumer);
538 srs_verbose("consumer created success."); 538 srs_verbose("consumer created success.");
539 539
540 - if (_srs_config->get_vhost_is_edge(req->vhost)) {  
541 - // notice edge to start for the first client.  
542 - if ((ret = source->on_edge_start_play()) != ERROR_SUCCESS) {  
543 - srs_error("notice edge start play stream failed. ret=%d", ret);  
544 - return ret;  
545 - }  
546 - }  
547 -  
548 // use isolate thread to recv, 540 // use isolate thread to recv,
549 // @see: https://github.com/simple-rtmp-server/srs/issues/217 541 // @see: https://github.com/simple-rtmp-server/srs/issues/217
550 SrsQueueRecvThread trd(consumer, rtmp, SRS_PERF_MW_SLEEP); 542 SrsQueueRecvThread trd(consumer, rtmp, SRS_PERF_MW_SLEEP);
@@ -835,7 +827,6 @@ int SrsRtmpConn::acquire_publish(SrsSource* source, bool is_edge) @@ -835,7 +827,6 @@ int SrsRtmpConn::acquire_publish(SrsSource* source, bool is_edge)
835 if ((ret = source->on_edge_start_publish()) != ERROR_SUCCESS) { 827 if ((ret = source->on_edge_start_publish()) != ERROR_SUCCESS) {
836 srs_error("notice edge start publish stream failed. ret=%d", ret); 828 srs_error("notice edge start publish stream failed. ret=%d", ret);
837 } 829 }
838 - return ret;  
839 } else { 830 } else {
840 if ((ret = source->on_publish()) != ERROR_SUCCESS) { 831 if ((ret = source->on_publish()) != ERROR_SUCCESS) {
841 srs_error("notify publish failed. ret=%d", ret); 832 srs_error("notify publish failed. ret=%d", ret);
@@ -765,7 +765,7 @@ SrsSource* SrsSource::fetch(SrsRequest* r) @@ -765,7 +765,7 @@ SrsSource* SrsSource::fetch(SrsRequest* r)
765 SrsSource* SrsSource::fetch(std::string vhost, std::string app, std::string stream) 765 SrsSource* SrsSource::fetch(std::string vhost, std::string app, std::string stream)
766 { 766 {
767 SrsSource* source = NULL; 767 SrsSource* source = NULL;
768 - string stream_url = srs_generate_stream_url(vhost, app, stream); 768 + string stream_url = srs_generate_stream_url(vhost, app, stream);
769 769
770 if (pool.find(stream_url) == pool.end()) { 770 if (pool.find(stream_url) == pool.end()) {
771 return NULL; 771 return NULL;
@@ -2135,6 +2135,15 @@ int SrsSource::create_consumer(SrsConsumer*& consumer, bool ds, bool dm, bool dg @@ -2135,6 +2135,15 @@ int SrsSource::create_consumer(SrsConsumer*& consumer, bool ds, bool dm, bool dg
2135 } else { 2135 } else {
2136 srs_trace("create consumer, ignore gop cache, jitter=%d", jitter_algorithm); 2136 srs_trace("create consumer, ignore gop cache, jitter=%d", jitter_algorithm);
2137 } 2137 }
  2138 +
  2139 + // for edge, when play edge stream, check the state
  2140 + if (_srs_config->get_vhost_is_edge(_req->vhost)) {
  2141 + // notice edge to start for the first client.
  2142 + if ((ret = play_edge->on_client_play()) != ERROR_SUCCESS) {
  2143 + srs_error("notice edge start play stream failed. ret=%d", ret);
  2144 + return ret;
  2145 + }
  2146 + }
2138 2147
2139 return ret; 2148 return ret;
2140 } 2149 }
@@ -2163,11 +2172,6 @@ SrsRtmpJitterAlgorithm SrsSource::jitter() @@ -2163,11 +2172,6 @@ SrsRtmpJitterAlgorithm SrsSource::jitter()
2163 return jitter_algorithm; 2172 return jitter_algorithm;
2164 } 2173 }
2165 2174
2166 -int SrsSource::on_edge_start_play()  
2167 -{  
2168 - return play_edge->on_client_play();  
2169 -}  
2170 -  
2171 int SrsSource::on_edge_start_publish() 2175 int SrsSource::on_edge_start_publish()
2172 { 2176 {
2173 return publish_edge->on_client_publish(); 2177 return publish_edge->on_client_publish();
@@ -574,8 +574,6 @@ public: @@ -574,8 +574,6 @@ public:
574 virtual SrsRtmpJitterAlgorithm jitter(); 574 virtual SrsRtmpJitterAlgorithm jitter();
575 // internal 575 // internal
576 public: 576 public:
577 - // for edge, when play edge stream, check the state  
578 - virtual int on_edge_start_play();  
579 // for edge, when publish edge stream, check the state 577 // for edge, when publish edge stream, check the state
580 virtual int on_edge_start_publish(); 578 virtual int on_edge_start_publish();
581 // for edge, proxy the publish 579 // for edge, proxy the publish