gstreamer/subprojects/gst-plugins-good/tests/examples/qt6/qmlsrc/main.cpp
Matthew Waters 293ad62035 qt6: add qml6glsrc element
Same functionality as qmlglsrc (Qt5) but for Qt6.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3737>
2023-01-28 02:24:09 +00:00

82 lines
1.9 KiB
C++

#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQuickWindow>
#include <QQuickItem>
#include <QQuickView>
#include <QRunnable>
#include <QDebug>
#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_);
}
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);
QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
GstElement *pipeline = gst_pipeline_new (NULL);
GstElement *src = gst_element_factory_make ("qml6glsrc", NULL);
GstElement *sink = gst_element_factory_make ("glimagesink", NULL);
g_assert (src && sink);
gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
gst_element_link_many (src, sink, NULL);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QQuickWindow *rootObject;
/* find and set the QQuickWindow on the src */
rootObject = static_cast<QQuickWindow *> (engine.rootObjects().first());
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);
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;
}