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 1 commit
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: 37 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 @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like we need to null check programMapTable itself here and below too, likely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call, I also realized that flushStreams isn't only called on flush which gave us a lot more trackinfo events than we wanted. I moved this code to this.flush and the unit tests in vhs pass 💯

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) {
Expand Down Expand Up @@ -488,6 +523,8 @@ ElementaryStream = function() {
});
}

segmentHadPmt = true;

self.trigger('data', event);
}
})[data.type]();
Expand Down