Skip to content

Commit 43d8da6

Browse files
committed
M4A support
1 parent 91e07e5 commit 43d8da6

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/AudioTools/AudioCodecs/AudioCodecsBase.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ class AudioDecoder : public AudioWriter, public AudioInfoSource {
6565
return p_print;
6666
}
6767

68+
/// Some decoders need e.g. a magic cookie to provide the relevant info for decoding
69+
virtual bool setCodecInfo(const uint8_t* data, size_t len){
70+
LOGE("not implemented");
71+
}
72+
6873
protected:
6974
Print *p_print = nullptr;
7075
AudioInfo info;

src/AudioTools/CoreAudio/AudioMetaData/MimeDetector.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class MimeDetector {
2929
setCheck("audio/prs.sid", checkSID);
3030
setCheck("audio/mpeg", checkMP3Ext);
3131
setCheck("audio/aac", checkAACExt);
32+
setCheck("audio/m4a", checkM4A);
3233
}
3334

3435
bool begin() {
@@ -65,9 +66,7 @@ class MimeDetector {
6566

6667
/// Provides the actual mime type, that was determined from the first
6768
/// available data
68-
const char* mime() {
69-
return actual_mime;
70-
}
69+
const char* mime() { return actual_mime; }
7170

7271
static bool checkAAC(uint8_t* start, size_t len) {
7372
return start[0] == 0xFF &&
@@ -76,7 +75,7 @@ class MimeDetector {
7675

7776
static bool checkAACExt(uint8_t* start, size_t len) {
7877
// checking logic for files
79-
if (memcmp(start+4, "ftypM4A", 7) == 0) {
78+
if (memcmp(start + 4, "ftypM4A", 7) == 0) {
8079
return true;
8180
}
8281
// check for streaming
@@ -87,7 +86,7 @@ class MimeDetector {
8786
return false;
8887
}
8988
// make sure that it is not an mp3
90-
if (aac.isValid(start+pos, len-pos)) {
89+
if (aac.isValid(start + pos, len - pos)) {
9190
return false;
9291
}
9392
return true;
@@ -123,6 +122,21 @@ class MimeDetector {
123122
return memcmp(start, "PSID", 4) == 0 || memcmp(start, "RSID", 4) == 0;
124123
}
125124

125+
static bool checkM4A(uint8_t* header, size_t len) {
126+
if (len < 12) return false;
127+
128+
// Check for "ftyp" at offset 4
129+
if (memcmp(header + 4, "ftyp", 4) != 0) return false;
130+
131+
// Check for "M4A " or similar major brand
132+
if (memcmp(header + 8, "M4A ", 4) == 0 ||
133+
memcmp(header + 8, "mp42", 4) == 0 ||
134+
memcmp(header + 8, "isom", 4) == 0)
135+
return true;
136+
137+
return false;
138+
}
139+
126140
/// Provides the default mime type if no mime could be determined
127141
void setDefaultMime(const char* mime) { default_mime = mime; }
128142

0 commit comments

Comments
 (0)