Skip to content

Commit

Permalink
fix: Remove useless calls to isTypeSupported (#7817)
Browse files Browse the repository at this point in the history
It also enables a test that has been disabled due to this bug.
  • Loading branch information
avelad authored and joeyparrish committed Jan 6, 2025
1 parent f22ada1 commit 828dc35
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 63 deletions.
5 changes: 5 additions & 0 deletions lib/media/media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ shaka.media.MediaSourceEngine = class {
for (const ref of stream.segmentIndex) {
const mimeType = ref.mimeType || stream.mimeType || '';
let codecs = ref.codecs || stream.codecs || '';
// Optimization for the case where the codecs and mimetype of the stream
// match the reference.
if (mimeType == stream.mimeType && codecs == stream.codecs) {
continue;
}
// Don't check the same combination of mimetype + codecs twice.
const combo = mimeType + ':' + codecs;
if (seenCombos.has(combo)) {
Expand Down
60 changes: 0 additions & 60 deletions lib/util/stream_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,6 @@ shaka.util.StreamUtils = class {
if (!variantSupported) {
return false;
}
const ContentType = shaka.util.ManifestParserUtils.ContentType;
const Capabilities = shaka.media.Capabilities;
const ManifestParserUtils = shaka.util.ManifestParserUtils;
const MimeUtils = shaka.util.MimeUtils;
const StreamUtils = shaka.util.StreamUtils;

const isXboxOne = shaka.util.Platform.isXboxOne();
const isFirefoxAndroid = shaka.util.Platform.isFirefox() &&
Expand All @@ -519,45 +514,6 @@ shaka.util.StreamUtils = class {
return false;
}

if (video) {
let videoCodecs = StreamUtils.getCorrectVideoCodecs(video.codecs);
// For multiplexed streams. Here we must check the audio of the
// stream to see if it is compatible.
if (video.codecs.includes(',')) {
const allCodecs = video.codecs.split(',');

videoCodecs = ManifestParserUtils.guessCodecs(
ContentType.VIDEO, allCodecs);
videoCodecs = StreamUtils.getCorrectVideoCodecs(videoCodecs);
let audioCodecs = ManifestParserUtils.guessCodecs(
ContentType.AUDIO, allCodecs);
audioCodecs = StreamUtils.getCorrectAudioCodecs(
audioCodecs, video.mimeType);

const audioFullType = MimeUtils.getFullOrConvertedType(
video.mimeType, audioCodecs, ContentType.AUDIO);

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

// Update the codec string with the (possibly) converted codecs.
videoCodecs = [videoCodecs, audioCodecs].join(',');
}

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

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

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

const audio = variant.audio;

// See: https://github.com/shaka-project/shaka-player/issues/6111
Expand All @@ -569,22 +525,6 @@ shaka.util.StreamUtils = class {
return false;
}

if (audio) {
const codecs = StreamUtils.getCorrectAudioCodecs(
audio.codecs, audio.mimeType);
if (audio.codecs != codecs) {
const fullType = MimeUtils.getFullOrConvertedType(
audio.mimeType, codecs, ContentType.AUDIO);

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

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

return true;
}

Expand Down
15 changes: 12 additions & 3 deletions test/transmuxer/transmuxer_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,22 @@ describe('Transmuxer Player', () => {
});

it('H.264+MP3 in TS', async () => {
if (!await Util.isTypeSupported('audio/mp4; codecs="mp3"')) {
pending('Codec MP3 in MP4 is not supported by the platform.');
if (!await Util.isTypeSupported('audio/mp4; codecs="mp3"') &&
!await Util.isTypeSupported('audio/mpeg')) {
pending('Codec MP3 is not supported by the platform.');
}
if (!shaka.util.Platform.supportsSequenceMode()) {
pending('Sequence mode is not supported by the platform.');
}

// eslint-disable-next-line max-len
await player.load('/base/test/test/assets/hls-ts-muxed-mp3-h264/index.m3u8');
await video.play();
try {
await video.play();
// eslint-disable-next-line no-restricted-syntax
} catch (e) {
// Ignore play errors
}
expect(player.isLive()).toBe(false);

// Wait for the video to start playback. If it takes longer than 10
Expand Down

0 comments on commit 828dc35

Please sign in to comment.