@@ -26,8 +26,7 @@ MediaPlayer.rules.DownloadRatioRule = function() {
2626 name : "DownloadRatioRule" ,
2727
2828 checkIndex : function ( current , metrics , data ) {
29- var self = this ,
30- requests = self . metricsExt . getHttpRequests ( metrics ) ,
29+ var requests = this . metricsExt . getHttpRequests ( metrics ) ,
3130 lastRequest = null ,
3231 downloadTime ,
3332 totalTime ,
@@ -44,13 +43,13 @@ MediaPlayer.rules.DownloadRatioRule = function() {
4443 p = MediaPlayer . rules . SwitchRequest . prototype . DEFAULT ;
4544
4645 if ( data && data . hasOwnProperty ( 'type' ) ) {
47- latencyInBandwidth = self . config . getParamFor ( data . type , "ABR.latencyInBandwidth" , "boolean" , true ) ;
48- switchUpRatioSafetyFactor = self . config . getParamFor ( data . type , "ABR.switchUpRatioSafetyFactor" , "number" , 1.5 ) ;
49- //self .debug.log("Checking download ratio rule...");
50- self . debug . log ( "[DownloadRatioRule][" + data . type + "] Checking download ratio rule... (current = " + current + ")" ) ;
46+ latencyInBandwidth = this . config . getParamFor ( data . type , "ABR.latencyInBandwidth" , "boolean" , true ) ;
47+ switchUpRatioSafetyFactor = this . config . getParamFor ( data . type , "ABR.switchUpRatioSafetyFactor" , "number" , 1.5 ) ;
48+ //this .debug.log("Checking download ratio rule...");
49+ this . debug . log ( "[DownloadRatioRule][" + data . type + "] Checking download ratio rule... (current = " + current + ")" ) ;
5150
5251 if ( ! metrics ) {
53- self . debug . log ( "[DownloadRatioRule][" + data . type + "] No metrics, bailing." ) ;
52+ this . debug . log ( "[DownloadRatioRule][" + data . type + "] No metrics, bailing." ) ;
5453 return new MediaPlayer . rules . SwitchRequest ( ) ;
5554 }
5655
@@ -64,38 +63,40 @@ MediaPlayer.rules.DownloadRatioRule = function() {
6463 }
6564
6665 if ( lastRequest === null ) {
67- self . debug . log ( "[DownloadRatioRule][" + data . type + "] No valid requests made for this stream yet, bailing." ) ;
66+ this . debug . log ( "[DownloadRatioRule][" + data . type + "] No valid requests made for this stream yet, bailing." ) ;
6867 return new MediaPlayer . rules . SwitchRequest ( ) ;
6968 }
7069
7170 totalTime = ( lastRequest . tfinish . getTime ( ) - lastRequest . trequest . getTime ( ) ) / 1000 ;
7271 downloadTime = ( lastRequest . tfinish . getTime ( ) - lastRequest . tresponse . getTime ( ) ) / 1000 ;
7372
7473 if ( totalTime <= 0 ) {
75- self . debug . log ( "[DownloadRatioRule][" + data . type + "] Don't know how long the download of the last fragment took, bailing." ) ;
74+ this . debug . log ( "[DownloadRatioRule][" + data . type + "] Don't know how long the download of the last fragment took, bailing." ) ;
7675 return new MediaPlayer . rules . SwitchRequest ( ) ;
7776 }
7877
7978 if ( lastRequest . mediaduration === null ||
8079 lastRequest . mediaduration === undefined ||
8180 lastRequest . mediaduration <= 0 ||
8281 isNaN ( lastRequest . mediaduration ) ) {
83- self . debug . log ( "[DownloadRatioRule][" + data . type + "] Don't know the duration of the last media fragment, bailing." ) ;
82+ this . debug . log ( "[DownloadRatioRule][" + data . type + "] Don't know the duration of the last media fragment, bailing." ) ;
8483 return new MediaPlayer . rules . SwitchRequest ( ) ;
8584 }
8685
87- self . debug . log ( "[DownloadRatioRule][" + data . type + "] DL: " + Number ( downloadTime . toFixed ( 3 ) ) + "s, Total: " + Number ( totalTime . toFixed ( 3 ) ) + "s" ) ;
88-
8986 totalBytesLength = lastRequest . bytesLength ;
9087
88+ this . debug . log ( "[DownloadRatioRule][" + data . type + "] DL: " + Number ( downloadTime . toFixed ( 3 ) ) + "s, Total: " + Number ( totalTime . toFixed ( 3 ) ) + "s, Length: " + totalBytesLength ) ;
89+
9190 // Take average bandwidth over 3 requests
9291 count = 1 ;
9392 while ( i >= 0 && count < 3 ) {
9493 if ( requests [ i ] . tfinish && requests [ i ] . trequest && requests [ i ] . tresponse && requests [ i ] . bytesLength > 0 ) {
95- self . debug . log ( "[DownloadRatioRule][" + data . type + "] length: " + requests [ i ] . bytesLength + ", time: " + ( ( requests [ i ] . tfinish . getTime ( ) - requests [ i ] . trequest . getTime ( ) ) / 1000 ) ) ;
94+ var _totalTime = ( requests [ i ] . tfinish . getTime ( ) - requests [ i ] . trequest . getTime ( ) ) / 1000 ;
95+ var _downloadTime = ( requests [ i ] . tfinish . getTime ( ) - requests [ i ] . tresponse . getTime ( ) ) / 1000 ;
96+ this . debug . log ( "[DownloadRatioRule][" + data . type + "] DL: " + Number ( _downloadTime . toFixed ( 3 ) ) + "s, Total: " + Number ( _totalTime . toFixed ( 3 ) ) + "s, Length: " + requests [ i ] . bytesLength ) ;
97+ totalTime += _totalTime ;
98+ downloadTime += _downloadTime ;
9699 totalBytesLength += requests [ i ] . bytesLength ;
97- totalTime += ( requests [ i ] . tfinish . getTime ( ) - requests [ i ] . trequest . getTime ( ) ) / 1000 ;
98- downloadTime += ( requests [ i ] . tfinish . getTime ( ) - requests [ i ] . tresponse . getTime ( ) ) / 1000 ;
99100 count += 1 ;
100101 }
101102 i -- ;
@@ -106,17 +107,17 @@ MediaPlayer.rules.DownloadRatioRule = function() {
106107
107108 calculatedBandwidth = latencyInBandwidth ? ( totalBytesLength / totalTime ) : ( totalBytesLength / downloadTime ) ;
108109
109- self . debug . log ( "[DownloadRatioRule][" + data . type + "] BW = " + Math . round ( calculatedBandwidth / 1000 ) + " kb/s" ) ;
110+ this . debug . log ( "[DownloadRatioRule][" + data . type + "] BW = " + Math . round ( calculatedBandwidth / 1000 ) + " kb/s" ) ;
110111
111112 if ( isNaN ( calculatedBandwidth ) ) {
112113 return new MediaPlayer . rules . SwitchRequest ( ) ;
113114 }
114115
115- count = self . manifestExt . getRepresentationCount ( data ) ;
116- currentRepresentation = self . manifestExt . getRepresentationFor ( current , data ) ;
117- currentBandwidth = self . manifestExt . getBandwidth ( currentRepresentation ) ;
116+ count = this . manifestExt . getRepresentationCount ( data ) ;
117+ currentRepresentation = this . manifestExt . getRepresentationFor ( current , data ) ;
118+ currentBandwidth = this . manifestExt . getBandwidth ( currentRepresentation ) ;
118119 for ( i = 0 ; i < count ; i += 1 ) {
119- bandwidths . push ( self . manifestExt . getRepresentationBandwidth ( data , i ) ) ;
120+ bandwidths . push ( this . manifestExt . getRepresentationBandwidth ( data , i ) ) ;
120121 }
121122 if ( calculatedBandwidth <= currentBandwidth ) {
122123 for ( i = current - 1 ; i > 0 ; i -= 1 ) {
@@ -127,20 +128,20 @@ MediaPlayer.rules.DownloadRatioRule = function() {
127128 q = i ;
128129 p = MediaPlayer . rules . SwitchRequest . prototype . WEAK ;
129130
130- self . debug . info ( "[DownloadRatioRule][" + data . type + "] SwitchRequest: q=" + q + "/" + ( count - 1 ) + " (" + bandwidths [ q ] + "), p=" + p ) ;
131+ this . debug . info ( "[DownloadRatioRule][" + data . type + "] SwitchRequest: q=" + q + "/" + ( count - 1 ) + " (" + bandwidths [ q ] + "), p=" + p ) ;
131132 return new MediaPlayer . rules . SwitchRequest ( q , p ) ;
132133 } else {
133134 for ( i = count - 1 ; i > current ; i -= 1 ) {
134135 if ( calculatedBandwidth > ( bandwidths [ i ] * switchUpRatioSafetyFactor ) ) {
135- //self .debug.log("[DownloadRatioRule][" + data.type + "] bw = " + calculatedBandwidth + " results[i] * switchUpRatioSafetyFactor =" + (bandwidths[i] * switchUpRatioSafetyFactor) + " with i=" + i);
136+ //this .debug.log("[DownloadRatioRule][" + data.type + "] bw = " + calculatedBandwidth + " results[i] * switchUpRatioSafetyFactor =" + (bandwidths[i] * switchUpRatioSafetyFactor) + " with i=" + i);
136137 break ;
137138 }
138139 }
139140
140141 q = i ;
141142 p = MediaPlayer . rules . SwitchRequest . prototype . STRONG ;
142143
143- self . debug . info ( "[DownloadRatioRule][" + data . type + "] SwitchRequest: q=" + q + "/" + ( count - 1 ) + " (" + bandwidths [ q ] + "), p=" + p ) ;
144+ this . debug . info ( "[DownloadRatioRule][" + data . type + "] SwitchRequest: q=" + q + "/" + ( count - 1 ) + " (" + bandwidths [ q ] + "), p=" + p ) ;
144145 return new MediaPlayer . rules . SwitchRequest ( q , p ) ;
145146 }
146147 } else {
0 commit comments