Skip to content

Commit f7185c0

Browse files
vlazhjoeyparrish
authored andcommitted
fix: Check bandwidth when filtering streams (#8125)
Fixes #8124.
1 parent 810582c commit f7185c0

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

lib/util/stream_utils.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,7 @@ shaka.util.StreamUtils = class {
196196
continue;
197197
}
198198
}
199-
if (stream.width > previousStream.width ||
200-
stream.height > previousStream.height) {
201-
validVideoStreams.push(stream);
202-
validVideoIds.push(stream.id);
203-
} else if (stream.width == previousStream.width &&
199+
if (stream.width == previousStream.width &&
204200
stream.height == previousStream.height) {
205201
const previousCodec =
206202
MimeUtils.getNormalizedCodec(previousStream.codecs);
@@ -213,6 +209,11 @@ shaka.util.StreamUtils = class {
213209
validVideoIds.push(stream.id);
214210
}
215211
}
212+
} else if (stream.width > previousStream.width ||
213+
stream.height > previousStream.height ||
214+
stream.bandwidth > previousStream.bandwidth) {
215+
validVideoStreams.push(stream);
216+
validVideoIds.push(stream.id);
216217
}
217218
}
218219
validVideoStreamsMap.set(groupId, validVideoStreams);

test/util/stream_utils_unit.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,38 @@ describe('StreamUtils', () => {
851851
v.video.bandwidth))).toBeTruthy();
852852
});
853853

854+
it('should keep variants where the lower resolution bandwidth' +
855+
' is greater than the higher resolution bandwidth', () => {
856+
manifest = shaka.test.ManifestGenerator.generate((manifest) => {
857+
manifest.addVariant(0, (variant) => {
858+
variant.addVideo(1, (stream) => {
859+
stream.bandwidth = 4000000;
860+
stream.size(1920, 1080);
861+
});
862+
});
863+
manifest.addVariant(1, (variant) => {
864+
variant.addVideo(2, (stream) => {
865+
stream.bandwidth = 5000000;
866+
stream.size(1280, 720);
867+
});
868+
});
869+
manifest.addVariant(2, (variant) => {
870+
variant.addVideo(3, (stream) => {
871+
stream.bandwidth = 3000000;
872+
stream.size(640, 360);
873+
});
874+
});
875+
});
876+
877+
shaka.util.StreamUtils.chooseCodecsAndFilterManifest(manifest,
878+
/* preferredVideoCodecs= */[],
879+
/* preferredAudioCodecs= */[],
880+
/* preferredDecodingAttributes= */[],
881+
/* preferredTextFormats= */ []);
882+
883+
expect(manifest.variants.length).toBe(3);
884+
});
885+
854886
it('should filter variants by the best available bandwidth' +
855887
' for audio language', () => {
856888
// This test is flaky in some Tizen devices, due to codec restrictions.

0 commit comments

Comments
 (0)