Move files from gst-examples into the "subprojects/gst-examples/" subdir
[platform/upstream/gstreamer.git] / subprojects / gst-examples / playback / player / qt / main.cpp
1 /* GStreamer
2  *
3  * Copyright (C) 2015 Alexandre Moreno <alexmorenocano@gmail.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #include <QApplication>
22 #include <QQmlApplicationEngine>
23 #include <QQmlProperty>
24 #include <QQuickItem>
25 #include <QCommandLineParser>
26 #include <QStringList>
27 #include <QUrl>
28 #include <gst/gst.h>
29
30 int main(int argc, char *argv[])
31 {
32     /* Use QApplication instead of QGuiApplication since the latter is needed
33      * for widgets like the QFileDialog to work */
34     QApplication app(argc, argv);
35     int result;
36
37     QCommandLineParser parser;
38     parser.setApplicationDescription("GstPlayer");
39     parser.addHelpOption();
40     parser.addPositionalArgument("urls",
41         QCoreApplication::translate("main", "URLs to play, optionally."), "[urls...]");
42     parser.process(app);
43
44     QList<QUrl> media_files;
45
46     const QStringList args = parser.positionalArguments();
47     foreach (const QString file, args) {
48         media_files << QUrl::fromUserInput(file);
49     }
50
51     /* the plugin must be loaded before loading the qml file to register the
52      * GstGLVideoItem qml item
53      * FIXME Add a QQmlExtensionPlugin into qmlglsink to register GstGLVideoItem
54      * with the QML engine, then remove this */
55     gst_init(NULL,NULL);
56     GstElement *sink = gst_element_factory_make ("qmlglsink", NULL);
57     gst_object_unref(sink);
58
59
60     QQmlApplicationEngine engine;
61     engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
62
63     QObject *rootObject = engine.rootObjects().first();
64
65     QObject *player = rootObject->findChild<QObject*>("player");
66     QObject *videoItem = rootObject->findChild<QObject*>("videoItem");
67     QVariant v;
68     v.setValue<QObject*>(videoItem);
69     QQmlProperty(player, "videoOutput").write(v);
70
71     if (!media_files.isEmpty()) {
72         QVariant v;
73         v.setValue<QList<QUrl>>(media_files);
74         QQmlProperty(player, "playlist").write(QVariant (v));
75     }
76
77     result = app.exec();
78
79     gst_deinit ();
80     return result;
81 }