diff --git a/lib/m2ts/m2ts.js b/lib/m2ts/m2ts.js index e45d4c01..4f4a97b3 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: [], @@ -488,6 +489,8 @@ ElementaryStream = function() { }); } + segmentHadPmt = true; + self.trigger('data', event); } })[data.type](); @@ -519,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'); };