From 86c41aabd7f176b6862145baf29259a539b86fa5 Mon Sep 17 00:00:00 2001 From: David Marcec Date: Sun, 29 Jul 2018 09:44:58 +1000 Subject: [PATCH] Fixed opus cmake, changed std::unique_ptr --- src/core/CMakeLists.txt | 2 +- src/core/hle/service/audio/hwopus.cpp | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 7ea1c77482..a80a6d6440 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -310,7 +310,7 @@ add_library(core STATIC create_target_directory_groups(core) target_link_libraries(core PUBLIC common PRIVATE audio_core video_core) -target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt lz4_static unicorn opus) +target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt lz4_static opus unicorn) if (ARCHITECTURE_x86_64) target_sources(core PRIVATE diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp index 3cfd1fbaa5..480f494d4f 100644 --- a/src/core/hle/service/audio/hwopus.cpp +++ b/src/core/hle/service/audio/hwopus.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include #include "common/logging/log.h" #include "core/hle/ipc_helpers.h" @@ -12,7 +13,8 @@ namespace Service::Audio { class IHardwareOpusDecoderManager final : public ServiceFramework { public: - IHardwareOpusDecoderManager(std::unique_ptr decoder, u32 sample_rate, u32 channel_count) + IHardwareOpusDecoderManager(std::unique_ptr decoder, + u32 sample_rate, u32 channel_count) : ServiceFramework("IHardwareOpusDecoderManager"), decoder(std::move(decoder)), sample_rate(sample_rate), channel_count(channel_count) { static const FunctionInfo functions[] = { @@ -62,7 +64,7 @@ private: if (decoded_sample_count * channel_count * sizeof(u16) > output.size()) return false; auto out_sample_count = - opus_decode(static_cast(*decoder), frame, hdr.sz, output.data(), + opus_decode(decoder.get(), frame, hdr.sz, output.data(), (static_cast(output.size() / sizeof(s16) / channel_count)), 0); if (out_sample_count < 0) return false; @@ -77,7 +79,7 @@ private: }; static_assert(sizeof(OpusHeader) == 0x8, "OpusHeader is an invalid size"); - std::unique_ptr decoder; + std::unique_ptr decoder; u32 sample_rate; u32 channel_count; }; @@ -112,9 +114,9 @@ void HwOpus::OpenOpusDecoder(Kernel::HLERequestContext& ctx) { size_t worker_sz = WorkerBufferSize(channel_count); ASSERT_MSG(buffer_sz < worker_sz, "Worker buffer too large"); - std::unique_ptr decoder; - decoder = std::make_unique(std::malloc(worker_sz)); - if (opus_decoder_init(static_cast(*decoder), sample_rate, channel_count)) { + std::unique_ptr decoder{ + static_cast(std::malloc(worker_sz)), std::free}; + if (opus_decoder_init(decoder.get(), sample_rate, channel_count)) { IPC::ResponseBuilder rb{ctx, 2}; // TODO(ogniK): Use correct error code rb.Push(ResultCode(-1));