#include "AudioCodecs.h" #include #include #include using namespace bell; #ifdef BELL_CODEC_AAC #include "AACDecoder.h" static std::shared_ptr codecAac; #endif #ifdef BELL_CODEC_MP3 #include "MP3Decoder.h" static std::shared_ptr codecMp3; #endif #ifdef BELL_CODEC_VORBIS #include "VorbisDecoder.h" static std::shared_ptr codecVorbis; #endif #ifdef BELL_CODEC_OPUS #include "OPUSDecoder.h" static std::shared_ptr codecOpus; #endif std::map> customCodecs; std::shared_ptr AudioCodecs::getCodec(AudioCodec type) { if (customCodecs.find(type) != customCodecs.end()) return customCodecs[type]; switch (type) { #ifdef BELL_CODEC_AAC case AudioCodec::AAC: if (codecAac) return codecAac; codecAac = std::make_shared(); return codecAac; #endif #ifdef BELL_CODEC_MP3 case AudioCodec::MP3: if (codecMp3) return codecMp3; codecMp3 = std::make_shared(); return codecMp3; #endif #ifdef BELL_CODEC_VORBIS case AudioCodec::VORBIS: if (codecVorbis) return codecVorbis; codecVorbis = std::make_shared(); return codecVorbis; #endif #ifdef BELL_CODEC_OPUS case AudioCodec::OPUS: if (codecOpus) return codecOpus; codecOpus = std::make_shared(); return codecOpus; #endif default: return nullptr; } } std::shared_ptr AudioCodecs::getCodec(AudioContainer* container) { auto codec = getCodec(container->getCodec()); if (codec != nullptr) { codec->setup(container); } return codec; } void AudioCodecs::addCodec(AudioCodec type, const std::shared_ptr& codec) { customCodecs[type] = codec; }