38 ** $QT_END_LICENSE$ |
38 ** $QT_END_LICENSE$ |
39 ** |
39 ** |
40 ****************************************************************************/ |
40 ****************************************************************************/ |
41 |
41 |
42 #include "qgstreamerrecordercontrol.h" |
42 #include "qgstreamerrecordercontrol.h" |
|
43 #include "qgstreameraudioencode.h" |
|
44 #include "qgstreamervideoencode.h" |
|
45 #include "qgstreamermediacontainercontrol.h" |
43 #include <QtCore/QDebug> |
46 #include <QtCore/QDebug> |
44 |
47 |
45 QGstreamerRecorderControl::QGstreamerRecorderControl(QGstreamerCaptureSession *session) |
48 QGstreamerRecorderControl::QGstreamerRecorderControl(QGstreamerCaptureSession *session) |
46 :QMediaRecorderControl(session), m_session(session), m_state(QMediaRecorder::StoppedState) |
49 :QMediaRecorderControl(session), m_session(session), m_state(QMediaRecorder::StoppedState) |
47 { |
50 { |
98 } |
101 } |
99 |
102 |
100 void QGstreamerRecorderControl::record() |
103 void QGstreamerRecorderControl::record() |
101 { |
104 { |
102 m_session->dumpGraph("before-record"); |
105 m_session->dumpGraph("before-record"); |
103 if (!m_hasPreviewState || m_session->state() != QGstreamerCaptureSession::StoppedState) |
106 if (!m_hasPreviewState || m_session->state() != QGstreamerCaptureSession::StoppedState) { |
104 m_session->setState(QGstreamerCaptureSession::RecordingState); |
107 m_session->setState(QGstreamerCaptureSession::RecordingState); |
105 else |
108 } else |
106 emit error(QMediaRecorder::ResourceError, tr("Service has not been started")); |
109 emit error(QMediaRecorder::ResourceError, tr("Service has not been started")); |
107 |
110 |
108 m_session->dumpGraph("after-record"); |
111 m_session->dumpGraph("after-record"); |
109 } |
112 } |
110 |
113 |
111 void QGstreamerRecorderControl::pause() |
114 void QGstreamerRecorderControl::pause() |
112 { |
115 { |
113 m_session->dumpGraph("before-pause"); |
116 m_session->dumpGraph("before-pause"); |
114 if (!m_hasPreviewState || m_session->state() != QGstreamerCaptureSession::StoppedState) |
117 if (!m_hasPreviewState || m_session->state() != QGstreamerCaptureSession::StoppedState) { |
115 m_session->setState(QGstreamerCaptureSession::PausedState); |
118 m_session->setState(QGstreamerCaptureSession::PausedState); |
116 else |
119 } else |
117 emit error(QMediaRecorder::ResourceError, tr("Service has not been started")); |
120 emit error(QMediaRecorder::ResourceError, tr("Service has not been started")); |
118 } |
121 } |
119 |
122 |
120 void QGstreamerRecorderControl::stop() |
123 void QGstreamerRecorderControl::stop() |
121 { |
124 { |
124 } else { |
127 } else { |
125 if (m_session->state() != QGstreamerCaptureSession::StoppedState) |
128 if (m_session->state() != QGstreamerCaptureSession::StoppedState) |
126 m_session->setState(QGstreamerCaptureSession::PreviewState); |
129 m_session->setState(QGstreamerCaptureSession::PreviewState); |
127 } |
130 } |
128 } |
131 } |
|
132 |
|
133 void QGstreamerRecorderControl::applySettings() |
|
134 { |
|
135 //Check the codecs are compatible with container, |
|
136 //and choose the compatible codecs/container if omitted |
|
137 QGstreamerAudioEncode *audioEncodeControl = m_session->audioEncodeControl(); |
|
138 QGstreamerVideoEncode *videoEncodeControl = m_session->videoEncodeControl(); |
|
139 QGstreamerMediaContainerControl *mediaContainerControl = m_session->mediaContainerControl(); |
|
140 |
|
141 bool needAudio = m_session->captureMode() & QGstreamerCaptureSession::Audio; |
|
142 bool needVideo = m_session->captureMode() & QGstreamerCaptureSession::Video; |
|
143 |
|
144 QStringList containerCandidates; |
|
145 if (mediaContainerControl->containerMimeType().isEmpty()) |
|
146 containerCandidates = mediaContainerControl->supportedContainers(); |
|
147 else |
|
148 containerCandidates << mediaContainerControl->containerMimeType(); |
|
149 |
|
150 |
|
151 QStringList audioCandidates; |
|
152 if (needAudio) { |
|
153 QAudioEncoderSettings audioSettings = audioEncodeControl->audioSettings(); |
|
154 if (audioSettings.codec().isEmpty()) |
|
155 audioCandidates = audioEncodeControl->supportedAudioCodecs(); |
|
156 else |
|
157 audioCandidates << audioSettings.codec(); |
|
158 } |
|
159 |
|
160 QStringList videoCandidates; |
|
161 if (needVideo) { |
|
162 QVideoEncoderSettings videoSettings = videoEncodeControl->videoSettings(); |
|
163 if (videoSettings.codec().isEmpty()) |
|
164 videoCandidates = videoEncodeControl->supportedVideoCodecs(); |
|
165 else |
|
166 videoCandidates << videoSettings.codec(); |
|
167 } |
|
168 |
|
169 QString container; |
|
170 QString audioCodec; |
|
171 QString videoCodec; |
|
172 |
|
173 foreach (const QString &containerCandidate, containerCandidates) { |
|
174 QSet<QString> supportedTypes = mediaContainerControl->supportedStreamTypes(containerCandidate); |
|
175 |
|
176 audioCodec.clear(); |
|
177 videoCodec.clear(); |
|
178 |
|
179 if (needAudio) { |
|
180 bool found = false; |
|
181 foreach (const QString &audioCandidate, audioCandidates) { |
|
182 QSet<QString> audioTypes = audioEncodeControl->supportedStreamTypes(audioCandidate); |
|
183 if (!audioTypes.intersect(supportedTypes).isEmpty()) { |
|
184 found = true; |
|
185 audioCodec = audioCandidate; |
|
186 break; |
|
187 } |
|
188 } |
|
189 if (!found) |
|
190 continue; |
|
191 } |
|
192 |
|
193 if (needVideo) { |
|
194 bool found = false; |
|
195 foreach (const QString &videoCandidate, videoCandidates) { |
|
196 QSet<QString> videoTypes = videoEncodeControl->supportedStreamTypes(videoCandidate); |
|
197 if (!videoTypes.intersect(supportedTypes).isEmpty()) { |
|
198 found = true; |
|
199 videoCodec = videoCandidate; |
|
200 break; |
|
201 } |
|
202 } |
|
203 if (!found) |
|
204 continue; |
|
205 } |
|
206 |
|
207 container = containerCandidate; |
|
208 break; |
|
209 } |
|
210 |
|
211 if (container.isEmpty()) { |
|
212 emit error(QMediaRecorder::FormatError, tr("Not compatible codecs and container format.")); |
|
213 } else { |
|
214 mediaContainerControl->setContainerMimeType(container); |
|
215 |
|
216 if (needAudio) { |
|
217 QAudioEncoderSettings audioSettings = audioEncodeControl->audioSettings(); |
|
218 audioSettings.setCodec(audioCodec); |
|
219 audioEncodeControl->setAudioSettings(audioSettings); |
|
220 } |
|
221 |
|
222 if (needVideo) { |
|
223 QVideoEncoderSettings videoSettings = videoEncodeControl->videoSettings(); |
|
224 videoSettings.setCodec(videoCodec); |
|
225 videoEncodeControl->setVideoSettings(videoSettings); |
|
226 } |
|
227 } |
|
228 } |