mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-05 16:06:43 +00:00
65fc381403
Currently supported are RGBA, BGRA and YV12 Output is still RGBA textures Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5119>
87 lines
2.2 KiB
C++
87 lines
2.2 KiB
C++
#include <QApplication>
|
|
#include <QQmlApplicationEngine>
|
|
#include <QQuickWindow>
|
|
#include <QQuickItem>
|
|
#include <QRunnable>
|
|
#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;
|
|
|
|
gst_init (&argc, &argv);
|
|
|
|
{
|
|
QGuiApplication app(argc, argv);
|
|
|
|
GstElement *pipeline = gst_pipeline_new (NULL);
|
|
GstElement *src = gst_element_factory_make ("videotestsrc", NULL);
|
|
GstElement *capsfilter = gst_element_factory_make ("capsfilter", NULL);
|
|
GstCaps *caps = gst_caps_from_string ("video/x-raw,format=YV12");
|
|
g_object_set (capsfilter, "caps", caps, NULL);
|
|
gst_caps_unref (caps);
|
|
GstElement *glupload = gst_element_factory_make ("glupload", NULL);
|
|
/* the plugin must be loaded before loading the qml file to register the
|
|
* GstGLVideoItem qml item */
|
|
GstElement *sink = gst_element_factory_make ("qmlglsink", NULL);
|
|
|
|
g_assert (src && glupload && sink);
|
|
|
|
gst_bin_add_many (GST_BIN (pipeline), src, capsfilter, glupload, sink, NULL);
|
|
gst_element_link_many (src, capsfilter, glupload, sink, NULL);
|
|
|
|
QQmlApplicationEngine engine;
|
|
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
|
|
|
QQuickItem *videoItem;
|
|
QQuickWindow *rootObject;
|
|
|
|
/* find and set the videoItem on the sink */
|
|
rootObject = static_cast<QQuickWindow *> (engine.rootObjects().first());
|
|
videoItem = rootObject->findChild<QQuickItem *> ("videoItem");
|
|
g_assert (videoItem);
|
|
g_object_set(sink, "widget", videoItem, 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;
|
|
}
|