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

feat: add general error/warn/debug log events #391

Merged
merged 3 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions lib/codecs/adts.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ AdtsStream = function(handlePartialSegments) {

AdtsStream.prototype.init.call(this);

this.skipWarn_ = function(start, end) {
this.trigger('warn', {message: `adts skiping bytes ${start} to ${end} in frame ${frameNum} outside syncword`});
};

this.push = function(packet) {
var
i = 0,
Expand Down Expand Up @@ -75,18 +79,27 @@ AdtsStream = function(handlePartialSegments) {

// unpack any ADTS frames which have been fully received
// for details on the ADTS header, see http://wiki.multimedia.cx/index.php?title=ADTS
var skip;

// We use i + 7 here because we want to be able to parse the entire header.
// If we don't have enough bytes to do that, then we definitely won't have a full frame.
while ((i + 7) < buffer.length) {
// Look for the start of an ADTS header..
if ((buffer[i] !== 0xFF) || (buffer[i + 1] & 0xF6) !== 0xF0) {
if (typeof skip !== 'number') {
skip = i;
}
// If a valid header was not found, jump one forward and attempt to
// find a valid ADTS header starting at the next byte
i++;
continue;
}

if (typeof skip === 'number') {
this.skipWarn_(skip, i);
skip = null;
}

// The protection skip bit tells us if we have 2 bytes of CRC data at the
// end of the ADTS header
protectionSkipBytes = (~buffer[i + 1] & 0x01) * 2;
Expand Down Expand Up @@ -128,6 +141,11 @@ AdtsStream = function(handlePartialSegments) {
i += frameLength;
}

if (typeof skip === 'number') {
this.skipWarn_(skip, i);
skip = null;
}

// remove processed bytes from the buffer.
buffer = buffer.subarray(i);
};
Expand Down
1 change: 1 addition & 0 deletions lib/mp4/transmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,7 @@ Transmuxer = function(options) {
pipeline.coalesceStream.on('caption', this.trigger.bind(this, 'caption'));
// Let the consumer know we have finished flushing the entire pipeline
pipeline.coalesceStream.on('done', this.trigger.bind(this, 'done'));
pipeline.adtsStream.on('warn', this.trigger.bind(this, 'warn'));
};

// hook up the segment streams once track metadata is delivered
Expand Down