summaryrefslogtreecommitdiffstats
path: root/DOCS/client_api_examples/qml
diff options
context:
space:
mode:
Diffstat (limited to 'DOCS/client_api_examples/qml')
-rw-r--r--DOCS/client_api_examples/qml/main.cpp136
-rw-r--r--DOCS/client_api_examples/qml/main.h36
-rw-r--r--DOCS/client_api_examples/qml/main.qml71
-rw-r--r--DOCS/client_api_examples/qml/mpvtest.pro12
-rw-r--r--DOCS/client_api_examples/qml/mpvtest.qrc5
5 files changed, 0 insertions, 260 deletions
diff --git a/DOCS/client_api_examples/qml/main.cpp b/DOCS/client_api_examples/qml/main.cpp
deleted file mode 100644
index 2122cd8c5c..0000000000
--- a/DOCS/client_api_examples/qml/main.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-#include "main.h"
-
-#include <stdexcept>
-#include <clocale>
-
-#include <QObject>
-#include <QtGlobal>
-#include <QOpenGLContext>
-#include <QGuiApplication>
-
-#include <QtGui/QOpenGLFramebufferObject>
-
-#include <QtQuick/QQuickWindow>
-#include <QtQuick/QQuickView>
-
-class MpvRenderer : public QQuickFramebufferObject::Renderer
-{
- static void *get_proc_address(void *ctx, const char *name) {
- (void)ctx;
- QOpenGLContext *glctx = QOpenGLContext::currentContext();
- if (!glctx)
- return NULL;
- return (void *)glctx->getProcAddress(QByteArray(name));
- }
-
- mpv::qt::Handle mpv;
- QQuickWindow *window;
- mpv_opengl_cb_context *mpv_gl;
-public:
- MpvRenderer(const MpvObject *obj)
- : mpv(obj->mpv), window(obj->window()), mpv_gl(obj->mpv_gl)
- {
- int r = mpv_opengl_cb_init_gl(mpv_gl, NULL, get_proc_address, NULL);
- if (r < 0)
- throw std::runtime_error("could not initialize OpenGL");
- }
-
- virtual ~MpvRenderer()
- {
- // Until this call is done, we need to make sure the player remains
- // alive. This is done implicitly with the mpv::qt::Handle instance
- // in this class.
- mpv_opengl_cb_uninit_gl(mpv_gl);
- }
-
- void render()
- {
- QOpenGLFramebufferObject *fbo = framebufferObject();
- window->resetOpenGLState();
- mpv_opengl_cb_draw(mpv_gl, fbo->handle(), fbo->width(), fbo->height());
- window->resetOpenGLState();
- }
-};
-
-MpvObject::MpvObject(QQuickItem * parent)
- : QQuickFramebufferObject(parent), mpv_gl(0)
-{
- mpv = mpv::qt::Handle::FromRawHandle(mpv_create());
- if (!mpv)
- throw std::runtime_error("could not create mpv context");
-
- mpv_set_option_string(mpv, "terminal", "yes");
- mpv_set_option_string(mpv, "msg-level", "all=v");
-
- if (mpv_initialize(mpv) < 0)
- throw std::runtime_error("could not initialize mpv context");
-
- // Make use of the MPV_SUB_API_OPENGL_CB API.
- mpv::qt::set_option_variant(mpv, "vo", "opengl-cb");
-
- // Request hw decoding, just for testing.
- mpv::qt::set_option_variant(mpv, "hwdec", "auto");
-
- // Setup the callback that will make QtQuick update and redraw if there
- // is a new video frame. Use a queued connection: this makes sure the
- // doUpdate() function is run on the GUI thread.
- mpv_gl = (mpv_opengl_cb_context *)mpv_get_sub_api(mpv, MPV_SUB_API_OPENGL_CB);
- if (!mpv_gl)
- throw std::runtime_error("OpenGL not compiled in");
- mpv_opengl_cb_set_update_callback(mpv_gl, MpvObject::on_update, (void *)this);
- connect(this, &MpvObject::onUpdate, this, &MpvObject::doUpdate,
- Qt::QueuedConnection);
-}
-
-MpvObject::~MpvObject()
-{
- if (mpv_gl)
- mpv_opengl_cb_set_update_callback(mpv_gl, NULL, NULL);
-}
-
-void MpvObject::on_update(void *ctx)
-{
- MpvObject *self = (MpvObject *)ctx;
- emit self->onUpdate();
-}
-
-// connected to onUpdate(); signal makes sure it runs on the GUI thread
-void MpvObject::doUpdate()
-{
- update();
-}
-
-void MpvObject::command(const QVariant& params)
-{
- mpv::qt::command_variant(mpv, params);
-}
-
-void MpvObject::setProperty(const QString& name, const QVariant& value)
-{
- mpv::qt::set_property_variant(mpv, name, value);
-}
-
-QQuickFramebufferObject::Renderer *MpvObject::createRenderer() const
-{
- window()->setPersistentOpenGLContext(true);
- window()->setPersistentSceneGraph(true);
- return new MpvRenderer(this);
-}
-
-int main(int argc, char **argv)
-{
- QGuiApplication app(argc, argv);
-
- // Qt sets the locale in the QGuiApplication constructor, but libmpv
- // requires the LC_NUMERIC category to be set to "C", so change it back.
- std::setlocale(LC_NUMERIC, "C");
-
- qmlRegisterType<MpvObject>("mpvtest", 1, 0, "MpvObject");
-
- QQuickView view;
- view.setResizeMode(QQuickView::SizeRootObjectToView);
- view.setSource(QUrl("qrc:///mpvtest/main.qml"));
- view.show();
-
- return app.exec();
-}
diff --git a/DOCS/client_api_examples/qml/main.h b/DOCS/client_api_examples/qml/main.h
deleted file mode 100644
index 9a65ae5350..0000000000
--- a/DOCS/client_api_examples/qml/main.h
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifndef MPVRENDERER_H_
-#define MPVRENDERER_H_
-
-#include <QtQuick/QQuickFramebufferObject>
-
-#include <mpv/client.h>
-#include <mpv/opengl_cb.h>
-#include <mpv/qthelper.hpp>
-
-class MpvRenderer;
-
-class MpvObject : public QQuickFramebufferObject
-{
- Q_OBJECT
-
- mpv::qt::Handle mpv;
- mpv_opengl_cb_context *mpv_gl;
-
- friend class MpvRenderer;
-
-public:
- MpvObject(QQuickItem * parent = 0);
- virtual ~MpvObject();
- virtual Renderer *createRenderer() const;
-public slots:
- void command(const QVariant& params);
- void setProperty(const QString& name, const QVariant& value);
-signals:
- void onUpdate();
-private slots:
- void doUpdate();
-private:
- static void on_update(void *ctx);
-};
-
-#endif
diff --git a/DOCS/client_api_examples/qml/main.qml b/DOCS/client_api_examples/qml/main.qml
deleted file mode 100644
index ec06790e86..0000000000
--- a/DOCS/client_api_examples/qml/main.qml
+++ /dev/null
@@ -1,71 +0,0 @@
-import QtQuick 2.0
-import QtQuick.Controls 1.0
-
-import mpvtest 1.0
-
-Item {
- width: 1280
- height: 720
-
- MpvObject {
- id: renderer
- anchors.fill: parent
-
- MouseArea {
- anchors.fill: parent
- onClicked: renderer.command(["loadfile", "../../../test.mkv"])
- }
- }
-
- Rectangle {
- id: labelFrame
- anchors.margins: -50
- radius: 5
- color: "white"
- border.color: "black"
- opacity: 0.8
- anchors.fill: box
- }
-
- Row {
- id: box
- anchors.bottom: renderer.bottom
- anchors.left: renderer.left
- anchors.right: renderer.right
- anchors.margins: 100
-
- Text {
- anchors.margins: 10
- wrapMode: Text.WordWrap
- text: "QtQuick and mpv are both rendering stuff.\n
- Click to load ../../../test.mkv"
- }
-
- // Don't take these controls too seriously. They're for testing.
- Column {
- CheckBox {
- id: checkbox
- anchors.margins: 10
- // Heavily filtered means good, right?
- text: "Make video look like on a Smart TV"
- onClicked: {
- if (checkbox.checked) {
- renderer.command(["vo_cmdline", "sharpen=5.0"])
- } else {
- renderer.command(["vo_cmdline", ""])
- }
- }
- }
- Slider {
- id: slider
- anchors.margins: 10
- anchors.left: checkbox.left
- anchors.right: checkbox.right
- minimumValue: -100
- maximumValue: 100
- value: 0
- onValueChanged: renderer.setProperty("gamma", slider.value | 0)
- }
- }
- }
-}
diff --git a/DOCS/client_api_examples/qml/mpvtest.pro b/DOCS/client_api_examples/qml/mpvtest.pro
deleted file mode 100644
index 0b2e96fe99..0000000000
--- a/DOCS/client_api_examples/qml/mpvtest.pro
+++ /dev/null
@@ -1,12 +0,0 @@
-QT += qml quick
-
-HEADERS += main.h
-SOURCES += main.cpp
-
-QT_CONFIG -= no-pkg-config
-CONFIG += link_pkgconfig debug
-PKGCONFIG += mpv
-
-RESOURCES += mpvtest.qrc
-
-OTHER_FILES += main.qml
diff --git a/DOCS/client_api_examples/qml/mpvtest.qrc b/DOCS/client_api_examples/qml/mpvtest.qrc
deleted file mode 100644
index bb672657e5..0000000000
--- a/DOCS/client_api_examples/qml/mpvtest.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<RCC>
- <qresource prefix="/mpvtest">
- <file>main.qml</file>
- </qresource>
-</RCC>