Skip to content

Commit

Permalink
fix: Check bandwidth when filtering streams (#8125)
Browse files Browse the repository at this point in the history
Fixes #8124.
  • Loading branch information
vlazh authored and joeyparrish committed Feb 22, 2025
1 parent 810582c commit f7185c0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/util/stream_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,7 @@ shaka.util.StreamUtils = class {
continue;
}
}
if (stream.width > previousStream.width ||
stream.height > previousStream.height) {
validVideoStreams.push(stream);
validVideoIds.push(stream.id);
} else if (stream.width == previousStream.width &&
if (stream.width == previousStream.width &&
stream.height == previousStream.height) {
const previousCodec =
MimeUtils.getNormalizedCodec(previousStream.codecs);
Expand All @@ -213,6 +209,11 @@ shaka.util.StreamUtils = class {
validVideoIds.push(stream.id);
}
}
} else if (stream.width > previousStream.width ||
stream.height > previousStream.height ||
stream.bandwidth > previousStream.bandwidth) {
validVideoStreams.push(stream);
validVideoIds.push(stream.id);
}
}
validVideoStreamsMap.set(groupId, validVideoStreams);
Expand Down
32 changes: 32 additions & 0 deletions test/util/stream_utils_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,38 @@ describe('StreamUtils', () => {
v.video.bandwidth))).toBeTruthy();
});

it('should keep variants where the lower resolution bandwidth' +
' is greater than the higher resolution bandwidth', () => {
manifest = shaka.test.ManifestGenerator.generate((manifest) => {
manifest.addVariant(0, (variant) => {
variant.addVideo(1, (stream) => {
stream.bandwidth = 4000000;
stream.size(1920, 1080);
});
});
manifest.addVariant(1, (variant) => {
variant.addVideo(2, (stream) => {
stream.bandwidth = 5000000;
stream.size(1280, 720);
});
});
manifest.addVariant(2, (variant) => {
variant.addVideo(3, (stream) => {
stream.bandwidth = 3000000;
stream.size(640, 360);
});
});
});

shaka.util.StreamUtils.chooseCodecsAndFilterManifest(manifest,
/* preferredVideoCodecs= */[],
/* preferredAudioCodecs= */[],
/* preferredDecodingAttributes= */[],
/* preferredTextFormats= */ []);

expect(manifest.variants.length).toBe(3);
});

it('should filter variants by the best available bandwidth' +
' for audio language', () => {
// This test is flaky in some Tizen devices, due to codec restrictions.
Expand Down

0 comments on commit f7185c0

Please sign in to comment.