1 #include <QApplication>
2 #include <QQmlApplicationEngine>
3 #include <QQuickWindow>
4 #include <QQuickItem>
5 #include <QQuickView>
6 #include <QRunnable>
7 #include <QDebug>
8 #include <gst/gst.h>
9
10 class SetPlaying : public QRunnable
11 {
12 public:
13 SetPlaying(GstElement *);
14 ~SetPlaying();
15
16 void run ();
17
18 private:
19 GstElement * pipeline_;
20 };
21
SetPlaying(GstElement * pipeline)22 SetPlaying::SetPlaying (GstElement * pipeline)
23 {
24 this->pipeline_ = pipeline ? static_cast<GstElement *> (gst_object_ref (pipeline)) : NULL;
25 }
26
~SetPlaying()27 SetPlaying::~SetPlaying ()
28 {
29 if (this->pipeline_)
30 gst_object_unref (this->pipeline_);
31
32 }
33
34 void
run()35 SetPlaying::run ()
36 {
37 if (this->pipeline_)
38 gst_element_set_state (this->pipeline_, GST_STATE_PLAYING);
39 }
40
main(int argc,char * argv[])41 int main(int argc, char *argv[])
42 {
43 int ret;
44
45 QGuiApplication app(argc, argv);
46 gst_init (&argc, &argv);
47
48 GstElement *pipeline = gst_pipeline_new (NULL);
49 GstElement *src = gst_element_factory_make ("qmlglsrc", NULL);
50 GstElement *sink = gst_element_factory_make ("glimagesink", NULL);
51
52 g_assert (src && sink);
53
54 gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
55 gst_element_link_many (src, sink, NULL);
56
57 QQmlApplicationEngine engine;
58 engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
59
60 QQuickWindow *rootObject;
61
62 /* find and set the QQuickWindow on the src */
63 rootObject = static_cast<QQuickWindow *> (engine.rootObjects().first());
64 g_object_set(src, "window", rootObject, NULL);
65 g_object_set(src, "use-default-fbo", TRUE, NULL);
66 /* output buffer of qmlglsrc is vertical flip, get the image orientation tag */
67 g_object_set(sink, "rotate-method", 8, NULL);
68
69 rootObject->scheduleRenderJob (new SetPlaying (pipeline),
70 QQuickWindow::BeforeSynchronizingStage);
71
72 ret = app.exec();
73
74 gst_element_set_state (pipeline, GST_STATE_NULL);
75 gst_object_unref (pipeline);
76
77 gst_deinit ();
78
79 return ret;
80 }
81