diff options
author | wm4 <wm4@nowhere> | 2020-09-03 14:55:26 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-09-03 14:55:26 +0200 |
commit | 829775865dbd69db9211cd4b6b6c9b1e5ad82953 (patch) | |
tree | c1c0e9f7c88303ac8326db0fc2827a52b1c931b0 /libmpv/qml_direct | |
parent | 9be9e0877cbfe1ec19d359464a9121db56f6b0ed (diff) | |
download | mpv-examples-829775865dbd69db9211cd4b6b6c9b1e5ad82953.tar.bz2 mpv-examples-829775865dbd69db9211cd4b6b6c9b1e5ad82953.tar.xz |
Remove examples which use the old opengl_cb API
I made an attempt to convert some of them, but in the end, meh, I can't
be bothered. Do it yourself if you care, PRs to restore any of these
example by using the render API might be accepted.
The qt_opengl example was converted before; just fixing some old
comments in it.
Fixes: #38
Diffstat (limited to 'libmpv/qml_direct')
-rw-r--r-- | libmpv/qml_direct/main.cpp | 173 | ||||
-rw-r--r-- | libmpv/qml_direct/main.h | 53 | ||||
-rw-r--r-- | libmpv/qml_direct/main.qml | 62 | ||||
-rw-r--r-- | libmpv/qml_direct/mpvtest.pro | 12 | ||||
-rw-r--r-- | libmpv/qml_direct/mpvtest.qrc | 5 |
5 files changed, 0 insertions, 305 deletions
diff --git a/libmpv/qml_direct/main.cpp b/libmpv/qml_direct/main.cpp deleted file mode 100644 index 7f7e22b..0000000 --- a/libmpv/qml_direct/main.cpp +++ /dev/null @@ -1,173 +0,0 @@ -#include "main.h" - -#include <stdexcept> -#include <clocale> - -#include <QObject> -#include <QtGlobal> -#include <QOpenGLContext> - -#include <QGuiApplication> -#include <QtQuick/QQuickWindow> -#include <QtQuick/QQuickView> - -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)); -} - -MpvRenderer::MpvRenderer(mpv::qt::Handle a_mpv, mpv_opengl_cb_context *a_mpv_gl) - : mpv(a_mpv), mpv_gl(a_mpv_gl), window(0), size() -{ - 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"); -} - -MpvRenderer::~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 MpvRenderer::paint() -{ - window->resetOpenGLState(); - - // This uses 0 as framebuffer, which indicates that mpv will render directly - // to the frontbuffer. Note that mpv will always switch framebuffers - // explicitly. Some QWindow setups (such as using QQuickWidget) actually - // want you to render into a FBO in the beforeRendering() signal, and this - // code won't work there. - // The negation is used for rendering with OpenGL's flipped coordinates. - mpv_opengl_cb_draw(mpv_gl, 0, size.width(), -size.height()); - - window->resetOpenGLState(); -} - -MpvObject::MpvObject(QQuickItem * parent) - : QQuickItem(parent), mpv_gl(0), renderer(0), killOnce(false) -{ - 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"); - - // 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); - - connect(this, &QQuickItem::windowChanged, - this, &MpvObject::handleWindowChanged); -} - -MpvObject::~MpvObject() -{ - if (mpv_gl) - mpv_opengl_cb_set_update_callback(mpv_gl, NULL, NULL); -} - -void MpvObject::handleWindowChanged(QQuickWindow *win) -{ - if (!win) - return; - connect(win, &QQuickWindow::beforeSynchronizing, - this, &MpvObject::sync, Qt::DirectConnection); - connect(win, &QQuickWindow::sceneGraphInvalidated, - this, &MpvObject::cleanup, Qt::DirectConnection); - connect(win, &QQuickWindow::frameSwapped, - this, &MpvObject::swapped, Qt::DirectConnection); - win->setClearBeforeRendering(false); -} - -void MpvObject::sync() -{ - if (killOnce) - cleanup(); - killOnce = false; - - if (!renderer) { - renderer = new MpvRenderer(mpv, mpv_gl); - connect(window(), &QQuickWindow::beforeRendering, - renderer, &MpvRenderer::paint, Qt::DirectConnection); - } - renderer->window = window(); - renderer->size = window()->size() * window()->devicePixelRatio(); -} - -void MpvObject::swapped() -{ - mpv_opengl_cb_report_flip(mpv_gl, 0); -} - -void MpvObject::cleanup() -{ - if (renderer) { - delete renderer; - renderer = 0; - } -} - -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() -{ - window()->update(); -} - -void MpvObject::command(const QVariant& params) -{ - mpv::qt::command_variant(mpv, params); -} - -void MpvObject::reinitRenderer() -{ - // Don't make it stop playback if the VO dies. - mpv_set_option_string(mpv, "stop-playback-on-init-failure", "no"); - // Make it recreate the renderer, which involves calling - // mpv_opengl_cb_uninit_gl() (which is the thing we want to test). - killOnce = true; - window()->update(); -} - -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/libmpv/qml_direct/main.h b/libmpv/qml_direct/main.h deleted file mode 100644 index e73af34..0000000 --- a/libmpv/qml_direct/main.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef MPVRENDERER_H_ -#define MPVRENDERER_H_ - -#include <QtQuick/QQuickItem> - -#include <mpv/client.h> -#include <mpv/opengl_cb.h> -#include "../common/qthelper.hpp" - -class MpvRenderer : public QObject -{ - Q_OBJECT - mpv::qt::Handle mpv; - mpv_opengl_cb_context *mpv_gl; - QQuickWindow *window; - QSize size; - - friend class MpvObject; -public: - MpvRenderer(mpv::qt::Handle a_mpv, mpv_opengl_cb_context *a_mpv_gl); - virtual ~MpvRenderer(); -public slots: - void paint(); -}; - -class MpvObject : public QQuickItem -{ - Q_OBJECT - - mpv::qt::Handle mpv; - mpv_opengl_cb_context *mpv_gl; - MpvRenderer *renderer; - bool killOnce; - -public: - MpvObject(QQuickItem * parent = 0); - virtual ~MpvObject(); -public slots: - void command(const QVariant& params); - void sync(); - void swapped(); - void cleanup(); - void reinitRenderer(); -signals: - void onUpdate(); -private slots: - void doUpdate(); - void handleWindowChanged(QQuickWindow *win); -private: - static void on_update(void *ctx); -}; - -#endif diff --git a/libmpv/qml_direct/main.qml b/libmpv/qml_direct/main.qml deleted file mode 100644 index a8a68d5..0000000 --- a/libmpv/qml_direct/main.qml +++ /dev/null @@ -1,62 +0,0 @@ -import QtQuick 2.0 -import QtQuick.Controls 1.0 - -import mpvtest 1.0 - -Item { - width: 1280 - height: 720 - - MpvObject { - id: renderer - - // This object isn't real and not visible; it just renders into the - // background of the containing Window. - width: 0 - height: 0 - } - - 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: parent.bottom - anchors.left: parent.left - anchors.right: parent.right - anchors.margins: 100 - - Text { - anchors.margins: 10 - wrapMode: Text.WordWrap - text: "QtQuick and mpv are both rendering stuff.\n - In this example, mpv is always in the background.\n - Click to load test.mkv" - } - - Column { - Button { - anchors.margins: 10 - text: "Reinit QQuickItem renderer (for testing opengl-cb uninit during playback)" - onClicked: renderer.reinitRenderer() - } - Button { - anchors.margins: 10 - text: "Cycle video" - onClicked: renderer.command(["cycle", "video"]) - } - } - } -} diff --git a/libmpv/qml_direct/mpvtest.pro b/libmpv/qml_direct/mpvtest.pro deleted file mode 100644 index 0b2e96f..0000000 --- a/libmpv/qml_direct/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/libmpv/qml_direct/mpvtest.qrc b/libmpv/qml_direct/mpvtest.qrc deleted file mode 100644 index bb67265..0000000 --- a/libmpv/qml_direct/mpvtest.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<RCC> - <qresource prefix="/mpvtest"> - <file>main.qml</file> - </qresource> -</RCC> |