From cef0eaba1ff42b881f837ca97cd07ba264a017b9 Mon Sep 17 00:00:00 2001 From: brandonocasey Date: Thu, 1 Jul 2021 16:33:22 -0400 Subject: [PATCH 1/3] feat: add general error/warn/debug log events --- lib/codecs/adts.js | 18 ++++++++++++++++++ lib/mp4/transmuxer.js | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/lib/codecs/adts.js b/lib/codecs/adts.js index e249fab1..763c489d 100644 --- a/lib/codecs/adts.js +++ b/lib/codecs/adts.js @@ -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, @@ -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 (skip) { + 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; @@ -128,6 +141,11 @@ AdtsStream = function(handlePartialSegments) { i += frameLength; } + if (skip) { + this.skipWarn_(skip, i); + skip = null; + } + // remove processed bytes from the buffer. buffer = buffer.subarray(i); }; diff --git a/lib/mp4/transmuxer.js b/lib/mp4/transmuxer.js index 865dd344..18e24718 100644 --- a/lib/mp4/transmuxer.js +++ b/lib/mp4/transmuxer.js @@ -1099,6 +1099,10 @@ 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', function(message) { + self.trigger('warn', message); + }); }; // hook up the segment streams once track metadata is delivered From cfa40cf510e3061f0dab5b1e588ba3f95bc756a2 Mon Sep 17 00:00:00 2001 From: brandonocasey Date: Fri, 2 Jul 2021 11:00:21 -0400 Subject: [PATCH 2/3] use typeof --- lib/codecs/adts.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/codecs/adts.js b/lib/codecs/adts.js index 763c489d..b140d9dc 100644 --- a/lib/codecs/adts.js +++ b/lib/codecs/adts.js @@ -95,7 +95,7 @@ AdtsStream = function(handlePartialSegments) { continue; } - if (skip) { + if (typeof skip === 'number') { this.skipWarn_(skip, i); skip = null; } @@ -141,7 +141,7 @@ AdtsStream = function(handlePartialSegments) { i += frameLength; } - if (skip) { + if (typeof skip === 'number') { this.skipWarn_(skip, i); skip = null; } From e5d8d8495f6d54cf817d243fee1dcbd4fef52bfa Mon Sep 17 00:00:00 2001 From: Brandon Casey <2381475+brandonocasey@users.noreply.github.com> Date: Fri, 2 Jul 2021 11:00:40 -0400 Subject: [PATCH 3/3] Update lib/mp4/transmuxer.js Co-authored-by: Garrett Singer --- lib/mp4/transmuxer.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/mp4/transmuxer.js b/lib/mp4/transmuxer.js index 18e24718..c33c7928 100644 --- a/lib/mp4/transmuxer.js +++ b/lib/mp4/transmuxer.js @@ -1099,10 +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', function(message) { - self.trigger('warn', message); - }); + pipeline.adtsStream.on('warn', this.trigger.bind(this, 'warn')); }; // hook up the segment streams once track metadata is delivered