Skip to content

Commit

Permalink
chore: Simplify and remove optional parameters in AdaptationSetCriter…
Browse files Browse the repository at this point in the history
…ia to avoid future problems (#7548)
  • Loading branch information
avelad committed Nov 12, 2024
1 parent 5a9f4ed commit 2f7ca9d
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 72 deletions.
69 changes: 22 additions & 47 deletions lib/media/adaptation_set_criteria.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand All @@ -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} */
Expand Down
3 changes: 2 additions & 1 deletion lib/media/preload_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 2f7ca9d

Please sign in to comment.