From fb51a655b8042b8ad83b2c8eb973e83d24a7ad69 Mon Sep 17 00:00:00 2001 From: David Marcec Date: Wed, 29 Apr 2020 00:19:07 +1000 Subject: [PATCH 1/2] Audin:u ListAudioIns, OpenAudioIn, ListAudioInsAuto, OpenAudioInAuto, ListAudioInsAutoFiltered, OpenAudioInProtocolSpecified Closes #2874 --- src/core/hle/service/audio/audin_u.cpp | 69 ++++++++++++++++++++++++-- src/core/hle/service/audio/audin_u.h | 29 +++++++++++ 2 files changed, 93 insertions(+), 5 deletions(-) diff --git a/src/core/hle/service/audio/audin_u.cpp b/src/core/hle/service/audio/audin_u.cpp index d7f1d348d..bce7e61dd 100644 --- a/src/core/hle/service/audio/audin_u.cpp +++ b/src/core/hle/service/audio/audin_u.cpp @@ -2,6 +2,9 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include "common/logging/log.h" +#include "core/hle/ipc_helpers.h" +#include "core/hle/kernel/hle_ipc.h" #include "core/hle/service/audio/audin_u.h" namespace Service::Audio { @@ -36,11 +39,12 @@ public: AudInU::AudInU() : ServiceFramework("audin:u") { // clang-format off static const FunctionInfo functions[] = { - {0, nullptr, "ListAudioIns"}, - {1, nullptr, "OpenAudioIn"}, - {2, nullptr, "Unknown"}, - {3, nullptr, "OpenAudioInAuto"}, - {4, nullptr, "ListAudioInsAuto"}, + {0, &AudInU::ListAudioIns, "ListAudioIns"}, + {1, &AudInU::OpenAudioIn, "OpenAudioIn"}, + {2, &AudInU::ListAudioIns, "ListAudioInsAuto"}, + {3, &AudInU::OpenAudioIn, "OpenAudioInAuto"}, + {4, &AudInU::ListAudioInsAutoFiltered, "ListAudioInsAutoFiltered"}, + {5, &AudInU::OpenAudioInProtocolSpecified, "OpenAudioInProtocolSpecified"}, }; // clang-format on @@ -49,4 +53,59 @@ AudInU::AudInU() : ServiceFramework("audin:u") { AudInU::~AudInU() = default; +void AudInU::ListAudioIns(Kernel::HLERequestContext& ctx) { + LOG_DEBUG(Service_Audio, "called"); + const std::size_t count = ctx.GetWriteBufferSize() / sizeof(AudioInDeviceName); + + std::vector device_names; + const std::size_t device_count = std::min(count, audio_device_names.size()); + + for (std::size_t i = 0; i < device_count; i++) { + const auto& device_name = audio_device_names[i]; + auto& entry = device_names.emplace_back(); + device_name.copy(entry.data(), device_name.size()); + } + + ctx.WriteBuffer(device_names); + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(RESULT_SUCCESS); + rb.Push(static_cast(device_names.size())); +} + +void AudInU::ListAudioInsAutoFiltered(Kernel::HLERequestContext& ctx) { + LOG_DEBUG(Service_Audio, "called"); + const u32 device_count = 0; + + // Since we don't actually use any other audio input devices, we return 0 devices. Filtered + // device listing just omits the default input device + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(RESULT_SUCCESS); + rb.Push(static_cast(device_count)); +} + +void AudInU::OpenInOutImpl(Kernel::HLERequestContext& ctx) { + AudInOutParams params{}; + params.channel_count = 2; + params.sample_format = SampleFormat::PCM16; + params.sample_rate = 48000; + params.state = State::Started; + + IPC::ResponseBuilder rb{ctx, 6, 0, 1}; + rb.Push(RESULT_SUCCESS); + rb.PushRaw(params); + rb.PushIpcInterface(); +} + +void AudInU::OpenAudioIn(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service_Audio, "called"); + OpenInOutImpl(ctx); +} + +void AudInU::OpenAudioInProtocolSpecified(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service_Audio, "called"); + OpenInOutImpl(ctx); +} + } // namespace Service::Audio diff --git a/src/core/hle/service/audio/audin_u.h b/src/core/hle/service/audio/audin_u.h index 0538b9560..a599f4a64 100644 --- a/src/core/hle/service/audio/audin_u.h +++ b/src/core/hle/service/audio/audin_u.h @@ -16,6 +16,35 @@ class AudInU final : public ServiceFramework { public: explicit AudInU(); ~AudInU() override; + +private: + enum class SampleFormat : u32_le { + PCM16 = 2, + }; + + enum class State : u32_le { + Started = 0, + Stopped = 1, + }; + + struct AudInOutParams { + u32_le sample_rate{}; + u32_le channel_count{}; + SampleFormat sample_format{}; + State state{}; + }; + static_assert(sizeof(AudInOutParams) == 0x10, "AudInOutParams is an invalid size"); + + using AudioInDeviceName = std::array; + static constexpr std::array audio_device_names{{ + "BuiltInHeadset", + }}; + + void ListAudioIns(Kernel::HLERequestContext& ctx); + void ListAudioInsAutoFiltered(Kernel::HLERequestContext& ctx); + void OpenInOutImpl(Kernel::HLERequestContext& ctx); + void OpenAudioIn(Kernel::HLERequestContext& ctx); + void OpenAudioInProtocolSpecified(Kernel::HLERequestContext& ctx); }; } // namespace Service::Audio From 1276e425d2e1cd0f80c6b7872a56956d5e2a985b Mon Sep 17 00:00:00 2001 From: David Marcec Date: Wed, 29 Apr 2020 00:43:05 +1000 Subject: [PATCH 2/2] marked stubs --- src/core/hle/service/audio/audin_u.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/hle/service/audio/audin_u.cpp b/src/core/hle/service/audio/audin_u.cpp index bce7e61dd..3e2299426 100644 --- a/src/core/hle/service/audio/audin_u.cpp +++ b/src/core/hle/service/audio/audin_u.cpp @@ -57,8 +57,9 @@ void AudInU::ListAudioIns(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); const std::size_t count = ctx.GetWriteBufferSize() / sizeof(AudioInDeviceName); - std::vector device_names; const std::size_t device_count = std::min(count, audio_device_names.size()); + std::vector device_names; + device_names.reserve(device_count); for (std::size_t i = 0; i < device_count; i++) { const auto& device_name = audio_device_names[i]; @@ -75,7 +76,7 @@ void AudInU::ListAudioIns(Kernel::HLERequestContext& ctx) { void AudInU::ListAudioInsAutoFiltered(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); - const u32 device_count = 0; + constexpr u32 device_count = 0; // Since we don't actually use any other audio input devices, we return 0 devices. Filtered // device listing just omits the default input device @@ -99,12 +100,12 @@ void AudInU::OpenInOutImpl(Kernel::HLERequestContext& ctx) { } void AudInU::OpenAudioIn(Kernel::HLERequestContext& ctx) { - LOG_WARNING(Service_Audio, "called"); + LOG_WARNING(Service_Audio, "(STUBBED) called"); OpenInOutImpl(ctx); } void AudInU::OpenAudioInProtocolSpecified(Kernel::HLERequestContext& ctx) { - LOG_WARNING(Service_Audio, "called"); + LOG_WARNING(Service_Audio, "(STUBBED) called"); OpenInOutImpl(ctx); }