summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-09-09 12:32:52 +0200
committerwm4 <wm4@nowhere>2016-09-09 12:32:52 +0200
commita7b959cdfed6801d27963808f91eca0abb146b7e (patch)
tree43616dc299c22db2aca52640cfd4a89dde9cce70
parente8bc5e5d837e517288ab8149fa29d3547f7a8b0e (diff)
downloadmpv-examples-a7b959cdfed6801d27963808f91eca0abb146b7e.tar.bz2
mpv-examples-a7b959cdfed6801d27963808f91eca0abb146b7e.tar.xz
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.
-rw-r--r--libmpv/qml_direct/main.cpp16
-rw-r--r--libmpv/qml_direct/main.h2
-rw-r--r--libmpv/qml_direct/main.qml17
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"])
+ }
}
}
}