Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add adaptation set criteria factory configuration #7886

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2323,6 +2323,7 @@ shaka.extern.TextDisplayerConfiguration;
* streaming: shaka.extern.StreamingConfiguration,
* mediaSource: shaka.extern.MediaSourceConfiguration,
* abrFactory: shaka.extern.AbrManager.Factory,
* adaptationSetCriteriaFactory: shaka.media.AdaptationSetCriteria.Factory,
* abr: shaka.extern.AbrConfiguration,
* cmcd: shaka.extern.CmcdConfiguration,
* cmsd: shaka.extern.CmsdConfiguration,
Expand Down Expand Up @@ -2368,6 +2369,9 @@ shaka.extern.TextDisplayerConfiguration;
* Media source configuration and settings.
* @property {shaka.extern.AbrManager.Factory} abrFactory
* A factory to construct an abr manager.
* @property {shaka.media.AdaptationSetCriteria.Factory}
* adaptationSetCriteriaFactory
* A factory to construct an adaptation set criteria.
* @property {shaka.extern.AbrConfiguration} abr
* ABR configuration and settings.
* @property {shaka.extern.CmcdConfiguration} cmcd
Expand Down
1 change: 1 addition & 0 deletions lib/media/adaptation_set.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ goog.require('shaka.util.MimeUtils');
* A set of variants that we want to adapt between.
*
* @final
* @export
*/
shaka.media.AdaptationSet = class {
/**
Expand Down
57 changes: 57 additions & 0 deletions lib/media/adaptation_set_criteria.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
goog.provide('shaka.media.AdaptationSetCriteria');

goog.require('shaka.media.AdaptationSet');
goog.require('shaka.config.CodecSwitchingStrategy');


/**
Expand All @@ -15,6 +16,7 @@ goog.require('shaka.media.AdaptationSet');
* adapted between.
*
* @interface
* @export
*/
shaka.media.AdaptationSetCriteria = class {
/**
Expand All @@ -23,6 +25,61 @@ shaka.media.AdaptationSetCriteria = class {
*
* @param {!Array.<shaka.extern.Variant>} variants
* @return {!shaka.media.AdaptationSet}
* @exportInterface
*/
create(variants) {}

/**
* Sets the AdaptationSetCriteria configuration.
*
* @param {shaka.media.AdaptationSetCriteria.Configuration} config
* @exportInterface
*/
configure(config) {}
};

/**
* A factory for creating the AdaptationSetCriteria.
*
* @typedef {function():!shaka.media.AdaptationSetCriteria}
* @export
*/
shaka.media.AdaptationSetCriteria.Factory;

/**
* @typedef {{
* language: string,
* role: string,
* channelCount: number,
* hdrLevel: string,
* spatialAudio: boolean,
* videoLayout: string,
* audioLabel: string,
* videoLabel: string,
* codecSwitchingStrategy: shaka.config.CodecSwitchingStrategy,
* audioCodec: string
* }}
*
* @property {string} language
* The language used to filter variants.
* @property {string} role
* The adaptation role used to filter variants.
* @property {string} channelCount
* The audio channel count used to filter variants.
* @property {string} hdrLevel
* The HDR level used to filter variants.
* @property {boolean} spatialAudio
* Whether should prefer audio tracks with spatial audio.
* @property {string} videoLayout
* The video layout used to filter variants.
* @property {string} audioLabel
* The audio label used to filter variants.
* @property {string} videoLabel
* The video label used to filter variants.
* @property {shaka.config.CodecSwitchingStrategy} codecSwitchingStrategy
* The codec switching strategy used to filter variants.
* @property {string} audioCodec
* The audio codec used to filter variants.
* @export
*/
shaka.media.AdaptationSetCriteria.Configuration;
32 changes: 25 additions & 7 deletions lib/media/example_based_criteria.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
goog.provide('shaka.media.ExampleBasedCriteria');

goog.require('shaka.media.AdaptationSetCriteria');
goog.require('shaka.media.PreferenceBasedCriteria');
goog.requireType('shaka.config.CodecSwitchingStrategy');


Expand All @@ -19,8 +18,10 @@ shaka.media.ExampleBasedCriteria = class {
/**
* @param {shaka.extern.Variant} example
* @param {shaka.config.CodecSwitchingStrategy} codecSwitchingStrategy
* @param {shaka.media.AdaptationSetCriteria.Factory}
* adaptationSetCriteriaFactory
*/
constructor(example, codecSwitchingStrategy) {
constructor(example, codecSwitchingStrategy, adaptationSetCriteriaFactory) {
// We can't know if role and label are really important, so we don't use
// role and label for this.
const role = '';
Expand All @@ -38,14 +39,31 @@ shaka.media.ExampleBasedCriteria = class {
example.audio.codecs : '';

/** @private {!shaka.media.AdaptationSetCriteria} */
this.preferenceBasedCriteria_ = new shaka.media.PreferenceBasedCriteria(
example.language, role, channelCount, hdrLevel, spatialAudio,
videoLayout, audioLabel, videoLabel,
codecSwitchingStrategy, audioCodec);
this.preferenceBasedCriteria_ = adaptationSetCriteriaFactory();
this.preferenceBasedCriteria_.configure({
language: example.language,
role,
channelCount,
hdrLevel,
spatialAudio,
videoLayout,
audioLabel,
videoLabel,
codecSwitchingStrategy,
audioCodec,
});
}

/** @override */
/**
* @override
*/
create(variants) {
return this.preferenceBasedCriteria_.create(variants);
}

/**
* @override
*/
configure() {
}
};
81 changes: 32 additions & 49 deletions lib/media/preference_based_criteria.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,33 @@ goog.require('shaka.util.LanguageUtils');
/**
* @implements {shaka.media.AdaptationSetCriteria}
* @final
* @export
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically I think it is not necessary to export it because it is the default solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, yeah, let me double-check if it's still needed. Added it for the same reason as example-based-criteria.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

*/
shaka.media.PreferenceBasedCriteria = class {
/** */
constructor() {
/** @private {?shaka.media.AdaptationSetCriteria.Configuration} */
this.config_ = null;
}

/**
* @param {string} language
* @param {string} role
* @param {number} channelCount
* @param {string} hdrLevel
* @param {boolean} spatialAudio
* @param {string} videoLayout
* @param {string} audioLabel
* @param {string} videoLabel
* @param {shaka.config.CodecSwitchingStrategy} codecSwitchingStrategy
* @param {string} audioCodec
* @override
* @export
*/
constructor(language, role, channelCount, hdrLevel, spatialAudio,
videoLayout, audioLabel, videoLabel, codecSwitchingStrategy, audioCodec) {
/** @private {string} */
this.language_ = language;
/** @private {string} */
this.role_ = role;
/** @private {number} */
this.channelCount_ = channelCount;
/** @private {string} */
this.hdrLevel_ = hdrLevel;
/** @private {boolean} */
this.spatialAudio_ = spatialAudio;
/** @private {string} */
this.videoLayout_ = videoLayout;
/** @private {string} */
this.audioLabel_ = audioLabel;
/** @private {string} */
this.videoLabel_ = videoLabel;
/** @private {shaka.config.CodecSwitchingStrategy} */
this.codecSwitchingStrategy_ = codecSwitchingStrategy;
/** @private {string} */
this.audioCodec_ = audioCodec;
configure(config) {
this.config_ = config;
}

/** @override */
/**
* @override
* @export
*/
create(variants) {
const Class = shaka.media.PreferenceBasedCriteria;

let current = [];

const byLanguage = Class.filterByLanguage_(variants, this.language_);
const byLanguage = Class.filterByLanguage_(variants, this.config_.language);
const byPrimary = variants.filter((variant) => variant.primary);

if (byLanguage.length) {
Expand All @@ -74,16 +56,16 @@ shaka.media.PreferenceBasedCriteria = class {

// Now refine the choice based on role preference. Even the empty string
// works here, and will match variants without any roles.
const byRole = Class.filterVariantsByRole_(current, this.role_);
const byRole = Class.filterVariantsByRole_(current, this.config_.role);
if (byRole.length) {
current = byRole;
} else {
shaka.log.warning('No exact match for variant role could be found.');
}

if (this.videoLayout_) {
if (this.config_.videoLayout) {
const byVideoLayout = Class.filterVariantsByVideoLayout_(
current, this.videoLayout_);
current, this.config_.videoLayout);
if (byVideoLayout.length) {
current = byVideoLayout;
} else {
Expand All @@ -92,9 +74,9 @@ shaka.media.PreferenceBasedCriteria = class {
}
}

if (this.hdrLevel_) {
if (this.config_.hdrLevel) {
const byHdrLevel = Class.filterVariantsByHDRLevel_(
current, this.hdrLevel_);
current, this.config_.hdrLevel);
if (byHdrLevel.length) {
current = byHdrLevel;
} else {
Expand All @@ -103,9 +85,9 @@ shaka.media.PreferenceBasedCriteria = class {
}
}

if (this.channelCount_) {
if (this.config_.channelCount) {
const byChannel = Class.filterVariantsByAudioChannelCount_(
current, this.channelCount_);
current, this.config_.channelCount);
if (byChannel.length) {
current = byChannel;
} else {
Expand All @@ -114,19 +96,19 @@ shaka.media.PreferenceBasedCriteria = class {
}
}

if (this.audioLabel_) {
if (this.config_.audioLabel) {
const byLabel = Class.filterVariantsByAudioLabel_(
current, this.audioLabel_);
current, this.config_.audioLabel);
if (byLabel.length) {
current = byLabel;
} else {
shaka.log.warning('No exact match for audio label could be found.');
}
}

if (this.videoLabel_) {
if (this.config_.videoLabel) {
const byLabel = Class.filterVariantsByVideoLabel_(
current, this.videoLabel_);
current, this.config_.videoLabel);
if (byLabel.length) {
current = byLabel;
} else {
Expand All @@ -135,24 +117,25 @@ shaka.media.PreferenceBasedCriteria = class {
}

const bySpatialAudio = Class.filterVariantsBySpatialAudio_(
current, this.spatialAudio_);
current, this.config_.spatialAudio);
if (bySpatialAudio.length) {
current = bySpatialAudio;
} else {
shaka.log.warning('No exact match for spatial audio could be found.');
}

if (this.audioCodec_) {
if (this.config_.audioCodec) {
const byAudioCodec = Class.filterVariantsByAudioCodec_(
current, this.audioCodec_);
current, this.config_.audioCodec);
if (byAudioCodec.length) {
current = byAudioCodec;
} else {
shaka.log.warning('No exact match for audio codec could be found.');
}
}

const supportsSmoothCodecTransitions = this.codecSwitchingStrategy_ ==
const supportsSmoothCodecTransitions =
this.config_.codecSwitchingStrategy ==
shaka.config.CodecSwitchingStrategy.SMOOTH &&
shaka.media.Capabilities.isChangeTypeSupported();

Expand Down
26 changes: 14 additions & 12 deletions lib/media/preload_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ goog.require('shaka.log');
goog.require('shaka.media.AdaptationSetCriteria');
goog.require('shaka.media.ManifestFilterer');
goog.require('shaka.media.ManifestParser');
goog.require('shaka.media.PreferenceBasedCriteria');
goog.require('shaka.media.QualityObserver');
goog.require('shaka.media.RegionTimeline');
goog.require('shaka.media.SegmentPrefetch');
Expand Down Expand Up @@ -644,17 +643,20 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {
// Copy preferred languages from the config again, in case the config was
// changed between construction and playback.
this.currentAdaptationSetCriteria_ =
new shaka.media.PreferenceBasedCriteria(
this.config_.preferredAudioLanguage,
this.config_.preferredVariantRole,
this.config_.preferredAudioChannelCount,
this.config_.preferredVideoHdrLevel,
this.config_.preferSpatialAudio,
this.config_.preferredVideoLayout,
this.config_.preferredAudioLabel,
this.config_.preferredVideoLabel,
this.config_.mediaSource.codecSwitchingStrategy,
/* audioCodec= */ '');
this.config_.adaptationSetCriteriaFactory();
this.currentAdaptationSetCriteria_.configure({
language: this.config_.preferredAudioLanguage,
role: this.config_.preferredVariantRole,
channelCount: this.config_.preferredAudioChannelCount,
hdrLevel: this.config_.preferredVideoHdrLevel,
spatialAudio: this.config_.preferSpatialAudio,
videoLayout: this.config_.preferredVideoLayout,
audioLabel: this.config_.preferredAudioLabel,
videoLabel: this.config_.preferredVideoLabel,
codecSwitchingStrategy:
this.config_.mediaSource.codecSwitchingStrategy,
audioCodec: '',
});
}

// Make the ABR manager.
Expand Down
Loading
Loading