2
2
* highly optimized TS demuxer:
3
3
* parse PAT, PMT
4
4
* extract PES packet from audio and video PIDs
5
- * extract AVC/H264 NAL units and AAC/ADTS samples from PES packet
5
+ * extract AVC/H264 (or HEVC/H265) NAL units and AAC/ADTS samples from PES packet
6
6
* trigger the remuxer upon parsing completion
7
7
* it also tries to workaround as best as it can audio codec switch (HE-AAC to AAC and vice versa), without having to restart the MediaSource.
8
8
* it also controls the remuxing process :
@@ -14,6 +14,7 @@ import * as MpegAudio from './audio/mpegaudio';
14
14
import * as AC3 from './audio/ac3-demuxer' ;
15
15
import BaseVideoParser from './video/base-video-parser' ;
16
16
import AvcVideoParser from './video/avc-video-parser' ;
17
+ import HevcVideoParser from './video/hevc-video-parser' ;
17
18
import SampleAesDecrypter from './sample-aes' ;
18
19
import { Events } from '../events' ;
19
20
import { appendUint8Array , RemuxerTrackIdConfig } from '../utils/mp4-tools' ;
@@ -75,7 +76,7 @@ class TSDemuxer implements Demuxer {
75
76
private _txtTrack ?: DemuxedUserdataTrack ;
76
77
private aacOverFlow : AudioFrame | null = null ;
77
78
private remainderData : Uint8Array | null = null ;
78
- private videoParser : BaseVideoParser ;
79
+ private videoParser : BaseVideoParser | null ;
79
80
80
81
constructor (
81
82
observer : HlsEventEmitter ,
@@ -85,7 +86,7 @@ class TSDemuxer implements Demuxer {
85
86
this . observer = observer ;
86
87
this . config = config ;
87
88
this . typeSupported = typeSupported ;
88
- this . videoParser = new AvcVideoParser ( ) ;
89
+ this . videoParser = null ;
89
90
}
90
91
91
92
static probe ( data : Uint8Array ) {
@@ -291,13 +292,25 @@ class TSDemuxer implements Demuxer {
291
292
case videoPid :
292
293
if ( stt ) {
293
294
if ( videoData && ( pes = parsePES ( videoData ) ) ) {
294
- this . videoParser . parsePES (
295
- videoTrack ,
296
- textTrack ,
297
- pes ,
298
- false ,
299
- this . _duration ,
300
- ) ;
295
+ if ( this . videoParser === null ) {
296
+ switch ( videoTrack . segmentCodec ) {
297
+ case 'avc' :
298
+ this . videoParser = new AvcVideoParser ( ) ;
299
+ break ;
300
+ case 'hevc' :
301
+ this . videoParser = new HevcVideoParser ( ) ;
302
+ break ;
303
+ }
304
+ }
305
+ if ( this . videoParser !== null ) {
306
+ this . videoParser . parsePES (
307
+ videoTrack ,
308
+ textTrack ,
309
+ pes ,
310
+ false ,
311
+ this . _duration ,
312
+ ) ;
313
+ }
301
314
}
302
315
303
316
videoData = { data : [ ] , size : 0 } ;
@@ -469,14 +482,26 @@ class TSDemuxer implements Demuxer {
469
482
// try to parse last PES packets
470
483
let pes : PES | null ;
471
484
if ( videoData && ( pes = parsePES ( videoData ) ) ) {
472
- this . videoParser . parsePES (
473
- videoTrack as DemuxedVideoTrack ,
474
- textTrack as DemuxedUserdataTrack ,
475
- pes ,
476
- true ,
477
- this . _duration ,
478
- ) ;
479
- videoTrack . pesData = null ;
485
+ if ( this . videoParser === null ) {
486
+ switch ( videoTrack . segmentCodec ) {
487
+ case 'avc' :
488
+ this . videoParser = new AvcVideoParser ( ) ;
489
+ break ;
490
+ case 'hevc' :
491
+ this . videoParser = new HevcVideoParser ( ) ;
492
+ break ;
493
+ }
494
+ }
495
+ if ( this . videoParser !== null ) {
496
+ this . videoParser . parsePES (
497
+ videoTrack as DemuxedVideoTrack ,
498
+ textTrack as DemuxedUserdataTrack ,
499
+ pes ,
500
+ true ,
501
+ this . _duration ,
502
+ ) ;
503
+ videoTrack . pesData = null ;
504
+ }
480
505
} else {
481
506
// either avcData null or PES truncated, keep it for next frag parsing
482
507
videoTrack . pesData = videoData ;
@@ -873,8 +898,13 @@ function parsePMT(
873
898
case 0x87 :
874
899
logger . warn ( 'Unsupported EC-3 in M2TS found' ) ;
875
900
break ;
876
- case 0x24 :
877
- logger . warn ( 'Unsupported HEVC in M2TS found' ) ;
901
+
902
+ case 0x24 : // ITU-T Rec. H.265 and ISO/IEC 23008-2 (HEVC)
903
+ if ( result . videoPid === - 1 ) {
904
+ result . videoPid = pid ;
905
+ result . segmentVideoCodec = 'hevc' ;
906
+ logger . log ( 'HEVC in M2TS found' ) ;
907
+ }
878
908
break ;
879
909
880
910
default :
0 commit comments