Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 13 additions & 24 deletions src/demux/tsdemuxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class TSDemuxer implements Demuxer {
this._audioTrack.segmentCodec = 'aac';

// flush any partial content
this.videoParser = null;
this.aacOverFlow = null;
this.remainderData = null;
this.audioCodec = audioCodec;
Expand Down Expand Up @@ -291,18 +292,7 @@ class TSDemuxer implements Demuxer {
case videoPid:
if (stt) {
if (videoData && (pes = parsePES(videoData, this.logger))) {
if (this.videoParser === null) {
switch (videoTrack.segmentCodec) {
case 'avc':
this.videoParser = new AvcVideoParser();
break;
case 'hevc':
if (__USE_M2TS_ADVANCED_CODECS__) {
this.videoParser = new HevcVideoParser();
}
break;
}
}
this.readyVideoParser(videoTrack.segmentCodec);
if (this.videoParser !== null) {
this.videoParser.parsePES(videoTrack, textTrack, pes, false);
}
Expand Down Expand Up @@ -477,18 +467,7 @@ class TSDemuxer implements Demuxer {
// try to parse last PES packets
let pes: PES | null;
if (videoData && (pes = parsePES(videoData, this.logger))) {
if (this.videoParser === null) {
switch (videoTrack.segmentCodec) {
case 'avc':
this.videoParser = new AvcVideoParser();
break;
case 'hevc':
if (__USE_M2TS_ADVANCED_CODECS__) {
this.videoParser = new HevcVideoParser();
}
break;
}
}
this.readyVideoParser(videoTrack.segmentCodec);
if (this.videoParser !== null) {
this.videoParser.parsePES(
videoTrack as DemuxedVideoTrack,
Expand Down Expand Up @@ -557,6 +536,16 @@ class TSDemuxer implements Demuxer {
return this.decrypt(demuxResult, sampleAes);
}

private readyVideoParser(codec: string | undefined) {
if (this.videoParser === null) {
if (codec === 'avc') {
this.videoParser = new AvcVideoParser();
} else if (__USE_M2TS_ADVANCED_CODECS__ && codec === 'hevc') {
this.videoParser = new HevcVideoParser();
}
}
}

private decrypt(
demuxResult: DemuxerResult,
sampleAes: SampleAesDecrypter,
Expand Down
Loading