From c319cc6a40cc07abbe0dc50d2af92c194a0b5648 Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 12 Jul 2014 20:48:03 +0800 Subject: [PATCH] refine bandwidth test client, provides js and as library --- trunk/research/players/js/srs.bandwidth.js | 57 +- trunk/research/players/srs_bwt.html | 12 +- .../players/srs_bwt/release/srs_bwt.swf | Bin 4940 -> 6511 bytes .../srs_bwt/src/SrsClass/SrsElapsedTimer.as | 24 - .../srs_bwt/src/SrsClass/SrsSettings.as | 27 - .../players/srs_bwt/src/srs/SrsBandwidth.as | 502 ++++++++++++++++++ trunk/research/players/srs_bwt/src/srs_bwt.as | 361 ++++--------- trunk/src/app/srs_app_bandwidth.cpp | 37 +- trunk/src/app/srs_app_bandwidth.hpp | 8 +- trunk/src/app/srs_app_conn.cpp | 2 +- trunk/src/rtmp/srs_protocol_stack.cpp | 2 +- trunk/src/rtmp/srs_protocol_stack.hpp | 4 +- 12 files changed, 700 insertions(+), 336 deletions(-) delete mode 100755 trunk/research/players/srs_bwt/src/SrsClass/SrsElapsedTimer.as delete mode 100755 trunk/research/players/srs_bwt/src/SrsClass/SrsSettings.as create mode 100755 trunk/research/players/srs_bwt/src/srs/SrsBandwidth.as diff --git a/trunk/research/players/js/srs.bandwidth.js b/trunk/research/players/js/srs.bandwidth.js index 1b63b2ac8..759960ebe 100755 --- a/trunk/research/players/js/srs.bandwidth.js +++ b/trunk/research/players/js/srs.bandwidth.js @@ -27,6 +27,8 @@ function SrsBandwidth(container, width, height, private_object) { // the callback set data. this.percent = 0; this.status = ""; + this.report = ""; + this.server = ""; } /** * user can set some callback, then start the bandwidth. @@ -38,7 +40,7 @@ function SrsBandwidth(container, width, height, private_object) { * on_update_status(status:String):void, when srs bandwidth update the status. * status:String the human readable status text. */ -SrsBandwidth.prototype.start = function(url) { +SrsBandwidth.prototype.render = function(url) { if (url) { this.stream_url = url; } @@ -49,6 +51,8 @@ SrsBandwidth.prototype.start = function(url) { flashvars.on_bandwidth_ready = "__srs_on_bandwidth_ready"; flashvars.on_update_progress = "__srs_on_update_progress"; flashvars.on_update_status = "__srs_on_update_status"; + flashvars.on_srs_info = "__srs_on_srs_info"; + flashvars.on_complete = "__srs_on_complete"; var params = {}; params.wmode = "opaque"; @@ -75,7 +79,6 @@ SrsBandwidth.prototype.start = function(url) { /** * play the stream. * @param stream_url the url of stream, rtmp or http. -* @param volume the volume, 0 is mute, 1 is 100%, 2 is 200%. */ SrsBandwidth.prototype.check_bandwidth = function(url) { this.stop(); @@ -107,6 +110,10 @@ SrsBandwidth.prototype.on_update_progress = function(percent) { } SrsBandwidth.prototype.on_update_status = function(status) { } +SrsBandwidth.prototype.on_srs_info = function(srs_server, srs_primary_authors, srs_id, srs_pid, srs_server_ip) { +} +SrsBandwidth.prototype.on_complete = function(start_time, end_time, play_kbps, publish_kbps, play_bytes, publish_bytes, play_time, publish_time) { +} function __srs_find_bandwidth(id) { for (var i = 0; i < SrsBandwidth.__bandwidths.length; i++) { var bandwidth = SrsBandwidth.__bandwidths[i]; @@ -129,8 +136,52 @@ function __srs_on_update_progress(id, percent) { bandwidth.percent = percent; bandwidth.on_update_progress(percent); } -function __srs_on_update_status(id, status) { +function __srs_on_update_status(id, code, data) { var bandwidth = __srs_find_bandwidth(id); + + var status = ""; + switch(code){ + case "NetConnection.Connect.Failed": + status = "连接服务器失败!"; + break; + case "NetConnection.Connect.Rejected": + status = "服务器拒绝连接!"; + break; + case "NetConnection.Connect.Success": + status = "连接服务器成功!"; + break; + case "NetConnection.Connect.Closed": + if (bandwidth.report) { + return; + } + status = "连接已断开!"; + break; + case "srs.bwtc.play.start": + status = "开始测试下行带宽"; + break; + case "srs.bwtc.play.stop": + status = "下行带宽测试完毕," + data + "kbps,开始测试上行带宽。"; + break; + default: + return; + } + bandwidth.status = status; bandwidth.on_update_status(status); +} +function __srs_on_srs_info(id, srs_server, srs_primary_authors, srs_id, srs_pid, srs_server_ip) { + var bandwidth = __srs_find_bandwidth(id); + bandwidth.status = status; + bandwidth.server = srs_server_ip; + bandwidth.on_srs_info(srs_server, srs_primary_authors, srs_id, srs_pid, srs_server_ip); +} +function __srs_on_complete(id, start_time, end_time, play_kbps, publish_kbps, play_bytes, publish_bytes, play_time, publish_time) { + var bandwidth = __srs_find_bandwidth(id); + + var status = "检测结束: " + bandwidth.server + " 上行: " + publish_kbps + " kbps" + " 下行: " + play_kbps + " kbps" + + " 测试时间: " + Number((end_time - start_time) / 1000).toFixed(1) + " 秒"; + bandwidth.report = 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); } \ No newline at end of file diff --git a/trunk/research/players/srs_bwt.html b/trunk/research/players/srs_bwt.html index dc2593adb..25f41a1f6 100644 --- a/trunk/research/players/srs_bwt.html +++ b/trunk/research/players/srs_bwt.html @@ -35,6 +35,7 @@ function on_click_play() { $("#check_status").text(""); + $("#check_info").text(""); $("#progress_bar").width("0%"); $("#main_modal").modal({show:true, keyboard:false}); } @@ -61,7 +62,13 @@ bandwidth.on_update_status = function(status) { $("#check_status").text(status); } - bandwidth.start(url); + bandwidth.on_srs_info = function(srs_server, srs_primary_authors, srs_id, srs_pid, srs_server_ip) { + $("#check_info").text( + "server:" + srs_server + ", authors:" + srs_primary_authors + + ", srs_id:" + srs_id + ", srs_pid:" + srs_pid + ", ip:" + srs_server_ip + ); + } + bandwidth.render(url); } function on_stop_bandwidth_test() { bandwidth.stop(); @@ -112,7 +119,8 @@
- status +
status
+
info