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

perf: Reduce calls to isTypeSupported #7729

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
64 changes: 36 additions & 28 deletions lib/util/stream_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,23 @@ shaka.util.StreamUtils = class {
* @private
*/
static checkVariantSupported_(variant, keySystem) {
const variantSupported = variant.decodingInfos.some((decodingInfo) => {
if (!decodingInfo.supported) {
return false;
}
if (keySystem) {
const keySystemAccess = decodingInfo.keySystemAccess;
if (keySystemAccess) {
if (keySystemAccess.keySystem != keySystem) {
return false;
}
}
}
return true;
});
if (!variantSupported) {
return false;
}
const ContentType = shaka.util.ManifestParserUtils.ContentType;
const Capabilities = shaka.media.Capabilities;
const ManifestParserUtils = shaka.util.ManifestParserUtils;
Expand Down Expand Up @@ -537,15 +554,17 @@ shaka.util.StreamUtils = class {
videoCodecs = [videoCodecs, audioCodecs].join(',');
}

const fullType = MimeUtils.getFullOrConvertedType(
video.mimeType, videoCodecs, ContentType.VIDEO);
if (video.codecs != videoCodecs) {
const fullType = MimeUtils.getFullOrConvertedType(
video.mimeType, videoCodecs, ContentType.VIDEO);

if (!Capabilities.isTypeSupported(fullType)) {
return false;
}
if (!Capabilities.isTypeSupported(fullType)) {
return false;
}

// Update the codec string with the (possibly) converted codecs.
video.codecs = videoCodecs;
// Update the codec string with the (possibly) converted codecs.
video.codecs = videoCodecs;
}
}

const audio = variant.audio;
Expand All @@ -562,31 +581,20 @@ shaka.util.StreamUtils = class {
if (audio) {
const codecs = StreamUtils.getCorrectAudioCodecs(
audio.codecs, audio.mimeType);
const fullType = MimeUtils.getFullOrConvertedType(
audio.mimeType, codecs, ContentType.AUDIO);
if (audio.codecs != codecs) {
const fullType = MimeUtils.getFullOrConvertedType(
audio.mimeType, codecs, ContentType.AUDIO);

if (!Capabilities.isTypeSupported(fullType)) {
return false;
}
if (!Capabilities.isTypeSupported(fullType)) {
return false;
}

// Update the codec string with the (possibly) converted codecs.
audio.codecs = codecs;
// Update the codec string with the (possibly) converted codecs.
audio.codecs = codecs;
}
}

return variant.decodingInfos.some((decodingInfo) => {
if (!decodingInfo.supported) {
return false;
}
if (keySystem) {
const keySystemAccess = decodingInfo.keySystemAccess;
if (keySystemAccess) {
if (keySystemAccess.keySystem != keySystem) {
return false;
}
}
}
return true;
});
return true;
}


Expand Down
2 changes: 2 additions & 0 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3712,6 +3712,8 @@ describe('Player', () => {
stream.mimeType = 'video';
stream.codecs = 'unsupported';
stream.addDrmInfo('foo.bar');
stream.fullMimeTypes = new Set([shaka.util.MimeUtils.getFullType(
stream.mimeType, stream.codecs)]);
});
});
manifest.addVariant(1, (variant) => {
Expand Down
Loading