mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-19 00:01:23 +00:00
769fffa3d9
Very much in the same spirit as the Gtk GL sink Two things are provided 1. A QQuickItem subclass that renders out RGBA filled GstGLMemory buffers that is instantiated from qml. 2. A sink element that will push buffers into (1) To use 1. Declare the GstGLVideoItem in qml with an appropriate objectName property set. 2. Get the aforementioned GstGLVideoItem from qml using something like QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); QObject *rootObject = engine.rootObjects().first(); QQuickItem *videoItem = rootObject->findChild<QQuickItem *> ("videoItem"); 3. Set the videoItem on the sink https://bugzilla.gnome.org/show_bug.cgi?id=752185
80 lines
1.9 KiB
C++
80 lines
1.9 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;
|
|
|
|
QGuiApplication app(argc, argv);
|
|
gst_init (&argc, &argv);
|
|
|
|
GstElement *pipeline = gst_pipeline_new (NULL);
|
|
GstElement *src = gst_element_factory_make ("videotestsrc", NULL);
|
|
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, glupload, sink, NULL);
|
|
gst_element_link_many (src, 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;
|
|
}
|