diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/hle/service/audio/audin_u.cpp | 36 | ||||
| -rw-r--r-- | src/core/hle/service/audio/audout_u.cpp | 26 |
2 files changed, 49 insertions, 13 deletions
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}; |