From dfecfb65b107cd7773e487a4171514e82b1702ec Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 20 Aug 2015 18:13:07 +0800 Subject: [PATCH] support fluency and stream empty count --- trunk/research/players/js/srs.player.js | 67 ++++++- trunk/research/players/js/winlin.utility.js | 2 +- trunk/research/players/srs_player.html | 167 ++++++++++-------- .../players/srs_player/release/srs_player.swf | Bin 5638 -> 6306 bytes .../players/srs_player/src/srs_player.as | 75 ++++++-- 5 files changed, 224 insertions(+), 87 deletions(-) diff --git a/trunk/research/players/js/srs.player.js b/trunk/research/players/js/srs.player.js index f04859ca9..91dea7f16 100755 --- a/trunk/research/players/js/srs.player.js +++ b/trunk/research/players/js/srs.player.js @@ -30,6 +30,32 @@ function SrsPlayer(container, width, height, private_object) { this.meatadata = {}; // for on_player_metadata this.time = 0; // current stream time. this.buffer_length = 0; // current stream buffer length. + this.kbps = 0; // current stream bitrate(video+audio) in kbps. + this.fps = 0; // current stream video fps. + this.rtime = 0; // flash relative time in ms. + + this.__fluency = { + total_empty_count: 0, + total_empty_time: 0, + current_empty_time: 0 + }; + this.__fluency.on_stream_empty = function(time) { + this.total_empty_count++; + this.current_empty_time = time; + }; + this.__fluency.on_stream_full = function(time) { + if (this.current_empty_time > 0) { + this.total_empty_time += time - this.current_empty_time; + this.current_empty_time = 0; + } + }; + this.__fluency.calc = function(time) { + var den = this.total_empty_count * 4 + this.total_empty_time * 2 + time; + if (den > 0) { + return time * 100 / den; + } + return 0; + }; } /** * user can set some callback, then start the player. @@ -49,6 +75,8 @@ SrsPlayer.prototype.start = function(url) { flashvars.on_player_ready = "__srs_on_player_ready"; flashvars.on_player_metadata = "__srs_on_player_metadata"; flashvars.on_player_timer = "__srs_on_player_timer"; + flashvars.on_player_empty = "__srs_on_player_empty"; + flashvars.on_player_full = "__srs_on_player_full"; var params = {}; params.wmode = "opaque"; @@ -112,6 +140,18 @@ SrsPlayer.prototype.pause = function() { SrsPlayer.prototype.resume = function() { this.callbackObj.ref.__resume(); } +/** + * get the stream fluency, where 100 is 100%. + */ +SrsPlayer.prototype.fluency = function() { + return this.__fluency.calc(this.rtime); +} +/** + * get the stream empty count. + */ +SrsPlayer.prototype.empty_count = function() { + return this.__fluency.total_empty_count; +} /** * to set the DAR, for example, DAR=16:9 where num=16,den=9. * @param num, for example, 16. @@ -148,7 +188,13 @@ SrsPlayer.prototype.on_player_ready = function() { SrsPlayer.prototype.on_player_metadata = function(metadata) { // ignore. } -SrsPlayer.prototype.on_player_timer = function(time, buffer_length) { +SrsPlayer.prototype.on_player_timer = function(time, buffer_length, kbps, fps, rtime) { + // ignore. +} +SrsPlayer.prototype.on_player_empty = function(time) { + // ignore. +} +SrsPlayer.prototype.on_player_full = function(time) { // ignore. } function __srs_find_player(id) { @@ -177,7 +223,7 @@ function __srs_on_player_metadata(id, metadata) { player.on_player_metadata(metadata); } -function __srs_on_player_timer(id, time, buffer_length) { +function __srs_on_player_timer(id, time, buffer_length, kbps, fps, rtime) { var player = __srs_find_player(id); buffer_length = Math.max(0, buffer_length); @@ -189,6 +235,19 @@ function __srs_on_player_timer(id, time, buffer_length) { // so set the data before invoke it. player.time = time; player.buffer_length = buffer_length; - - player.on_player_timer(time, buffer_length); + player.kbps = kbps; + player.fps = fps; + player.rtime = rtime; + + player.on_player_timer(time, buffer_length, kbps, fps, rtime); +} +function __srs_on_player_empty(id, time) { + var player = __srs_find_player(id); + player.__fluency.on_stream_empty(time); + player.on_player_empty(time); +} +function __srs_on_player_full(id, time) { + var player = __srs_find_player(id); + player.__fluency.on_stream_full(time); + player.on_player_full(time); } diff --git a/trunk/research/players/js/winlin.utility.js b/trunk/research/players/js/winlin.utility.js index 6bbc9329b..8eb6e3d94 100644 --- a/trunk/research/players/js/winlin.utility.js +++ b/trunk/research/players/js/winlin.utility.js @@ -5,7 +5,7 @@ * depends: jquery1.10 * https://code.csdn.net/snippets/147103 * @see: http://blog.csdn.net/win_lin/article/details/17994347 - * v 1.0.10 + * v 1.0.11 */ /** diff --git a/trunk/research/players/srs_player.html b/trunk/research/players/srs_player.html index f8392ab1c..34c1f90f3 100755 --- a/trunk/research/players/srs_player.html +++ b/trunk/research/players/srs_player.html @@ -12,7 +12,7 @@ margin-top: -20px; padding-top: 3px; } - #div_play_time { + .div_play_time { margin-top: 10px; } #pb_buffer_bg { @@ -47,7 +47,7 @@
URL: - +
@@ -281,57 +281,82 @@