@@ -44,10 +44,17 @@ function DashMetrics(config) {
4444 let dashManifestModel = config . dashManifestModel ;
4545 let manifestModel = config . manifestModel ;
4646
47+ function getPeriod ( periodId ) {
48+ const manifest = manifestModel . getValue ( ) ;
49+ if ( ! manifest ) {
50+ return - 1 ;
51+ }
52+ return manifest . Period_asArray [ periodId ] ;
53+ }
54+
4755 function getBandwidthForRepresentation ( representationId , periodId ) {
4856 let representation ;
49- const manifest = manifestModel . getValue ( ) ;
50- let period = manifest . Period_asArray [ periodId ] ;
57+ let period = getPeriod ( periodId ) ;
5158
5259 representation = findRepresentation ( period , representationId ) ;
5360
@@ -58,20 +65,16 @@ function DashMetrics(config) {
5865 return representation . bandwidth ;
5966 }
6067
61-
6268 /**
6369 *
6470 * @param {string } representationId
6571 * @param {number } periodIdx
6672 * @returns {* }
6773 */
6874 function getIndexForRepresentation ( representationId , periodIdx ) {
69- let representationIndex ;
70- const manifest = manifestModel . getValue ( ) ;
71- let period = manifest . Period_asArray [ periodIdx ] ;
75+ let period = getPeriod ( periodIdx ) ;
7276
73- representationIndex = findRepresentationIndex ( period , representationId ) ;
74- return representationIndex ;
77+ return findRepresentationIndex ( period , representationId ) ;
7578 }
7679
7780 /**
@@ -84,15 +87,9 @@ function DashMetrics(config) {
8487 * @instance
8588 */
8689 function getMaxIndexForBufferType ( bufferType , periodIdx ) {
87- let maxIndex ;
88- const manifest = manifestModel . getValue ( ) ;
89- if ( ! manifest ) {
90- return - 1 ;
91- }
92- let period = manifest . Period_asArray [ periodIdx ] ;
90+ let period = getPeriod ( periodIdx ) ;
9391
94- maxIndex = findMaxBufferIndex ( period , bufferType ) ;
95- return maxIndex ;
92+ return findMaxBufferIndex ( period , bufferType ) ;
9693 }
9794
9895 /**
0 commit comments