1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include "cxevideorecorderutilitysymbian.h" |
|
18 #include "cxenamespace.h" |
|
19 #include "cxutils.h" |
|
20 #include <AudioPreference.h> |
|
21 |
|
22 namespace |
|
23 { |
|
24 // Controller UId, can be used by the client to identify the controller, e.g. if the custom command can be used |
|
25 const TUid KCamCControllerImplementationUid = {0x101F8503}; |
|
26 |
|
27 // Custom command for setting a new filename without closing & reopening the controller |
|
28 enum TCamCControllerCustomCommands |
|
29 { |
|
30 ECamCControllerCCNewFilename = 0, |
|
31 ECamCControllerCCVideoStopAsync |
|
32 }; |
|
33 |
|
34 const uint KOneMillion = 1000000; |
|
35 } |
|
36 |
|
37 |
|
38 CxeVideoRecorderUtilitySymbian::~CxeVideoRecorderUtilitySymbian() |
|
39 { |
|
40 CX_DEBUG_ENTER_FUNCTION(); |
|
41 delete mVideoRecorder; |
|
42 mVideoRecorder = NULL; |
|
43 CX_DEBUG_EXIT_FUNCTION(); |
|
44 } |
|
45 |
|
46 CxeVideoRecorderUtilitySymbian::CxeVideoRecorderUtilitySymbian(MVideoRecorderUtilityObserver& aObserver) |
|
47 { |
|
48 CX_DEBUG_ENTER_FUNCTION(); |
|
49 QT_TRAP_THROWING(mVideoRecorder = |
|
50 CVideoRecorderUtility::NewL(aObserver, |
|
51 KAudioPriorityVideoRecording, |
|
52 TMdaPriorityPreference(KAudioPrefVideoRecording))); |
|
53 CX_DEBUG_EXIT_FUNCTION(); |
|
54 } |
|
55 |
|
56 /*! |
|
57 * Open new file for recording. |
|
58 * @param cameraHandle Handle for camera. |
|
59 * @param filename Full filename of the video file to open. |
|
60 * @param fileMimeType MIME type for the video file. |
|
61 * @param supplier Preferred supplier. |
|
62 * @param videoType Video codec MIME type. |
|
63 * @param audioType Audio FourCC type. |
|
64 */ |
|
65 void CxeVideoRecorderUtilitySymbian::open(int cameraHandle, |
|
66 const QString &filename, |
|
67 const QString &fileMimeType, |
|
68 const QString &supplier, |
|
69 const QString &videoType, |
|
70 const QString &audioType) |
|
71 { |
|
72 CX_DEBUG_ENTER_FUNCTION(); |
|
73 CX_DEBUG(("CxeVideoRecorderUtilitySymbian - filename [%s]", filename.toAscii().constData())); |
|
74 CX_DEBUG(("CxeVideoRecorderUtilitySymbian - file mime [%s]", fileMimeType.toAscii().constData())); |
|
75 CX_DEBUG(("CxeVideoRecorderUtilitySymbian - supplier [%s]", supplier.toAscii().constData())); |
|
76 CX_DEBUG(("CxeVideoRecorderUtilitySymbian - codec mime [%s]", videoType.toAscii().constData())); |
|
77 CX_DEBUG(("CxeVideoRecorderUtilitySymbian - audio FourCC [%s]", audioType.toAscii().constData())); |
|
78 |
|
79 QByteArray bytes = videoType.toLatin1(); |
|
80 TPtrC8 videoTypeDesC(reinterpret_cast<const TUint8*>(bytes.constData()), bytes.size()); |
|
81 TPtrC16 filenameDesC(reinterpret_cast<const TUint16*>(filename.utf16())); |
|
82 |
|
83 TUid controllerId; |
|
84 TUid formatId; |
|
85 QT_TRAP_THROWING({ |
|
86 // Find the video controller id and video format id. |
|
87 findControllerL(fileMimeType, supplier, controllerId, formatId); |
|
88 |
|
89 // Try to open new video file with given parameters. |
|
90 mVideoRecorder->OpenFileL(filenameDesC, cameraHandle, controllerId, |
|
91 formatId, videoTypeDesC, audioFourCC(audioType)); |
|
92 }); |
|
93 CX_DEBUG_EXIT_FUNCTION(); |
|
94 } |
|
95 |
|
96 /*! |
|
97 * Set frame size. |
|
98 * @param size The video frame size. |
|
99 */ |
|
100 void CxeVideoRecorderUtilitySymbian::setVideoFrameSize(const QSize &size) |
|
101 { |
|
102 CX_DEBUG_ENTER_FUNCTION(); |
|
103 TSize frameSize(size.width(), size.height()); |
|
104 QT_TRAP_THROWING(mVideoRecorder->SetVideoFrameSizeL(frameSize)); |
|
105 CX_DEBUG_EXIT_FUNCTION(); |
|
106 } |
|
107 |
|
108 /*! |
|
109 * Set video frame rate. |
|
110 * @param rate The video frame rate. |
|
111 */ |
|
112 void CxeVideoRecorderUtilitySymbian::setVideoFrameRate(int rate) |
|
113 { |
|
114 CX_DEBUG_ENTER_FUNCTION(); |
|
115 QT_TRAP_THROWING(mVideoRecorder->SetVideoFrameRateL(rate)); |
|
116 CX_DEBUG_EXIT_FUNCTION(); |
|
117 } |
|
118 |
|
119 /*! |
|
120 * Set video bit rate. |
|
121 * @param The video bit rate. |
|
122 */ |
|
123 void CxeVideoRecorderUtilitySymbian::setVideoBitRate(int rate) |
|
124 { |
|
125 CX_DEBUG_ENTER_FUNCTION(); |
|
126 QT_TRAP_THROWING(mVideoRecorder->SetVideoBitRateL(rate)); |
|
127 CX_DEBUG_EXIT_FUNCTION(); |
|
128 } |
|
129 |
|
130 /*! |
|
131 * Set if audio recording is on or not. |
|
132 * @param enabled Is audio recording enabled. |
|
133 */ |
|
134 void CxeVideoRecorderUtilitySymbian::setAudioEnabled(bool enabled) |
|
135 { |
|
136 CX_DEBUG_ENTER_FUNCTION(); |
|
137 QT_TRAP_THROWING(mVideoRecorder->SetAudioEnabledL(enabled)); |
|
138 CX_DEBUG_EXIT_FUNCTION(); |
|
139 } |
|
140 |
|
141 /*! |
|
142 * Set maximum video clip size in bytes. |
|
143 * @param sizeInBytes Video clip size limit. |
|
144 */ |
|
145 void CxeVideoRecorderUtilitySymbian::setVideoMaxSize(int sizeInBytes) |
|
146 { |
|
147 CX_DEBUG_ENTER_FUNCTION(); |
|
148 if (sizeInBytes <= 0) { |
|
149 sizeInBytes = KMMFNoMaxClipSize; |
|
150 } |
|
151 QT_TRAP_THROWING(mVideoRecorder->SetMaxClipSizeL(sizeInBytes)); |
|
152 CX_DEBUG_EXIT_FUNCTION(); |
|
153 } |
|
154 |
|
155 /*! |
|
156 * Close video recorder, freeing its resources. |
|
157 */ |
|
158 void CxeVideoRecorderUtilitySymbian::close() |
|
159 { |
|
160 CX_DEBUG_ENTER_FUNCTION(); |
|
161 mVideoRecorder->Close(); |
|
162 CX_DEBUG_EXIT_FUNCTION(); |
|
163 } |
|
164 |
|
165 /*! |
|
166 * Prepare for video recording. |
|
167 */ |
|
168 void CxeVideoRecorderUtilitySymbian::prepare() |
|
169 { |
|
170 CX_DEBUG_ENTER_FUNCTION(); |
|
171 mVideoRecorder->Prepare(); |
|
172 CX_DEBUG_EXIT_FUNCTION(); |
|
173 } |
|
174 |
|
175 /*! |
|
176 * Start recording. |
|
177 */ |
|
178 void CxeVideoRecorderUtilitySymbian::record() |
|
179 { |
|
180 CX_DEBUG_ENTER_FUNCTION(); |
|
181 mVideoRecorder->Record(); |
|
182 CX_DEBUG_EXIT_FUNCTION(); |
|
183 } |
|
184 |
|
185 /*! |
|
186 * Stop recording. |
|
187 * @param asynchronous Use asynchronous (true) or synchronous (false) stopping. |
|
188 */ |
|
189 void CxeVideoRecorderUtilitySymbian::stop(bool asynchronous) |
|
190 { |
|
191 CX_DEBUG_ENTER_FUNCTION(); |
|
192 |
|
193 if (asynchronous) { |
|
194 TMMFMessageDestination dest(KCamCControllerImplementationUid, KMMFObjectHandleController); |
|
195 qt_symbian_throwIfError(mVideoRecorder->CustomCommandSync( |
|
196 dest, ECamCControllerCCVideoStopAsync, KNullDesC8, KNullDesC8)); |
|
197 } else { |
|
198 qt_symbian_throwIfError(mVideoRecorder->Stop()); |
|
199 } |
|
200 CX_DEBUG_EXIT_FUNCTION(); |
|
201 } |
|
202 |
|
203 /*! |
|
204 * Pause recording. |
|
205 */ |
|
206 void CxeVideoRecorderUtilitySymbian::pause() |
|
207 { |
|
208 CX_DEBUG_ENTER_FUNCTION(); |
|
209 QT_TRAP_THROWING(mVideoRecorder->PauseL()); |
|
210 CX_DEBUG_EXIT_FUNCTION(); |
|
211 } |
|
212 |
|
213 /*! |
|
214 * Get estimated available recording time. |
|
215 * @return Available recording time estimate in seconds. |
|
216 */ |
|
217 int CxeVideoRecorderUtilitySymbian::availableRecordingTime() |
|
218 { |
|
219 CX_DEBUG_IN_FUNCTION(); |
|
220 // Convert microseconds to seconds. |
|
221 return mVideoRecorder->RecordTimeAvailable().Int64() * 1.0 / KOneMillion; |
|
222 } |
|
223 |
|
224 /*! |
|
225 * Get elapsed duration of the recorded video. |
|
226 * @return Duration of the video in seconds. |
|
227 */ |
|
228 int CxeVideoRecorderUtilitySymbian::duration() |
|
229 { |
|
230 CX_DEBUG_ENTER_FUNCTION(); |
|
231 int time(0); |
|
232 // Convert microseconds to seconds. |
|
233 QT_TRAP_THROWING(time = mVideoRecorder->DurationL().Int64() * 1.0 / KOneMillion); |
|
234 CX_DEBUG_EXIT_FUNCTION(); |
|
235 return time; |
|
236 } |
|
237 |
|
238 /*! |
|
239 * Find video controller and format UIDs based on file mime type and preferred supplier. |
|
240 * @param fileMimeType MIME type for the video file. |
|
241 * @param supplier Preferred supplier. |
|
242 * @param controllerId Returns found controller UID. |
|
243 * @param formatId Returns found format UID. |
|
244 */ |
|
245 void CxeVideoRecorderUtilitySymbian::findControllerL(const QString& fileMimeType, |
|
246 const QString& supplier, |
|
247 TUid& controllerId, |
|
248 TUid& formatId) |
|
249 { |
|
250 CX_DEBUG_ENTER_FUNCTION(); |
|
251 |
|
252 // Retrieve a list of possible controllers from ECOM. |
|
253 // Controller must support recording the requested mime type. |
|
254 // Controller must be provided by preferred supplier. |
|
255 controllerId = KNullUid; |
|
256 formatId = KNullUid; |
|
257 |
|
258 QByteArray bytes = fileMimeType.toLatin1(); |
|
259 TPtrC8 mimeTPtr(reinterpret_cast<const TUint8*>(bytes.constData()), bytes.size()); |
|
260 TPtrC16 supplierTPtr(reinterpret_cast<const TUint16*>(supplier.utf16())); |
|
261 |
|
262 CMMFControllerPluginSelectionParameters* cSelect(NULL); |
|
263 CMMFFormatSelectionParameters* fSelect(NULL); |
|
264 RMMFControllerImplInfoArray controllers; |
|
265 |
|
266 cSelect = CMMFControllerPluginSelectionParameters::NewLC(); |
|
267 fSelect = CMMFFormatSelectionParameters::NewLC(); |
|
268 |
|
269 fSelect->SetMatchToMimeTypeL(mimeTPtr); |
|
270 cSelect->SetRequiredRecordFormatSupportL(*fSelect); |
|
271 cSelect->SetPreferredSupplierL(supplierTPtr, |
|
272 CMMFPluginSelectionParameters::EOnlyPreferredSupplierPluginsReturned); |
|
273 cSelect->ListImplementationsL(controllers); |
|
274 CleanupResetAndDestroyPushL(controllers); |
|
275 |
|
276 if (controllers.Count() <= 0) { |
|
277 CX_DEBUG(("CxeVideoRecorderUtilitySymbian - zero controllers found, leaving!")); |
|
278 User::Leave(KErrNotFound); |
|
279 } |
|
280 |
|
281 // Inquires the controller about supported formats. |
|
282 // We use the first controller found having index 0. |
|
283 const RMMFFormatImplInfoArray& formats = controllers[0]->RecordFormats(); |
|
284 |
|
285 // Get the first format that supports our mime type. |
|
286 int count(formats.Count()); |
|
287 for (int i=0; i<count; i++) { |
|
288 if (formats[i]->SupportsMimeType(mimeTPtr)) { |
|
289 CX_DEBUG(("CxeVideoRecorderUtilitySymbian - found controller")); |
|
290 // Store the format UID |
|
291 formatId = formats[i]->Uid(); |
|
292 // Store the controller UID |
|
293 controllerId = controllers[0]->Uid(); |
|
294 break; |
|
295 } |
|
296 } |
|
297 |
|
298 // Check that we found the uids. |
|
299 if (controllerId == KNullUid) { |
|
300 CX_DEBUG(("CxeVideoRecorderUtilitySymbian - no matching controller found, leaving!")); |
|
301 User::Leave(KErrNotFound); |
|
302 } |
|
303 |
|
304 CleanupStack::PopAndDestroy(3); // controllers, fSelect, cSelect |
|
305 CX_DEBUG_EXIT_FUNCTION(); |
|
306 } |
|
307 |
|
308 /*! |
|
309 * Helper method to convert QString to TFourCC. |
|
310 * @param str String to convert. |
|
311 */ |
|
312 TFourCC CxeVideoRecorderUtilitySymbian::audioFourCC(const QString& str) |
|
313 { |
|
314 CX_DEBUG_ENTER_FUNCTION(); |
|
315 |
|
316 QByteArray audioType = str.toAscii(); |
|
317 |
|
318 quint8 char1(' '); |
|
319 quint8 char2(' '); |
|
320 quint8 char3(' '); |
|
321 quint8 char4(' '); |
|
322 |
|
323 if (audioType.count() > 3) { |
|
324 char1 = audioType[0]; |
|
325 char2 = audioType[1]; |
|
326 char3 = audioType[2]; |
|
327 |
|
328 if (audioType.count() == 4) { |
|
329 char4 = audioType[3]; |
|
330 } |
|
331 } |
|
332 |
|
333 CX_DEBUG_EXIT_FUNCTION(); |
|
334 return TFourCC(char1, char2, char3, char4); |
|
335 } |
|
336 |
|
337 |
|
338 // end of file |
|