From 4823dfefea0c497adca145e50fe4500d16fc4b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Thu, 18 Jan 2024 07:28:06 +0100 Subject: [PATCH] fix: Include text bandwidth in stats (#6109) --- lib/player.js | 7 +++++-- test/player_unit.js | 23 +++++++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/player.js b/lib/player.js index 2cb6d363b1..caaf67d498 100644 --- a/lib/player.js +++ b/lib/player.js @@ -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); } diff --git a/test/player_unit.js b/test/player_unit.js index 28643ecc5f..fe436487ba 100644 --- a/test/player_unit.js +++ b/test/player_unit.js @@ -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); @@ -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', () => { @@ -2793,7 +2800,7 @@ describe('Player', () => { * @param {!Array.} additional */ function checkHistory(additional) { - const prefix = { + const variantPrefix = { timestamp: jasmine.any(Number), id: 0, type: 'variant', @@ -2801,10 +2808,18 @@ describe('Player', () => { 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); } /**