os/mm/mmplugins/cameraplugins/source/testcamera/TestCamera.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #ifndef __TESTCAMERA_H__
    17 #define __TESTCAMERA_H__
    18 
    19 
    20 #include <ecam/ecamplugin.h>
    21 #include <ecam/ecaminfoplugin.h>
    22 #include <bitdev.h>
    23 #include <ecam.h>
    24 #include <w32std.h>
    25 #include <ecamadvsettings.h>
    26 
    27 _LIT(KTestCameraPluginName, "C:\\102070cc.txt");
    28 
    29 const TInt KMinTestCameraZoom = -3;
    30 const TInt KMaxTestCameraZoom = 3;
    31 const TReal32 KMaxTestCameraDigitalZoomFactor = 1.0;
    32 const TInt KMaxTestCameraDigitalZoom = 0;
    33 const TInt KFramePosIncrement = 5;
    34 const TInt KFrameFeatureSize = 25;
    35 const TInt KFrameFeatureBorderThickness = 5;
    36 const enum CCamera::TFormat KInitialViewFinderFormat = CCamera::EFormatFbsBitmapColor16M;
    37 const TDisplayMode KViewFinderDisplayMode = EColor4K;
    38 
    39 class CTestCamAdvSet;
    40 class CTestCamPresets;
    41 class CTestCamSnapshot;
    42 class CTestCamImgProc;
    43 
    44 class RTestCameraFrameBuffer : public MCameraBuffer
    45 	{
    46 public:
    47 	RTestCameraFrameBuffer(CFbsBitmap*& aFrame): iAvailable(ETrue), iFrame(aFrame) {}
    48 	virtual TInt NumFrames() {return 0;}
    49 	virtual TDesC8* DataL(TInt aFrameIndex) {if (aFrameIndex != 0) { User::Leave(KErrArgument); } return NULL; }
    50 	virtual CFbsBitmap& BitmapL(TInt aFrameIndex) {if (aFrameIndex != 0) { User::Leave(KErrArgument); } return *iFrame;}
    51  	virtual	RChunk& ChunkL() { return iChunk;}
    52 	virtual TInt ChunkOffsetL(TInt aFrameIndex) {if (aFrameIndex != 0) { User::Leave(KErrArgument); } return 0;}
    53 	virtual TInt FrameSize(TInt aFrameIndex) {if (aFrameIndex != 0) { User::Leave(KErrArgument); } return 0; }
    54 	virtual void Release() {iAvailable = ETrue;}
    55 public:	
    56 	volatile TBool iAvailable;
    57 	CFbsBitmap*& iFrame;
    58 	RChunk iChunk;
    59 	};
    60 
    61 class RTestFrameBuffer : public MFrameBuffer
    62 	{
    63 public:
    64 	RTestFrameBuffer(CFbsBitmap*& aFrame): iAvailable(ETrue), iFrame(aFrame) {}
    65 	virtual TDesC8* DataL(TInt /*aIndex*/) { User::Leave(KErrNotSupported); return NULL; }
    66 	virtual CFbsBitmap* FrameL(TInt aIndex) { if (aIndex != 0) User::Leave(KErrNotSupported); return iFrame; }
    67 	virtual void Release() { iAvailable = ETrue; }
    68 public:
    69 	TBool iAvailable;
    70 	CFbsBitmap*& iFrame;
    71 	};
    72 
    73 class CDirectScreenAccess;
    74 
    75 class CTestCamera : public CCameraPlugin, public MDirectScreenAccess
    76 	{
    77 	friend class CTestCamAdvSet;
    78 	friend class CTestCamPresets;
    79 	friend class CTestCamSnapshot;
    80 	friend class CTestCamImgProc;
    81 	
    82 public:
    83 	static CTestCamera* NewL();
    84 	~CTestCamera();
    85 	void ConstructL();
    86 	// from CCameraPlugin
    87 	void Construct2L(MCameraObserver& aObserver,TInt aCameraIndex);
    88 	void Construct2DupL(MCameraObserver& aObserver,TInt aCameraHandle);
    89 	void Construct2L(MCameraObserver2& aObserver,TInt aCameraIndex,TInt aPriority);
    90 	void Construct2DupL(MCameraObserver2& aObserver,TInt aCameraHandle);
    91 private:
    92 	// From CCamera
    93 	virtual void CameraInfo(TCameraInfo& aInfo) const;
    94 	virtual void Reserve();
    95 	virtual void Release();
    96 	virtual void PowerOn();
    97 	virtual void PowerOff();
    98 	virtual TInt Handle();
    99 
   100 	virtual void SetZoomFactorL(TInt aZoomFactor = 0);
   101 	virtual TInt ZoomFactor() const;
   102 	virtual void SetDigitalZoomFactorL(TInt aDigitalZoomFactor = 0);
   103 	virtual TInt DigitalZoomFactor() const;
   104 
   105 	virtual void SetContrastL(TInt aContrast);
   106 	virtual TInt Contrast() const;
   107 	virtual void SetBrightnessL(TInt aBrightness);
   108 	virtual TInt Brightness() const;
   109 	virtual void SetFlashL(TFlash aFlash = EFlashNone);
   110 	virtual TFlash Flash() const;
   111 	virtual void SetExposureL(TExposure aExposure = EExposureAuto);
   112 	virtual TExposure Exposure() const;
   113 	virtual void SetWhiteBalanceL(TWhiteBalance aWhiteBalance = EWBAuto);
   114 	virtual TWhiteBalance WhiteBalance() const;
   115 
   116 	virtual void StartViewFinderDirectL(RWsSession& aWs,CWsScreenDevice& aScreenDevice,RWindowBase& aWindow,TRect& aScreenRect);
   117 	virtual void StartViewFinderDirectL(RWsSession& aWs,CWsScreenDevice& aScreenDevice,RWindowBase& aWindow,TRect& aScreenRect,TRect& aClipRect);
   118 	virtual void StartViewFinderBitmapsL(TSize& aSize);
   119 	virtual void StartViewFinderBitmapsL(TSize& aSize,TRect& aClipRect);
   120 	virtual void StartViewFinderL(TFormat aImageFormat,TSize& aSize);
   121 	virtual void StartViewFinderL(TFormat aImageFormat,TSize& aSize,TRect& aClipRect);
   122 	virtual void StopViewFinder();
   123 	virtual TBool ViewFinderActive() const;
   124 	virtual void SetViewFinderMirrorL(TBool aMirror);
   125 	virtual TBool ViewFinderMirror() const;
   126 
   127 	virtual void PrepareImageCaptureL(TFormat aImageFormat,TInt aSizeIndex);
   128 	virtual void PrepareImageCaptureL(TFormat aImageFormat,TInt aSizeIndex,const TRect& aClipRect);
   129 	virtual void CaptureImage();
   130 	virtual void CancelCaptureImage();
   131 	virtual void EnumerateCaptureSizes(TSize& aSize,TInt aSizeIndex,TFormat aFormat) const;
   132 
   133 	virtual void PrepareVideoCaptureL(TFormat aFormat,TInt aSizeIndex,TInt aRateIndex,TInt aBuffersToUse,TInt aFramesPerBuffer);
   134 	virtual void PrepareVideoCaptureL(TFormat aFormat,TInt aSizeIndex,TInt aRateIndex,TInt aBuffersToUse,TInt aFramesPerBuffer,const TRect& aClipRect);
   135 	virtual void StartVideoCapture();
   136 	virtual void StopVideoCapture();
   137 
   138 	virtual TBool VideoCaptureActive() const;
   139 	virtual void EnumerateVideoFrameSizes(TSize& aSize,TInt aSizeIndex,TFormat aFormat) const;
   140 	virtual void EnumerateVideoFrameRates(TReal32& aRate,TInt aRateIndex,TFormat aFormat,TInt aSizeIndex,TExposure aExposure = EExposureAuto) const;
   141 	virtual void GetFrameSize(TSize& aSize) const;
   142 	virtual TReal32 FrameRate() const;
   143 	virtual TInt BuffersInUse() const;
   144 	virtual TInt FramesPerBuffer() const;
   145 
   146 	virtual void SetJpegQuality(TInt aQuality);
   147 	virtual TInt JpegQuality() const;
   148 
   149 	virtual TAny* CustomInterface(TUid aInterface);
   150 
   151 	// From MAbortDirectScreenAccess
   152 	virtual void AbortNow(RDirectScreenAccess::TTerminationReasons aReason);
   153 
   154 	// From MDirectScreenAccess
   155 	virtual void Restart(RDirectScreenAccess::TTerminationReasons aReason);
   156 
   157 	// New functions
   158 	static TInt TimerCallBack(TAny* aThis);
   159 	void FrameReady();
   160 	void GetFrame(CFbsBitGc& aGc, TPoint& aPos) const;
   161 	void GetImgProcessedFrame(CFbsBitGc& aGc, TPoint& aPos) const;
   162 	void ServiceVideo(TInt aBuferNum);
   163 	void ServiceViewFinder(CFbsBitmap* aSourceFrame);
   164 	void ServiceImageCapture(const CFbsBitGc& aSourceBitmapGc);
   165 	void ServiceBurstImageCapture(const CFbsBitGc& aSourceBitmapGc);
   166 	void DoCaptureImageL();
   167 	void CheckReserveAndPowerL();
   168 	TInt CheckReserveAndPower() const;
   169 	void CustomInterfaceL(TAny*& aIface, TUid aInterface);
   170 	static TInt ReserveCallBack(TAny* aThis);
   171 	static TInt PowerOnCallBack(TAny* aThis);
   172 	static TInt ImageCaptureCallBack(TAny* aThis);
   173 	static TInt VideoCaptureCallBack(TAny* aThis);
   174 	static TInt HandleEventCallBack(TAny* aThis);
   175 	static TInt HandleEvent2CallBack(TAny* aThis);
   176 	
   177 private:
   178 	 CTestCamera();	
   179 private:
   180 	MCameraObserver* iObserver; // not owned
   181 	MCameraObserver2* iObserver2; // not owned
   182 	TBool iReserved;
   183 	TBool iPowerOn;
   184 
   185 	TCameraInfo iInfo;
   186 	CPeriodic* iTimer;
   187 	TTimeIntervalMicroSeconds32 iFrameDelay;
   188 	TInt iFrameIndex;
   189 	TTimeIntervalMicroSeconds iElapsedTime;
   190 	TPoint iStillImagePos;
   191 	TPoint iVideoFramePos;
   192 
   193 	TReal32 iVideoFrameRate;
   194 	TInt iBuffersInUse;
   195 	TSize iVideoFrameSize;
   196 	TFormat iVideoFrameFormat;
   197 
   198 	CFbsBitmap* iVideoFrame1;
   199 	CFbsBitmapDevice* iVideoFrameDev1;
   200 	CFbsBitGc* iVideoFrameGc1;
   201 	CFbsBitmap* iVideoFrame2;
   202 	CFbsBitmapDevice* iVideoFrameDev2;
   203 	CFbsBitGc* iVideoFrameGc2;
   204 
   205 	TInt iStillCaptureErr;
   206 	TSize iStillImageSize;
   207 	TFormat iStillImageFormat;
   208 	CFbsBitmap* iStillImage;
   209 	CFbsBitmapDevice* iStillImageDev;
   210 	CFbsBitGc* iStillImageGc;
   211 
   212 	TSize iViewFinderSize;
   213 	TFormat iViewFinderFormat;
   214 	CFbsBitmap* iViewFinderBitmap;
   215 	CFbsBitmapDevice* iViewFinderBitmapDev;
   216 	CFbsBitGc* iViewFinderBitmapGc;
   217 
   218 	CDirectScreenAccess* iDSA;
   219 	CFbsScreenDevice* iScreenDev;
   220 	CFbsBitGc* iScreenGc;
   221 	TRect iScreenRect;
   222 	TRect iClipRect;
   223 
   224 	CFbsBitmap* iImage;
   225 	CFbsBitmapDevice* iDev;
   226 	CFbsBitGc* iGc;
   227 
   228 	CAsyncCallBack iReserveAsync;
   229 	CAsyncCallBack iPowerOnAsync;
   230 	CAsyncCallBack iImageCaptureAsync;
   231 	CAsyncCallBack iVideoCaptureAsync;
   232 	CAsyncCallBack iHandleEventAsync;
   233 	CAsyncCallBack iHandleEvent2Async;
   234 
   235 	RTestFrameBuffer iFrameBuffer1;
   236 	RTestFrameBuffer iFrameBuffer2;
   237 	
   238 	RTestCameraFrameBuffer iFrameCameraBuffer1;
   239 	RTestCameraFrameBuffer iFrameCameraBuffer2;
   240 
   241 	TInt iVideoCaptureErr;
   242 	// Members to store the current optical or digital value set with SetZoomFactorL() and SetDigitalZoomFactorL()
   243 	// Although arguments have trailing Factor in fact they must contain values in the ranges specified by
   244 	//  	iInfo.iMinZoom : iInfo.iMaxZoom for optical zoom and 
   245 	//		0 : iInfo.iMaxDigitalZoom for digital zoom 
   246 	// The factor values cannot be modified using Camera API as it is assumed 
   247 	// that they are determined by the camera hardware.  
   248 	TInt iZoom;
   249 	TInt iDigitalZoom;
   250 	
   251 	TInt iContrast;
   252 	TInt iBrightness;
   253 	
   254 	TInt iImgProcBrightness;
   255 	TInt iImgProcContrast;
   256 	
   257 	volatile TBool iViewFinderActive;
   258 	volatile TBool iVideoCaptureActive;
   259 	volatile TBool iImageCaptureActive;
   260 	volatile TBool iVideoPreparedLast;
   261 	volatile TBool iVideoCapturePrepared;
   262 	volatile TBool iImageCapturePrepared;
   263 
   264 	RArray<TSize> iImageSizes;
   265 	RArray<TSize> iVideoFrameSizes;
   266 	RArray<TReal32> iVideoFrameRates;
   267 	TInt iCameraIndex;
   268 	TInt iCameraHandle;
   269 	TInt iPriority;	
   270 	
   271 	TECAMEvent iECamEvent;
   272 	TECAMEvent2 iECamEvent2;
   273 	TInt iEventError;
   274 	
   275 	CTestCamAdvSet* iAdvSettingsImpl;
   276 	CTestCamSnapshot* iSnapshotImpl;
   277 	CTestCamImgProc* iImgProcImpl;
   278 	
   279 	CCamera::CCameraAdvancedSettings::TDriveMode iDriveMode;
   280 	TInt iBurstImages;
   281 	};
   282 	
   283 class CTestCameraInfo : public CCameraInfoPlugin
   284 	{
   285 public:
   286 	static CTestCameraInfo* NewL();
   287 	~CTestCameraInfo();
   288 	// from CCameraInfoPlugin
   289 	TInt CamerasAvailable();
   290 private:
   291 	CTestCameraInfo();	
   292 	};
   293 	
   294 enum TStubPanicReasons
   295 	{
   296 	EPanicUnimplemented=1
   297 	};	
   298 
   299 class FileDependencyUtil
   300 	{
   301 public:
   302 	static void CheckFileDependencyL();
   303 	};
   304 
   305 class CDataGlobal : public CBase
   306 	{
   307 public:
   308 	CTestCamAdvSet* iTestCamAdvSet;
   309 	CTestCamPresets* iTestCamPresets;
   310 	CTestCamSnapshot* iTestCamSnapshot;
   311 	CTestCamImgProc* iTestCamImgProc;
   312 	TInt 		iAdvSetReferenceCount;	
   313 	TInt 		iPresetsReferenceCount;
   314 	TInt 		iSnapshotReferenceCount;	
   315 	TInt 		iImgProcReferenceCount;
   316 	};
   317 	
   318 #endif