Skip to content

Commit 6588d48

Browse files
feat: add general error/warn/debug log events and log skipped adts data (#391)
1 parent 590ac39 commit 6588d48

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/codecs/adts.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ AdtsStream = function(handlePartialSegments) {
4343

4444
AdtsStream.prototype.init.call(this);
4545

46+
this.skipWarn_ = function(start, end) {
47+
this.trigger('warn', {message: `adts skiping bytes ${start} to ${end} in frame ${frameNum} outside syncword`});
48+
};
49+
4650
this.push = function(packet) {
4751
var
4852
i = 0,
@@ -75,18 +79,27 @@ AdtsStream = function(handlePartialSegments) {
7579

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

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

98+
if (typeof skip === 'number') {
99+
this.skipWarn_(skip, i);
100+
skip = null;
101+
}
102+
90103
// The protection skip bit tells us if we have 2 bytes of CRC data at the
91104
// end of the ADTS header
92105
protectionSkipBytes = (~buffer[i + 1] & 0x01) * 2;
@@ -128,6 +141,11 @@ AdtsStream = function(handlePartialSegments) {
128141
i += frameLength;
129142
}
130143

144+
if (typeof skip === 'number') {
145+
this.skipWarn_(skip, i);
146+
skip = null;
147+
}
148+
131149
// remove processed bytes from the buffer.
132150
buffer = buffer.subarray(i);
133151
};

lib/mp4/transmuxer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,7 @@ Transmuxer = function(options) {
10991099
pipeline.coalesceStream.on('caption', this.trigger.bind(this, 'caption'));
11001100
// Let the consumer know we have finished flushing the entire pipeline
11011101
pipeline.coalesceStream.on('done', this.trigger.bind(this, 'done'));
1102+
pipeline.adtsStream.on('warn', this.trigger.bind(this, 'warn'));
11021103
};
11031104

11041105
// hook up the segment streams once track metadata is delivered

0 commit comments

Comments
 (0)