mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-04-29 21:58:58 +02:00
[qt_common, core, audio] remove duplicate string literal definitions, inline SystemManager::threadfunc, increase latency of audio shutdown (#3030)
Very small code cleanup, also remove `[[unlikely]]` because it doesn't matter + increase latency of audio render when shutting down Signed-off-by: lizzie lizzie@eden-emu.dev Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3030 Reviewed-by: Caio Oliveira <caiooliveirafarias0@gmail.com> Reviewed-by: crueter <crueter@eden-emu.dev> Co-authored-by: lizzie <lizzie@eden-emu.dev> Co-committed-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
parent
c160d6b752
commit
d1ac5b2e50
8 changed files with 54 additions and 87 deletions
|
|
@ -130,16 +130,14 @@ void AudioRenderer::CreateSinkStreams() {
|
|||
}
|
||||
|
||||
void AudioRenderer::Main(std::stop_token stop_token) {
|
||||
static constexpr char name[]{"DSP_AudioRenderer_Main"};
|
||||
Common::SetCurrentThreadName(name);
|
||||
Common::SetCurrentThreadName("DSP_AudioRenderer_Main");
|
||||
Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
|
||||
|
||||
// TODO: Create buffer map/unmap thread + mailbox
|
||||
// TODO: Create gMix devices, initialize them here
|
||||
|
||||
if (mailbox.Receive(Direction::DSP) != Message::InitializeOK) {
|
||||
LOG_ERROR(Service_Audio,
|
||||
"ADSP Audio Renderer -- Failed to receive initialize message from host!");
|
||||
LOG_ERROR(Service_Audio, "ADSP Audio Renderer -- Failed to receive initialize message from host!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -156,8 +154,8 @@ void AudioRenderer::Main(std::stop_token stop_token) {
|
|||
return;
|
||||
|
||||
case Message::Render: {
|
||||
if (system.IsShuttingDown()) [[unlikely]] {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||
if (system.IsShuttingDown()) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
mailbox.Send(Direction::Host, Message::RenderResponse);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -175,8 +173,8 @@ void AudioRenderer::Main(std::stop_token stop_token) {
|
|||
// this is a new command list, initialize it.
|
||||
if (command_buffer.remaining_command_count == 0) {
|
||||
command_list_processor.Initialize(system, *command_buffer.process,
|
||||
command_buffer.buffer,
|
||||
command_buffer.size, streams[index]);
|
||||
command_buffer.buffer,
|
||||
command_buffer.size, streams[index]);
|
||||
}
|
||||
|
||||
if (command_buffer.reset_buffer && !buffers_reset[index]) {
|
||||
|
|
@ -213,13 +211,10 @@ void AudioRenderer::Main(std::stop_token stop_token) {
|
|||
command_buffer.render_time_taken_us = end_time - start_time;
|
||||
}
|
||||
}
|
||||
|
||||
mailbox.Send(Direction::Host, Message::RenderResponse);
|
||||
} break;
|
||||
|
||||
default:
|
||||
LOG_WARNING(Service_Audio,
|
||||
"ADSP AudioRenderer received an invalid message, msg={:02X}!", msg);
|
||||
LOG_WARNING(Service_Audio, "ADSP AudioRenderer received an invalid message, msg={:02X}!", msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,73 +26,59 @@ void SystemManager::InitializeUnsafe() {
|
|||
if (!active) {
|
||||
active = true;
|
||||
audio_renderer.Start();
|
||||
thread = std::jthread([this](std::stop_token stop_token) { ThreadFunc(stop_token); });
|
||||
thread = std::jthread([this](std::stop_token stop_token) {
|
||||
Common::SetCurrentThreadName("AudioRenderSystemManager");
|
||||
Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
|
||||
while (active && !stop_token.stop_requested()) {
|
||||
{
|
||||
std::scoped_lock l{mutex1};
|
||||
for (auto system : systems)
|
||||
system->SendCommandToDsp();
|
||||
}
|
||||
audio_renderer.Signal();
|
||||
audio_renderer.Wait();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void SystemManager::Stop() {
|
||||
if (!active) {
|
||||
return;
|
||||
if (active) {
|
||||
active = false;
|
||||
thread.request_stop();
|
||||
thread.join();
|
||||
audio_renderer.Stop();
|
||||
}
|
||||
active = false;
|
||||
thread.request_stop();
|
||||
thread.join();
|
||||
audio_renderer.Stop();
|
||||
}
|
||||
|
||||
bool SystemManager::Add(System& system_) {
|
||||
std::scoped_lock l2{mutex2};
|
||||
|
||||
if (systems.size() + 1 > MaxRendererSessions) {
|
||||
LOG_ERROR(Service_Audio, "Maximum AudioRenderer Systems active, cannot add more!");
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
std::scoped_lock l{mutex1};
|
||||
if (systems.empty()) {
|
||||
if (systems.empty())
|
||||
InitializeUnsafe();
|
||||
}
|
||||
}
|
||||
|
||||
systems.push_back(&system_);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SystemManager::Remove(System& system_) {
|
||||
std::scoped_lock l2{mutex2};
|
||||
|
||||
{
|
||||
std::scoped_lock l{mutex1};
|
||||
if (systems.remove(&system_) == 0) {
|
||||
LOG_ERROR(Service_Audio,
|
||||
"Failed to remove a render system, it was not found in the list!");
|
||||
LOG_ERROR(Service_Audio, "Failed to remove a render system, it was not found in the list!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (systems.empty()) {
|
||||
if (systems.empty())
|
||||
Stop();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SystemManager::ThreadFunc(std::stop_token stop_token) {
|
||||
static constexpr char name[]{"AudioRenderSystemManager"};
|
||||
Common::SetCurrentThreadName(name);
|
||||
Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
|
||||
while (active && !stop_token.stop_requested()) {
|
||||
{
|
||||
std::scoped_lock l{mutex1};
|
||||
|
||||
for (auto system : systems) {
|
||||
system->SendCommandToDsp();
|
||||
}
|
||||
}
|
||||
|
||||
audio_renderer.Signal();
|
||||
audio_renderer.Wait();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace AudioCore::Renderer
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -66,11 +69,6 @@ public:
|
|||
bool Remove(System& system);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Main thread responsible for command generation.
|
||||
*/
|
||||
void ThreadFunc(std::stop_token stop_token);
|
||||
|
||||
/// Core system
|
||||
Core::System& core;
|
||||
/// List of pointers to managed systems
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue