Skip to content

Commit cfa4810

Browse files
committed
MimeDetector multiple codecs for ogg
1 parent 9703ef4 commit cfa4810

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/AudioTools/CoreAudio/AudioMetaData/MimeDetector.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class MimeDetector : public MimeSource {
6161
setCheck("audio/vnd.wave", checkWAV);
6262
setCheck("audio/flac", checkFLAC);
6363
setCheck("audio/ogg; codecs=flac", checkOggFLAC);
64+
setCheck("audio/ogg; codecs=opus", checkOggOpus);
65+
setCheck("audio/ogg; codec=vorbis", checkOggVorbis);
6466
setCheck("audio/ogg", checkOGG);
6567
setCheck("video/MP2T", checkMP2T);
6668
setCheck("audio/prs.sid", checkSID);
@@ -177,6 +179,60 @@ class MimeDetector : public MimeSource {
177179
return false;
178180
}
179181

182+
/**
183+
* @brief Checks for OGG Opus format
184+
*
185+
* Detects OGG containers that contain Opus-encoded audio data.
186+
* Opus in OGG streams typically have "OpusHead" as the codec identifier
187+
* in the first page of the stream.
188+
*
189+
* @param start Pointer to the data buffer
190+
* @param len Length of the data buffer
191+
* @return true if OGG Opus format is detected, false otherwise
192+
*/
193+
static bool checkOggOpus(uint8_t* start, size_t len) {
194+
// Check for OGG Opus - OGG container with Opus content
195+
// OGG starts with "OggS" and contains Opus codec identifier
196+
if (len >= 32 && memcmp(start, "OggS", 4) == 0) {
197+
// Look for Opus signature within the first OGG page
198+
// Opus in OGG typically has "OpusHead" as the codec identifier
199+
for (size_t i = 4; i < len - 8 && i < 80; i++) {
200+
if (memcmp(start + i, "OpusHead", 8) == 0) {
201+
return true;
202+
}
203+
}
204+
}
205+
206+
return false;
207+
}
208+
209+
/**
210+
* @brief Checks for OGG Vorbis format
211+
*
212+
* Detects OGG containers that contain Vorbis-encoded audio data.
213+
* Vorbis in OGG streams have "\x01vorbis" as the codec identifier
214+
* in the first page of the stream.
215+
*
216+
* @param start Pointer to the data buffer
217+
* @param len Length of the data buffer
218+
* @return true if OGG Vorbis format is detected, false otherwise
219+
*/
220+
static bool checkOggVorbis(uint8_t* start, size_t len) {
221+
// Check for OGG Vorbis - OGG container with Vorbis content
222+
// OGG starts with "OggS" and contains Vorbis codec identifier
223+
if (len >= 32 && memcmp(start, "OggS", 4) == 0) {
224+
// Look for Vorbis signature within the first OGG page
225+
// Vorbis in OGG has "\x01vorbis" as the codec identifier
226+
for (size_t i = 4; i < len - 7 && i < 80; i++) {
227+
if (start[i] == 0x01 && memcmp(start + i + 1, "vorbis", 6) == 0) {
228+
return true;
229+
}
230+
}
231+
}
232+
233+
return false;
234+
}
235+
180236
/// MPEG-2 TS Byte Stream Format
181237
static bool checkMP2T(uint8_t* start, size_t len) {
182238
if (len < 189) return start[0] == 0x47;

0 commit comments

Comments
 (0)