winlin

fix bandwidth bug, config item interval to float.

@@ -41,6 +41,7 @@ @@ -41,6 +41,7 @@
41 } 41 }
42 function on_start_bandwidth_test() { 42 function on_start_bandwidth_test() {
43 $("#div_container").remove(); 43 $("#div_container").remove();
  44 + $("#progress_bar").removeClass("bar-danger");
44 45
45 var div_container = $("<div/>"); 46 var div_container = $("<div/>");
46 $(div_container).attr("id", "div_container"); 47 $(div_container).attr("id", "div_container");
@@ -68,6 +69,9 @@ @@ -68,6 +69,9 @@
68 ", srs_id:" + srs_id + ", srs_pid:" + srs_pid + ", ip:" + srs_server_ip 69 ", srs_id:" + srs_id + ", srs_pid:" + srs_pid + ", ip:" + srs_server_ip
69 ); 70 );
70 } 71 }
  72 + bandwidth.on_error = function(code) {
  73 + $("#progress_bar").addClass("bar-danger");
  74 + }
71 bandwidth.render(url); 75 bandwidth.render(url);
72 } 76 }
73 function on_stop_bandwidth_test() { 77 function on_stop_bandwidth_test() {
@@ -49,8 +49,8 @@ function SrsBandwidth(container, width, height, private_object) { @@ -49,8 +49,8 @@ function SrsBandwidth(container, width, height, private_object) {
49 // the callback set data. 49 // the callback set data.
50 this.percent = 0; 50 this.percent = 0;
51 this.status = ""; 51 this.status = "";
52 - this.report = "";  
53 this.server = ""; 52 this.server = "";
  53 + this.completed = false;
54 } 54 }
55 /** 55 /**
56 * user can set some callback, then start the bandwidth. 56 * user can set some callback, then start the bandwidth.
@@ -106,6 +106,12 @@ SrsBandwidth.prototype.check_bandwidth = function(url) { @@ -106,6 +106,12 @@ SrsBandwidth.prototype.check_bandwidth = function(url) {
106 this.stop(); 106 this.stop();
107 SrsBandwidth.__bandwidths.push(this); 107 SrsBandwidth.__bandwidths.push(this);
108 108
  109 + // the callback set data.
  110 + this.percent = 0;
  111 + this.status = "";
  112 + this.server = "";
  113 + this.completed = false;
  114 +
109 if (url) { 115 if (url) {
110 this.stream_url = url; 116 this.stream_url = url;
111 } 117 }
@@ -136,6 +142,8 @@ SrsBandwidth.prototype.on_srs_info = function(srs_server, srs_primary_authors, s @@ -136,6 +142,8 @@ SrsBandwidth.prototype.on_srs_info = function(srs_server, srs_primary_authors, s
136 } 142 }
137 SrsBandwidth.prototype.on_complete = function(start_time, end_time, play_kbps, publish_kbps, play_bytes, publish_bytes, play_time, publish_time) { 143 SrsBandwidth.prototype.on_complete = function(start_time, end_time, play_kbps, publish_kbps, play_bytes, publish_bytes, play_time, publish_time) {
138 } 144 }
  145 +SrsBandwidth.prototype.on_error = function(code) {
  146 +}
139 function __srs_find_bandwidth(id) { 147 function __srs_find_bandwidth(id) {
140 for (var i = 0; i < SrsBandwidth.__bandwidths.length; i++) { 148 for (var i = 0; i < SrsBandwidth.__bandwidths.length; i++) {
141 var bandwidth = SrsBandwidth.__bandwidths[i]; 149 var bandwidth = SrsBandwidth.__bandwidths[i];
@@ -164,24 +172,36 @@ function __srs_on_update_status(id, code, data) { @@ -164,24 +172,36 @@ function __srs_on_update_status(id, code, data) {
164 var status = ""; 172 var status = "";
165 switch(code){ 173 switch(code){
166 case "NetConnection.Connect.Failed": 174 case "NetConnection.Connect.Failed":
  175 + if (bandwidth.completed) {
  176 + return;
  177 + }
  178 + bandwidth.on_error(code);
167 status = "连接服务器失败!"; 179 status = "连接服务器失败!";
168 break; 180 break;
169 case "NetConnection.Connect.Rejected": 181 case "NetConnection.Connect.Rejected":
170 - status = "服务器拒绝连接!"; 182 + if (bandwidth.completed) {
  183 + return;
  184 + }
  185 + bandwidth.completed = true;
  186 + bandwidth.on_update_progress(100);
  187 + bandwidth.on_error(code);
  188 + status = "服务器拒绝连接,测速过于频繁!";
171 break; 189 break;
172 case "NetConnection.Connect.Success": 190 case "NetConnection.Connect.Success":
173 status = "连接服务器成功!"; 191 status = "连接服务器成功!";
174 break; 192 break;
175 case "NetConnection.Connect.Closed": 193 case "NetConnection.Connect.Closed":
176 - if (bandwidth.report) { 194 + if (bandwidth.completed) {
177 return; 195 return;
178 } 196 }
  197 + bandwidth.on_error(code);
179 status = "连接已断开!"; 198 status = "连接已断开!";
180 break; 199 break;
181 case "srs.bwtc.play.start": 200 case "srs.bwtc.play.start":
182 status = "开始测试下行带宽"; 201 status = "开始测试下行带宽";
183 break; 202 break;
184 case "srs.bwtc.play.stop": 203 case "srs.bwtc.play.stop":
  204 + bandwidth.completed = true;
185 status = "下行带宽测试完毕," + data + "kbps,开始测试上行带宽。"; 205 status = "下行带宽测试完毕," + data + "kbps,开始测试上行带宽。";
186 break; 206 break;
187 default: 207 default:
@@ -202,7 +222,7 @@ function __srs_on_complete(id, start_time, end_time, play_kbps, publish_kbps, pl @@ -202,7 +222,7 @@ function __srs_on_complete(id, start_time, end_time, play_kbps, publish_kbps, pl
202 222
203 var status = "检测结束: " + bandwidth.server + " 上行: " + publish_kbps + " kbps" + " 下行: " + play_kbps + " kbps" 223 var status = "检测结束: " + bandwidth.server + " 上行: " + publish_kbps + " kbps" + " 下行: " + play_kbps + " kbps"
204 + " 测试时间: " + Number((end_time - start_time) / 1000).toFixed(1) + " 秒"; 224 + " 测试时间: " + Number((end_time - start_time) / 1000).toFixed(1) + " 秒";
205 - bandwidth.report = status; 225 + bandwidth.status = status;
206 bandwidth.on_update_status(status); 226 bandwidth.on_update_status(status);
207 227
208 bandwidth.on_complete(start_time, end_time, play_kbps, publish_kbps, play_bytes, publish_bytes, play_time, publish_time); 228 bandwidth.on_complete(start_time, end_time, play_kbps, publish_kbps, play_bytes, publish_bytes, play_time, publish_time);
@@ -78,7 +78,7 @@ int SrsBandwidth::bandwidth_check(SrsRtmpServer* rtmp, SrsRequest* req, string l @@ -78,7 +78,7 @@ int SrsBandwidth::bandwidth_check(SrsRtmpServer* rtmp, SrsRequest* req, string l
78 // reject the connection in the interval window. 78 // reject the connection in the interval window.
79 if (last_check_time > 0 && time_now - last_check_time < interval_ms) { 79 if (last_check_time > 0 && time_now - last_check_time < interval_ms) {
80 ret = ERROR_SYSTEM_BANDWIDTH_DENIED; 80 ret = ERROR_SYSTEM_BANDWIDTH_DENIED;
81 - srs_trace("bandcheck denied, " 81 + srs_trace("reject, "
82 "last_check=%"PRId64", now=%"PRId64", interval=%d", 82 "last_check=%"PRId64", now=%"PRId64", interval=%d",
83 last_check_time, time_now, interval_ms); 83 last_check_time, time_now, interval_ms);
84 84
@@ -1866,20 +1866,20 @@ int SrsConfig::get_bw_check_interval_ms(const string &vhost) @@ -1866,20 +1866,20 @@ int SrsConfig::get_bw_check_interval_ms(const string &vhost)
1866 SrsConfDirective* conf = get_vhost(vhost); 1866 SrsConfDirective* conf = get_vhost(vhost);
1867 1867
1868 if (!conf) { 1868 if (!conf) {
1869 - return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL; 1869 + return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL * 1000;
1870 } 1870 }
1871 1871
1872 conf = conf->get("bandcheck"); 1872 conf = conf->get("bandcheck");
1873 if (!conf) { 1873 if (!conf) {
1874 - return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL; 1874 + return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL * 1000;
1875 } 1875 }
1876 1876
1877 - conf = conf->get("interval_ms"); 1877 + conf = conf->get("interval");
1878 if (!conf) { 1878 if (!conf) {
1879 - return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL; 1879 + return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL * 1000;
1880 } 1880 }
1881 1881
1882 - return ::atoi(conf->arg0().c_str()) * 1000; 1882 + return ::atof(conf->arg0().c_str()) * 1000;
1883 } 1883 }
1884 1884
1885 int SrsConfig::get_bw_check_limit_kbps(const string &vhost) 1885 int SrsConfig::get_bw_check_limit_kbps(const string &vhost)
@@ -910,12 +910,10 @@ void SrsRtmpServer::response_connect_reject(SrsRequest *req, const char* desc) @@ -910,12 +910,10 @@ void SrsRtmpServer::response_connect_reject(SrsRequest *req, const char* desc)
910 { 910 {
911 int ret = ERROR_SUCCESS; 911 int ret = ERROR_SUCCESS;
912 912
913 - SrsConnectAppResPacket* pkt = new SrsConnectAppResPacket();  
914 - pkt->command_name = "_error";  
915 - pkt->props->set(StatusLevel, SrsAmf0Any::str(StatusLevelError));  
916 - pkt->props->set(StatusCode, SrsAmf0Any::str(StatusCodeConnectRejected));  
917 - pkt->props->set(StatusDescription, SrsAmf0Any::str(desc));  
918 - //pkt->props->set("objectEncoding", SrsAmf0Any::number(req->objectEncoding)); 913 + SrsOnStatusCallPacket* pkt = new SrsOnStatusCallPacket();
  914 + pkt->data->set(StatusLevel, SrsAmf0Any::str(StatusLevelError));
  915 + pkt->data->set(StatusCode, SrsAmf0Any::str(StatusCodeConnectRejected));
  916 + pkt->data->set(StatusDescription, SrsAmf0Any::str(desc));
919 917
920 if ((ret = protocol->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) { 918 if ((ret = protocol->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) {
921 srs_error("send connect app response rejected message failed. ret=%d", ret); 919 srs_error("send connect app response rejected message failed. ret=%d", ret);