diff options
author | Markus Härer <markus.haerer@gmx.net> | 2024-04-23 01:21:08 +0200 |
---|---|---|
committer | Markus Härer <markus.haerer@gmx.net> | 2024-04-23 01:32:40 +0200 |
commit | 6cad37352412345c3d1868b97a4a8a19fe4769c0 (patch) | |
tree | c5bef85d7e011d18063452701bdae3a87235ce37 | |
parent | 180b099125edcbc5393376ef6820795c9f527d26 (diff) | |
download | xbmc-6cad37352412345c3d1868b97a4a8a19fe4769c0.tar.xz |
fixup! [AudioEngine] Make a smarter choice between PulseAudio and PipeWire
-rw-r--r-- | xbmc/cores/AudioEngine/Sinks/AESinkPULSE.cpp | 35 | ||||
-rw-r--r-- | xbmc/platform/freebsd/PlatformFreebsd.cpp | 6 |
2 files changed, 23 insertions, 18 deletions
diff --git a/xbmc/cores/AudioEngine/Sinks/AESinkPULSE.cpp b/xbmc/cores/AudioEngine/Sinks/AESinkPULSE.cpp index bfbafa969e..5ec64fe9f0 100644 --- a/xbmc/cores/AudioEngine/Sinks/AESinkPULSE.cpp +++ b/xbmc/cores/AudioEngine/Sinks/AESinkPULSE.cpp @@ -320,20 +320,17 @@ static void SinkChangedCallback(pa_context *c, pa_subscription_event_type_t t, u struct ServerInfoStruct { - std::mutex m_mutex; - std::condition_variable m_cv; + pa_threaded_mainloop* m_mainloop; bool m_isInfoSet{false}; - - bool m_isPipeWireServer{}; ///< true if server name contains "PipeWire" in any casing + std::string m_serverName; }; static void ServerInfoCallback(pa_context* c, const pa_server_info* i, void* userdata) { auto serverInfo = reinterpret_cast<ServerInfoStruct*>(userdata); - std::unique_lock l(serverInfo->m_mutex); - serverInfo->m_isPipeWireServer = StringUtils::Contains(i->server_name, "pipewire", true); + serverInfo->m_serverName = i->server_name; serverInfo->m_isInfoSet = true; - serverInfo->m_cv.notify_one(); + pa_threaded_mainloop_signal(serverInfo->m_mainloop, 0); } struct SinkInfoStruct @@ -685,24 +682,32 @@ bool CDriverMonitor::Start(bool allowPipeWireCompatServer) return false; } + pa_threaded_mainloop_lock(m_pMainLoop); + + ServerInfoStruct serverInfo; + serverInfo.m_mainloop = m_pMainLoop; + pa_context_get_server_info(m_pContext, ServerInfoCallback, &serverInfo); + while (!serverInfo.m_isInfoSet) + pa_threaded_mainloop_wait(m_pMainLoop); + + CLog::Log(LOGINFO, "PulseAudio: Server name: {}", serverInfo.m_serverName); + #ifdef HAS_PIPEWIRE // If Kodi is build with PipeWire support we prefer native PipeWire over the - // PulseAudio compatibility layer IF PulseAudio isn't explicitly selected + // PulseAudio compatibility layer IF NOT PulseAudio is explicitly selected if (!allowPipeWireCompatServer) { // Check the PulseAudio server name. If it contains PipeWire in any form // it is the compatibility layer provided by PipeWire - ServerInfoStruct serverInfo; - std::unique_lock l(serverInfo.m_mutex); - pa_context_get_server_info(m_pContext, ServerInfoCallback, &serverInfo); - serverInfo.m_cv.wait(l, [&]() { return serverInfo.m_isInfoSet; }); - if (serverInfo.m_isPipeWireServer) + if (StringUtils::Contains(serverInfo.m_serverName, "pipewire", true)) + { + CLog::Log(LOGINFO, "PulseAudio: Server is PipeWire, bail and use native PipeWire interface"); + pa_threaded_mainloop_unlock(m_pMainLoop); return false; + } } #endif - pa_threaded_mainloop_lock(m_pMainLoop); - m_isInit = true; std::unique_lock<CCriticalSection> lock(m_sec); diff --git a/xbmc/platform/freebsd/PlatformFreebsd.cpp b/xbmc/platform/freebsd/PlatformFreebsd.cpp index c949a339cb..6ab3f46ed2 100644 --- a/xbmc/platform/freebsd/PlatformFreebsd.cpp +++ b/xbmc/platform/freebsd/PlatformFreebsd.cpp @@ -89,7 +89,7 @@ bool CPlatformFreebsd::InitStageOne() } else if (sink == "pulseaudio") { - OPTIONALS::PulseAudioRegister(); + OPTIONALS::PulseAudioRegister(true); } else if (sink == "oss") { @@ -102,11 +102,11 @@ bool CPlatformFreebsd::InitStageOne() else if (sink == "alsa+pulseaudio") { OPTIONALS::ALSARegister(); - OPTIONALS::PulseAudioRegister(); + OPTIONALS::PulseAudioRegister(true); } else { - if (!OPTIONALS::PulseAudioRegister()) + if (!OPTIONALS::PulseAudioRegister(false)) { if (!OPTIONALS::ALSARegister()) { |