Skip to content

Commit cbcba99

Browse files
aveladtykus160
andauthored
feat(Stats): Add current codecs to stats (#8418)
Co-authored-by: Wojciech Tyczyński <[email protected]>
1 parent 46c998d commit cbcba99

File tree

6 files changed

+39
-2
lines changed

6 files changed

+39
-2
lines changed

externs/shaka/player.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ shaka.extern.StateChange;
6464
* width: number,
6565
* height: number,
6666
* streamBandwidth: number,
67+
* currentCodecs: string,
6768
*
6869
* decodedFrames: number,
6970
* droppedFrames: number,
@@ -111,6 +112,8 @@ shaka.extern.StateChange;
111112
* @property {number} streamBandwidth
112113
* The bandwidth required for the current streams (total, in bit/sec).
113114
* It takes into account the playbackrate. If nothing is loaded, NaN.
115+
* @property {string} currentCodecs
116+
* The current codec of the current streams.
114117
*
115118
* @property {number} decodedFrames
116119
* The total number of frames decoded by the Player. If not reported by the

lib/player.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6438,6 +6438,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
64386438
/* width= */ element.videoWidth || NaN,
64396439
/* height= */ element.videoHeight || NaN);
64406440

6441+
this.stats_.setCodecs('');
6442+
64416443
if (this.isLive()) {
64426444
// Apple's native HLS gives us getStartDate(), which is only available
64436445
// if EXT-X-PROGRAM-DATETIME is in the playlist.
@@ -6467,6 +6469,13 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
64676469
/* width= */ variant.width || NaN,
64686470
/* height= */ variant.height || NaN);
64696471
}
6472+
let codecs = variant.codecs;
6473+
if (textTrack) {
6474+
codecs += ',' + (textTrack.codecs || textTrack.mimeType);
6475+
}
6476+
if (codecs) {
6477+
this.stats_.setCodecs(codecs);
6478+
}
64706479
}
64716480

64726481
if (this.loadMode_ == shaka.Player.LoadMode.MEDIA_SOURCE &&

lib/util/stats.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ shaka.util.Stats = class {
2424
/** @private {number} */
2525
this.height_ = NaN;
2626

27+
/** @private {string} */
28+
this.currentCodecs_ = '';
29+
2730
/** @private {number} */
2831
this.totalDroppedFrames_ = NaN;
2932
/** @private {number} */
@@ -132,6 +135,15 @@ shaka.util.Stats = class {
132135
this.height_ = height;
133136
}
134137

138+
/**
139+
* Set the codecs that we are currently playing.
140+
*
141+
* @param {string} codecs
142+
*/
143+
setCodecs(codecs) {
144+
this.currentCodecs_ = codecs;
145+
}
146+
135147
/**
136148
* Record the time it took between the user signalling "I want to play this"
137149
* to "I am now seeing this".
@@ -276,6 +288,7 @@ shaka.util.Stats = class {
276288
return {
277289
width: this.width_,
278290
height: this.height_,
291+
currentCodecs: this.currentCodecs_,
279292
streamBandwidth: this.currentStreamBandwidth_,
280293
decodedFrames: this.totalDecodedFrames_,
281294
droppedFrames: this.totalDroppedFrames_,
@@ -313,6 +326,7 @@ shaka.util.Stats = class {
313326
return {
314327
width: NaN,
315328
height: NaN,
329+
currentCodecs: '',
316330
streamBandwidth: NaN,
317331
decodedFrames: NaN,
318332
droppedFrames: NaN,

test/player_integration.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ describe('Player', () => {
242242
width: jasmine.any(Number),
243243
height: jasmine.any(Number),
244244
streamBandwidth: jasmine.any(Number),
245+
currentCodecs: jasmine.any(String),
245246

246247
decodedFrames: jasmine.any(Number),
247248
droppedFrames: jasmine.any(Number),

ui/statistics_button.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ shaka.ui.StatisticsButton = class extends shaka.ui.Element {
8989
return this.currentStats_[name] + ' (px)';
9090
};
9191

92+
const parseString = (name) => {
93+
return this.currentStats_[name];
94+
};
95+
9296
const parsePercent = (name) => {
9397
return this.currentStats_[name] + ' (%)';
9498
};
@@ -143,6 +147,7 @@ shaka.ui.StatisticsButton = class extends shaka.ui.Element {
143147
this.parseFrom_ = new Map()
144148
.set('width', parsePx)
145149
.set('height', parsePx)
150+
.set('currentCodecs', parseString)
146151
.set('completionPercent', parsePercent)
147152
.set('bufferingTime', parseSeconds)
148153
.set('drmTimeSeconds', parseSeconds)
@@ -276,8 +281,12 @@ shaka.ui.StatisticsButton = class extends shaka.ui.Element {
276281
const element = this.displayedElements_.get(name);
277282
element.textContent = this.parseFrom_.get(name)(name);
278283
if (element && element.parentElement) {
279-
shaka.ui.Utils.setDisplay(element.parentElement,
280-
!isNaN(this.currentStats_[name]));
284+
const value = this.currentStats_[name];
285+
if (typeof value == 'string') {
286+
shaka.ui.Utils.setDisplay(element.parentElement, value != '');
287+
} else {
288+
shaka.ui.Utils.setDisplay(element.parentElement, !isNaN(value));
289+
}
281290
}
282291
}
283292
}

ui/ui.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ shaka.ui.Overlay = class {
272272
statisticsList: [
273273
'width',
274274
'height',
275+
'currentCodecs',
275276
'corruptedFrames',
276277
'decodedFrames',
277278
'droppedFrames',

0 commit comments

Comments
 (0)