44 virtual const char*
mime() = 0;
95 size_t write(uint8_t* data,
size_t len) {
102 void setCheck(
const char*
mime,
bool (*check)(uint8_t* start,
size_t len),
103 bool isActvie =
true) {
105 for (
int j = 0; j <
checks.size(); j++) {
107 if (mime_str.equals(l_check.
mime)) {
108 l_check.
check = check;
115 checks.push_back(check_to_add);
116 LOGI(
"MimeDetector for %s: %s",
mime, isActvie ?
"active" :
"inactive");
130 return start[0] == 0xFF &&
131 (start[1] == 0xF0 || start[1] == 0xF1 || start[1] == 0xF9);
136 if (memcmp(start + 4,
"ftypM4A", 7) == 0) {
147 if (aac.
isValid(start + pos, len - pos)) {
154 return memcmp(start,
"ID3", 3) == 0 ||
155 (start[0] == 0xFF && ((start[1] & 0xE0) == 0xE0));
160 return mp3.
isValid(start, len);
164 if (memcmp(start,
"RIFF", 4) != 0)
return false;
166 header.
write(start, len);
167 if (!header.
parse())
return false;
175 return memcmp(start,
"RIFF", 4) == 0;
179 return memcmp(start,
"OggS", 4) == 0;
183 if (len < 4)
return false;
186 if (memcmp(start,
"fLaC", 4) == 0) {
195 if (len >= 32 && memcmp(start,
"OggS", 4) == 0) {
198 for (
size_t i = 4; i < len - 4 && i < 64; i++) {
199 if (memcmp(start + i,
"FLAC", 4) == 0) {
203 if (i < len - 5 && start[i] == 0x7F &&
204 memcmp(start + i + 1,
"FLAC", 4) == 0) {
227 if (len >= 32 && memcmp(start,
"OggS", 4) == 0) {
230 for (
size_t i = 4; i < len - 8 && i < 80; i++) {
231 if (memcmp(start + i,
"OpusHead", 8) == 0) {
254 if (len >= 32 && memcmp(start,
"OggS", 4) == 0) {
257 for (
size_t i = 4; i < len - 7 && i < 80; i++) {
258 if (start[i] == 0x01 && memcmp(start + i + 1,
"vorbis", 6) == 0) {
269 if (len < 189)
return start[0] == 0x47;
271 return start[0] == 0x47 && start[188] == 0x47;
276 if (len < 4)
return false;
277 return memcmp(start,
"DSD ", 4) == 0;
282 return memcmp(start,
"PSID", 4) == 0 || memcmp(start,
"RSID", 4) == 0;
285 static bool checkM4A(uint8_t* header,
size_t len) {
286 if (len < 12)
return false;
289 if (memcmp(header,
"ID3", 3) == 0)
return false;
292 if (memcmp(header + 4,
"mdat", 4) != 0)
return true;
295 if (memcmp(header + 4,
"ftyp", 4) != 0)
return false;
298 if (memcmp(header + 8,
"M4A ", 4) == 0 ||
299 memcmp(header + 8,
"mp42", 4) == 0 ||
300 memcmp(header + 8,
"isom", 4) == 0)
312 for (
auto& check :
checks) {
314 check.is_active = active;
315 LOGI(
"MimeDetector for %s: %s", check.mime,
316 check.is_active ?
"active" :
"inactive");
333 bool (*
check)(uint8_t* data,
size_t len) =
nullptr;
360 for (
int j = 0; j <
checks.size(); j++) {
#define TRACED()
Definition AudioLoggerIDF.h:31
#define LOGI(...)
Definition AudioLoggerIDF.h:28