Skip to content

Commit

Permalink
fix(DASH): Fix period combining when roles are equal (#7065)
Browse files Browse the repository at this point in the history
When roles exist and are equal between tracks and periods, period
combiner matches based on that instead of looking for other
similarities. This PR addresses it & adds regression test.
  • Loading branch information
tykus160 authored and avelad committed Jul 22, 2024
1 parent e123c5c commit 617f157
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/util/periods.js
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ shaka.util.PeriodCombiner = class {
return true;
} else if (candidateRoleMatches.length < bestRoleMatches.length) {
return false;
} else {
} else if (candidate.roles.length !== best.roles.length) {
// Both streams have the same role overlap with the outputStream
// If this is the case, choose the stream with the fewer roles overall.
// Streams that match best together tend to be streams with the same
Expand Down
68 changes: 68 additions & 0 deletions test/util/periods_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,74 @@ describe('PeriodCombiner', () => {
expect(variants[3].audio.originalId).toBe('stream2,stream2');
});

it('Matches streams based on bandwidth when roles are equal', async () => {
const stream1 = makeAudioStream('en');
stream1.bandwidth = 192000;
stream1.roles = ['main'];
stream1.originalId = 'stream1';

const stream2 = makeAudioStream('en');
stream2.bandwidth = 640000;
stream2.roles = ['main'];
stream2.originalId = 'stream2';

const stream3 = makeAudioStream('en');
stream3.bandwidth = 192000;
stream3.roles = ['main'];
stream3.originalId = 'stream3';

const stream4 = makeAudioStream('en');
// make slightly different bandwidth to avoid direct match by hashing.
stream4.bandwidth = 639000;
stream4.roles = ['main'];
stream4.originalId = 'stream4';

/** @type {!Array.<shaka.extern.Period>} */
const periods = [
{
id: '1',
videoStreams: [
makeVideoStream(1080),
],
audioStreams: [
stream1,
stream2,
],
textStreams: [],
imageStreams: [],
},
{
id: '2',
videoStreams: [
makeVideoStream(1080),
],
audioStreams: [
stream3,
stream4,
],
textStreams: [],
imageStreams: [],
},
];

await combiner.combinePeriods(periods, /* isDynamic= */ false);
const variants = combiner.getVariants();

expect(variants).toEqual(jasmine.arrayWithExactContents([
makeAVVariant(1080, 'en', 2, ['main']),
makeAVVariant(1080, 'en', 2, ['main']),
]));

// We can use the originalId field to see what each track is composed of.
const audio1 = variants[0].audio;
expect(audio1.bandwidth).toBe(192000);
expect(audio1.originalId).toBe('stream1,stream3');

const audio2 = variants[1].audio;
expect(audio2.bandwidth).toBe(640000);
expect(audio2.originalId).toBe('stream2,stream4');
});

it('Matches streams with mismatched roles', async () => {
/** @type {!Array.<shaka.extern.Period>} */
const periods = [
Expand Down

0 comments on commit 617f157

Please sign in to comment.