Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodolphe Breton committed Dec 1, 2023
2 parents fb12faa + 90bc6a7 commit d715c75
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 16 deletions.
1 change: 1 addition & 0 deletions demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ shakaDemo.Config = class {
this.latestInput_.input().value = shakaDemoMain.getUILocale();
this.addNumberInput_('Preferred Audio Channel Count',
'preferredAudioChannelCount');
this.addBoolInput_('Prefer Spatial Audio', 'preferSpatialAudio');
this.addBoolInput_('Prefer Forced Subs', 'preferForcedSubs');
}

Expand Down
3 changes: 3 additions & 0 deletions externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,7 @@ shaka.extern.OfflineConfiguration;
* preferredVideoLabel: string,
* preferredDecodingAttributes: !Array.<string>,
* preferForcedSubs: boolean,
* preferSpatialAudio: boolean,
* restrictions: shaka.extern.Restrictions,
* playRangeStart: number,
* playRangeEnd: number,
Expand Down Expand Up @@ -1681,6 +1682,8 @@ shaka.extern.OfflineConfiguration;
* If the content has no forced captions and the value is true,
* no text track is chosen.
* Changing this during playback will not affect the current playback.
* @property {boolean} preferSpatialAudio
* If true, a spatial audio track is preferred. Defaults to false.
* @property {shaka.extern.Restrictions} restrictions
* The application restrictions to apply to the tracks. These are "hard"
* restrictions. Any track that fails to meet these restrictions will not
Expand Down
22 changes: 17 additions & 5 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3753,14 +3753,26 @@ shaka.hls.HlsParser = class {

// If unable to guess mime type, request a segment and try getting it
// from the response.
let contentMimeType;
const type = shaka.net.NetworkingEngine.AdvancedRequestType.MEDIA_SEGMENT;
const headRequest = shaka.net.NetworkingEngine.makeRequest(
middleSegmentUris, this.config_.retryParameters);
headRequest.method = 'HEAD';
const type = shaka.net.NetworkingEngine.AdvancedRequestType.MEDIA_SEGMENT;
const response = await this.makeNetworkRequest_(
headRequest, requestType, {type});
try {
headRequest.method = 'HEAD';
const response = await this.makeNetworkRequest_(
headRequest, requestType, {type});

contentMimeType = response.headers['content-type'];
} catch (error) {
if (error && error.code == shaka.util.Error.Code.HTTP_ERROR) {
headRequest.method = 'GET';
const response = await this.makeNetworkRequest_(
headRequest, requestType, {type});

contentMimeType = response.headers['content-type'];
}
}

const contentMimeType = response.headers['content-type'];
if (contentMimeType) {
// Split the MIME type in case the server sent additional parameters.
return contentMimeType.split(';')[0];
Expand Down
37 changes: 33 additions & 4 deletions lib/media/adaptation_set_criteria.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,16 @@ shaka.media.ExampleBasedCriteria = class {
const audioLabel = '';
const videoLabel = '';
const hdrLevel = '';
const spatialAudio = false;
const videoLayout = '';
const channelCount = example.audio && example.audio.channelsCount ?
example.audio.channelsCount :
0;

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

Expand Down Expand Up @@ -108,14 +109,15 @@ shaka.media.PreferenceBasedCriteria = class {
* @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 {boolean=} enableAudioGroups
*/
constructor(language, role, channelCount, hdrLevel, videoLayout,
audioLabel = '', videoLabel = '',
constructor(language, role, channelCount, hdrLevel, spatialAudio,
videoLayout, audioLabel = '', videoLabel = '',
codecSwitchingStrategy = shaka.config.CodecSwitchingStrategy.RELOAD,
enableAudioGroups = false) {
/** @private {string} */
Expand All @@ -126,6 +128,8 @@ shaka.media.PreferenceBasedCriteria = class {
this.channelCount_ = channelCount;
/** @private {string} */
this.hdrLevel_ = hdrLevel;
/** @private {boolean} */
this.spatialAudio_ = spatialAudio;
/** @private {string} */
this.videoLayout_ = videoLayout;
/** @private {string} */
Expand Down Expand Up @@ -217,6 +221,14 @@ shaka.media.PreferenceBasedCriteria = class {
}
}

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

const supportsSmoothCodecTransitions = this.codecSwitchingStrategy_ ==
shaka.config.CodecSwitchingStrategy.SMOOTH &&
shaka.media.Capabilities.isChangeTypeSupported();
Expand Down Expand Up @@ -374,4 +386,21 @@ shaka.media.PreferenceBasedCriteria = class {
return true;
});
}


/**
* Filters variants according to the given spatial audio config.
*
* @param {!Array.<shaka.extern.Variant>} variants
* @param {boolean} spatialAudio
* @private
*/
static filterVariantsBySpatialAudio_(variants, spatialAudio) {
return variants.filter((variant) => {
if (variant.audio && variant.audio.spatialAudio != spatialAudio) {
return false;
}
return true;
});
}
};
9 changes: 5 additions & 4 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
this.config_.preferredVariantRole,
this.config_.preferredAudioChannelCount,
this.config_.preferredVideoHdrLevel,
this.config_.preferSpatialAudio,
this.config_.preferredVideoLayout,
this.config_.preferredAudioLabel,
this.config_.preferredVideoLabel,
Expand Down Expand Up @@ -1857,6 +1858,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
this.config_.preferredVariantRole,
this.config_.preferredAudioChannelCount,
this.config_.preferredVideoHdrLevel,
this.config_.preferSpatialAudio,
this.config_.preferredVideoLayout,
this.config_.preferredAudioLabel,
this.config_.preferredVideoLabel,
Expand Down Expand Up @@ -4064,6 +4066,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
role || '',
channelsCount,
/* hdrLevel= */ '',
/* spatialAudio= */ false,
/* videoLayout= */ '',
/* audioLabel= */ '',
/* videoLabel= */ '',
Expand Down Expand Up @@ -4189,6 +4192,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
/* role= */ '',
/* channelCount= */ 0,
/* hdrLevel= */ '',
/* spatialAudio= */ false,
/* videoLayout= */ '',
label,
/* videoLabel= */ '',
Expand Down Expand Up @@ -6462,6 +6466,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
} // if (keyIds.size)

if (tracksChanged) {
this.onTracksChanged_();
const variantsUpdated = this.updateAbrManagerVariants_();
if (!variantsUpdated) {
return;
Expand All @@ -6473,10 +6478,6 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
shaka.log.debug('Choosing new streams after key status changed');
this.chooseVariantAndSwitch_();
}

if (tracksChanged) {
this.onTracksChanged_();
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/text/vtt_text_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,9 +826,9 @@ shaka.text.VttTextParser = class {
} else if ((results = /^size:([\d.]+)%$/.exec(word))) {
cue.size = Number(results[1]);
} else if ((results =
// eslint-disable-next-line max-len
/^position:([\d.]+)%(?:,(line-left|line-right|middle|center|start|end|auto))?$/
.exec(word))) {
// eslint-disable-next-line max-len
/^position:([\d.]+)%(?:,(line-left|line-right|middle|center|start|end|auto))?$/
.exec(word))) {
cue.position = Number(results[1]);
if (results[2]) {
VttTextParser.setPositionAlign_(cue, results[2]);
Expand Down
1 change: 1 addition & 0 deletions lib/util/player_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ shaka.util.PlayerConfiguration = class {
preferredVideoCodecs: [],
preferredAudioCodecs: [],
preferForcedSubs: false,
preferSpatialAudio: false,
preferredDecodingAttributes: [],
restrictions: {
minWidth: 0,
Expand Down
Loading

0 comments on commit d715c75

Please sign in to comment.