Update contrib.
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 #include <ecom/ecom.h>
18 #include <ecom/implementationproxy.h>
20 #include "TestCamera.h"
21 #include "test_advanced_settings.h"
22 #include "test_snapshot.h"
23 #include "test_image_processing.h"
24 #include "TestCameraUids.hrh"
31 // 2nd stage ConstructL calls called by framework
33 CTestCamera* CTestCamera::NewL()
35 FileDependencyUtil::CheckFileDependencyL();
36 CTestCamera* self = new(ELeave) CTestCamera;
37 CleanupStack::PushL(self);
39 CleanupStack::Pop(self);
43 void CTestCamera::Construct2L(MCameraObserver& aObserver,TInt aCameraIndex)
45 iObserver = &aObserver;
46 iCameraIndex = aCameraIndex;
49 void CTestCamera::Construct2DupL(MCameraObserver& aObserver,TInt aCameraHandle)
51 iObserver = &aObserver;
52 iCameraHandle = aCameraHandle;
55 void CTestCamera::ConstructL()
59 TRAP(err, iScreenDev = CFbsScreenDevice::NewL(_L(""),EColor16MA));
60 if (err == KErrNotSupported)
62 TRAP(err, iScreenDev = CFbsScreenDevice::NewL(_L(""),EColor16M));
64 if (err == KErrNotSupported)
66 TRAP(err, iScreenDev = CFbsScreenDevice::NewL(_L(""),EColor64K));
68 if (err == KErrNotSupported)
70 TRAP(err, iScreenDev = CFbsScreenDevice::NewL(_L(""),EColor4K));
72 if (err == KErrNotSupported)
74 TRAP(err, iScreenDev = CFbsScreenDevice::NewL(_L(""),EColor256));
76 if (err == KErrNotSupported)
78 iScreenDev = CFbsScreenDevice::NewL(_L(""),EColor16MAP);
82 User::LeaveIfError(err);
85 User::LeaveIfError(iScreenDev->CreateContext(iScreenGc));
86 User::LeaveIfError(iImageSizes.Append( TSize(640, 480) )); // VGA
87 User::LeaveIfError(iImageSizes.Append( TSize(160, 120) )); // QQVGA
88 iInfo.iNumImageSizesSupported = iImageSizes.Count();
89 iStillImageSize = iImageSizes[1]; // Defaults to QQVGA
91 User::LeaveIfError(iVideoFrameSizes.Append( TSize(176, 144) )); // QCIF
92 User::LeaveIfError(iVideoFrameSizes.Append( TSize(128, 96) )); // subQCIF
93 iInfo.iNumVideoFrameSizesSupported = iVideoFrameSizes.Count();
94 User::LeaveIfError(iVideoFrameRates.Append( 10.00 ));
95 User::LeaveIfError(iVideoFrameRates.Append( 5.00 ));
96 User::LeaveIfError(iVideoFrameRates.Append( 1.00 ));
97 iInfo.iNumVideoFrameRatesSupported = iVideoFrameRates.Count();
98 iVideoFrameRate = iVideoFrameRates[0];
99 // Still image used as view finder source if not defined otherwise
100 iStillImage = new(ELeave) CFbsBitmap;
101 User::LeaveIfError(iStillImage->Create(iStillImageSize, KViewFinderDisplayMode));
102 iStillImageDev = CFbsBitmapDevice::NewL(iStillImage);
103 User::LeaveIfError(iStillImageDev->CreateContext(iStillImageGc));
104 iStillImageGc->SetPenColor(KRgbBlack);
105 iStillImageGc->SetPenSize(TSize(KFrameFeatureBorderThickness, KFrameFeatureBorderThickness));
106 iStillImageGc->SetBrushColor(KRgbWhite);
107 iStillImageGc->SetFaded(ETrue);
108 iVideoPreparedLast = EFalse;
109 iTimer = CPeriodic::NewL(CActive::EPriorityHigh);
113 void CTestCamera::Construct2L(MCameraObserver2& aObserver,TInt aCameraIndex,TInt aPriority)
115 iObserver2 = &aObserver;
116 iCameraIndex = aCameraIndex;
117 iPriority = aPriority;
120 void CTestCamera::Construct2DupL(MCameraObserver2& aObserver,TInt aCameraHandle)
122 iObserver2 = &aObserver;
123 iCameraHandle = aCameraHandle;
127 CTestCamera::CTestCamera():
128 iStillImageFormat(KInitialViewFinderFormat),
129 iReserveAsync(CActive::EPriorityStandard),
130 iPowerOnAsync(CActive::EPriorityStandard),
131 iImageCaptureAsync(CActive::EPriorityStandard),
132 iVideoCaptureAsync(CActive::EPriorityStandard),
133 iHandleEventAsync(CActive::EPriorityStandard),
134 iHandleEvent2Async(CActive::EPriorityStandard),
135 iFrameBuffer1(iVideoFrame1),
136 iFrameBuffer2(iVideoFrame2),
137 iFrameCameraBuffer1(iVideoFrame1),
138 iFrameCameraBuffer2(iVideoFrame2),
141 iImgProcBrightness(0),
143 iVideoCaptureActive(EFalse),
144 iImageCaptureActive(EFalse),
145 iVideoPreparedLast(EFalse),
146 iVideoCapturePrepared(EFalse),
147 iImageCapturePrepared(EFalse),
148 iECamEvent(KNullUid, KErrNone),
149 iECamEvent2(KNullUid, KErrNone, 0),
150 iAdvSettingsImpl(NULL),
153 iDriveMode(KDefaultDriveMode),
154 iBurstImages(KBurstImages)
156 TCallBack reserveCallBack(ReserveCallBack,this);
157 iReserveAsync.Set(reserveCallBack);
158 TCallBack powerOnCallBack(PowerOnCallBack,this);
159 iPowerOnAsync.Set(powerOnCallBack);
160 TCallBack imageCaptureCallBack(ImageCaptureCallBack,this);
161 iImageCaptureAsync.Set(imageCaptureCallBack);
162 TCallBack videoCaptureCallBack(VideoCaptureCallBack,this);
163 iVideoCaptureAsync.Set(videoCaptureCallBack);
164 TCallBack handleEventCallBack(HandleEventCallBack,this);
165 iHandleEventAsync.Set(handleEventCallBack);
166 TCallBack handleEvent2CallBack(HandleEvent2CallBack,this);
167 iHandleEvent2Async.Set(handleEvent2CallBack);
169 iInfo.iHardwareVersion.iMajor = 0;
170 iInfo.iHardwareVersion.iMinor = 0;
171 iInfo.iHardwareVersion.iBuild = 0;
172 iInfo.iSoftwareVersion.iMajor = 0;
173 iInfo.iSoftwareVersion.iMinor = 0;
174 iInfo.iSoftwareVersion.iBuild = 0;
175 iInfo.iOrientation = TCameraInfo::EOrientationOutwards;
177 iInfo.iOptionsSupported = 0;
178 iInfo.iOptionsSupported |= TCameraInfo::EViewFinderDirectSupported;
179 iInfo.iOptionsSupported |= TCameraInfo::EViewFinderBitmapsSupported;
180 iInfo.iOptionsSupported |= TCameraInfo::EImageCaptureSupported;
181 iInfo.iOptionsSupported |= TCameraInfo::EVideoCaptureSupported;
182 iInfo.iOptionsSupported |= TCameraInfo::EContrastSupported;
183 iInfo.iOptionsSupported |= TCameraInfo::EBrightnessSupported;
184 iInfo.iOptionsSupported |= TCameraInfo::EViewFinderClippingSupported;
186 iInfo.iFlashModesSupported = 0; // Bitfield of TFlash values
187 iInfo.iExposureModesSupported = 0; // Bitfield of TExposure values
188 iInfo.iWhiteBalanceModesSupported = 0; // Bitfield of TWhiteBalance values
190 iInfo.iMinZoom = KMinTestCameraZoom;
191 // KMinTestCameraZoom is zero or negative
192 // note the algorithm for creating of zoom factor
193 iInfo.iMinZoomFactor = TReal32(1)/TReal32(1 << -KMinTestCameraZoom);
194 iInfo.iMaxZoom = KMaxTestCameraZoom;
195 iInfo.iMaxZoomFactor = 1 << KMaxTestCameraZoom;
197 iInfo.iMaxDigitalZoom = KMaxTestCameraDigitalZoom;
198 iInfo.iMaxDigitalZoomFactor = KMaxTestCameraDigitalZoomFactor;
200 iInfo.iImageFormatsSupported = 0;
201 iInfo.iImageFormatsSupported |= EFormatFbsBitmapColor4K;
202 iInfo.iImageFormatsSupported |= EFormatFbsBitmapColor64K;
203 iInfo.iImageFormatsSupported |= EFormatFbsBitmapColor16M;
205 iInfo.iVideoFrameFormatsSupported = 0;
206 iInfo.iVideoFrameFormatsSupported |= EFormatFbsBitmapColor4K;
207 iInfo.iVideoFrameFormatsSupported |= EFormatFbsBitmapColor64K;
208 iInfo.iVideoFrameFormatsSupported |= EFormatFbsBitmapColor16M;
209 iInfo.iMaxFramesPerBufferSupported = 1;
210 iInfo.iMaxBuffersSupported = 2;
212 iScreenRect = TRect(TPoint(0,0), TPoint(0,0));
214 iEventError = KErrNone;
217 CTestCamera::~CTestCamera()
221 delete iStillImageGc;
222 delete iStillImageDev;
224 delete iVideoFrameGc1;
225 delete iVideoFrameDev1;
227 delete iVideoFrameGc2;
228 delete iVideoFrameDev2;
229 delete iViewFinderBitmapGc;
230 delete iViewFinderBitmapDev;
231 delete iViewFinderBitmap;
238 delete iAdvSettingsImpl;
239 delete iSnapshotImpl;
242 iVideoFrameSizes.Reset();
243 iVideoFrameRates.Reset();
246 void CTestCamera::CameraInfo(TCameraInfo& aInfo) const
251 void CTestCamera::Reserve()
254 iReserveAsync.CallBack();
257 void CTestCamera::Release()
263 void CTestCamera::PowerOn()
265 if (!iReserved || iPowerOn)
267 iPowerOnAsync.CallBack();
272 TCallBack callback(TimerCallBack,this);
273 iTimer->Start(0,TInt(TReal32(1000000) / iVideoFrameRate), callback);
274 iPowerOnAsync.CallBack();
277 void CTestCamera::PowerOff()
283 TInt CTestCamera::Handle()
288 void CTestCamera::SetZoomFactorL(TInt aZoomFactor)
290 // it is equivalent to comparing with iInfo members as they are initialised with the same constants
291 // if (aZoomFactor < iInfo.iMinZoom || aZoomFactor > iInfo.iMaxZoom)
292 if (aZoomFactor < KMinTestCameraZoom || aZoomFactor > KMaxTestCameraZoom)
294 User::Leave(KErrNotSupported);
300 TInt CTestCamera::ZoomFactor() const
302 // default value is 0
306 void CTestCamera::SetDigitalZoomFactorL(TInt aDigitalZoomFactor)
308 CheckReserveAndPowerL();
309 // it is equivalent to comparing with iInfo member as it is initialised with the same constant
310 // if (aDigitalZoomFactor < 0 || aDigitalZoomFactor > iInfo.iMaxDigitalZoom)
311 if (aDigitalZoomFactor < 0 || aDigitalZoomFactor > KMaxTestCameraDigitalZoom)
313 User::Leave(KErrNotSupported);
316 iDigitalZoom = aDigitalZoomFactor;
319 TInt CTestCamera::DigitalZoomFactor() const
321 // default value is 0
325 void CTestCamera::SetContrastL(TInt aContrast)
327 CheckReserveAndPowerL();
329 iContrast = Min(Max(aContrast,-100),100);
332 TInt CTestCamera::Contrast() const
337 void CTestCamera::SetBrightnessL(TInt aBrightness)
339 CheckReserveAndPowerL();
341 iBrightness = Min(Max(aBrightness,-100),100);
344 TInt CTestCamera::Brightness() const
349 void CTestCamera::SetFlashL(TFlash aFlash)
351 CheckReserveAndPowerL();
353 if (aFlash != EFlashNone)
355 User::Leave(KErrNotSupported);
359 CCamera::TFlash CTestCamera::Flash() const
364 void CTestCamera::SetExposureL(TExposure aExposure)
366 CheckReserveAndPowerL();
368 if (aExposure != EExposureAuto)
370 User::Leave(KErrNotSupported);
374 CCamera::TExposure CTestCamera::Exposure() const
376 return EExposureAuto;
379 void CTestCamera::SetWhiteBalanceL(TWhiteBalance aWhiteBalance)
381 CheckReserveAndPowerL();
383 if (aWhiteBalance != EWBAuto)
385 User::Leave(KErrNotSupported);
389 CCamera::TWhiteBalance CTestCamera::WhiteBalance() const
394 void CTestCamera::StartViewFinderDirectL(RWsSession& aWs,CWsScreenDevice& aScreenDevice,RWindowBase& aWindow,TRect& aScreenRect)
397 StartViewFinderDirectL(aWs,aScreenDevice,aWindow,aScreenRect,emptyRect);
400 void CTestCamera::StartViewFinderDirectL(RWsSession& aWs,CWsScreenDevice& aScreenDevice,RWindowBase& aWindow,TRect& aScreenRect,TRect& aClipRect)
404 User::Leave(KErrInUse);
407 if (!iPowerOn || iViewFinderActive)
409 User::Leave(KErrNotReady);
412 iScreenRect = aScreenRect;
413 iClipRect = aClipRect;
417 iViewFinderActive = EFalse;
418 iDSA = CDirectScreenAccess::NewL(aWs,aScreenDevice,aWindow,*this);
420 iViewFinderActive = ETrue;
421 iDSA->Gc()->SetOrigin(); // Set Origin to top left of screen (0,0)
423 if (!iClipRect.IsEmpty())
425 iDSA->Gc()->SetClippingRect(iClipRect);
429 void CTestCamera::StartViewFinderBitmapsL(TSize& aSize)
432 StartViewFinderBitmapsL(aSize,emptyRect);
435 void CTestCamera::StartViewFinderBitmapsL(TSize& aSize, TRect& aClipRect)
439 User::Leave(KErrInUse);
441 if (!iPowerOn || iViewFinderActive)
443 User::Leave(KErrNotReady);
446 iViewFinderActive = ETrue;
447 iScreenRect = TRect(TPoint(0,0), aSize);
448 iClipRect = aClipRect;
449 iClipRect.Intersection(iScreenRect);
451 delete iViewFinderBitmapGc;
452 iViewFinderBitmapGc = NULL;
453 delete iViewFinderBitmapDev;
454 iViewFinderBitmapDev = NULL;
455 delete iViewFinderBitmap;
456 iViewFinderBitmap = NULL;
458 iViewFinderBitmap = new(ELeave) CFbsBitmap;
459 if (!iClipRect.IsEmpty())
461 User::LeaveIfError(iViewFinderBitmap->Create(iClipRect.Size(), KViewFinderDisplayMode));
465 User::LeaveIfError(iViewFinderBitmap->Create(aSize, KViewFinderDisplayMode));
467 iViewFinderBitmapDev = CFbsBitmapDevice::NewL(iViewFinderBitmap);
468 User::LeaveIfError(iViewFinderBitmapDev->CreateContext(iViewFinderBitmapGc));
471 void CTestCamera::StartViewFinderL(TFormat aImageFormat,TSize& aSize)
474 StartViewFinderL(aImageFormat,aSize,emptyRect);
477 void CTestCamera::StartViewFinderL(TFormat aImageFormat,TSize& /*aSize*/,TRect& aClipRect)
481 User::Leave(KErrInUse);
483 if(!iPowerOn || iViewFinderActive)
485 User::Leave(KErrNotReady);
488 iViewFinderActive = ETrue;
489 iClipRect = aClipRect;
490 if(!(aImageFormat & iInfo.iImageFormatsSupported))
492 User::Leave(KErrNotSupported);
497 void CTestCamera::StopViewFinder()
499 iViewFinderActive = EFalse;
503 delete iViewFinderBitmapGc;
504 iViewFinderBitmapGc = NULL;
505 delete iViewFinderBitmapDev;
506 iViewFinderBitmapDev = NULL;
507 delete iViewFinderBitmap;
508 iViewFinderBitmap = NULL;
511 TBool CTestCamera::ViewFinderActive() const
513 return iViewFinderActive;
516 void CTestCamera::SetViewFinderMirrorL(TBool aMirror)
520 User::Leave(KErrNotSupported);
524 TBool CTestCamera::ViewFinderMirror() const
529 void CTestCamera::PrepareImageCaptureL(TFormat aImageFormat,TInt aSizeIndex)
533 User::Leave(KErrInUse);
536 if (!iPowerOn || iVideoCaptureActive || iImageCaptureActive)
538 User::Leave(KErrNotReady);
542 if (!(aImageFormat & iInfo.iImageFormatsSupported) || aSizeIndex < 0
543 || aSizeIndex >= iInfo.iNumImageSizesSupported)
545 User::Leave(KErrNotSupported);
548 iVideoPreparedLast = EFalse;
550 if (iImageCapturePrepared
551 && iStillImageSize == iImageSizes[aSizeIndex]
552 && iStillImageFormat == aImageFormat)
557 iStillImageSize = iImageSizes[aSizeIndex];
558 iStillImageFormat = aImageFormat;
560 TDisplayMode displayMode = ENone;
561 switch (iStillImageFormat)
563 case EFormatFbsBitmapColor4K :
564 displayMode = EColor4K;
566 case EFormatFbsBitmapColor64K :
567 displayMode = EColor64K;
569 case EFormatFbsBitmapColor16M :
570 displayMode = EColor16M;
573 User::Leave(KErrNotSupported);
577 delete iStillImageGc;
578 iStillImageGc = NULL;
579 delete iStillImageDev;
580 iStillImageDev = NULL;
584 iStillImage = new(ELeave) CFbsBitmap;
585 User::LeaveIfError(iStillImage->Create(iStillImageSize, displayMode));
586 iStillImageDev = CFbsBitmapDevice::NewL(iStillImage);
587 User::LeaveIfError(iStillImageDev->CreateContext(iStillImageGc));
588 iStillImageGc->SetPenColor(KRgbBlack);
589 iStillImageGc->SetPenSize(TSize(KFrameFeatureBorderThickness, KFrameFeatureBorderThickness));
590 iStillImageGc->SetBrushColor(KRgbWhite);
591 iStillImageGc->SetFaded(ETrue);
592 iImageCapturePrepared = ETrue;
595 void CTestCamera::PrepareImageCaptureL(TFormat /*aImageFormat*/,TInt /*aSizeIndex*/,const TRect& /*aClipRect*/)
597 User::Leave(KErrNotSupported);
600 void CTestCamera::CaptureImage()
604 iStillCaptureErr = KErrInUse;
607 if (!iPowerOn || iImageCaptureActive || iVideoCaptureActive || !iImageCapturePrepared)
609 iStillCaptureErr = KErrNotReady;
612 if (iStillCaptureErr == KErrNone)
614 TRAP(iStillCaptureErr,DoCaptureImageL());
617 if (iStillCaptureErr == KErrNone)
619 iImageCaptureActive = ETrue;
623 iImageCaptureAsync.CallBack();
627 void CTestCamera::DoCaptureImageL()
636 CFbsBitmap* image = new(ELeave) CFbsBitmap;
637 CleanupStack::PushL(image);
638 User::LeaveIfError(image->Create(iStillImageSize, iStillImage->DisplayMode()));
639 CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL(image);
640 CleanupStack::PushL(dev);
641 CFbsBitGc* gc = NULL;
642 User::LeaveIfError(dev->CreateContext(gc));
643 CleanupStack::Pop(dev);
644 CleanupStack::Pop(image);
651 void CTestCamera::CancelCaptureImage()
653 iImageCaptureActive = EFalse;
656 void CTestCamera::EnumerateCaptureSizes(TSize& aSize,TInt aSizeIndex,TFormat aFormat) const
658 if (aSizeIndex < 0 || aSizeIndex >= iInfo.iNumImageSizesSupported ||
659 !(aFormat & iInfo.iImageFormatsSupported) )
665 aSize = iImageSizes[aSizeIndex];
669 void CTestCamera::PrepareVideoCaptureL(TFormat aFormat,TInt aSizeIndex,TInt aRateIndex,TInt aBuffersToUse,TInt aFramesPerBuffer)
673 User::Leave(KErrInUse);
676 if (!iPowerOn || iVideoCaptureActive || iImageCaptureActive)
678 User::Leave(KErrNotReady);
681 if (!(aFormat & iInfo.iVideoFrameFormatsSupported)
682 || aSizeIndex < 0 || aSizeIndex >= iInfo.iNumVideoFrameSizesSupported
683 || aRateIndex < 0 || aRateIndex >= iInfo.iNumVideoFrameRatesSupported
684 || aBuffersToUse != 2 || aFramesPerBuffer != 1)
686 User::Leave(KErrNotSupported);
689 iVideoPreparedLast = ETrue;
691 if (iVideoCapturePrepared
692 && iVideoFrameSize == iVideoFrameSizes[aSizeIndex]
693 && iVideoFrameFormat == aFormat)
698 TDisplayMode displayMode = ENone;
701 case EFormatFbsBitmapColor4K :
702 displayMode = EColor4K;
704 case EFormatFbsBitmapColor64K :
705 displayMode = EColor64K;
707 case EFormatFbsBitmapColor16M :
708 displayMode = EColor16M;
711 User::Leave(KErrNotSupported);
715 iVideoFrameSize = iVideoFrameSizes[aSizeIndex];
716 iVideoFrameRate = iVideoFrameRates[aRateIndex];
717 iVideoFrameFormat = aFormat;
718 iBuffersInUse = aBuffersToUse;
720 delete iVideoFrameGc1;
721 iVideoFrameGc1 = NULL;
722 delete iVideoFrameDev1;
723 iVideoFrameDev1 = NULL;
727 delete iVideoFrameGc2;
728 iVideoFrameGc2 = NULL;
729 delete iVideoFrameDev2;
730 iVideoFrameDev2 = NULL;
734 iVideoFrame1 = new(ELeave) CFbsBitmap;
735 User::LeaveIfError(iVideoFrame1->Create(iVideoFrameSize, displayMode));
736 iVideoFrameDev1 = CFbsBitmapDevice::NewL(iVideoFrame1);
737 User::LeaveIfError(iVideoFrameDev1->CreateContext(iVideoFrameGc1));
738 iVideoFrameGc1->SetPenColor(KRgbBlack);
739 iVideoFrameGc1->SetPenSize(TSize(KFrameFeatureBorderThickness, KFrameFeatureBorderThickness));
740 iVideoFrameGc1->SetBrushColor(KRgbWhite);
741 iVideoFrameGc1->SetFaded(ETrue);
743 if (iBuffersInUse == 2)
745 iVideoFrame2 = new(ELeave) CFbsBitmap;
746 User::LeaveIfError(iVideoFrame2->Create(iVideoFrameSize, displayMode));
747 iVideoFrameDev2 = CFbsBitmapDevice::NewL(iVideoFrame2);
748 User::LeaveIfError(iVideoFrameDev1->CreateContext(iVideoFrameGc2));
749 iVideoFrameGc2->SetPenColor(KRgbBlack);
750 iVideoFrameGc2->SetPenSize(TSize(KFrameFeatureBorderThickness, KFrameFeatureBorderThickness));
751 iVideoFrameGc2->SetBrushColor(KRgbWhite);
752 iVideoFrameGc2->SetFaded(ETrue);
755 iVideoCapturePrepared = ETrue;
758 void CTestCamera::PrepareVideoCaptureL(TFormat /*aFormat*/,TInt /*aSizeIndex*/,TInt /*aRateIndex*/,TInt /*aBuffersToUse*/,TInt /*aFramesPerBuffer*/,const TRect& /*aClipRect*/)
760 User::Leave(KErrNotSupported);
763 void CTestCamera::StartVideoCapture()
767 iVideoCaptureErr = KErrInUse;
770 if (!iPowerOn || iImageCaptureActive || iVideoCaptureActive || !iVideoCapturePrepared)
772 iVideoCaptureErr = KErrNotReady;
775 if (iVideoCaptureErr == KErrNone)
777 iVideoCaptureActive = ETrue;
782 iVideoCaptureAsync.CallBack();
786 void CTestCamera::StopVideoCapture()
788 iVideoCaptureActive = EFalse;
793 TBool CTestCamera::VideoCaptureActive() const
795 return iVideoCaptureActive;
798 void CTestCamera::EnumerateVideoFrameSizes(TSize& aSize,TInt aSizeIndex,TFormat aFormat) const
800 if (aSizeIndex < 0 || aSizeIndex >= iInfo.iNumVideoFrameSizesSupported ||
801 !(aFormat & iInfo.iVideoFrameFormatsSupported))
807 aSize = iVideoFrameSizes[aSizeIndex];
811 void CTestCamera::EnumerateVideoFrameRates(TReal32& aRate,TInt aRateIndex,TFormat aFormat,TInt aSizeIndex,TExposure aExposure) const
813 if (aRateIndex < 0 || aRateIndex >= iInfo.iNumVideoFrameRatesSupported ||
814 aSizeIndex < 0 || aSizeIndex >= iInfo.iNumVideoFrameSizesSupported ||
815 !(aFormat & iInfo.iVideoFrameFormatsSupported) ||
816 (!(aExposure & iInfo.iExposureModesSupported) && aExposure != CCamera::EExposureAuto))
822 aRate = iVideoFrameRates[aRateIndex];
826 void CTestCamera::GetFrameSize(TSize& aSize) const
828 aSize = iVideoFrameSize;
831 TReal32 CTestCamera::FrameRate() const
833 return iVideoFrameRate;
836 TInt CTestCamera::BuffersInUse() const
838 return iBuffersInUse;
841 TInt CTestCamera::FramesPerBuffer() const
846 void CTestCamera::SetJpegQuality(TInt /*aQuality*/)
850 TInt CTestCamera::JpegQuality() const
855 TAny* CTestCamera::CustomInterface(TUid aInterface)
857 TAny* ptrIface = NULL;
858 TRAPD(error,CustomInterfaceL(ptrIface, aInterface));
860 if(error == KErrNone)
862 switch(aInterface.iUid)
864 // advanced settings interface pointers
865 case KECamMCameraAdvancedSettingsUidValue:
867 return static_cast<MCameraAdvancedSettings*>(ptrIface);
869 case KECamMCameraAdvancedSettings2UidValue:
871 return static_cast<MCameraAdvancedSettings2*>(ptrIface);
873 case KECamMCameraAdvancedSettings3UidValue:
875 return static_cast<MCameraAdvancedSettings3*>(ptrIface);
878 // snapshot interface pointers
879 case KECamMCameraSnapshotUidValue:
881 return static_cast<MCameraSnapshot*>(ptrIface);
884 // preset interface pointers
885 case KECamMCameraPresetsUidValue:
886 return static_cast<MCameraPresets*>(ptrIface);
888 // image processing interface pointers
889 case KECamMCameraImageProcessingUidValue:
891 return static_cast<MCameraImageProcessing*>(ptrIface);
894 case KECamMCameraImageProcessing2UidValue:
896 return static_cast<MCameraImageProcessing2*>(ptrIface);
909 void CTestCamera::CustomInterfaceL(TAny*& aIface, TUid aInterface)
911 switch(aInterface.iUid)
913 // advanced settings interface pointers
914 case KECamMCameraAdvancedSettingsUidValue:
916 iAdvSettingsImpl = CTestCamAdvSet::NewL(*this);
917 aIface = static_cast<MCameraAdvancedSettings*>(iAdvSettingsImpl);
920 case KECamMCameraAdvancedSettings2UidValue:
922 iAdvSettingsImpl = CTestCamAdvSet::NewL(*this);
923 aIface = static_cast<MCameraAdvancedSettings2*>(iAdvSettingsImpl);
926 case KECamMCameraAdvancedSettings3UidValue:
928 iAdvSettingsImpl = CTestCamAdvSet::NewL(*this);
929 aIface = static_cast<MCameraAdvancedSettings3*>(iAdvSettingsImpl);
933 // snapshot interface pointers
934 case KECamMCameraSnapshotUidValue:
936 iSnapshotImpl = CTestCamSnapshot::NewL(*this);
937 aIface = static_cast<MCameraSnapshot*>(iSnapshotImpl);
940 // preset interface pointers
941 case KECamMCameraPresetsUidValue:
943 aIface = static_cast<MCameraPresets*>(CTestCamPresets::NewL(*this));
947 // image processing interface pointers
948 case KECamMCameraImageProcessingUidValue:
950 iImgProcImpl = CTestCamImgProc::NewL(*this);
951 aIface = static_cast<MCameraImageProcessing*>(iImgProcImpl);
955 case KECamMCameraImageProcessing2UidValue:
957 iImgProcImpl = CTestCamImgProc::NewL(*this);
958 aIface = static_cast<MCameraImageProcessing2*>(iImgProcImpl);
967 void CTestCamera::AbortNow(RDirectScreenAccess::TTerminationReasons /*aReason*/)
969 iViewFinderActive = EFalse;
972 void CTestCamera::Restart(RDirectScreenAccess::TTerminationReasons /*aReason*/)
974 TRAPD(error,iDSA->StartL());
975 if (error != KErrNone)
979 iDSA->Gc()->SetOrigin(); // Set Origin to top left of screen (0,0)
981 if (!iClipRect.IsEmpty())
983 iDSA->Gc()->SetClippingRect(iClipRect);
987 iDSA->Gc()->CancelClippingRect();
990 iViewFinderActive = ETrue;
993 TInt CTestCamera::TimerCallBack(TAny* aThis)
995 static_cast<CTestCamera*>(aThis)->FrameReady();
999 void CTestCamera::FrameReady()
1001 if (iVideoPreparedLast)
1003 iVideoFramePos.iX += KFramePosIncrement;
1004 iVideoFramePos.iY += KFramePosIncrement;
1006 if (iVideoFramePos.iX >= iVideoFrameSize.iWidth)
1008 iVideoFramePos.iX = 0;
1011 if (iVideoFramePos.iY >= iVideoFrameSize.iHeight)
1013 iVideoFramePos.iY = 0;
1018 iStillImagePos.iX += KFramePosIncrement;
1019 iStillImagePos.iY += KFramePosIncrement;
1021 if (iStillImagePos.iX >= iStillImageSize.iWidth)
1023 iStillImagePos.iX = 0;
1026 if (iStillImagePos.iY >= iStillImageSize.iHeight)
1028 iStillImagePos.iY = 0;
1032 if (iImageCaptureActive)
1034 if (!iImageCapturePrepared)
1036 iImageCaptureActive = EFalse;
1039 iObserver2->ImageBufferReady(iFrameCameraBuffer1,KErrNotReady);
1043 iObserver->ImageReady(NULL,NULL,KErrNotReady);
1048 if(iDriveMode == CCamera::CCameraAdvancedSettings::EDriveModeBurst)
1050 for (TInt index =0; index < iBurstImages -1; index++)
1052 if(iSnapshotImpl != NULL)
1054 if(iSnapshotImpl->iSnapshotActive)
1056 GetFrame(*(iSnapshotImpl->iSnapshotImageGc), iStillImagePos);
1057 iSnapshotImpl->ServiceBurstImageSnapshot(*(iSnapshotImpl->iSnapshotImageGc));
1061 GetImgProcessedFrame(*iStillImageGc, iStillImagePos);
1062 ServiceBurstImageCapture(*iStillImageGc);
1066 // normal case, single shot and last image from burst mode
1067 if(iSnapshotImpl != NULL)
1069 if(iSnapshotImpl->iSnapshotActive)
1071 GetFrame(*iSnapshotImpl->iSnapshotImageGc, iStillImagePos);
1072 iSnapshotImpl->ServiceSnapshot(*(iSnapshotImpl->iSnapshotImageGc));
1076 GetImgProcessedFrame(*iStillImageGc, iStillImagePos);
1077 ServiceImageCapture(*iStillImageGc);
1079 if (iVideoPreparedLast)
1081 GetFrame(*iVideoFrameGc1, iVideoFramePos);
1082 if (iViewFinderActive)
1084 ServiceViewFinder(iVideoFrame1);
1089 if (iViewFinderActive)
1091 ServiceViewFinder(iStillImage);
1097 else if (iVideoCaptureActive)
1099 if (!iVideoCapturePrepared)
1101 iVideoCaptureActive = EFalse;
1104 iObserver2->VideoBufferReady(iFrameCameraBuffer1,KErrNotReady);
1108 iObserver->FrameBufferReady(NULL,KErrNotReady);
1115 if (iFrameCameraBuffer1.iAvailable)
1117 GetFrame(*iVideoFrameGc1, iVideoFramePos);
1119 if (iViewFinderActive)
1121 ServiceViewFinder(iVideoFrame1);
1124 else if (iFrameCameraBuffer2.iAvailable && iBuffersInUse == 2)
1126 GetFrame(*iVideoFrameGc2, iVideoFramePos);
1128 if (iViewFinderActive)
1130 ServiceViewFinder(iVideoFrame2);
1136 if (iFrameBuffer1.iAvailable)
1138 GetFrame(*iVideoFrameGc1, iVideoFramePos);
1140 if (iViewFinderActive)
1142 ServiceViewFinder(iVideoFrame1);
1145 else if (iFrameBuffer2.iAvailable && iBuffersInUse == 2)
1147 GetFrame(*iVideoFrameGc2, iVideoFramePos);
1149 if (iViewFinderActive)
1151 ServiceViewFinder(iVideoFrame2);
1158 else if (iViewFinderActive)
1160 if (iVideoPreparedLast)
1162 GetFrame(*iVideoFrameGc1, iVideoFramePos);
1163 ServiceViewFinder(iVideoFrame1);
1167 GetFrame(*iStillImageGc, iStillImagePos);
1168 ServiceViewFinder(iStillImage);
1173 void CTestCamera::GetFrame(CFbsBitGc& aGc, TPoint& aPos) const
1175 TInt black = (100 - iContrast) * 127 / 200;
1176 TInt white = ((100 + iContrast) * 128 / 200) + 127;
1178 const TInt brightAdjust = iBrightness * 255 / 100;
1179 black += brightAdjust;
1180 white += brightAdjust;
1182 black = Min(Max(black,0),255);
1183 white = Min(Max(white,0),255);
1185 aGc.SetFadingParameters(TUint8(black),TUint8(white));
1187 aGc.DrawRect(TRect(aPos,TSize(KFrameFeatureSize,KFrameFeatureSize)));
1190 void CTestCamera::GetImgProcessedFrame(CFbsBitGc& aGc, TPoint& aPos) const
1192 TInt contrast = iContrast;
1193 TInt brightness = iBrightness;
1195 if(iImgProcImpl != NULL)
1197 for(TInt index=0; index<iImgProcImpl->iActiveTransformations.Count(); index++)
1199 switch(iImgProcImpl->iActiveTransformations[index].iUid)
1201 case KUidECamEventImageProcessingAdjustBrightnessUidValue:
1203 brightness = iImgProcBrightness;
1206 case KUidECamEventImageProcessingAdjustContrastUidValue:
1208 contrast = iImgProcContrast;
1219 TInt black = (100 - contrast) * 127 / 200;
1220 TInt white = ((100 + contrast) * 128 / 200) + 127;
1222 const TInt brightAdjust = brightness * 255 / 100;
1223 black += brightAdjust;
1224 white += brightAdjust;
1226 black = Min(Max(black,0),255);
1227 white = Min(Max(white,0),255);
1229 aGc.SetFadingParameters(TUint8(black),TUint8(white));
1231 aGc.DrawRect(TRect(aPos,TSize(KFrameFeatureSize,KFrameFeatureSize)));
1234 void CTestCamera::ServiceVideo(TInt aBufferNum)
1237 iElapsedTime = iElapsedTime.Int64() + (TInt64(1000000) / TInt64(iVideoFrameRate));
1239 if (aBufferNum == 1)
1243 iFrameCameraBuffer1.iIndexOfFirstFrameInBuffer = iFrameIndex;
1244 iFrameCameraBuffer1.iElapsedTime = iElapsedTime;
1245 iFrameCameraBuffer1.iAvailable = EFalse;
1249 iFrameBuffer1.iIndexOfFirstFrameInBuffer = iFrameIndex;
1250 iFrameBuffer1.iElapsedTime = iElapsedTime;
1251 iFrameBuffer1.iAvailable = EFalse;
1256 iObserver2->VideoBufferReady(iFrameCameraBuffer1,KErrNone);
1260 iObserver->FrameBufferReady(&iFrameBuffer1,KErrNone);
1263 else if (aBufferNum == 2)
1267 iFrameCameraBuffer2.iIndexOfFirstFrameInBuffer = iFrameIndex;
1268 iFrameCameraBuffer2.iElapsedTime = iElapsedTime;
1269 iFrameCameraBuffer2.iAvailable = EFalse;
1273 iFrameBuffer2.iIndexOfFirstFrameInBuffer = iFrameIndex;
1274 iFrameBuffer2.iElapsedTime = iElapsedTime;
1275 iFrameBuffer2.iAvailable = EFalse;
1280 iObserver2->VideoBufferReady(iFrameCameraBuffer2,KErrNone);
1284 iObserver->FrameBufferReady(&iFrameBuffer2,KErrNone);
1289 void CTestCamera::ServiceViewFinder(CFbsBitmap* aSourceFrame)
1293 iDSA->Gc()->DrawBitmap(iScreenRect,aSourceFrame);
1294 iDSA->ScreenDevice()->Update();
1296 else if (iViewFinderBitmap)
1298 if (iViewFinderBitmapGc)
1300 if (!iClipRect.IsEmpty())
1302 TReal32 xRatio = static_cast<TReal32>(aSourceFrame->SizeInPixels().iWidth) /
1303 static_cast<TReal32>(iClipRect.Size().iWidth);
1305 TReal32 yRatio = static_cast<TReal32>(aSourceFrame->SizeInPixels().iHeight) /
1306 static_cast<TReal32>(iClipRect.Size().iHeight);
1308 TRect sourceRect(TPoint(static_cast<TInt>(xRatio*iClipRect.iTl.iX),
1309 static_cast<TInt>(yRatio*iClipRect.iTl.iY)),
1310 TPoint(static_cast<TInt>(xRatio*iClipRect.iBr.iX),
1311 static_cast<TInt>(yRatio*iClipRect.iBr.iY)));
1313 TRect destRect(TPoint(0,0), iClipRect.Size());
1315 iViewFinderBitmapGc->DrawBitmap(destRect,
1321 TRect destRect(TPoint(0,0), iViewFinderBitmap->SizeInPixels());
1322 iViewFinderBitmapGc->DrawBitmap(destRect, aSourceFrame);
1327 iObserver2->ViewFinderReady(iFrameCameraBuffer1,KErrNone);
1331 iObserver->ViewFinderFrameReady(*iViewFinderBitmap);
1338 iScreenGc->DrawBitmap(iClipRect,aSourceFrame);
1339 iScreenDev->Update();
1343 void CTestCamera::ServiceImageCapture(const CFbsBitGc& aSourceBitmapGc)
1345 iImageCaptureActive = EFalse;
1346 iGc->BitBlt(TPoint(0,0), aSourceBitmapGc);
1347 CFbsBitmap* image = iImage;
1348 RTestCameraFrameBuffer frameBuffer(image);
1353 if (iObserver2 != NULL)
1355 iObserver2->ImageBufferReady(frameBuffer,KErrNone);
1360 iObserver->ImageReady(image,NULL,KErrNone);
1364 void CTestCamera::ServiceBurstImageCapture(const CFbsBitGc& aSourceBitmapGc)
1366 iGc->BitBlt(TPoint(0,0), aSourceBitmapGc);
1367 if (iObserver2 != NULL)
1369 CFbsBitmap* image = iImage;
1370 RTestCameraFrameBuffer frameBuffer(image);
1371 iObserver2->ImageBufferReady(frameBuffer,KErrNone);
1373 else//not for MCameraObserver
1380 if(iSnapshotImpl->iSnapshotActive)
1385 User::After(500000);
1386 iStillImagePos.iX += KFramePosIncrement;
1387 iStillImagePos.iY += KFramePosIncrement;
1389 if (iStillImagePos.iX >= iStillImageSize.iWidth)
1391 iStillImagePos.iX = 0;
1394 if (iStillImagePos.iY >= iStillImageSize.iHeight)
1396 iStillImagePos.iY = 0;
1400 void CTestCamera::CheckReserveAndPowerL()
1404 User::Leave(KErrInUse);
1409 User::Leave(KErrNotReady);
1413 TInt CTestCamera::CheckReserveAndPower() const
1422 return KErrNotReady;
1428 TInt CTestCamera::ReserveCallBack(TAny* aThis)
1430 const TECAMEvent event(KUidECamEventReserveComplete,KErrNone);
1431 CTestCamera* testCamera = static_cast<CTestCamera*>(aThis);
1432 if (testCamera->iObserver2)
1434 testCamera->iObserver2->HandleEvent(event);
1438 testCamera->iObserver->ReserveComplete(KErrNone);
1443 TInt CTestCamera::PowerOnCallBack(TAny* aThis)
1445 TECAMEvent event(KUidECamEventPowerOnComplete,KErrNone);
1446 CTestCamera* testCamera = static_cast<CTestCamera*>(aThis);
1447 if (testCamera->iObserver2)
1449 testCamera->iObserver2->HandleEvent(event);
1453 testCamera->iObserver->PowerOnComplete(testCamera->iPowerOn ? KErrNone : KErrInUse);
1458 TInt CTestCamera::ImageCaptureCallBack(TAny* aThis)
1460 CTestCamera* testCamera = static_cast<CTestCamera*>(aThis);
1461 if (testCamera->iObserver2)
1463 testCamera->iObserver2->ImageBufferReady((static_cast<CTestCamera*>(aThis))->iFrameCameraBuffer1,testCamera->iStillCaptureErr);
1467 testCamera->iObserver->ImageReady(NULL,NULL,testCamera->iStillCaptureErr);
1469 testCamera->iStillCaptureErr = KErrNone;
1473 TInt CTestCamera::VideoCaptureCallBack(TAny* aThis)
1475 CTestCamera* testCamera = static_cast<CTestCamera*>(aThis);
1476 if (testCamera->iObserver2)
1478 testCamera->iObserver2->VideoBufferReady((static_cast<CTestCamera*>(aThis))->iFrameCameraBuffer1,testCamera->iVideoCaptureErr);
1482 testCamera->iObserver->FrameBufferReady(NULL,testCamera->iVideoCaptureErr);
1484 testCamera->iVideoCaptureErr = KErrNone;
1488 TInt CTestCamera::HandleEventCallBack(TAny* aThis)
1490 CTestCamera* testCamera = static_cast<CTestCamera*>(aThis);
1491 if (testCamera->iObserver2)
1493 testCamera->iObserver2->HandleEvent(testCamera->iECamEvent);
1499 TInt CTestCamera::HandleEvent2CallBack(TAny* aThis)
1501 CTestCamera* testCamera = static_cast<CTestCamera*>(aThis);
1502 if (testCamera->iObserver2)
1504 testCamera->iObserver2->HandleEvent(testCamera->iECamEvent2);
1514 CTestCameraInfo::CTestCameraInfo()
1518 CTestCameraInfo::~CTestCameraInfo()
1522 CTestCameraInfo* CTestCameraInfo::NewL()
1524 FileDependencyUtil::CheckFileDependencyL();
1525 return new (ELeave) CTestCameraInfo;
1528 TInt CTestCameraInfo::CamerasAvailable()
1533 //void CTestCamera::CheckFileDependencyL()
1534 void FileDependencyUtil::CheckFileDependencyL()
1538 CleanupClosePushL(fsSession);
1539 User::LeaveIfError(fsSession.Connect());
1540 TInt err = file.Open(fsSession, KTestCameraPluginName, EFileRead);
1544 User::LeaveIfError(KErrNotSupported);
1546 CleanupStack::PopAndDestroy(); //fsSession
1549 // __________________________________________________________________________
1550 // Exported proxy for instantiation method resolution
1551 // Define the interface UIDs
1552 const TImplementationProxy ImplementationTable[] =
1554 IMPLEMENTATION_PROXY_ENTRY(KUidOnboardCameraTestPlugin, CTestCamera::NewL),
1555 IMPLEMENTATION_PROXY_ENTRY(KUidOnboardCameraTestInfo, CTestCameraInfo::NewL)
1558 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
1560 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
1562 return ImplementationTable;