• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * GStreamer
3  * Copyright (C) 2020 Matthew Waters <matthew@cenricular.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef __QT_QUICK_RENDER_H__
22 #define __QT_QUICK_RENDER_H__
23 
24 #include <QThread>
25 #include <QMutex>
26 
27 #include <gst/gl/gl.h>
28 
29 QT_FORWARD_DECLARE_CLASS(QOpenGLContext)
QT_FORWARD_DECLARE_CLASS(QOpenGLFramebufferObject)30 QT_FORWARD_DECLARE_CLASS(QOpenGLFramebufferObject)
31 QT_FORWARD_DECLARE_CLASS(QQuickRenderControl)
32 QT_FORWARD_DECLARE_CLASS(QQuickWindow)
33 QT_FORWARD_DECLARE_CLASS(QQmlEngine)
34 QT_FORWARD_DECLARE_CLASS(QQmlComponent)
35 QT_FORWARD_DECLARE_CLASS(QQuickItem)
36 QT_FORWARD_DECLARE_CLASS(GstAnimationDriver)
37 QT_FORWARD_DECLARE_CLASS(GstBackingSurface)
38 
39 class GstQuickRenderer : public QObject
40 {
41     Q_OBJECT
42 
43 public:
44     GstQuickRenderer();
45     ~GstQuickRenderer();
46 
47     /* initialize the GStreamer/Qt integration.  On failure returns false
48      * and fills @error.
49      * Must be called with @context not wrapped and current in the current
50      * thread  */
51     bool init (GstGLContext * context, GError ** error);
52 
53     /* set the qml scene.  returns false and fills @error on failure */
54     bool setQmlScene (const gchar * scene, GError ** error);
55 
56     void setSize(int w, int h);
57 
58     GstGLMemory *generateOutput(GstClockTime input_ns);
59 
60     /* cleanup any resources.  Any use of this object after calling this
61      * function may result in undefined behaviour */
62     void cleanup();
63 
64     /* retrieve the rootItem from the qml scene.  Only valid after
65      * setQmlScene() has been successfully called */
66     QQuickItem *rootItem() const;
67 
68 private slots:
69     void initializeQml();
70 
71 private:
72     void init();
73     void ensureFbo();
74 
75     void updateSizes();
76 
77     static void render_gst_gl_c (GstGLContext * context, GstQuickRenderer * self) { self->renderGstGL (); }
78     void renderGstGL ();
79 
80     static void initialize_gst_gl_c (GstGLContext * context, GstQuickRenderer * self) { self->initializeGstGL (); }
81     void initializeGstGL ();
82 
83     static void stop_c (GstGLContext * context, GstQuickRenderer * self) { self->stopGL (); }
84     void stopGL ();
85 
86     static void activate_context_c (GstGLContext * context, GstQuickRenderer * self) { self->activateContext (); }
87     void activateContext ();
88 
89     static void deactivate_context_c (GstGLContext * context, GstQuickRenderer * self) { self->deactivateContext (); }
90     void deactivateContext ();
91 
92     GstGLContext *gl_context;
93     QOpenGLFramebufferObject *m_fbo;
94     QQuickWindow *m_quickWindow;
95     QQuickRenderControl *m_renderControl;
96     QQmlEngine *m_qmlEngine;
97     QQmlComponent *m_qmlComponent;
98     QQuickItem *m_rootItem;
99 
100     GstGLBaseMemoryAllocator *gl_allocator;
101     GstGLAllocationParams *gl_params;
102     GstVideoInfo v_info;
103     GstGLMemory *gl_mem;
104 
105     QString m_errorString;
106     struct SharedRenderData *m_sharedRenderData;
107 };
108 
109 class CreateSurfaceWorker : public QObject
110 {
111   Q_OBJECT
112 
113 public:
114   CreateSurfaceWorker (struct SharedRenderData * rdata);
115   ~CreateSurfaceWorker ();
116 
117   bool event(QEvent *ev) override;
118 
119 private:
120   struct SharedRenderData *m_sharedRenderData;
121 };
122 
123 #endif /* __QT_QUICK_RENDER_H__ */
124