Skip to content

Commit 81d30d5

Browse files
committed
Reset TS video parser with init segment
Fixes video-dev#7402
1 parent ea55b28 commit 81d30d5

File tree

1 file changed

+13
-24
lines changed

1 file changed

+13
-24
lines changed

src/demux/tsdemuxer.ts

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ class TSDemuxer implements Demuxer {
191191
this._audioTrack.segmentCodec = 'aac';
192192

193193
// flush any partial content
194+
this.videoParser = null;
194195
this.aacOverFlow = null;
195196
this.remainderData = null;
196197
this.audioCodec = audioCodec;
@@ -291,18 +292,7 @@ class TSDemuxer implements Demuxer {
291292
case videoPid:
292293
if (stt) {
293294
if (videoData && (pes = parsePES(videoData, this.logger))) {
294-
if (this.videoParser === null) {
295-
switch (videoTrack.segmentCodec) {
296-
case 'avc':
297-
this.videoParser = new AvcVideoParser();
298-
break;
299-
case 'hevc':
300-
if (__USE_M2TS_ADVANCED_CODECS__) {
301-
this.videoParser = new HevcVideoParser();
302-
}
303-
break;
304-
}
305-
}
295+
this.readyVideoParser(videoTrack.segmentCodec);
306296
if (this.videoParser !== null) {
307297
this.videoParser.parsePES(videoTrack, textTrack, pes, false);
308298
}
@@ -477,18 +467,7 @@ class TSDemuxer implements Demuxer {
477467
// try to parse last PES packets
478468
let pes: PES | null;
479469
if (videoData && (pes = parsePES(videoData, this.logger))) {
480-
if (this.videoParser === null) {
481-
switch (videoTrack.segmentCodec) {
482-
case 'avc':
483-
this.videoParser = new AvcVideoParser();
484-
break;
485-
case 'hevc':
486-
if (__USE_M2TS_ADVANCED_CODECS__) {
487-
this.videoParser = new HevcVideoParser();
488-
}
489-
break;
490-
}
491-
}
470+
this.readyVideoParser(videoTrack.segmentCodec);
492471
if (this.videoParser !== null) {
493472
this.videoParser.parsePES(
494473
videoTrack as DemuxedVideoTrack,
@@ -557,6 +536,16 @@ class TSDemuxer implements Demuxer {
557536
return this.decrypt(demuxResult, sampleAes);
558537
}
559538

539+
private readyVideoParser(codec: string | undefined) {
540+
if (this.videoParser === null) {
541+
if (codec === 'avc') {
542+
this.videoParser = new AvcVideoParser();
543+
} else if (__USE_M2TS_ADVANCED_CODECS__ && codec === 'hevc') {
544+
this.videoParser = new HevcVideoParser();
545+
}
546+
}
547+
}
548+
560549
private decrypt(
561550
demuxResult: DemuxerResult,
562551
sampleAes: SampleAesDecrypter,

0 commit comments

Comments
 (0)