2024-07-26 01:06:30 +00:00
|
|
|
// SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
//
|
|
|
|
// Copyright (C) 2016, Haihua Hu <jared.hu@nxp.com>
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// a) Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// b) Redistributions in binary form must reproduce the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer in
|
|
|
|
// the documentation and/or other materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
// THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2015-07-06 13:10:51 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QQmlApplicationEngine>
|
|
|
|
#include <QQuickWindow>
|
|
|
|
#include <QQuickItem>
|
2016-07-27 01:28:23 +00:00
|
|
|
#include <QQuickView>
|
2015-07-06 13:10:51 +00:00
|
|
|
#include <QRunnable>
|
2016-07-27 01:28:23 +00:00
|
|
|
#include <QDebug>
|
2015-07-06 13:10:51 +00:00
|
|
|
#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_);
|
2024-07-26 01:06:30 +00:00
|
|
|
|
2015-07-06 13:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2016-07-27 01:28:23 +00:00
|
|
|
GstElement *src = gst_element_factory_make ("qmlglsrc", NULL);
|
2024-07-26 01:06:30 +00:00
|
|
|
GstElement *sink = gst_element_factory_make ("glimagesink", NULL);
|
2015-07-06 13:10:51 +00:00
|
|
|
|
2016-07-27 01:28:23 +00:00
|
|
|
g_assert (src && sink);
|
2015-07-06 13:10:51 +00:00
|
|
|
|
2016-07-27 01:28:23 +00:00
|
|
|
gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
|
|
|
|
gst_element_link_many (src, sink, NULL);
|
2015-07-06 13:10:51 +00:00
|
|
|
|
|
|
|
QQmlApplicationEngine engine;
|
|
|
|
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
|
|
|
|
|
|
|
QQuickWindow *rootObject;
|
|
|
|
|
2016-07-27 01:28:23 +00:00
|
|
|
/* find and set the QQuickWindow on the src */
|
2015-07-06 13:10:51 +00:00
|
|
|
rootObject = static_cast<QQuickWindow *> (engine.rootObjects().first());
|
2016-07-27 01:28:23 +00:00
|
|
|
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);
|
2015-07-06 13:10:51 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|