mirror of https://git.suyu.dev/suyu/suyu
service/audio: Remove global system accessors
Trims out the lingering reliance on global state out of the audio code.
This commit is contained in:
parent
7653e4babc
commit
ed0485c599
|
@ -19,16 +19,16 @@
|
||||||
|
|
||||||
namespace Service::Audio {
|
namespace Service::Audio {
|
||||||
|
|
||||||
void InstallInterfaces(SM::ServiceManager& service_manager) {
|
void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) {
|
||||||
std::make_shared<AudCtl>()->InstallAsService(service_manager);
|
std::make_shared<AudCtl>()->InstallAsService(service_manager);
|
||||||
std::make_shared<AudOutA>()->InstallAsService(service_manager);
|
std::make_shared<AudOutA>()->InstallAsService(service_manager);
|
||||||
std::make_shared<AudOutU>()->InstallAsService(service_manager);
|
std::make_shared<AudOutU>(system)->InstallAsService(service_manager);
|
||||||
std::make_shared<AudInA>()->InstallAsService(service_manager);
|
std::make_shared<AudInA>()->InstallAsService(service_manager);
|
||||||
std::make_shared<AudInU>()->InstallAsService(service_manager);
|
std::make_shared<AudInU>()->InstallAsService(service_manager);
|
||||||
std::make_shared<AudRecA>()->InstallAsService(service_manager);
|
std::make_shared<AudRecA>()->InstallAsService(service_manager);
|
||||||
std::make_shared<AudRecU>()->InstallAsService(service_manager);
|
std::make_shared<AudRecU>()->InstallAsService(service_manager);
|
||||||
std::make_shared<AudRenA>()->InstallAsService(service_manager);
|
std::make_shared<AudRenA>()->InstallAsService(service_manager);
|
||||||
std::make_shared<AudRenU>()->InstallAsService(service_manager);
|
std::make_shared<AudRenU>(system)->InstallAsService(service_manager);
|
||||||
std::make_shared<CodecCtl>()->InstallAsService(service_manager);
|
std::make_shared<CodecCtl>()->InstallAsService(service_manager);
|
||||||
std::make_shared<HwOpus>()->InstallAsService(service_manager);
|
std::make_shared<HwOpus>()->InstallAsService(service_manager);
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,10 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class System;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Service::SM {
|
namespace Service::SM {
|
||||||
class ServiceManager;
|
class ServiceManager;
|
||||||
}
|
}
|
||||||
|
@ -11,6 +15,6 @@ class ServiceManager;
|
||||||
namespace Service::Audio {
|
namespace Service::Audio {
|
||||||
|
|
||||||
/// Registers all Audio services with the specified service manager.
|
/// Registers all Audio services with the specified service manager.
|
||||||
void InstallInterfaces(SM::ServiceManager& service_manager);
|
void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system);
|
||||||
|
|
||||||
} // namespace Service::Audio
|
} // namespace Service::Audio
|
||||||
|
|
|
@ -40,8 +40,8 @@ enum class AudioState : u32 {
|
||||||
|
|
||||||
class IAudioOut final : public ServiceFramework<IAudioOut> {
|
class IAudioOut final : public ServiceFramework<IAudioOut> {
|
||||||
public:
|
public:
|
||||||
IAudioOut(AudoutParams audio_params, AudioCore::AudioOut& audio_core, std::string&& device_name,
|
IAudioOut(Core::System& system, AudoutParams audio_params, AudioCore::AudioOut& audio_core,
|
||||||
std::string&& unique_name)
|
std::string&& device_name, std::string&& unique_name)
|
||||||
: ServiceFramework("IAudioOut"), audio_core(audio_core),
|
: ServiceFramework("IAudioOut"), audio_core(audio_core),
|
||||||
device_name(std::move(device_name)), audio_params(audio_params) {
|
device_name(std::move(device_name)), audio_params(audio_params) {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
@ -65,7 +65,6 @@ public:
|
||||||
RegisterHandlers(functions);
|
RegisterHandlers(functions);
|
||||||
|
|
||||||
// This is the event handle used to check if the audio buffer was released
|
// This is the event handle used to check if the audio buffer was released
|
||||||
auto& system = Core::System::GetInstance();
|
|
||||||
buffer_event = Kernel::WritableEvent::CreateEventPair(
|
buffer_event = Kernel::WritableEvent::CreateEventPair(
|
||||||
system.Kernel(), Kernel::ResetType::Manual, "IAudioOutBufferReleased");
|
system.Kernel(), Kernel::ResetType::Manual, "IAudioOutBufferReleased");
|
||||||
|
|
||||||
|
@ -212,6 +211,22 @@ private:
|
||||||
Kernel::EventPair buffer_event;
|
Kernel::EventPair buffer_event;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AudOutU::AudOutU(Core::System& system_) : ServiceFramework("audout:u"), system{system_} {
|
||||||
|
// clang-format off
|
||||||
|
static const FunctionInfo functions[] = {
|
||||||
|
{0, &AudOutU::ListAudioOutsImpl, "ListAudioOuts"},
|
||||||
|
{1, &AudOutU::OpenAudioOutImpl, "OpenAudioOut"},
|
||||||
|
{2, &AudOutU::ListAudioOutsImpl, "ListAudioOutsAuto"},
|
||||||
|
{3, &AudOutU::OpenAudioOutImpl, "OpenAudioOutAuto"},
|
||||||
|
};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
|
RegisterHandlers(functions);
|
||||||
|
audio_core = std::make_unique<AudioCore::AudioOut>();
|
||||||
|
}
|
||||||
|
|
||||||
|
AudOutU::~AudOutU() = default;
|
||||||
|
|
||||||
void AudOutU::ListAudioOutsImpl(Kernel::HLERequestContext& ctx) {
|
void AudOutU::ListAudioOutsImpl(Kernel::HLERequestContext& ctx) {
|
||||||
LOG_DEBUG(Service_Audio, "called");
|
LOG_DEBUG(Service_Audio, "called");
|
||||||
|
|
||||||
|
@ -248,7 +263,7 @@ void AudOutU::OpenAudioOutImpl(Kernel::HLERequestContext& ctx) {
|
||||||
|
|
||||||
std::string unique_name{fmt::format("{}-{}", device_name, audio_out_interfaces.size())};
|
std::string unique_name{fmt::format("{}-{}", device_name, audio_out_interfaces.size())};
|
||||||
auto audio_out_interface = std::make_shared<IAudioOut>(
|
auto audio_out_interface = std::make_shared<IAudioOut>(
|
||||||
params, *audio_core, std::move(device_name), std::move(unique_name));
|
system, params, *audio_core, std::move(device_name), std::move(unique_name));
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 6, 0, 1};
|
IPC::ResponseBuilder rb{ctx, 6, 0, 1};
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
|
@ -256,20 +271,9 @@ void AudOutU::OpenAudioOutImpl(Kernel::HLERequestContext& ctx) {
|
||||||
rb.Push<u32>(params.channel_count);
|
rb.Push<u32>(params.channel_count);
|
||||||
rb.Push<u32>(static_cast<u32>(AudioCore::Codec::PcmFormat::Int16));
|
rb.Push<u32>(static_cast<u32>(AudioCore::Codec::PcmFormat::Int16));
|
||||||
rb.Push<u32>(static_cast<u32>(AudioState::Stopped));
|
rb.Push<u32>(static_cast<u32>(AudioState::Stopped));
|
||||||
rb.PushIpcInterface<Audio::IAudioOut>(audio_out_interface);
|
rb.PushIpcInterface<IAudioOut>(audio_out_interface);
|
||||||
|
|
||||||
audio_out_interfaces.push_back(std::move(audio_out_interface));
|
audio_out_interfaces.push_back(std::move(audio_out_interface));
|
||||||
}
|
}
|
||||||
|
|
||||||
AudOutU::AudOutU() : ServiceFramework("audout:u") {
|
|
||||||
static const FunctionInfo functions[] = {{0, &AudOutU::ListAudioOutsImpl, "ListAudioOuts"},
|
|
||||||
{1, &AudOutU::OpenAudioOutImpl, "OpenAudioOut"},
|
|
||||||
{2, &AudOutU::ListAudioOutsImpl, "ListAudioOutsAuto"},
|
|
||||||
{3, &AudOutU::OpenAudioOutImpl, "OpenAudioOutAuto"}};
|
|
||||||
RegisterHandlers(functions);
|
|
||||||
audio_core = std::make_unique<AudioCore::AudioOut>();
|
|
||||||
}
|
|
||||||
|
|
||||||
AudOutU::~AudOutU() = default;
|
|
||||||
|
|
||||||
} // namespace Service::Audio
|
} // namespace Service::Audio
|
||||||
|
|
|
@ -11,6 +11,10 @@ namespace AudioCore {
|
||||||
class AudioOut;
|
class AudioOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class System;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
class HLERequestContext;
|
class HLERequestContext;
|
||||||
}
|
}
|
||||||
|
@ -21,15 +25,17 @@ class IAudioOut;
|
||||||
|
|
||||||
class AudOutU final : public ServiceFramework<AudOutU> {
|
class AudOutU final : public ServiceFramework<AudOutU> {
|
||||||
public:
|
public:
|
||||||
AudOutU();
|
explicit AudOutU(Core::System& system_);
|
||||||
~AudOutU() override;
|
~AudOutU() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void ListAudioOutsImpl(Kernel::HLERequestContext& ctx);
|
||||||
|
void OpenAudioOutImpl(Kernel::HLERequestContext& ctx);
|
||||||
|
|
||||||
std::vector<std::shared_ptr<IAudioOut>> audio_out_interfaces;
|
std::vector<std::shared_ptr<IAudioOut>> audio_out_interfaces;
|
||||||
std::unique_ptr<AudioCore::AudioOut> audio_core;
|
std::unique_ptr<AudioCore::AudioOut> audio_core;
|
||||||
|
|
||||||
void ListAudioOutsImpl(Kernel::HLERequestContext& ctx);
|
Core::System& system;
|
||||||
void OpenAudioOutImpl(Kernel::HLERequestContext& ctx);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Service::Audio
|
} // namespace Service::Audio
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace Service::Audio {
|
||||||
|
|
||||||
class IAudioRenderer final : public ServiceFramework<IAudioRenderer> {
|
class IAudioRenderer final : public ServiceFramework<IAudioRenderer> {
|
||||||
public:
|
public:
|
||||||
explicit IAudioRenderer(AudioCore::AudioRendererParameter audren_params,
|
explicit IAudioRenderer(Core::System& system, AudioCore::AudioRendererParameter audren_params,
|
||||||
const std::size_t instance_number)
|
const std::size_t instance_number)
|
||||||
: ServiceFramework("IAudioRenderer") {
|
: ServiceFramework("IAudioRenderer") {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
@ -47,7 +47,6 @@ public:
|
||||||
// clang-format on
|
// clang-format on
|
||||||
RegisterHandlers(functions);
|
RegisterHandlers(functions);
|
||||||
|
|
||||||
auto& system = Core::System::GetInstance();
|
|
||||||
system_event = Kernel::WritableEvent::CreateEventPair(
|
system_event = Kernel::WritableEvent::CreateEventPair(
|
||||||
system.Kernel(), Kernel::ResetType::Manual, "IAudioRenderer:SystemEvent");
|
system.Kernel(), Kernel::ResetType::Manual, "IAudioRenderer:SystemEvent");
|
||||||
renderer = std::make_unique<AudioCore::AudioRenderer>(
|
renderer = std::make_unique<AudioCore::AudioRenderer>(
|
||||||
|
@ -161,7 +160,7 @@ private:
|
||||||
|
|
||||||
class IAudioDevice final : public ServiceFramework<IAudioDevice> {
|
class IAudioDevice final : public ServiceFramework<IAudioDevice> {
|
||||||
public:
|
public:
|
||||||
explicit IAudioDevice() : ServiceFramework("IAudioDevice") {
|
explicit IAudioDevice(Core::System& system) : ServiceFramework("IAudioDevice") {
|
||||||
static const FunctionInfo functions[] = {
|
static const FunctionInfo functions[] = {
|
||||||
{0, &IAudioDevice::ListAudioDeviceName, "ListAudioDeviceName"},
|
{0, &IAudioDevice::ListAudioDeviceName, "ListAudioDeviceName"},
|
||||||
{1, &IAudioDevice::SetAudioDeviceOutputVolume, "SetAudioDeviceOutputVolume"},
|
{1, &IAudioDevice::SetAudioDeviceOutputVolume, "SetAudioDeviceOutputVolume"},
|
||||||
|
@ -179,7 +178,7 @@ public:
|
||||||
};
|
};
|
||||||
RegisterHandlers(functions);
|
RegisterHandlers(functions);
|
||||||
|
|
||||||
auto& kernel = Core::System::GetInstance().Kernel();
|
auto& kernel = system.Kernel();
|
||||||
buffer_event = Kernel::WritableEvent::CreateEventPair(kernel, Kernel::ResetType::Automatic,
|
buffer_event = Kernel::WritableEvent::CreateEventPair(kernel, Kernel::ResetType::Automatic,
|
||||||
"IAudioOutBufferReleasedEvent");
|
"IAudioOutBufferReleasedEvent");
|
||||||
|
|
||||||
|
@ -277,7 +276,7 @@ private:
|
||||||
|
|
||||||
}; // namespace Audio
|
}; // namespace Audio
|
||||||
|
|
||||||
AudRenU::AudRenU() : ServiceFramework("audren:u") {
|
AudRenU::AudRenU(Core::System& system_) : ServiceFramework("audren:u"), system{system_} {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
static const FunctionInfo functions[] = {
|
static const FunctionInfo functions[] = {
|
||||||
{0, &AudRenU::OpenAudioRenderer, "OpenAudioRenderer"},
|
{0, &AudRenU::OpenAudioRenderer, "OpenAudioRenderer"},
|
||||||
|
@ -605,7 +604,7 @@ void AudRenU::GetAudioDeviceService(Kernel::HLERequestContext& ctx) {
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
||||||
|
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
rb.PushIpcInterface<Audio::IAudioDevice>();
|
rb.PushIpcInterface<IAudioDevice>(system);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudRenU::OpenAudioRendererAuto(Kernel::HLERequestContext& ctx) {
|
void AudRenU::OpenAudioRendererAuto(Kernel::HLERequestContext& ctx) {
|
||||||
|
@ -619,9 +618,10 @@ void AudRenU::GetAudioDeviceServiceWithRevisionInfo(Kernel::HLERequestContext& c
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
||||||
|
|
||||||
|
// TODO(ogniK): Figure out what is different based on the current revision
|
||||||
|
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
rb.PushIpcInterface<Audio::IAudioDevice>(); // TODO(ogniK): Figure out what is different
|
rb.PushIpcInterface<IAudioDevice>(system);
|
||||||
// based on the current revision
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudRenU::OpenAudioRendererImpl(Kernel::HLERequestContext& ctx) {
|
void AudRenU::OpenAudioRendererImpl(Kernel::HLERequestContext& ctx) {
|
||||||
|
@ -630,7 +630,7 @@ void AudRenU::OpenAudioRendererImpl(Kernel::HLERequestContext& ctx) {
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
||||||
|
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
rb.PushIpcInterface<IAudioRenderer>(params, audren_instance_count++);
|
rb.PushIpcInterface<IAudioRenderer>(system, params, audren_instance_count++);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudRenU::IsFeatureSupported(AudioFeatures feature, u32_le revision) const {
|
bool AudRenU::IsFeatureSupported(AudioFeatures feature, u32_le revision) const {
|
||||||
|
|
|
@ -6,6 +6,10 @@
|
||||||
|
|
||||||
#include "core/hle/service/service.h"
|
#include "core/hle/service/service.h"
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class System;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
class HLERequestContext;
|
class HLERequestContext;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +18,7 @@ namespace Service::Audio {
|
||||||
|
|
||||||
class AudRenU final : public ServiceFramework<AudRenU> {
|
class AudRenU final : public ServiceFramework<AudRenU> {
|
||||||
public:
|
public:
|
||||||
explicit AudRenU();
|
explicit AudRenU(Core::System& system_);
|
||||||
~AudRenU() override;
|
~AudRenU() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -33,7 +37,9 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
bool IsFeatureSupported(AudioFeatures feature, u32_le revision) const;
|
bool IsFeatureSupported(AudioFeatures feature, u32_le revision) const;
|
||||||
|
|
||||||
std::size_t audren_instance_count = 0;
|
std::size_t audren_instance_count = 0;
|
||||||
|
Core::System& system;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Service::Audio
|
} // namespace Service::Audio
|
||||||
|
|
|
@ -206,7 +206,7 @@ void Init(std::shared_ptr<SM::ServiceManager>& sm, Core::System& system) {
|
||||||
AM::InstallInterfaces(*sm, nv_flinger, system);
|
AM::InstallInterfaces(*sm, nv_flinger, system);
|
||||||
AOC::InstallInterfaces(*sm);
|
AOC::InstallInterfaces(*sm);
|
||||||
APM::InstallInterfaces(system);
|
APM::InstallInterfaces(system);
|
||||||
Audio::InstallInterfaces(*sm);
|
Audio::InstallInterfaces(*sm, system);
|
||||||
BCAT::InstallInterfaces(*sm);
|
BCAT::InstallInterfaces(*sm);
|
||||||
BPC::InstallInterfaces(*sm);
|
BPC::InstallInterfaces(*sm);
|
||||||
BtDrv::InstallInterfaces(*sm);
|
BtDrv::InstallInterfaces(*sm);
|
||||||
|
|
Loading…
Reference in New Issue