@@ -43,6 +43,10 @@ AdtsStream = function(handlePartialSegments) {
43
43
44
44
AdtsStream . prototype . init . call ( this ) ;
45
45
46
+ this . skipWarn_ = function ( start , end ) {
47
+ this . trigger ( 'warn' , { message : `adts skiping bytes ${ start } to ${ end } in frame ${ frameNum } outside syncword` } ) ;
48
+ } ;
49
+
46
50
this . push = function ( packet ) {
47
51
var
48
52
i = 0 ,
@@ -75,18 +79,27 @@ AdtsStream = function(handlePartialSegments) {
75
79
76
80
// unpack any ADTS frames which have been fully received
77
81
// for details on the ADTS header, see http://wiki.multimedia.cx/index.php?title=ADTS
82
+ var skip ;
78
83
79
84
// We use i + 7 here because we want to be able to parse the entire header.
80
85
// If we don't have enough bytes to do that, then we definitely won't have a full frame.
81
86
while ( ( i + 7 ) < buffer . length ) {
82
87
// Look for the start of an ADTS header..
83
88
if ( ( buffer [ i ] !== 0xFF ) || ( buffer [ i + 1 ] & 0xF6 ) !== 0xF0 ) {
89
+ if ( typeof skip !== 'number' ) {
90
+ skip = i ;
91
+ }
84
92
// If a valid header was not found, jump one forward and attempt to
85
93
// find a valid ADTS header starting at the next byte
86
94
i ++ ;
87
95
continue ;
88
96
}
89
97
98
+ if ( typeof skip === 'number' ) {
99
+ this . skipWarn_ ( skip , i ) ;
100
+ skip = null ;
101
+ }
102
+
90
103
// The protection skip bit tells us if we have 2 bytes of CRC data at the
91
104
// end of the ADTS header
92
105
protectionSkipBytes = ( ~ buffer [ i + 1 ] & 0x01 ) * 2 ;
@@ -128,6 +141,11 @@ AdtsStream = function(handlePartialSegments) {
128
141
i += frameLength ;
129
142
}
130
143
144
+ if ( typeof skip === 'number' ) {
145
+ this . skipWarn_ ( skip , i ) ;
146
+ skip = null ;
147
+ }
148
+
131
149
// remove processed bytes from the buffer.
132
150
buffer = buffer . subarray ( i ) ;
133
151
} ;
0 commit comments