summaryrefslogtreecommitdiff
path: root/tests/examples/qt
diff options
context:
space:
mode:
authorMatthew Waters <matthew@centricular.com>2015-07-06 23:10:51 +1000
committerMatthew Waters <matthew@centricular.com>2015-07-10 15:25:26 +1000
commit769fffa3d93d89c692a3be6591bac9b610d3acaa (patch)
treeecc0236f5ccbabe2a1eec375e95b9ef6dd36f74d /tests/examples/qt
parentd533bfddb527012654ece8c6301f6bffa4192c7a (diff)
new qt5 qml GL video sink
Very much in the same spirit as the Gtk GL sink Two things are provided 1. A QQuickItem subclass that renders out RGBA filled GstGLMemory buffers that is instantiated from qml. 2. A sink element that will push buffers into (1) To use 1. Declare the GstGLVideoItem in qml with an appropriate objectName property set. 2. Get the aforementioned GstGLVideoItem from qml using something like QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); QObject *rootObject = engine.rootObjects().first(); QQuickItem *videoItem = rootObject->findChild<QQuickItem *> ("videoItem"); 3. Set the videoItem on the sink https://bugzilla.gnome.org/show_bug.cgi?id=752185
Diffstat (limited to 'tests/examples/qt')
-rw-r--r--tests/examples/qt/qml/.gitignore3
-rw-r--r--tests/examples/qt/qml/main.cpp80
-rw-r--r--tests/examples/qt/qml/main.qml60
-rw-r--r--tests/examples/qt/qml/play.pro20
-rw-r--r--tests/examples/qt/qml/qml.qrc5
5 files changed, 168 insertions, 0 deletions
diff --git a/tests/examples/qt/qml/.gitignore b/tests/examples/qt/qml/.gitignore
new file mode 100644
index 000000000..1f8151858
--- /dev/null
+++ b/tests/examples/qt/qml/.gitignore
@@ -0,0 +1,3 @@
+deployment.pri
+play
+qrc_qml.cpp
diff --git a/tests/examples/qt/qml/main.cpp b/tests/examples/qt/qml/main.cpp
new file mode 100644
index 000000000..2317b0541
--- /dev/null
+++ b/tests/examples/qt/qml/main.cpp
@@ -0,0 +1,80 @@
+#include <QApplication>
+#include <QQmlApplicationEngine>
+#include <QQuickWindow>
+#include <QQuickItem>
+#include <QRunnable>
+#include <gst/gst.h>
+
+class SetPlaying : public QRunnable
+{
+public:
+ SetPlaying(GstElement *);
+ ~SetPlaying();
+
+ void run ();
+
+private:
+ GstElement * pipeline_;
+};
+
+SetPlaying::SetPlaying (GstElement * pipeline)
+{
+ this->pipeline_ = pipeline ? static_cast<GstElement *> (gst_object_ref (pipeline)) : NULL;
+}
+
+SetPlaying::~SetPlaying ()
+{
+ if (this->pipeline_)
+ gst_object_unref (this->pipeline_);
+}
+
+void
+SetPlaying::run ()
+{
+ if (this->pipeline_)
+ gst_element_set_state (this->pipeline_, GST_STATE_PLAYING);
+}
+
+int main(int argc, char *argv[])
+{
+ int ret;
+
+ QGuiApplication app(argc, argv);
+ gst_init (&argc, &argv);
+
+ GstElement *pipeline = gst_pipeline_new (NULL);
+ GstElement *src = gst_element_factory_make ("videotestsrc", NULL);
+ GstElement *glupload = gst_element_factory_make ("glupload", NULL);
+ /* the plugin must be loaded before loading the qml file to register the
+ * GstGLVideoItem qml item */
+ GstElement *sink = gst_element_factory_make ("qmlglsink", NULL);
+
+ g_assert (src && glupload && sink);
+
+ gst_bin_add_many (GST_BIN (pipeline), src, glupload, sink, NULL);
+ gst_element_link_many (src, glupload, sink, NULL);
+
+ QQmlApplicationEngine engine;
+ engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
+
+ QQuickItem *videoItem;
+ QQuickWindow *rootObject;
+
+ /* find and set the videoItem on the sink */
+ rootObject = static_cast<QQuickWindow *> (engine.rootObjects().first());
+ videoItem = rootObject->findChild<QQuickItem *> ("videoItem");
+ g_assert (videoItem);
+ g_object_set(sink, "widget", videoItem, NULL);
+
+ rootObject->scheduleRenderJob (new SetPlaying (pipeline),
+ QQuickWindow::BeforeSynchronizingStage);
+
+ ret = app.exec();
+
+ gst_element_set_state (pipeline, GST_STATE_NULL);
+ gst_object_unref (pipeline);
+
+ gst_deinit ();
+
+ return ret;
+}
diff --git a/tests/examples/qt/qml/main.qml b/tests/examples/qt/qml/main.qml
new file mode 100644
index 000000000..842e98f2e
--- /dev/null
+++ b/tests/examples/qt/qml/main.qml
@@ -0,0 +1,60 @@
+import QtQuick 2.4
+import QtQuick.Controls 1.1
+import QtQuick.Controls.Styles 1.3
+import QtQuick.Dialogs 1.2
+import QtQuick.Window 2.1
+
+import org.freedesktop.gstreamer.GLVideoItem 1.0
+
+ApplicationWindow {
+ id: window
+ visible: true
+ width: 640
+ height: 480
+ x: 30
+ y: 30
+ color: "black"
+
+ Item {
+ anchors.fill: parent
+
+ GstGLVideoItem {
+ id: video
+ objectName: "videoItem"
+ anchors.centerIn: parent
+ width: parent.width
+ height: parent.height
+ }
+
+ Rectangle {
+ color: Qt.rgba(1, 1, 1, 0.7)
+ border.width: 1
+ border.color: "white"
+ anchors.bottom: video.bottom
+ anchors.bottomMargin: 15
+ anchors.horizontalCenter: parent.horizontalCenter
+ width : childrenRect.width + 20
+ height: childrenRect.height + 20
+ radius: 8
+
+ MouseArea {
+ id: mousearea
+ anchors.fill: parent
+ hoverEnabled: true
+ onEntered: {
+ parent.opacity = 1.0
+ hidetimer.start()
+ }
+ }
+
+ Timer {
+ id: hidetimer
+ interval: 5000
+ onTriggered: {
+ parent.opacity = 0.0
+ stop()
+ }
+ }
+ }
+ }
+}
diff --git a/tests/examples/qt/qml/play.pro b/tests/examples/qt/qml/play.pro
new file mode 100644
index 000000000..374e40297
--- /dev/null
+++ b/tests/examples/qt/qml/play.pro
@@ -0,0 +1,20 @@
+TEMPLATE = app
+
+QT += qml quick widgets
+
+QT_CONFIG -= no-pkg-config
+CONFIG += link_pkgconfig debug
+PKGCONFIG = \
+ gstreamer-1.0 \
+ gstreamer-video-1.0
+
+DEFINES += GST_USE_UNSTABLE_API
+
+INCLUDEPATH += ../lib
+
+SOURCES += main.cpp
+
+RESOURCES += qml.qrc
+
+# Additional import path used to resolve QML modules in Qt Creator's code model
+QML_IMPORT_PATH =
diff --git a/tests/examples/qt/qml/qml.qrc b/tests/examples/qt/qml/qml.qrc
new file mode 100644
index 000000000..5f6483ac3
--- /dev/null
+++ b/tests/examples/qt/qml/qml.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ </qresource>
+</RCC>