From a7b959cdfed6801d27963808f91eca0abb146b7e Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 9 Sep 2016 12:32:52 +0200 Subject: qml_direct: add a test for mpv_opengl_cb_uninit_gl() That function is awfully corner-caseish, so it's nice to have a good way to test it. --- libmpv/qml_direct/main.cpp | 16 +++++++++++++++- libmpv/qml_direct/main.h | 2 ++ libmpv/qml_direct/main.qml | 17 +++++++++++++++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/libmpv/qml_direct/main.cpp b/libmpv/qml_direct/main.cpp index 37c6119..7f7e22b 100644 --- a/libmpv/qml_direct/main.cpp +++ b/libmpv/qml_direct/main.cpp @@ -51,7 +51,7 @@ void MpvRenderer::paint() } MpvObject::MpvObject(QQuickItem * parent) - : QQuickItem(parent), mpv_gl(0), renderer(0) + : QQuickItem(parent), mpv_gl(0), renderer(0), killOnce(false) { mpv = mpv::qt::Handle::FromRawHandle(mpv_create()); if (!mpv) @@ -101,6 +101,10 @@ void MpvObject::handleWindowChanged(QQuickWindow *win) void MpvObject::sync() { + if (killOnce) + cleanup(); + killOnce = false; + if (!renderer) { renderer = new MpvRenderer(mpv, mpv_gl); connect(window(), &QQuickWindow::beforeRendering, @@ -140,6 +144,16 @@ 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); diff --git a/libmpv/qml_direct/main.h b/libmpv/qml_direct/main.h index b0310ff..c872b56 100644 --- a/libmpv/qml_direct/main.h +++ b/libmpv/qml_direct/main.h @@ -30,6 +30,7 @@ class MpvObject : public QQuickItem mpv::qt::Handle mpv; mpv_opengl_cb_context *mpv_gl; MpvRenderer *renderer; + bool killOnce; public: MpvObject(QQuickItem * parent = 0); @@ -39,6 +40,7 @@ public slots: void sync(); void swapped(); void cleanup(); + void reinitRenderer(); signals: void onUpdate(); private slots: diff --git a/libmpv/qml_direct/main.qml b/libmpv/qml_direct/main.qml index 92be9bc..a8a68d5 100644 --- a/libmpv/qml_direct/main.qml +++ b/libmpv/qml_direct/main.qml @@ -18,7 +18,7 @@ Item { MouseArea { anchors.fill: parent - onClicked: renderer.command(["loadfile", "../../../test.mkv"]) + onClicked: renderer.command(["loadfile", "test.mkv"]) } Rectangle { @@ -43,7 +43,20 @@ Item { 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" + 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"]) + } } } } -- cgit v1.2.3