winlin

for #742, refine the rtmp conn, use info as data cluster.

@@ -254,15 +254,13 @@ void SrsQueueRecvThread::on_stop() @@ -254,15 +254,13 @@ void SrsQueueRecvThread::on_stop()
254 SrsPublishRecvThread::SrsPublishRecvThread( 254 SrsPublishRecvThread::SrsPublishRecvThread(
255 SrsRtmpServer* rtmp_sdk, 255 SrsRtmpServer* rtmp_sdk,
256 SrsRequest* _req, int mr_sock_fd, int timeout_ms, 256 SrsRequest* _req, int mr_sock_fd, int timeout_ms,
257 - SrsRtmpConn* conn, SrsSource* source, bool is_fmle, bool is_edge 257 + SrsRtmpConn* conn, SrsSource* source
258 ): trd(this, rtmp_sdk, timeout_ms) 258 ): trd(this, rtmp_sdk, timeout_ms)
259 { 259 {
260 rtmp = rtmp_sdk; 260 rtmp = rtmp_sdk;
261 261
262 _conn = conn; 262 _conn = conn;
263 _source = source; 263 _source = source;
264 - _is_fmle = is_fmle;  
265 - _is_edge = is_edge;  
266 264
267 recv_error_code = ERROR_SUCCESS; 265 recv_error_code = ERROR_SUCCESS;
268 _nb_msgs = 0; 266 _nb_msgs = 0;
@@ -351,7 +349,7 @@ int SrsPublishRecvThread::consume(SrsCommonMessage* msg) @@ -351,7 +349,7 @@ int SrsPublishRecvThread::consume(SrsCommonMessage* msg)
351 srs_update_system_time_ms(), msg->header.timestamp, msg->size); 349 srs_update_system_time_ms(), msg->header.timestamp, msg->size);
352 350
353 // the rtmp connection will handle this message 351 // the rtmp connection will handle this message
354 - ret = _conn->handle_publish_message(_source, msg, _is_fmle, _is_edge); 352 + ret = _conn->handle_publish_message(_source, msg);
355 353
356 // must always free it, 354 // must always free it,
357 // the source will copy it if need to use. 355 // the source will copy it if need to use.
@@ -181,8 +181,6 @@ private: @@ -181,8 +181,6 @@ private:
181 SrsRtmpConn* _conn; 181 SrsRtmpConn* _conn;
182 // the params for conn callback. 182 // the params for conn callback.
183 SrsSource* _source; 183 SrsSource* _source;
184 - bool _is_fmle;  
185 - bool _is_edge;  
186 // the error timeout cond 184 // the error timeout cond
187 // @see https://github.com/ossrs/srs/issues/244 185 // @see https://github.com/ossrs/srs/issues/244
188 st_cond_t error; 186 st_cond_t error;
@@ -192,7 +190,7 @@ private: @@ -192,7 +190,7 @@ private:
192 public: 190 public:
193 SrsPublishRecvThread(SrsRtmpServer* rtmp_sdk, 191 SrsPublishRecvThread(SrsRtmpServer* rtmp_sdk,
194 SrsRequest* _req, int mr_sock_fd, int timeout_ms, 192 SrsRequest* _req, int mr_sock_fd, int timeout_ms,
195 - SrsRtmpConn* conn, SrsSource* source, bool is_fmle, bool is_edge); 193 + SrsRtmpConn* conn, SrsSource* source);
196 virtual ~SrsPublishRecvThread(); 194 virtual ~SrsPublishRecvThread();
197 public: 195 public:
198 /** 196 /**
@@ -283,13 +283,25 @@ void SrsSimpleRtmpClient::set_recv_timeout(int64_t timeout) @@ -283,13 +283,25 @@ void SrsSimpleRtmpClient::set_recv_timeout(int64_t timeout)
283 transport->set_recv_timeout(timeout); 283 transport->set_recv_timeout(timeout);
284 } 284 }
285 285
  286 +SrsClientInfo::SrsClientInfo()
  287 +{
  288 + edge = false;
  289 + req = new SrsRequest();
  290 + res = new SrsResponse();
  291 + type = SrsRtmpConnUnknown;
  292 +}
  293 +
  294 +SrsClientInfo::~SrsClientInfo()
  295 +{
  296 + srs_freep(req);
  297 + srs_freep(res);
  298 +}
  299 +
286 SrsRtmpConn::SrsRtmpConn(SrsServer* svr, st_netfd_t c, string cip) 300 SrsRtmpConn::SrsRtmpConn(SrsServer* svr, st_netfd_t c, string cip)
287 : SrsConnection(svr, c, cip) 301 : SrsConnection(svr, c, cip)
288 { 302 {
289 server = svr; 303 server = svr;
290 304
291 - req = new SrsRequest();  
292 - res = new SrsResponse();  
293 skt = new SrsStSocket(c); 305 skt = new SrsStSocket(c);
294 rtmp = new SrsRtmpServer(skt); 306 rtmp = new SrsRtmpServer(skt);
295 refer = new SrsRefer(); 307 refer = new SrsRefer();
@@ -305,7 +317,7 @@ SrsRtmpConn::SrsRtmpConn(SrsServer* svr, st_netfd_t c, string cip) @@ -305,7 +317,7 @@ SrsRtmpConn::SrsRtmpConn(SrsServer* svr, st_netfd_t c, string cip)
305 realtime = SRS_PERF_MIN_LATENCY_ENABLED; 317 realtime = SRS_PERF_MIN_LATENCY_ENABLED;
306 send_min_interval = 0; 318 send_min_interval = 0;
307 tcp_nodelay = false; 319 tcp_nodelay = false;
308 - client_type = SrsRtmpConnUnknown; 320 + info = new SrsClientInfo();
309 321
310 _srs_config->subscribe(this); 322 _srs_config->subscribe(this);
311 } 323 }
@@ -314,8 +326,7 @@ SrsRtmpConn::~SrsRtmpConn() @@ -314,8 +326,7 @@ SrsRtmpConn::~SrsRtmpConn()
314 { 326 {
315 _srs_config->unsubscribe(this); 327 _srs_config->unsubscribe(this);
316 328
317 - srs_freep(req);  
318 - srs_freep(res); 329 + srs_freep(info);
319 srs_freep(rtmp); 330 srs_freep(rtmp);
320 srs_freep(skt); 331 srs_freep(skt);
321 srs_freep(refer); 332 srs_freep(refer);
@@ -358,6 +369,7 @@ int SrsRtmpConn::do_cycle() @@ -358,6 +369,7 @@ int SrsRtmpConn::do_cycle()
358 } 369 }
359 srs_verbose("rtmp handshake success"); 370 srs_verbose("rtmp handshake success");
360 371
  372 + SrsRequest* req = info->req;
361 if ((ret = rtmp->connect_app(req)) != ERROR_SUCCESS) { 373 if ((ret = rtmp->connect_app(req)) != ERROR_SUCCESS) {
362 srs_error("rtmp connect vhost/app failed. ret=%d", ret); 374 srs_error("rtmp connect vhost/app failed. ret=%d", ret);
363 return ret; 375 return ret;
@@ -440,6 +452,8 @@ int SrsRtmpConn::on_reload_vhost_removed(string vhost) @@ -440,6 +452,8 @@ int SrsRtmpConn::on_reload_vhost_removed(string vhost)
440 { 452 {
441 int ret = ERROR_SUCCESS; 453 int ret = ERROR_SUCCESS;
442 454
  455 + SrsRequest* req = info->req;
  456 +
443 if (req->vhost != vhost) { 457 if (req->vhost != vhost) {
444 return ret; 458 return ret;
445 } 459 }
@@ -460,6 +474,8 @@ int SrsRtmpConn::on_reload_vhost_play(string vhost) @@ -460,6 +474,8 @@ int SrsRtmpConn::on_reload_vhost_play(string vhost)
460 { 474 {
461 int ret = ERROR_SUCCESS; 475 int ret = ERROR_SUCCESS;
462 476
  477 + SrsRequest* req = info->req;
  478 +
463 if (req->vhost != vhost) { 479 if (req->vhost != vhost) {
464 return ret; 480 return ret;
465 } 481 }
@@ -480,6 +496,8 @@ int SrsRtmpConn::on_reload_vhost_tcp_nodelay(string vhost) @@ -480,6 +496,8 @@ int SrsRtmpConn::on_reload_vhost_tcp_nodelay(string vhost)
480 { 496 {
481 int ret = ERROR_SUCCESS; 497 int ret = ERROR_SUCCESS;
482 498
  499 + SrsRequest* req = info->req;
  500 +
483 if (req->vhost != vhost) { 501 if (req->vhost != vhost) {
484 return ret; 502 return ret;
485 } 503 }
@@ -493,6 +511,8 @@ int SrsRtmpConn::on_reload_vhost_realtime(string vhost) @@ -493,6 +511,8 @@ int SrsRtmpConn::on_reload_vhost_realtime(string vhost)
493 { 511 {
494 int ret = ERROR_SUCCESS; 512 int ret = ERROR_SUCCESS;
495 513
  514 + SrsRequest* req = info->req;
  515 +
496 if (req->vhost != vhost) { 516 if (req->vhost != vhost) {
497 return ret; 517 return ret;
498 } 518 }
@@ -510,6 +530,8 @@ int SrsRtmpConn::on_reload_vhost_publish(string vhost) @@ -510,6 +530,8 @@ int SrsRtmpConn::on_reload_vhost_publish(string vhost)
510 { 530 {
511 int ret = ERROR_SUCCESS; 531 int ret = ERROR_SUCCESS;
512 532
  533 + SrsRequest* req = info->req;
  534 +
513 if (req->vhost != vhost) { 535 if (req->vhost != vhost) {
514 return ret; 536 return ret;
515 } 537 }
@@ -553,6 +575,8 @@ int SrsRtmpConn::service_cycle() @@ -553,6 +575,8 @@ int SrsRtmpConn::service_cycle()
553 { 575 {
554 int ret = ERROR_SUCCESS; 576 int ret = ERROR_SUCCESS;
555 577
  578 + SrsRequest* req = info->req;
  579 +
556 int out_ack_size = _srs_config->get_out_ack_size(req->vhost); 580 int out_ack_size = _srs_config->get_out_ack_size(req->vhost);
557 if (out_ack_size && (ret = rtmp->set_window_ack_size(out_ack_size)) != ERROR_SUCCESS) { 581 if (out_ack_size && (ret = rtmp->set_window_ack_size(out_ack_size)) != ERROR_SUCCESS) {
558 srs_error("set output window acknowledgement size failed. ret=%d", ret); 582 srs_error("set output window acknowledgement size failed. ret=%d", ret);
@@ -582,9 +606,9 @@ int SrsRtmpConn::service_cycle() @@ -582,9 +606,9 @@ int SrsRtmpConn::service_cycle()
582 // do token traverse before serve it. 606 // do token traverse before serve it.
583 // @see https://github.com/ossrs/srs/pull/239 607 // @see https://github.com/ossrs/srs/pull/239
584 if (true) { 608 if (true) {
585 - bool vhost_is_edge = _srs_config->get_vhost_is_edge(req->vhost); 609 + info->edge = _srs_config->get_vhost_is_edge(req->vhost);
586 bool edge_traverse = _srs_config->get_vhost_edge_token_traverse(req->vhost); 610 bool edge_traverse = _srs_config->get_vhost_edge_token_traverse(req->vhost);
587 - if (vhost_is_edge && edge_traverse) { 611 + if (info->edge && edge_traverse) {
588 if ((ret = check_edge_token_traverse_auth()) != ERROR_SUCCESS) { 612 if ((ret = check_edge_token_traverse_auth()) != ERROR_SUCCESS) {
589 srs_warn("token auth failed, ret=%d", ret); 613 srs_warn("token auth failed, ret=%d", ret);
590 return ret; 614 return ret;
@@ -667,8 +691,9 @@ int SrsRtmpConn::stream_service_cycle() @@ -667,8 +691,9 @@ int SrsRtmpConn::stream_service_cycle()
667 { 691 {
668 int ret = ERROR_SUCCESS; 692 int ret = ERROR_SUCCESS;
669 693
670 - SrsRtmpConnType type;  
671 - if ((ret = rtmp->identify_client(res->stream_id, type, req->stream, req->duration)) != ERROR_SUCCESS) { 694 + SrsRequest* req = info->req;
  695 +
  696 + if ((ret = rtmp->identify_client(info->res->stream_id, info->type, req->stream, req->duration)) != ERROR_SUCCESS) {
672 if (!srs_is_client_gracefully_close(ret)) { 697 if (!srs_is_client_gracefully_close(ret)) {
673 srs_error("identify client failed. ret=%d", ret); 698 srs_error("identify client failed. ret=%d", ret);
674 } 699 }
@@ -676,10 +701,10 @@ int SrsRtmpConn::stream_service_cycle() @@ -676,10 +701,10 @@ int SrsRtmpConn::stream_service_cycle()
676 } 701 }
677 req->strip(); 702 req->strip();
678 srs_trace("client identified, type=%s, stream_name=%s, duration=%.2f", 703 srs_trace("client identified, type=%s, stream_name=%s, duration=%.2f",
679 - srs_client_type_string(type).c_str(), req->stream.c_str(), req->duration); 704 + srs_client_type_string(info->type).c_str(), req->stream.c_str(), req->duration);
680 705
681 // security check 706 // security check
682 - if ((ret = security->check(type, ip, req)) != ERROR_SUCCESS) { 707 + if ((ret = security->check(info->type, ip, req)) != ERROR_SUCCESS) {
683 srs_error("security check failed. ret=%d", ret); 708 srs_error("security check failed. ret=%d", ret);
684 return ret; 709 return ret;
685 } 710 }
@@ -698,25 +723,23 @@ int SrsRtmpConn::stream_service_cycle() @@ -698,25 +723,23 @@ int SrsRtmpConn::stream_service_cycle()
698 723
699 // update the statistic when source disconveried. 724 // update the statistic when source disconveried.
700 SrsStatistic* stat = SrsStatistic::instance(); 725 SrsStatistic* stat = SrsStatistic::instance();
701 - if ((ret = stat->on_client(_srs_context->get_id(), req, this, type)) != ERROR_SUCCESS) { 726 + if ((ret = stat->on_client(_srs_context->get_id(), req, this, info->type)) != ERROR_SUCCESS) {
702 srs_error("stat client failed. ret=%d", ret); 727 srs_error("stat client failed. ret=%d", ret);
703 return ret; 728 return ret;
704 } 729 }
705 730
706 - bool vhost_is_edge = _srs_config->get_vhost_is_edge(req->vhost);  
707 bool enabled_cache = _srs_config->get_gop_cache(req->vhost); 731 bool enabled_cache = _srs_config->get_gop_cache(req->vhost);
708 srs_trace("source url=%s, ip=%s, cache=%d, is_edge=%d, source_id=%d[%d]", 732 srs_trace("source url=%s, ip=%s, cache=%d, is_edge=%d, source_id=%d[%d]",
709 - req->get_stream_url().c_str(), ip.c_str(), enabled_cache, vhost_is_edge, 733 + req->get_stream_url().c_str(), ip.c_str(), enabled_cache, info->edge,
710 source->source_id(), source->source_id()); 734 source->source_id(), source->source_id());
711 source->set_cache(enabled_cache); 735 source->set_cache(enabled_cache);
712 736
713 - client_type = type;  
714 - switch (type) { 737 + switch (info->type) {
715 case SrsRtmpConnPlay: { 738 case SrsRtmpConnPlay: {
716 srs_verbose("start to play stream %s.", req->stream.c_str()); 739 srs_verbose("start to play stream %s.", req->stream.c_str());
717 740
718 // response connection start play 741 // response connection start play
719 - if ((ret = rtmp->start_play(res->stream_id)) != ERROR_SUCCESS) { 742 + if ((ret = rtmp->start_play(info->res->stream_id)) != ERROR_SUCCESS) {
720 srs_error("start to play stream failed. ret=%d", ret); 743 srs_error("start to play stream failed. ret=%d", ret);
721 return ret; 744 return ret;
722 } 745 }
@@ -734,7 +757,7 @@ int SrsRtmpConn::stream_service_cycle() @@ -734,7 +757,7 @@ int SrsRtmpConn::stream_service_cycle()
734 case SrsRtmpConnFMLEPublish: { 757 case SrsRtmpConnFMLEPublish: {
735 srs_verbose("FMLE start to publish stream %s.", req->stream.c_str()); 758 srs_verbose("FMLE start to publish stream %s.", req->stream.c_str());
736 759
737 - if ((ret = rtmp->start_fmle_publish(res->stream_id)) != ERROR_SUCCESS) { 760 + if ((ret = rtmp->start_fmle_publish(info->res->stream_id)) != ERROR_SUCCESS) {
738 srs_error("start to publish stream failed. ret=%d", ret); 761 srs_error("start to publish stream failed. ret=%d", ret);
739 return ret; 762 return ret;
740 } 763 }
@@ -744,7 +767,7 @@ int SrsRtmpConn::stream_service_cycle() @@ -744,7 +767,7 @@ int SrsRtmpConn::stream_service_cycle()
744 case SrsRtmpConnFlashPublish: { 767 case SrsRtmpConnFlashPublish: {
745 srs_verbose("flash start to publish stream %s.", req->stream.c_str()); 768 srs_verbose("flash start to publish stream %s.", req->stream.c_str());
746 769
747 - if ((ret = rtmp->start_flash_publish(res->stream_id)) != ERROR_SUCCESS) { 770 + if ((ret = rtmp->start_flash_publish(info->res->stream_id)) != ERROR_SUCCESS) {
748 srs_error("flash start to publish stream failed. ret=%d", ret); 771 srs_error("flash start to publish stream failed. ret=%d", ret);
749 return ret; 772 return ret;
750 } 773 }
@@ -765,6 +788,7 @@ int SrsRtmpConn::check_vhost(bool try_default_vhost) @@ -765,6 +788,7 @@ int SrsRtmpConn::check_vhost(bool try_default_vhost)
765 { 788 {
766 int ret = ERROR_SUCCESS; 789 int ret = ERROR_SUCCESS;
767 790
  791 + SrsRequest* req = info->req;
768 srs_assert(req != NULL); 792 srs_assert(req != NULL);
769 793
770 SrsConfDirective* vhost = _srs_config->get_vhost(req->vhost, try_default_vhost); 794 SrsConfDirective* vhost = _srs_config->get_vhost(req->vhost, try_default_vhost);
@@ -845,6 +869,7 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe @@ -845,6 +869,7 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe
845 869
846 srs_assert(consumer != NULL); 870 srs_assert(consumer != NULL);
847 871
  872 + SrsRequest* req = info->req;
848 if (_srs_config->get_refer_enabled(req->vhost)) { 873 if (_srs_config->get_refer_enabled(req->vhost)) {
849 if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_play(req->vhost))) != ERROR_SUCCESS) { 874 if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_play(req->vhost))) != ERROR_SUCCESS) {
850 srs_error("check play_refer failed. ret=%d", ret); 875 srs_error("check play_refer failed. ret=%d", ret);
@@ -991,7 +1016,7 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe @@ -991,7 +1016,7 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe
991 1016
992 // sendout messages, all messages are freed by send_and_free_messages(). 1017 // sendout messages, all messages are freed by send_and_free_messages().
993 // no need to assert msg, for the rtmp will assert it. 1018 // no need to assert msg, for the rtmp will assert it.
994 - if (count > 0 && (ret = rtmp->send_and_free_messages(msgs.msgs, count, res->stream_id)) != ERROR_SUCCESS) { 1019 + if (count > 0 && (ret = rtmp->send_and_free_messages(msgs.msgs, count, info->res->stream_id)) != ERROR_SUCCESS) {
995 if (!srs_is_client_gracefully_close(ret)) { 1020 if (!srs_is_client_gracefully_close(ret)) {
996 srs_error("send messages to client failed. ret=%d", ret); 1021 srs_error("send messages to client failed. ret=%d", ret);
997 } 1022 }
@@ -1021,6 +1046,8 @@ int SrsRtmpConn::publishing(SrsSource* source) @@ -1021,6 +1046,8 @@ int SrsRtmpConn::publishing(SrsSource* source)
1021 { 1046 {
1022 int ret = ERROR_SUCCESS; 1047 int ret = ERROR_SUCCESS;
1023 1048
  1049 + SrsRequest* req = info->req;
  1050 +
1024 if (_srs_config->get_refer_enabled(req->vhost)) { 1051 if (_srs_config->get_refer_enabled(req->vhost)) {
1025 if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_publish(req->vhost))) != ERROR_SUCCESS) { 1052 if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_publish(req->vhost))) != ERROR_SUCCESS) {
1026 srs_error("check publish_refer failed. ret=%d", ret); 1053 srs_error("check publish_refer failed. ret=%d", ret);
@@ -1034,14 +1061,10 @@ int SrsRtmpConn::publishing(SrsSource* source) @@ -1034,14 +1061,10 @@ int SrsRtmpConn::publishing(SrsSource* source)
1034 return ret; 1061 return ret;
1035 } 1062 }
1036 1063
1037 - bool vhost_is_edge = _srs_config->get_vhost_is_edge(req->vhost);  
1038 - if ((ret = acquire_publish(source, vhost_is_edge)) == ERROR_SUCCESS) { 1064 + if ((ret = acquire_publish(source)) == ERROR_SUCCESS) {
1039 // use isolate thread to recv, 1065 // use isolate thread to recv,
1040 // @see: https://github.com/ossrs/srs/issues/237 1066 // @see: https://github.com/ossrs/srs/issues/237
1041 - SrsPublishRecvThread trd(rtmp, req,  
1042 - st_netfd_fileno(stfd), 0, this, source,  
1043 - client_type == SrsRtmpConnFMLEPublish,  
1044 - vhost_is_edge); 1067 + SrsPublishRecvThread trd(rtmp, req, st_netfd_fileno(stfd), 0, this, source);
1045 1068
1046 srs_info("start to publish stream %s success", req->stream.c_str()); 1069 srs_info("start to publish stream %s success", req->stream.c_str());
1047 ret = do_publishing(source, &trd); 1070 ret = do_publishing(source, &trd);
@@ -1056,7 +1079,7 @@ int SrsRtmpConn::publishing(SrsSource* source) @@ -1056,7 +1079,7 @@ int SrsRtmpConn::publishing(SrsSource* source)
1056 // @see https://github.com/ossrs/srs/issues/474 1079 // @see https://github.com/ossrs/srs/issues/474
1057 // @remark when stream is busy, should never release it. 1080 // @remark when stream is busy, should never release it.
1058 if (ret != ERROR_SYSTEM_STREAM_BUSY) { 1081 if (ret != ERROR_SYSTEM_STREAM_BUSY) {
1059 - release_publish(source, vhost_is_edge); 1082 + release_publish(source);
1060 } 1083 }
1061 1084
1062 http_hooks_on_unpublish(); 1085 http_hooks_on_unpublish();
@@ -1068,6 +1091,7 @@ int SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* trd) @@ -1068,6 +1091,7 @@ int SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* trd)
1068 { 1091 {
1069 int ret = ERROR_SUCCESS; 1092 int ret = ERROR_SUCCESS;
1070 1093
  1094 + SrsRequest* req = info->req;
1071 SrsPithyPrint* pprint = SrsPithyPrint::create_rtmp_publish(); 1095 SrsPithyPrint* pprint = SrsPithyPrint::create_rtmp_publish();
1072 SrsAutoFree(SrsPithyPrint, pprint); 1096 SrsAutoFree(SrsPithyPrint, pprint);
1073 1097
@@ -1150,11 +1174,13 @@ int SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* trd) @@ -1150,11 +1174,13 @@ int SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* trd)
1150 return ret; 1174 return ret;
1151 } 1175 }
1152 1176
1153 -int SrsRtmpConn::acquire_publish(SrsSource* source, bool is_edge) 1177 +int SrsRtmpConn::acquire_publish(SrsSource* source)
1154 { 1178 {
1155 int ret = ERROR_SUCCESS; 1179 int ret = ERROR_SUCCESS;
1156 1180
1157 - if (!source->can_publish(is_edge)) { 1181 + SrsRequest* req = info->req;
  1182 +
  1183 + if (!source->can_publish(info->edge)) {
1158 ret = ERROR_SYSTEM_STREAM_BUSY; 1184 ret = ERROR_SYSTEM_STREAM_BUSY;
1159 srs_warn("stream %s is already publishing. ret=%d", 1185 srs_warn("stream %s is already publishing. ret=%d",
1160 req->get_stream_url().c_str(), ret); 1186 req->get_stream_url().c_str(), ret);
@@ -1162,7 +1188,7 @@ int SrsRtmpConn::acquire_publish(SrsSource* source, bool is_edge) @@ -1162,7 +1188,7 @@ int SrsRtmpConn::acquire_publish(SrsSource* source, bool is_edge)
1162 } 1188 }
1163 1189
1164 // when edge, ignore the publish event, directly proxy it. 1190 // when edge, ignore the publish event, directly proxy it.
1165 - if (is_edge) { 1191 + if (info->edge) {
1166 if ((ret = source->on_edge_start_publish()) != ERROR_SUCCESS) { 1192 if ((ret = source->on_edge_start_publish()) != ERROR_SUCCESS) {
1167 srs_error("notice edge start publish stream failed. ret=%d", ret); 1193 srs_error("notice edge start publish stream failed. ret=%d", ret);
1168 return ret; 1194 return ret;
@@ -1177,18 +1203,18 @@ int SrsRtmpConn::acquire_publish(SrsSource* source, bool is_edge) @@ -1177,18 +1203,18 @@ int SrsRtmpConn::acquire_publish(SrsSource* source, bool is_edge)
1177 return ret; 1203 return ret;
1178 } 1204 }
1179 1205
1180 -void SrsRtmpConn::release_publish(SrsSource* source, bool is_edge) 1206 +void SrsRtmpConn::release_publish(SrsSource* source)
1181 { 1207 {
1182 // when edge, notice edge to change state. 1208 // when edge, notice edge to change state.
1183 // when origin, notice all service to unpublish. 1209 // when origin, notice all service to unpublish.
1184 - if (is_edge) { 1210 + if (info->edge) {
1185 source->on_edge_proxy_unpublish(); 1211 source->on_edge_proxy_unpublish();
1186 } else { 1212 } else {
1187 source->on_unpublish(); 1213 source->on_unpublish();
1188 } 1214 }
1189 } 1215 }
1190 1216
1191 -int SrsRtmpConn::handle_publish_message(SrsSource* source, SrsCommonMessage* msg, bool is_fmle, bool vhost_is_edge) 1217 +int SrsRtmpConn::handle_publish_message(SrsSource* source, SrsCommonMessage* msg)
1192 { 1218 {
1193 int ret = ERROR_SUCCESS; 1219 int ret = ERROR_SUCCESS;
1194 1220
@@ -1202,7 +1228,7 @@ int SrsRtmpConn::handle_publish_message(SrsSource* source, SrsCommonMessage* msg @@ -1202,7 +1228,7 @@ int SrsRtmpConn::handle_publish_message(SrsSource* source, SrsCommonMessage* msg
1202 SrsAutoFree(SrsPacket, pkt); 1228 SrsAutoFree(SrsPacket, pkt);
1203 1229
1204 // for flash, any packet is republish. 1230 // for flash, any packet is republish.
1205 - if (!is_fmle) { 1231 + if (info->type == SrsRtmpConnFlashPublish) {
1206 // flash unpublish. 1232 // flash unpublish.
1207 // TODO: maybe need to support republish. 1233 // TODO: maybe need to support republish.
1208 srs_trace("flash flash publish finished."); 1234 srs_trace("flash flash publish finished.");
@@ -1212,7 +1238,7 @@ int SrsRtmpConn::handle_publish_message(SrsSource* source, SrsCommonMessage* msg @@ -1212,7 +1238,7 @@ int SrsRtmpConn::handle_publish_message(SrsSource* source, SrsCommonMessage* msg
1212 // for fmle, drop others except the fmle start packet. 1238 // for fmle, drop others except the fmle start packet.
1213 if (dynamic_cast<SrsFMLEStartPacket*>(pkt)) { 1239 if (dynamic_cast<SrsFMLEStartPacket*>(pkt)) {
1214 SrsFMLEStartPacket* unpublish = dynamic_cast<SrsFMLEStartPacket*>(pkt); 1240 SrsFMLEStartPacket* unpublish = dynamic_cast<SrsFMLEStartPacket*>(pkt);
1215 - if ((ret = rtmp->fmle_unpublish(res->stream_id, unpublish->transaction_id)) != ERROR_SUCCESS) { 1241 + if ((ret = rtmp->fmle_unpublish(info->res->stream_id, unpublish->transaction_id)) != ERROR_SUCCESS) {
1216 return ret; 1242 return ret;
1217 } 1243 }
1218 return ERROR_CONTROL_REPUBLISH; 1244 return ERROR_CONTROL_REPUBLISH;
@@ -1223,7 +1249,7 @@ int SrsRtmpConn::handle_publish_message(SrsSource* source, SrsCommonMessage* msg @@ -1223,7 +1249,7 @@ int SrsRtmpConn::handle_publish_message(SrsSource* source, SrsCommonMessage* msg
1223 } 1249 }
1224 1250
1225 // video, audio, data message 1251 // video, audio, data message
1226 - if ((ret = process_publish_message(source, msg, vhost_is_edge)) != ERROR_SUCCESS) { 1252 + if ((ret = process_publish_message(source, msg)) != ERROR_SUCCESS) {
1227 srs_error("fmle process publish message failed. ret=%d", ret); 1253 srs_error("fmle process publish message failed. ret=%d", ret);
1228 return ret; 1254 return ret;
1229 } 1255 }
@@ -1231,12 +1257,12 @@ int SrsRtmpConn::handle_publish_message(SrsSource* source, SrsCommonMessage* msg @@ -1231,12 +1257,12 @@ int SrsRtmpConn::handle_publish_message(SrsSource* source, SrsCommonMessage* msg
1231 return ret; 1257 return ret;
1232 } 1258 }
1233 1259
1234 -int SrsRtmpConn::process_publish_message(SrsSource* source, SrsCommonMessage* msg, bool vhost_is_edge) 1260 +int SrsRtmpConn::process_publish_message(SrsSource* source, SrsCommonMessage* msg)
1235 { 1261 {
1236 int ret = ERROR_SUCCESS; 1262 int ret = ERROR_SUCCESS;
1237 1263
1238 // for edge, directly proxy message to origin. 1264 // for edge, directly proxy message to origin.
1239 - if (vhost_is_edge) { 1265 + if (info->edge) {
1240 if ((ret = source->on_edge_proxy_publish(msg)) != ERROR_SUCCESS) { 1266 if ((ret = source->on_edge_proxy_publish(msg)) != ERROR_SUCCESS) {
1241 srs_error("edge publish proxy msg failed. ret=%d", ret); 1267 srs_error("edge publish proxy msg failed. ret=%d", ret);
1242 return ret; 1268 return ret;
@@ -1354,7 +1380,7 @@ int SrsRtmpConn::process_play_control_msg(SrsConsumer* consumer, SrsCommonMessag @@ -1354,7 +1380,7 @@ int SrsRtmpConn::process_play_control_msg(SrsConsumer* consumer, SrsCommonMessag
1354 // pause 1380 // pause
1355 SrsPausePacket* pause = dynamic_cast<SrsPausePacket*>(pkt); 1381 SrsPausePacket* pause = dynamic_cast<SrsPausePacket*>(pkt);
1356 if (pause) { 1382 if (pause) {
1357 - if ((ret = rtmp->on_play_client_pause(res->stream_id, pause->is_pause)) != ERROR_SUCCESS) { 1383 + if ((ret = rtmp->on_play_client_pause(info->res->stream_id, pause->is_pause)) != ERROR_SUCCESS) {
1358 srs_error("rtmp process play client pause failed. ret=%d", ret); 1384 srs_error("rtmp process play client pause failed. ret=%d", ret);
1359 return ret; 1385 return ret;
1360 } 1386 }
@@ -1425,6 +1451,8 @@ void SrsRtmpConn::change_mw_sleep(int sleep_ms) @@ -1425,6 +1451,8 @@ void SrsRtmpConn::change_mw_sleep(int sleep_ms)
1425 1451
1426 void SrsRtmpConn::set_sock_options() 1452 void SrsRtmpConn::set_sock_options()
1427 { 1453 {
  1454 + SrsRequest* req = info->req;
  1455 +
1428 bool nvalue = _srs_config->get_tcp_nodelay(req->vhost); 1456 bool nvalue = _srs_config->get_tcp_nodelay(req->vhost);
1429 if (nvalue != tcp_nodelay) { 1457 if (nvalue != tcp_nodelay) {
1430 tcp_nodelay = nvalue; 1458 tcp_nodelay = nvalue;
@@ -1454,6 +1482,7 @@ int SrsRtmpConn::check_edge_token_traverse_auth() @@ -1454,6 +1482,7 @@ int SrsRtmpConn::check_edge_token_traverse_auth()
1454 { 1482 {
1455 int ret = ERROR_SUCCESS; 1483 int ret = ERROR_SUCCESS;
1456 1484
  1485 + SrsRequest* req = info->req;
1457 srs_assert(req); 1486 srs_assert(req);
1458 1487
1459 vector<string> args = _srs_config->get_vhost_edge_origin(req->vhost)->args; 1488 vector<string> args = _srs_config->get_vhost_edge_origin(req->vhost)->args;
@@ -1492,6 +1521,7 @@ int SrsRtmpConn::do_token_traverse_auth(SrsRtmpClient* client) @@ -1492,6 +1521,7 @@ int SrsRtmpConn::do_token_traverse_auth(SrsRtmpClient* client)
1492 { 1521 {
1493 int ret = ERROR_SUCCESS; 1522 int ret = ERROR_SUCCESS;
1494 1523
  1524 + SrsRequest* req = info->req;
1495 srs_assert(client); 1525 srs_assert(client);
1496 1526
1497 client->set_recv_timeout(SRS_CONSTS_RTMP_TMMS); 1527 client->set_recv_timeout(SRS_CONSTS_RTMP_TMMS);
@@ -1535,6 +1565,8 @@ int SrsRtmpConn::http_hooks_on_connect() @@ -1535,6 +1565,8 @@ int SrsRtmpConn::http_hooks_on_connect()
1535 { 1565 {
1536 int ret = ERROR_SUCCESS; 1566 int ret = ERROR_SUCCESS;
1537 1567
  1568 + SrsRequest* req = info->req;
  1569 +
1538 #ifdef SRS_AUTO_HTTP_CALLBACK 1570 #ifdef SRS_AUTO_HTTP_CALLBACK
1539 if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { 1571 if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
1540 return ret; 1572 return ret;
@@ -1571,6 +1603,8 @@ int SrsRtmpConn::http_hooks_on_connect() @@ -1571,6 +1603,8 @@ int SrsRtmpConn::http_hooks_on_connect()
1571 void SrsRtmpConn::http_hooks_on_close() 1603 void SrsRtmpConn::http_hooks_on_close()
1572 { 1604 {
1573 #ifdef SRS_AUTO_HTTP_CALLBACK 1605 #ifdef SRS_AUTO_HTTP_CALLBACK
  1606 + SrsRequest* req = info->req;
  1607 +
1574 if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { 1608 if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
1575 return; 1609 return;
1576 } 1610 }
@@ -1603,6 +1637,8 @@ int SrsRtmpConn::http_hooks_on_publish() @@ -1603,6 +1637,8 @@ int SrsRtmpConn::http_hooks_on_publish()
1603 int ret = ERROR_SUCCESS; 1637 int ret = ERROR_SUCCESS;
1604 1638
1605 #ifdef SRS_AUTO_HTTP_CALLBACK 1639 #ifdef SRS_AUTO_HTTP_CALLBACK
  1640 + SrsRequest* req = info->req;
  1641 +
1606 if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { 1642 if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
1607 return ret; 1643 return ret;
1608 } 1644 }
@@ -1638,6 +1674,8 @@ int SrsRtmpConn::http_hooks_on_publish() @@ -1638,6 +1674,8 @@ int SrsRtmpConn::http_hooks_on_publish()
1638 void SrsRtmpConn::http_hooks_on_unpublish() 1674 void SrsRtmpConn::http_hooks_on_unpublish()
1639 { 1675 {
1640 #ifdef SRS_AUTO_HTTP_CALLBACK 1676 #ifdef SRS_AUTO_HTTP_CALLBACK
  1677 + SrsRequest* req = info->req;
  1678 +
1641 if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { 1679 if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
1642 return; 1680 return;
1643 } 1681 }
@@ -1670,6 +1708,8 @@ int SrsRtmpConn::http_hooks_on_play() @@ -1670,6 +1708,8 @@ int SrsRtmpConn::http_hooks_on_play()
1670 int ret = ERROR_SUCCESS; 1708 int ret = ERROR_SUCCESS;
1671 1709
1672 #ifdef SRS_AUTO_HTTP_CALLBACK 1710 #ifdef SRS_AUTO_HTTP_CALLBACK
  1711 + SrsRequest* req = info->req;
  1712 +
1673 if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { 1713 if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
1674 return ret; 1714 return ret;
1675 } 1715 }
@@ -1705,6 +1745,8 @@ int SrsRtmpConn::http_hooks_on_play() @@ -1705,6 +1745,8 @@ int SrsRtmpConn::http_hooks_on_play()
1705 void SrsRtmpConn::http_hooks_on_stop() 1745 void SrsRtmpConn::http_hooks_on_stop()
1706 { 1746 {
1707 #ifdef SRS_AUTO_HTTP_CALLBACK 1747 #ifdef SRS_AUTO_HTTP_CALLBACK
  1748 + SrsRequest* req = info->req;
  1749 +
1708 if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { 1750 if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
1709 return; 1751 return;
1710 } 1752 }
@@ -114,6 +114,25 @@ public: @@ -114,6 +114,25 @@ public:
114 }; 114 };
115 115
116 /** 116 /**
  117 + * Some information of client.
  118 + */
  119 +class SrsClientInfo
  120 +{
  121 +public:
  122 + // The type of client, play or publish.
  123 + SrsRtmpConnType type;
  124 + // Whether the client connected at the edge server.
  125 + bool edge;
  126 + // Original request object from client.
  127 + SrsRequest* req;
  128 + // Response object to client.
  129 + SrsResponse* res;
  130 +public:
  131 + SrsClientInfo();
  132 + virtual ~SrsClientInfo();
  133 +};
  134 +
  135 +/**
117 * the client provides the main logic control for RTMP clients. 136 * the client provides the main logic control for RTMP clients.
118 */ 137 */
119 class SrsRtmpConn : public virtual SrsConnection, public virtual ISrsReloadHandler 138 class SrsRtmpConn : public virtual SrsConnection, public virtual ISrsReloadHandler
@@ -122,8 +141,6 @@ class SrsRtmpConn : public virtual SrsConnection, public virtual ISrsReloadHandl @@ -122,8 +141,6 @@ class SrsRtmpConn : public virtual SrsConnection, public virtual ISrsReloadHandl
122 friend class SrsPublishRecvThread; 141 friend class SrsPublishRecvThread;
123 private: 142 private:
124 SrsServer* server; 143 SrsServer* server;
125 - SrsRequest* req;  
126 - SrsResponse* res;  
127 SrsStSocket* skt; 144 SrsStSocket* skt;
128 SrsRtmpServer* rtmp; 145 SrsRtmpServer* rtmp;
129 SrsRefer* refer; 146 SrsRefer* refer;
@@ -151,8 +168,8 @@ private: @@ -151,8 +168,8 @@ private:
151 int publish_normal_timeout; 168 int publish_normal_timeout;
152 // whether enable the tcp_nodelay. 169 // whether enable the tcp_nodelay.
153 bool tcp_nodelay; 170 bool tcp_nodelay;
154 - // The type of client, play or publish.  
155 - SrsRtmpConnType client_type; 171 + // About the rtmp client.
  172 + SrsClientInfo* info;
156 public: 173 public:
157 SrsRtmpConn(SrsServer* svr, st_netfd_t c, std::string cip); 174 SrsRtmpConn(SrsServer* svr, st_netfd_t c, std::string cip);
158 virtual ~SrsRtmpConn(); 175 virtual ~SrsRtmpConn();
@@ -183,10 +200,10 @@ private: @@ -183,10 +200,10 @@ private:
183 virtual int do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRecvThread* trd); 200 virtual int do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRecvThread* trd);
184 virtual int publishing(SrsSource* source); 201 virtual int publishing(SrsSource* source);
185 virtual int do_publishing(SrsSource* source, SrsPublishRecvThread* trd); 202 virtual int do_publishing(SrsSource* source, SrsPublishRecvThread* trd);
186 - virtual int acquire_publish(SrsSource* source, bool is_edge);  
187 - virtual void release_publish(SrsSource* source, bool is_edge);  
188 - virtual int handle_publish_message(SrsSource* source, SrsCommonMessage* msg, bool is_fmle, bool vhost_is_edge);  
189 - virtual int process_publish_message(SrsSource* source, SrsCommonMessage* msg, bool vhost_is_edge); 203 + virtual int acquire_publish(SrsSource* source);
  204 + virtual void release_publish(SrsSource* source);
  205 + virtual int handle_publish_message(SrsSource* source, SrsCommonMessage* msg);
  206 + virtual int process_publish_message(SrsSource* source, SrsCommonMessage* msg);
190 virtual int process_play_control_msg(SrsConsumer* consumer, SrsCommonMessage* msg); 207 virtual int process_play_control_msg(SrsConsumer* consumer, SrsCommonMessage* msg);
191 virtual void change_mw_sleep(int sleep_ms); 208 virtual void change_mw_sleep(int sleep_ms);
192 virtual void set_sock_options(); 209 virtual void set_sock_options();