1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company 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 CAMERABINCAPTURESESSION_H
41#define CAMERABINCAPTURESESSION_H
42
43#include <QtMultimedia/private/qtmultimediaglobal_p.h>
44#include <qmediarecordercontrol.h>
45
46#include <QtCore/qurl.h>
47#include <QtCore/qdir.h>
48
49#include <gst/gst.h>
50#if QT_CONFIG(gstreamer_photography)
51#include <gst/interfaces/photography.h>
52#endif
53
54#include <private/qgstreamerbushelper_p.h>
55#include <private/qgstreamervideoprobecontrol_p.h>
56#include <private/qmediastoragelocation_p.h>
57#include "qcamera.h"
58
59QT_BEGIN_NAMESPACE
60
61class QGstreamerMessage;
62class QGstreamerBusHelper;
63class CameraBinControl;
64class CameraBinAudioEncoder;
65class CameraBinVideoEncoder;
66class CameraBinImageEncoder;
67class CameraBinRecorder;
68class CameraBinContainer;
69class CameraBinExposure;
70class CameraBinFlash;
71class CameraBinFocus;
72class CameraBinImageProcessing;
73class CameraBinLocks;
74class CameraBinZoom;
75class CameraBinCaptureDestination;
76class CameraBinCaptureBufferFormat;
77class QGstreamerVideoRendererInterface;
78class CameraBinViewfinderSettings;
79
80class QGstreamerElementFactory
81{
82public:
83 virtual GstElement *buildElement() = 0;
84};
85
86class CameraBinSession : public QObject,
87 public QGstreamerBusMessageFilter,
88 public QGstreamerSyncMessageFilter
89{
90 Q_OBJECT
91 Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged)
92 Q_INTERFACES(QGstreamerBusMessageFilter QGstreamerSyncMessageFilter)
93public:
94 CameraBinSession(GstElementFactory *sourceFactory, QObject *parent);
95 ~CameraBinSession();
96
97#if QT_CONFIG(gstreamer_photography)
98 GstPhotography *photography();
99#endif
100 GstElement *cameraBin() { return m_camerabin; }
101 GstElement *cameraSource() { return m_cameraSrc; }
102 QGstreamerBusHelper *bus() { return m_busHelper; }
103
104 QList< QPair<int,int> > supportedFrameRates(const QSize &frameSize, bool *continuous) const;
105 QList<QSize> supportedResolutions(QPair<int,int> rate, bool *continuous, QCamera::CaptureModes mode) const;
106
107 QCamera::CaptureModes captureMode() { return m_captureMode; }
108 void setCaptureMode(QCamera::CaptureModes mode);
109
110 QUrl outputLocation() const;
111 bool setOutputLocation(const QUrl& sink);
112
113 GstElement *buildCameraSource();
114 GstElementFactory *sourceFactory() const { return m_sourceFactory; }
115
116 CameraBinControl *cameraControl() const { return m_cameraControl; }
117 CameraBinAudioEncoder *audioEncodeControl() const { return m_audioEncodeControl; }
118 CameraBinVideoEncoder *videoEncodeControl() const { return m_videoEncodeControl; }
119 CameraBinImageEncoder *imageEncodeControl() const { return m_imageEncodeControl; }
120
121#if QT_CONFIG(gstreamer_photography)
122 CameraBinExposure *cameraExposureControl();
123 CameraBinFlash *cameraFlashControl();
124 CameraBinFocus *cameraFocusControl();
125 CameraBinLocks *cameraLocksControl();
126#endif
127
128 CameraBinZoom *cameraZoomControl() const { return m_cameraZoomControl; }
129 CameraBinImageProcessing *imageProcessingControl() const { return m_imageProcessingControl; }
130 CameraBinCaptureDestination *captureDestinationControl() const { return m_captureDestinationControl; }
131 CameraBinCaptureBufferFormat *captureBufferFormatControl() const { return m_captureBufferFormatControl; }
132
133 CameraBinRecorder *recorderControl() const { return m_recorderControl; }
134 CameraBinContainer *mediaContainerControl() const { return m_mediaContainerControl; }
135
136 QGstreamerElementFactory *audioInput() const { return m_audioInputFactory; }
137 void setAudioInput(QGstreamerElementFactory *audioInput);
138
139 QGstreamerElementFactory *videoInput() const { return m_videoInputFactory; }
140 void setVideoInput(QGstreamerElementFactory *videoInput);
141 bool isReady() const;
142
143 QObject *viewfinder() const { return m_viewfinder; }
144 void setViewfinder(QObject *viewfinder);
145
146 QList<QCameraViewfinderSettings> supportedViewfinderSettings() const;
147 QCameraViewfinderSettings viewfinderSettings() const;
148 void setViewfinderSettings(const QCameraViewfinderSettings &settings) { m_viewfinderSettings = settings; }
149
150 void captureImage(int requestId, const QString &fileName);
151
152 QCamera::Status status() const;
153 QCamera::State pendingState() const;
154 bool isBusy() const;
155
156 qint64 duration() const;
157
158 void recordVideo();
159 void stopVideoRecording();
160
161 bool isMuted() const;
162
163 QString device() const { return m_inputDevice; }
164
165 bool processSyncMessage(const QGstreamerMessage &message) override;
166 bool processBusMessage(const QGstreamerMessage &message) override;
167
168 QGstreamerVideoProbeControl *videoProbe();
169
170signals:
171 void statusChanged(QCamera::Status status);
172 void pendingStateChanged(QCamera::State state);
173 void durationChanged(qint64 duration);
174 void error(int error, const QString &errorString);
175 void imageExposed(int requestId);
176 void imageCaptured(int requestId, const QImage &img);
177 void mutedChanged(bool);
178 void viewfinderChanged();
179 void readyChanged(bool);
180 void busyChanged(bool);
181
182public slots:
183 void setDevice(const QString &device);
184 void setState(QCamera::State);
185 void setCaptureDevice(const QString &deviceName);
186 void setMetaData(const QMap<QByteArray, QVariant>&);
187 void setMuted(bool);
188
189private slots:
190 void handleViewfinderChange();
191 void setupCaptureResolution();
192
193private:
194 void load();
195 void unload();
196 void start();
197 void stop();
198
199 void setStatus(QCamera::Status status);
200 void setStateHelper(QCamera::State state);
201 void setError(int error, const QString &errorString);
202
203 bool setupCameraBin();
204 void setAudioCaptureCaps();
205 GstCaps *supportedCaps(QCamera::CaptureModes mode) const;
206 static void updateBusyStatus(GObject *o, GParamSpec *p, gpointer d);
207
208 QString currentContainerFormat() const;
209
210 static void elementAdded(GstBin *bin, GstElement *element, CameraBinSession *session);
211 static void elementRemoved(GstBin *bin, GstElement *element, CameraBinSession *session);
212
213 QUrl m_sink;
214 QUrl m_actualSink;
215 bool m_recordingActive;
216 QString m_captureDevice;
217 QCamera::Status m_status;
218 QCamera::State m_pendingState;
219 QString m_inputDevice;
220 bool m_muted;
221 bool m_busy;
222 QMediaStorageLocation m_mediaStorageLocation;
223
224 QCamera::CaptureModes m_captureMode;
225 QMap<QByteArray, QVariant> m_metaData;
226
227 QGstreamerElementFactory *m_audioInputFactory;
228 QGstreamerElementFactory *m_videoInputFactory;
229 QObject *m_viewfinder;
230 QGstreamerVideoRendererInterface *m_viewfinderInterface;
231 mutable QList<QCameraViewfinderSettings> m_supportedViewfinderSettings;
232 QCameraViewfinderSettings m_viewfinderSettings;
233 QCameraViewfinderSettings m_actualViewfinderSettings;
234
235 CameraBinControl *m_cameraControl;
236 CameraBinAudioEncoder *m_audioEncodeControl;
237 CameraBinVideoEncoder *m_videoEncodeControl;
238 CameraBinImageEncoder *m_imageEncodeControl;
239 CameraBinRecorder *m_recorderControl;
240 CameraBinContainer *m_mediaContainerControl;
241#if QT_CONFIG(gstreamer_photography)
242 CameraBinExposure *m_cameraExposureControl;
243 CameraBinFlash *m_cameraFlashControl;
244 CameraBinFocus *m_cameraFocusControl;
245 CameraBinLocks *m_cameraLocksControl;
246#endif
247 CameraBinZoom *m_cameraZoomControl;
248 CameraBinImageProcessing *m_imageProcessingControl;
249 CameraBinCaptureDestination *m_captureDestinationControl;
250 CameraBinCaptureBufferFormat *m_captureBufferFormatControl;
251
252 QGstreamerBusHelper *m_busHelper;
253 GstBus* m_bus;
254 GstElement *m_camerabin;
255 GstElement *m_cameraSrc;
256 GstElement *m_videoSrc;
257 GstElement *m_viewfinderElement;
258 GstElementFactory *m_sourceFactory;
259 bool m_viewfinderHasChanged;
260 bool m_inputDeviceHasChanged;
261 bool m_usingWrapperCameraBinSrc;
262
263 class ViewfinderProbe : public QGstreamerVideoProbeControl {
264 public:
265 ViewfinderProbe(CameraBinSession *s)
266 : QGstreamerVideoProbeControl(s)
267 , session(s)
268 {}
269
270 void probeCaps(GstCaps *caps) override;
271
272 private:
273 CameraBinSession * const session;
274 } m_viewfinderProbe;
275
276 GstElement *m_audioSrc;
277 GstElement *m_audioConvert;
278 GstElement *m_capsFilter;
279 GstElement *m_fileSink;
280 GstElement *m_audioEncoder;
281 GstElement *m_videoEncoder;
282 GstElement *m_muxer;
283
284public:
285 QString m_imageFileName;
286 int m_requestId;
287};
288
289QT_END_NAMESPACE
290
291#endif // CAMERABINCAPTURESESSION_H
292

source code of qtmultimedia/src/plugins/gstreamer/camerabin/camerabinsession.h