Skip to content

Commit

Permalink
feat: add general error/warn/debug log events and log skipped adts da…
Browse files Browse the repository at this point in the history
…ta (#391)
  • Loading branch information
brandonocasey committed Jul 2, 2021
1 parent 590ac39 commit 6588d48
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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

0 comments on commit 6588d48

Please sign in to comment.