@@ -2247,32 +2247,32 @@ shaka.media.MediaSourceEngine = class {
2247
2247
}
2248
2248
2249
2249
/**
2250
- * Codec switch if necessary, this will not resolve until the codec
2251
- * switch is over.
2252
2250
* @param {shaka.util.ManifestParserUtils.ContentType } contentType
2253
2251
* @param {string } mimeType
2254
2252
* @param {string } codecs
2255
- * @param {!Map.<shaka.util.ManifestParserUtils.ContentType,
2256
- * shaka.extern.Stream>} streamsByType
2257
- * @return {!Promise.<boolean> } true if there was a codec switch,
2258
- * false otherwise.
2253
+ * @return {{transmuxer: ?shaka.extern.Transmuxer,
2254
+ * transmuxerMuxed: boolean, basicType: string, codec: string,
2255
+ * mimeType: string}}
2259
2256
* @private
2260
2257
*/
2261
- async codecSwitchIfNecessary_ ( contentType , mimeType , codecs , streamsByType ) {
2258
+ getRealInfo_ ( contentType , mimeType , codecs ) {
2262
2259
const ContentType = shaka . util . ManifestParserUtils . ContentType ;
2263
- if ( contentType == ContentType . TEXT ) {
2264
- return false ;
2265
- }
2266
2260
const MimeUtils = shaka . util . MimeUtils ;
2267
- const currentCodec = MimeUtils . getNormalizedCodec (
2268
- MimeUtils . getCodecs ( this . sourceBufferTypes_ [ contentType ] ) ) ;
2269
- const currentBasicType = MimeUtils . getBasicType (
2270
- this . sourceBufferTypes_ [ contentType ] ) ;
2271
-
2272
2261
/** @type {?shaka.extern.Transmuxer } */
2273
2262
let transmuxer ;
2274
2263
let transmuxerMuxed = false ;
2275
- let newMimeType = shaka . util . MimeUtils . getFullType ( mimeType , codecs ) ;
2264
+ const audioCodec = shaka . util . ManifestParserUtils . guessCodecsSafe (
2265
+ ContentType . AUDIO , ( codecs || '' ) . split ( ',' ) ) ;
2266
+ const videoCodec = shaka . util . ManifestParserUtils . guessCodecsSafe (
2267
+ ContentType . VIDEO , ( codecs || '' ) . split ( ',' ) ) ;
2268
+ let codec = videoCodec ;
2269
+ if ( contentType == ContentType . AUDIO ) {
2270
+ codec = audioCodec ;
2271
+ }
2272
+ if ( ! codec ) {
2273
+ codec = codecs ;
2274
+ }
2275
+ let newMimeType = shaka . util . MimeUtils . getFullType ( mimeType , codec ) ;
2276
2276
let needTransmux = this . config_ . forceTransmux ;
2277
2277
if ( ! shaka . media . Capabilities . isTypeSupported ( newMimeType ) ||
2278
2278
( ! this . sequenceMode_ &&
@@ -2282,36 +2282,79 @@ shaka.media.MediaSourceEngine = class {
2282
2282
const TransmuxerEngine = shaka . transmuxer . TransmuxerEngine ;
2283
2283
if ( needTransmux ) {
2284
2284
const newMimeTypeWithAllCodecs =
2285
- shaka . util . MimeUtils . getFullTypeWithAllCodecs ( mimeType , codecs ) ;
2285
+ shaka . util . MimeUtils . getFullTypeWithAllCodecs ( mimeType , codec ) ;
2286
2286
const transmuxerPlugin =
2287
2287
TransmuxerEngine . findTransmuxer ( newMimeTypeWithAllCodecs ) ;
2288
2288
if ( transmuxerPlugin ) {
2289
2289
transmuxer = transmuxerPlugin ( ) ;
2290
- const audioCodec = shaka . util . ManifestParserUtils . guessCodecsSafe (
2291
- ContentType . AUDIO , ( codecs || '' ) . split ( ',' ) ) ;
2292
- const videoCodec = shaka . util . ManifestParserUtils . guessCodecsSafe (
2293
- ContentType . VIDEO , ( codecs || '' ) . split ( ',' ) ) ;
2294
2290
if ( audioCodec && videoCodec ) {
2295
2291
transmuxerMuxed = true ;
2296
- let codec = videoCodec ;
2297
- if ( contentType == ContentType . AUDIO ) {
2298
- codec = audioCodec ;
2299
- }
2300
- newMimeType = transmuxer . convertCodecs ( contentType ,
2301
- shaka . util . MimeUtils . getFullTypeWithAllCodecs ( mimeType , codec ) ) ;
2302
- } else {
2303
- newMimeType =
2304
- transmuxer . convertCodecs ( contentType , newMimeTypeWithAllCodecs ) ;
2305
2292
}
2293
+ newMimeType =
2294
+ transmuxer . convertCodecs ( contentType , newMimeTypeWithAllCodecs ) ;
2306
2295
}
2307
2296
}
2308
2297
2309
2298
const newCodec = MimeUtils . getNormalizedCodec (
2310
2299
MimeUtils . getCodecs ( newMimeType ) ) ;
2311
2300
const newBasicType = MimeUtils . getBasicType ( newMimeType ) ;
2301
+ return {
2302
+ transmuxer,
2303
+ transmuxerMuxed,
2304
+ basicType : newBasicType ,
2305
+ codec : newCodec ,
2306
+ mimeType : newMimeType ,
2307
+ } ;
2308
+ }
2309
+
2310
+ /**
2311
+ * Codec switch if necessary, this will not resolve until the codec
2312
+ * switch is over.
2313
+ * @param {shaka.util.ManifestParserUtils.ContentType } contentType
2314
+ * @param {string } mimeType
2315
+ * @param {string } codecs
2316
+ * @param {!Map.<shaka.util.ManifestParserUtils.ContentType,
2317
+ * shaka.extern.Stream>} streamsByType
2318
+ * @return {!Promise.<boolean> } true if there was a codec switch,
2319
+ * false otherwise.
2320
+ * @private
2321
+ */
2322
+ async codecSwitchIfNecessary_ ( contentType , mimeType , codecs , streamsByType ) {
2323
+ const ContentType = shaka . util . ManifestParserUtils . ContentType ;
2324
+ if ( contentType == ContentType . TEXT ) {
2325
+ return false ;
2326
+ }
2327
+ const MimeUtils = shaka . util . MimeUtils ;
2328
+ const currentCodec = MimeUtils . getNormalizedCodec (
2329
+ MimeUtils . getCodecs ( this . sourceBufferTypes_ [ contentType ] ) ) ;
2330
+ const currentBasicType = MimeUtils . getBasicType (
2331
+ this . sourceBufferTypes_ [ contentType ] ) ;
2332
+
2333
+ const realInfo = this . getRealInfo_ ( contentType , mimeType , codecs ) ;
2334
+ const transmuxer = realInfo . transmuxer ;
2335
+ const transmuxerMuxed = realInfo . transmuxerMuxed ;
2336
+ const newBasicType = realInfo . basicType ;
2337
+ const newCodec = realInfo . codec ;
2338
+ const newMimeType = realInfo . mimeType ;
2339
+
2340
+ let muxedContentCheck = true ;
2341
+ if ( transmuxerMuxed ) {
2342
+ const muxedRealInfo =
2343
+ this . getRealInfo_ ( ContentType . AUDIO , mimeType , codecs ) ;
2344
+ const muxedCurrentCodec = MimeUtils . getNormalizedCodec (
2345
+ MimeUtils . getCodecs ( this . sourceBufferTypes_ [ ContentType . AUDIO ] ) ) ;
2346
+ const muxedCurrentBasicType = MimeUtils . getBasicType (
2347
+ this . sourceBufferTypes_ [ ContentType . AUDIO ] ) ;
2348
+ muxedContentCheck = muxedCurrentCodec == muxedRealInfo . codec &&
2349
+ muxedCurrentBasicType == muxedRealInfo . basicType ;
2350
+ if ( muxedRealInfo . transmuxer ) {
2351
+ muxedRealInfo . transmuxer . destroy ( ) ;
2352
+ }
2353
+ }
2312
2354
2313
2355
// Current/new codecs base and basic type match then no need to switch
2314
- if ( currentCodec === newCodec && currentBasicType === newBasicType ) {
2356
+ if ( currentCodec === newCodec && currentBasicType === newBasicType &&
2357
+ muxedContentCheck ) {
2315
2358
if ( this . transmuxers_ [ contentType ] && ! transmuxer ) {
2316
2359
this . transmuxers_ [ contentType ] . destroy ( ) ;
2317
2360
delete this . transmuxers_ [ contentType ] ;
0 commit comments