Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: on flush if a pmt has not been emitted and we have one, emit it #388

Merged
merged 2 commits into from
Jun 24, 2021
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
39 changes: 39 additions & 0 deletions lib/m2ts/m2ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ TransportParseStream.STREAM_TYPES = {
ElementaryStream = function() {
var
self = this,
segmentHadPmt = false,
// PES packet fragments
video = {
data: [],
Expand Down Expand Up @@ -488,6 +489,8 @@ ElementaryStream = function() {
});
}

segmentHadPmt = true;

self.trigger('data', event);
}
})[data.type]();
Expand Down Expand Up @@ -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');
};
Expand Down