@@ -29,6 +29,7 @@ class MimeDetector {
29
29
setCheck (" audio/prs.sid" , checkSID);
30
30
setCheck (" audio/mpeg" , checkMP3Ext);
31
31
setCheck (" audio/aac" , checkAACExt);
32
+ setCheck (" audio/m4a" , checkM4A);
32
33
}
33
34
34
35
bool begin () {
@@ -65,9 +66,7 @@ class MimeDetector {
65
66
66
67
// / Provides the actual mime type, that was determined from the first
67
68
// / available data
68
- const char * mime () {
69
- return actual_mime;
70
- }
69
+ const char * mime () { return actual_mime; }
71
70
72
71
static bool checkAAC (uint8_t * start, size_t len) {
73
72
return start[0 ] == 0xFF &&
@@ -76,7 +75,7 @@ class MimeDetector {
76
75
77
76
static bool checkAACExt (uint8_t * start, size_t len) {
78
77
// checking logic for files
79
- if (memcmp (start+ 4 , " ftypM4A" , 7 ) == 0 ) {
78
+ if (memcmp (start + 4 , " ftypM4A" , 7 ) == 0 ) {
80
79
return true ;
81
80
}
82
81
// check for streaming
@@ -87,7 +86,7 @@ class MimeDetector {
87
86
return false ;
88
87
}
89
88
// make sure that it is not an mp3
90
- if (aac.isValid (start+ pos, len- pos)) {
89
+ if (aac.isValid (start + pos, len - pos)) {
91
90
return false ;
92
91
}
93
92
return true ;
@@ -123,6 +122,21 @@ class MimeDetector {
123
122
return memcmp (start, " PSID" , 4 ) == 0 || memcmp (start, " RSID" , 4 ) == 0 ;
124
123
}
125
124
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
+
126
140
// / Provides the default mime type if no mime could be determined
127
141
void setDefaultMime (const char * mime) { default_mime = mime; }
128
142
0 commit comments