@@ -105,33 +105,34 @@ class ADTSParser {
105105 ADTSHeader header_ref{0 };
106106 bool is_first = true ;
107107 bool is_valid = false ;
108+ const char *error_fmt_chnange = " - Invalid ADTS change: %s" ;
109+ const char *error_fmt = " - Invalid ADTS: %s (0x%x)" ;
108110
109111 bool check () {
110112 if (header.syncword != 0b111111111111 ) {
113+ LOGW (error_fmt, " sync" , header.syncword );
111114 is_valid = false ;
112115 }
113116 if (header.id > 6 ) {
114- LOGD ( " - Invalid id" );
117+ LOGW (error_fmt, " id" , header. id );
115118 is_valid = false ;
116119 }
117120 if (header.sampling_freq_idx > 0xb ) {
118- LOGD ( " - Invalid sampl. freq" );
121+ LOGW (error_fmt, " freq" , header. sampling_freq_idx );
119122 is_valid = false ;
120123 }
121124 if (header.channel_cfg > 2 ) {
122- LOGD ( " - Invalid channels" );
125+ LOGW (error_fmt, " channels" , header. channel_cfg );
123126 is_valid = false ;
124127 }
125- if (header.frame_length > 1024 ) {
126- LOGD ( " - Invalid frame_length" );
128+ if (header.frame_length > 8191 ) { // tymically <= 768
129+ LOGW (error_fmt, " frame_length" , header. frame_length );
127130 is_valid = false ;
128131 }
132+ // on subsequent checks we need to compare with the first header
129133 if (!is_first) {
130134 is_valid = checkRef ();
131135 }
132- if (!is_valid) {
133- LOGD (" => Invalid ADTS" );
134- }
135136 if (is_valid) {
136137 is_first = false ;
137138 header_ref = header;
@@ -140,17 +141,34 @@ class ADTSParser {
140141 }
141142
142143 bool checkRef () {
144+ char msg[200 ] = " " ;
143145 bool is_valid = true ;
144- if (header.id != header_ref.id ) is_valid = false ;
145- if (header.layer != header_ref.layer ) is_valid = false ;
146- if (header.profile != header_ref.profile ) is_valid = false ;
147- if (header.sampling_freq_idx != header_ref.sampling_freq_idx )
146+ if (header.id != header_ref.id ) {
147+ strcat (msg, " id " );
148+ is_valid = false ;
149+ }
150+ if (header.layer != header_ref.layer ) {
151+ strcat (msg, " layer " );
152+ is_valid = false ;
153+ }
154+ if (header.profile != header_ref.profile ) {
155+ strcat (msg, " profile " );
148156 is_valid = false ;
149- if (header.channel_cfg != header_ref.channel_cfg ) is_valid = false ;
150- if (header.adts_buf_fullness != header_ref.adts_buf_fullness )
157+ }
158+ if (header.sampling_freq_idx != header_ref.sampling_freq_idx ) {
159+ strcat (msg, " freq " );
160+ is_valid = false ;
161+ }
162+ if (header.channel_cfg != header_ref.channel_cfg ) {
163+ strcat (msg, " channel " );
151164 is_valid = false ;
165+ }
166+ if (header.adts_buf_fullness != header_ref.adts_buf_fullness ) {
167+ strcat (msg, " fullness" );
168+ is_valid = false ;
169+ }
152170 if (!is_valid) {
153- LOGE ( " => Invalid ADTS change " );
171+ LOGW (error_fmt_chnange, msg );
154172 }
155173 return is_valid;
156174 }
@@ -211,7 +229,7 @@ class ADTSDecoder : public AudioDecoder {
211229 void setParseBufferSize (int size) { buffer.resize (size); }
212230
213231 // / Defines where the decoded result is written to
214- void setOutput (AudioStream &out_stream) override {
232+ void setOutput (AudioStream &out_stream) override {
215233 if (p_dec) {
216234 p_dec->setOutput (out_stream);
217235 } else {
0 commit comments