mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
fix bandwidth bug, config item interval to float.
This commit is contained in:
parent
d8ed7cc968
commit
3a1b3dd142
5 changed files with 60 additions and 38 deletions
|
@ -41,6 +41,7 @@
|
|||
}
|
||||
function on_start_bandwidth_test() {
|
||||
$("#div_container").remove();
|
||||
$("#progress_bar").removeClass("bar-danger");
|
||||
|
||||
var div_container = $("<div/>");
|
||||
$(div_container).attr("id", "div_container");
|
||||
|
@ -68,6 +69,9 @@
|
|||
", srs_id:" + srs_id + ", srs_pid:" + srs_pid + ", ip:" + srs_server_ip
|
||||
);
|
||||
}
|
||||
bandwidth.on_error = function(code) {
|
||||
$("#progress_bar").addClass("bar-danger");
|
||||
}
|
||||
bandwidth.render(url);
|
||||
}
|
||||
function on_stop_bandwidth_test() {
|
||||
|
|
|
@ -49,8 +49,8 @@ function SrsBandwidth(container, width, height, private_object) {
|
|||
// the callback set data.
|
||||
this.percent = 0;
|
||||
this.status = "";
|
||||
this.report = "";
|
||||
this.server = "";
|
||||
this.completed = false;
|
||||
}
|
||||
/**
|
||||
* user can set some callback, then start the bandwidth.
|
||||
|
@ -106,6 +106,12 @@ SrsBandwidth.prototype.check_bandwidth = function(url) {
|
|||
this.stop();
|
||||
SrsBandwidth.__bandwidths.push(this);
|
||||
|
||||
// the callback set data.
|
||||
this.percent = 0;
|
||||
this.status = "";
|
||||
this.server = "";
|
||||
this.completed = false;
|
||||
|
||||
if (url) {
|
||||
this.stream_url = url;
|
||||
}
|
||||
|
@ -136,6 +142,8 @@ SrsBandwidth.prototype.on_srs_info = function(srs_server, srs_primary_authors, s
|
|||
}
|
||||
SrsBandwidth.prototype.on_complete = function(start_time, end_time, play_kbps, publish_kbps, play_bytes, publish_bytes, play_time, publish_time) {
|
||||
}
|
||||
SrsBandwidth.prototype.on_error = function(code) {
|
||||
}
|
||||
function __srs_find_bandwidth(id) {
|
||||
for (var i = 0; i < SrsBandwidth.__bandwidths.length; i++) {
|
||||
var bandwidth = SrsBandwidth.__bandwidths[i];
|
||||
|
@ -164,24 +172,36 @@ function __srs_on_update_status(id, code, data) {
|
|||
var status = "";
|
||||
switch(code){
|
||||
case "NetConnection.Connect.Failed":
|
||||
if (bandwidth.completed) {
|
||||
return;
|
||||
}
|
||||
bandwidth.on_error(code);
|
||||
status = "连接服务器失败!";
|
||||
break;
|
||||
case "NetConnection.Connect.Rejected":
|
||||
status = "服务器拒绝连接!";
|
||||
if (bandwidth.completed) {
|
||||
return;
|
||||
}
|
||||
bandwidth.completed = true;
|
||||
bandwidth.on_update_progress(100);
|
||||
bandwidth.on_error(code);
|
||||
status = "服务器拒绝连接,测速过于频繁!";
|
||||
break;
|
||||
case "NetConnection.Connect.Success":
|
||||
status = "连接服务器成功!";
|
||||
break;
|
||||
case "NetConnection.Connect.Closed":
|
||||
if (bandwidth.report) {
|
||||
if (bandwidth.completed) {
|
||||
return;
|
||||
}
|
||||
bandwidth.on_error(code);
|
||||
status = "连接已断开!";
|
||||
break;
|
||||
case "srs.bwtc.play.start":
|
||||
status = "开始测试下行带宽";
|
||||
break;
|
||||
case "srs.bwtc.play.stop":
|
||||
bandwidth.completed = true;
|
||||
status = "下行带宽测试完毕," + data + "kbps,开始测试上行带宽。";
|
||||
break;
|
||||
default:
|
||||
|
@ -202,7 +222,7 @@ function __srs_on_complete(id, start_time, end_time, play_kbps, publish_kbps, pl
|
|||
|
||||
var status = "检测结束: " + bandwidth.server + " 上行: " + publish_kbps + " kbps" + " 下行: " + play_kbps + " kbps"
|
||||
+ " 测试时间: " + Number((end_time - start_time) / 1000).toFixed(1) + " 秒";
|
||||
bandwidth.report = status;
|
||||
bandwidth.status = status;
|
||||
bandwidth.on_update_status(status);
|
||||
|
||||
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
|
|||
// reject the connection in the interval window.
|
||||
if (last_check_time > 0 && time_now - last_check_time < interval_ms) {
|
||||
ret = ERROR_SYSTEM_BANDWIDTH_DENIED;
|
||||
srs_trace("bandcheck denied, "
|
||||
srs_trace("reject, "
|
||||
"last_check=%"PRId64", now=%"PRId64", interval=%d",
|
||||
last_check_time, time_now, interval_ms);
|
||||
|
||||
|
|
|
@ -1866,20 +1866,20 @@ int SrsConfig::get_bw_check_interval_ms(const string &vhost)
|
|||
SrsConfDirective* conf = get_vhost(vhost);
|
||||
|
||||
if (!conf) {
|
||||
return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL;
|
||||
return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL * 1000;
|
||||
}
|
||||
|
||||
conf = conf->get("bandcheck");
|
||||
if (!conf) {
|
||||
return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL;
|
||||
return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL * 1000;
|
||||
}
|
||||
|
||||
conf = conf->get("interval_ms");
|
||||
conf = conf->get("interval");
|
||||
if (!conf) {
|
||||
return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL;
|
||||
return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL * 1000;
|
||||
}
|
||||
|
||||
return ::atoi(conf->arg0().c_str()) * 1000;
|
||||
return ::atof(conf->arg0().c_str()) * 1000;
|
||||
}
|
||||
|
||||
int SrsConfig::get_bw_check_limit_kbps(const string &vhost)
|
||||
|
|
|
@ -40,39 +40,39 @@ using namespace std;
|
|||
/**
|
||||
* the signature for packets to client.
|
||||
*/
|
||||
#define RTMP_SIG_FMS_VER "3,5,3,888"
|
||||
#define RTMP_SIG_AMF0_VER 0
|
||||
#define RTMP_SIG_CLIENT_ID "ASAICiss"
|
||||
#define RTMP_SIG_FMS_VER "3,5,3,888"
|
||||
#define RTMP_SIG_AMF0_VER 0
|
||||
#define RTMP_SIG_CLIENT_ID "ASAICiss"
|
||||
|
||||
/**
|
||||
* onStatus consts.
|
||||
*/
|
||||
#define StatusLevel "level"
|
||||
#define StatusCode "code"
|
||||
#define StatusDescription "description"
|
||||
#define StatusDetails "details"
|
||||
#define StatusClientId "clientid"
|
||||
#define StatusLevel "level"
|
||||
#define StatusCode "code"
|
||||
#define StatusDescription "description"
|
||||
#define StatusDetails "details"
|
||||
#define StatusClientId "clientid"
|
||||
// status value
|
||||
#define StatusLevelStatus "status"
|
||||
#define StatusLevelStatus "status"
|
||||
// status error
|
||||
#define StatusLevelError "error"
|
||||
#define StatusLevelError "error"
|
||||
// code value
|
||||
#define StatusCodeConnectSuccess "NetConnection.Connect.Success"
|
||||
#define StatusCodeConnectRejected "NetConnection.Connect.Rejected"
|
||||
#define StatusCodeStreamReset "NetStream.Play.Reset"
|
||||
#define StatusCodeStreamStart "NetStream.Play.Start"
|
||||
#define StatusCodeStreamPause "NetStream.Pause.Notify"
|
||||
#define StatusCodeStreamUnpause "NetStream.Unpause.Notify"
|
||||
#define StatusCodePublishStart "NetStream.Publish.Start"
|
||||
#define StatusCodeDataStart "NetStream.Data.Start"
|
||||
#define StatusCodeUnpublishSuccess "NetStream.Unpublish.Success"
|
||||
#define StatusCodeConnectSuccess "NetConnection.Connect.Success"
|
||||
#define StatusCodeConnectRejected "NetConnection.Connect.Rejected"
|
||||
#define StatusCodeStreamReset "NetStream.Play.Reset"
|
||||
#define StatusCodeStreamStart "NetStream.Play.Start"
|
||||
#define StatusCodeStreamPause "NetStream.Pause.Notify"
|
||||
#define StatusCodeStreamUnpause "NetStream.Unpause.Notify"
|
||||
#define StatusCodePublishStart "NetStream.Publish.Start"
|
||||
#define StatusCodeDataStart "NetStream.Data.Start"
|
||||
#define StatusCodeUnpublishSuccess "NetStream.Unpublish.Success"
|
||||
|
||||
// FMLE
|
||||
#define RTMP_AMF0_COMMAND_ON_FC_PUBLISH "onFCPublish"
|
||||
#define RTMP_AMF0_COMMAND_ON_FC_UNPUBLISH "onFCUnpublish"
|
||||
#define RTMP_AMF0_COMMAND_ON_FC_PUBLISH "onFCPublish"
|
||||
#define RTMP_AMF0_COMMAND_ON_FC_UNPUBLISH "onFCUnpublish"
|
||||
|
||||
// default stream id for response the createStream request.
|
||||
#define SRS_DEFAULT_SID 1
|
||||
#define SRS_DEFAULT_SID 1
|
||||
|
||||
SrsRequest::SrsRequest()
|
||||
{
|
||||
|
@ -910,12 +910,10 @@ void SrsRtmpServer::response_connect_reject(SrsRequest *req, const char* desc)
|
|||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
SrsConnectAppResPacket* pkt = new SrsConnectAppResPacket();
|
||||
pkt->command_name = "_error";
|
||||
pkt->props->set(StatusLevel, SrsAmf0Any::str(StatusLevelError));
|
||||
pkt->props->set(StatusCode, SrsAmf0Any::str(StatusCodeConnectRejected));
|
||||
pkt->props->set(StatusDescription, SrsAmf0Any::str(desc));
|
||||
//pkt->props->set("objectEncoding", SrsAmf0Any::number(req->objectEncoding));
|
||||
SrsOnStatusCallPacket* pkt = new SrsOnStatusCallPacket();
|
||||
pkt->data->set(StatusLevel, SrsAmf0Any::str(StatusLevelError));
|
||||
pkt->data->set(StatusCode, SrsAmf0Any::str(StatusCodeConnectRejected));
|
||||
pkt->data->set(StatusDescription, SrsAmf0Any::str(desc));
|
||||
|
||||
if ((ret = protocol->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) {
|
||||
srs_error("send connect app response rejected message failed. ret=%d", ret);
|
||||
|
|
Loading…
Reference in a new issue