1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

refine the bwtc, to compatible with bms4.

This commit is contained in:
winlin 2016-03-12 20:53:37 +08:00
parent eed4626c35
commit b3c13f2550
4 changed files with 79 additions and 26 deletions

View file

@ -38,3 +38,4 @@
<buildCSSFiles/> <buildCSSFiles/>
<flashCatalyst validateFlashCatalystCompatibility="false"/> <flashCatalyst validateFlashCatalystCompatibility="false"/>
</actionScriptProperties> </actionScriptProperties>

View file

@ -25,6 +25,7 @@ package
import flash.events.NetStatusEvent; import flash.events.NetStatusEvent;
import flash.external.ExternalInterface; import flash.external.ExternalInterface;
import flash.net.NetConnection; import flash.net.NetConnection;
import flash.net.NetStream;
import flash.net.ObjectEncoding; import flash.net.ObjectEncoding;
import flash.utils.clearTimeout; import flash.utils.clearTimeout;
import flash.utils.setTimeout; import flash.utils.setTimeout;
@ -92,7 +93,7 @@ package
* srs_server: the srs server info. * srs_server: the srs server info.
* srs_primary: the srs primary authors info. * srs_primary: the srs primary authors info.
* srs_authors: the srs authors info. * srs_authors: the srs authors info.
* srs_id: the tracable log id, to direclty grep the log.. * srs_id: the tracable log id, to direclty grep the log.
* srs_pid: the srs process id, to direclty grep the log. * srs_pid: the srs process id, to direclty grep the log.
* srs_server_ip: the srs server ip, where client connected at. * srs_server_ip: the srs server ip, where client connected at.
* @param as_on_complete, function(start_time:Number, end_time:Number, play_kbps:Number, publish_kbps:Number, play_bytes:Number, publish_bytes:Number, play_time:Number, publish_time:Number):void, where * @param as_on_complete, function(start_time:Number, end_time:Number, play_kbps:Number, publish_kbps:Number, play_bytes:Number, publish_bytes:Number, play_time:Number, publish_time:Number):void, where
@ -280,6 +281,8 @@ package
* check/test with server. * check/test with server.
*/ */
private var connection:NetConnection = null; private var connection:NetConnection = null;
// for bms4, use stream to play then do bandwidth test.
private var stream:NetStream = null;
/** /**
* use timeout to sendout publish call packets. * use timeout to sendout publish call packets.
@ -293,7 +296,7 @@ package
*/ */
private function system_on_js_ready():void { private function system_on_js_ready():void {
if (!flash.external.ExternalInterface.available) { if (!flash.external.ExternalInterface.available) {
trace("js not ready, try later."); log("js not ready, try later.");
flash.utils.setTimeout(this.system_on_js_ready, 100); flash.utils.setTimeout(this.system_on_js_ready, 100);
return; return;
} }
@ -318,6 +321,7 @@ package
__on_progress_change(0); __on_progress_change(0);
// init connection // init connection
log("create connection for bandwidth check");
connection = new NetConnection; connection = new NetConnection;
connection.objectEncoding = ObjectEncoding.AMF0; connection.objectEncoding = ObjectEncoding.AMF0;
connection.client = { connection.client = {
@ -350,7 +354,7 @@ package
private function onSrsBandCheckStartPlayBytes(evt:Object):void{ private function onSrsBandCheckStartPlayBytes(evt:Object):void{
var duration_ms:Number = evt.duration_ms; var duration_ms:Number = evt.duration_ms;
var interval_ms:Number = evt.interval_ms; var interval_ms:Number = evt.interval_ms;
trace("start play test, duration=" + duration_ms + ", interval=" + interval_ms); log("start play test, duration=" + duration_ms + ", interval=" + interval_ms);
connection.call("onSrsBandCheckStartingPlayBytes", null); connection.call("onSrsBandCheckStartingPlayBytes", null);
__on_status_change(SrsBandwidth.StatusSrsBwtcPlayStart); __on_status_change(SrsBandwidth.StatusSrsBwtcPlayStart);
@ -482,8 +486,9 @@ package
* get NetConnection NetStatusEvent * get NetConnection NetStatusEvent
*/ */
private function onStatus(evt:NetStatusEvent): void { private function onStatus(evt:NetStatusEvent): void {
trace(evt.info.code); log(evt.info.code);
var srs_version:String = null;
if (evt.info.hasOwnProperty("data") && evt.info.data) { if (evt.info.hasOwnProperty("data") && evt.info.data) {
if (evt.info.data.hasOwnProperty("srs_server")) { if (evt.info.data.hasOwnProperty("srs_server")) {
srs_server = evt.info.data.srs_server; srs_server = evt.info.data.srs_server;
@ -503,6 +508,9 @@ package
if (evt.info.data.hasOwnProperty("srs_server_ip")) { if (evt.info.data.hasOwnProperty("srs_server_ip")) {
srs_server_ip = evt.info.data.srs_server_ip; srs_server_ip = evt.info.data.srs_server_ip;
} }
if (evt.info.data.hasOwnProperty("srs_version")) {
srs_version = evt.info.data.srs_version;
}
if (this.as_on_srs_info != null) { if (this.as_on_srs_info != null) {
this.as_on_srs_info(srs_server, srs_primary, srs_authors, srs_id, srs_pid, srs_server_ip); this.as_on_srs_info(srs_server, srs_primary, srs_authors, srs_id, srs_pid, srs_server_ip);
@ -511,16 +519,46 @@ package
flash.external.ExternalInterface.call(this.js_on_srs_info, this.js_id, flash.external.ExternalInterface.call(this.js_on_srs_info, this.js_id,
srs_server, srs_primary, srs_authors, srs_id, srs_pid, srs_server_ip); srs_server, srs_primary, srs_authors, srs_id, srs_pid, srs_server_ip);
} }
} }
if (evt.info.code) {
__on_status_change(evt.info.code); var e:NetStatusEvent = evt;
} var foo:Function = function():void{
switch(evt.info.code){ var evt:NetStatusEvent = e;
case "NetConnection.Connect.Success": if (evt.info.code) {
__on_progress_change(8); __on_status_change(evt.info.code);
break; }
} switch(evt.info.code){
case "NetConnection.Connect.Success":
__on_progress_change(8);
break;
}
};
foo();
// for bms4, play stream to trigger the bandwidth check.
if (evt.info.code != "NetConnection.Connect.Success") {
return;
}
if (stream != null) {
return;
}
var is_bms:Boolean = false;
if (srs_server.indexOf("BMS/") == 0 || srs_server.indexOf("UPYUN/") == 0) {
is_bms = true;
}
if (parseInt(srs_version.charAt(0)) >= 4 && is_bms) {
stream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void{
log(evt.info.code);
if (evt.info.code == "NetStream.Play.Start") {
}
});
stream.play("test");
log("play stream for " + srs_server + " " + srs_version);
return;
}
} }
/** /**
@ -544,5 +582,12 @@ package
code, data); code, data);
} }
} }
private function log(msg:String):void {
trace(msg);
if (ExternalInterface.available) {
ExternalInterface.call("console.log", msg);
}
}
} }
} }

View file

@ -121,13 +121,13 @@ package
// for directly run swf. // for directly run swf.
if (!conf.id) { if (!conf.id) {
trace("directly run swf, load default url: " + this.default_url); log("directly run swf, load default url: " + this.default_url);
this.bandwidth.check_bandwidth(this.default_url); this.bandwidth.check_bandwidth(this.default_url);
} }
} }
private function on_progress(percent:Number):void { private function on_progress(percent:Number):void {
trace("progress:" + percent + "%"); log("progress:" + percent + "%");
} }
private function update_context_items( private function update_context_items(
srs_server:String, srs_primary:String, srs_authors:String, srs_server:String, srs_primary:String, srs_authors:String,
@ -156,31 +156,31 @@ package
contextMenu.customItems = customItems; contextMenu.customItems = customItems;
} }
public function on_status_change(code:String, data:String): void { public function on_status_change(code:String, data:String): void {
trace(code); log(code);
switch(code){ switch(code){
case "NetConnection.Connect.Failed": case "NetConnection.Connect.Failed":
trace("连接服务器失败!"); log("连接服务器失败!");
break; break;
case "NetConnection.Connect.Rejected": case "NetConnection.Connect.Rejected":
trace("服务器拒绝连接!"); log("服务器拒绝连接!");
break; break;
case "NetConnection.Connect.Success": case "NetConnection.Connect.Success":
trace("连接服务器成功!"); log("连接服务器成功!");
break; break;
case SrsBandwidth.StatusSrsBwtcPlayStart: case SrsBandwidth.StatusSrsBwtcPlayStart:
trace("开始测试下行带宽"); log("开始测试下行带宽");
break; break;
case SrsBandwidth.StatusSrsBwtcPlayStop: case SrsBandwidth.StatusSrsBwtcPlayStop:
trace("下行带宽测试完毕," + data + "kbps开始测试上行带宽。"); log("下行带宽测试完毕," + data + "kbps开始测试上行带宽。");
break; break;
case SrsBandwidth.StatusSrsBwtcPublishStart: case SrsBandwidth.StatusSrsBwtcPublishStart:
trace("开始测试上行带宽"); log("开始测试上行带宽");
break; break;
case SrsBandwidth.StatusSrsBwtcPublishStop: case SrsBandwidth.StatusSrsBwtcPublishStop:
trace("上行带宽测试完毕," + data + "kbps"); log("上行带宽测试完毕," + data + "kbps");
break; break;
case "NetConnection.Connect.Closed": case "NetConnection.Connect.Closed":
trace("连接已断开!"); log("连接已断开!");
break; break;
} }
} }
@ -190,7 +190,14 @@ package
):void { ):void {
var status:String = "检测结束: 上行: " + publish_kbps + " kbps" + " 下行: " + play_kbps + " kbps" var status:String = "检测结束: 上行: " + publish_kbps + " kbps" + " 下行: " + play_kbps + " kbps"
+ " 测试时间: " + Number((end_time - start_time) / 1000).toFixed(1) + " 秒"; + " 测试时间: " + Number((end_time - start_time) / 1000).toFixed(1) + " 秒";
trace(status); log(status);
} }
private function log(msg:String):void {
trace(msg);
if (ExternalInterface.available) {
ExternalInterface.call("console.log", msg);
}
}
} }
} }