winlin

for #319, move mw_latency to play.

@@ -373,18 +373,84 @@ vhost publish.srs.com { @@ -373,18 +373,84 @@ vhost publish.srs.com {
373 } 373 }
374 } 374 }
375 375
  376 +# the play specified configs
  377 +vhost play.srs.com {
  378 + # for play client, both RTMP and other stream clients,
  379 + # for instance, the HTTP FLV stream clients.
  380 + play {
  381 + # about the stream monotonically increasing:
  382 + # 1. video timestamp is monotonically increasing,
  383 + # 2. audio timestamp is monotonically increasing,
  384 + # 3. video and audio timestamp is interleaved/mixed monotonically increasing.
  385 + # it's specified by RTMP specification, @see 3. Byte Order, Alignment, and Time Format
  386 + # however, some encoder cannot provides this feature, please set this to off to ignore time jitter.
  387 + # the time jitter algorithm:
  388 + # 1. full, to ensure stream start at zero, and ensure stream monotonically increasing.
  389 + # 2. zero, only ensure sttream start at zero, ignore timestamp jitter.
  390 + # 3. off, disable the time jitter algorithm, like atc.
  391 + # default: full
  392 + time_jitter full;
  393 + # whether use the interleaved/mixed algorithm to correct the timestamp.
  394 + # if on, always ensure the timestamp of audio+video is interleaved/mixed monotonically increase.
  395 + # if off, use time_jitter to correct the timestamp if required.
  396 + # default: off
  397 + mix_correct off;
  398 +
  399 + # vhost for atc for hls/hds/rtmp backup.
  400 + # generally, atc default to off, server delivery rtmp stream to client(flash) timestamp from 0.
  401 + # when atc is on, server delivery rtmp stream by absolute time.
  402 + # atc is used, for instance, encoder will copy stream to master and slave server,
  403 + # server use atc to delivery stream to edge/client, where stream time from master/slave server
  404 + # is always the same, client/tools can slice RTMP stream to HLS according to the same time,
  405 + # if the time not the same, the HLS stream cannot slice to support system backup.
  406 + #
  407 + # @see http://www.adobe.com/cn/devnet/adobe-media-server/articles/varnish-sample-for-failover.html
  408 + # @see http://www.baidu.com/#wd=hds%20hls%20atc
  409 + #
  410 + # default: off
  411 + atc off;
  412 + # whether enable the auto atc,
  413 + # if enabled, detect the bravo_atc="true" in onMetaData packet,
  414 + # set atc to on if matched.
  415 + # always ignore the onMetaData if atc_auto is off.
  416 + # default: off
  417 + atc_auto off;
  418 +
  419 + # set the MW(merged-write) latency in ms.
  420 + # SRS always set mw on, so we just set the latency value.
  421 + # the latency of stream >= mw_latency + mr_latency
  422 + # the value recomment is [300, 1800]
  423 + # default: 350
  424 + mw_latency 350;
  425 + }
  426 +}
  427 +
  428 +# vhost for time jitter
  429 +vhost jitter.srs.com {
  430 + # @see play.srs.com
  431 + time_jitter full;
  432 + # @see play.srs.com
  433 + mix_correct off;
  434 +}
  435 +
  436 +# vhost for atc.
  437 +vhost atc.srs.com {
  438 + # @see play.srs.com
  439 + atc on;
  440 + # @see play.srs.com
  441 + atc_auto on;
  442 +}
  443 +
376 # the MR(merged-read) setting for publisher. 444 # the MR(merged-read) setting for publisher.
377 # the MW(merged-write) settings for player. 445 # the MW(merged-write) settings for player.
378 vhost mrw.srs.com { 446 vhost mrw.srs.com {
379 # @see scope.vhost.srs.com 447 # @see scope.vhost.srs.com
380 min_latency off; 448 min_latency off;
381 449
382 - # set the MW(merged-write) latency in ms.  
383 - # SRS always set mw on, so we just set the latency value.  
384 - # the latency of stream >= mw_latency + mr_latency  
385 - # the value recomment is [300, 1800]  
386 - # default: 350  
387 - mw_latency 350; 450 + # @see play.srs.com
  451 + play {
  452 + mw_latency 350;
  453 + }
388 454
389 # @see publish.srs.com 455 # @see publish.srs.com
390 publish { 456 publish {
@@ -395,10 +461,11 @@ vhost mrw.srs.com { @@ -395,10 +461,11 @@ vhost mrw.srs.com {
395 461
396 # the vhost for min delay, donot cache any stream. 462 # the vhost for min delay, donot cache any stream.
397 vhost min.delay.com { 463 vhost min.delay.com {
398 - # @see vhost mrw.srs.com for detail. 464 + # @see scope.vhost.srs.com
399 min_latency on; 465 min_latency on;
400 # @see scope.vhost.srs.com 466 # @see scope.vhost.srs.com
401 - mw_latency 100; 467 + tcp_nodelay on;
  468 +
402 # whether cache the last gop. 469 # whether cache the last gop.
403 # if on, cache the last gop and dispatch to client, 470 # if on, cache the last gop and dispatch to client,
404 # to enabled fast startup for client, client play immediately. 471 # to enabled fast startup for client, client play immediately.
@@ -413,8 +480,11 @@ vhost min.delay.com { @@ -413,8 +480,11 @@ vhost min.delay.com {
413 # drop the old whole gop. 480 # drop the old whole gop.
414 # default: 30 481 # default: 30
415 queue_length 10; 482 queue_length 10;
416 - # @see scope.vhost.srs.com  
417 - tcp_nodelay on; 483 +
  484 + # @see play.srs.com
  485 + play {
  486 + mw_latency 100;
  487 + }
418 488
419 # @see publish.srs.com 489 # @see publish.srs.com
420 publish { 490 publish {
@@ -424,12 +494,13 @@ vhost min.delay.com { @@ -424,12 +494,13 @@ vhost min.delay.com {
424 494
425 # the vhost to control the stream delivery feature 495 # the vhost to control the stream delivery feature
426 vhost stream.control.com { 496 vhost stream.control.com {
427 - # @see vhost mrw.srs.com for detail. 497 + # @see scope.vhost.srs.com
428 min_latency on; 498 min_latency on;
429 - mw_latency 100; 499 + # @see scope.vhost.srs.com
  500 + tcp_nodelay on;
  501 +
430 # @see vhost min.delay.com 502 # @see vhost min.delay.com
431 queue_length 10; 503 queue_length 10;
432 - tcp_nodelay on;  
433 # the minimal packets send interval in ms, 504 # the minimal packets send interval in ms,
434 # used to control the ndiff of stream by srs_rtmp_dump, 505 # used to control the ndiff of stream by srs_rtmp_dump,
435 # for example, some device can only accept some stream which 506 # for example, some device can only accept some stream which
@@ -445,6 +516,11 @@ vhost stream.control.com { @@ -445,6 +516,11 @@ vhost stream.control.com {
445 # default: off 516 # default: off
446 reduce_sequence_header on; 517 reduce_sequence_header on;
447 518
  519 + # @see play.srs.com
  520 + play {
  521 + mw_latency 100;
  522 + }
  523 +
448 # @see publish.srs.com 524 # @see publish.srs.com
449 publish { 525 publish {
450 mr off; 526 mr off;
@@ -485,67 +561,6 @@ vhost exec.srs.com { @@ -485,67 +561,6 @@ vhost exec.srs.com {
485 } 561 }
486 } 562 }
487 563
488 -# the play specified configs  
489 -vhost play.srs.com {  
490 - # for play client, both RTMP and other stream clients,  
491 - # for instance, the HTTP FLV stream clients.  
492 - play {  
493 - # about the stream monotonically increasing:  
494 - # 1. video timestamp is monotonically increasing,  
495 - # 2. audio timestamp is monotonically increasing,  
496 - # 3. video and audio timestamp is interleaved/mixed monotonically increasing.  
497 - # it's specified by RTMP specification, @see 3. Byte Order, Alignment, and Time Format  
498 - # however, some encoder cannot provides this feature, please set this to off to ignore time jitter.  
499 - # the time jitter algorithm:  
500 - # 1. full, to ensure stream start at zero, and ensure stream monotonically increasing.  
501 - # 2. zero, only ensure sttream start at zero, ignore timestamp jitter.  
502 - # 3. off, disable the time jitter algorithm, like atc.  
503 - # default: full  
504 - time_jitter full;  
505 - # whether use the interleaved/mixed algorithm to correct the timestamp.  
506 - # if on, always ensure the timestamp of audio+video is interleaved/mixed monotonically increase.  
507 - # if off, use time_jitter to correct the timestamp if required.  
508 - # default: off  
509 - mix_correct off;  
510 -  
511 - # vhost for atc for hls/hds/rtmp backup.  
512 - # generally, atc default to off, server delivery rtmp stream to client(flash) timestamp from 0.  
513 - # when atc is on, server delivery rtmp stream by absolute time.  
514 - # atc is used, for instance, encoder will copy stream to master and slave server,  
515 - # server use atc to delivery stream to edge/client, where stream time from master/slave server  
516 - # is always the same, client/tools can slice RTMP stream to HLS according to the same time,  
517 - # if the time not the same, the HLS stream cannot slice to support system backup.  
518 - #  
519 - # @see http://www.adobe.com/cn/devnet/adobe-media-server/articles/varnish-sample-for-failover.html  
520 - # @see http://www.baidu.com/#wd=hds%20hls%20atc  
521 - #  
522 - # default: off  
523 - atc off;  
524 - # whether enable the auto atc,  
525 - # if enabled, detect the bravo_atc="true" in onMetaData packet,  
526 - # set atc to on if matched.  
527 - # always ignore the onMetaData if atc_auto is off.  
528 - # default: off  
529 - atc_auto off;  
530 - }  
531 -}  
532 -  
533 -# vhost for time jitter  
534 -vhost jitter.srs.com {  
535 - # @see play.srs.com  
536 - time_jitter full;  
537 - # @see play.srs.com  
538 - mix_correct off;  
539 -}  
540 -  
541 -# vhost for atc.  
542 -vhost atc.srs.com {  
543 - # @see play.srs.com  
544 - atc on;  
545 - # @see play.srs.com  
546 - atc_auto on;  
547 -}  
548 -  
549 # the security to allow or deny clients. 564 # the security to allow or deny clients.
550 vhost security.srs.com { 565 vhost security.srs.com {
551 # security for host to allow or deny clients. 566 # security for host to allow or deny clients.
@@ -841,18 +841,6 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root) @@ -841,18 +841,6 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
841 srs_trace("vhost %s reload publish success.", vhost.c_str()); 841 srs_trace("vhost %s reload publish success.", vhost.c_str());
842 } 842 }
843 843
844 - // mw, only one per vhost  
845 - if (!srs_directive_equals(new_vhost->get("mw_latency"), old_vhost->get("mw_latency"))) {  
846 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
847 - ISrsReloadHandler* subscribe = *it;  
848 - if ((ret = subscribe->on_reload_vhost_mw(vhost)) != ERROR_SUCCESS) {  
849 - srs_error("vhost %s notify subscribes mw failed. ret=%d", vhost.c_str(), ret);  
850 - return ret;  
851 - }  
852 - }  
853 - srs_trace("vhost %s reload mw success.", vhost.c_str());  
854 - }  
855 -  
856 // smi(send_min_interval), only one per vhost 844 // smi(send_min_interval), only one per vhost
857 if (!srs_directive_equals(new_vhost->get("send_min_interval"), old_vhost->get("send_min_interval"))) { 845 if (!srs_directive_equals(new_vhost->get("send_min_interval"), old_vhost->get("send_min_interval"))) {
858 for (it = subscribes.begin(); it != subscribes.end(); ++it) { 846 for (it = subscribes.begin(); it != subscribes.end(); ++it) {
@@ -1735,11 +1723,6 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj) @@ -1735,11 +1723,6 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj)
1735 obj->set("debug_srs_upnode", dir->dumps_arg0_to_boolean()); 1723 obj->set("debug_srs_upnode", dir->dumps_arg0_to_boolean());
1736 } 1724 }
1737 1725
1738 - // mrw  
1739 - if ((dir = vhost->get("mw_latency")) != NULL) {  
1740 - obj->set("mw_latency", dir->dumps_arg0_to_number());  
1741 - }  
1742 -  
1743 // realtime latency 1726 // realtime latency
1744 if ((dir = vhost->get("gop_cache")) != NULL) { 1727 if ((dir = vhost->get("gop_cache")) != NULL) {
1745 obj->set("gop_cache", dir->dumps_arg0_to_boolean()); 1728 obj->set("gop_cache", dir->dumps_arg0_to_boolean());
@@ -1772,6 +1755,8 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj) @@ -1772,6 +1755,8 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj)
1772 play->set("atc", sdir->dumps_arg0_to_boolean()); 1755 play->set("atc", sdir->dumps_arg0_to_boolean());
1773 } else if (sdir->name == "atc_auto") { 1756 } else if (sdir->name == "atc_auto") {
1774 play->set("atc_auto", sdir->dumps_arg0_to_boolean()); 1757 play->set("atc_auto", sdir->dumps_arg0_to_boolean());
  1758 + } else if (sdir->name == "mw_latency") {
  1759 + play->set("mw_latency", sdir->dumps_arg0_to_number());
1775 } 1760 }
1776 } 1761 }
1777 } 1762 }
@@ -2654,7 +2639,7 @@ int SrsConfig::check_config() @@ -2654,7 +2639,7 @@ int SrsConfig::check_config()
2654 && n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks" 2639 && n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks"
2655 && n != "gop_cache" && n != "queue_length" 2640 && n != "gop_cache" && n != "queue_length"
2656 && n != "refer" && n != "forward" && n != "transcode" && n != "bandcheck" 2641 && n != "refer" && n != "forward" && n != "transcode" && n != "bandcheck"
2657 - && n != "debug_srs_upnode" && n != "play" && n != "publish" && n != "mw_latency" 2642 + && n != "debug_srs_upnode" && n != "play" && n != "publish"
2658 && n != "send_min_interval" && n != "reduce_sequence_header" 2643 && n != "send_min_interval" && n != "reduce_sequence_header"
2659 && n != "security" && n != "http_remux" 2644 && n != "security" && n != "http_remux"
2660 && n != "http_static" && n != "hds" && n != "exec" 2645 && n != "http_static" && n != "hds" && n != "exec"
@@ -2696,7 +2681,7 @@ int SrsConfig::check_config() @@ -2696,7 +2681,7 @@ int SrsConfig::check_config()
2696 } else if (n == "play") { 2681 } else if (n == "play") {
2697 for (int j = 0; j < (int)conf->directives.size(); j++) { 2682 for (int j = 0; j < (int)conf->directives.size(); j++) {
2698 string m = conf->at(j)->name.c_str(); 2683 string m = conf->at(j)->name.c_str();
2699 - if (m != "time_jitter" && m != "mix_correct" && m != "atc" && m != "atc_auto" ) { 2684 + if (m != "time_jitter" && m != "mix_correct" && m != "atc" && m != "atc_auto" && m != "mw_latency") {
2700 ret = ERROR_SYSTEM_CONFIG_INVALID; 2685 ret = ERROR_SYSTEM_CONFIG_INVALID;
2701 srs_error("unsupported vhost play directive %s, ret=%d", m.c_str(), ret); 2686 srs_error("unsupported vhost play directive %s, ret=%d", m.c_str(), ret);
2702 return ret; 2687 return ret;
@@ -3482,6 +3467,11 @@ int SrsConfig::get_mw_sleep_ms(string vhost) @@ -3482,6 +3467,11 @@ int SrsConfig::get_mw_sleep_ms(string vhost)
3482 if (!conf) { 3467 if (!conf) {
3483 return SRS_PERF_MW_SLEEP; 3468 return SRS_PERF_MW_SLEEP;
3484 } 3469 }
  3470 +
  3471 + conf = conf->get("play");
  3472 + if (!conf || conf->arg0().empty()) {
  3473 + return SRS_PERF_MW_SLEEP;
  3474 + }
3485 3475
3486 conf = conf->get("mw_latency"); 3476 conf = conf->get("mw_latency");
3487 if (!conf || conf->arg0().empty()) { 3477 if (!conf || conf->arg0().empty()) {
@@ -5789,12 +5779,12 @@ int srs_config_transform_vhost(SrsConfDirective* root) @@ -5789,12 +5779,12 @@ int srs_config_transform_vhost(SrsConfDirective* root)
5789 } 5779 }
5790 5780
5791 // SRS3.0, change the folowing like a shadow: 5781 // SRS3.0, change the folowing like a shadow:
5792 - // time_jitter, mix_correct, atc, atc_auto 5782 + // time_jitter, mix_correct, atc, atc_auto, mw_latency
5793 // SRS1/2: 5783 // SRS1/2:
5794 // vhost { shadow; } 5784 // vhost { shadow; }
5795 // SRS3+: 5785 // SRS3+:
5796 // vhost { play { shadow; } } 5786 // vhost { play { shadow; } }
5797 - if (n == "time_jitter" || n == "mix_correct" || n == "atc" || n == "atc_auto") { 5787 + if (n == "time_jitter" || n == "mix_correct" || n == "atc" || n == "atc_auto" || n == "mw_latency") {
5798 it = dir->directives.erase(it); 5788 it = dir->directives.erase(it);
5799 5789
5800 SrsConfDirective* play = dir->get_or_create("play"); 5790 SrsConfDirective* play = dir->get_or_create("play");
@@ -165,11 +165,6 @@ int ISrsReloadHandler::on_reload_vhost_publish(string /*vhost*/) @@ -165,11 +165,6 @@ int ISrsReloadHandler::on_reload_vhost_publish(string /*vhost*/)
165 return ERROR_SUCCESS; 165 return ERROR_SUCCESS;
166 } 166 }
167 167
168 -int ISrsReloadHandler::on_reload_vhost_mw(string /*vhost*/)  
169 -{  
170 - return ERROR_SUCCESS;  
171 -}  
172 -  
173 int ISrsReloadHandler::on_reload_vhost_smi(string /*vhost*/) 168 int ISrsReloadHandler::on_reload_vhost_smi(string /*vhost*/)
174 { 169 {
175 return ERROR_SUCCESS; 170 return ERROR_SUCCESS;
@@ -72,7 +72,6 @@ public: @@ -72,7 +72,6 @@ public:
72 virtual int on_reload_vhost_hds(std::string vhost); 72 virtual int on_reload_vhost_hds(std::string vhost);
73 virtual int on_reload_vhost_dvr(std::string vhost); 73 virtual int on_reload_vhost_dvr(std::string vhost);
74 virtual int on_reload_vhost_publish(std::string vhost); 74 virtual int on_reload_vhost_publish(std::string vhost);
75 - virtual int on_reload_vhost_mw(std::string vhost);  
76 virtual int on_reload_vhost_smi(std::string vhost); 75 virtual int on_reload_vhost_smi(std::string vhost);
77 virtual int on_reload_vhost_tcp_nodelay(std::string vhost); 76 virtual int on_reload_vhost_tcp_nodelay(std::string vhost);
78 virtual int on_reload_vhost_realtime(std::string vhost); 77 virtual int on_reload_vhost_realtime(std::string vhost);
@@ -231,18 +231,13 @@ int SrsRtmpConn::on_reload_vhost_removed(string vhost) @@ -231,18 +231,13 @@ int SrsRtmpConn::on_reload_vhost_removed(string vhost)
231 return ret; 231 return ret;
232 } 232 }
233 233
234 -int SrsRtmpConn::on_reload_vhost_mw(string vhost) 234 +int SrsRtmpConn::on_reload_vhost_play(string vhost)
235 { 235 {
236 int ret = ERROR_SUCCESS; 236 int ret = ERROR_SUCCESS;
237 237
238 if (req->vhost != vhost) { 238 if (req->vhost != vhost) {
239 return ret; 239 return ret;
240 } 240 }
241 -  
242 - int sleep_ms = _srs_config->get_mw_sleep_ms(req->vhost);  
243 -  
244 - // when mw_sleep changed, resize the socket send buffer.  
245 - change_mw_sleep(sleep_ms);  
246 241
247 return ret; 242 return ret;
248 } 243 }
@@ -103,7 +103,7 @@ protected: @@ -103,7 +103,7 @@ protected:
103 // interface ISrsReloadHandler 103 // interface ISrsReloadHandler
104 public: 104 public:
105 virtual int on_reload_vhost_removed(std::string vhost); 105 virtual int on_reload_vhost_removed(std::string vhost);
106 - virtual int on_reload_vhost_mw(std::string vhost); 106 + virtual int on_reload_vhost_play(std::string vhost);
107 virtual int on_reload_vhost_smi(std::string vhost); 107 virtual int on_reload_vhost_smi(std::string vhost);
108 virtual int on_reload_vhost_tcp_nodelay(std::string vhost); 108 virtual int on_reload_vhost_tcp_nodelay(std::string vhost);
109 virtual int on_reload_vhost_realtime(std::string vhost); 109 virtual int on_reload_vhost_realtime(std::string vhost);