Sélectionner une révision Git
mpvwidget.cc 11,99 Kio
#include "mpvwidget.hh"
#include <stdexcept>
#include <QtGui/QOpenGLContext>
#include <QtCore/QMetaObject>
#include <QApplication>
#include <QKeyEvent>
#include <QString>
#include "qthelper.hh"
#include "../mpv.h"
#include <lektor/mkv.h>
PRIVATE_FUNCTION void
wakeup(void *ctx)
{
QMetaObject::invokeMethod(static_cast<MpvWidget *>(ctx), "on_mpv_events", Qt::QueuedConnection);
}
PRIVATE_FUNCTION void *
get_proc_address(void *ctx, const char *name)
{
Q_UNUSED(ctx);
QOpenGLContext *glctx = QOpenGLContext::currentContext();
if (!glctx)
return nullptr;
return reinterpret_cast<void *>(glctx->getProcAddress(QByteArray(name)));
}
MpvWidget::MpvWidget(struct queue *queue, lkt_db *db, struct module_reg *reg, bool *launched,
QWidget *parent)
: QOpenGLWidget(parent)
, m_queue(queue)
, m_db(db)
, m_reg(reg)
, m_launched(launched)
{
mpv = mpv_create();
if (!mpv)
throw std::runtime_error("could not create mpv context");
setFocusPolicy(Qt::StrongFocus);
mpv_set_option_string(mpv, "osc", "yes");
if (mpv_initialize(mpv) < 0)
throw std::runtime_error("could not initialize mpv context");
// Request hw decoding, just for testing.
mpv_set_option_string(mpv, "hwdec", "auto");
mpv_observe_property(mpv, 0, "duration", MPV_FORMAT_DOUBLE);
mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE);
mpv_set_wakeup_callback(mpv, wakeup, this);
}
MpvWidget::~MpvWidget()
{
makeCurrent();
if (mpv_gl)
mpv_render_context_free(mpv_gl);
mpv_terminate_destroy(mpv);
}
void
MpvWidget::command(const QVariant ¶ms)
{
mpv::qt::command(mpv, params);
}