1/****************************************************************************
2**
3** Copyright (C) 2016 Jolla Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QGSTVIDEORENDERERSINK_P_H
41#define QGSTVIDEORENDERERSINK_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtMultimedia/private/qtmultimediaglobal_p.h>
55#include <gst/video/gstvideosink.h>
56#include <gst/video/video.h>
57
58#include <QtCore/qlist.h>
59#include <QtCore/qmutex.h>
60#include <QtCore/qqueue.h>
61#include <QtCore/qpointer.h>
62#include <QtCore/qwaitcondition.h>
63#include <qvideosurfaceformat.h>
64#include <qvideoframe.h>
65#include <qabstractvideobuffer.h>
66
67#include "qgstvideorendererplugin_p.h"
68
69#include "qgstvideorendererplugin_p.h"
70
71#if QT_CONFIG(gstreamer_gl)
72#ifndef GST_USE_UNSTABLE_API
73#define GST_USE_UNSTABLE_API
74#endif
75#include <gst/gl/gl.h>
76#endif
77
78QT_BEGIN_NAMESPACE
79class QAbstractVideoSurface;
80
81class QGstDefaultVideoRenderer : public QGstVideoRenderer
82{
83public:
84 QGstDefaultVideoRenderer();
85 ~QGstDefaultVideoRenderer();
86
87 GstCaps *getCaps(QAbstractVideoSurface *surface) override;
88 bool start(QAbstractVideoSurface *surface, GstCaps *caps) override;
89 void stop(QAbstractVideoSurface *surface) override;
90
91 bool proposeAllocation(GstQuery *query) override;
92
93 bool present(QAbstractVideoSurface *surface, GstBuffer *buffer) override;
94 void flush(QAbstractVideoSurface *surface) override;
95
96private:
97 QVideoSurfaceFormat m_format;
98 GstVideoInfo m_videoInfo;
99 bool m_flushed = true;
100 QAbstractVideoBuffer::HandleType m_handleType = QAbstractVideoBuffer::NoHandle;
101};
102
103class QVideoSurfaceGstDelegate : public QObject
104{
105 Q_OBJECT
106public:
107 QVideoSurfaceGstDelegate(QAbstractVideoSurface *surface);
108 ~QVideoSurfaceGstDelegate();
109
110 GstCaps *caps();
111
112 bool start(GstCaps *caps);
113 void stop();
114 void unlock();
115 bool proposeAllocation(GstQuery *query);
116
117 void flush();
118
119 GstFlowReturn render(GstBuffer *buffer);
120
121 bool event(QEvent *event) override;
122 bool query(GstQuery *query);
123
124private slots:
125 bool handleEvent(QMutexLocker *locker);
126 void updateSupportedFormats();
127
128private:
129 void notify();
130 bool waitForAsyncEvent(QMutexLocker *locker, QWaitCondition *condition, unsigned long time);
131
132 QPointer<QAbstractVideoSurface> m_surface;
133
134 QMutex m_mutex;
135 QWaitCondition m_setupCondition;
136 QWaitCondition m_renderCondition;
137 GstFlowReturn m_renderReturn = GST_FLOW_OK;
138 QList<QGstVideoRenderer *> m_renderers;
139 QGstVideoRenderer *m_renderer = nullptr;
140 QGstVideoRenderer *m_activeRenderer = nullptr;
141
142 GstCaps *m_surfaceCaps = nullptr;
143 GstCaps *m_startCaps = nullptr;
144 GstBuffer *m_renderBuffer = nullptr;
145#if QT_CONFIG(gstreamer_gl)
146 GstGLContext *m_gstGLDisplayContext = nullptr;
147#endif
148
149 bool m_notified = false;
150 bool m_stop = false;
151 bool m_flush = false;
152};
153
154class Q_GSTTOOLS_EXPORT QGstVideoRendererSink
155{
156public:
157 GstVideoSink parent;
158
159 static QGstVideoRendererSink *createSink(QAbstractVideoSurface *surface);
160 static void setSurface(QAbstractVideoSurface *surface);
161
162private:
163 static GType get_type();
164 static void class_init(gpointer g_class, gpointer class_data);
165 static void base_init(gpointer g_class);
166 static void instance_init(GTypeInstance *instance, gpointer g_class);
167
168 static void finalize(GObject *object);
169
170 static void handleShowPrerollChange(GObject *o, GParamSpec *p, gpointer d);
171
172 static GstStateChangeReturn change_state(GstElement *element, GstStateChange transition);
173
174 static GstCaps *get_caps(GstBaseSink *sink, GstCaps *filter);
175 static gboolean set_caps(GstBaseSink *sink, GstCaps *caps);
176
177 static gboolean propose_allocation(GstBaseSink *sink, GstQuery *query);
178
179 static gboolean stop(GstBaseSink *sink);
180
181 static gboolean unlock(GstBaseSink *sink);
182
183 static GstFlowReturn show_frame(GstVideoSink *sink, GstBuffer *buffer);
184 static gboolean query(GstBaseSink *element, GstQuery *query);
185
186private:
187 QVideoSurfaceGstDelegate *delegate = nullptr;
188};
189
190
191class QGstVideoRendererSinkClass
192{
193public:
194 GstVideoSinkClass parent_class;
195};
196
197QT_END_NAMESPACE
198
199#endif
200

source code of qtmultimedia/src/gsttools/qgstvideorenderersink_p.h