diff --git a/src/librssguard/gui/mediaplayer/libmpv/libmpvbackend.cpp b/src/librssguard/gui/mediaplayer/libmpv/libmpvbackend.cpp index 7d099b3fd..d00dbe11f 100644 --- a/src/librssguard/gui/mediaplayer/libmpv/libmpvbackend.cpp +++ b/src/librssguard/gui/mediaplayer/libmpv/libmpvbackend.cpp @@ -34,15 +34,6 @@ #define CONFIG_MAIN_NAME "mpv.conf" #define CONFIG_INPUT_NAME "input.conf" -static void wakeup(void* ctx) { - // This callback is invoked from any mpv thread (but possibly also - // recursively from a thread that is calling the mpv API). Just notify - // the Qt GUI thread to wake up (so that it can process events with - // mpv_wait_event()), and return as quickly as possible. - LibMpvBackend* backend = (LibMpvBackend*)ctx; - emit backend->launchMpvEvents(); -} - LibMpvBackend::LibMpvBackend(Application* app, QWidget* parent) : PlayerBackend(app, parent), m_mpvContainer(nullptr), m_mpvHandle(nullptr) { installEventFilter(this); @@ -100,14 +91,12 @@ LibMpvBackend::LibMpvBackend(Application* app, QWidget* parent) // From this point on, the wakeup function will be called. The callback // can come from any thread, so we use the QueuedConnection mechanism to // relay the wakeup in a thread-safe way. - connect(this, - &LibMpvBackend::launchMpvEvents, + connect(m_mpvContainer, + &LibMpvWidget::launchMpvEvents, this, &LibMpvBackend::onMpvEvents, Qt::ConnectionType::QueuedConnection); - mpv_set_wakeup_callback(m_mpvHandle, wakeup, this); - if (mpv_initialize(m_mpvHandle) < 0) { qFatal("cannot create mpv instance"); } diff --git a/src/librssguard/gui/mediaplayer/libmpv/libmpvbackend.h b/src/librssguard/gui/mediaplayer/libmpv/libmpvbackend.h index b8b76e63a..952eff38c 100644 --- a/src/librssguard/gui/mediaplayer/libmpv/libmpvbackend.h +++ b/src/librssguard/gui/mediaplayer/libmpv/libmpvbackend.h @@ -39,9 +39,6 @@ class LibMpvBackend : public PlayerBackend { private slots: void onMpvEvents(); - signals: - void launchMpvEvents(); - private: void processEndFile(mpv_event_end_file* end_file); void processTracks(const QJsonDocument& json); diff --git a/src/librssguard/gui/mediaplayer/libmpv/libmpvwidget.cpp b/src/librssguard/gui/mediaplayer/libmpv/libmpvwidget.cpp index e59abf28f..503b5862d 100644 --- a/src/librssguard/gui/mediaplayer/libmpv/libmpvwidget.cpp +++ b/src/librssguard/gui/mediaplayer/libmpv/libmpvwidget.cpp @@ -4,6 +4,15 @@ #include +static void wakeup(void* ctx) { + // This callback is invoked from any mpv thread (but possibly also + // recursively from a thread that is calling the mpv API). Just notify + // the Qt GUI thread to wake up (so that it can process events with + // mpv_wait_event()), and return as quickly as possible. + LibMpvWidget* backend = (LibMpvWidget*)ctx; + emit backend->launchMpvEvents(); +} + LibMpvWidget::LibMpvWidget(mpv_handle* mpv_handle, QWidget* parent) : QWidget(parent), m_mpvHandle(mpv_handle) { setAttribute(Qt::WidgetAttribute::WA_DontCreateNativeAncestors); setAttribute(Qt::WidgetAttribute::WA_NativeWindow); @@ -22,4 +31,6 @@ void LibMpvWidget::bind() { #endif mpv_set_option(m_mpvHandle, "wid", MPV_FORMAT_INT64, &wid); + + mpv_set_wakeup_callback(m_mpvHandle, wakeup, this); } diff --git a/src/librssguard/gui/mediaplayer/libmpv/libmpvwidget.h b/src/librssguard/gui/mediaplayer/libmpv/libmpvwidget.h index 702abc036..19568c65d 100644 --- a/src/librssguard/gui/mediaplayer/libmpv/libmpvwidget.h +++ b/src/librssguard/gui/mediaplayer/libmpv/libmpvwidget.h @@ -16,6 +16,7 @@ class LibMpvWidget : public QWidget { void bind(); signals: + void launchMpvEvents(); private: mpv_handle* m_mpvHandle;