15 * |
15 * |
16 */ |
16 */ |
17 #include "cxevideorecorderutilitysymbian.h" |
17 #include "cxevideorecorderutilitysymbian.h" |
18 #include "cxenamespace.h" |
18 #include "cxenamespace.h" |
19 #include "cxutils.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 } |
20 |
36 |
21 |
37 |
22 CxeVideoRecorderUtilitySymbian::~CxeVideoRecorderUtilitySymbian() |
38 CxeVideoRecorderUtilitySymbian::~CxeVideoRecorderUtilitySymbian() |
23 { |
39 { |
24 CX_DEBUG_ENTER_FUNCTION(); |
40 CX_DEBUG_ENTER_FUNCTION(); |
25 delete mVideoRecorder; |
41 delete mVideoRecorder; |
26 mVideoRecorder = NULL; |
42 mVideoRecorder = NULL; |
27 CX_DEBUG_EXIT_FUNCTION(); |
43 CX_DEBUG_EXIT_FUNCTION(); |
28 } |
44 } |
29 |
45 |
30 CxeVideoRecorderUtilitySymbian::CxeVideoRecorderUtilitySymbian(MVideoRecorderUtilityObserver& aObserver, |
46 CxeVideoRecorderUtilitySymbian::CxeVideoRecorderUtilitySymbian(MVideoRecorderUtilityObserver& aObserver) |
31 TInt aPriority, |
47 { |
32 TMdaPriorityPreference aPref) |
48 CX_DEBUG_ENTER_FUNCTION(); |
33 { |
49 QT_TRAP_THROWING(mVideoRecorder = |
34 CX_DEBUG_ENTER_FUNCTION(); |
50 CVideoRecorderUtility::NewL(aObserver, |
35 TRAPD(initErr, mVideoRecorder = CVideoRecorderUtility::NewL(aObserver, aPriority, aPref)); |
51 KAudioPriorityVideoRecording, |
36 mStartuperror = initErr; |
52 TMdaPriorityPreference(KAudioPrefVideoRecording))); |
37 CX_DEBUG_EXIT_FUNCTION(); |
53 CX_DEBUG_EXIT_FUNCTION(); |
38 } |
54 } |
39 |
55 |
40 TInt CxeVideoRecorderUtilitySymbian::CustomCommandSync(const TMMFMessageDestinationPckg& aDestination, |
56 /*! |
41 TInt aFunction, |
57 * Open new file for recording. |
42 const TDesC8& aDataTo1, |
58 * @param cameraHandle Handle for camera. |
43 const TDesC8& aDataTo2) |
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() |
44 { |
218 { |
45 CX_DEBUG_IN_FUNCTION(); |
219 CX_DEBUG_IN_FUNCTION(); |
46 return mVideoRecorder->CustomCommandSync(aDestination, aFunction, aDataTo1, aDataTo2); |
220 // Convert microseconds to seconds. |
47 } |
221 return mVideoRecorder->RecordTimeAvailable().Int64() * 1.0 / KOneMillion; |
48 |
222 } |
49 void CxeVideoRecorderUtilitySymbian::OpenFileL(const TDesC& aFileName, |
223 |
50 TInt aCameraHandle, |
224 /*! |
51 TUid aControllerUid, |
225 * Get elapsed duration of the recorded video. |
52 TUid aVideoFormat, |
226 * @return Duration of the video in seconds. |
53 const TDesC8& aVideoType, |
227 */ |
54 TFourCC aAudioType) |
228 int CxeVideoRecorderUtilitySymbian::duration() |
55 { |
229 { |
56 CX_DEBUG_ENTER_FUNCTION(); |
230 CX_DEBUG_ENTER_FUNCTION(); |
57 mVideoRecorder->OpenFileL(aFileName, aCameraHandle, aControllerUid, aVideoFormat, aVideoType, aAudioType); |
231 int time(0); |
58 CX_DEBUG_EXIT_FUNCTION(); |
232 // Convert microseconds to seconds. |
59 } |
233 QT_TRAP_THROWING(time = mVideoRecorder->DurationL().Int64() * 1.0 / KOneMillion); |
60 |
234 CX_DEBUG_EXIT_FUNCTION(); |
61 void CxeVideoRecorderUtilitySymbian::SetVideoFrameSizeL(TSize aSize) |
235 return time; |
62 { |
236 } |
63 CX_DEBUG_ENTER_FUNCTION(); |
237 |
64 mVideoRecorder->SetVideoFrameSizeL(aSize); |
238 /*! |
65 CX_DEBUG_EXIT_FUNCTION(); |
239 * Find video controller and format UIDs based on file mime type and preferred supplier. |
66 } |
240 * @param fileMimeType MIME type for the video file. |
67 |
241 * @param supplier Preferred supplier. |
68 void CxeVideoRecorderUtilitySymbian::SetVideoFrameRateL(TInt aRate) |
242 * @param controllerId Returns found controller UID. |
69 { |
243 * @param formatId Returns found format UID. |
70 CX_DEBUG_ENTER_FUNCTION(); |
244 */ |
71 mVideoRecorder->SetVideoFrameRateL(aRate); |
245 void CxeVideoRecorderUtilitySymbian::findControllerL(const QString& fileMimeType, |
72 CX_DEBUG_EXIT_FUNCTION(); |
246 const QString& supplier, |
73 } |
247 TUid& controllerId, |
74 |
248 TUid& formatId) |
75 void CxeVideoRecorderUtilitySymbian::SetVideoBitRateL(TInt aRate) |
249 { |
76 { |
250 CX_DEBUG_ENTER_FUNCTION(); |
77 CX_DEBUG_ENTER_FUNCTION(); |
251 |
78 mVideoRecorder->SetVideoBitRateL(aRate); |
252 // Retrieve a list of possible controllers from ECOM. |
79 CX_DEBUG_EXIT_FUNCTION(); |
253 // Controller must support recording the requested mime type. |
80 } |
254 // Controller must be provided by preferred supplier. |
81 |
255 controllerId = KNullUid; |
82 void CxeVideoRecorderUtilitySymbian::SetAudioEnabledL(TBool aEnable) |
256 formatId = KNullUid; |
83 { |
257 |
84 CX_DEBUG_ENTER_FUNCTION(); |
258 QByteArray bytes = fileMimeType.toLatin1(); |
85 mVideoRecorder->SetAudioEnabledL(aEnable); |
259 TPtrC8 mimeTPtr(reinterpret_cast<const TUint8*>(bytes.constData()), bytes.size()); |
86 CX_DEBUG_EXIT_FUNCTION(); |
260 TPtrC16 supplierTPtr(reinterpret_cast<const TUint16*>(supplier.utf16())); |
87 } |
261 |
88 |
262 CMMFControllerPluginSelectionParameters* cSelect(NULL); |
89 void CxeVideoRecorderUtilitySymbian::SetMaxClipSizeL(TInt aClipSizeInBytes) |
263 CMMFFormatSelectionParameters* fSelect(NULL); |
90 { |
264 RMMFControllerImplInfoArray controllers; |
91 CX_DEBUG_ENTER_FUNCTION(); |
265 |
92 if (aClipSizeInBytes <= 0) { |
266 cSelect = CMMFControllerPluginSelectionParameters::NewLC(); |
93 aClipSizeInBytes = KMMFNoMaxClipSize; |
267 fSelect = CMMFFormatSelectionParameters::NewLC(); |
94 } |
268 |
95 mVideoRecorder->SetMaxClipSizeL(aClipSizeInBytes); |
269 fSelect->SetMatchToMimeTypeL(mimeTPtr); |
96 CX_DEBUG_EXIT_FUNCTION(); |
270 cSelect->SetRequiredRecordFormatSupportL(*fSelect); |
97 } |
271 cSelect->SetPreferredSupplierL(supplierTPtr, |
98 |
272 CMMFPluginSelectionParameters::EOnlyPreferredSupplierPluginsReturned); |
99 void CxeVideoRecorderUtilitySymbian::Close() |
273 cSelect->ListImplementationsL(controllers); |
100 { |
274 CleanupResetAndDestroyPushL(controllers); |
101 CX_DEBUG_ENTER_FUNCTION(); |
275 |
102 mVideoRecorder->Close(); |
276 if (controllers.Count() <= 0) { |
103 CX_DEBUG_EXIT_FUNCTION(); |
277 CX_DEBUG(("CxeVideoRecorderUtilitySymbian - zero controllers found, leaving!")); |
104 } |
278 User::Leave(KErrNotFound); |
105 |
279 } |
106 void CxeVideoRecorderUtilitySymbian::Prepare() |
280 |
107 { |
281 // Inquires the controller about supported formats. |
108 CX_DEBUG_ENTER_FUNCTION(); |
282 // We use the first controller found having index 0. |
109 mVideoRecorder->Prepare(); |
283 const RMMFFormatImplInfoArray& formats = controllers[0]->RecordFormats(); |
110 CX_DEBUG_EXIT_FUNCTION(); |
284 |
111 } |
285 // Get the first format that supports our mime type. |
112 |
286 int count(formats.Count()); |
113 void CxeVideoRecorderUtilitySymbian::Record() |
287 for (int i=0; i<count; i++) { |
114 { |
288 if (formats[i]->SupportsMimeType(mimeTPtr)) { |
115 CX_DEBUG_ENTER_FUNCTION(); |
289 CX_DEBUG(("CxeVideoRecorderUtilitySymbian - found controller")); |
116 mVideoRecorder->Record(); |
290 // Store the format UID |
117 CX_DEBUG_EXIT_FUNCTION(); |
291 formatId = formats[i]->Uid(); |
118 } |
292 // Store the controller UID |
119 |
293 controllerId = controllers[0]->Uid(); |
120 int CxeVideoRecorderUtilitySymbian::Stop() |
294 break; |
121 { |
295 } |
122 CX_DEBUG_IN_FUNCTION(); |
296 } |
123 return mVideoRecorder->Stop(); |
297 |
124 } |
298 // Check that we found the uids. |
125 |
299 if (controllerId == KNullUid) { |
126 void CxeVideoRecorderUtilitySymbian::PauseL() |
300 CX_DEBUG(("CxeVideoRecorderUtilitySymbian - no matching controller found, leaving!")); |
127 { |
301 User::Leave(KErrNotFound); |
128 CX_DEBUG_ENTER_FUNCTION(); |
302 } |
129 mVideoRecorder->PauseL(); |
303 |
130 CX_DEBUG_EXIT_FUNCTION(); |
304 CleanupStack::PopAndDestroy(3); // controllers, fSelect, cSelect |
131 } |
305 CX_DEBUG_EXIT_FUNCTION(); |
132 |
306 } |
133 TTimeIntervalMicroSeconds CxeVideoRecorderUtilitySymbian::RecordTimeAvailable() |
307 |
134 { |
308 /*! |
135 CX_DEBUG_IN_FUNCTION(); |
309 * Helper method to convert QString to TFourCC. |
136 return mVideoRecorder->RecordTimeAvailable(); |
310 * @param str String to convert. |
137 } |
311 */ |
138 |
312 TFourCC CxeVideoRecorderUtilitySymbian::audioFourCC(const QString& str) |
139 TTimeIntervalMicroSeconds CxeVideoRecorderUtilitySymbian::DurationL() |
313 { |
140 { |
314 CX_DEBUG_ENTER_FUNCTION(); |
141 CX_DEBUG_IN_FUNCTION(); |
315 |
142 return mVideoRecorder->DurationL(); |
316 QByteArray audioType = str.toAscii(); |
143 } |
317 |
144 |
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 } |
145 |
336 |
146 |
337 |
147 // end of file |
338 // end of file |