Debian Codegraph @

tests/examples/qt6/qmlsrc/main.cpp

raw
1 // SPDX-License-Identifier: BSD-2-Clause
2 //
3 // Copyright (C) 2022, Matthew Waters <[email protected]>
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // a) Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 //
11 // b) Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in
13 // the documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25 // THE POSSIBILITY OF SUCH DAMAGE.
26
27 #include <QApplication>
28 #include <QQmlApplicationEngine>
29 #include <QQuickWindow>
30 #include <QQuickItem>
31 #include <QQuickView>
32 #include <QRunnable>
33 #include <QDebug>
34 #include <gst/gst.h>
35
36 class SetPlaying : public QRunnable
37 {
38 public:
39 SetPlaying(GstElement *);
40 ~SetPlaying();
41
42 void run ();
43
44 private:
45 GstElement * pipeline_;
46 };
47
48 SetPlaying::SetPlaying (GstElement * pipeline)
49 {
50 this->pipeline_ = pipeline ? static_cast<GstElement *> (gst_object_ref (pipeline)) : NULL;
51 }
52
53 SetPlaying::~SetPlaying ()
54 {
55 if (this->pipeline_)
56 gst_object_unref (this->pipeline_);
57
58 }
59
60 void
61 SetPlaying::run ()
62 {
63 if (this->pipeline_)
64 gst_element_set_state (this->pipeline_, GST_STATE_PLAYING);
65 }
66
67 int main(int argc, char *argv[])
68 {
69 int ret;
70
71 QGuiApplication app(argc, argv);
72 gst_init (&argc, &argv);
73
74 QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
75
76 GstElement *pipeline = gst_pipeline_new (NULL);
77 GstElement *src = gst_element_factory_make ("qml6glsrc", NULL);
78 GstElement *sink = gst_element_factory_make ("glimagesink", NULL);
79
80 g_assert (src && sink);
81
82 gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
83 gst_element_link_many (src, sink, NULL);
84
85 QQmlApplicationEngine engine;
86 engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
87
88 QQuickWindow *rootObject;
89
90 /* find and set the QQuickWindow on the src */
91 rootObject = static_cast<QQuickWindow *> (engine.rootObjects().first());
92 g_object_set(src, "window", rootObject, NULL);
93 g_object_set(src, "use-default-fbo", TRUE, NULL);
94 /* output buffer of qmlglsrc is vertical flip, get the image orientation tag */
95 g_object_set(sink, "rotate-method", 8, NULL);
96
97 rootObject->scheduleRenderJob (new SetPlaying (pipeline),
98 QQuickWindow::BeforeSynchronizingStage);
99
100 ret = app.exec();
101
102 gst_element_set_state (pipeline, GST_STATE_NULL);
103 gst_object_unref (pipeline);
104
105 gst_deinit ();
106
107 return ret;
108 }