@@ -5,7 +5,8 @@ namespace audio_tools {
5
5
6
6
/* *
7
7
* @brief MP3 header parser to check if the data is a valid mp3 and
8
- * to extract some relevant audio information.
8
+ * to extract some relevant audio information. We try to find some valid
9
+ * frames with a valid sync in the beginning and the end.
9
10
* See https://www.codeproject.com/KB/audio-video/mpegaudioinfo.aspx
10
11
* @ingroup codecs
11
12
* @ingroup decoder
@@ -231,6 +232,15 @@ class MP3HeaderParser {
231
232
readFrameHeader (data);
232
233
is_valid_mp3 = validate (data + sync_pos, len_available);
233
234
235
+ // check expected expected end of frame ( next frame)
236
+ int frame_len = getFrameLength ();
237
+ if (is_valid_mp3 && frame_len > 0 ){
238
+ int expected_next_frame = sync_pos + getFrameLength ();
239
+ int pos = seekFrameSync (data + expected_next_frame, len - expected_next_frame);
240
+ LOGI (" - end frame found: %s" , pos==0 ?" yes" : " no" );
241
+ if (pos !=0 ) is_valid_mp3 = false ;
242
+ }
243
+
234
244
// find end sync
235
245
int pos = seekFrameSync (data + sync_pos + 2 , len_available - 2 );
236
246
// no more data to be validated
@@ -246,12 +256,13 @@ class MP3HeaderParser {
246
256
LOGI (" is mp3: %s" , is_valid_mp3 ? " yes" : " no" );
247
257
LOGI (" frame size: %d" , getFrameLength ());
248
258
LOGI (" sample rate: %u" , getSampleRate ());
249
- LOGI (" bit rate index: %d" , getFrameHeader ().BitrateIndex );
259
+ // LOGI("bit rate index: %d", getFrameHeader().BitrateIndex);
250
260
LOGI (" bit rate: %d" , getBitRate ());
251
261
LOGI (" Padding: %d" , getFrameHeader ().Padding );
262
+ LOGI (" Layer: %s (0x%x)" , getLayerStr (), getFrameHeader ().Layer );
252
263
LOGI (" Version: %s (0x%x)" , getVersionStr (),
253
264
getFrameHeader ().AudioVersion );
254
- LOGI (" Layer: %s (0x%x) " , getLayerStr (), getFrameHeader (). Layer );
265
+ LOGI (" ------------------- " );
255
266
}
256
267
return is_valid_mp3;
257
268
}
0 commit comments