From 966a7565785136395cd8121b296ee7aa5a2a2511 Mon Sep 17 00:00:00 2001 From: Michelle Zhuo Date: Mon, 22 Mar 2021 22:31:48 -0700 Subject: [PATCH] feat(MediaCap): Support multiplex content with MediaCap If we have a multiplexd content with audio and video, we combine the audio and video codecs in the manifest parser. For example, a multiplexed stream would be with: mimeType="video/mp4", codecs="avc1.64001e,mp4a.40.2". When sending the request to MediaCapabilities.decodingInfo(), we need to have the config for both audio and video to get the result as "supported". The video config would be: contentType='video/mp4, codecs="avc1.64001e"'. The audio config would be: contentType='audio/mp4, codecs="mp4a.40.2"'. Issue #1391 Change-Id: I74a8580c07228e9600dc40c611ebd5d34f8cd7ee --- lib/util/stream_utils.js | 19 ++++++++++++++++++- test/util/stream_utils_unit.js | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/util/stream_utils.js b/lib/util/stream_utils.js index 6165749f25..d61d7a836e 100644 --- a/lib/util/stream_utils.js +++ b/lib/util/stream_utils.js @@ -374,8 +374,25 @@ shaka.util.StreamUtils = class { }; if (video) { + let audioCodec; + let videoCodec = video.codecs; + + // For multiplexed streams with audio+video codecs, the config should have + // AudioConfiguration and VideoConfiguration. + if (video.codecs.includes(',')) { + [videoCodec, audioCodec] = video.codecs.split(','); + const audioFullType = shaka.util.MimeUtils.getFullOrConvertedType( + video.mimeType, audioCodec, ContentType.AUDIO); + mediaDecodingConfig['audio'] = { + contentType: audioFullType, + channels: 2, + bitrate: variant.bandwidth || 1, + samplerate: 1, + spatialRendering: false, + }; + } const fullType = shaka.util.MimeUtils.getFullOrConvertedType( - video.mimeType, video.codecs, ContentType.VIDEO); + video.mimeType, videoCodec, ContentType.VIDEO); // VideoConfiguration mediaDecodingConfig['video'] = { contentType: fullType, diff --git a/test/util/stream_utils_unit.js b/test/util/stream_utils_unit.js index f6e0eabab6..30f333133c 100644 --- a/test/util/stream_utils_unit.js +++ b/test/util/stream_utils_unit.js @@ -464,6 +464,24 @@ describe('StreamUtils', () => { }); }); + describe('getDecodingInfosForVariants', () => { + it('for multiplexd content', async () => { + manifest = shaka.test.ManifestGenerator.generate((manifest) => { + manifest.addVariant(0, (variant) => { + variant.addVideo(1, (stream) => { + stream.mime('video/mp2t', 'avc1.4d400d,mp4a.40.2'); + }); + }); + }); + + await shaka.util.StreamUtils.getDecodingInfosForVariants( + manifest.variants); + expect(manifest.variants.length).toBeTruthy(); + expect(manifest.variants[0].decodingInfos.length).toBe(1); + expect(manifest.variants[0].decodingInfos[0].supported).toBeTruthy(); + }); + }); + describe('filterManifest', () => { let fakeDrmEngine;