diff --git a/hooks/audio/implementations/pipewire.cpp b/hooks/audio/implementations/pipewire.cpp index ab027eb..5a54b29 100644 --- a/hooks/audio/implementations/pipewire.cpp +++ b/hooks/audio/implementations/pipewire.cpp @@ -94,7 +94,7 @@ HRESULT PipewireBackend::on_initialize(AUDCLNT_SHAREMODE *ShareMode, DWORD *Stre log_info("audio::pipewire", "{}", __FUNCTION__); // Initialize pipewire client (without starting the thread) - client_ = BmswClientCreate(GAME_INSTANCE->title(), nullptr, nullptr);//(void *)callback_notify,this + client_ = BmswClientCreate(GAME_INSTANCE->title(), nullptr, nullptr); notif_ = std::thread(PipewireBackend::notif_poll, this); if (!client_) @@ -116,9 +116,12 @@ HRESULT PipewireBackend::on_initialize(AUDCLNT_SHAREMODE *ShareMode, DWORD *Stre HRESULT PipewireBackend::on_set_event_handle(HANDLE *event_handle) { log_info("audio::pipewire", "{}", __FUNCTION__); - this->relay_handle_ = *event_handle; // take over WASAPI's owned handle pre-initialized by client - //BmswClientUpdateCallback(client_, (void *) 0, this->relay_handle_); - *event_handle = CreateEvent(nullptr, true, false, nullptr); // replace WASAPI's handle with always off handle + + // Take over WASAPI's owned handle pre-initialized by client and replace with always off dummy, cleaning up previously owned handle + if (relay_handle_) CloseHandle(relay_handle_); + relay_handle_ = *event_handle; + *event_handle = CreateEvent(nullptr, true, false, nullptr); + //BmswClientUpdateCallback(client_, (void *) 0, relay_handle_); return S_OK; @@ -137,7 +140,7 @@ HRESULT PipewireBackend::on_start() noexcept BmswClientStart(client_); return S_OK; } -PipewireBackend::PipewireBackend() : relay_handle_(nullptr), format_(hooks::audio::FORMAT), client_(nullptr), notif_state_(-1) +PipewireBackend::PipewireBackend() : relay_handle_(CreateEvent(nullptr, true, false, nullptr)), format_(hooks::audio::FORMAT), client_(nullptr), notif_state_(-1) { log_info("audio::pipewire", "{}", __FUNCTION__); @@ -183,7 +186,7 @@ inline static void callback_notify(void *self) { DWORD last_error = GetLastError(); - log_warning("audio::pipewire", "SetEvent failed: {} ({})", + log_warning("audio::pipewire", "SetEvent failed({}): {}", last_error, std::system_category().message(last_error)); } @@ -267,6 +270,7 @@ PipewireBackend::~PipewireBackend() } } if (client_) BmswClientDestroy(client_); + if (relay_handle_) CloseHandle(relay_handle_); } /* Unsorted (unknown callers, should be considered as unimplemented/untested) *///_BUG: does this need implementation? @@ -277,14 +281,14 @@ const WAVEFORMATEXTENSIBLE &PipewireBackend::format() const noexcept } HRESULT PipewireBackend::on_get_stream_latency(REFERENCE_TIME *latency) noexcept { - log_info("audio::pipewire", "{}", __FUNCTION__); +// log_info("audio::pipewire", "{}", __FUNCTION__); *latency = BmswClientFormatPeriodWRT(client_); return S_OK; } HRESULT PipewireBackend::on_get_current_padding(std::optional &padding_frames) noexcept { - log_info("audio::pipewire", "{}", __FUNCTION__); +// log_info("audio::pipewire", "{}", __FUNCTION__); padding_frames = 0; return S_OK;