diff --git a/input/LibSndfileSource.cpp b/input/LibSndfileSource.cpp index e723eb4d..0e813ed5 100644 --- a/input/LibSndfileSource.cpp +++ b/input/LibSndfileSource.cpp @@ -1,5 +1,7 @@ #include "LibSndfileSource.h" #include +#include +#include #include "taglibhelper.h" #include "win32util.h" #include "metadata.h" @@ -139,6 +141,7 @@ LibSndfileSource::LibSndfileSource(const std::shared_ptr &fp) { SF_FORMAT_ALAC_24, 24, kAudioFormatFlagIsSignedInteger }, { SF_FORMAT_ALAC_32, 32, kAudioFormatFlagIsSignedInteger }, { SF_FORMAT_VORBIS, 32, kAudioFormatFlagIsFloat }, + { SF_FORMAT_OPUS, 32, kAudioFormatFlagIsFloat }, { 0, 0, 0 } }, *p = mapping; for (; p->subtype && p->subtype != subformat; ++p) @@ -173,7 +176,7 @@ LibSndfileSource::LibSndfileSource(const std::shared_ptr &fp) else if (m_format_name == "caf") m_tags = CAF::fetchTags(fileno(m_fp.get())); else if (m_format_name == "oga") - fetchVorbisTags(); + fetchVorbisTags(p->subtype); } void LibSndfileSource::seekTo(int64_t count) @@ -190,17 +193,24 @@ int64_t LibSndfileSource::getPosition() return pos; } -void LibSndfileSource::fetchVorbisTags() +void LibSndfileSource::fetchVorbisTags(int codec) { int fd = fileno(m_fp.get()); util::FilePositionSaver _(fd); lseek(fd, 0, SEEK_SET); TagLibX::FDIOStreamReader stream(fd); - TagLib::Ogg::Vorbis::File file(&stream, false); - + std::unique_ptr file; + if (codec == SF_FORMAT_OPUS) + file = std::make_unique(&stream, false); + else if (codec == SF_FORMAT_VORBIS) + file = std::make_unique(&stream, false); + else if (codec == SF_FORMAT_FLAC) + file = std::make_unique(&stream, false); + else + return; std::map tags; - auto tag = file.tag(); + auto tag = dynamic_cast(file->tag()); auto &map = tag->fieldListMap(); for (auto it = map.begin(); it != map.end(); ++it) { std::string key = it->first.toCString(); diff --git a/input/LibSndfileSource.h b/input/LibSndfileSource.h index 3a26fe95..369b5510 100644 --- a/input/LibSndfileSource.h +++ b/input/LibSndfileSource.h @@ -72,7 +72,7 @@ class LibSndfileSource: public ISeekableSource, public ITagParser int64_t getPosition(); const std::map &getTags() const { return m_tags; } private: - void fetchVorbisTags(); + void fetchVorbisTags(int codec); }; #endif