Skip to content

Commit

Permalink
fix: Include text bandwidth in stats (#6109)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Jan 18, 2024
1 parent 216a13d commit 1f49e81
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
7 changes: 5 additions & 2 deletions lib/player.js
Expand Up @@ -4605,13 +4605,16 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
// variant yet because we set the load mode before we select the first
// variant to stream.
const variant = this.streamingEngine_.getCurrentVariant();
const textStream = this.streamingEngine_.getCurrentTextStream();

if (variant) {
const rate = this.playRateController_ ?
this.playRateController_.getRealRate() : 1;
const variantBandwidth = rate * variant.bandwidth;
// TODO: Should include text bandwidth if it enabled.
const currentStreamBandwidth = variantBandwidth;
let currentStreamBandwidth = variantBandwidth;
if (textStream && textStream.bandwidth) {
currentStreamBandwidth += (rate * textStream.bandwidth);
}
this.stats_.setCurrentStreamBandwidth(currentStreamBandwidth);
}

Expand Down
23 changes: 19 additions & 4 deletions test/player_unit.js
Expand Up @@ -2658,6 +2658,9 @@ describe('Player', () => {
variant.addExistingStream(1); // audio
variant.addExistingStream(2); // video
});
manifest.addTextStream(4, (stream) => {
stream.bandwidth = 10;
});
});

await player.load(fakeManifestUri, 0, fakeMimeType);
Expand All @@ -2674,11 +2677,15 @@ describe('Player', () => {
});

it('tracks info about current stream', () => {
const stats = player.getStats();
let stats = player.getStats();
// Should have chosen the first of each type of stream.
expect(stats.width).toBe(100);
expect(stats.height).toBe(200);
expect(stats.streamBandwidth).toBe(200);
const textTracks = player.getTextTracks();
player.selectTextTrack(textTracks[0]);
stats = player.getStats();
expect(stats.streamBandwidth).toBe(210);
});

it('tracks frame info', () => {
Expand Down Expand Up @@ -2793,18 +2800,26 @@ describe('Player', () => {
* @param {!Array.<shaka.extern.TrackChoice>} additional
*/
function checkHistory(additional) {
const prefix = {
const variantPrefix = {
timestamp: jasmine.any(Number),
id: 0,
type: 'variant',
fromAdaptation: true,
bandwidth: 200,
};

const textPrefix = {
timestamp: jasmine.any(Number),
id: 4,
type: 'text',
fromAdaptation: true,
bandwidth: null,
};
const switchHistory = player.getStats().switchHistory;

expect(switchHistory[0]).toEqual(prefix);
expect(switchHistory.slice(1)).toEqual(additional);
expect(switchHistory[0]).toEqual(variantPrefix);
expect(switchHistory[1]).toEqual(textPrefix);
expect(switchHistory.slice(2)).toEqual(additional);
}

/**
Expand Down

0 comments on commit 1f49e81

Please sign in to comment.