From 1b8e3801b2444f6e466e1b7c09cfc51605e80fb3 Mon Sep 17 00:00:00 2001 From: Frederik M J Vestre Date: Thu, 26 Jul 2012 14:38:32 +0200 Subject: Initial opus codec support Synchronised with opus repo on github (https://github.com/freqmod/rockbox-opus) Status: * Seeking ported from speex, but fails on some cases (e.g. seek to granule 0) * ReplayGain parsing needs to be reworked, we do vorbis-style replaygain now. http://wiki.xiph.org/OggOpus#Comment_Header explicitly forbids these in favour of R128_TRACK_GAIN tag. * No optimisation yet, source files still nearly identical to opus upstream * Multi-stream opus files may not be parsed correctly Change-Id: Ia66f1027dc1d288083e3c57b2816700078376f9a Reviewed-on: http://gerrit.rockbox.org/300 Reviewed-by: Bertrik Sikken Tested-by: Bertrik Sikken --- lib/rbcodec/metadata/metadata.c | 3 +++ lib/rbcodec/metadata/metadata.h | 1 + lib/rbcodec/metadata/ogg.c | 14 ++++++++++++++ lib/rbcodec/metadata/vorbis.c | 18 +++++++++++++++++- 4 files changed, 35 insertions(+), 1 deletion(-) (limited to 'lib/rbcodec/metadata') diff --git a/lib/rbcodec/metadata/metadata.c b/lib/rbcodec/metadata/metadata.c index 668ece97cf..5caf933b55 100644 --- a/lib/rbcodec/metadata/metadata.c +++ b/lib/rbcodec/metadata/metadata.c @@ -233,6 +233,9 @@ const struct afmt_entry audio_formats[AFMT_NUM_CODECS] = /* KSS (MSX computer KSS Music File) */ [AFMT_KSS] = AFMT_ENTRY("KSS", "kss", NULL, get_kss_metadata, "kss\0"), + /* Opus */ + [AFMT_OPUS] = + AFMT_ENTRY("Opus", "opus", NULL, get_ogg_metadata, "opus\0"), #endif }; diff --git a/lib/rbcodec/metadata/metadata.h b/lib/rbcodec/metadata/metadata.h index 4b4a8337fb..18cfce7523 100644 --- a/lib/rbcodec/metadata/metadata.h +++ b/lib/rbcodec/metadata/metadata.h @@ -89,6 +89,7 @@ enum AFMT_SGC, /* SGC (Sega Master System, Game Gear, Coleco Vision Sound Format) */ AFMT_VGM, /* VGM (Video Game Music Format) */ AFMT_KSS, /* KSS (MSX computer KSS Music File) */ + AFMT_OPUS, /* Opus (see http://www.opus-codec.org ) */ #endif /* add new formats at any index above this line to have a sensible order - diff --git a/lib/rbcodec/metadata/ogg.c b/lib/rbcodec/metadata/ogg.c index f3231c6f8a..5d302442ed 100644 --- a/lib/rbcodec/metadata/ogg.c +++ b/lib/rbcodec/metadata/ogg.c @@ -102,6 +102,20 @@ bool get_ogg_metadata(int fd, struct mp3entry* id3) return false; } } + else if (memcmp(&buf[28], "OpusHead", 8) == 0) + { + id3->codectype = AFMT_OPUS; + id3->frequency = 48000; + id3->vbr = true; + +// FIXME handle an actual channel mapping table + /* Comments are in second Ogg page (byte 108 onwards for Speex) */ + if (lseek(fd, 47, SEEK_SET) < 0) + { + DEBUGF("Couldnotseektoogg"); + return false; + } + } else { /* Unsupported format, try to print the marker, catches Ogg/FLAC at least */ diff --git a/lib/rbcodec/metadata/vorbis.c b/lib/rbcodec/metadata/vorbis.c index d020808c56..66aa85022f 100644 --- a/lib/rbcodec/metadata/vorbis.c +++ b/lib/rbcodec/metadata/vorbis.c @@ -250,7 +250,7 @@ static bool file_init(struct file* file, int fd, int type, int remaining) memset(file, 0, sizeof(*file)); file->fd = fd; - if (type == AFMT_OGG_VORBIS || type == AFMT_SPEEX) + if (type == AFMT_OGG_VORBIS || type == AFMT_SPEEX || type == AFMT_OPUS) { if (!file_read_page_header(file)) { @@ -276,6 +276,22 @@ static bool file_init(struct file* file, int fd, int type, int remaining) return false; } } + else if (type == AFMT_OPUS) + { + char buffer[8]; + + /* Read comment header */ + if (file_read(file, buffer, sizeof(buffer)) < (ssize_t) sizeof(buffer)) + { + return false; + } + + /* Should be equal to "OpusTags" */ + if (memcmp(buffer, "OpusTags", 8) != 0) + { + return false; + } + } else if (type == AFMT_FLAC) { file->packet_remaining = remaining; -- cgit v1.2.3