|
1 /* |
|
2 * Copyright (c) 2006 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 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <e32def.h> |
|
23 #include <CCMRMediaRecorder.h> |
|
24 |
|
25 #include "mccvideosourcewrapper.h" |
|
26 #include "mccvideosourcesinklogs.h" |
|
27 |
|
28 #define VIDEO_SOURCE_ASSERT_READINESS \ |
|
29 __ASSERT_ALWAYS( iMediaRecorder && !iFatalErrorOccured, User::Leave( KErrNotReady ) ); |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS =============================== |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CMccVideoSourceWrapper::NewL |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CMccVideoSourceWrapper* CMccVideoSourceWrapper::NewL( |
|
38 MCMRMediaSink& aObserver, |
|
39 MCMRMediaRecorderObserver& aObserver2 ) |
|
40 { |
|
41 CMccVideoSourceWrapper* self = new ( ELeave ) CMccVideoSourceWrapper( |
|
42 aObserver, aObserver2 ); |
|
43 CleanupStack::PushL( self ); |
|
44 self->ConstructL(); |
|
45 CleanupStack::Pop( self ); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CMccVideoSourceWrapper::ConstructL |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 void CMccVideoSourceWrapper::ConstructL() |
|
54 { |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CMccVideoSourceWrapper::CMccVideoSourceWrapper |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 CMccVideoSourceWrapper::CMccVideoSourceWrapper( |
|
62 MCMRMediaSink& aObserver, |
|
63 MCMRMediaRecorderObserver& aObserver2 ) |
|
64 : iObserver( aObserver ), iObserver2( aObserver2 ) |
|
65 { |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CMccVideoSourceWrapper::~CMccVideoSourceWrapper |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CMccVideoSourceWrapper::~CMccVideoSourceWrapper() |
|
73 { |
|
74 if ( iMediaRecorder && |
|
75 !iFatalErrorOccured && |
|
76 iMediaRecorder->State() == CCMRMediaRecorder::EStateRecording ) |
|
77 { |
|
78 TRAP_IGNORE( StopL() ) |
|
79 } |
|
80 delete iMediaRecorder; |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CMccVideoSourceWrapper::OpenL |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 void CMccVideoSourceWrapper::OpenL( |
|
88 MDataSource* aAudioSource, |
|
89 TInt aCameraHandle, |
|
90 const TDesC8& aVideoMimeType, |
|
91 TFourCC aAudioType, |
|
92 TUid aEncoderUid ) |
|
93 { |
|
94 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::OpenL" ) |
|
95 |
|
96 __ASSERT_ALWAYS( !iMediaRecorder, User::Leave( KErrAlreadyExists ) ); |
|
97 iMediaRecorder = CCMRMediaRecorder::NewL(); |
|
98 |
|
99 iFatalErrorOccured = EFalse; |
|
100 |
|
101 iMediaRecorder->OpenL( this, aAudioSource, this, aCameraHandle, |
|
102 aVideoMimeType, aAudioType ) ; |
|
103 iMediaRecorder->SetAudioEnabledL( EFalse ); |
|
104 |
|
105 if ( iMediaRecorder->State() == CCMRMediaRecorder::EStateOpen ) |
|
106 { |
|
107 if ( aEncoderUid != KNullUid ) |
|
108 { |
|
109 __V_SOURCESINK_CONTROLL_INT1( "SetPreferredVideoEncoderL, uid:", |
|
110 aEncoderUid.iUid ) |
|
111 iMediaRecorder->SetPreferredVideoEncoderL( aEncoderUid ); |
|
112 __V_SOURCESINK_CONTROLL( "SetPreferredVideoEncapsulationL" ) |
|
113 iMediaRecorder->SetPreferredVideoEncapsulationL( EDuElementaryStream ); |
|
114 } |
|
115 |
|
116 __V_SOURCESINK_CONTROLL( "SetVideoCodingOptionsL" ) |
|
117 //set mediarecorder to insert GOB:s |
|
118 TCCMRVideoCodingOptions CodingOptions; |
|
119 CodingOptions.iSyncIntervalInPicture = 1; |
|
120 CodingOptions.iMinRandomAccessPeriodInSeconds = KIPULRandomAccessPeriod; |
|
121 iMediaRecorder->SetVideoCodingOptionsL( CodingOptions ); |
|
122 |
|
123 __V_SOURCESINK_CONTROLL( "PrepareL" ) |
|
124 iMediaRecorder->PrepareL(); |
|
125 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper, \ |
|
126 preparing recorder success" ) |
|
127 } |
|
128 else |
|
129 { |
|
130 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper, \ |
|
131 opening recorder success, waiting" ) |
|
132 } |
|
133 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::OpenL, exit" ) |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CMccVideoSourceWrapper::PlayL() |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 void CMccVideoSourceWrapper::PlayL() |
|
141 { |
|
142 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::SourcePlayL" ) |
|
143 |
|
144 VIDEO_SOURCE_ASSERT_READINESS |
|
145 iMediaRecorder->RecordL(); |
|
146 |
|
147 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::SourcePlayL, exit" ) |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CMccVideoSourceWrapper::ResumeL() |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 void CMccVideoSourceWrapper::ResumeL() |
|
155 { |
|
156 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::ResumeL" ) |
|
157 |
|
158 VIDEO_SOURCE_ASSERT_READINESS |
|
159 iMediaRecorder->ResumeL(); |
|
160 |
|
161 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::ResumeL, exit" ) |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CMccVideoSourceWrapper::PauseL() |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 void CMccVideoSourceWrapper::PauseL() |
|
169 { |
|
170 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::SourcePauseL") |
|
171 |
|
172 VIDEO_SOURCE_ASSERT_READINESS |
|
173 iMediaRecorder->PauseL(); |
|
174 |
|
175 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::SourcePauseL, exit") |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CMccVideoSourceWrapper::StopL() |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 void CMccVideoSourceWrapper::StopL() |
|
183 { |
|
184 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::SourceStopL" ) |
|
185 |
|
186 if ( iMediaRecorder && !iFatalErrorOccured ) |
|
187 { |
|
188 iMediaRecorder->StopL(); |
|
189 } |
|
190 |
|
191 // Delete the recorder in order to free camera resources |
|
192 delete iMediaRecorder; |
|
193 iMediaRecorder = 0; |
|
194 |
|
195 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::SourceStopL, exit" ) |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CMccVideoSourceWrapper::GetVideoBitrate() |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 TUint CMccVideoSourceWrapper::GetVideoBitrateL() |
|
203 { |
|
204 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::SetVideoBitrateL" ) |
|
205 |
|
206 VIDEO_SOURCE_ASSERT_READINESS |
|
207 return iMediaRecorder->VideoBitRateL(); |
|
208 } |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // CMccVideoSourceWrapper::SetVideoBitrateL() |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 void CMccVideoSourceWrapper::SetVideoBitrateL( TUint aVideoBitRate ) |
|
215 { |
|
216 __V_SOURCESINK_CONTROLL_INT1( "CMccVideoSourceWrapper::SetVideoBitrateL", aVideoBitRate ) |
|
217 |
|
218 VIDEO_SOURCE_ASSERT_READINESS |
|
219 iMediaRecorder->SetVideoBitRateL( aVideoBitRate ); |
|
220 |
|
221 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::SetVideoBitrateL, exit" ) |
|
222 } |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // CMccVideoSourceWrapper::SetVideoFrameRateL() |
|
226 // ----------------------------------------------------------------------------- |
|
227 // |
|
228 void CMccVideoSourceWrapper::SetVideoFrameRateL( TReal32 aFramesPerSecond ) |
|
229 { |
|
230 __V_SOURCESINK_CONTROLL_REAL( "CMccVideoSourceWrapper::SetVideoFrameRateL", |
|
231 aFramesPerSecond ) |
|
232 |
|
233 VIDEO_SOURCE_ASSERT_READINESS |
|
234 |
|
235 if ( aFramesPerSecond > 0 ) |
|
236 { |
|
237 iMediaRecorder->SetVideoFrameRateL( aFramesPerSecond ); |
|
238 } |
|
239 |
|
240 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::SetVideoFrameRateL, exit" ) |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CMccVideoSourceWrapper::SetVideoRateControlOptionsL() |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 void CMccVideoSourceWrapper::SetVideoRateControlOptionsL( const TRateControlOptions& aOptions ) |
|
248 { |
|
249 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::SetVideoRateControlOptionsL") |
|
250 |
|
251 VIDEO_SOURCE_ASSERT_READINESS |
|
252 iMediaRecorder->SetVideoRateControlOptionsL( aOptions ); |
|
253 |
|
254 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::SetVideoRateControlOptionsL, exit" ) |
|
255 } |
|
256 |
|
257 // ----------------------------------------------------------------------------- |
|
258 // CMccVideoSourceWrapper::GetVideoRateControlOptionsL() |
|
259 // ----------------------------------------------------------------------------- |
|
260 // |
|
261 void CMccVideoSourceWrapper::GetVideoRateControlOptionsL( TRateControlOptions& aOptions ) |
|
262 { |
|
263 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::GetVideoRateControlOptionsL") |
|
264 |
|
265 VIDEO_SOURCE_ASSERT_READINESS |
|
266 iMediaRecorder->GetVideoRateControlOptionsL( aOptions ); |
|
267 |
|
268 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::GetVideoRateControlOptionsL, exit" ) |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // CMccVideoSourceWrapper::SetVideoBitrateL() |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 CCMRMediaRecorder::TRecorderState CMccVideoSourceWrapper::State() |
|
276 { |
|
277 if ( iMediaRecorder && !iFatalErrorOccured ) |
|
278 { |
|
279 return iMediaRecorder->State(); |
|
280 } |
|
281 else |
|
282 { |
|
283 return CCMRMediaRecorder::EStateNone; |
|
284 } |
|
285 } |
|
286 |
|
287 // ----------------------------------------------------------------------------- |
|
288 // CMccVideoSourceWrapper::WriteBufferL() |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 void CMccVideoSourceWrapper::WriteBufferL( CCMRMediaBuffer* aBuffer ) |
|
292 { |
|
293 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::WriteBufferL" ) |
|
294 iObserver.WriteBufferL( aBuffer ); |
|
295 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::WriteBufferL, exit" ) |
|
296 } |
|
297 |
|
298 // ----------------------------------------------------------------------------- |
|
299 // CMccVideoSourceWrapper::SetVideoFrameSize() |
|
300 // ----------------------------------------------------------------------------- |
|
301 // |
|
302 TInt CMccVideoSourceWrapper::SetVideoFrameSize( TSize aSize ) |
|
303 { |
|
304 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::SetVideoFrameSize" ) |
|
305 return iObserver.SetVideoFrameSize( aSize ); |
|
306 } |
|
307 |
|
308 // ----------------------------------------------------------------------------- |
|
309 // CMccVideoSourceWrapper::SetAverageVideoBitRate() |
|
310 // ----------------------------------------------------------------------------- |
|
311 // |
|
312 TInt CMccVideoSourceWrapper::SetAverageVideoBitRate( TInt aBitRate ) |
|
313 { |
|
314 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::SetAverageVideoBitRate" ) |
|
315 return iObserver.SetAverageVideoBitRate( aBitRate ); |
|
316 } |
|
317 |
|
318 // ----------------------------------------------------------------------------- |
|
319 // CMccVideoSourceWrapper::SetMaxVideoBitRate() |
|
320 // ----------------------------------------------------------------------------- |
|
321 // |
|
322 TInt CMccVideoSourceWrapper::SetMaxVideoBitRate( TInt aBitRate ) |
|
323 { |
|
324 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::SetMaxVideoBitRate" ) |
|
325 return iObserver.SetMaxVideoBitRate( aBitRate ); |
|
326 } |
|
327 |
|
328 // ----------------------------------------------------------------------------- |
|
329 // CMccVideoSourceWrapper::SetAverageAudioBitRate() |
|
330 // ----------------------------------------------------------------------------- |
|
331 // |
|
332 TInt CMccVideoSourceWrapper::SetAverageAudioBitRate( TInt aBitRate ) |
|
333 { |
|
334 __V_SOURCESINK_CONTROLL( "CMccVideoSourceWrapper::SetAverageAudioBitRate" ) |
|
335 return iObserver.SetAverageAudioBitRate( aBitRate ); |
|
336 } |
|
337 |
|
338 // ----------------------------------------------------------------------------- |
|
339 // CMccVideoSourceWrapper::MmroPrepareComplete() |
|
340 // ----------------------------------------------------------------------------- |
|
341 // |
|
342 void CMccVideoSourceWrapper::MmroPrepareComplete( TInt aError ) |
|
343 { |
|
344 __V_SOURCESINK_CONTROLL_INT1( "CMccVideoSourceWrapper::MmroPrepareComplete=", |
|
345 aError ) |
|
346 iObserver2.MmroPrepareComplete( aError ); |
|
347 |
|
348 } |
|
349 |
|
350 // ----------------------------------------------------------------------------- |
|
351 // CMccVideoSourceWrapper::MmroStateChange() |
|
352 // ----------------------------------------------------------------------------- |
|
353 // |
|
354 void CMccVideoSourceWrapper::MmroStateChange( TInt aState, TInt aError ) |
|
355 { |
|
356 __V_SOURCESINK_CONTROLL_INT2( "CMccVideoSourceWrapper::MmroStateChange, \ |
|
357 aState=", aState, "aError=", aError ) |
|
358 |
|
359 if ( iMediaRecorder ) |
|
360 { |
|
361 __V_SOURCESINK_CONTROLL_INT1( "CMccVideoSourceWrapper, media recorder state:", |
|
362 iMediaRecorder->State() ) |
|
363 } |
|
364 |
|
365 iObserver2.MmroStateChange( aState, aError ); |
|
366 } |
|
367 |
|
368 // ----------------------------------------------------------------------------- |
|
369 // CMccVideoSourceWrapper::MmroTemporaryError() |
|
370 // ----------------------------------------------------------------------------- |
|
371 // |
|
372 void CMccVideoSourceWrapper::MmroTemporaryError( TInt aError ) |
|
373 { |
|
374 __V_SOURCESINK_CONTROLL_INT1( "CMccVideoSourceWrapper::MmroTemporaryError=", |
|
375 aError ) |
|
376 iObserver2.MmroTemporaryError( aError ); |
|
377 } |
|
378 |
|
379 // ----------------------------------------------------------------------------- |
|
380 // CMccVideoSourceWrapper::MmroFatalError() |
|
381 // ----------------------------------------------------------------------------- |
|
382 // |
|
383 void CMccVideoSourceWrapper::MmroFatalError( TInt aError ) |
|
384 { |
|
385 __V_SOURCESINK_CONTROLL_INT1( "CMccVideoSourceWrapper::MmroFatalError=", aError ) |
|
386 |
|
387 // Remember fatal error |
|
388 iFatalErrorOccured = ETrue; |
|
389 |
|
390 iObserver2.MmroFatalError( aError ); |
|
391 } |
|
392 |
|
393 |
|
394 |