1 #include <QApplication>
2 #include <QQmlApplicationEngine>
3 #include <QQuickWindow>
4 #include <QQuickItem>
5 #include <QRunnable>
6 #include <gst/gst.h>
7 #include <QWidget>
8 #include <QHBoxLayout>
9 #include <QQuickWindow>
10 #include <QQuickWidget>
11
12 class SetPlaying : public QRunnable
13 {
14 public:
15 SetPlaying(GstElement *);
16 ~SetPlaying();
17
18 void run ();
19
20 private:
21 GstElement * pipeline_;
22 };
23
SetPlaying(GstElement * pipeline)24 SetPlaying::SetPlaying (GstElement * pipeline)
25 {
26 this->pipeline_ = pipeline ? static_cast<GstElement *> (gst_object_ref (pipeline)) : NULL;
27 }
28
~SetPlaying()29 SetPlaying::~SetPlaying ()
30 {
31 if (this->pipeline_)
32 gst_object_unref (this->pipeline_);
33 }
34
35 void
run()36 SetPlaying::run ()
37 {
38 if (this->pipeline_)
39 gst_element_set_state (this->pipeline_, GST_STATE_PLAYING);
40 }
41
main(int argc,char * argv[])42 int main(int argc, char *argv[])
43 {
44 int ret;
45
46 gst_init (&argc, &argv);
47
48 {
49 QApplication app(argc, argv);
50
51 GstElement *pipeline = gst_element_factory_make ("playbin", NULL);
52 g_object_set(G_OBJECT(pipeline), "uri", argv[1], NULL);
53
54 GstBin *sinkbin = (GstBin *) gst_parse_bin_from_description ("glupload ! qmlglsink name=sink", TRUE, NULL);
55 GstElement *videosink = gst_bin_get_by_name (sinkbin, "sink");
56
57 g_object_set(G_OBJECT(pipeline), "video-sink", sinkbin, NULL);
58
59
60 QQmlApplicationEngine engine;
61 engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
62
63 QQuickItem *videoItem;
64 QQuickWindow *rootObject;
65
66 /* find and set the videoItem on the sink */
67 rootObject = static_cast<QQuickWindow *> (engine.rootObjects().first());
68 videoItem = rootObject->findChild<QQuickItem *> ("videoItem");
69 g_assert (videoItem);
70 g_object_set(G_OBJECT(videosink), "widget", videoItem, NULL);
71
72 rootObject->scheduleRenderJob (new SetPlaying (pipeline),
73 QQuickWindow::BeforeSynchronizingStage);
74
75 ret = app.exec();
76
77 gst_element_set_state (pipeline, GST_STATE_NULL);
78 gst_object_unref (pipeline);
79 }
80
81 gst_deinit ();
82
83 return ret;
84 }
85