diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,11 +58,6 @@ # find_package(PulseAudio "${PA_MIN_VERSION}") -# PulseAudio requires GLib2 -if (PulseAudio_FOUND) - find_package(GLIB2 REQUIRED) -endif(PulseAudio_FOUND) - # Canberra is an optional dependency find_package(Canberra) @@ -99,7 +94,6 @@ if (PulseAudio_FOUND) add_definitions(-DHAVE_PULSE) include_directories(${PulseAudio_INCLUDE_DIRS}) - include_directories(${GLIB2_INCLUDE_DIR}) endif (PulseAudio_FOUND) if (CANBERRA_FOUND) @@ -213,7 +207,7 @@ endif (HAVE_LIBASOUND2) if (PulseAudio_FOUND) - target_link_libraries(kmixcore PRIVATE ${PulseAudio_LIBRARIES} ${PulseAudio_MAINLOOP_LIBRARY} ${GLIB2_LIBRARIES}) + target_link_libraries(kmixcore PRIVATE ${PulseAudio_LIBRARIES} ${PulseAudio_MAINLOOP_LIBRARY}) endif (PulseAudio_FOUND) if (CANBERRA_FOUND) diff --git a/backends/mixer_pulse.h b/backends/mixer_pulse.h --- a/backends/mixer_pulse.h +++ b/backends/mixer_pulse.h @@ -27,6 +27,8 @@ #include "mixer_backend.h" #include +struct QtPaMainLoop; + typedef QMap chanIDMap; typedef struct { int index; @@ -77,6 +79,7 @@ int fd; QString _id; + std::unique_ptr m_mainloop; private: bool addDevice(devinfo& dev, bool isAppStream = false); diff --git a/backends/mixer_pulse.cpp b/backends/mixer_pulse.cpp --- a/backends/mixer_pulse.cpp +++ b/backends/mixer_pulse.cpp @@ -21,6 +21,8 @@ #include "mixer_pulse.h" +#include "qtpamainloop.h" + #include #include #include @@ -32,7 +34,6 @@ #include "core/ControlManager.h" #include "core/GlobalConfig.h" -#include #include #if defined(HAVE_CANBERRA) # include @@ -55,7 +56,6 @@ #define KMIXPA_EVENT_KEY "sink-input-by-media-role:event" static unsigned int refcount = 0; -static pa_glib_mainloop *s_mainloop = NULL; static pa_context *s_context = NULL; static enum { UNKNOWN, ACTIVE, INACTIVE } s_pulseActive = UNKNOWN; static int s_outstandingRequests = 0; @@ -689,8 +689,6 @@ if (s_context != c) { pa_context_disconnect(c); } else { - // If we're not probing, it means we've been disconnected from our - // GLib context pa_context_unref(s_context); s_context = NULL; @@ -956,10 +954,14 @@ Q_ASSERT(NULL == s_context); qCDebug(KMIX_LOG) << "Attempting connection to PulseAudio sound daemon"; - pa_mainloop_api *api = pa_glib_mainloop_get_api(s_mainloop); - Q_ASSERT(api); - s_context = pa_context_new(api, "KMix"); + // No need to create this until necessary + if (!m_mainloop) { + // When bumping c++ requirement to c++14, + // replace with `= std::make_unique();` + m_mainloop.reset(new QtPaMainLoop); + } + s_context = pa_context_new(&m_mainloop->pa_vtable, "KMix"); Q_ASSERT(s_context); if (pa_context_connect(s_context, NULL, PA_CONTEXT_NOFAIL, 0) < 0) { @@ -981,13 +983,6 @@ if (pulseenv.toInt()) s_pulseActive = INACTIVE; - // We require a glib event loop - if (!QByteArray(QAbstractEventDispatcher::instance()->metaObject()->className()).contains("EventDispatcherGlib") && - !QByteArray(QAbstractEventDispatcher::instance()->metaObject()->className()).contains("GlibEventDispatcher")) { - qCDebug(KMIX_LOG) << "Disabling PulseAudio integration for lack of GLib event loop"; - s_pulseActive = INACTIVE; - } - ++refcount; if (INACTIVE != s_pulseActive && 1 == refcount) { @@ -1040,9 +1035,6 @@ if (INACTIVE != s_pulseActive) { // Reconnect via integrated mainloop - s_mainloop = pa_glib_mainloop_new(NULL); - Q_ASSERT(s_mainloop); - connectToDaemon(); #if defined(HAVE_CANBERRA) @@ -1082,11 +1074,6 @@ pa_context_unref(s_context); s_context = NULL; } - - if (s_mainloop) { - pa_glib_mainloop_free(s_mainloop); - s_mainloop = NULL; - } } } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -31,6 +31,6 @@ endif (HAVE_LIBASOUND2) if (PULSEAUDIO_FOUND) - target_link_libraries(profiletest ${PULSEAUDIO_LIBRARY} ${PULSEAUDIO_MAINLOOP_LIBRARY} ${GLIB2_LIBRARIES}) + target_link_libraries(profiletest ${PULSEAUDIO_LIBRARY} ${PULSEAUDIO_MAINLOOP_LIBRARY}) endif (PULSEAUDIO_FOUND)