Skip to content

Commit

Permalink
feat(Stats): add size of the manifest to player stats (#6783)
Browse files Browse the repository at this point in the history
  • Loading branch information
tykus160 authored Jun 10, 2024
1 parent 08e8111 commit d0d5843
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ shaka.extern.StateChange;
* gapsJumped: number,
* stallsDetected: number,
*
* manifestSizeBytes: number,
* bytesDownloaded: number,
*
* nonFatalErrorCount: number,
Expand Down Expand Up @@ -165,6 +166,10 @@ shaka.extern.StateChange;
* The presentation's max segment duration in seconds. If nothing is loaded,
* NaN.
*
* @property {number} manifestSizeBytes
* Size of the manifest payload. For DASH & MSS it will match the latest
* downloaded manifest. For HLS, it will match the lastly downloaded playlist.
* If nothing is loaded or in src= mode, NaN.
* @property {number} bytesDownloaded
* The bytes downloaded during the playback. If nothing is loaded, NaN.
*
Expand Down
3 changes: 3 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -3266,6 +3266,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
const stats = getStats();
if (stats) {
stats.addBytesDownloaded(bytesDownloaded);
if (type === shaka.net.NetworkingEngine.RequestType.MANIFEST) {
stats.setManifestSize(bytesDownloaded);
}
}
}
};
Expand Down
11 changes: 11 additions & 0 deletions lib/util/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ shaka.util.Stats = class {
/** @private {number} */
this.bandwidthEstimate_ = NaN;

/** @private {number} */
this.manifestSizeBytes_ = NaN;
/** @private {number} */
this.bytesDownloaded_ = NaN;

Expand Down Expand Up @@ -209,6 +211,13 @@ shaka.util.Stats = class {
this.bandwidthEstimate_ = bandwidth;
}

/**
* @param {number} size
*/
setManifestSize(size) {
this.manifestSizeBytes_ = size;
}

/**
* @param {number} bytesDownloaded
*/
Expand Down Expand Up @@ -266,6 +275,7 @@ shaka.util.Stats = class {
licenseTime: this.licenseTimeSeconds_,
liveLatency: this.liveLatencySeconds_,
maxSegmentDuration: this.maxSegmentDurationSeconds_,
manifestSizeBytes: this.manifestSizeBytes_,
bytesDownloaded: this.bytesDownloaded_,
nonFatalErrorCount: this.nonFatalErrorCount_,
stateHistory: this.stateHistory_.getCopy(),
Expand Down Expand Up @@ -300,6 +310,7 @@ shaka.util.Stats = class {
licenseTime: NaN,
liveLatency: NaN,
maxSegmentDuration: NaN,
manifestSizeBytes: NaN,
bytesDownloaded: NaN,
nonFatalErrorCount: NaN,
switchHistory: [],
Expand Down
1 change: 1 addition & 0 deletions test/player_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ describe('Player', () => {

maxSegmentDuration: jasmine.any(Number),

manifestSizeBytes: jasmine.any(Number),
bytesDownloaded: jasmine.any(Number),

nonFatalErrorCount: jasmine.any(Number),
Expand Down
5 changes: 3 additions & 2 deletions ui/statistics_button.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ shaka.ui.StatisticsButton = class extends shaka.ui.Element {
return this.currentStats_[name] + ' (errors)';
};

const parseBytesDownloaded = (name) => {
const parseBytes = (name) => {
const bytes = parseInt(this.currentStats_[name], 10);
if (bytes > 1e6) {
return (bytes / 1e6).toFixed(2) + 'MB';
Expand Down Expand Up @@ -153,7 +153,8 @@ shaka.ui.StatisticsButton = class extends shaka.ui.Element {
'droppedFrames': parseFrames,
'stallsDetected': parseStalls,
'gapsJumped': parseGaps,
'bytesDownloaded': parseBytesDownloaded,
'manifestSizeBytes': parseBytes,
'bytesDownloaded': parseBytes,
'nonFatalErrorCount': parseErrors,
};

Expand Down

0 comments on commit d0d5843

Please sign in to comment.