@@ -596,17 +596,20 @@ shaka.hls.HlsParser = class {
596
596
const allCodecs = this . getCodecsForVariantTag_ ( variantTag ) ;
597
597
598
598
if ( subGroupId ) {
599
- const textCodecs = this . guessCodecsSafe_ ( ContentType . TEXT , allCodecs ) ;
599
+ const textCodecs = shaka . util . ManifestParserUtils . guessCodecsSafe (
600
+ ContentType . TEXT , allCodecs ) ;
600
601
goog . asserts . assert ( textCodecs != null , 'Text codecs should be valid.' ) ;
601
602
this . groupIdToCodecsMap_ . set ( subGroupId , textCodecs ) ;
602
603
shaka . util . ArrayUtils . remove ( allCodecs , textCodecs ) ;
603
604
}
604
605
if ( audioGroupId ) {
605
- const codecs = this . guessCodecs_ ( ContentType . AUDIO , allCodecs ) ;
606
+ const codecs = shaka . util . ManifestParserUtils . guessCodecs (
607
+ ContentType . AUDIO , allCodecs ) ;
606
608
this . groupIdToCodecsMap_ . set ( audioGroupId , codecs ) ;
607
609
}
608
610
if ( videoGroupId ) {
609
- const codecs = this . guessCodecs_ ( ContentType . VIDEO , allCodecs ) ;
611
+ const codecs = shaka . util . ManifestParserUtils . guessCodecs (
612
+ ContentType . VIDEO , allCodecs ) ;
610
613
this . groupIdToCodecsMap_ . set ( videoGroupId , codecs ) ;
611
614
}
612
615
}
@@ -774,8 +777,10 @@ shaka.hls.HlsParser = class {
774
777
return audio && audio . verbatimMediaPlaylistUri == streamURI ;
775
778
} ) ;
776
779
777
- const videoCodecs = this . guessCodecsSafe_ ( ContentType . VIDEO , allCodecs ) ;
778
- const audioCodecs = this . guessCodecsSafe_ ( ContentType . AUDIO , allCodecs ) ;
780
+ const videoCodecs = shaka . util . ManifestParserUtils . guessCodecsSafe (
781
+ ContentType . VIDEO , allCodecs ) ;
782
+ const audioCodecs = shaka . util . ManifestParserUtils . guessCodecsSafe (
783
+ ContentType . AUDIO , allCodecs ) ;
779
784
780
785
if ( audioCodecs && ! videoCodecs ) {
781
786
// There are no associated media tags, and there's only audio codec,
@@ -1196,7 +1201,7 @@ shaka.hls.HlsParser = class {
1196
1201
}
1197
1202
1198
1203
const closedCaptions = this . getClosedCaptions_ ( tag , type ) ;
1199
- const codecs = this . guessCodecs_ ( type , allCodecs ) ;
1204
+ const codecs = shaka . util . ManifestParserUtils . guessCodecs ( type , allCodecs ) ;
1200
1205
const streamInfo = await this . createStreamInfo_ ( verbatimMediaPlaylistUri ,
1201
1206
codecs , type , /* language= */ 'und' , /* primary= */ false ,
1202
1207
/* name= */ null , /* channelcount= */ null , closedCaptions ,
@@ -2291,65 +2296,6 @@ shaka.hls.HlsParser = class {
2291
2296
}
2292
2297
}
2293
2298
2294
- /**
2295
- * Attempts to guess which codecs from the codecs list belong to a given
2296
- * content type.
2297
- * Assumes that at least one codec is correct, and throws if none are.
2298
- *
2299
- * @param {string } contentType
2300
- * @param {!Array.<string> } codecs
2301
- * @return {string }
2302
- * @private
2303
- */
2304
- guessCodecs_ ( contentType , codecs ) {
2305
- if ( codecs . length == 1 ) {
2306
- return codecs [ 0 ] ;
2307
- }
2308
-
2309
- const match = this . guessCodecsSafe_ ( contentType , codecs ) ;
2310
- // A failure is specifically denoted by null; an empty string represents a
2311
- // valid match of no codec.
2312
- if ( match != null ) {
2313
- return match ;
2314
- }
2315
-
2316
- // Unable to guess codecs.
2317
- throw new shaka . util . Error (
2318
- shaka . util . Error . Severity . CRITICAL ,
2319
- shaka . util . Error . Category . MANIFEST ,
2320
- shaka . util . Error . Code . HLS_COULD_NOT_GUESS_CODECS ,
2321
- codecs ) ;
2322
- }
2323
-
2324
- /**
2325
- * Attempts to guess which codecs from the codecs list belong to a given
2326
- * content type. Does not assume a single codec is anything special, and does
2327
- * not throw if it fails to match.
2328
- *
2329
- * @param {string } contentType
2330
- * @param {!Array.<string> } codecs
2331
- * @return {?string } or null if no match is found
2332
- * @private
2333
- */
2334
- guessCodecsSafe_ ( contentType , codecs ) {
2335
- const formats =
2336
- shaka . hls . HlsParser . CODEC_REGEXPS_BY_CONTENT_TYPE_ [ contentType ] ;
2337
- for ( const format of formats ) {
2338
- for ( const codec of codecs ) {
2339
- if ( format . test ( codec . trim ( ) ) ) {
2340
- return codec . trim ( ) ;
2341
- }
2342
- }
2343
- }
2344
-
2345
- // Text does not require a codec string.
2346
- if ( contentType == shaka . util . ManifestParserUtils . ContentType . TEXT ) {
2347
- return '' ;
2348
- }
2349
-
2350
- return null ;
2351
- }
2352
-
2353
2299
/**
2354
2300
* Replaces the variables of a given URI.
2355
2301
*
@@ -2719,60 +2665,6 @@ shaka.hls.HlsParser.StreamInfo;
2719
2665
shaka . hls . HlsParser . StreamInfos ;
2720
2666
2721
2667
2722
- /**
2723
- * A list of regexps to detect well-known video codecs.
2724
- *
2725
- * @const {!Array.<!RegExp>}
2726
- * @private
2727
- */
2728
- shaka . hls . HlsParser . VIDEO_CODEC_REGEXPS_ = [
2729
- / ^ a v c / ,
2730
- / ^ h e v / ,
2731
- / ^ h v c / ,
2732
- / ^ v p 0 ? [ 8 9 ] / ,
2733
- / ^ a v 1 $ / ,
2734
- ] ;
2735
-
2736
-
2737
- /**
2738
- * A list of regexps to detect well-known audio codecs.
2739
- *
2740
- * @const {!Array.<!RegExp>}
2741
- * @private
2742
- */
2743
- shaka . hls . HlsParser . AUDIO_CODEC_REGEXPS_ = [
2744
- / ^ v o r b i s $ / ,
2745
- / ^ o p u s $ / ,
2746
- / ^ f l a c $ / ,
2747
- / ^ m p 4 a / ,
2748
- / ^ [ a e ] c - 3 $ / ,
2749
- ] ;
2750
-
2751
-
2752
- /**
2753
- * A list of regexps to detect well-known text codecs.
2754
- *
2755
- * @const {!Array.<!RegExp>}
2756
- * @private
2757
- */
2758
- shaka . hls . HlsParser . TEXT_CODEC_REGEXPS_ = [
2759
- / ^ v t t $ / ,
2760
- / ^ w v t t / ,
2761
- / ^ s t p p / ,
2762
- ] ;
2763
-
2764
-
2765
- /**
2766
- * @const {!Object.<string, !Array.<!RegExp>>}
2767
- * @private
2768
- */
2769
- shaka . hls . HlsParser . CODEC_REGEXPS_BY_CONTENT_TYPE_ = {
2770
- 'audio' : shaka . hls . HlsParser . AUDIO_CODEC_REGEXPS_ ,
2771
- 'video' : shaka . hls . HlsParser . VIDEO_CODEC_REGEXPS_ ,
2772
- 'text' : shaka . hls . HlsParser . TEXT_CODEC_REGEXPS_ ,
2773
- } ;
2774
-
2775
-
2776
2668
/**
2777
2669
* @const {!Object.<string, string>}
2778
2670
* @private
0 commit comments