Skip to content

Commit cb2f082

Browse files
committed
MultiDecoder
1 parent dc7197e commit cb2f082

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/AudioTools/AudioCodecs/MultiDecoder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class MultiDecoder : public AudioDecoder {
5757
bool result = false;
5858
// do nothing if no change
5959
if (StrView(mime).equals(actual_decoder.mime)) {
60+
is_first = false;
6061
return true;
6162
}
6263
// close actual decoder
@@ -77,6 +78,7 @@ class MultiDecoder : public AudioDecoder {
7778
result = true;
7879
}
7980
}
81+
is_first = false;
8082
return result;
8183
}
8284

src/AudioTools/CoreAudio/MimeDetector.h

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#pragma once
2+
#include "AudioTools/CoreAudio/AudioBasic/StrView.h"
23

34
namespace audio_tools {
45

6+
57
/**
68
* @brief Logic to detemine the mime type from the content.
79
* By default the following mime types are supported (audio/aac, audio/mpeg,
@@ -59,24 +61,33 @@ class MimeDetector {
5961
}
6062
}
6163

64+
static bool findSyncWord(uint8_t* buf, int nBytes, uint8_t SYNCWORDH,
65+
uint8_t SYNCWORDL) {
66+
for (int i = 0; i < nBytes - 1; i++) {
67+
if ((buf[i + 0] & SYNCWORDH) == SYNCWORDH &&
68+
(buf[i + 1] & SYNCWORDL) == SYNCWORDL)
69+
return true;
70+
}
71+
return false;
72+
}
73+
6274
/// Default logic which supports aac, mp3, wav and ogg
6375
static const char* defaultMimeDetector(uint8_t* data, size_t len) {
6476
const char* mime = nullptr;
65-
if (len > 4) {
66-
const uint8_t* start = (const uint8_t*)data;
67-
if (start[0] == 0xFF && (start[1] == 0xF0 || start[1] == 0xF1 || start[1] == 0xF9)) {
68-
mime = "audio/aac";
69-
} else if (memcmp(start, "ID3", 3) == 0 || start[0] == 0xFF ||
70-
start[1] == 0xFE) {
71-
mime = "audio/mpeg";
72-
} else if (memcmp(start, "RIFF", 4) == 0) {
73-
mime = "audio/vnd.wave";
74-
} else if (memcmp(start, "OggS", 4) == 0) {
75-
mime = "audio/ogg";
76-
}
77+
if (memcmp(data, "ID3", 3) || (data[0] == (char)0xff && (data[1] == (char)0xfb || data[1] == (char)0xe3 || data[1] == (char)0xe2))) {
78+
mime = "audio/mpeg";
79+
} else if (data[0] == (char)0xff && (data[1] == (char)0xf1 || data[1] == (char)0xf9)) {
80+
mime = "audio/aac";
81+
} else if (memcmp(data, "RIFF", 4) == 0) {
82+
mime = "audio/vnd.wave";
83+
} else if (memcmp(data, "OggS", 4) == 0) {
84+
mime = "audio/ogg";
7785
}
86+
7887
if (mime != nullptr) {
7988
LOGI("Determined mime: %s", mime);
89+
} else {
90+
LOGW("Could not determine mime");
8091
}
8192
return mime;
8293
}

0 commit comments

Comments
 (0)