Skip to content

Commit

Permalink
enhance the separation
Browse files Browse the repository at this point in the history
  • Loading branch information
martinrotter committed Dec 19, 2023
1 parent 3143328 commit bf2ca83
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
15 changes: 2 additions & 13 deletions src/librssguard/gui/mediaplayer/libmpv/libmpvbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
}
Expand Down
3 changes: 0 additions & 3 deletions src/librssguard/gui/mediaplayer/libmpv/libmpvbackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/librssguard/gui/mediaplayer/libmpv/libmpvwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

#include <mpv/client.h>

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);
Expand All @@ -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);
}
1 change: 1 addition & 0 deletions src/librssguard/gui/mediaplayer/libmpv/libmpvwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class LibMpvWidget : public QWidget {
void bind();

signals:
void launchMpvEvents();

private:
mpv_handle* m_mpvHandle;
Expand Down

0 comments on commit bf2ca83

Please sign in to comment.