Skip to content

Commit c19fbd6

Browse files
committed
MP3HeaderParser
1 parent 76459c7 commit c19fbd6

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/AudioTools/AudioCodecs/MP3HeaderParser.h

+14-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ namespace audio_tools {
55

66
/**
77
* @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.
910
* See https://www.codeproject.com/KB/audio-video/mpegaudioinfo.aspx
1011
* @ingroup codecs
1112
* @ingroup decoder
@@ -231,6 +232,15 @@ class MP3HeaderParser {
231232
readFrameHeader(data);
232233
is_valid_mp3 = validate(data + sync_pos, len_available);
233234

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+
234244
// find end sync
235245
int pos = seekFrameSync(data + sync_pos + 2, len_available - 2);
236246
// no more data to be validated
@@ -246,12 +256,13 @@ class MP3HeaderParser {
246256
LOGI("is mp3: %s", is_valid_mp3 ? "yes" : "no");
247257
LOGI("frame size: %d", getFrameLength());
248258
LOGI("sample rate: %u", getSampleRate());
249-
LOGI("bit rate index: %d", getFrameHeader().BitrateIndex);
259+
// LOGI("bit rate index: %d", getFrameHeader().BitrateIndex);
250260
LOGI("bit rate: %d", getBitRate());
251261
LOGI("Padding: %d", getFrameHeader().Padding);
262+
LOGI("Layer: %s (0x%x)", getLayerStr(), getFrameHeader().Layer);
252263
LOGI("Version: %s (0x%x)", getVersionStr(),
253264
getFrameHeader().AudioVersion);
254-
LOGI("Layer: %s (0x%x)", getLayerStr(), getFrameHeader().Layer);
265+
LOGI("-------------------");
255266
}
256267
return is_valid_mp3;
257268
}

src/AudioTools/CoreAudio/AudioMetaData/MimeDetector.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ namespace audio_tools {
1919
class MimeDetector {
2020
public:
2121
MimeDetector() {
22-
setCheck("audio/aac", checkAAC);
23-
setCheck("audio/mpeg", checkMP3);
22+
setCheck("audio/aac", checkAACExt);
23+
setCheck("audio/mpeg", checkMP3Ext);
2424
setCheck("audio/vnd.wave", checkWAV);
2525
setCheck("audio/ogg", checkOGG);
2626
}

0 commit comments

Comments
 (0)