mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-09-18 08:59:51 +00:00
@@ -183,43 +183,19 @@ public:
|
|||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
OpusDecoder::OpusDecoder(Core::System& system_) : system{system_} {
|
OpusDecoder::OpusDecoder(Core::System& system) {
|
||||||
init_thread = std::jthread([this](std::stop_token stop_token) { Init(stop_token); });
|
dsp_thread = std::jthread([this, &system](std::stop_token stop_token) {
|
||||||
}
|
Common::SetCurrentThreadName("DSP_OpusDecoder");
|
||||||
|
if (Receive(Direction::DSP, stop_token) != Message::Start) {
|
||||||
|
LOG_ERROR(Service_Audio, "DSP OpusDecoder failed to receive Start message. Opus initialization failed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Send(Direction::Host, Message::StartOK);
|
||||||
|
|
||||||
OpusDecoder::~OpusDecoder() {
|
// Main OpusDecoder thread, responsible for processing the incoming Opus packets.
|
||||||
if (main_thread.joinable()) {
|
|
||||||
// Shutdown the thread
|
|
||||||
Send(Direction::DSP, Message::Shutdown);
|
|
||||||
auto msg = Receive(Direction::Host);
|
|
||||||
ASSERT_MSG(msg == Message::ShutdownOK, "Expected Opus shutdown code {}, got {}", Message::ShutdownOK, msg);
|
|
||||||
main_thread.request_stop();
|
|
||||||
main_thread.join();
|
|
||||||
} else {
|
|
||||||
init_thread.request_stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpusDecoder::Send(Direction dir, u32 message) {
|
|
||||||
mailbox.Send(dir, std::move(message));
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 OpusDecoder::Receive(Direction dir, std::stop_token stop_token) {
|
|
||||||
return mailbox.Receive(dir, stop_token);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpusDecoder::Init(std::stop_token stop_token) {
|
|
||||||
Common::SetCurrentThreadName("DSP_OpusDecoder_Init");
|
|
||||||
if (Receive(Direction::DSP, stop_token) != Message::Start) {
|
|
||||||
LOG_ERROR(Service_Audio, "DSP OpusDecoder failed to receive Start message. Opus initialization failed.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Main OpusDecoder thread, responsible for processing the incoming Opus packets.
|
|
||||||
main_thread = std::jthread([this](std::stop_token thread_stop_token) {
|
|
||||||
::Common::unordered_map<u64, OpusGenericDecodeObject> decode_objects;
|
::Common::unordered_map<u64, OpusGenericDecodeObject> decode_objects;
|
||||||
Common::SetCurrentThreadName("DSP_OpusDecoder_Main");
|
while (!stop_token.stop_requested()) {
|
||||||
while (!thread_stop_token.stop_requested()) {
|
auto msg = Receive(Direction::DSP, stop_token);
|
||||||
auto msg = Receive(Direction::DSP, thread_stop_token);
|
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
case Shutdown:
|
case Shutdown:
|
||||||
Send(Direction::Host, Message::ShutdownOK);
|
Send(Direction::Host, Message::ShutdownOK);
|
||||||
@@ -399,7 +375,26 @@ void OpusDecoder::Init(std::stop_token stop_token) {
|
|||||||
for (auto e : decode_objects)
|
for (auto e : decode_objects)
|
||||||
e.second.Shutdown();
|
e.second.Shutdown();
|
||||||
});
|
});
|
||||||
Send(Direction::Host, Message::StartOK);
|
}
|
||||||
|
|
||||||
|
OpusDecoder::~OpusDecoder() {
|
||||||
|
if (dsp_thread.joinable()) {
|
||||||
|
// Shutdown the thread
|
||||||
|
auto const stop_token = dsp_thread.get_stop_token();
|
||||||
|
Send(Direction::DSP, Message::Shutdown);
|
||||||
|
auto msg = Receive(Direction::Host, stop_token);
|
||||||
|
ASSERT_MSG(msg == Message::ShutdownOK, "Expected Opus shutdown code {}, got {}", Message::ShutdownOK, msg);
|
||||||
|
dsp_thread.request_stop();
|
||||||
|
dsp_thread.join();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpusDecoder::Send(Direction dir, u32 message) {
|
||||||
|
mailbox.Send(dir, std::move(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 OpusDecoder::Receive(Direction dir, std::stop_token stop_token) {
|
||||||
|
return mailbox.Receive(dir, stop_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace AudioCore::ADSP::OpusDecoder
|
} // namespace AudioCore::ADSP::OpusDecoder
|
||||||
|
|||||||
@@ -67,27 +67,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// @brief Initializing thread, launched at audio_core boot to avoid blocking the main emu boot thread.
|
|
||||||
void Init(std::stop_token stop_token);
|
|
||||||
/**
|
|
||||||
* Main OpusDecoder thread, responsible for processing the incoming Opus packets.
|
|
||||||
*/
|
|
||||||
void Main(std::stop_token stop_token);
|
|
||||||
|
|
||||||
/// Mailbox to communicate messages with the host, drives the main thread
|
/// Mailbox to communicate messages with the host, drives the main thread
|
||||||
Mailbox mailbox;
|
Mailbox mailbox;
|
||||||
/// Core system
|
|
||||||
Core::System& system;
|
|
||||||
/// Structure shared with the host, input data set by the host before sending a mailbox message,
|
/// Structure shared with the host, input data set by the host before sending a mailbox message,
|
||||||
/// and the responses are written back by the OpusDecoder.
|
/// and the responses are written back by the OpusDecoder.
|
||||||
SharedMemory* shared_memory{};
|
SharedMemory* shared_memory{};
|
||||||
/// Init thread
|
std::jthread dsp_thread{};
|
||||||
std::jthread init_thread{};
|
|
||||||
/// Main thread
|
|
||||||
std::jthread main_thread{};
|
|
||||||
|
|
||||||
/// The current state
|
|
||||||
bool running{};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace AudioCore::ADSP::OpusDecoder
|
} // namespace AudioCore::ADSP::OpusDecoder
|
||||||
|
|||||||
Reference in New Issue
Block a user