diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt index 95b9790e9f..a6fe42594e 100644 --- a/src/audio_core/CMakeLists.txt +++ b/src/audio_core/CMakeLists.txt @@ -29,6 +29,7 @@ add_library(audio_core STATIC $<$:sdl2_sink.cpp sdl2_sink.h> $<$:cubeb_sink.cpp cubeb_sink.h> + $<$:hle/ffmpeg_decoder.cpp hle/ffmpeg_decoder.h hle/ffmpeg_dl.cpp hle/ffmpeg_dl.h> $<$:hle/wmf_decoder.cpp hle/wmf_decoder.h hle/wmf_decoder_utils.cpp hle/wmf_decoder_utils.h hle/adts_reader.c> ) @@ -37,6 +38,15 @@ create_target_directory_groups(audio_core) target_link_libraries(audio_core PUBLIC common core) target_link_libraries(audio_core PRIVATE SoundTouch teakra) +if(FFMPEG_FOUND) + if(UNIX) + target_link_libraries(audio_core PRIVATE FFmpeg::avcodec) + else() + target_include_directories(audio_core PRIVATE ${FFMPEG_DIR}/include) + endif() + target_compile_definitions(audio_core PUBLIC HAVE_FFMPEG) +endif() + if(ENABLE_MF) target_link_libraries(audio_core PRIVATE mf.lib mfplat.lib mfuuid.lib) target_compile_definitions(audio_core PUBLIC HAVE_MF) diff --git a/src/audio_core/hle/aac_decoder.cpp b/src/audio_core/hle/ffmpeg_decoder.cpp similarity index 91% rename from src/audio_core/hle/aac_decoder.cpp rename to src/audio_core/hle/ffmpeg_decoder.cpp index 774d1a8ee6..0bed4bbb48 100644 --- a/src/audio_core/hle/aac_decoder.cpp +++ b/src/audio_core/hle/ffmpeg_decoder.cpp @@ -2,12 +2,12 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include "audio_core/hle/aac_decoder.h" +#include "audio_core/hle/ffmpeg_decoder.h" #include "audio_core/hle/ffmpeg_dl.h" namespace AudioCore::HLE { -class AACDecoder::Impl { +class FFMPEGDecoder::Impl { public: explicit Impl(Memory::MemorySystem& memory); ~Impl(); @@ -56,13 +56,13 @@ private: std::unique_ptr decoded_frame; }; -AACDecoder::Impl::Impl(Memory::MemorySystem& memory) : memory(memory) { +FFMPEGDecoder::Impl::Impl(Memory::MemorySystem& memory) : memory(memory) { have_ffmpeg_dl = InitFFmpegDL(); } -AACDecoder::Impl::~Impl() = default; +FFMPEGDecoder::Impl::~Impl() = default; -std::optional AACDecoder::Impl::ProcessRequest(const BinaryRequest& request) { +std::optional FFMPEGDecoder::Impl::ProcessRequest(const BinaryRequest& request) { if (request.codec != DecoderCodec::AAC) { LOG_ERROR(Audio_DSP, "Got wrong codec {}", static_cast(request.codec)); return {}; @@ -87,7 +87,7 @@ std::optional AACDecoder::Impl::ProcessRequest(const BinaryReque } } -std::optional AACDecoder::Impl::Initalize(const BinaryRequest& request) { +std::optional FFMPEGDecoder::Impl::Initalize(const BinaryRequest& request) { if (initalized) { Clear(); } @@ -129,7 +129,7 @@ std::optional AACDecoder::Impl::Initalize(const BinaryRequest& r return response; } -void AACDecoder::Impl::Clear() { +void FFMPEGDecoder::Impl::Clear() { if (!have_ffmpeg_dl) { return; } @@ -140,7 +140,7 @@ void AACDecoder::Impl::Clear() { av_packet.reset(); } -std::optional AACDecoder::Impl::Decode(const BinaryRequest& request) { +std::optional FFMPEGDecoder::Impl::Decode(const BinaryRequest& request) { BinaryResponse response; response.codec = request.codec; response.cmd = request.cmd; @@ -252,11 +252,11 @@ std::optional AACDecoder::Impl::Decode(const BinaryRequest& requ return response; } -AACDecoder::AACDecoder(Memory::MemorySystem& memory) : impl(std::make_unique(memory)) {} +FFMPEGDecoder::FFMPEGDecoder(Memory::MemorySystem& memory) : impl(std::make_unique(memory)) {} -AACDecoder::~AACDecoder() = default; +FFMPEGDecoder::~FFMPEGDecoder() = default; -std::optional AACDecoder::ProcessRequest(const BinaryRequest& request) { +std::optional FFMPEGDecoder::ProcessRequest(const BinaryRequest& request) { return impl->ProcessRequest(request); } diff --git a/src/audio_core/hle/aac_decoder.h b/src/audio_core/hle/ffmpeg_decoder.h similarity index 74% rename from src/audio_core/hle/aac_decoder.h rename to src/audio_core/hle/ffmpeg_decoder.h index ec941dfb0c..190251543e 100644 --- a/src/audio_core/hle/aac_decoder.h +++ b/src/audio_core/hle/ffmpeg_decoder.h @@ -8,10 +8,10 @@ namespace AudioCore::HLE { -class AACDecoder final : public DecoderBase { +class FFMPEGDecoder final : public DecoderBase { public: - explicit AACDecoder(Memory::MemorySystem& memory); - ~AACDecoder() override; + explicit FFMPEGDecoder(Memory::MemorySystem& memory); + ~FFMPEGDecoder() override; std::optional ProcessRequest(const BinaryRequest& request) override; private: diff --git a/src/audio_core/hle/hle.cpp b/src/audio_core/hle/hle.cpp index 6482ee3e54..0bb7d44136 100644 --- a/src/audio_core/hle/hle.cpp +++ b/src/audio_core/hle/hle.cpp @@ -5,6 +5,8 @@ #include "audio_core/audio_types.h" #ifdef HAVE_MF #include "audio_core/hle/wmf_decoder.h" +#elif HAVE_FFMPEG +#include "audio_core/hle/ffmpeg_decoder.h" #endif #include "audio_core/hle/common.h" #include "audio_core/hle/decoder.h" @@ -87,8 +89,10 @@ DspHle::Impl::Impl(DspHle& parent_, Memory::MemorySystem& memory) : parent(paren #ifdef HAVE_MF decoder = std::make_unique(memory); +#elif HAVE_FFMPEG + decoder = std::make_unique(memory); #else - LOG_WARNING(Audio_DSP, "FFmpeg missing, this could lead to missing audio"); + LOG_WARNING(Audio_DSP, "No decoder found, this could lead to missing audio"); decoder = std::make_unique(); #endif // HAVE_MF diff --git a/src/tests/audio_core/decoder_tests.cpp b/src/tests/audio_core/decoder_tests.cpp index 3a197f0dc7..5a723c2996 100644 --- a/src/tests/audio_core/decoder_tests.cpp +++ b/src/tests/audio_core/decoder_tests.cpp @@ -1,7 +1,7 @@ // Copyright 2017 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#ifdef HAVE_MF +#if defined(HAVE_MF) || defined(HAVE_FFMPEG) #include #include "core/core.h" @@ -12,7 +12,11 @@ #include "core/memory.h" #include "audio_core/hle/decoder.h" +#ifdef HAVE_MF #include "audio_core/hle/wmf_decoder.h" +#elif HAVE_FFMPEG +#include "audio_core/hle/ffmpeg_decoder.h" +#endif #include "audio_fixures.h" TEST_CASE("DSP HLE Audio Decoder", "[audio_core]") { @@ -23,7 +27,11 @@ TEST_CASE("DSP HLE Audio Decoder", "[audio_core]") { SECTION("decoder should produce correct samples") { auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0)); auto decoder = +#ifdef HAVE_MF std::make_unique(*Core::System::GetInstance().memory); +#elif HAVE_FFMPEG + std::make_unique(*Core::System::GetInstance().memory); +#endif AudioCore::HLE::BinaryRequest request; request.codec = AudioCore::HLE::DecoderCodec::AAC;