59 size_t write(uint8_t* data,
size_t len) {
66 void setCheck(
const char*
mime,
bool (*check)(uint8_t* start,
size_t len),
67 bool isActvie =
true) {
69 for (
int j = 0; j <
checks.size(); j++) {
71 if (mime_str.equals(l_check.
mime)) {
72 l_check.
check = check;
79 checks.push_back(check_to_add);
80 LOGI(
"MimeDetector for %s: %s",
mime, isActvie ?
"active" :
"inactive");
93 static bool checkAAC(uint8_t* start,
size_t len) {
94 return start[0] == 0xFF &&
95 (start[1] == 0xF0 || start[1] == 0xF1 || start[1] == 0xF9);
100 if (memcmp(start + 4,
"ftypM4A", 7) == 0) {
112 if (!aac.
isValid(start + pos, len - pos)) {
125 return memcmp(start,
"ID3", 3) == 0 ||
126 (start[0] == 0xFF && ((start[1] & 0xE0) == 0xE0));
131 return mp3.
isValid(start, len);
135 if (memcmp(start,
"RIFF", 4) != 0)
return false;
137 header.
write(start, len);
138 if (!header.
parse())
return false;
146 return memcmp(start,
"RIFF", 4) == 0;
150 return memcmp(start,
"OggS", 4) == 0;
154 if (len < 4)
return false;
157 if (memcmp(start,
"fLaC", 4) == 0) {
166 if (len >= 32 && memcmp(start,
"OggS", 4) == 0) {
169 for (
size_t i = 4; i < len - 4 && i < 64; i++) {
170 if (memcmp(start + i,
"FLAC", 4) == 0) {
174 if (i < len - 5 && start[i] == 0x7F &&
175 memcmp(start + i + 1,
"FLAC", 4) == 0) {
198 if (len >= 32 && memcmp(start,
"OggS", 4) == 0) {
201 for (
size_t i = 4; i < len - 8 && i < 80; i++) {
202 if (memcmp(start + i,
"OpusHead", 8) == 0) {
225 if (len >= 32 && memcmp(start,
"OggS", 4) == 0) {
228 for (
size_t i = 4; i < len - 7 && i < 80; i++) {
229 if (start[i] == 0x01 && memcmp(start + i + 1,
"vorbis", 6) == 0) {
240 if (len < 189)
return start[0] == 0x47;
242 return start[0] == 0x47 && start[188] == 0x47;
247 if (len < 4)
return false;
248 return memcmp(start,
"DSD ", 4) == 0;
253 return memcmp(start,
"PSID", 4) == 0 || memcmp(start,
"RSID", 4) == 0;
256 static bool checkM4A(uint8_t* header,
size_t len) {
257 if (len < 12)
return false;
260 if (memcmp(header,
"ID3", 3) == 0)
return false;
263 if (memcmp(header + 4,
"mdat", 4) != 0)
return true;
266 if (memcmp(header + 4,
"ftyp", 4) != 0)
return false;
269 if (memcmp(header + 8,
"M4A ", 4) == 0 ||
270 memcmp(header + 8,
"mp42", 4) == 0 ||
271 memcmp(header + 8,
"isom", 4) == 0)
283 for (
auto& check :
checks) {
285 check.is_active = active;
286 LOGI(
"MimeDetector for %s: %s", check.mime,
287 check.is_active ?
"active" :
"inactive");
304 bool (*
check)(uint8_t* data,
size_t len) =
nullptr;
331 for (
int j = 0; j <
checks.size(); j++) {
#define TRACED()
Definition AudioLoggerIDF.h:31
#define LOGI(...)
Definition AudioLoggerIDF.h:28