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#include <QtMultimedia/private/qtmultimediaglobal_p.h>
41#include "camerabinservice.h"
42#include "camerabinsession.h"
43#include "camerabinrecorder.h"
44#include "camerabincontainer.h"
45#include "camerabinaudioencoder.h"
46#include "camerabinvideoencoder.h"
47#include "camerabinimageencoder.h"
48#include "camerabincontrol.h"
49#include "camerabinmetadata.h"
50#include "camerabininfocontrol.h"
51
52#if QT_CONFIG(gstreamer_photography)
53#include "camerabinexposure.h"
54#include "camerabinflash.h"
55#include "camerabinfocus.h"
56#include "camerabinlocks.h"
57#endif
58
59#include "camerabinimagecapture.h"
60#include "camerabinimageprocessing.h"
61#include "camerabincapturebufferformat.h"
62#include "camerabincapturedestination.h"
63#include "camerabinviewfindersettings.h"
64#include "camerabinviewfindersettings2.h"
65#include "camerabinzoom.h"
66#include <private/qgstreamerbushelper_p.h>
67#include <private/qgstutils_p.h>
68
69#include <private/qgstreameraudioinputselector_p.h>
70#include <private/qgstreamervideoinputdevicecontrol_p.h>
71
72#if defined(HAVE_WIDGETS)
73#include <private/qgstreamervideowidget_p.h>
74#endif
75#include <private/qgstreamervideowindow_p.h>
76#include <private/qgstreamervideorenderer_p.h>
77#include <private/qmediaserviceprovider_p.h>
78
79#include <QtCore/qdebug.h>
80
81QT_BEGIN_NAMESPACE
82
83CameraBinService::CameraBinService(GstElementFactory *sourceFactory, QObject *parent):
84 QMediaService(parent),
85 m_cameraInfoControl(0),
86 m_viewfinderSettingsControl(0),
87 m_viewfinderSettingsControl2(0)
88{
89 m_captureSession = 0;
90 m_metaDataControl = 0;
91
92 m_audioInputSelector = 0;
93 m_videoInputDevice = 0;
94
95 m_videoOutput = 0;
96 m_videoRenderer = 0;
97 m_videoWindow = 0;
98#if defined(HAVE_WIDGETS)
99 m_videoWidgetControl = 0;
100#endif
101 m_imageCaptureControl = 0;
102
103 m_captureSession = new CameraBinSession(sourceFactory, this);
104 m_videoInputDevice = new QGstreamerVideoInputDeviceControl(sourceFactory, m_captureSession);
105 m_imageCaptureControl = new CameraBinImageCapture(m_captureSession);
106
107 connect(sender: m_videoInputDevice, SIGNAL(selectedDeviceChanged(QString)),
108 receiver: m_captureSession, SLOT(setDevice(QString)));
109
110 if (m_videoInputDevice->deviceCount())
111 m_captureSession->setDevice(m_videoInputDevice->deviceName(index: m_videoInputDevice->selectedDevice()));
112
113 m_videoRenderer = new QGstreamerVideoRenderer(this);
114
115 m_videoWindow = new QGstreamerVideoWindow(this);
116 // If the GStreamer video sink is not available, don't provide the video window control since
117 // it won't work anyway.
118 if (!m_videoWindow->videoSink()) {
119 delete m_videoWindow;
120 m_videoWindow = 0;
121 }
122#if defined(HAVE_WIDGETS)
123 m_videoWidgetControl = new QGstreamerVideoWidgetControl(this);
124
125 // If the GStreamer video sink is not available, don't provide the video widget control since
126 // it won't work anyway. QVideoWidget will fall back to QVideoRendererControl in that case.
127 if (!m_videoWidgetControl->videoSink()) {
128 delete m_videoWidgetControl;
129 m_videoWidgetControl = 0;
130 }
131#endif
132
133 m_audioInputSelector = new QGstreamerAudioInputSelector(this);
134 connect(sender: m_audioInputSelector, SIGNAL(activeInputChanged(QString)), receiver: m_captureSession, SLOT(setCaptureDevice(QString)));
135
136 if (m_captureSession && m_audioInputSelector->availableInputs().size() > 0)
137 m_captureSession->setCaptureDevice(m_audioInputSelector->defaultInput());
138
139 m_metaDataControl = new CameraBinMetaData(this);
140 connect(sender: m_metaDataControl, SIGNAL(metaDataChanged(QMap<QByteArray,QVariant>)),
141 receiver: m_captureSession, SLOT(setMetaData(QMap<QByteArray,QVariant>)));
142}
143
144CameraBinService::~CameraBinService()
145{
146}
147
148QMediaControl *CameraBinService::requestControl(const char *name)
149{
150 if (!m_captureSession)
151 return 0;
152
153 if (!m_videoOutput) {
154 if (qstrcmp(str1: name, QVideoRendererControl_iid) == 0) {
155 m_videoOutput = m_videoRenderer;
156 } else if (qstrcmp(str1: name, QVideoWindowControl_iid) == 0) {
157 m_videoOutput = m_videoWindow;
158 }
159#if defined(HAVE_WIDGETS)
160 else if (qstrcmp(str1: name, QVideoWidgetControl_iid) == 0) {
161 m_videoOutput = m_videoWidgetControl;
162 }
163#endif
164
165 if (m_videoOutput) {
166 m_captureSession->setViewfinder(m_videoOutput);
167 return m_videoOutput;
168 }
169 }
170
171 if (qstrcmp(str1: name, QMediaVideoProbeControl_iid) == 0)
172 return m_captureSession->videoProbe();
173
174 if (qstrcmp(str1: name,QAudioInputSelectorControl_iid) == 0)
175 return m_audioInputSelector;
176
177 if (qstrcmp(str1: name,QVideoDeviceSelectorControl_iid) == 0)
178 return m_videoInputDevice;
179
180 if (qstrcmp(str1: name,QMediaRecorderControl_iid) == 0)
181 return m_captureSession->recorderControl();
182
183 if (qstrcmp(str1: name,QAudioEncoderSettingsControl_iid) == 0)
184 return m_captureSession->audioEncodeControl();
185
186 if (qstrcmp(str1: name,QVideoEncoderSettingsControl_iid) == 0)
187 return m_captureSession->videoEncodeControl();
188
189 if (qstrcmp(str1: name,QImageEncoderControl_iid) == 0)
190 return m_captureSession->imageEncodeControl();
191
192
193 if (qstrcmp(str1: name,QMediaContainerControl_iid) == 0)
194 return m_captureSession->mediaContainerControl();
195
196 if (qstrcmp(str1: name,QCameraControl_iid) == 0)
197 return m_captureSession->cameraControl();
198
199 if (qstrcmp(str1: name,QMetaDataWriterControl_iid) == 0)
200 return m_metaDataControl;
201
202 if (qstrcmp(str1: name, QCameraImageCaptureControl_iid) == 0)
203 return m_imageCaptureControl;
204
205#if QT_CONFIG(gstreamer_photography)
206 if (qstrcmp(str1: name, QCameraExposureControl_iid) == 0)
207 return m_captureSession->cameraExposureControl();
208
209 if (qstrcmp(str1: name, QCameraFlashControl_iid) == 0)
210 return m_captureSession->cameraFlashControl();
211
212 if (qstrcmp(str1: name, QCameraFocusControl_iid) == 0)
213 return m_captureSession->cameraFocusControl();
214
215 if (qstrcmp(str1: name, QCameraLocksControl_iid) == 0)
216 return m_captureSession->cameraLocksControl();
217#endif
218
219 if (qstrcmp(str1: name, QCameraZoomControl_iid) == 0)
220 return m_captureSession->cameraZoomControl();
221
222 if (qstrcmp(str1: name, QCameraImageProcessingControl_iid) == 0)
223 return m_captureSession->imageProcessingControl();
224
225 if (qstrcmp(str1: name, QCameraCaptureDestinationControl_iid) == 0)
226 return m_captureSession->captureDestinationControl();
227
228 if (qstrcmp(str1: name, QCameraCaptureBufferFormatControl_iid) == 0)
229 return m_captureSession->captureBufferFormatControl();
230
231 if (qstrcmp(str1: name, QCameraViewfinderSettingsControl_iid) == 0) {
232 if (!m_viewfinderSettingsControl)
233 m_viewfinderSettingsControl = new CameraBinViewfinderSettings(m_captureSession);
234 return m_viewfinderSettingsControl;
235 }
236
237 if (qstrcmp(str1: name, QCameraViewfinderSettingsControl2_iid) == 0) {
238 if (!m_viewfinderSettingsControl2)
239 m_viewfinderSettingsControl2 = new CameraBinViewfinderSettings2(m_captureSession);
240 return m_viewfinderSettingsControl2;
241 }
242
243 if (qstrcmp(str1: name, QCameraInfoControl_iid) == 0) {
244 if (!m_cameraInfoControl)
245 m_cameraInfoControl = new CameraBinInfoControl(m_captureSession->sourceFactory(), this);
246 return m_cameraInfoControl;
247 }
248
249 return 0;
250}
251
252void CameraBinService::releaseControl(QMediaControl *control)
253{
254 if (control && control == m_videoOutput) {
255 m_videoOutput = 0;
256 m_captureSession->setViewfinder(0);
257 }
258}
259
260bool CameraBinService::isCameraBinAvailable()
261{
262 GstElementFactory *factory = gst_element_factory_find(QT_GSTREAMER_CAMERABIN_ELEMENT_NAME);
263 if (factory) {
264 gst_object_unref(GST_OBJECT(factory));
265 return true;
266 }
267
268 return false;
269}
270
271QT_END_NAMESPACE
272

source code of qtmultimedia/src/plugins/gstreamer/camerabin/camerabinservice.cpp