#include #include #include #include #include #include #include #include #include #include class SetPlaying : public QRunnable { public: SetPlaying(GstElement *); ~SetPlaying(); void run (); private: GstElement * pipeline_; }; SetPlaying::SetPlaying (GstElement * pipeline) { this->pipeline_ = pipeline ? static_cast (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); { QApplication app(argc, argv); GstElement *pipeline = gst_element_factory_make ("playbin", NULL); g_object_set(G_OBJECT(pipeline), "uri", argv[1], NULL); GstBin *sinkbin = (GstBin *) gst_parse_bin_from_description ("glupload ! qmlglsink name=sink", TRUE, NULL); GstElement *videosink = gst_bin_get_by_name (sinkbin, "sink"); g_object_set(G_OBJECT(pipeline), "video-sink", sinkbin, 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 (engine.rootObjects().first()); videoItem = rootObject->findChild ("videoItem"); g_assert (videoItem); g_object_set(G_OBJECT(videosink), "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; }