Guest User

Untitled

a guest
Aug 15th, 2024
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #include <QApplication>
  2. #include <QQmlApplicationEngine>
  3. #include <QQuickWindow>
  4. #include <QQuickItem>
  5. #include <QRunnable>
  6. #include <gst/gst.h>
  7.  
  8. class SetPlaying : public QRunnable
  9. {
  10. public:
  11. SetPlaying(GstElement *);
  12. ~SetPlaying();
  13.  
  14. void run ();
  15.  
  16. private:
  17. GstElement * pipeline_;
  18. };
  19.  
  20. SetPlaying::SetPlaying (GstElement * pipeline)
  21. {
  22. this->pipeline_ = pipeline ? static_cast<GstElement *> (gst_object_ref (pipeline)) : NULL;
  23. }
  24.  
  25. SetPlaying::~SetPlaying ()
  26. {
  27. if (this->pipeline_)
  28. gst_object_unref (this->pipeline_);
  29. }
  30.  
  31. void
  32. SetPlaying::run ()
  33. {
  34. if (this->pipeline_)
  35. gst_element_set_state (this->pipeline_, GST_STATE_PLAYING);
  36. }
  37.  
  38. int main(int argc, char *argv[])
  39. {
  40. int ret;
  41.  
  42. gst_init (&argc, &argv);
  43.  
  44. {
  45. QGuiApplication app(argc, argv);
  46.  
  47. GstElement *pipeline = gst_parse_launch ("filesrc location=/media/usb0/big_buck_bunny_1080p_h264.mov ! decodebin3 ! glupload ! glcolorconvert ! qmlglsink name=sink", NULL);
  48. /* the plugin must be loaded before loading the qml file to register the
  49. * GstGLVideoItem qml item */
  50. GstElement *sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
  51.  
  52. g_assert (sink);
  53.  
  54. QQmlApplicationEngine engine;
  55. engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
  56.  
  57. QQuickItem *videoItem;
  58. QQuickWindow *rootObject;
  59.  
  60. /* find and set the videoItem on the sink */
  61. rootObject = static_cast<QQuickWindow *> (engine.rootObjects().first());
  62. videoItem = rootObject->findChild<QQuickItem *> ("videoItem");
  63. g_assert (videoItem);
  64. g_object_set(sink, "widget", videoItem, NULL);
  65. gst_object_unref (sink);
  66.  
  67. rootObject->scheduleRenderJob (new SetPlaying (pipeline),
  68. QQuickWindow::BeforeSynchronizingStage);
  69.  
  70. ret = app.exec();
  71.  
  72. gst_element_set_state (pipeline, GST_STATE_NULL);
  73. gst_object_unref (pipeline);
  74. }
  75.  
  76. gst_deinit ();
  77.  
  78. return ret;
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment