diff options
| author | 2024-01-12 09:35:08 -0500 | |
|---|---|---|
| committer | 2024-01-12 10:03:16 -0500 | |
| commit | d940974789b1b8ff473440883d8c506a275b9b3b (patch) | |
| tree | e859ecfe3e8c0537035972a83bf2344ebf3577b6 /src | |
| parent | Merge pull request #12653 from liamwhite/once-more (diff) | |
| download | yuzu-d940974789b1b8ff473440883d8c506a275b9b3b.tar.gz yuzu-d940974789b1b8ff473440883d8c506a275b9b3b.tar.xz yuzu-d940974789b1b8ff473440883d8c506a275b9b3b.zip | |
audio: fetch process object from handle table
Diffstat (limited to 'src')
| -rw-r--r-- | src/audio_core/device/device_session.cpp | 14 | ||||
| -rw-r--r-- | src/audio_core/device/device_session.h | 12 | ||||
| -rw-r--r-- | src/audio_core/in/audio_in_system.cpp | 2 | ||||
| -rw-r--r-- | src/audio_core/in/audio_in_system.h | 13 | ||||
| -rw-r--r-- | src/audio_core/out/audio_out_system.cpp | 4 | ||||
| -rw-r--r-- | src/audio_core/out/audio_out_system.h | 13 | ||||
| -rw-r--r-- | src/core/hle/service/audio/audin_u.cpp | 36 | ||||
| -rw-r--r-- | src/core/hle/service/audio/audout_u.cpp | 26 |
8 files changed, 85 insertions, 35 deletions
diff --git a/src/audio_core/device/device_session.cpp b/src/audio_core/device/device_session.cpp index ee42ae529..3c214ec00 100644 --- a/src/audio_core/device/device_session.cpp +++ b/src/audio_core/device/device_session.cpp | |||
| @@ -10,6 +10,8 @@ | |||
| 10 | #include "core/core_timing.h" | 10 | #include "core/core_timing.h" |
| 11 | #include "core/memory.h" | 11 | #include "core/memory.h" |
| 12 | 12 | ||
| 13 | #include "core/hle/kernel/k_process.h" | ||
| 14 | |||
| 13 | namespace AudioCore { | 15 | namespace AudioCore { |
| 14 | 16 | ||
| 15 | using namespace std::literals; | 17 | using namespace std::literals; |
| @@ -25,7 +27,7 @@ DeviceSession::~DeviceSession() { | |||
| 25 | } | 27 | } |
| 26 | 28 | ||
| 27 | Result DeviceSession::Initialize(std::string_view name_, SampleFormat sample_format_, | 29 | Result DeviceSession::Initialize(std::string_view name_, SampleFormat sample_format_, |
| 28 | u16 channel_count_, size_t session_id_, u32 handle_, | 30 | u16 channel_count_, size_t session_id_, Kernel::KProcess* handle_, |
| 29 | u64 applet_resource_user_id_, Sink::StreamType type_) { | 31 | u64 applet_resource_user_id_, Sink::StreamType type_) { |
| 30 | if (stream) { | 32 | if (stream) { |
| 31 | Finalize(); | 33 | Finalize(); |
| @@ -36,6 +38,7 @@ Result DeviceSession::Initialize(std::string_view name_, SampleFormat sample_for | |||
| 36 | channel_count = channel_count_; | 38 | channel_count = channel_count_; |
| 37 | session_id = session_id_; | 39 | session_id = session_id_; |
| 38 | handle = handle_; | 40 | handle = handle_; |
| 41 | handle->Open(); | ||
| 39 | applet_resource_user_id = applet_resource_user_id_; | 42 | applet_resource_user_id = applet_resource_user_id_; |
| 40 | 43 | ||
| 41 | if (type == Sink::StreamType::In) { | 44 | if (type == Sink::StreamType::In) { |
| @@ -54,6 +57,11 @@ void DeviceSession::Finalize() { | |||
| 54 | sink->CloseStream(stream); | 57 | sink->CloseStream(stream); |
| 55 | stream = nullptr; | 58 | stream = nullptr; |
| 56 | } | 59 | } |
| 60 | |||
| 61 | if (handle) { | ||
| 62 | handle->Close(); | ||
| 63 | handle = nullptr; | ||
| 64 | } | ||
| 57 | } | 65 | } |
| 58 | 66 | ||
| 59 | void DeviceSession::Start() { | 67 | void DeviceSession::Start() { |
| @@ -91,7 +99,7 @@ void DeviceSession::AppendBuffers(std::span<const AudioBuffer> buffers) { | |||
| 91 | stream->AppendBuffer(new_buffer, tmp_samples); | 99 | stream->AppendBuffer(new_buffer, tmp_samples); |
| 92 | } else { | 100 | } else { |
| 93 | Core::Memory::CpuGuestMemory<s16, Core::Memory::GuestMemoryFlags::UnsafeRead> samples( | 101 | Core::Memory::CpuGuestMemory<s16, Core::Memory::GuestMemoryFlags::UnsafeRead> samples( |
| 94 | system.ApplicationMemory(), buffer.samples, buffer.size / sizeof(s16)); | 102 | handle->GetMemory(), buffer.samples, buffer.size / sizeof(s16)); |
| 95 | stream->AppendBuffer(new_buffer, samples); | 103 | stream->AppendBuffer(new_buffer, samples); |
| 96 | } | 104 | } |
| 97 | } | 105 | } |
| @@ -100,7 +108,7 @@ void DeviceSession::AppendBuffers(std::span<const AudioBuffer> buffers) { | |||
| 100 | void DeviceSession::ReleaseBuffer(const AudioBuffer& buffer) const { | 108 | void DeviceSession::ReleaseBuffer(const AudioBuffer& buffer) const { |
| 101 | if (type == Sink::StreamType::In) { | 109 | if (type == Sink::StreamType::In) { |
| 102 | auto samples{stream->ReleaseBuffer(buffer.size / sizeof(s16))}; | 110 | auto samples{stream->ReleaseBuffer(buffer.size / sizeof(s16))}; |
| 103 | system.ApplicationMemory().WriteBlockUnsafe(buffer.samples, samples.data(), buffer.size); | 111 | handle->GetMemory().WriteBlockUnsafe(buffer.samples, samples.data(), buffer.size); |
| 104 | } | 112 | } |
| 105 | } | 113 | } |
| 106 | 114 | ||
diff --git a/src/audio_core/device/device_session.h b/src/audio_core/device/device_session.h index 7d52f362d..f3fae2617 100644 --- a/src/audio_core/device/device_session.h +++ b/src/audio_core/device/device_session.h | |||
| @@ -20,6 +20,10 @@ struct EventType; | |||
| 20 | } // namespace Timing | 20 | } // namespace Timing |
| 21 | } // namespace Core | 21 | } // namespace Core |
| 22 | 22 | ||
| 23 | namespace Kernel { | ||
| 24 | class KProcess; | ||
| 25 | } // namespace Kernel | ||
| 26 | |||
| 23 | namespace AudioCore { | 27 | namespace AudioCore { |
| 24 | 28 | ||
| 25 | namespace Sink { | 29 | namespace Sink { |
| @@ -44,13 +48,13 @@ public: | |||
| 44 | * @param sample_format - Sample format for this device's output. | 48 | * @param sample_format - Sample format for this device's output. |
| 45 | * @param channel_count - Number of channels for this device (2 or 6). | 49 | * @param channel_count - Number of channels for this device (2 or 6). |
| 46 | * @param session_id - This session's id. | 50 | * @param session_id - This session's id. |
| 47 | * @param handle - Handle for this device session (unused). | 51 | * @param handle - Process handle for this device session. |
| 48 | * @param applet_resource_user_id - Applet resource user id for this device session (unused). | 52 | * @param applet_resource_user_id - Applet resource user id for this device session (unused). |
| 49 | * @param type - Type of this stream (Render, In, Out). | 53 | * @param type - Type of this stream (Render, In, Out). |
| 50 | * @return Result code for this call. | 54 | * @return Result code for this call. |
| 51 | */ | 55 | */ |
| 52 | Result Initialize(std::string_view name, SampleFormat sample_format, u16 channel_count, | 56 | Result Initialize(std::string_view name, SampleFormat sample_format, u16 channel_count, |
| 53 | size_t session_id, u32 handle, u64 applet_resource_user_id, | 57 | size_t session_id, Kernel::KProcess* handle, u64 applet_resource_user_id, |
| 54 | Sink::StreamType type); | 58 | Sink::StreamType type); |
| 55 | 59 | ||
| 56 | /** | 60 | /** |
| @@ -137,8 +141,8 @@ private: | |||
| 137 | u16 channel_count{}; | 141 | u16 channel_count{}; |
| 138 | /// Session id of this device session | 142 | /// Session id of this device session |
| 139 | size_t session_id{}; | 143 | size_t session_id{}; |
| 140 | /// Handle of this device session | 144 | /// Process handle of device memory owner |
| 141 | u32 handle{}; | 145 | Kernel::KProcess* handle{}; |
| 142 | /// Applet resource user id of this device session | 146 | /// Applet resource user id of this device session |
| 143 | u64 applet_resource_user_id{}; | 147 | u64 applet_resource_user_id{}; |
| 144 | /// Total number of samples played by this device session | 148 | /// Total number of samples played by this device session |
diff --git a/src/audio_core/in/audio_in_system.cpp b/src/audio_core/in/audio_in_system.cpp index 579129121..b2dd3ef9f 100644 --- a/src/audio_core/in/audio_in_system.cpp +++ b/src/audio_core/in/audio_in_system.cpp | |||
| @@ -57,7 +57,7 @@ Result System::IsConfigValid(const std::string_view device_name, | |||
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | Result System::Initialize(std::string device_name, const AudioInParameter& in_params, | 59 | Result System::Initialize(std::string device_name, const AudioInParameter& in_params, |
| 60 | const u32 handle_, const u64 applet_resource_user_id_) { | 60 | Kernel::KProcess* handle_, const u64 applet_resource_user_id_) { |
| 61 | auto result{IsConfigValid(device_name, in_params)}; | 61 | auto result{IsConfigValid(device_name, in_params)}; |
| 62 | if (result.IsError()) { | 62 | if (result.IsError()) { |
| 63 | return result; | 63 | return result; |
diff --git a/src/audio_core/in/audio_in_system.h b/src/audio_core/in/audio_in_system.h index 1c5154638..ee048190c 100644 --- a/src/audio_core/in/audio_in_system.h +++ b/src/audio_core/in/audio_in_system.h | |||
| @@ -19,7 +19,8 @@ class System; | |||
| 19 | 19 | ||
| 20 | namespace Kernel { | 20 | namespace Kernel { |
| 21 | class KEvent; | 21 | class KEvent; |
| 22 | } | 22 | class KProcess; |
| 23 | } // namespace Kernel | ||
| 23 | 24 | ||
| 24 | namespace AudioCore::AudioIn { | 25 | namespace AudioCore::AudioIn { |
| 25 | 26 | ||
| @@ -93,12 +94,12 @@ public: | |||
| 93 | * | 94 | * |
| 94 | * @param device_name - The name of the requested input device. | 95 | * @param device_name - The name of the requested input device. |
| 95 | * @param in_params - Input parameters, see AudioInParameter. | 96 | * @param in_params - Input parameters, see AudioInParameter. |
| 96 | * @param handle - Unused. | 97 | * @param handle - Process handle. |
| 97 | * @param applet_resource_user_id - Unused. | 98 | * @param applet_resource_user_id - Unused. |
| 98 | * @return Result code. | 99 | * @return Result code. |
| 99 | */ | 100 | */ |
| 100 | Result Initialize(std::string device_name, const AudioInParameter& in_params, u32 handle, | 101 | Result Initialize(std::string device_name, const AudioInParameter& in_params, |
| 101 | u64 applet_resource_user_id); | 102 | Kernel::KProcess* handle, u64 applet_resource_user_id); |
| 102 | 103 | ||
| 103 | /** | 104 | /** |
| 104 | * Start this system. | 105 | * Start this system. |
| @@ -244,8 +245,8 @@ public: | |||
| 244 | private: | 245 | private: |
| 245 | /// Core system | 246 | /// Core system |
| 246 | Core::System& system; | 247 | Core::System& system; |
| 247 | /// (Unused) | 248 | /// Process handle |
| 248 | u32 handle{}; | 249 | Kernel::KProcess* handle{}; |
| 249 | /// (Unused) | 250 | /// (Unused) |
| 250 | u64 applet_resource_user_id{}; | 251 | u64 applet_resource_user_id{}; |
| 251 | /// Buffer event, signalled when a buffer is ready | 252 | /// Buffer event, signalled when a buffer is ready |
diff --git a/src/audio_core/out/audio_out_system.cpp b/src/audio_core/out/audio_out_system.cpp index 0adf64bd3..7b3ff4e88 100644 --- a/src/audio_core/out/audio_out_system.cpp +++ b/src/audio_core/out/audio_out_system.cpp | |||
| @@ -48,8 +48,8 @@ Result System::IsConfigValid(std::string_view device_name, | |||
| 48 | return Service::Audio::ResultInvalidChannelCount; | 48 | return Service::Audio::ResultInvalidChannelCount; |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | Result System::Initialize(std::string device_name, const AudioOutParameter& in_params, u32 handle_, | 51 | Result System::Initialize(std::string device_name, const AudioOutParameter& in_params, |
| 52 | u64 applet_resource_user_id_) { | 52 | Kernel::KProcess* handle_, u64 applet_resource_user_id_) { |
| 53 | auto result = IsConfigValid(device_name, in_params); | 53 | auto result = IsConfigValid(device_name, in_params); |
| 54 | if (result.IsError()) { | 54 | if (result.IsError()) { |
| 55 | return result; | 55 | return result; |
diff --git a/src/audio_core/out/audio_out_system.h b/src/audio_core/out/audio_out_system.h index b95cb91be..82aada185 100644 --- a/src/audio_core/out/audio_out_system.h +++ b/src/audio_core/out/audio_out_system.h | |||
| @@ -19,7 +19,8 @@ class System; | |||
| 19 | 19 | ||
| 20 | namespace Kernel { | 20 | namespace Kernel { |
| 21 | class KEvent; | 21 | class KEvent; |
| 22 | } | 22 | class KProcess; |
| 23 | } // namespace Kernel | ||
| 23 | 24 | ||
| 24 | namespace AudioCore::AudioOut { | 25 | namespace AudioCore::AudioOut { |
| 25 | 26 | ||
| @@ -84,12 +85,12 @@ public: | |||
| 84 | * | 85 | * |
| 85 | * @param device_name - The name of the requested output device. | 86 | * @param device_name - The name of the requested output device. |
| 86 | * @param in_params - Input parameters, see AudioOutParameter. | 87 | * @param in_params - Input parameters, see AudioOutParameter. |
| 87 | * @param handle - Unused. | 88 | * @param handle - Process handle. |
| 88 | * @param applet_resource_user_id - Unused. | 89 | * @param applet_resource_user_id - Unused. |
| 89 | * @return Result code. | 90 | * @return Result code. |
| 90 | */ | 91 | */ |
| 91 | Result Initialize(std::string device_name, const AudioOutParameter& in_params, u32 handle, | 92 | Result Initialize(std::string device_name, const AudioOutParameter& in_params, |
| 92 | u64 applet_resource_user_id); | 93 | Kernel::KProcess* handle, u64 applet_resource_user_id); |
| 93 | 94 | ||
| 94 | /** | 95 | /** |
| 95 | * Start this system. | 96 | * Start this system. |
| @@ -228,8 +229,8 @@ public: | |||
| 228 | private: | 229 | private: |
| 229 | /// Core system | 230 | /// Core system |
| 230 | Core::System& system; | 231 | Core::System& system; |
| 231 | /// (Unused) | 232 | /// Process handle |
| 232 | u32 handle{}; | 233 | Kernel::KProcess* handle{}; |
| 233 | /// (Unused) | 234 | /// (Unused) |
| 234 | u64 applet_resource_user_id{}; | 235 | u64 applet_resource_user_id{}; |
| 235 | /// Buffer event, signalled when a buffer is ready | 236 | /// Buffer event, signalled when a buffer is ready |
diff --git a/src/core/hle/service/audio/audin_u.cpp b/src/core/hle/service/audio/audin_u.cpp index 56fee4591..de2aa6906 100644 --- a/src/core/hle/service/audio/audin_u.cpp +++ b/src/core/hle/service/audio/audin_u.cpp | |||
| @@ -18,11 +18,11 @@ using namespace AudioCore::AudioIn; | |||
| 18 | class IAudioIn final : public ServiceFramework<IAudioIn> { | 18 | class IAudioIn final : public ServiceFramework<IAudioIn> { |
| 19 | public: | 19 | public: |
| 20 | explicit IAudioIn(Core::System& system_, Manager& manager, size_t session_id, | 20 | explicit IAudioIn(Core::System& system_, Manager& manager, size_t session_id, |
| 21 | const std::string& device_name, const AudioInParameter& in_params, u32 handle, | 21 | const std::string& device_name, const AudioInParameter& in_params, |
| 22 | u64 applet_resource_user_id) | 22 | Kernel::KProcess* handle, u64 applet_resource_user_id) |
| 23 | : ServiceFramework{system_, "IAudioIn"}, | 23 | : ServiceFramework{system_, "IAudioIn"}, |
| 24 | service_context{system_, "IAudioIn"}, event{service_context.CreateEvent("AudioInEvent")}, | 24 | service_context{system_, "IAudioIn"}, event{service_context.CreateEvent("AudioInEvent")}, |
| 25 | impl{std::make_shared<In>(system_, manager, event, session_id)} { | 25 | process{handle}, impl{std::make_shared<In>(system_, manager, event, session_id)} { |
| 26 | // clang-format off | 26 | // clang-format off |
| 27 | static const FunctionInfo functions[] = { | 27 | static const FunctionInfo functions[] = { |
| 28 | {0, &IAudioIn::GetAudioInState, "GetAudioInState"}, | 28 | {0, &IAudioIn::GetAudioInState, "GetAudioInState"}, |
| @@ -45,6 +45,8 @@ public: | |||
| 45 | 45 | ||
| 46 | RegisterHandlers(functions); | 46 | RegisterHandlers(functions); |
| 47 | 47 | ||
| 48 | process->Open(); | ||
| 49 | |||
| 48 | if (impl->GetSystem() | 50 | if (impl->GetSystem() |
| 49 | .Initialize(device_name, in_params, handle, applet_resource_user_id) | 51 | .Initialize(device_name, in_params, handle, applet_resource_user_id) |
| 50 | .IsError()) { | 52 | .IsError()) { |
| @@ -55,6 +57,7 @@ public: | |||
| 55 | ~IAudioIn() override { | 57 | ~IAudioIn() override { |
| 56 | impl->Free(); | 58 | impl->Free(); |
| 57 | service_context.CloseEvent(event); | 59 | service_context.CloseEvent(event); |
| 60 | process->Close(); | ||
| 58 | } | 61 | } |
| 59 | 62 | ||
| 60 | [[nodiscard]] std::shared_ptr<In> GetImpl() { | 63 | [[nodiscard]] std::shared_ptr<In> GetImpl() { |
| @@ -196,6 +199,7 @@ private: | |||
| 196 | 199 | ||
| 197 | KernelHelpers::ServiceContext service_context; | 200 | KernelHelpers::ServiceContext service_context; |
| 198 | Kernel::KEvent* event; | 201 | Kernel::KEvent* event; |
| 202 | Kernel::KProcess* process; | ||
| 199 | std::shared_ptr<AudioCore::AudioIn::In> impl; | 203 | std::shared_ptr<AudioCore::AudioIn::In> impl; |
| 200 | Common::ScratchBuffer<u64> released_buffer; | 204 | Common::ScratchBuffer<u64> released_buffer; |
| 201 | }; | 205 | }; |
| @@ -267,6 +271,14 @@ void AudInU::OpenAudioIn(HLERequestContext& ctx) { | |||
| 267 | auto device_name = Common::StringFromBuffer(device_name_data); | 271 | auto device_name = Common::StringFromBuffer(device_name_data); |
| 268 | auto handle{ctx.GetCopyHandle(0)}; | 272 | auto handle{ctx.GetCopyHandle(0)}; |
| 269 | 273 | ||
| 274 | auto process{ctx.GetObjectFromHandle<Kernel::KProcess>(handle)}; | ||
| 275 | if (process.IsNull()) { | ||
| 276 | LOG_ERROR(Service_Audio, "Failed to get process handle"); | ||
| 277 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 278 | rb.Push(ResultUnknown); | ||
| 279 | return; | ||
| 280 | } | ||
| 281 | |||
| 270 | std::scoped_lock l{impl->mutex}; | 282 | std::scoped_lock l{impl->mutex}; |
| 271 | auto link{impl->LinkToManager()}; | 283 | auto link{impl->LinkToManager()}; |
| 272 | if (link.IsError()) { | 284 | if (link.IsError()) { |
| @@ -287,8 +299,9 @@ void AudInU::OpenAudioIn(HLERequestContext& ctx) { | |||
| 287 | LOG_DEBUG(Service_Audio, "Opening new AudioIn, sessionid={}, free sessions={}", new_session_id, | 299 | LOG_DEBUG(Service_Audio, "Opening new AudioIn, sessionid={}, free sessions={}", new_session_id, |
| 288 | impl->num_free_sessions); | 300 | impl->num_free_sessions); |
| 289 | 301 | ||
| 290 | auto audio_in = std::make_shared<IAudioIn>(system, *impl, new_session_id, device_name, | 302 | auto audio_in = |
| 291 | in_params, handle, applet_resource_user_id); | 303 | std::make_shared<IAudioIn>(system, *impl, new_session_id, device_name, in_params, |
| 304 | process.GetPointerUnsafe(), applet_resource_user_id); | ||
| 292 | impl->sessions[new_session_id] = audio_in->GetImpl(); | 305 | impl->sessions[new_session_id] = audio_in->GetImpl(); |
| 293 | impl->applet_resource_user_ids[new_session_id] = applet_resource_user_id; | 306 | impl->applet_resource_user_ids[new_session_id] = applet_resource_user_id; |
| 294 | 307 | ||
| @@ -318,6 +331,14 @@ void AudInU::OpenAudioInProtocolSpecified(HLERequestContext& ctx) { | |||
| 318 | auto device_name = Common::StringFromBuffer(device_name_data); | 331 | auto device_name = Common::StringFromBuffer(device_name_data); |
| 319 | auto handle{ctx.GetCopyHandle(0)}; | 332 | auto handle{ctx.GetCopyHandle(0)}; |
| 320 | 333 | ||
| 334 | auto process{ctx.GetObjectFromHandle<Kernel::KProcess>(handle)}; | ||
| 335 | if (process.IsNull()) { | ||
| 336 | LOG_ERROR(Service_Audio, "Failed to get process handle"); | ||
| 337 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 338 | rb.Push(ResultUnknown); | ||
| 339 | return; | ||
| 340 | } | ||
| 341 | |||
| 321 | std::scoped_lock l{impl->mutex}; | 342 | std::scoped_lock l{impl->mutex}; |
| 322 | auto link{impl->LinkToManager()}; | 343 | auto link{impl->LinkToManager()}; |
| 323 | if (link.IsError()) { | 344 | if (link.IsError()) { |
| @@ -338,8 +359,9 @@ void AudInU::OpenAudioInProtocolSpecified(HLERequestContext& ctx) { | |||
| 338 | LOG_DEBUG(Service_Audio, "Opening new AudioIn, sessionid={}, free sessions={}", new_session_id, | 359 | LOG_DEBUG(Service_Audio, "Opening new AudioIn, sessionid={}, free sessions={}", new_session_id, |
| 339 | impl->num_free_sessions); | 360 | impl->num_free_sessions); |
| 340 | 361 | ||
| 341 | auto audio_in = std::make_shared<IAudioIn>(system, *impl, new_session_id, device_name, | 362 | auto audio_in = |
| 342 | in_params, handle, applet_resource_user_id); | 363 | std::make_shared<IAudioIn>(system, *impl, new_session_id, device_name, in_params, |
| 364 | process.GetPointerUnsafe(), applet_resource_user_id); | ||
| 343 | impl->sessions[new_session_id] = audio_in->GetImpl(); | 365 | impl->sessions[new_session_id] = audio_in->GetImpl(); |
| 344 | impl->applet_resource_user_ids[new_session_id] = applet_resource_user_id; | 366 | impl->applet_resource_user_ids[new_session_id] = applet_resource_user_id; |
| 345 | 367 | ||
diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp index ca683d72c..8cc7b69f4 100644 --- a/src/core/hle/service/audio/audout_u.cpp +++ b/src/core/hle/service/audio/audout_u.cpp | |||
| @@ -26,9 +26,10 @@ class IAudioOut final : public ServiceFramework<IAudioOut> { | |||
| 26 | public: | 26 | public: |
| 27 | explicit IAudioOut(Core::System& system_, AudioCore::AudioOut::Manager& manager, | 27 | explicit IAudioOut(Core::System& system_, AudioCore::AudioOut::Manager& manager, |
| 28 | size_t session_id, const std::string& device_name, | 28 | size_t session_id, const std::string& device_name, |
| 29 | const AudioOutParameter& in_params, u32 handle, u64 applet_resource_user_id) | 29 | const AudioOutParameter& in_params, Kernel::KProcess* handle, |
| 30 | u64 applet_resource_user_id) | ||
| 30 | : ServiceFramework{system_, "IAudioOut"}, service_context{system_, "IAudioOut"}, | 31 | : ServiceFramework{system_, "IAudioOut"}, service_context{system_, "IAudioOut"}, |
| 31 | event{service_context.CreateEvent("AudioOutEvent")}, | 32 | event{service_context.CreateEvent("AudioOutEvent")}, process{handle}, |
| 32 | impl{std::make_shared<AudioCore::AudioOut::Out>(system_, manager, event, session_id)} { | 33 | impl{std::make_shared<AudioCore::AudioOut::Out>(system_, manager, event, session_id)} { |
| 33 | 34 | ||
| 34 | // clang-format off | 35 | // clang-format off |
| @@ -50,11 +51,14 @@ public: | |||
| 50 | }; | 51 | }; |
| 51 | // clang-format on | 52 | // clang-format on |
| 52 | RegisterHandlers(functions); | 53 | RegisterHandlers(functions); |
| 54 | |||
| 55 | process->Open(); | ||
| 53 | } | 56 | } |
| 54 | 57 | ||
| 55 | ~IAudioOut() override { | 58 | ~IAudioOut() override { |
| 56 | impl->Free(); | 59 | impl->Free(); |
| 57 | service_context.CloseEvent(event); | 60 | service_context.CloseEvent(event); |
| 61 | process->Close(); | ||
| 58 | } | 62 | } |
| 59 | 63 | ||
| 60 | [[nodiscard]] std::shared_ptr<AudioCore::AudioOut::Out> GetImpl() { | 64 | [[nodiscard]] std::shared_ptr<AudioCore::AudioOut::Out> GetImpl() { |
| @@ -206,6 +210,7 @@ private: | |||
| 206 | 210 | ||
| 207 | KernelHelpers::ServiceContext service_context; | 211 | KernelHelpers::ServiceContext service_context; |
| 208 | Kernel::KEvent* event; | 212 | Kernel::KEvent* event; |
| 213 | Kernel::KProcess* process; | ||
| 209 | std::shared_ptr<AudioCore::AudioOut::Out> impl; | 214 | std::shared_ptr<AudioCore::AudioOut::Out> impl; |
| 210 | Common::ScratchBuffer<u64> released_buffer; | 215 | Common::ScratchBuffer<u64> released_buffer; |
| 211 | }; | 216 | }; |
| @@ -257,6 +262,14 @@ void AudOutU::OpenAudioOut(HLERequestContext& ctx) { | |||
| 257 | auto device_name = Common::StringFromBuffer(device_name_data); | 262 | auto device_name = Common::StringFromBuffer(device_name_data); |
| 258 | auto handle{ctx.GetCopyHandle(0)}; | 263 | auto handle{ctx.GetCopyHandle(0)}; |
| 259 | 264 | ||
| 265 | auto process{ctx.GetObjectFromHandle<Kernel::KProcess>(handle)}; | ||
| 266 | if (process.IsNull()) { | ||
| 267 | LOG_ERROR(Service_Audio, "Failed to get process handle"); | ||
| 268 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 269 | rb.Push(ResultUnknown); | ||
| 270 | return; | ||
| 271 | } | ||
| 272 | |||
| 260 | auto link{impl->LinkToManager()}; | 273 | auto link{impl->LinkToManager()}; |
| 261 | if (link.IsError()) { | 274 | if (link.IsError()) { |
| 262 | LOG_ERROR(Service_Audio, "Failed to link Audio Out to Audio Manager"); | 275 | LOG_ERROR(Service_Audio, "Failed to link Audio Out to Audio Manager"); |
| @@ -276,10 +289,11 @@ void AudOutU::OpenAudioOut(HLERequestContext& ctx) { | |||
| 276 | LOG_DEBUG(Service_Audio, "Opening new AudioOut, sessionid={}, free sessions={}", new_session_id, | 289 | LOG_DEBUG(Service_Audio, "Opening new AudioOut, sessionid={}, free sessions={}", new_session_id, |
| 277 | impl->num_free_sessions); | 290 | impl->num_free_sessions); |
| 278 | 291 | ||
| 279 | auto audio_out = std::make_shared<IAudioOut>(system, *impl, new_session_id, device_name, | 292 | auto audio_out = |
| 280 | in_params, handle, applet_resource_user_id); | 293 | std::make_shared<IAudioOut>(system, *impl, new_session_id, device_name, in_params, |
| 281 | result = audio_out->GetImpl()->GetSystem().Initialize(device_name, in_params, handle, | 294 | process.GetPointerUnsafe(), applet_resource_user_id); |
| 282 | applet_resource_user_id); | 295 | result = audio_out->GetImpl()->GetSystem().Initialize( |
| 296 | device_name, in_params, process.GetPointerUnsafe(), applet_resource_user_id); | ||
| 283 | if (result.IsError()) { | 297 | if (result.IsError()) { |
| 284 | LOG_ERROR(Service_Audio, "Failed to initialize the AudioOut System!"); | 298 | LOG_ERROR(Service_Audio, "Failed to initialize the AudioOut System!"); |
| 285 | IPC::ResponseBuilder rb{ctx, 2}; | 299 | IPC::ResponseBuilder rb{ctx, 2}; |