@@ -105,33 +105,34 @@ class ADTSParser {
105
105
ADTSHeader header_ref{0 };
106
106
bool is_first = true ;
107
107
bool is_valid = false ;
108
+ const char *error_fmt_chnange = " - Invalid ADTS change: %s" ;
109
+ const char *error_fmt = " - Invalid ADTS: %s (0x%x)" ;
108
110
109
111
bool check () {
110
112
if (header.syncword != 0b111111111111 ) {
113
+ LOGW (error_fmt, " sync" , header.syncword );
111
114
is_valid = false ;
112
115
}
113
116
if (header.id > 6 ) {
114
- LOGD ( " - Invalid id" );
117
+ LOGW (error_fmt, " id" , header. id );
115
118
is_valid = false ;
116
119
}
117
120
if (header.sampling_freq_idx > 0xb ) {
118
- LOGD ( " - Invalid sampl. freq" );
121
+ LOGW (error_fmt, " freq" , header. sampling_freq_idx );
119
122
is_valid = false ;
120
123
}
121
124
if (header.channel_cfg > 2 ) {
122
- LOGD ( " - Invalid channels" );
125
+ LOGW (error_fmt, " channels" , header. channel_cfg );
123
126
is_valid = false ;
124
127
}
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 );
127
130
is_valid = false ;
128
131
}
132
+ // on subsequent checks we need to compare with the first header
129
133
if (!is_first) {
130
134
is_valid = checkRef ();
131
135
}
132
- if (!is_valid) {
133
- LOGD (" => Invalid ADTS" );
134
- }
135
136
if (is_valid) {
136
137
is_first = false ;
137
138
header_ref = header;
@@ -140,17 +141,34 @@ class ADTSParser {
140
141
}
141
142
142
143
bool checkRef () {
144
+ char msg[200 ] = " " ;
143
145
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 " );
148
156
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 " );
151
164
is_valid = false ;
165
+ }
166
+ if (header.adts_buf_fullness != header_ref.adts_buf_fullness ) {
167
+ strcat (msg, " fullness" );
168
+ is_valid = false ;
169
+ }
152
170
if (!is_valid) {
153
- LOGE ( " => Invalid ADTS change " );
171
+ LOGW (error_fmt_chnange, msg );
154
172
}
155
173
return is_valid;
156
174
}
@@ -211,7 +229,7 @@ class ADTSDecoder : public AudioDecoder {
211
229
void setParseBufferSize (int size) { buffer.resize (size); }
212
230
213
231
// / Defines where the decoded result is written to
214
- void setOutput (AudioStream &out_stream) override {
232
+ void setOutput (AudioStream &out_stream) override {
215
233
if (p_dec) {
216
234
p_dec->setOutput (out_stream);
217
235
} else {
0 commit comments