diff options
author | Haihua Hu <jared.hu@nxp.com> | 2016-07-27 09:28:23 +0800 |
---|---|---|
committer | Matthew Waters <matthew@centricular.com> | 2016-08-03 22:11:11 +1000 |
commit | 65a3c3567066a37f61c23d05dbf2c3f68c5d8c98 (patch) | |
tree | 2e2c88acfc144a32acb4355771d536c3d9c8adb7 /tests | |
parent | 0b23bb5a595c23ba7c1e02219ea6f0d180477fb3 (diff) | |
download | gstreamer-plugins-bad-65a3c3567066a37f61c23d05dbf2c3f68c5d8c98.tar.gz |
qmlglsrc: Add qmlglsrc unit test example
https://bugzilla.gnome.org/show_bug.cgi?id=768160
Diffstat (limited to 'tests')
-rw-r--r-- | tests/examples/qt/qmlsink/.gitignore (renamed from tests/examples/qt/qml/.gitignore) | 0 | ||||
-rw-r--r-- | tests/examples/qt/qmlsink/main.cpp (renamed from tests/examples/qt/qml/main.cpp) | 11 | ||||
-rw-r--r-- | tests/examples/qt/qmlsink/main.qml (renamed from tests/examples/qt/qml/main.qml) | 0 | ||||
-rw-r--r-- | tests/examples/qt/qmlsink/play.pro (renamed from tests/examples/qt/qml/play.pro) | 0 | ||||
-rw-r--r-- | tests/examples/qt/qmlsink/qml.qrc (renamed from tests/examples/qt/qml/qml.qrc) | 0 | ||||
-rw-r--r-- | tests/examples/qt/qmlsrc/.gitignore | 2 | ||||
-rw-r--r-- | tests/examples/qt/qmlsrc/grabqml.pro | 20 | ||||
-rw-r--r-- | tests/examples/qt/qmlsrc/main.cpp | 80 | ||||
-rw-r--r-- | tests/examples/qt/qmlsrc/main.qml | 65 | ||||
-rw-r--r-- | tests/examples/qt/qmlsrc/qml.qrc | 5 |
10 files changed, 176 insertions, 7 deletions
diff --git a/tests/examples/qt/qml/.gitignore b/tests/examples/qt/qmlsink/.gitignore index 1f8151858..1f8151858 100644 --- a/tests/examples/qt/qml/.gitignore +++ b/tests/examples/qt/qmlsink/.gitignore diff --git a/tests/examples/qt/qml/main.cpp b/tests/examples/qt/qmlsink/main.cpp index bc5d28824..2317b0541 100644 --- a/tests/examples/qt/qml/main.cpp +++ b/tests/examples/qt/qmlsink/main.cpp @@ -44,18 +44,15 @@ int main(int argc, char *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); - GstElement *sinkbin = gst_element_factory_make ("glsinkbin", NULL); - g_assert (src && sink && sinkbin); + g_assert (src && glupload && sink); - g_object_set (sinkbin, "sink", sink, NULL); - g_object_unref (sink); - - gst_bin_add_many (GST_BIN (pipeline), src, sinkbin, NULL); - gst_element_link_many (src, sinkbin, NULL); + 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"))); diff --git a/tests/examples/qt/qml/main.qml b/tests/examples/qt/qmlsink/main.qml index ffd3cd165..ffd3cd165 100644 --- a/tests/examples/qt/qml/main.qml +++ b/tests/examples/qt/qmlsink/main.qml diff --git a/tests/examples/qt/qml/play.pro b/tests/examples/qt/qmlsink/play.pro index 374e40297..374e40297 100644 --- a/tests/examples/qt/qml/play.pro +++ b/tests/examples/qt/qmlsink/play.pro diff --git a/tests/examples/qt/qml/qml.qrc b/tests/examples/qt/qmlsink/qml.qrc index 5f6483ac3..5f6483ac3 100644 --- a/tests/examples/qt/qml/qml.qrc +++ b/tests/examples/qt/qmlsink/qml.qrc diff --git a/tests/examples/qt/qmlsrc/.gitignore b/tests/examples/qt/qmlsrc/.gitignore new file mode 100644 index 000000000..d2246aeb2 --- /dev/null +++ b/tests/examples/qt/qmlsrc/.gitignore @@ -0,0 +1,2 @@ +grabqml +qrc_qml.cpp diff --git a/tests/examples/qt/qmlsrc/grabqml.pro b/tests/examples/qt/qmlsrc/grabqml.pro new file mode 100644 index 000000000..374e40297 --- /dev/null +++ b/tests/examples/qt/qmlsrc/grabqml.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/qmlsrc/main.cpp b/tests/examples/qt/qmlsrc/main.cpp new file mode 100644 index 000000000..35cedcb09 --- /dev/null +++ b/tests/examples/qt/qmlsrc/main.cpp @@ -0,0 +1,80 @@ +#include <QApplication> +#include <QQmlApplicationEngine> +#include <QQuickWindow> +#include <QQuickItem> +#include <QQuickView> +#include <QRunnable> +#include <QDebug> +#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 ("qmlglsrc", NULL); + GstElement *sink = gst_element_factory_make ("glimagesink", NULL); + + g_assert (src && sink); + + gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL); + gst_element_link_many (src, sink, NULL); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + QQuickWindow *rootObject; + + /* find and set the QQuickWindow on the src */ + rootObject = static_cast<QQuickWindow *> (engine.rootObjects().first()); + g_object_set(src, "window", rootObject, NULL); + g_object_set(src, "use-default-fbo", TRUE, NULL); + /* output buffer of qmlglsrc is vertical flip, get the image orientation tag */ + g_object_set(sink, "rotate-method", 8, 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/qmlsrc/main.qml b/tests/examples/qt/qmlsrc/main.qml new file mode 100644 index 000000000..18b36e650 --- /dev/null +++ b/tests/examples/qt/qmlsrc/main.qml @@ -0,0 +1,65 @@ +import QtQuick 2.4 +import QtQuick.Controls 1.1 +import QtQuick.Controls.Styles 1.1 +import QtQuick.Dialogs 1.1 +import QtQuick.Window 2.1 + +ApplicationWindow { + id: window + visible: true + width: 640 + height: 480 + x: 30 + y: 30 + color: "dodgerblue" + + Item { + anchors.fill: parent + + Rectangle { + color: Qt.rgba(1, 1, 1, 0.7) + border.width: 1 + border.color: "white" + anchors.bottomMargin: 15 + anchors.horizontalCenter: parent.horizontalCenter + width : parent.width - 30 + height: parent.height - 30 + radius: 8 + + Text { + id: text1 + anchors.centerIn: parent + text: "Hello World!" + font.pointSize: 24 + visible: timer.tex1_visible + } + + Text { + id: text2 + anchors.centerIn: parent + text: "This is qmlglsrc demo!" + font.pointSize: 24 + visible: timer.tex2_visible + } + + Timer { + id: timer + property int count: 0 + property int tex1_visible: 1 + property int tex2_visible: 0 + interval: 30; running: true; repeat: true + onTriggered: { + count++; + if (count%2 == 0) { + tex1_visible = 1; + tex2_visible = 0; + } + else { + tex1_visible = 0; + tex2_visible = 1; + } + } + } + } + } +} diff --git a/tests/examples/qt/qmlsrc/qml.qrc b/tests/examples/qt/qmlsrc/qml.qrc new file mode 100644 index 000000000..5f6483ac3 --- /dev/null +++ b/tests/examples/qt/qmlsrc/qml.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>main.qml</file> + </qresource> +</RCC> |