From 802e18287e9ccc214576fa343b5c2c8347d09395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Tyczy=C5=84ski?= Date: Thu, 18 Jul 2024 18:03:17 +0200 Subject: [PATCH] fix(ABR): Do not adapt between spatial & non spatial audio --- lib/media/adaptation_set.js | 6 ++++++ test/media/adaptation_set_unit.js | 22 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/media/adaptation_set.js b/lib/media/adaptation_set.js index 77714aa876..d8f6ec41ee 100644 --- a/lib/media/adaptation_set.js +++ b/lib/media/adaptation_set.js @@ -150,6 +150,12 @@ shaka.media.AdaptationSet = class { } } + // Don't adapt between spatial and non spatial audio, which may + // annoy the user. + if (a.spatialAudio !== b.spatialAudio) { + return false; + } + // We can only adapt between base-codecs. if (compareCodecs && !AdaptationSet.canTransitionBetween_(a, b)) { return false; diff --git a/test/media/adaptation_set_unit.js b/test/media/adaptation_set_unit.js index 8240645d54..35ffcb4e89 100644 --- a/test/media/adaptation_set_unit.js +++ b/test/media/adaptation_set_unit.js @@ -162,6 +162,22 @@ describe('AdaptationSet', () => { expect(set.canInclude(variants[1])).toBeFalsy(); }); + it('rejects misaligned spatial audio', () => { + const variants = [ + makeVariant( + 1, // variant id + makeStream(11, 'a', ['a.35'], [], 6, false), + makeStream(12, 'a', ['b.12'], [], 6, false)), + makeVariant( + 2, // variant id + makeStream(21, 'a', ['a.35'], [], 6, true), + makeStream(22, 'a', ['b.12'], [], 6, true)), + ]; + + const set = new shaka.media.AdaptationSet(variants[0]); + expect(set.canInclude(variants[1])).toBeFalsy(); + }); + /** * Create a variant where the audio stream is optional but the video stream * is required. For the cases where audio and video are in the same stream, @@ -193,13 +209,15 @@ describe('AdaptationSet', () => { * @param {!Array.} codecs * @param {!Array.} roles * @param {?number} channelsCount + * @param {boolean=} spatialAudio * @return {shaka.extern.Stream} */ - function makeStream(id, mimeType, codecs, roles, channelsCount) { + function makeStream(id, mimeType, codecs, roles, channelsCount, + spatialAudio = false) { return { audioSamplingRate: null, channelsCount: channelsCount, - spatialAudio: false, + spatialAudio, closedCaptions: null, codecs: codecs.join(','), createSegmentIndex: () => Promise.resolve(),