enhance the separation
This commit is contained in:
parent
3143328ca0
commit
bf2ca8325c
@ -34,15 +34,6 @@
|
|||||||
#define CONFIG_MAIN_NAME "mpv.conf"
|
#define CONFIG_MAIN_NAME "mpv.conf"
|
||||||
#define CONFIG_INPUT_NAME "input.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)
|
LibMpvBackend::LibMpvBackend(Application* app, QWidget* parent)
|
||||||
: PlayerBackend(app, parent), m_mpvContainer(nullptr), m_mpvHandle(nullptr) {
|
: PlayerBackend(app, parent), m_mpvContainer(nullptr), m_mpvHandle(nullptr) {
|
||||||
installEventFilter(this);
|
installEventFilter(this);
|
||||||
@ -100,14 +91,12 @@ LibMpvBackend::LibMpvBackend(Application* app, QWidget* parent)
|
|||||||
// From this point on, the wakeup function will be called. The callback
|
// From this point on, the wakeup function will be called. The callback
|
||||||
// can come from any thread, so we use the QueuedConnection mechanism to
|
// can come from any thread, so we use the QueuedConnection mechanism to
|
||||||
// relay the wakeup in a thread-safe way.
|
// relay the wakeup in a thread-safe way.
|
||||||
connect(this,
|
connect(m_mpvContainer,
|
||||||
&LibMpvBackend::launchMpvEvents,
|
&LibMpvWidget::launchMpvEvents,
|
||||||
this,
|
this,
|
||||||
&LibMpvBackend::onMpvEvents,
|
&LibMpvBackend::onMpvEvents,
|
||||||
Qt::ConnectionType::QueuedConnection);
|
Qt::ConnectionType::QueuedConnection);
|
||||||
|
|
||||||
mpv_set_wakeup_callback(m_mpvHandle, wakeup, this);
|
|
||||||
|
|
||||||
if (mpv_initialize(m_mpvHandle) < 0) {
|
if (mpv_initialize(m_mpvHandle) < 0) {
|
||||||
qFatal("cannot create mpv instance");
|
qFatal("cannot create mpv instance");
|
||||||
}
|
}
|
||||||
|
@ -39,9 +39,6 @@ class LibMpvBackend : public PlayerBackend {
|
|||||||
private slots:
|
private slots:
|
||||||
void onMpvEvents();
|
void onMpvEvents();
|
||||||
|
|
||||||
signals:
|
|
||||||
void launchMpvEvents();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void processEndFile(mpv_event_end_file* end_file);
|
void processEndFile(mpv_event_end_file* end_file);
|
||||||
void processTracks(const QJsonDocument& json);
|
void processTracks(const QJsonDocument& json);
|
||||||
|
@ -4,6 +4,15 @@
|
|||||||
|
|
||||||
#include <mpv/client.h>
|
#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) {
|
LibMpvWidget::LibMpvWidget(mpv_handle* mpv_handle, QWidget* parent) : QWidget(parent), m_mpvHandle(mpv_handle) {
|
||||||
setAttribute(Qt::WidgetAttribute::WA_DontCreateNativeAncestors);
|
setAttribute(Qt::WidgetAttribute::WA_DontCreateNativeAncestors);
|
||||||
setAttribute(Qt::WidgetAttribute::WA_NativeWindow);
|
setAttribute(Qt::WidgetAttribute::WA_NativeWindow);
|
||||||
@ -22,4 +31,6 @@ void LibMpvWidget::bind() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
mpv_set_option(m_mpvHandle, "wid", MPV_FORMAT_INT64, &wid);
|
mpv_set_option(m_mpvHandle, "wid", MPV_FORMAT_INT64, &wid);
|
||||||
|
|
||||||
|
mpv_set_wakeup_callback(m_mpvHandle, wakeup, this);
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ class LibMpvWidget : public QWidget {
|
|||||||
void bind();
|
void bind();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void launchMpvEvents();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mpv_handle* m_mpvHandle;
|
mpv_handle* m_mpvHandle;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user