From 9591b8c96e85adbe6b0288a846e03544ab636558 Mon Sep 17 00:00:00 2001 From: brandonocasey Date: Wed, 23 Jun 2021 16:57:04 -0400 Subject: [PATCH 1/2] fix: on flush if a pmt has not been emitted and we have one, emit it --- lib/m2ts/m2ts.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lib/m2ts/m2ts.js b/lib/m2ts/m2ts.js index e45d4c01..68345f8b 100644 --- a/lib/m2ts/m2ts.js +++ b/lib/m2ts/m2ts.js @@ -294,6 +294,7 @@ TransportParseStream.STREAM_TYPES = { ElementaryStream = function() { var self = this, + segmentHadPmt = false, // PES packet fragments video = { data: [], @@ -406,6 +407,40 @@ ElementaryStream = function() { stream.data.length = 0; } + if (!segmentHadPmt) { + var + pmt = { + type: 'metadata', + tracks: [] + }; + // translate audio and video streams to tracks + if (programMapTable.video !== null) { + pmt.tracks.push({ + timelineStartInfo: { + baseMediaDecodeTime: 0 + }, + id: +programMapTable.video, + codec: 'avc', + type: 'video' + }); + } + + if (programMapTable.audio !== null) { + pmt.tracks.push({ + timelineStartInfo: { + baseMediaDecodeTime: 0 + }, + id: +programMapTable.audio, + codec: 'adts', + type: 'audio' + }); + } + + self.trigger('data', pmt); + } + + segmentHadPmt = false; + // only emit packets that are complete. this is to avoid assembling // incomplete PES packets due to poor segmentation if (packetFlushable) { @@ -488,6 +523,8 @@ ElementaryStream = function() { }); } + segmentHadPmt = true; + self.trigger('data', event); } })[data.type](); From 5d2536235e45632109b26b76bd38a3e4c1e1bffd Mon Sep 17 00:00:00 2001 From: brandonocasey Date: Wed, 23 Jun 2021 17:10:34 -0400 Subject: [PATCH 2/2] only do it on flush --- lib/m2ts/m2ts.js | 70 +++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/lib/m2ts/m2ts.js b/lib/m2ts/m2ts.js index 68345f8b..4f4a97b3 100644 --- a/lib/m2ts/m2ts.js +++ b/lib/m2ts/m2ts.js @@ -407,40 +407,6 @@ ElementaryStream = function() { stream.data.length = 0; } - if (!segmentHadPmt) { - var - pmt = { - type: 'metadata', - tracks: [] - }; - // translate audio and video streams to tracks - if (programMapTable.video !== null) { - pmt.tracks.push({ - timelineStartInfo: { - baseMediaDecodeTime: 0 - }, - id: +programMapTable.video, - codec: 'avc', - type: 'video' - }); - } - - if (programMapTable.audio !== null) { - pmt.tracks.push({ - timelineStartInfo: { - baseMediaDecodeTime: 0 - }, - id: +programMapTable.audio, - codec: 'adts', - type: 'audio' - }); - } - - self.trigger('data', pmt); - } - - segmentHadPmt = false; - // only emit packets that are complete. this is to avoid assembling // incomplete PES packets due to poor segmentation if (packetFlushable) { @@ -556,6 +522,42 @@ ElementaryStream = function() { }; this.flush = function() { + // if on flush we haven't had a pmt emitted + // and we have a pmt to emit. emit the pmt + // so that we trigger a trackinfo downstream. + if (!segmentHadPmt && programMapTable) { + var + pmt = { + type: 'metadata', + tracks: [] + }; + // translate audio and video streams to tracks + if (programMapTable.video !== null) { + pmt.tracks.push({ + timelineStartInfo: { + baseMediaDecodeTime: 0 + }, + id: +programMapTable.video, + codec: 'avc', + type: 'video' + }); + } + + if (programMapTable.audio !== null) { + pmt.tracks.push({ + timelineStartInfo: { + baseMediaDecodeTime: 0 + }, + id: +programMapTable.audio, + codec: 'adts', + type: 'audio' + }); + } + + self.trigger('data', pmt); + } + + segmentHadPmt = false; this.flushStreams_(); this.trigger('done'); };