1 /* |
|
2 * Copyright (c) 2009-2010 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 #include "cxedummycamera.h" |
|
19 |
|
20 #if defined(CXE_USE_DUMMY_CAMERA) || defined(__WINSCW__) |
|
21 |
|
22 #include <bitdev.h> |
|
23 |
|
24 #include "cxutils.h" |
|
25 |
|
26 // Disable warnings about unused arguments |
|
27 #pragma warn_unusedarg off |
|
28 |
|
29 namespace |
|
30 { |
|
31 static const TSize IMAGE_CAPTURE_SIZES[] = |
|
32 { |
|
33 TSize(4000,3000), |
|
34 TSize(4000,2248), |
|
35 TSize(3264,2448), |
|
36 TSize(3264,1832), |
|
37 TSize(2592,1944), |
|
38 TSize(2592,1456), |
|
39 TSize(2048,1536), |
|
40 TSize(1600,1200), |
|
41 TSize(1280,960), |
|
42 TSize(1024,768), |
|
43 TSize(640,480) |
|
44 }; |
|
45 static const int IMAGE_CAPTURE_SIZE_COUNT = sizeof(IMAGE_CAPTURE_SIZES)/sizeof(TSize); |
|
46 |
|
47 _LIT( PANICDUMMYCAMERA, "DummyCamera" ); |
|
48 } |
|
49 |
|
50 |
|
51 CxeDummyCamera* CxeDummyCamera::NewL(MCameraObserver2& aObserver,TInt aCameraIndex,TInt aPriority, TInt aCameraVersion) |
|
52 { |
|
53 return new (ELeave) CxeDummyCamera( aObserver, aCameraIndex, aPriority, aCameraVersion ); |
|
54 } |
|
55 |
|
56 |
|
57 CxeDummyCamera::CxeDummyCamera(MCameraObserver2& aObserver,TInt aCameraIndex,TInt aPriority, TInt aCameraVersion) |
|
58 : iObserver( aObserver ), iAdvancedSettings(0), iSnapshot(0), iStillImage(0), iImageProcessing(0) |
|
59 { |
|
60 iCommandTimer = CPeriodic::NewL(0); |
|
61 |
|
62 iInfo.iMaxZoom = 5; |
|
63 iInfo.iMaxDigitalZoom = 5; |
|
64 iInfo.iMaxDigitalZoomFactor = 0; |
|
65 iInfo.iMaxZoomFactor = 0; |
|
66 iInfo.iMinZoomFactor = 0; |
|
67 iInfo.iMinZoom = 0; |
|
68 |
|
69 iInfo.iNumImageSizesSupported = IMAGE_CAPTURE_SIZE_COUNT; |
|
70 } |
|
71 |
|
72 CxeDummyCamera::~CxeDummyCamera() |
|
73 { |
|
74 delete iCommandTimer; |
|
75 delete iAdvancedSettings; |
|
76 delete iSnapshot; |
|
77 delete iStillImage; |
|
78 delete iImageProcessing; |
|
79 } |
|
80 |
|
81 void CxeDummyCamera::doCommand( TCxeDummyCommand aCmd ) |
|
82 { |
|
83 TInt status = iCommandBuf.Insert( aCmd, 0 ); |
|
84 if ( status != KErrNone ) |
|
85 { |
|
86 User::Panic(PANICDUMMYCAMERA, 1); |
|
87 } |
|
88 if ( !iCommandTimer->IsActive() ) |
|
89 { |
|
90 iCommandTimer->Start(100, 100, TCallBack(CxeDummyCamera::callBack, this)); |
|
91 } |
|
92 } |
|
93 |
|
94 TInt CxeDummyCamera::callBack( TAny* aParam ) |
|
95 { |
|
96 CxeDummyCamera* self = (CxeDummyCamera*)aParam; |
|
97 return self->doHandleCallback(); |
|
98 } |
|
99 |
|
100 void CxeDummyCamera::CaptureImage() |
|
101 { |
|
102 doCommand( EProvideStillImage ); |
|
103 |
|
104 if ( iSnapshot && iSnapshot->IsSnapshotActive() ) |
|
105 { |
|
106 doCommand( EProvideSnapshot ); |
|
107 } |
|
108 } |
|
109 |
|
110 void CxeDummyCamera::EnumerateCaptureSizes(TSize& aSize,TInt aSizeIndex,TFormat aFormat) const |
|
111 { |
|
112 if(aSizeIndex < IMAGE_CAPTURE_SIZE_COUNT) |
|
113 { |
|
114 aSize = IMAGE_CAPTURE_SIZES[aSizeIndex]; |
|
115 } |
|
116 else |
|
117 { |
|
118 aSize = TSize(0,0); |
|
119 } |
|
120 } |
|
121 |
|
122 TInt CxeDummyCamera::doHandleCallback() |
|
123 { |
|
124 TCxeDummyCommand cmd = iCommandBuf[ 0 ]; |
|
125 iCommandBuf.Remove( 0 ); |
|
126 |
|
127 switch ( cmd ) |
|
128 { |
|
129 case EReserve: |
|
130 { |
|
131 iState = EStReserved; |
|
132 TECAMEvent e( KUidECamEventReserveComplete, KErrNone ); |
|
133 iObserver.HandleEvent( e ); |
|
134 break; |
|
135 } |
|
136 case EPowerOn: |
|
137 { |
|
138 iState = EStPowerOn; |
|
139 TECAMEvent e( KUidECamEventPowerOnComplete, KErrNone ); |
|
140 iObserver.HandleEvent( e ); |
|
141 break; |
|
142 } |
|
143 case EProvideStillImage: |
|
144 { |
|
145 if ( !iStillImage ) |
|
146 { |
|
147 iStillImage = new (ELeave) CxeDummyBuffer(); |
|
148 } |
|
149 iObserver.ImageBufferReady(*iStillImage, KErrNone); |
|
150 break; |
|
151 } |
|
152 case EProvideSnapshot: |
|
153 { |
|
154 TECAMEvent e( KUidECamEventCameraSnapshot, KErrNone ); |
|
155 iObserver.HandleEvent( e ); |
|
156 break; |
|
157 } |
|
158 } |
|
159 |
|
160 if ( !iCommandBuf.Count() ) |
|
161 { |
|
162 iCommandTimer->Cancel(); |
|
163 } |
|
164 |
|
165 return KErrNone; |
|
166 } |
|
167 |
|
168 void CxeDummyCamera::Reserve() |
|
169 { |
|
170 CX_DEBUG_ENTER_FUNCTION(); |
|
171 iState = EStReserving; |
|
172 doCommand( EReserve ); |
|
173 CX_DEBUG_EXIT_FUNCTION(); |
|
174 } |
|
175 |
|
176 void CxeDummyCamera::Release() |
|
177 { |
|
178 CX_DEBUG_ENTER_FUNCTION(); |
|
179 iState = EStReleased; |
|
180 CX_DEBUG_EXIT_FUNCTION(); |
|
181 } |
|
182 |
|
183 void CxeDummyCamera::PowerOn() |
|
184 { |
|
185 iState = EStPoweringOn; |
|
186 doCommand( EPowerOn ); |
|
187 } |
|
188 |
|
189 void CxeDummyCamera::PowerOff() |
|
190 { |
|
191 iState = EStReserved; |
|
192 } |
|
193 |
|
194 TAny* CxeDummyCamera::CustomInterface(TUid aInterface) |
|
195 { |
|
196 CX_DEBUG_ENTER_FUNCTION(); |
|
197 CX_DEBUG(("CxeDummyCamera::CustomInterface: request for interface uid %x", aInterface)); |
|
198 |
|
199 if ( aInterface == KECamMCameraAdvancedSettingsUid ) |
|
200 { |
|
201 CX_DEBUG(("Advanced settings custom interface requested")); |
|
202 if ( !iAdvancedSettings ) |
|
203 { |
|
204 iAdvancedSettings = new ( ELeave ) CxeDummyAdvancedSettings(this); |
|
205 } |
|
206 CX_DEBUG_EXIT_FUNCTION(); |
|
207 return static_cast<MCameraAdvancedSettings*>( iAdvancedSettings ); |
|
208 } |
|
209 else if (aInterface == KECamMCameraAdvancedSettings3Uid) |
|
210 { |
|
211 CX_DEBUG(("Advanced settings 3 custom interface requested")); |
|
212 if (!iAdvancedSettings) |
|
213 { |
|
214 iAdvancedSettings = new (ELeave) CxeDummyAdvancedSettings(this); |
|
215 } |
|
216 CX_DEBUG_EXIT_FUNCTION(); |
|
217 return static_cast<MCameraAdvancedSettings3*> (iAdvancedSettings); |
|
218 } |
|
219 else if ( aInterface == KECamMCameraSnapshotUid ) |
|
220 { |
|
221 CX_DEBUG(("Snapshot custom interface requested")); |
|
222 if ( !iSnapshot ) |
|
223 { |
|
224 iSnapshot = new ( ELeave ) CxeDummySnapshot(); |
|
225 } |
|
226 CX_DEBUG_EXIT_FUNCTION(); |
|
227 return static_cast<MCameraSnapshot*>( iSnapshot ); |
|
228 } |
|
229 else if ( aInterface == KECamMCameraDirectViewFinderUid ) |
|
230 { |
|
231 CX_DEBUG(("Direct viewfinder custom interface requested")); |
|
232 if( !iDirectViewfinder ) |
|
233 { |
|
234 iDirectViewfinder = new ( ELeave ) CxeDummyDirectViewfinder(); |
|
235 } |
|
236 return static_cast<MCameraDirectViewFinder*>( iDirectViewfinder ); |
|
237 } |
|
238 else if ( aInterface == KECamMCameraImageProcessingUid ) |
|
239 { |
|
240 CX_DEBUG(("Image processing custom interface requested")); |
|
241 if (!iImageProcessing ) |
|
242 { |
|
243 iImageProcessing = new ( ELeave ) CxeDummyImageProcessing; |
|
244 } |
|
245 return static_cast<MCameraImageProcessing*>( iImageProcessing ); |
|
246 } |
|
247 CX_DEBUG_EXIT_FUNCTION(); |
|
248 return NULL; |
|
249 } |
|
250 |
|
251 |
|
252 void CxeDummyBuffer::CreateBitmapL( const TSize& aSize ) |
|
253 { |
|
254 CX_DEBUG_ENTER_FUNCTION(); |
|
255 |
|
256 delete iBitmap; |
|
257 iBitmap = NULL; |
|
258 |
|
259 iBitmap = new (ELeave) CFbsBitmap(); |
|
260 User::LeaveIfError( iBitmap->Create( aSize, EColor16MU ) ); |
|
261 CFbsBitmapDevice* device = CFbsBitmapDevice::NewL( iBitmap ); |
|
262 CleanupStack::PushL( device ); |
|
263 CFbsBitGc* gc; |
|
264 User::LeaveIfError( device->CreateContext(gc) ); |
|
265 CleanupStack::PushL(gc); |
|
266 |
|
267 const TInt gridsize = 16; |
|
268 |
|
269 gc->SetPenStyle( CGraphicsContext::ENullPen ); |
|
270 gc->SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
271 |
|
272 for ( TInt x = 0; x < aSize.iWidth/16; x++ ) |
|
273 { |
|
274 for ( TInt y = 0; y < aSize.iWidth/16; y++ ) |
|
275 { |
|
276 gc->SetBrushColor( ( ( x + y ) & 1 ) ? 0x00AAAAAA : 0x00888888 ); |
|
277 gc->DrawRect( TRect( TPoint( x * 16, y * 16 ), TSize( gridsize, gridsize ) ) ); |
|
278 } |
|
279 } |
|
280 |
|
281 CleanupStack::PopAndDestroy(gc); |
|
282 CleanupStack::PopAndDestroy(device); |
|
283 |
|
284 CX_DEBUG_EXIT_FUNCTION(); |
|
285 } |
|
286 |
|
287 void CxeDummySnapshot::PrepareSnapshotL(CCamera::TFormat aFormat, const TPoint& aPosition, const TSize& aSize, const TRgb& aBgColor, TBool aMaintainAspectRatio) |
|
288 { |
|
289 CX_DEBUG_ENTER_FUNCTION(); |
|
290 PrepareSnapshotL( aFormat, aSize, aMaintainAspectRatio ); |
|
291 CX_DEBUG_EXIT_FUNCTION(); |
|
292 } |
|
293 |
|
294 void CxeDummySnapshot::PrepareSnapshotL(CCamera::TFormat aFormat, const TSize& aSize, TBool aMaintainAspectRatio) |
|
295 { |
|
296 CX_DEBUG_ENTER_FUNCTION(); |
|
297 if ( !iBuffer ) |
|
298 { |
|
299 iBuffer = new ( ELeave ) CxeDummyBuffer(); |
|
300 } |
|
301 iBuffer->CreateBitmapL( aSize ); |
|
302 CX_DEBUG_EXIT_FUNCTION(); |
|
303 } |
|
304 |
|
305 |
|
306 // CxeDummyDirectViewfinder |
|
307 |
|
308 CxeDummyDirectViewfinder::CxeDummyDirectViewfinder() |
|
309 : iState(CCamera::CCameraDirectViewFinder::EViewFinderInActive) |
|
310 { |
|
311 CX_DEBUG_IN_FUNCTION(); |
|
312 } |
|
313 |
|
314 CxeDummyDirectViewfinder::~CxeDummyDirectViewfinder() |
|
315 { |
|
316 CX_DEBUG_ENTER_FUNCTION(); |
|
317 CX_DEBUG_EXIT_FUNCTION(); |
|
318 } |
|
319 |
|
320 void CxeDummyDirectViewfinder::Release() |
|
321 { |
|
322 iState = CCamera::CCameraDirectViewFinder::EViewFinderInActive; |
|
323 } |
|
324 |
|
325 void CxeDummyDirectViewfinder::PauseViewFinderDirectL() |
|
326 { |
|
327 if( iState != CCamera::CCameraDirectViewFinder::EViewFinderActive ) |
|
328 { |
|
329 User::Leave( KErrGeneral ); |
|
330 } |
|
331 iState = CCamera::CCameraDirectViewFinder::EViewFinderPause; |
|
332 } |
|
333 |
|
334 void CxeDummyDirectViewfinder::ResumeViewFinderDirectL() |
|
335 { |
|
336 if( iState != CCamera::CCameraDirectViewFinder::EViewFinderPause ) |
|
337 { |
|
338 User::Leave( KErrGeneral ); |
|
339 } |
|
340 iState = CCamera::CCameraDirectViewFinder::EViewFinderActive; |
|
341 } |
|
342 |
|
343 CCamera::CCameraDirectViewFinder::TViewFinderState CxeDummyDirectViewfinder::ViewFinderState() const |
|
344 { |
|
345 return iState; |
|
346 } |
|
347 |
|
348 |
|
349 // CxeDummyAdvancedSettings |
|
350 |
|
351 CxeDummyAdvancedSettings::CxeDummyAdvancedSettings(CCamera* aCamera) |
|
352 : iCamera( aCamera ) |
|
353 { |
|
354 QT_TRANSLATE_SYMBIAN_LEAVE_TO_EXCEPTION(iNotificationTimer = CPeriodic::NewL(0)); |
|
355 iZoomValue = 0; |
|
356 } |
|
357 |
|
358 CxeDummyAdvancedSettings::~CxeDummyAdvancedSettings() |
|
359 { |
|
360 delete iNotificationTimer; |
|
361 iNotificationTimer = NULL; |
|
362 |
|
363 iClientNofications.Reset(); |
|
364 iClientNofications.Close(); |
|
365 } |
|
366 |
|
367 void CxeDummyAdvancedSettings::GetDigitalZoomStepsForStillL(RArray<TInt>& aDigitalZoomSteps, TValueInfo& aInfo, TInt aSizeIndex, |
|
368 CCamera::TFormat aFormat, TBool& aIsInfluencePossible) const |
|
369 { |
|
370 |
|
371 aDigitalZoomSteps.Reset(); |
|
372 aDigitalZoomSteps.AppendL(0); |
|
373 aDigitalZoomSteps.AppendL(1); |
|
374 aDigitalZoomSteps.AppendL(2); |
|
375 aDigitalZoomSteps.AppendL(3); |
|
376 aDigitalZoomSteps.AppendL(4); |
|
377 aDigitalZoomSteps.AppendL(5); |
|
378 |
|
379 } |
|
380 |
|
381 void CxeDummyAdvancedSettings::GetDigitalZoomStepsL(RArray<TInt>& aDigitalZoomSteps, TValueInfo& aInfo) const |
|
382 { |
|
383 aDigitalZoomSteps.Reset(); |
|
384 aDigitalZoomSteps.AppendL(0); |
|
385 aDigitalZoomSteps.AppendL(1); |
|
386 aDigitalZoomSteps.AppendL(2); |
|
387 aDigitalZoomSteps.AppendL(3); |
|
388 aDigitalZoomSteps.AppendL(4); |
|
389 aDigitalZoomSteps.AppendL(5); |
|
390 } |
|
391 |
|
392 |
|
393 TInt CxeDummyAdvancedSettings::SupportedFocusModes() const |
|
394 { |
|
395 return CCamera::CCameraAdvancedSettings::EFocusModeAuto; |
|
396 } |
|
397 |
|
398 CCamera::CCameraAdvancedSettings::TFocusMode CxeDummyAdvancedSettings::FocusMode() const |
|
399 { |
|
400 return iFocusMode; |
|
401 } |
|
402 |
|
403 void CxeDummyAdvancedSettings::SetFocusMode(CCamera::CCameraAdvancedSettings::TFocusMode aFocusMode) |
|
404 { |
|
405 iFocusMode = aFocusMode; |
|
406 |
|
407 // notify client with relevant event.. |
|
408 queueClientNotification(KUidECamEventCameraSettingFocusMode, KErrNone); |
|
409 } |
|
410 |
|
411 TInt CxeDummyAdvancedSettings::SupportedFocusRanges() const |
|
412 { |
|
413 return CCamera::CCameraAdvancedSettings::EFocusRangeAuto |
|
414 | CCamera::CCameraAdvancedSettings::EFocusRangeHyperfocal |
|
415 | CCamera::CCameraAdvancedSettings::EFocusRangeInfinite |
|
416 | CCamera::CCameraAdvancedSettings::EFocusRangeMacro |
|
417 | CCamera::CCameraAdvancedSettings::EFocusRangeNormal |
|
418 | CCamera::CCameraAdvancedSettings::EFocusRangePortrait |
|
419 | CCamera::CCameraAdvancedSettings::EFocusRangeSuperMacro |
|
420 | CCamera::CCameraAdvancedSettings::EFocusRangeTele; |
|
421 } |
|
422 |
|
423 CCamera::CCameraAdvancedSettings::TFocusRange CxeDummyAdvancedSettings::FocusRange() const |
|
424 { |
|
425 return iFocusRange; |
|
426 } |
|
427 |
|
428 void CxeDummyAdvancedSettings::SetFocusRange(CCamera::CCameraAdvancedSettings::TFocusRange aFocusRange) |
|
429 { |
|
430 iFocusRange = aFocusRange; |
|
431 queueClientNotification(KUidECamEventCameraSettingFocusRange2, KErrNone); |
|
432 } |
|
433 |
|
434 TInt CxeDummyAdvancedSettings::SupportedAutoFocusTypes() const |
|
435 { |
|
436 return CCamera::CCameraAdvancedSettings::EAutoFocusTypeSingle |
|
437 | CCamera::CCameraAdvancedSettings::EAutoFocusTypeOff; |
|
438 } |
|
439 |
|
440 CCamera::CCameraAdvancedSettings::TAutoFocusType CxeDummyAdvancedSettings::AutoFocusType() const |
|
441 { |
|
442 return iFocusType; |
|
443 } |
|
444 |
|
445 void CxeDummyAdvancedSettings::SetAutoFocusType(CCamera::CCameraAdvancedSettings::TAutoFocusType aAutoFocusType) |
|
446 { |
|
447 iFocusType = aAutoFocusType; |
|
448 queueClientNotification(KUidECamEventCameraSettingAutoFocusType2, KErrNone); |
|
449 |
|
450 // If AF set to OFF, remove any "optimal focus" events from earlier |
|
451 // started focusing. |
|
452 if (iFocusType == CCamera::CCameraAdvancedSettings::EAutoFocusTypeOff) { |
|
453 for (TInt i = iClientNofications.Count()-1; i >= 0; i--) { |
|
454 if (iClientNofications[i].iEventUid == KUidECamEventCameraSettingsOptimalFocus) { |
|
455 iClientNofications.Remove(i); |
|
456 } |
|
457 } |
|
458 } |
|
459 else { |
|
460 // Otherwise queue optimal focus event for this focusing request. |
|
461 queueClientNotification(KUidECamEventCameraSettingsOptimalFocus, KErrNone); |
|
462 } |
|
463 } |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 void CxeDummyAdvancedSettings::queueClientNotification(TUid aUid, TInt aStatus) |
|
473 { |
|
474 CX_DEBUG_ENTER_FUNCTION(); |
|
475 iClientNofications.Append(TCxeDummyNotification(aUid,aStatus)); |
|
476 if (iNotificationTimer == NULL) { |
|
477 QT_TRANSLATE_SYMBIAN_LEAVE_TO_EXCEPTION(iNotificationTimer = CPeriodic::NewL(0)); |
|
478 } |
|
479 |
|
480 if (!iNotificationTimer->IsActive()) { |
|
481 TCallBack cb(CxeDummyAdvancedSettings::clientNotificationCallback, this); |
|
482 iNotificationTimer->Start(100, 100, cb); |
|
483 } |
|
484 CX_DEBUG_EXIT_FUNCTION(); |
|
485 } |
|
486 |
|
487 void CxeDummyAdvancedSettings::doClientNotification( ) |
|
488 { |
|
489 CX_DEBUG_ENTER_FUNCTION(); |
|
490 const TInt count(iClientNofications.Count()); |
|
491 |
|
492 if (count != 0) { |
|
493 const TCxeDummyNotification& notify(iClientNofications[count-1]); |
|
494 const TECAMEvent event(notify.iEventUid, notify.iStatus); |
|
495 iClientNofications.Remove(count-1); |
|
496 (static_cast<CxeDummyCamera*>(iCamera))->iObserver.HandleEvent(event); |
|
497 } |
|
498 else { |
|
499 delete iNotificationTimer; |
|
500 iNotificationTimer = NULL; |
|
501 } |
|
502 CX_DEBUG_EXIT_FUNCTION(); |
|
503 } |
|
504 |
|
505 TInt CxeDummyAdvancedSettings::clientNotificationCallback(TAny* aParam) |
|
506 { |
|
507 (static_cast<CxeDummyAdvancedSettings*>(aParam))->doClientNotification(); |
|
508 return 1; // Not used by CPeriodic |
|
509 } |
|
510 |
|
511 |
|
512 #endif // defined(CXE_USE_DUMMY_CAMERA) || defined(__WINSCW__) |
|