winlin

for #319, move time_jitter and mix_correct to play

@@ -42,4 +42,32 @@ vhost __defaultVhost__ { @@ -42,4 +42,32 @@ vhost __defaultVhost__ {
42 enabled off; 42 enabled off;
43 latency 350; 43 latency 350;
44 } 44 }
  45 +
  46 + # for SRS2
  47 + mode remote;
  48 + origin 127.0.0.1:1935 localhost:1935;
  49 +
  50 + token_traverse off;
  51 + vhost same.edge.srs.com;
  52 +
  53 + debug_srs_upnode off;
  54 +
  55 + # for SRS2
  56 + forward 127.0.0.1:1936 127.0.0.1:1937;
  57 +
  58 + # for SRS2
  59 + time_jitter full;
  60 + mix_correct off;
  61 +
  62 + atc on;
  63 + atc_auto on;
  64 +
  65 + min_latency on;
  66 + mw_latency 100;
  67 +
  68 + gop_cache off;
  69 + queue_length 10;
  70 +
  71 + send_min_interval 10.0;
  72 + reduce_sequence_header on;
45 } 73 }
@@ -979,7 +979,7 @@ vhost mrw.srs.com { @@ -979,7 +979,7 @@ vhost mrw.srs.com {
979 979
980 # @see publish.srs.com 980 # @see publish.srs.com
981 publish { 981 publish {
982 - mr off; 982 + mr on;
983 mr_latenct 350; 983 mr_latenct 350;
984 } 984 }
985 } 985 }
@@ -988,9 +988,6 @@ vhost mrw.srs.com { @@ -988,9 +988,6 @@ vhost mrw.srs.com {
988 vhost min.delay.com { 988 vhost min.delay.com {
989 # @see vhost mrw.srs.com for detail. 989 # @see vhost mrw.srs.com for detail.
990 min_latency on; 990 min_latency on;
991 - mr {  
992 - enabled off;  
993 - }  
994 mw_latency 100; 991 mw_latency 100;
995 # whether cache the last gop. 992 # whether cache the last gop.
996 # if on, cache the last gop and dispatch to client, 993 # if on, cache the last gop and dispatch to client,
@@ -1010,15 +1007,17 @@ vhost min.delay.com { @@ -1010,15 +1007,17 @@ vhost min.delay.com {
1010 # if on, set the nodelay of fd by setsockopt 1007 # if on, set the nodelay of fd by setsockopt
1011 # default: off 1008 # default: off
1012 tcp_nodelay on; 1009 tcp_nodelay on;
  1010 +
  1011 + # @see publish.srs.com
  1012 + publish {
  1013 + mr off;
  1014 + }
1013 } 1015 }
1014 1016
1015 # the vhost to control the stream delivery feature 1017 # the vhost to control the stream delivery feature
1016 vhost stream.control.com { 1018 vhost stream.control.com {
1017 # @see vhost mrw.srs.com for detail. 1019 # @see vhost mrw.srs.com for detail.
1018 min_latency on; 1020 min_latency on;
1019 - mr {  
1020 - enabled off;  
1021 - }  
1022 mw_latency 100; 1021 mw_latency 100;
1023 # @see vhost min.delay.com 1022 # @see vhost min.delay.com
1024 queue_length 10; 1023 queue_length 10;
@@ -1040,6 +1039,7 @@ vhost stream.control.com { @@ -1040,6 +1039,7 @@ vhost stream.control.com {
1040 1039
1041 # @see publish.srs.com 1040 # @see publish.srs.com
1042 publish { 1041 publish {
  1042 + mr off;
1043 firstpkt_timeout 20000; 1043 firstpkt_timeout 20000;
1044 normal_timeout 7000; 1044 normal_timeout 7000;
1045 } 1045 }
@@ -1086,8 +1086,11 @@ vhost chunksize.srs.com { @@ -1086,8 +1086,11 @@ vhost chunksize.srs.com {
1086 chunk_size 128; 1086 chunk_size 128;
1087 } 1087 }
1088 1088
1089 -# vhost for time jitter  
1090 -vhost jitter.srs.com { 1089 +# the play specified configs
  1090 +vhost play.srs.com {
  1091 + # for play client, both RTMP and other stream clients,
  1092 + # for instance, the HTTP FLV stream clients.
  1093 + play {
1091 # about the stream monotonically increasing: 1094 # about the stream monotonically increasing:
1092 # 1. video timestamp is monotonically increasing, 1095 # 1. video timestamp is monotonically increasing,
1093 # 2. audio timestamp is monotonically increasing, 1096 # 2. audio timestamp is monotonically increasing,
@@ -1105,6 +1108,15 @@ vhost jitter.srs.com { @@ -1105,6 +1108,15 @@ vhost jitter.srs.com {
1105 # if off, use time_jitter to correct the timestamp if required. 1108 # if off, use time_jitter to correct the timestamp if required.
1106 # default: off 1109 # default: off
1107 mix_correct off; 1110 mix_correct off;
  1111 + }
  1112 +}
  1113 +
  1114 +# vhost for time jitter
  1115 +vhost jitter.srs.com {
  1116 + # @see play.srs.com
  1117 + time_jitter full;
  1118 + # @see play.srs.com
  1119 + mix_correct off;
1108 } 1120 }
1109 1121
1110 # vhost for atc. 1122 # vhost for atc.
@@ -48,30 +48,42 @@ vhost __defaultVhost__ { @@ -48,30 +48,42 @@ vhost __defaultVhost__ {
48 vhost vhost.srs.com { 48 vhost vhost.srs.com {
49 enabled off; 49 enabled off;
50 50
  51 + chunk_size 128;
  52 + tcp_nodelay on;
  53 +
  54 + # TODO
  55 + cluster {
51 mode remote; 56 mode remote;
52 origin 127.0.0.1:1935 localhost:1935; 57 origin 127.0.0.1:1935 localhost:1935;
  58 +
53 token_traverse off; 59 token_traverse off;
54 vhost same.edge.srs.com; 60 vhost same.edge.srs.com;
55 61
56 - forward 127.0.0.1:1936 127.0.0.1:1937;  
57 -  
58 debug_srs_upnode off; 62 debug_srs_upnode off;
  63 + }
59 64
60 - chunk_size 128; 65 + # TODO
  66 + forward {
  67 + destination 127.0.0.1:1936 127.0.0.1:1937;
  68 + }
61 69
  70 + play {
62 time_jitter full; 71 time_jitter full;
63 mix_correct off; 72 mix_correct off;
64 73
  74 + # TODO
65 atc on; 75 atc on;
66 atc_auto on; 76 atc_auto on;
67 77
68 min_latency on; 78 min_latency on;
69 mw_latency 100; 79 mw_latency 100;
  80 +
70 gop_cache off; 81 gop_cache off;
71 queue_length 10; 82 queue_length 10;
72 - tcp_nodelay on; 83 +
73 send_min_interval 10.0; 84 send_min_interval 10.0;
74 reduce_sequence_header on; 85 reduce_sequence_header on;
  86 + }
75 87
76 publish { 88 publish {
77 mr off; 89 mr off;
@@ -5,11 +5,15 @@ @@ -5,11 +5,15 @@
5 listen 1935; 5 listen 1935;
6 max_connections 1000; 6 max_connections 1000;
7 vhost __defaultVhost__ { 7 vhost __defaultVhost__ {
  8 + tcp_nodelay on;
  9 +
  10 + play {
8 gop_cache off; 11 gop_cache off;
9 queue_length 10; 12 queue_length 10;
10 min_latency on; 13 min_latency on;
11 mw_latency 100; 14 mw_latency 100;
12 - tcp_nodelay on; 15 + }
  16 +
13 publish { 17 publish {
14 mr off; 18 mr off;
15 } 19 }
@@ -731,28 +731,16 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root) @@ -731,28 +731,16 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
731 srs_trace("vhost %s reload queue_length success.", vhost.c_str()); 731 srs_trace("vhost %s reload queue_length success.", vhost.c_str());
732 } 732 }
733 733
734 - // time_jitter, only one per vhost  
735 - if (!srs_directive_equals(new_vhost->get("time_jitter"), old_vhost->get("time_jitter"))) { 734 + // play, only one per vhost
  735 + if (!srs_directive_equals(new_vhost->get("play"), old_vhost->get("play"))) {
736 for (it = subscribes.begin(); it != subscribes.end(); ++it) { 736 for (it = subscribes.begin(); it != subscribes.end(); ++it) {
737 ISrsReloadHandler* subscribe = *it; 737 ISrsReloadHandler* subscribe = *it;
738 - if ((ret = subscribe->on_reload_vhost_time_jitter(vhost)) != ERROR_SUCCESS) {  
739 - srs_error("vhost %s notify subscribes time_jitter failed. ret=%d", vhost.c_str(), ret); 738 + if ((ret = subscribe->on_reload_vhost_play(vhost)) != ERROR_SUCCESS) {
  739 + srs_error("vhost %s notify subscribes play failed. ret=%d", vhost.c_str(), ret);
740 return ret; 740 return ret;
741 } 741 }
742 } 742 }
743 - srs_trace("vhost %s reload time_jitter success.", vhost.c_str());  
744 - }  
745 -  
746 - // mix_correct, only one per vhost  
747 - if (!srs_directive_equals(new_vhost->get("mix_correct"), old_vhost->get("mix_correct"))) {  
748 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
749 - ISrsReloadHandler* subscribe = *it;  
750 - if ((ret = subscribe->on_reload_vhost_mix_correct(vhost)) != ERROR_SUCCESS) {  
751 - srs_error("vhost %s notify subscribes mix_correct failed. ret=%d", vhost.c_str(), ret);  
752 - return ret;  
753 - }  
754 - }  
755 - srs_trace("vhost %s reload mix_correct success.", vhost.c_str()); 743 + srs_trace("vhost %s reload play success.", vhost.c_str());
756 } 744 }
757 745
758 // forward, only one per vhost 746 // forward, only one per vhost
@@ -1754,14 +1742,6 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj) @@ -1754,14 +1742,6 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj)
1754 obj->set("chunk_size", dir->dumps_arg0_to_number()); 1742 obj->set("chunk_size", dir->dumps_arg0_to_number());
1755 } 1743 }
1756 1744
1757 - // time_jitter  
1758 - if ((dir = vhost->get("time_jitter")) != NULL) {  
1759 - obj->set("time_jitter", dir->dumps_arg0_to_str());  
1760 - }  
1761 - if ((dir = vhost->get("mix_correct")) != NULL) {  
1762 - obj->set("mix_correct", dir->dumps_arg0_to_boolean());  
1763 - }  
1764 -  
1765 // atc 1745 // atc
1766 if ((dir = vhost->get("atc")) != NULL) { 1746 if ((dir = vhost->get("atc")) != NULL) {
1767 obj->set("atc", dir->dumps_arg0_to_boolean()); 1747 obj->set("atc", dir->dumps_arg0_to_boolean());
@@ -1797,6 +1777,22 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj) @@ -1797,6 +1777,22 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj)
1797 obj->set("reduce_sequence_header", dir->dumps_arg0_to_boolean()); 1777 obj->set("reduce_sequence_header", dir->dumps_arg0_to_boolean());
1798 } 1778 }
1799 1779
  1780 + // play
  1781 + if ((dir = vhost->get("play")) != NULL) {
  1782 + SrsAmf0Object* play = SrsAmf0Any::object();
  1783 + obj->set("play", play);
  1784 +
  1785 + for (int i = 0; i < (int)dir->directives.size(); i++) {
  1786 + SrsConfDirective* sdir = dir->directives.at(i);
  1787 +
  1788 + if (sdir->name == "time_jitter") {
  1789 + play->set("time_jitter", sdir->dumps_arg0_to_str());
  1790 + } else if (sdir->name == "mix_correct") {
  1791 + play->set("mix_correct", sdir->dumps_arg0_to_boolean());
  1792 + }
  1793 + }
  1794 + }
  1795 +
1800 // publish 1796 // publish
1801 if ((dir = vhost->get("publish")) != NULL) { 1797 if ((dir = vhost->get("publish")) != NULL) {
1802 SrsAmf0Object* publish = SrsAmf0Any::object(); 1798 SrsAmf0Object* publish = SrsAmf0Any::object();
@@ -2675,10 +2671,8 @@ int SrsConfig::check_config() @@ -2675,10 +2671,8 @@ int SrsConfig::check_config()
2675 && n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks" 2671 && n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks"
2676 && n != "gop_cache" && n != "queue_length" 2672 && n != "gop_cache" && n != "queue_length"
2677 && n != "refer" && n != "forward" && n != "transcode" && n != "bandcheck" 2673 && n != "refer" && n != "forward" && n != "transcode" && n != "bandcheck"
2678 - && n != "time_jitter" && n != "mix_correct"  
2679 - && n != "atc" && n != "atc_auto"  
2680 - && n != "debug_srs_upnode"  
2681 - && n != "publish" && n != "mw_latency" && n != "min_latency" 2674 + && n != "atc" && n != "atc_auto" && n != "debug_srs_upnode"
  2675 + && n != "play" && n != "publish" && n != "mw_latency" && n != "min_latency"
2682 && n != "tcp_nodelay" && n != "send_min_interval" && n != "reduce_sequence_header" 2676 && n != "tcp_nodelay" && n != "send_min_interval" && n != "reduce_sequence_header"
2683 && n != "security" && n != "http_remux" 2677 && n != "security" && n != "http_remux"
2684 && n != "http_static" && n != "hds" && n != "exec" 2678 && n != "http_static" && n != "hds" && n != "exec"
@@ -2717,6 +2711,15 @@ int SrsConfig::check_config() @@ -2717,6 +2711,15 @@ int SrsConfig::check_config()
2717 return ret; 2711 return ret;
2718 } 2712 }
2719 } 2713 }
  2714 + } else if (n == "play") {
  2715 + for (int j = 0; j < (int)conf->directives.size(); j++) {
  2716 + string m = conf->at(j)->name.c_str();
  2717 + if (m != "time_jitter" && m != "mix_correct") {
  2718 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  2719 + srs_error("unsupported vhost play directive %s, ret=%d", m.c_str(), ret);
  2720 + return ret;
  2721 + }
  2722 + }
2720 } else if (n == "publish") { 2723 } else if (n == "publish") {
2721 for (int j = 0; j < (int)conf->directives.size(); j++) { 2724 for (int j = 0; j < (int)conf->directives.size(); j++) {
2722 string m = conf->at(j)->name.c_str(); 2725 string m = conf->at(j)->name.c_str();
@@ -3295,6 +3298,11 @@ int SrsConfig::get_time_jitter(string vhost) @@ -3295,6 +3298,11 @@ int SrsConfig::get_time_jitter(string vhost)
3295 return _srs_time_jitter_string2int(DEFAULT); 3298 return _srs_time_jitter_string2int(DEFAULT);
3296 } 3299 }
3297 3300
  3301 + conf = conf->get("play");
  3302 + if (!conf || conf->arg0().empty()) {
  3303 + return _srs_time_jitter_string2int(DEFAULT);
  3304 + }
  3305 +
3298 conf = conf->get("time_jitter"); 3306 conf = conf->get("time_jitter");
3299 if (!conf || conf->arg0().empty()) { 3307 if (!conf || conf->arg0().empty()) {
3300 return _srs_time_jitter_string2int(DEFAULT); 3308 return _srs_time_jitter_string2int(DEFAULT);
@@ -3312,6 +3320,11 @@ bool SrsConfig::get_mix_correct(string vhost) @@ -3312,6 +3320,11 @@ bool SrsConfig::get_mix_correct(string vhost)
3312 return DEFAULT; 3320 return DEFAULT;
3313 } 3321 }
3314 3322
  3323 + conf = conf->get("play");
  3324 + if (!conf || conf->arg0().empty()) {
  3325 + return DEFAULT;
  3326 + }
  3327 +
3315 conf = conf->get("mix_correct"); 3328 conf = conf->get("mix_correct");
3316 if (!conf || conf->arg0().empty()) { 3329 if (!conf || conf->arg0().empty()) {
3317 return DEFAULT; 3330 return DEFAULT;
@@ -5782,6 +5795,23 @@ int srs_config_transform_vhost(SrsConfDirective* root) @@ -5782,6 +5795,23 @@ int srs_config_transform_vhost(SrsConfDirective* root)
5782 continue; 5795 continue;
5783 } 5796 }
5784 5797
  5798 + // SRS3.0, change the folowing like a shadow:
  5799 + // time_jitter, mix_correct
  5800 + // SRS1/2:
  5801 + // vhost { shadow; }
  5802 + // SRS3+:
  5803 + // vhost { play { shadow; } }
  5804 + if (conf->name == "time_jitter" || conf->name == "mix_correct") {
  5805 + it = dir->directives.erase(it);
  5806 +
  5807 + SrsConfDirective* play = dir->get_or_create("play");
  5808 + SrsConfDirective* shadow = play->get_or_create(conf->name);
  5809 + shadow->args = conf->args;
  5810 +
  5811 + srs_freep(conf);
  5812 + continue;
  5813 + }
  5814 +
5785 ++it; 5815 ++it;
5786 } 5816 }
5787 } 5817 }
@@ -140,12 +140,7 @@ int ISrsReloadHandler::on_reload_vhost_queue_length(string /*vhost*/) @@ -140,12 +140,7 @@ int ISrsReloadHandler::on_reload_vhost_queue_length(string /*vhost*/)
140 return ERROR_SUCCESS; 140 return ERROR_SUCCESS;
141 } 141 }
142 142
143 -int ISrsReloadHandler::on_reload_vhost_time_jitter(string /*vhost*/)  
144 -{  
145 - return ERROR_SUCCESS;  
146 -}  
147 -  
148 -int ISrsReloadHandler::on_reload_vhost_mix_correct(string /*vhost*/) 143 +int ISrsReloadHandler::on_reload_vhost_play(string /*vhost*/)
149 { 144 {
150 return ERROR_SUCCESS; 145 return ERROR_SUCCESS;
151 } 146 }
@@ -67,8 +67,7 @@ public: @@ -67,8 +67,7 @@ public:
67 virtual int on_reload_vhost_atc(std::string vhost); 67 virtual int on_reload_vhost_atc(std::string vhost);
68 virtual int on_reload_vhost_gop_cache(std::string vhost); 68 virtual int on_reload_vhost_gop_cache(std::string vhost);
69 virtual int on_reload_vhost_queue_length(std::string vhost); 69 virtual int on_reload_vhost_queue_length(std::string vhost);
70 - virtual int on_reload_vhost_time_jitter(std::string vhost);  
71 - virtual int on_reload_vhost_mix_correct(std::string vhost); 70 + virtual int on_reload_vhost_play(std::string vhost);
72 virtual int on_reload_vhost_forward(std::string vhost); 71 virtual int on_reload_vhost_forward(std::string vhost);
73 virtual int on_reload_vhost_hls(std::string vhost); 72 virtual int on_reload_vhost_hls(std::string vhost);
74 virtual int on_reload_vhost_hds(std::string vhost); 73 virtual int on_reload_vhost_hds(std::string vhost);
@@ -1121,7 +1121,7 @@ int SrsSource::on_reload_vhost_queue_length(string vhost) @@ -1121,7 +1121,7 @@ int SrsSource::on_reload_vhost_queue_length(string vhost)
1121 return ret; 1121 return ret;
1122 } 1122 }
1123 1123
1124 -int SrsSource::on_reload_vhost_time_jitter(string vhost) 1124 +int SrsSource::on_reload_vhost_play(string vhost)
1125 { 1125 {
1126 int ret = ERROR_SUCCESS; 1126 int ret = ERROR_SUCCESS;
1127 1127
@@ -1129,19 +1129,10 @@ int SrsSource::on_reload_vhost_time_jitter(string vhost) @@ -1129,19 +1129,10 @@ int SrsSource::on_reload_vhost_time_jitter(string vhost)
1129 return ret; 1129 return ret;
1130 } 1130 }
1131 1131
  1132 + // time_jitter
1132 jitter_algorithm = (SrsRtmpJitterAlgorithm)_srs_config->get_time_jitter(_req->vhost); 1133 jitter_algorithm = (SrsRtmpJitterAlgorithm)_srs_config->get_time_jitter(_req->vhost);
1133 1134
1134 - return ret;  
1135 -}  
1136 -  
1137 -int SrsSource::on_reload_vhost_mix_correct(string vhost)  
1138 -{  
1139 - int ret = ERROR_SUCCESS;  
1140 -  
1141 - if (_req->vhost != vhost) {  
1142 - return ret;  
1143 - }  
1144 - 1135 + // mix_correct
1145 bool v = _srs_config->get_mix_correct(_req->vhost); 1136 bool v = _srs_config->get_mix_correct(_req->vhost);
1146 1137
1147 // when changed, clear the mix queue. 1138 // when changed, clear the mix queue.
@@ -521,8 +521,7 @@ public: @@ -521,8 +521,7 @@ public:
521 virtual int on_reload_vhost_atc(std::string vhost); 521 virtual int on_reload_vhost_atc(std::string vhost);
522 virtual int on_reload_vhost_gop_cache(std::string vhost); 522 virtual int on_reload_vhost_gop_cache(std::string vhost);
523 virtual int on_reload_vhost_queue_length(std::string vhost); 523 virtual int on_reload_vhost_queue_length(std::string vhost);
524 - virtual int on_reload_vhost_time_jitter(std::string vhost);  
525 - virtual int on_reload_vhost_mix_correct(std::string vhost); 524 + virtual int on_reload_vhost_play(std::string vhost);
526 virtual int on_reload_vhost_forward(std::string vhost); 525 virtual int on_reload_vhost_forward(std::string vhost);
527 virtual int on_reload_vhost_hls(std::string vhost); 526 virtual int on_reload_vhost_hls(std::string vhost);
528 virtual int on_reload_vhost_hds(std::string vhost); 527 virtual int on_reload_vhost_hds(std::string vhost);
@@ -248,7 +248,7 @@ int MockReloadHandler::on_reload_vhost_queue_length(string /*vhost*/) @@ -248,7 +248,7 @@ int MockReloadHandler::on_reload_vhost_queue_length(string /*vhost*/)
248 return ERROR_SUCCESS; 248 return ERROR_SUCCESS;
249 } 249 }
250 250
251 -int MockReloadHandler::on_reload_vhost_time_jitter(string /*vhost*/) 251 +int MockReloadHandler::on_reload_vhost_play(string /*vhost*/)
252 { 252 {
253 vhost_time_jitter_reloaded = true; 253 vhost_time_jitter_reloaded = true;
254 return ERROR_SUCCESS; 254 return ERROR_SUCCESS;
@@ -88,7 +88,7 @@ public: @@ -88,7 +88,7 @@ public:
88 virtual int on_reload_vhost_atc(std::string vhost); 88 virtual int on_reload_vhost_atc(std::string vhost);
89 virtual int on_reload_vhost_gop_cache(std::string vhost); 89 virtual int on_reload_vhost_gop_cache(std::string vhost);
90 virtual int on_reload_vhost_queue_length(std::string vhost); 90 virtual int on_reload_vhost_queue_length(std::string vhost);
91 - virtual int on_reload_vhost_time_jitter(std::string vhost); 91 + virtual int on_reload_vhost_play(std::string vhost);
92 virtual int on_reload_vhost_forward(std::string vhost); 92 virtual int on_reload_vhost_forward(std::string vhost);
93 virtual int on_reload_vhost_hls(std::string vhost); 93 virtual int on_reload_vhost_hls(std::string vhost);
94 virtual int on_reload_vhost_hds(std::string vhost); 94 virtual int on_reload_vhost_hds(std::string vhost);