diff options
| author | 2024-02-20 21:17:59 -0500 | |
|---|---|---|
| committer | 2024-02-20 22:15:38 -0500 | |
| commit | c575a85233cfea2e0935a5609e4e13d980a8c28f (patch) | |
| tree | ebfb39a093a2042a8d15769532089a83c883d21a | |
| parent | audio: rewrite IHardwareOpusDecoderManager (diff) | |
| download | yuzu-c575a85233cfea2e0935a5609e4e13d980a8c28f.tar.gz yuzu-c575a85233cfea2e0935a5609e4e13d980a8c28f.tar.xz yuzu-c575a85233cfea2e0935a5609e4e13d980a8c28f.zip | |
audio: rewrite IAudioDevice
| -rw-r--r-- | src/audio_core/renderer/audio_device.cpp | 14 | ||||
| -rw-r--r-- | src/audio_core/renderer/audio_device.h | 6 | ||||
| -rw-r--r-- | src/common/string_util.cpp | 4 | ||||
| -rw-r--r-- | src/common/string_util.h | 1 | ||||
| -rw-r--r-- | src/core/hle/service/audio/audio_device.cpp | 180 | ||||
| -rw-r--r-- | src/core/hle/service/audio/audio_device.h | 41 | ||||
| -rw-r--r-- | src/core/hle/service/audio/audio_in_manager.cpp | 3 | ||||
| -rw-r--r-- | src/core/hle/service/audio/audio_out_manager.cpp | 4 |
8 files changed, 127 insertions, 126 deletions
diff --git a/src/audio_core/renderer/audio_device.cpp b/src/audio_core/renderer/audio_device.cpp index 2d9bf82bb..5be5594f6 100644 --- a/src/audio_core/renderer/audio_device.cpp +++ b/src/audio_core/renderer/audio_device.cpp | |||
| @@ -36,8 +36,7 @@ AudioDevice::AudioDevice(Core::System& system, const u64 applet_resource_user_id | |||
| 36 | : output_sink{system.AudioCore().GetOutputSink()}, | 36 | : output_sink{system.AudioCore().GetOutputSink()}, |
| 37 | applet_resource_user_id{applet_resource_user_id_}, user_revision{revision} {} | 37 | applet_resource_user_id{applet_resource_user_id_}, user_revision{revision} {} |
| 38 | 38 | ||
| 39 | u32 AudioDevice::ListAudioDeviceName(std::vector<AudioDeviceName>& out_buffer, | 39 | u32 AudioDevice::ListAudioDeviceName(std::span<AudioDeviceName> out_buffer) const { |
| 40 | const size_t max_count) const { | ||
| 41 | std::span<const AudioDeviceName> names{}; | 40 | std::span<const AudioDeviceName> names{}; |
| 42 | 41 | ||
| 43 | if (CheckFeatureSupported(SupportTags::AudioUsbDeviceOutput, user_revision)) { | 42 | if (CheckFeatureSupported(SupportTags::AudioUsbDeviceOutput, user_revision)) { |
| @@ -46,19 +45,18 @@ u32 AudioDevice::ListAudioDeviceName(std::vector<AudioDeviceName>& out_buffer, | |||
| 46 | names = device_names; | 45 | names = device_names; |
| 47 | } | 46 | } |
| 48 | 47 | ||
| 49 | const u32 out_count{static_cast<u32>(std::min(max_count, names.size()))}; | 48 | const u32 out_count{static_cast<u32>(std::min(out_buffer.size(), names.size()))}; |
| 50 | for (u32 i = 0; i < out_count; i++) { | 49 | for (u32 i = 0; i < out_count; i++) { |
| 51 | out_buffer.push_back(names[i]); | 50 | out_buffer[i] = names[i]; |
| 52 | } | 51 | } |
| 53 | return out_count; | 52 | return out_count; |
| 54 | } | 53 | } |
| 55 | 54 | ||
| 56 | u32 AudioDevice::ListAudioOutputDeviceName(std::vector<AudioDeviceName>& out_buffer, | 55 | u32 AudioDevice::ListAudioOutputDeviceName(std::span<AudioDeviceName> out_buffer) const { |
| 57 | const size_t max_count) const { | 56 | const u32 out_count{static_cast<u32>(std::min(out_buffer.size(), output_device_names.size()))}; |
| 58 | const u32 out_count{static_cast<u32>(std::min(max_count, output_device_names.size()))}; | ||
| 59 | 57 | ||
| 60 | for (u32 i = 0; i < out_count; i++) { | 58 | for (u32 i = 0; i < out_count; i++) { |
| 61 | out_buffer.push_back(output_device_names[i]); | 59 | out_buffer[i] = output_device_names[i]; |
| 62 | } | 60 | } |
| 63 | return out_count; | 61 | return out_count; |
| 64 | } | 62 | } |
diff --git a/src/audio_core/renderer/audio_device.h b/src/audio_core/renderer/audio_device.h index ca4040add..4242dad30 100644 --- a/src/audio_core/renderer/audio_device.h +++ b/src/audio_core/renderer/audio_device.h | |||
| @@ -36,20 +36,18 @@ public: | |||
| 36 | * Get a list of the available output devices. | 36 | * Get a list of the available output devices. |
| 37 | * | 37 | * |
| 38 | * @param out_buffer - Output buffer to write the available device names. | 38 | * @param out_buffer - Output buffer to write the available device names. |
| 39 | * @param max_count - Maximum number of devices to write (count of out_buffer). | ||
| 40 | * @return Number of device names written. | 39 | * @return Number of device names written. |
| 41 | */ | 40 | */ |
| 42 | u32 ListAudioDeviceName(std::vector<AudioDeviceName>& out_buffer, size_t max_count) const; | 41 | u32 ListAudioDeviceName(std::span<AudioDeviceName> out_buffer) const; |
| 43 | 42 | ||
| 44 | /** | 43 | /** |
| 45 | * Get a list of the available output devices. | 44 | * Get a list of the available output devices. |
| 46 | * Different to above somehow... | 45 | * Different to above somehow... |
| 47 | * | 46 | * |
| 48 | * @param out_buffer - Output buffer to write the available device names. | 47 | * @param out_buffer - Output buffer to write the available device names. |
| 49 | * @param max_count - Maximum number of devices to write (count of out_buffer). | ||
| 50 | * @return Number of device names written. | 48 | * @return Number of device names written. |
| 51 | */ | 49 | */ |
| 52 | u32 ListAudioOutputDeviceName(std::vector<AudioDeviceName>& out_buffer, size_t max_count) const; | 50 | u32 ListAudioOutputDeviceName(std::span<AudioDeviceName> out_buffer) const; |
| 53 | 51 | ||
| 54 | /** | 52 | /** |
| 55 | * Set the volume of all streams in the backend sink. | 53 | * Set the volume of all streams in the backend sink. |
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index 72c481798..1909aced5 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp | |||
| @@ -38,6 +38,10 @@ std::string StringFromBuffer(std::span<const u8> data) { | |||
| 38 | return std::string(data.begin(), std::find(data.begin(), data.end(), '\0')); | 38 | return std::string(data.begin(), std::find(data.begin(), data.end(), '\0')); |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | std::string StringFromBuffer(std::span<const char> data) { | ||
| 42 | return std::string(data.begin(), std::find(data.begin(), data.end(), '\0')); | ||
| 43 | } | ||
| 44 | |||
| 41 | // Turns " hej " into "hej". Also handles tabs. | 45 | // Turns " hej " into "hej". Also handles tabs. |
| 42 | std::string StripSpaces(const std::string& str) { | 46 | std::string StripSpaces(const std::string& str) { |
| 43 | const std::size_t s = str.find_first_not_of(" \t\r\n"); | 47 | const std::size_t s = str.find_first_not_of(" \t\r\n"); |
diff --git a/src/common/string_util.h b/src/common/string_util.h index 9da1ca4e9..53d0549ca 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h | |||
| @@ -19,6 +19,7 @@ namespace Common { | |||
| 19 | [[nodiscard]] std::string ToUpper(std::string str); | 19 | [[nodiscard]] std::string ToUpper(std::string str); |
| 20 | 20 | ||
| 21 | [[nodiscard]] std::string StringFromBuffer(std::span<const u8> data); | 21 | [[nodiscard]] std::string StringFromBuffer(std::span<const u8> data); |
| 22 | [[nodiscard]] std::string StringFromBuffer(std::span<const char> data); | ||
| 22 | 23 | ||
| 23 | [[nodiscard]] std::string StripSpaces(const std::string& s); | 24 | [[nodiscard]] std::string StripSpaces(const std::string& s); |
| 24 | [[nodiscard]] std::string StripQuotes(const std::string& s); | 25 | [[nodiscard]] std::string StripQuotes(const std::string& s); |
diff --git a/src/core/hle/service/audio/audio_device.cpp b/src/core/hle/service/audio/audio_device.cpp index 3608d08c7..438f3cccd 100644 --- a/src/core/hle/service/audio/audio_device.cpp +++ b/src/core/hle/service/audio/audio_device.cpp | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | #include "audio_core/audio_core.h" | 4 | #include "audio_core/audio_core.h" |
| 5 | #include "common/string_util.h" | 5 | #include "common/string_util.h" |
| 6 | #include "core/hle/service/audio/audio_device.h" | 6 | #include "core/hle/service/audio/audio_device.h" |
| 7 | #include "core/hle/service/ipc_helpers.h" | 7 | #include "core/hle/service/cmif_serialization.h" |
| 8 | 8 | ||
| 9 | namespace Service::Audio { | 9 | namespace Service::Audio { |
| 10 | using namespace AudioCore::Renderer; | 10 | using namespace AudioCore::Renderer; |
| @@ -15,20 +15,20 @@ IAudioDevice::IAudioDevice(Core::System& system_, u64 applet_resource_user_id, u | |||
| 15 | impl{std::make_unique<AudioDevice>(system_, applet_resource_user_id, revision)}, | 15 | impl{std::make_unique<AudioDevice>(system_, applet_resource_user_id, revision)}, |
| 16 | event{service_context.CreateEvent(fmt::format("IAudioDeviceEvent-{}", device_num))} { | 16 | event{service_context.CreateEvent(fmt::format("IAudioDeviceEvent-{}", device_num))} { |
| 17 | static const FunctionInfo functions[] = { | 17 | static const FunctionInfo functions[] = { |
| 18 | {0, &IAudioDevice::ListAudioDeviceName, "ListAudioDeviceName"}, | 18 | {0, D<&IAudioDevice::ListAudioDeviceName>, "ListAudioDeviceName"}, |
| 19 | {1, &IAudioDevice::SetAudioDeviceOutputVolume, "SetAudioDeviceOutputVolume"}, | 19 | {1, D<&IAudioDevice::SetAudioDeviceOutputVolume>, "SetAudioDeviceOutputVolume"}, |
| 20 | {2, &IAudioDevice::GetAudioDeviceOutputVolume, "GetAudioDeviceOutputVolume"}, | 20 | {2, D<&IAudioDevice::GetAudioDeviceOutputVolume>, "GetAudioDeviceOutputVolume"}, |
| 21 | {3, &IAudioDevice::GetActiveAudioDeviceName, "GetActiveAudioDeviceName"}, | 21 | {3, D<&IAudioDevice::GetActiveAudioDeviceName>, "GetActiveAudioDeviceName"}, |
| 22 | {4, &IAudioDevice::QueryAudioDeviceSystemEvent, "QueryAudioDeviceSystemEvent"}, | 22 | {4, D<&IAudioDevice::QueryAudioDeviceSystemEvent>, "QueryAudioDeviceSystemEvent"}, |
| 23 | {5, &IAudioDevice::GetActiveChannelCount, "GetActiveChannelCount"}, | 23 | {5, D<&IAudioDevice::GetActiveChannelCount>, "GetActiveChannelCount"}, |
| 24 | {6, &IAudioDevice::ListAudioDeviceName, "ListAudioDeviceNameAuto"}, | 24 | {6, D<&IAudioDevice::ListAudioDeviceNameAuto>, "ListAudioDeviceNameAuto"}, |
| 25 | {7, &IAudioDevice::SetAudioDeviceOutputVolume, "SetAudioDeviceOutputVolumeAuto"}, | 25 | {7, D<&IAudioDevice::SetAudioDeviceOutputVolumeAuto>, "SetAudioDeviceOutputVolumeAuto"}, |
| 26 | {8, &IAudioDevice::GetAudioDeviceOutputVolume, "GetAudioDeviceOutputVolumeAuto"}, | 26 | {8, D<&IAudioDevice::GetAudioDeviceOutputVolumeAuto>, "GetAudioDeviceOutputVolumeAuto"}, |
| 27 | {10, &IAudioDevice::GetActiveAudioDeviceName, "GetActiveAudioDeviceNameAuto"}, | 27 | {10, D<&IAudioDevice::GetActiveAudioDeviceNameAuto>, "GetActiveAudioDeviceNameAuto"}, |
| 28 | {11, &IAudioDevice::QueryAudioDeviceInputEvent, "QueryAudioDeviceInputEvent"}, | 28 | {11, D<&IAudioDevice::QueryAudioDeviceInputEvent>, "QueryAudioDeviceInputEvent"}, |
| 29 | {12, &IAudioDevice::QueryAudioDeviceOutputEvent, "QueryAudioDeviceOutputEvent"}, | 29 | {12, D<&IAudioDevice::QueryAudioDeviceOutputEvent>, "QueryAudioDeviceOutputEvent"}, |
| 30 | {13, &IAudioDevice::GetActiveAudioDeviceName, "GetActiveAudioOutputDeviceName"}, | 30 | {13, D<&IAudioDevice::GetActiveAudioDeviceName>, "GetActiveAudioOutputDeviceName"}, |
| 31 | {14, &IAudioDevice::ListAudioOutputDeviceName, "ListAudioOutputDeviceName"}, | 31 | {14, D<&IAudioDevice::ListAudioOutputDeviceName>, "ListAudioOutputDeviceName"}, |
| 32 | }; | 32 | }; |
| 33 | RegisterHandlers(functions); | 33 | RegisterHandlers(functions); |
| 34 | 34 | ||
| @@ -39,15 +39,33 @@ IAudioDevice::~IAudioDevice() { | |||
| 39 | service_context.CloseEvent(event); | 39 | service_context.CloseEvent(event); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | void IAudioDevice::ListAudioDeviceName(HLERequestContext& ctx) { | 42 | Result IAudioDevice::ListAudioDeviceName( |
| 43 | const size_t in_count = ctx.GetWriteBufferNumElements<AudioDevice::AudioDeviceName>(); | 43 | OutArray<AudioDevice::AudioDeviceName, BufferAttr_HipcMapAlias> out_names, Out<s32> out_count) { |
| 44 | R_RETURN(this->ListAudioDeviceNameAuto(out_names, out_count)); | ||
| 45 | } | ||
| 46 | |||
| 47 | Result IAudioDevice::SetAudioDeviceOutputVolume( | ||
| 48 | InArray<AudioDevice::AudioDeviceName, BufferAttr_HipcMapAlias> name, f32 volume) { | ||
| 49 | R_RETURN(this->SetAudioDeviceOutputVolumeAuto(name, volume)); | ||
| 50 | } | ||
| 51 | |||
| 52 | Result IAudioDevice::GetAudioDeviceOutputVolume( | ||
| 53 | Out<f32> out_volume, InArray<AudioDevice::AudioDeviceName, BufferAttr_HipcMapAlias> name) { | ||
| 54 | R_RETURN(this->GetAudioDeviceOutputVolumeAuto(out_volume, name)); | ||
| 55 | } | ||
| 44 | 56 | ||
| 45 | std::vector<AudioDevice::AudioDeviceName> out_names{}; | 57 | Result IAudioDevice::GetActiveAudioDeviceName( |
| 58 | OutArray<AudioDevice::AudioDeviceName, BufferAttr_HipcMapAlias> out_name) { | ||
| 59 | R_RETURN(this->GetActiveAudioDeviceNameAuto(out_name)); | ||
| 60 | } | ||
| 46 | 61 | ||
| 47 | const u32 out_count = impl->ListAudioDeviceName(out_names, in_count); | 62 | Result IAudioDevice::ListAudioDeviceNameAuto( |
| 63 | OutArray<AudioDevice::AudioDeviceName, BufferAttr_HipcAutoSelect> out_names, | ||
| 64 | Out<s32> out_count) { | ||
| 65 | *out_count = impl->ListAudioDeviceName(out_names); | ||
| 48 | 66 | ||
| 49 | std::string out{}; | 67 | std::string out{}; |
| 50 | for (u32 i = 0; i < out_count; i++) { | 68 | for (s32 i = 0; i < *out_count; i++) { |
| 51 | std::string a{}; | 69 | std::string a{}; |
| 52 | u32 j = 0; | 70 | u32 j = 0; |
| 53 | while (out_names[i].name[j] != '\0') { | 71 | while (out_names[i].name[j] != '\0') { |
| @@ -58,109 +76,77 @@ void IAudioDevice::ListAudioDeviceName(HLERequestContext& ctx) { | |||
| 58 | } | 76 | } |
| 59 | 77 | ||
| 60 | LOG_DEBUG(Service_Audio, "called.\nNames={}", out); | 78 | LOG_DEBUG(Service_Audio, "called.\nNames={}", out); |
| 61 | 79 | R_SUCCEED(); | |
| 62 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 63 | |||
| 64 | ctx.WriteBuffer(out_names); | ||
| 65 | |||
| 66 | rb.Push(ResultSuccess); | ||
| 67 | rb.Push(out_count); | ||
| 68 | } | 80 | } |
| 69 | 81 | ||
| 70 | void IAudioDevice::SetAudioDeviceOutputVolume(HLERequestContext& ctx) { | 82 | Result IAudioDevice::SetAudioDeviceOutputVolumeAuto( |
| 71 | IPC::RequestParser rp{ctx}; | 83 | InArray<AudioDevice::AudioDeviceName, BufferAttr_HipcAutoSelect> name, f32 volume) { |
| 72 | const f32 volume = rp.Pop<f32>(); | 84 | R_UNLESS(!name.empty(), Audio::ResultInsufficientBuffer); |
| 73 | |||
| 74 | const auto device_name_buffer = ctx.ReadBuffer(); | ||
| 75 | const std::string name = Common::StringFromBuffer(device_name_buffer); | ||
| 76 | 85 | ||
| 77 | LOG_DEBUG(Service_Audio, "called. name={}, volume={}", name, volume); | 86 | const std::string device_name = Common::StringFromBuffer(name[0].name); |
| 87 | LOG_DEBUG(Service_Audio, "called. name={}, volume={}", device_name, volume); | ||
| 78 | 88 | ||
| 79 | if (name == "AudioTvOutput") { | 89 | if (device_name == "AudioTvOutput") { |
| 80 | impl->SetDeviceVolumes(volume); | 90 | impl->SetDeviceVolumes(volume); |
| 81 | } | 91 | } |
| 82 | 92 | ||
| 83 | IPC::ResponseBuilder rb{ctx, 2}; | 93 | R_SUCCEED(); |
| 84 | rb.Push(ResultSuccess); | ||
| 85 | } | 94 | } |
| 86 | 95 | ||
| 87 | void IAudioDevice::GetAudioDeviceOutputVolume(HLERequestContext& ctx) { | 96 | Result IAudioDevice::GetAudioDeviceOutputVolumeAuto( |
| 88 | const auto device_name_buffer = ctx.ReadBuffer(); | 97 | Out<f32> out_volume, InArray<AudioDevice::AudioDeviceName, BufferAttr_HipcAutoSelect> name) { |
| 89 | const std::string name = Common::StringFromBuffer(device_name_buffer); | 98 | R_UNLESS(!name.empty(), Audio::ResultInsufficientBuffer); |
| 90 | 99 | ||
| 91 | LOG_DEBUG(Service_Audio, "called. Name={}", name); | 100 | const std::string device_name = Common::StringFromBuffer(name[0].name); |
| 101 | LOG_DEBUG(Service_Audio, "called. Name={}", device_name); | ||
| 92 | 102 | ||
| 93 | f32 volume{1.0f}; | 103 | *out_volume = 1.0f; |
| 94 | if (name == "AudioTvOutput") { | 104 | if (device_name == "AudioTvOutput") { |
| 95 | volume = impl->GetDeviceVolume(name); | 105 | *out_volume = impl->GetDeviceVolume(device_name); |
| 96 | } | 106 | } |
| 97 | 107 | ||
| 98 | IPC::ResponseBuilder rb{ctx, 3}; | 108 | R_SUCCEED(); |
| 99 | rb.Push(ResultSuccess); | ||
| 100 | rb.Push(volume); | ||
| 101 | } | 109 | } |
| 102 | 110 | ||
| 103 | void IAudioDevice::GetActiveAudioDeviceName(HLERequestContext& ctx) { | 111 | Result IAudioDevice::GetActiveAudioDeviceNameAuto( |
| 104 | const auto write_size = ctx.GetWriteBufferSize(); | 112 | OutArray<AudioDevice::AudioDeviceName, BufferAttr_HipcAutoSelect> out_name) { |
| 105 | std::string out_name{"AudioTvOutput"}; | 113 | R_UNLESS(!out_name.empty(), Audio::ResultInsufficientBuffer); |
| 106 | 114 | out_name[0] = AudioDevice::AudioDeviceName("AudioTvOutput"); | |
| 107 | LOG_DEBUG(Service_Audio, "(STUBBED) called. Name={}", out_name); | 115 | LOG_DEBUG(Service_Audio, "(STUBBED) called"); |
| 108 | 116 | R_SUCCEED(); | |
| 109 | out_name.resize(write_size); | ||
| 110 | |||
| 111 | ctx.WriteBuffer(out_name); | ||
| 112 | |||
| 113 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 114 | rb.Push(ResultSuccess); | ||
| 115 | } | 117 | } |
| 116 | 118 | ||
| 117 | void IAudioDevice::QueryAudioDeviceSystemEvent(HLERequestContext& ctx) { | 119 | Result IAudioDevice::QueryAudioDeviceSystemEvent(OutCopyHandle<Kernel::KReadableEvent> out_event) { |
| 118 | LOG_DEBUG(Service_Audio, "(STUBBED) called"); | 120 | LOG_DEBUG(Service_Audio, "(STUBBED) called"); |
| 119 | |||
| 120 | event->Signal(); | 121 | event->Signal(); |
| 121 | 122 | *out_event = &event->GetReadableEvent(); | |
| 122 | IPC::ResponseBuilder rb{ctx, 2, 1}; | 123 | R_SUCCEED(); |
| 123 | rb.Push(ResultSuccess); | ||
| 124 | rb.PushCopyObjects(event->GetReadableEvent()); | ||
| 125 | } | ||
| 126 | |||
| 127 | void IAudioDevice::GetActiveChannelCount(HLERequestContext& ctx) { | ||
| 128 | const auto& sink{system.AudioCore().GetOutputSink()}; | ||
| 129 | u32 channel_count{sink.GetSystemChannels()}; | ||
| 130 | |||
| 131 | LOG_DEBUG(Service_Audio, "(STUBBED) called. Channels={}", channel_count); | ||
| 132 | |||
| 133 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 134 | |||
| 135 | rb.Push(ResultSuccess); | ||
| 136 | rb.Push<u32>(channel_count); | ||
| 137 | } | 124 | } |
| 138 | 125 | ||
| 139 | void IAudioDevice::QueryAudioDeviceInputEvent(HLERequestContext& ctx) { | 126 | Result IAudioDevice::QueryAudioDeviceInputEvent(OutCopyHandle<Kernel::KReadableEvent> out_event) { |
| 140 | LOG_DEBUG(Service_Audio, "(STUBBED) called"); | 127 | LOG_DEBUG(Service_Audio, "(STUBBED) called"); |
| 141 | 128 | *out_event = &event->GetReadableEvent(); | |
| 142 | IPC::ResponseBuilder rb{ctx, 2, 1}; | 129 | R_SUCCEED(); |
| 143 | rb.Push(ResultSuccess); | ||
| 144 | rb.PushCopyObjects(event->GetReadableEvent()); | ||
| 145 | } | 130 | } |
| 146 | 131 | ||
| 147 | void IAudioDevice::QueryAudioDeviceOutputEvent(HLERequestContext& ctx) { | 132 | Result IAudioDevice::QueryAudioDeviceOutputEvent(OutCopyHandle<Kernel::KReadableEvent> out_event) { |
| 148 | LOG_DEBUG(Service_Audio, "called"); | 133 | LOG_DEBUG(Service_Audio, "called"); |
| 149 | 134 | *out_event = &event->GetReadableEvent(); | |
| 150 | IPC::ResponseBuilder rb{ctx, 2, 1}; | 135 | R_SUCCEED(); |
| 151 | rb.Push(ResultSuccess); | ||
| 152 | rb.PushCopyObjects(event->GetReadableEvent()); | ||
| 153 | } | 136 | } |
| 154 | 137 | ||
| 155 | void IAudioDevice::ListAudioOutputDeviceName(HLERequestContext& ctx) { | 138 | Result IAudioDevice::GetActiveChannelCount(Out<u32> out_active_channel_count) { |
| 156 | const size_t in_count = ctx.GetWriteBufferNumElements<AudioDevice::AudioDeviceName>(); | 139 | *out_active_channel_count = system.AudioCore().GetOutputSink().GetSystemChannels(); |
| 157 | 140 | LOG_DEBUG(Service_Audio, "(STUBBED) called. Channels={}", *out_active_channel_count); | |
| 158 | std::vector<AudioDevice::AudioDeviceName> out_names{}; | 141 | R_SUCCEED(); |
| 142 | } | ||
| 159 | 143 | ||
| 160 | const u32 out_count = impl->ListAudioOutputDeviceName(out_names, in_count); | 144 | Result IAudioDevice::ListAudioOutputDeviceName( |
| 145 | OutArray<AudioDevice::AudioDeviceName, BufferAttr_HipcMapAlias> out_names, Out<s32> out_count) { | ||
| 146 | *out_count = impl->ListAudioOutputDeviceName(out_names); | ||
| 161 | 147 | ||
| 162 | std::string out{}; | 148 | std::string out{}; |
| 163 | for (u32 i = 0; i < out_count; i++) { | 149 | for (s32 i = 0; i < *out_count; i++) { |
| 164 | std::string a{}; | 150 | std::string a{}; |
| 165 | u32 j = 0; | 151 | u32 j = 0; |
| 166 | while (out_names[i].name[j] != '\0') { | 152 | while (out_names[i].name[j] != '\0') { |
| @@ -171,13 +157,7 @@ void IAudioDevice::ListAudioOutputDeviceName(HLERequestContext& ctx) { | |||
| 171 | } | 157 | } |
| 172 | 158 | ||
| 173 | LOG_DEBUG(Service_Audio, "called.\nNames={}", out); | 159 | LOG_DEBUG(Service_Audio, "called.\nNames={}", out); |
| 174 | 160 | R_SUCCEED(); | |
| 175 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 176 | |||
| 177 | ctx.WriteBuffer(out_names); | ||
| 178 | |||
| 179 | rb.Push(ResultSuccess); | ||
| 180 | rb.Push(out_count); | ||
| 181 | } | 161 | } |
| 182 | 162 | ||
| 183 | } // namespace Service::Audio | 163 | } // namespace Service::Audio |
diff --git a/src/core/hle/service/audio/audio_device.h b/src/core/hle/service/audio/audio_device.h index 850c60051..752157272 100644 --- a/src/core/hle/service/audio/audio_device.h +++ b/src/core/hle/service/audio/audio_device.h | |||
| @@ -4,11 +4,18 @@ | |||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include "audio_core/renderer/audio_device.h" | 6 | #include "audio_core/renderer/audio_device.h" |
| 7 | #include "core/hle/service/cmif_types.h" | ||
| 7 | #include "core/hle/service/kernel_helpers.h" | 8 | #include "core/hle/service/kernel_helpers.h" |
| 8 | #include "core/hle/service/service.h" | 9 | #include "core/hle/service/service.h" |
| 9 | 10 | ||
| 11 | namespace Kernel { | ||
| 12 | class KReadableEvent; | ||
| 13 | } | ||
| 14 | |||
| 10 | namespace Service::Audio { | 15 | namespace Service::Audio { |
| 11 | 16 | ||
| 17 | using AudioCore::Renderer::AudioDevice; | ||
| 18 | |||
| 12 | class IAudioDevice final : public ServiceFramework<IAudioDevice> { | 19 | class IAudioDevice final : public ServiceFramework<IAudioDevice> { |
| 13 | 20 | ||
| 14 | public: | 21 | public: |
| @@ -17,15 +24,31 @@ public: | |||
| 17 | ~IAudioDevice() override; | 24 | ~IAudioDevice() override; |
| 18 | 25 | ||
| 19 | private: | 26 | private: |
| 20 | void ListAudioDeviceName(HLERequestContext& ctx); | 27 | Result ListAudioDeviceName( |
| 21 | void SetAudioDeviceOutputVolume(HLERequestContext& ctx); | 28 | OutArray<AudioDevice::AudioDeviceName, BufferAttr_HipcMapAlias> out_names, |
| 22 | void GetAudioDeviceOutputVolume(HLERequestContext& ctx); | 29 | Out<s32> out_count); |
| 23 | void GetActiveAudioDeviceName(HLERequestContext& ctx); | 30 | Result SetAudioDeviceOutputVolume( |
| 24 | void QueryAudioDeviceSystemEvent(HLERequestContext& ctx); | 31 | InArray<AudioDevice::AudioDeviceName, BufferAttr_HipcMapAlias> name, f32 volume); |
| 25 | void GetActiveChannelCount(HLERequestContext& ctx); | 32 | Result GetAudioDeviceOutputVolume( |
| 26 | void QueryAudioDeviceInputEvent(HLERequestContext& ctx); | 33 | Out<f32> out_volume, InArray<AudioDevice::AudioDeviceName, BufferAttr_HipcMapAlias> name); |
| 27 | void QueryAudioDeviceOutputEvent(HLERequestContext& ctx); | 34 | Result GetActiveAudioDeviceName( |
| 28 | void ListAudioOutputDeviceName(HLERequestContext& ctx); | 35 | OutArray<AudioDevice::AudioDeviceName, BufferAttr_HipcMapAlias> out_name); |
| 36 | Result ListAudioDeviceNameAuto( | ||
| 37 | OutArray<AudioDevice::AudioDeviceName, BufferAttr_HipcAutoSelect> out_names, | ||
| 38 | Out<s32> out_count); | ||
| 39 | Result SetAudioDeviceOutputVolumeAuto( | ||
| 40 | InArray<AudioDevice::AudioDeviceName, BufferAttr_HipcAutoSelect> name, f32 volume); | ||
| 41 | Result GetAudioDeviceOutputVolumeAuto( | ||
| 42 | Out<f32> out_volume, InArray<AudioDevice::AudioDeviceName, BufferAttr_HipcAutoSelect> name); | ||
| 43 | Result GetActiveAudioDeviceNameAuto( | ||
| 44 | OutArray<AudioDevice::AudioDeviceName, BufferAttr_HipcAutoSelect> out_name); | ||
| 45 | Result QueryAudioDeviceSystemEvent(OutCopyHandle<Kernel::KReadableEvent> out_event); | ||
| 46 | Result QueryAudioDeviceInputEvent(OutCopyHandle<Kernel::KReadableEvent> out_event); | ||
| 47 | Result QueryAudioDeviceOutputEvent(OutCopyHandle<Kernel::KReadableEvent> out_event); | ||
| 48 | Result GetActiveChannelCount(Out<u32> out_active_channel_count); | ||
| 49 | Result ListAudioOutputDeviceName( | ||
| 50 | OutArray<AudioDevice::AudioDeviceName, BufferAttr_HipcMapAlias> out_names, | ||
| 51 | Out<s32> out_count); | ||
| 29 | 52 | ||
| 30 | KernelHelpers::ServiceContext service_context; | 53 | KernelHelpers::ServiceContext service_context; |
| 31 | std::unique_ptr<AudioCore::Renderer::AudioDevice> impl; | 54 | std::unique_ptr<AudioCore::Renderer::AudioDevice> impl; |
diff --git a/src/core/hle/service/audio/audio_in_manager.cpp b/src/core/hle/service/audio/audio_in_manager.cpp index 9b67af367..d55da17c8 100644 --- a/src/core/hle/service/audio/audio_in_manager.cpp +++ b/src/core/hle/service/audio/audio_in_manager.cpp | |||
| @@ -96,8 +96,7 @@ Result IAudioInManager::OpenAudioInProtocolSpecified( | |||
| 96 | LOG_DEBUG(Service_Audio, "Opening new AudioIn, session_id={}, free sessions={}", new_session_id, | 96 | LOG_DEBUG(Service_Audio, "Opening new AudioIn, session_id={}, free sessions={}", new_session_id, |
| 97 | impl->num_free_sessions); | 97 | impl->num_free_sessions); |
| 98 | 98 | ||
| 99 | const auto name_buffer = std::span(reinterpret_cast<const u8*>(name[0].name.data()), 0x100); | 99 | const auto device_name = Common::StringFromBuffer(name[0].name); |
| 100 | const auto device_name = Common::StringFromBuffer(name_buffer); | ||
| 101 | *out_audio_in = std::make_shared<IAudioIn>(system, *impl, new_session_id, device_name, | 100 | *out_audio_in = std::make_shared<IAudioIn>(system, *impl, new_session_id, device_name, |
| 102 | parameter, process_handle.Get(), aruid.pid); | 101 | parameter, process_handle.Get(), aruid.pid); |
| 103 | impl->sessions[new_session_id] = (*out_audio_in)->GetImpl(); | 102 | impl->sessions[new_session_id] = (*out_audio_in)->GetImpl(); |
diff --git a/src/core/hle/service/audio/audio_out_manager.cpp b/src/core/hle/service/audio/audio_out_manager.cpp index 780e1dcda..153445097 100644 --- a/src/core/hle/service/audio/audio_out_manager.cpp +++ b/src/core/hle/service/audio/audio_out_manager.cpp | |||
| @@ -75,9 +75,7 @@ Result IAudioOutManager::OpenAudioOutAuto( | |||
| 75 | R_TRY(impl->LinkToManager()); | 75 | R_TRY(impl->LinkToManager()); |
| 76 | R_TRY(impl->AcquireSessionId(new_session_id)); | 76 | R_TRY(impl->AcquireSessionId(new_session_id)); |
| 77 | 77 | ||
| 78 | const auto name_buffer = std::span(reinterpret_cast<const u8*>(name[0].name.data()), 0x100); | 78 | const auto device_name = Common::StringFromBuffer(name[0].name); |
| 79 | const auto device_name = Common::StringFromBuffer(name_buffer); | ||
| 80 | |||
| 81 | LOG_DEBUG(Service_Audio, "Opening new AudioOut, sessionid={}, free sessions={}", new_session_id, | 79 | LOG_DEBUG(Service_Audio, "Opening new AudioOut, sessionid={}, free sessions={}", new_session_id, |
| 82 | impl->num_free_sessions); | 80 | impl->num_free_sessions); |
| 83 | 81 | ||