From 4e4e92e98da357285547859a98e6b3fe75d1904f Mon Sep 17 00:00:00 2001 From: Nyanmisaka Date: Tue, 24 May 2022 02:37:28 +0800 Subject: [PATCH] fix: Fix audio mime type in multiplexed HLS stream (#4241) --- lib/util/mime_utils.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/util/mime_utils.js b/lib/util/mime_utils.js index 1e0cf992d5..ae802ba1b7 100644 --- a/lib/util/mime_utils.js +++ b/lib/util/mime_utils.js @@ -8,6 +8,7 @@ goog.provide('shaka.util.MimeUtils'); goog.require('shaka.dependencies'); goog.require('shaka.media.Transmuxer'); +goog.require('shaka.util.ManifestParserUtils'); /** * @summary A set of utility functions for dealing with MIME types. @@ -34,6 +35,8 @@ shaka.util.MimeUtils = class { /** * Takes a MIME type and a codecs string and produces the full MIME * type. If it's a transport stream, convert its codecs to MP4 codecs. + * Otherwise for multiplexed content, convert the video MIME types to + * their audio equivalents if the content type is audio. * * @param {string} mimeType * @param {string} codecs @@ -42,13 +45,19 @@ shaka.util.MimeUtils = class { */ static getFullOrConvertedType(mimeType, codecs, contentType) { const fullMimeType = shaka.util.MimeUtils.getFullType(mimeType, codecs); + const ContentType = shaka.util.ManifestParserUtils.ContentType; - if (!shaka.dependencies.muxjs() || - !shaka.media.Transmuxer.isTsContainer(fullMimeType)) { - return fullMimeType; + if (shaka.media.Transmuxer.isTsContainer(fullMimeType)) { + if (shaka.dependencies.muxjs()) { + return shaka.media.Transmuxer.convertTsCodecs( + contentType, fullMimeType); + } + } else if (contentType == ContentType.AUDIO) { + // video/mp2t is the correct mime type for TS audio, so only replace the + // word "video" with "audio" for non-TS audio content. + return fullMimeType.replace('video', 'audio'); } - - return shaka.media.Transmuxer.convertTsCodecs(contentType, fullMimeType); + return fullMimeType; }