|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qgstreamercaptureservice.h" |
|
43 #include "qgstreamercapturesession.h" |
|
44 #include "qgstreamerrecordercontrol.h" |
|
45 #include "qgstreamermediacontainercontrol.h" |
|
46 #include "qgstreameraudioencode.h" |
|
47 #include "qgstreamervideoencode.h" |
|
48 #include "qgstreamerbushelper.h" |
|
49 #include "qgstreamerv4l2input.h" |
|
50 #include "qgstreamercapturemetadatacontrol.h" |
|
51 |
|
52 #include "qgstreameraudioinputendpointselector.h" |
|
53 #include "qgstreamervideoinputdevicecontrol.h" |
|
54 |
|
55 #include "qgstreamervideooverlay.h" |
|
56 #include "qgstreamervideorenderer.h" |
|
57 |
|
58 #include "qgstreamervideowidget.h" |
|
59 |
|
60 #include <qmediaserviceprovider.h> |
|
61 |
|
62 #include <QtCore/qdebug.h> |
|
63 |
|
64 |
|
65 class QGstreamerVideoRendererWrapper : public QGstreamerElementFactory |
|
66 { |
|
67 public: |
|
68 QGstreamerVideoRendererWrapper(QGstreamerVideoRendererInterface *videoRenderer) |
|
69 :m_videoRenderer(videoRenderer), |
|
70 m_bin(0), |
|
71 m_element(0), |
|
72 m_colorspace(0) |
|
73 { |
|
74 } |
|
75 |
|
76 virtual ~QGstreamerVideoRendererWrapper() |
|
77 { |
|
78 if (m_bin) |
|
79 gst_object_unref(GST_OBJECT(m_bin)); |
|
80 } |
|
81 |
|
82 GstElement *buildElement() |
|
83 { |
|
84 #ifdef Q_WS_MAEMO_5 |
|
85 return m_element = m_videoRenderer->videoSink(); |
|
86 #endif |
|
87 if (m_bin == NULL) { |
|
88 GstBin * bin = GST_BIN(gst_bin_new(NULL)); |
|
89 |
|
90 m_colorspace = gst_element_factory_make("ffmpegcolorspace", NULL); |
|
91 m_element = m_videoRenderer->videoSink(); |
|
92 |
|
93 gst_bin_add(bin, m_colorspace); |
|
94 gst_bin_add(bin, m_element); |
|
95 gst_element_link(m_colorspace, m_element); |
|
96 |
|
97 // add ghostpads |
|
98 GstPad *pad = gst_element_get_static_pad(m_colorspace, "sink"); |
|
99 gst_element_add_pad(GST_ELEMENT(bin), gst_ghost_pad_new("sink", pad)); |
|
100 gst_object_unref(GST_OBJECT(pad)); |
|
101 |
|
102 m_bin = GST_ELEMENT(bin); |
|
103 } |
|
104 |
|
105 m_videoRenderer->precessNewStream(); |
|
106 |
|
107 gst_object_ref(GST_OBJECT(m_bin)); |
|
108 return m_bin; |
|
109 } |
|
110 |
|
111 void prepareWinId() |
|
112 { |
|
113 m_videoRenderer->precessNewStream(); |
|
114 } |
|
115 |
|
116 private: |
|
117 QGstreamerVideoRendererInterface *m_videoRenderer; |
|
118 |
|
119 GstElement *m_bin; |
|
120 GstElement *m_element; |
|
121 GstElement *m_colorspace; |
|
122 }; |
|
123 |
|
124 |
|
125 QGstreamerCaptureService::QGstreamerCaptureService(const QString &service, QObject *parent): |
|
126 QMediaService(parent) |
|
127 { |
|
128 static bool initialized = false; |
|
129 if (!initialized) { |
|
130 initialized = true; |
|
131 gst_init(NULL, NULL); |
|
132 } |
|
133 |
|
134 m_captureSession = 0; |
|
135 m_metaDataControl = 0; |
|
136 |
|
137 m_videoInput = 0; |
|
138 m_audioInputEndpointSelector = 0; |
|
139 m_videoInputDevice = 0; |
|
140 |
|
141 m_videoOutput = 0; |
|
142 m_videoRenderer = 0; |
|
143 m_videoRendererFactory = 0; |
|
144 m_videoWindow = 0; |
|
145 m_videoWindowFactory = 0; |
|
146 m_videoWidgetControl = 0; |
|
147 m_videoWidgetFactory = 0; |
|
148 |
|
149 if (service == Q_MEDIASERVICE_AUDIOSOURCE) { |
|
150 m_captureSession = new QGstreamerCaptureSession(QGstreamerCaptureSession::Audio, this); |
|
151 } |
|
152 |
|
153 bool captureVideo = false; |
|
154 |
|
155 if (captureVideo) { |
|
156 m_captureSession = new QGstreamerCaptureSession(QGstreamerCaptureSession::AudioAndVideo, this); |
|
157 m_videoInput = new QGstreamerV4L2Input(this); |
|
158 m_captureSession->setVideoInput(m_videoInput); |
|
159 m_videoInputDevice = new QGstreamerVideoInputDeviceControl(this); |
|
160 |
|
161 connect(m_videoInputDevice, SIGNAL(selectedDeviceChanged(QString)), |
|
162 m_videoInput, SLOT(setDevice(QString))); |
|
163 |
|
164 if (m_videoInputDevice->deviceCount()) |
|
165 m_videoInput->setDevice(m_videoInputDevice->deviceName(m_videoInputDevice->selectedDevice())); |
|
166 |
|
167 m_videoRenderer = new QGstreamerVideoRenderer(this); |
|
168 m_videoRendererFactory = new QGstreamerVideoRendererWrapper(m_videoRenderer); |
|
169 |
|
170 #ifndef QT_NO_XVIDEO |
|
171 QGstreamerVideoOverlay *videoWindow = new QGstreamerVideoOverlay(this); |
|
172 m_videoWindow = videoWindow; |
|
173 m_videoWindowFactory = new QGstreamerVideoRendererWrapper(videoWindow); |
|
174 |
|
175 QGstreamerVideoWidgetControl *videoWidget = new QGstreamerVideoWidgetControl(this); |
|
176 m_videoWidgetControl = videoWidget; |
|
177 m_videoWidgetFactory = new QGstreamerVideoRendererWrapper(videoWidget); |
|
178 #endif |
|
179 } |
|
180 |
|
181 if (!m_captureSession) { |
|
182 qWarning() << "Service type is not supported:" << service; |
|
183 return; |
|
184 } |
|
185 |
|
186 m_audioInputEndpointSelector = new QGstreamerAudioInputEndpointSelector(this); |
|
187 connect(m_audioInputEndpointSelector, SIGNAL(activeEndpointChanged(QString)), m_captureSession, SLOT(setCaptureDevice(QString))); |
|
188 |
|
189 if (m_captureSession && m_audioInputEndpointSelector->availableEndpoints().size() > 0) |
|
190 m_captureSession->setCaptureDevice(m_audioInputEndpointSelector->defaultEndpoint()); |
|
191 |
|
192 m_metaDataControl = new QGstreamerCaptureMetaDataControl(this); |
|
193 connect(m_metaDataControl, SIGNAL(metaDataChanged(QMap<QByteArray,QVariant>)), |
|
194 m_captureSession, SLOT(setMetaData(QMap<QByteArray,QVariant>))); |
|
195 } |
|
196 |
|
197 QGstreamerCaptureService::~QGstreamerCaptureService() |
|
198 { |
|
199 } |
|
200 |
|
201 QMediaControl *QGstreamerCaptureService::requestControl(const char *name) |
|
202 { |
|
203 if (!m_captureSession) |
|
204 return 0; |
|
205 |
|
206 if (qstrcmp(name,QAudioEndpointSelector_iid) == 0) |
|
207 return m_audioInputEndpointSelector; |
|
208 |
|
209 if (qstrcmp(name,QVideoDeviceControl_iid) == 0) |
|
210 return m_videoInputDevice; |
|
211 |
|
212 if (qstrcmp(name,QMediaRecorderControl_iid) == 0) |
|
213 return m_captureSession->recorderControl(); |
|
214 |
|
215 if (qstrcmp(name,QAudioEncoderControl_iid) == 0) |
|
216 return m_captureSession->audioEncodeControl(); |
|
217 |
|
218 if (qstrcmp(name,QVideoEncoderControl_iid) == 0) |
|
219 return m_captureSession->videoEncodeControl(); |
|
220 |
|
221 if (qstrcmp(name,QMediaContainerControl_iid) == 0) |
|
222 return m_captureSession->mediaContainerControl(); |
|
223 |
|
224 if (qstrcmp(name,QMetaDataWriterControl_iid) == 0) |
|
225 return m_metaDataControl; |
|
226 |
|
227 if (!m_videoOutput) { |
|
228 if (qstrcmp(name, QVideoRendererControl_iid) == 0) { |
|
229 m_videoOutput = m_videoRenderer; |
|
230 m_captureSession->setVideoPreview(m_videoRendererFactory); |
|
231 } else if (qstrcmp(name, QVideoWindowControl_iid) == 0) { |
|
232 m_videoOutput = m_videoWindow; |
|
233 m_captureSession->setVideoPreview(m_videoWindowFactory); |
|
234 } else if (qstrcmp(name, QVideoWidgetControl_iid) == 0) { |
|
235 m_captureSession->setVideoPreview(m_videoWidgetFactory); |
|
236 m_videoOutput = m_videoWidgetControl; |
|
237 } |
|
238 |
|
239 if (m_videoOutput) |
|
240 return m_videoOutput; |
|
241 } |
|
242 |
|
243 return 0; |
|
244 } |
|
245 |
|
246 void QGstreamerCaptureService::releaseControl(QMediaControl *control) |
|
247 { |
|
248 if (control && control == m_videoOutput) { |
|
249 m_videoOutput = 0; |
|
250 m_captureSession->setVideoPreview(0); |
|
251 } |
|
252 } |