diff --git a/lib/media/adaptation_set_criteria.js b/lib/media/adaptation_set_criteria.js index 200d64e069..e86775abfa 100644 --- a/lib/media/adaptation_set_criteria.js +++ b/lib/media/adaptation_set_criteria.js @@ -41,60 +41,36 @@ shaka.media.AdaptationSetCriteria = class { shaka.media.ExampleBasedCriteria = class { /** * @param {shaka.extern.Variant} example - * @param {shaka.config.CodecSwitchingStrategy=} codecSwitchingStrategy - * @param {boolean=} enableAudioGroups + * @param {shaka.config.CodecSwitchingStrategy} codecSwitchingStrategy + * @param {boolean} enableAudioGroups */ - constructor(example, - codecSwitchingStrategy = shaka.config.CodecSwitchingStrategy.RELOAD, - enableAudioGroups = false) { - /** @private {shaka.extern.Variant} */ - this.example_ = example; - /** @private {shaka.config.CodecSwitchingStrategy} */ - this.codecSwitchingStrategy_ = codecSwitchingStrategy; - /** @private {boolean} */ - this.enableAudioGroups_ = enableAudioGroups; - - + constructor(example, codecSwitchingStrategy, enableAudioGroups) { // We can't know if role and label are really important, so we don't use // role and label for this. const role = ''; const audioLabel = ''; const videoLabel = ''; - const hdrLevel = ''; - const spatialAudio = false; - const videoLayout = ''; + const hdrLevel = example.video && example.video.hdr ? + example.video.hdr : ''; + const spatialAudio = example.audio && example.audio.spatialAudio ? + example.audio.spatialAudio : false; + const videoLayout = example.video && example.video.videoLayout ? + example.video.videoLayout : ''; const channelCount = example.audio && example.audio.channelsCount ? - example.audio.channelsCount : - 0; + example.audio.channelsCount : 0; + const audioCodec = example.audio && example.audio.codecs ? + example.audio.codecs : ''; /** @private {!shaka.media.AdaptationSetCriteria} */ - this.fallback_ = new shaka.media.PreferenceBasedCriteria( + this.preferenceBasedCriteria_ = new shaka.media.PreferenceBasedCriteria( example.language, role, channelCount, hdrLevel, spatialAudio, videoLayout, audioLabel, videoLabel, - codecSwitchingStrategy, enableAudioGroups); + codecSwitchingStrategy, enableAudioGroups, audioCodec); } /** @override */ create(variants) { - const supportsSmoothCodecTransitions = this.codecSwitchingStrategy_ == - shaka.config.CodecSwitchingStrategy.SMOOTH && - shaka.media.Capabilities.isChangeTypeSupported(); - // We can't assume that the example is in |variants| because it could - // actually be from another period. - const shortList = variants.filter((variant) => { - return shaka.media.AdaptationSet.areAdaptable(this.example_, variant, - !supportsSmoothCodecTransitions, this.enableAudioGroups_); - }); - - if (shortList.length) { - // Use the first item in the short list as the root. It should not matter - // which element we use as all items in the short list should already be - // compatible. - return new shaka.media.AdaptationSet(shortList[0], shortList, - !supportsSmoothCodecTransitions, this.enableAudioGroups_); - } else { - return this.fallback_.create(variants); - } + return this.preferenceBasedCriteria_.create(variants); } }; @@ -111,16 +87,15 @@ shaka.media.PreferenceBasedCriteria = class { * @param {string} hdrLevel * @param {boolean} spatialAudio * @param {string} videoLayout - * @param {string=} audioLabel - * @param {string=} videoLabel - * @param {shaka.config.CodecSwitchingStrategy=} codecSwitchingStrategy - * @param {boolean=} enableAudioGroups - * @param {string=} audioCodec + * @param {string} audioLabel + * @param {string} videoLabel + * @param {shaka.config.CodecSwitchingStrategy} codecSwitchingStrategy + * @param {boolean} enableAudioGroups + * @param {string} audioCodec */ constructor(language, role, channelCount, hdrLevel, spatialAudio, - videoLayout, audioLabel = '', videoLabel = '', - codecSwitchingStrategy = shaka.config.CodecSwitchingStrategy.RELOAD, - enableAudioGroups = false, audioCodec = '') { + videoLayout, audioLabel, videoLabel, codecSwitchingStrategy, + enableAudioGroups, audioCodec) { /** @private {string} */ this.language_ = language; /** @private {string} */ diff --git a/lib/media/preload_manager.js b/lib/media/preload_manager.js index 9c4e214798..42afd5248a 100644 --- a/lib/media/preload_manager.js +++ b/lib/media/preload_manager.js @@ -630,7 +630,8 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget { this.config_.preferredAudioLabel, this.config_.preferredVideoLabel, this.config_.mediaSource.codecSwitchingStrategy, - this.config_.manifest.dash.enableAudioGroups); + this.config_.manifest.dash.enableAudioGroups, + /* audioCodec= */ ''); } // Make the ABR manager. diff --git a/lib/player.js b/lib/player.js index 3f2f837fa8..a8dc6ae6ef 100644 --- a/lib/player.js +++ b/lib/player.js @@ -786,7 +786,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget { this.config_.preferredAudioLabel, this.config_.preferredVideoLabel, this.config_.mediaSource.codecSwitchingStrategy, - this.config_.manifest.dash.enableAudioGroups); + this.config_.manifest.dash.enableAudioGroups, + /* audioCodec= */ ''); /** @private {string} */ this.currentTextLanguage_ = this.config_.preferredTextLanguage; @@ -5296,7 +5297,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget { label, /* videoLabel= */ '', this.config_.mediaSource.codecSwitchingStrategy, - this.config_.manifest.dash.enableAudioGroups); + this.config_.manifest.dash.enableAudioGroups, + /* audioCodec= */ ''); this.chooseVariantAndSwitch_(clearBuffer, safeMargin); } else if (this.video_ && this.video_.audioTracks) { diff --git a/test/media/adaptation_set_criteria_unit.js b/test/media/adaptation_set_criteria_unit.js index c7739e105e..c08a5dfb5c 100644 --- a/test/media/adaptation_set_criteria_unit.js +++ b/test/media/adaptation_set_criteria_unit.js @@ -25,7 +25,12 @@ describe('AdaptationSetCriteria', () => { /* channelCount= */ 0, /* hdrLevel= */ '', /* spatialAudio= */ false, - /* videoLayout= */ ''); + /* videoLayout= */ '', + /* audioLabel= */ '', + /* videoLabel= */ '', + shaka.config.CodecSwitchingStrategy.RELOAD, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); checkSet(set, [ @@ -52,7 +57,12 @@ describe('AdaptationSetCriteria', () => { /* channelCount= */ 0, /* hdrLevel= */ '', /* spatialAudio= */ false, - /* videoLayout= */ ''); + /* videoLayout= */ '', + /* audioLabel= */ '', + /* videoLabel= */ '', + shaka.config.CodecSwitchingStrategy.RELOAD, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); checkSet(set, [ @@ -107,7 +117,9 @@ describe('AdaptationSetCriteria', () => { /* videoLayout= */ '', /* audioLabel= */ '', /* videoLabel= */ '', - shaka.config.CodecSwitchingStrategy.SMOOTH); + shaka.config.CodecSwitchingStrategy.SMOOTH, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); expect(Array.from(set.values()).length).toBe(3); @@ -155,7 +167,9 @@ describe('AdaptationSetCriteria', () => { /* videoLayout= */ '', /* audioLabel= */ '', /* videoLabel= */ '', - shaka.config.CodecSwitchingStrategy.RELOAD); + shaka.config.CodecSwitchingStrategy.RELOAD, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); expect(Array.from(set.values()).length).toBe(1); @@ -189,7 +203,12 @@ describe('AdaptationSetCriteria', () => { /* channelCount= */ 0, /* hdrLevel= */ '', /* spatialAudio= */ false, - /* videoLayout= */ ''); + /* videoLayout= */ '', + /* audioLabel= */ '', + /* videoLabel= */ '', + shaka.config.CodecSwitchingStrategy.RELOAD, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); checkSet(set, [ @@ -244,7 +263,12 @@ describe('AdaptationSetCriteria', () => { /* channelCount= */ 0, /* hdrLevel= */ '', /* spatialAudio= */ false, - /* videoLayout= */ ''); + /* videoLayout= */ '', + /* audioLabel= */ '', + /* videoLabel= */ '', + shaka.config.CodecSwitchingStrategy.RELOAD, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); // Which role is chosen is an implementation detail. @@ -308,7 +332,12 @@ describe('AdaptationSetCriteria', () => { /* channelCount= */ 0, /* hdrLevel= */ '', /* spatialAudio= */ false, - /* videoLayout= */ ''); + /* videoLayout= */ '', + /* audioLabel= */ '', + /* videoLabel= */ '', + shaka.config.CodecSwitchingStrategy.RELOAD, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); // Which role is chosen is an implementation detail. @@ -350,7 +379,12 @@ describe('AdaptationSetCriteria', () => { /* channelCount= */ 0, /* hdrLevel= */ '', /* spatialAudio= */ false, - /* videoLayout= */ ''); + /* videoLayout= */ '', + /* audioLabel= */ '', + /* videoLabel= */ '', + shaka.config.CodecSwitchingStrategy.RELOAD, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); // Which language is chosen is an implementation detail. @@ -412,7 +446,12 @@ describe('AdaptationSetCriteria', () => { /* channelCount= */ 0, /* hdrLevel= */ '', /* spatialAudio= */ false, - /* videoLayout= */ ''); + /* videoLayout= */ '', + /* audioLabel= */ '', + /* videoLabel= */ '', + shaka.config.CodecSwitchingStrategy.RELOAD, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); // Which role is chosen is an implementation detail. Each role is @@ -475,7 +514,12 @@ describe('AdaptationSetCriteria', () => { /* channelCount= */ 0, /* hdrLevel= */ '', /* spatialAudio= */ false, - /* videoLayout= */ ''); + /* videoLayout= */ '', + /* audioLabel= */ '', + /* videoLabel= */ '', + shaka.config.CodecSwitchingStrategy.RELOAD, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); checkSet(set, [ @@ -509,7 +553,12 @@ describe('AdaptationSetCriteria', () => { /* channelCount= */ 0, /* hdrLevel= */ 'PQ', /* spatialAudio= */ false, - /* videoLayout= */ ''); + /* videoLayout= */ '', + /* audioLabel= */ '', + /* videoLabel= */ '', + shaka.config.CodecSwitchingStrategy.RELOAD, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); checkSet(set, [ @@ -543,7 +592,12 @@ describe('AdaptationSetCriteria', () => { /* channelCount= */ 0, /* hdrLevel= */ '', /* spatialAudio= */ false, - /* videoLayout= */ 'CH-STEREO'); + /* videoLayout= */ 'CH-STEREO', + /* audioLabel= */ '', + /* videoLabel= */ '', + shaka.config.CodecSwitchingStrategy.RELOAD, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); checkSet(set, [ @@ -577,7 +631,12 @@ describe('AdaptationSetCriteria', () => { /* channelCount= */ 0, /* hdrLevel= */ '', /* spatialAudio= */ false, - /* videoLayout= */ 'CH-MONO'); + /* videoLayout= */ 'CH-MONO', + /* audioLabel= */ '', + /* videoLabel= */ '', + shaka.config.CodecSwitchingStrategy.RELOAD, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); checkSet(set, [ @@ -610,7 +669,12 @@ describe('AdaptationSetCriteria', () => { /* channelCount= */ 2, /* hdrLevel= */ '', /* spatialAudio= */ false, - /* videoLayout= */ ''); + /* videoLayout= */ '', + /* audioLabel= */ '', + /* videoLabel= */ '', + shaka.config.CodecSwitchingStrategy.RELOAD, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); checkSet(set, [ @@ -645,7 +709,12 @@ describe('AdaptationSetCriteria', () => { /* channelCount= */ 6, /* hdrLevel= */ '', /* spatialAudio= */ false, - /* videoLayout= */ ''); + /* videoLayout= */ '', + /* audioLabel= */ '', + /* videoLabel= */ '', + shaka.config.CodecSwitchingStrategy.RELOAD, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); checkSet(set, [ @@ -680,7 +749,12 @@ describe('AdaptationSetCriteria', () => { /* channelCount= */ 2, /* hdrLevel= */ '', /* spatialAudio= */ false, - /* videoLayout= */ ''); + /* videoLayout= */ '', + /* audioLabel= */ '', + /* videoLabel= */ '', + shaka.config.CodecSwitchingStrategy.RELOAD, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); checkSet(set, [ @@ -715,7 +789,11 @@ describe('AdaptationSetCriteria', () => { /* hdrLevel= */ '', /* spatialAudio= */ false, /* videoLayout= */ '', - /* audioLabel= */ 'preferredLabel'); + /* audioLabel= */ 'preferredLabel', + /* videoLabel= */ '', + shaka.config.CodecSwitchingStrategy.RELOAD, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); checkSet(set, [ @@ -745,7 +823,11 @@ describe('AdaptationSetCriteria', () => { /* hdrLevel= */ '', /* spatialAudio= */ true, /* videoLayout= */ '', - /* audioLabel= */ ''); + /* audioLabel= */ '', + /* videoLabel= */ '', + shaka.config.CodecSwitchingStrategy.RELOAD, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); checkSet(set, [ @@ -774,7 +856,11 @@ describe('AdaptationSetCriteria', () => { /* hdrLevel= */ '', /* spatialAudio= */ false, /* videoLayout= */ '', - /* audioLabel= */ ''); + /* audioLabel= */ '', + /* videoLabel= */ '', + shaka.config.CodecSwitchingStrategy.RELOAD, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); checkSet(set, [ @@ -821,7 +907,11 @@ describe('AdaptationSetCriteria', () => { /* hdrLevel= */ '', /* spatialAudio= */ false, /* videoLayout= */ '', - /* audioLabel= */ 'preferredLabel'); + /* audioLabel= */ 'preferredLabel', + /* videoLabel= */ '', + shaka.config.CodecSwitchingStrategy.RELOAD, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); checkSet(set, [ @@ -857,7 +947,10 @@ describe('AdaptationSetCriteria', () => { /* spatialAudio= */ false, /* videoLayout= */ '', /* audioLabel= */ '', - /* videoLabel= */ 'preferredLabel'); + /* videoLabel= */ 'preferredLabel', + shaka.config.CodecSwitchingStrategy.RELOAD, + /* enableAudioGroups= */ false, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); checkSet(set, [ @@ -901,7 +994,8 @@ describe('AdaptationSetCriteria', () => { /* audioLabel= */ '', /* videoLabel= */ '', shaka.config.CodecSwitchingStrategy.RELOAD, - /* enableAudioGroups= */ true); + /* enableAudioGroups= */ true, + /* audioCodec= */ ''); const set = builder.create(manifest.variants); checkSet(set, [