Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Include text bandwidth in stats #6109

Merged
merged 3 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -4628,13 +4628,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
Original file line number Diff line number Diff line change
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
Loading