mmplugins/cameraplugins/source/testcamera/TestCamera.cpp
changeset 0 40261b775718
child 64 92a82bc706f7
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     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 #include <w32std.h>
       
    17 #include <ecom/ecom.h>
       
    18 #include <ecom/implementationproxy.h>
       
    19 #include <f32file.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"
       
    25 #include <ecam.h>
       
    26 
       
    27 //
       
    28 // Main stuff
       
    29 //
       
    30 // 
       
    31 // 2nd stage ConstructL calls called by framework
       
    32 //
       
    33 CTestCamera* CTestCamera::NewL()
       
    34 	{
       
    35 	FileDependencyUtil::CheckFileDependencyL();
       
    36    	CTestCamera* self = new(ELeave) CTestCamera;
       
    37 	CleanupStack::PushL(self);
       
    38 	self->ConstructL();
       
    39 	CleanupStack::Pop(self);
       
    40 	return self;
       
    41 	}
       
    42 
       
    43 void CTestCamera::Construct2L(MCameraObserver& aObserver,TInt aCameraIndex)
       
    44 	{
       
    45 	iObserver = &aObserver;
       
    46 	iCameraIndex = aCameraIndex;
       
    47 	}
       
    48 	
       
    49 void CTestCamera::Construct2DupL(MCameraObserver& aObserver,TInt aCameraHandle)
       
    50 	{
       
    51 	iObserver = &aObserver;
       
    52 	iCameraHandle = aCameraHandle;
       
    53 	}
       
    54 
       
    55 void CTestCamera::ConstructL()	
       
    56 	{
       
    57 	
       
    58 	TInt err;
       
    59 	TRAP(err, iScreenDev = CFbsScreenDevice::NewL(_L(""),EColor16MA));
       
    60 	if (err == KErrNotSupported)
       
    61 		{
       
    62 		TRAP(err, iScreenDev = CFbsScreenDevice::NewL(_L(""),EColor16M));
       
    63 		}
       
    64 	if (err == KErrNotSupported)
       
    65 		{
       
    66 		TRAP(err, iScreenDev = CFbsScreenDevice::NewL(_L(""),EColor64K));
       
    67 		}
       
    68 	if (err == KErrNotSupported)
       
    69 		{
       
    70 		TRAP(err, iScreenDev = CFbsScreenDevice::NewL(_L(""),EColor4K));
       
    71 		}
       
    72 	if (err == KErrNotSupported)
       
    73 		{
       
    74 		TRAP(err, iScreenDev = CFbsScreenDevice::NewL(_L(""),EColor256));
       
    75 		}
       
    76 	if (err == KErrNotSupported)
       
    77 		{
       
    78 		iScreenDev = CFbsScreenDevice::NewL(_L(""),EColor16MAP);
       
    79 		}		
       
    80 	else
       
    81 		{
       
    82 		User::LeaveIfError(err);		
       
    83 		}
       
    84 
       
    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
       
    90 
       
    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);
       
   110 	}
       
   111 
       
   112 
       
   113 void CTestCamera::Construct2L(MCameraObserver2& aObserver,TInt aCameraIndex,TInt aPriority)
       
   114 	{
       
   115 	iObserver2 = &aObserver;
       
   116 	iCameraIndex = aCameraIndex;
       
   117 	iPriority = aPriority;
       
   118 	}
       
   119 	
       
   120 void CTestCamera::Construct2DupL(MCameraObserver2& aObserver,TInt aCameraHandle)
       
   121 	{
       
   122 	iObserver2 = &aObserver;
       
   123 	iCameraHandle = aCameraHandle;
       
   124 	}
       
   125 	
       
   126 
       
   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),
       
   139 	iContrast(0),
       
   140 	iBrightness(0),
       
   141 	iImgProcBrightness(0),
       
   142 	iImgProcContrast(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),
       
   151 	iSnapshotImpl(NULL),
       
   152 	iImgProcImpl(NULL),
       
   153 	iDriveMode(KDefaultDriveMode),
       
   154 	iBurstImages(KBurstImages)
       
   155 	{
       
   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);
       
   168 
       
   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;
       
   176 
       
   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;
       
   185 
       
   186 	iInfo.iFlashModesSupported = 0; // Bitfield of TFlash values
       
   187 	iInfo.iExposureModesSupported = 0; // Bitfield of TExposure values
       
   188 	iInfo.iWhiteBalanceModesSupported = 0; // Bitfield of TWhiteBalance values
       
   189 
       
   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;
       
   196 
       
   197 	iInfo.iMaxDigitalZoom = KMaxTestCameraDigitalZoom;
       
   198 	iInfo.iMaxDigitalZoomFactor = KMaxTestCameraDigitalZoomFactor;
       
   199 
       
   200 	iInfo.iImageFormatsSupported = 0;
       
   201 	iInfo.iImageFormatsSupported |= EFormatFbsBitmapColor4K;
       
   202 	iInfo.iImageFormatsSupported |= EFormatFbsBitmapColor64K;
       
   203 	iInfo.iImageFormatsSupported |= EFormatFbsBitmapColor16M;
       
   204 
       
   205 	iInfo.iVideoFrameFormatsSupported = 0;
       
   206 	iInfo.iVideoFrameFormatsSupported |= EFormatFbsBitmapColor4K;
       
   207 	iInfo.iVideoFrameFormatsSupported |= EFormatFbsBitmapColor64K;
       
   208 	iInfo.iVideoFrameFormatsSupported |= EFormatFbsBitmapColor16M;
       
   209 	iInfo.iMaxFramesPerBufferSupported = 1;
       
   210 	iInfo.iMaxBuffersSupported = 2;
       
   211 	
       
   212 	iScreenRect = TRect(TPoint(0,0), TPoint(0,0));
       
   213 	
       
   214 	iEventError = KErrNone;
       
   215 	}
       
   216 	
       
   217 CTestCamera::~CTestCamera()
       
   218 	{
       
   219 	delete iTimer;
       
   220 	delete iStillImage;
       
   221 	delete iStillImageGc;
       
   222 	delete iStillImageDev;
       
   223 	delete iVideoFrame1;
       
   224 	delete iVideoFrameGc1;
       
   225 	delete iVideoFrameDev1;
       
   226 	delete iVideoFrame2;
       
   227 	delete iVideoFrameGc2;
       
   228 	delete iVideoFrameDev2;
       
   229 	delete iViewFinderBitmapGc;
       
   230 	delete iViewFinderBitmapDev;
       
   231 	delete iViewFinderBitmap;
       
   232 	delete iDSA;
       
   233 	delete iScreenGc;
       
   234 	delete iScreenDev;
       
   235 	delete iGc;
       
   236 	delete iDev;
       
   237 	delete iImage;
       
   238 	delete iAdvSettingsImpl;
       
   239 	delete iSnapshotImpl;
       
   240 	delete iImgProcImpl;
       
   241 	iImageSizes.Reset();
       
   242 	iVideoFrameSizes.Reset();
       
   243 	iVideoFrameRates.Reset();
       
   244 	}
       
   245 
       
   246 void CTestCamera::CameraInfo(TCameraInfo& aInfo) const
       
   247 	{
       
   248 	aInfo = iInfo;
       
   249 	}
       
   250 
       
   251 void CTestCamera::Reserve()
       
   252 	{
       
   253 	iReserved = ETrue;
       
   254 	iReserveAsync.CallBack();
       
   255 	}
       
   256 
       
   257 void CTestCamera::Release()
       
   258 	{
       
   259 	iReserved = EFalse;
       
   260 	iTimer->Cancel();
       
   261 	}
       
   262 
       
   263 void CTestCamera::PowerOn()
       
   264 	{
       
   265 	if (!iReserved || iPowerOn)
       
   266 		{
       
   267 		iPowerOnAsync.CallBack();
       
   268 		return;
       
   269 		}
       
   270 
       
   271 	iPowerOn = ETrue;
       
   272 	TCallBack callback(TimerCallBack,this);
       
   273 	iTimer->Start(0,TInt(TReal32(1000000) / iVideoFrameRate), callback);
       
   274 	iPowerOnAsync.CallBack();
       
   275 	}
       
   276 
       
   277 void CTestCamera::PowerOff()
       
   278 	{
       
   279 	iPowerOn = EFalse;
       
   280 	iTimer->Cancel();
       
   281 	}
       
   282 
       
   283 TInt CTestCamera::Handle()
       
   284 	{
       
   285 	return 0;
       
   286 	}
       
   287 
       
   288 void CTestCamera::SetZoomFactorL(TInt aZoomFactor)
       
   289 	{
       
   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)
       
   293 		{
       
   294 		User::Leave(KErrNotSupported);	
       
   295 		}
       
   296 
       
   297 	iZoom = aZoomFactor;
       
   298 	}
       
   299 
       
   300 TInt CTestCamera::ZoomFactor() const
       
   301 	{
       
   302 	// default value is 0
       
   303 	return iZoom;
       
   304 	}
       
   305 
       
   306 void CTestCamera::SetDigitalZoomFactorL(TInt aDigitalZoomFactor)
       
   307 	{
       
   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)
       
   312 		{
       
   313 		User::Leave(KErrNotSupported);	
       
   314 		}
       
   315 
       
   316 	iDigitalZoom = aDigitalZoomFactor;
       
   317 	}
       
   318 
       
   319 TInt CTestCamera::DigitalZoomFactor() const
       
   320 	{
       
   321 	// default value is 0
       
   322 	return iDigitalZoom;
       
   323 	}
       
   324 
       
   325 void CTestCamera::SetContrastL(TInt aContrast)
       
   326 	{
       
   327 	CheckReserveAndPowerL();
       
   328 
       
   329 	iContrast = Min(Max(aContrast,-100),100);
       
   330 	}
       
   331 
       
   332 TInt CTestCamera::Contrast() const
       
   333 	{
       
   334 	return iContrast;
       
   335 	}
       
   336 
       
   337 void CTestCamera::SetBrightnessL(TInt aBrightness)
       
   338 	{
       
   339 	CheckReserveAndPowerL();
       
   340 
       
   341 	iBrightness = Min(Max(aBrightness,-100),100);
       
   342 	}
       
   343 
       
   344 TInt CTestCamera::Brightness() const
       
   345 	{
       
   346 	return iBrightness;
       
   347 	}
       
   348 
       
   349 void CTestCamera::SetFlashL(TFlash aFlash)
       
   350 	{
       
   351 	CheckReserveAndPowerL();
       
   352 
       
   353 	if (aFlash != EFlashNone)
       
   354 		{
       
   355 		User::Leave(KErrNotSupported);	
       
   356 		}
       
   357 	}
       
   358 
       
   359 CCamera::TFlash CTestCamera::Flash() const
       
   360 	{
       
   361 	return EFlashNone;
       
   362 	}
       
   363 
       
   364 void CTestCamera::SetExposureL(TExposure aExposure)
       
   365 	{
       
   366 	CheckReserveAndPowerL();
       
   367 
       
   368 	if (aExposure != EExposureAuto)
       
   369 		{
       
   370 		User::Leave(KErrNotSupported);
       
   371 		}
       
   372 	}
       
   373 
       
   374 CCamera::TExposure CTestCamera::Exposure() const
       
   375 	{
       
   376 	return EExposureAuto;
       
   377 	}
       
   378 
       
   379 void CTestCamera::SetWhiteBalanceL(TWhiteBalance aWhiteBalance)
       
   380 	{
       
   381 	CheckReserveAndPowerL();
       
   382 
       
   383 	if (aWhiteBalance != EWBAuto)
       
   384 		{
       
   385 		User::Leave(KErrNotSupported);
       
   386 		}
       
   387 	}
       
   388 
       
   389 CCamera::TWhiteBalance CTestCamera::WhiteBalance() const
       
   390 	{
       
   391 	return EWBAuto;
       
   392 	}
       
   393 
       
   394 void CTestCamera::StartViewFinderDirectL(RWsSession& aWs,CWsScreenDevice& aScreenDevice,RWindowBase& aWindow,TRect& aScreenRect)
       
   395 	{
       
   396 	TRect emptyRect;
       
   397 	StartViewFinderDirectL(aWs,aScreenDevice,aWindow,aScreenRect,emptyRect);
       
   398 	}
       
   399 
       
   400 void CTestCamera::StartViewFinderDirectL(RWsSession& aWs,CWsScreenDevice& aScreenDevice,RWindowBase& aWindow,TRect& aScreenRect,TRect& aClipRect)
       
   401 	{
       
   402 	if (!iReserved)
       
   403 		{
       
   404 		User::Leave(KErrInUse);		
       
   405 		}
       
   406 		
       
   407 	if (!iPowerOn || iViewFinderActive)
       
   408 		{
       
   409 		User::Leave(KErrNotReady);	
       
   410 		}
       
   411 
       
   412 	iScreenRect = aScreenRect;
       
   413 	iClipRect = aClipRect;
       
   414 
       
   415 	delete iDSA;
       
   416 	iDSA = NULL;
       
   417 	iViewFinderActive = EFalse;
       
   418 	iDSA = CDirectScreenAccess::NewL(aWs,aScreenDevice,aWindow,*this);
       
   419 	iDSA->StartL();
       
   420 	iViewFinderActive = ETrue;
       
   421 	iDSA->Gc()->SetOrigin(); // Set Origin to top left of screen (0,0)
       
   422 
       
   423 	if (!iClipRect.IsEmpty())
       
   424 		{
       
   425 		iDSA->Gc()->SetClippingRect(iClipRect);	
       
   426 		}
       
   427 	}
       
   428 
       
   429 void CTestCamera::StartViewFinderBitmapsL(TSize& aSize)
       
   430 	{
       
   431 	TRect emptyRect;
       
   432 	StartViewFinderBitmapsL(aSize,emptyRect);
       
   433 	}
       
   434 
       
   435 void CTestCamera::StartViewFinderBitmapsL(TSize& aSize, TRect& aClipRect)
       
   436 	{
       
   437 	if (!iReserved)
       
   438 		{
       
   439 		User::Leave(KErrInUse);
       
   440 		}
       
   441 	if (!iPowerOn || iViewFinderActive)
       
   442 		{
       
   443 		User::Leave(KErrNotReady);
       
   444 		}
       
   445 
       
   446 	iViewFinderActive = ETrue;
       
   447 	iScreenRect = TRect(TPoint(0,0), aSize);
       
   448 	iClipRect = aClipRect;
       
   449 	iClipRect.Intersection(iScreenRect);
       
   450 
       
   451 	delete iViewFinderBitmapGc;
       
   452 	iViewFinderBitmapGc = NULL;
       
   453 	delete iViewFinderBitmapDev;
       
   454 	iViewFinderBitmapDev = NULL;
       
   455 	delete iViewFinderBitmap;
       
   456 	iViewFinderBitmap = NULL;
       
   457 
       
   458 	iViewFinderBitmap = new(ELeave) CFbsBitmap;
       
   459 	if (!iClipRect.IsEmpty())
       
   460 		{
       
   461 		User::LeaveIfError(iViewFinderBitmap->Create(iClipRect.Size(), KViewFinderDisplayMode));		
       
   462 		}
       
   463 	else
       
   464 		{
       
   465 		User::LeaveIfError(iViewFinderBitmap->Create(aSize, KViewFinderDisplayMode));		
       
   466 		}
       
   467 	iViewFinderBitmapDev = CFbsBitmapDevice::NewL(iViewFinderBitmap);
       
   468 	User::LeaveIfError(iViewFinderBitmapDev->CreateContext(iViewFinderBitmapGc));
       
   469 	}
       
   470 	
       
   471 void CTestCamera::StartViewFinderL(TFormat aImageFormat,TSize& aSize)
       
   472        {
       
   473        TRect emptyRect;
       
   474        StartViewFinderL(aImageFormat,aSize,emptyRect);
       
   475        }
       
   476 	
       
   477 void CTestCamera::StartViewFinderL(TFormat aImageFormat,TSize& /*aSize*/,TRect& aClipRect)	
       
   478        {
       
   479      	if(!iReserved)
       
   480      		{
       
   481      		User::Leave(KErrInUse);
       
   482      		}
       
   483 		if(!iPowerOn || iViewFinderActive)
       
   484 			{
       
   485 			User::Leave(KErrNotReady);
       
   486 			}
       
   487 		
       
   488 		iViewFinderActive = ETrue;
       
   489 		iClipRect = aClipRect;
       
   490 		if(!(aImageFormat & iInfo.iImageFormatsSupported))
       
   491 			{
       
   492 			 User::Leave(KErrNotSupported);
       
   493 			}
       
   494        }
       
   495        
       
   496 
       
   497 void CTestCamera::StopViewFinder()
       
   498 	{
       
   499 	iViewFinderActive = EFalse;
       
   500 	delete iDSA;
       
   501 	iDSA = NULL;
       
   502 
       
   503 	delete iViewFinderBitmapGc;
       
   504 	iViewFinderBitmapGc = NULL;
       
   505 	delete iViewFinderBitmapDev;
       
   506 	iViewFinderBitmapDev = NULL;
       
   507 	delete iViewFinderBitmap;
       
   508 	iViewFinderBitmap = NULL;
       
   509 	}
       
   510 
       
   511 TBool CTestCamera::ViewFinderActive() const
       
   512 	{
       
   513 	return iViewFinderActive;
       
   514 	}
       
   515 
       
   516 void CTestCamera::SetViewFinderMirrorL(TBool aMirror)
       
   517 	{
       
   518 	if (aMirror)
       
   519 		{
       
   520 		User::Leave(KErrNotSupported);	
       
   521 		}
       
   522 	}
       
   523 
       
   524 TBool CTestCamera::ViewFinderMirror() const
       
   525 	{
       
   526 	return EFalse;
       
   527 	}
       
   528 
       
   529 void CTestCamera::PrepareImageCaptureL(TFormat aImageFormat,TInt aSizeIndex)
       
   530 	{
       
   531 	if (!iReserved)
       
   532 		{
       
   533 		User::Leave(KErrInUse);
       
   534 		}
       
   535 		
       
   536 	if (!iPowerOn || iVideoCaptureActive || iImageCaptureActive)
       
   537 		{
       
   538 		User::Leave(KErrNotReady);
       
   539 		}
       
   540 		
       
   541 
       
   542 	if (!(aImageFormat & iInfo.iImageFormatsSupported) || aSizeIndex < 0
       
   543 		|| aSizeIndex >= iInfo.iNumImageSizesSupported)
       
   544 		{
       
   545 		User::Leave(KErrNotSupported);
       
   546 		}
       
   547 
       
   548 	iVideoPreparedLast = EFalse;
       
   549 
       
   550 	if (iImageCapturePrepared
       
   551 		&& iStillImageSize == iImageSizes[aSizeIndex]
       
   552 		&& iStillImageFormat == aImageFormat)
       
   553 		{
       
   554 		return;
       
   555 		}
       
   556 
       
   557 	iStillImageSize = iImageSizes[aSizeIndex];
       
   558 	iStillImageFormat = aImageFormat;
       
   559 
       
   560 	TDisplayMode displayMode = ENone;
       
   561 	switch (iStillImageFormat)
       
   562 		{
       
   563 		case EFormatFbsBitmapColor4K :
       
   564 			displayMode = EColor4K;
       
   565 			break;
       
   566 		case EFormatFbsBitmapColor64K :
       
   567 			displayMode = EColor64K;
       
   568 			break;
       
   569 		case EFormatFbsBitmapColor16M :
       
   570 			displayMode = EColor16M;
       
   571 			break;
       
   572 		default :
       
   573 			User::Leave(KErrNotSupported);
       
   574 			break;
       
   575 		}
       
   576 
       
   577 	delete iStillImageGc;
       
   578 	iStillImageGc = NULL;
       
   579 	delete iStillImageDev;
       
   580 	iStillImageDev = NULL;
       
   581 	delete iStillImage;
       
   582 	iStillImage = NULL;
       
   583 
       
   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;
       
   593 	}
       
   594 
       
   595 void CTestCamera::PrepareImageCaptureL(TFormat /*aImageFormat*/,TInt /*aSizeIndex*/,const TRect& /*aClipRect*/)
       
   596 	{
       
   597 	User::Leave(KErrNotSupported);
       
   598 	}
       
   599 
       
   600 void CTestCamera::CaptureImage()
       
   601 	{
       
   602 	if (!iReserved)
       
   603 		{
       
   604 		iStillCaptureErr = KErrInUse;
       
   605 		}
       
   606 		
       
   607 	if (!iPowerOn || iImageCaptureActive || iVideoCaptureActive || !iImageCapturePrepared)
       
   608 		{
       
   609 		iStillCaptureErr = KErrNotReady;
       
   610 		}
       
   611 
       
   612 	if (iStillCaptureErr == KErrNone)
       
   613 		{
       
   614 		TRAP(iStillCaptureErr,DoCaptureImageL());
       
   615 		}
       
   616 
       
   617 	if (iStillCaptureErr == KErrNone)
       
   618 		{
       
   619 		iImageCaptureActive = ETrue;
       
   620 		}
       
   621 	else
       
   622 		{
       
   623 		iImageCaptureAsync.CallBack();
       
   624 		}
       
   625 	}
       
   626 
       
   627 void CTestCamera::DoCaptureImageL()
       
   628 	{
       
   629 	delete iGc;
       
   630 	iGc = NULL;
       
   631 	delete iDev;
       
   632 	iDev = NULL;
       
   633 	delete iImage;
       
   634 	iImage = NULL;
       
   635 
       
   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);
       
   645 
       
   646 	iImage = image;
       
   647 	iDev = dev;
       
   648 	iGc = gc;
       
   649 	}
       
   650 
       
   651 void CTestCamera::CancelCaptureImage()
       
   652 	{
       
   653 	iImageCaptureActive = EFalse;
       
   654 	}
       
   655 
       
   656 void CTestCamera::EnumerateCaptureSizes(TSize& aSize,TInt aSizeIndex,TFormat aFormat) const
       
   657 	{
       
   658 	if (aSizeIndex < 0 || aSizeIndex >= iInfo.iNumImageSizesSupported ||
       
   659 		!(aFormat & iInfo.iImageFormatsSupported) )
       
   660 		{
       
   661 		aSize = TSize(0,0);
       
   662 		}
       
   663 	else
       
   664 		{
       
   665 		aSize = iImageSizes[aSizeIndex];
       
   666 		}
       
   667 	}
       
   668 
       
   669 void CTestCamera::PrepareVideoCaptureL(TFormat aFormat,TInt aSizeIndex,TInt aRateIndex,TInt aBuffersToUse,TInt aFramesPerBuffer)
       
   670 	{
       
   671 	if (!iReserved)
       
   672 		{
       
   673 		User::Leave(KErrInUse);
       
   674 		}
       
   675 		
       
   676 	if (!iPowerOn || iVideoCaptureActive || iImageCaptureActive)
       
   677 		{
       
   678 		User::Leave(KErrNotReady);
       
   679 		}
       
   680 
       
   681 	if (!(aFormat & iInfo.iVideoFrameFormatsSupported) 
       
   682 		|| aSizeIndex < 0 || aSizeIndex >= iInfo.iNumVideoFrameSizesSupported
       
   683 		|| aRateIndex < 0 || aRateIndex >= iInfo.iNumVideoFrameRatesSupported
       
   684 		|| aBuffersToUse != 2 || aFramesPerBuffer != 1)
       
   685 		{
       
   686 		User::Leave(KErrNotSupported);
       
   687 		}
       
   688 
       
   689 	iVideoPreparedLast = ETrue;
       
   690 
       
   691 	if (iVideoCapturePrepared 
       
   692 		&& iVideoFrameSize == iVideoFrameSizes[aSizeIndex]
       
   693 		&& iVideoFrameFormat == aFormat)
       
   694 		{
       
   695 		return;
       
   696 		}
       
   697 
       
   698 	TDisplayMode displayMode = ENone;
       
   699 	switch (aFormat)
       
   700 		{
       
   701 		case EFormatFbsBitmapColor4K :
       
   702 			displayMode = EColor4K;
       
   703 			break;
       
   704 		case EFormatFbsBitmapColor64K :
       
   705 			displayMode = EColor64K;
       
   706 			break;
       
   707 		case EFormatFbsBitmapColor16M :
       
   708 			displayMode = EColor16M;
       
   709 			break;
       
   710 		default :
       
   711 			User::Leave(KErrNotSupported);
       
   712 			break;
       
   713 		}
       
   714 
       
   715 	iVideoFrameSize = iVideoFrameSizes[aSizeIndex];
       
   716 	iVideoFrameRate = iVideoFrameRates[aRateIndex];
       
   717 	iVideoFrameFormat = aFormat;
       
   718 	iBuffersInUse = aBuffersToUse;
       
   719 
       
   720 	delete iVideoFrameGc1;
       
   721 	iVideoFrameGc1 = NULL;
       
   722 	delete iVideoFrameDev1;
       
   723 	iVideoFrameDev1 = NULL;
       
   724 	delete iVideoFrame1;
       
   725 	iVideoFrame1 = NULL;
       
   726 
       
   727 	delete iVideoFrameGc2;
       
   728 	iVideoFrameGc2 = NULL;
       
   729 	delete iVideoFrameDev2;
       
   730 	iVideoFrameDev2 = NULL;
       
   731 	delete iVideoFrame2;
       
   732 	iVideoFrame2 = NULL;
       
   733 
       
   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);
       
   742 
       
   743 	if (iBuffersInUse == 2)
       
   744 		{
       
   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);		
       
   753 		}
       
   754 
       
   755 	iVideoCapturePrepared = ETrue;
       
   756 	}
       
   757 
       
   758 void CTestCamera::PrepareVideoCaptureL(TFormat /*aFormat*/,TInt /*aSizeIndex*/,TInt /*aRateIndex*/,TInt /*aBuffersToUse*/,TInt /*aFramesPerBuffer*/,const TRect& /*aClipRect*/)
       
   759 	{
       
   760 	User::Leave(KErrNotSupported);
       
   761 	}
       
   762 
       
   763 void CTestCamera::StartVideoCapture()
       
   764 	{
       
   765 	if (!iReserved)
       
   766 		{
       
   767 		iVideoCaptureErr = KErrInUse;
       
   768 		}
       
   769 		
       
   770 	if (!iPowerOn || iImageCaptureActive || iVideoCaptureActive || !iVideoCapturePrepared)
       
   771 		{
       
   772 		iVideoCaptureErr = KErrNotReady;
       
   773 		}
       
   774 		
       
   775 	if (iVideoCaptureErr == KErrNone)
       
   776 		{
       
   777 		iVideoCaptureActive = ETrue;
       
   778 		}
       
   779 		
       
   780 	else
       
   781 		{
       
   782 		iVideoCaptureAsync.CallBack();
       
   783 		}
       
   784 	}
       
   785 
       
   786 void CTestCamera::StopVideoCapture()
       
   787 	{
       
   788 	iVideoCaptureActive = EFalse;
       
   789 	iFrameIndex = 0;
       
   790 	iElapsedTime = 0;
       
   791 	}
       
   792 
       
   793 TBool CTestCamera::VideoCaptureActive() const
       
   794 	{
       
   795 	return iVideoCaptureActive;
       
   796 	}
       
   797 
       
   798 void CTestCamera::EnumerateVideoFrameSizes(TSize& aSize,TInt aSizeIndex,TFormat aFormat) const
       
   799 	{
       
   800 	if (aSizeIndex < 0 || aSizeIndex >= iInfo.iNumVideoFrameSizesSupported ||
       
   801 		!(aFormat & iInfo.iVideoFrameFormatsSupported))
       
   802 		{
       
   803 		aSize = TSize(0,0);
       
   804 		}
       
   805 	else
       
   806 		{
       
   807 		aSize = iVideoFrameSizes[aSizeIndex];
       
   808 		}
       
   809 	}
       
   810 
       
   811 void CTestCamera::EnumerateVideoFrameRates(TReal32& aRate,TInt aRateIndex,TFormat aFormat,TInt aSizeIndex,TExposure aExposure) const
       
   812 	{
       
   813 	if (aRateIndex < 0 || aRateIndex >= iInfo.iNumVideoFrameRatesSupported ||
       
   814 		aSizeIndex < 0 || aSizeIndex >= iInfo.iNumVideoFrameSizesSupported ||
       
   815 		!(aFormat & iInfo.iVideoFrameFormatsSupported) ||
       
   816 		(!(aExposure & iInfo.iExposureModesSupported) && aExposure != CCamera::EExposureAuto))
       
   817 		{
       
   818 		aRate = 0.0;
       
   819 		}
       
   820 	else
       
   821 		{
       
   822 		aRate = iVideoFrameRates[aRateIndex];
       
   823 		}
       
   824 	}
       
   825 
       
   826 void CTestCamera::GetFrameSize(TSize& aSize) const
       
   827 	{
       
   828 	aSize = iVideoFrameSize;
       
   829 	}
       
   830 
       
   831 TReal32 CTestCamera::FrameRate() const
       
   832 	{
       
   833 	return iVideoFrameRate;
       
   834 	}
       
   835 
       
   836 TInt CTestCamera::BuffersInUse() const
       
   837 	{
       
   838 	return iBuffersInUse;
       
   839 	}
       
   840 
       
   841 TInt CTestCamera::FramesPerBuffer() const
       
   842 	{
       
   843 	return 1;
       
   844 	}
       
   845 
       
   846 void CTestCamera::SetJpegQuality(TInt /*aQuality*/)
       
   847 	{
       
   848 	}
       
   849 
       
   850 TInt CTestCamera::JpegQuality() const
       
   851 	{
       
   852 	return 0;
       
   853 	}
       
   854 
       
   855 TAny* CTestCamera::CustomInterface(TUid aInterface)
       
   856 	{
       
   857 	TAny* ptrIface = NULL;
       
   858 	TRAPD(error,CustomInterfaceL(ptrIface, aInterface));
       
   859 	
       
   860 	if(error == KErrNone)
       
   861 		{
       
   862 		switch(aInterface.iUid)
       
   863 			{
       
   864 			// advanced settings interface pointers
       
   865 			case KECamMCameraAdvancedSettingsUidValue:
       
   866 				{
       
   867 				return static_cast<MCameraAdvancedSettings*>(ptrIface);
       
   868 				}
       
   869 			case KECamMCameraAdvancedSettings2UidValue:
       
   870 				{
       
   871 				return static_cast<MCameraAdvancedSettings2*>(ptrIface);			
       
   872 				}
       
   873 			case KECamMCameraAdvancedSettings3UidValue:
       
   874 				{
       
   875 				return static_cast<MCameraAdvancedSettings3*>(ptrIface);
       
   876 				}
       
   877 			
       
   878 			// snapshot interface pointers	
       
   879 			case KECamMCameraSnapshotUidValue:
       
   880 				{
       
   881 				return static_cast<MCameraSnapshot*>(ptrIface);
       
   882 				}
       
   883 				
       
   884 			// preset interface pointers	
       
   885 			case KECamMCameraPresetsUidValue:
       
   886 				return static_cast<MCameraPresets*>(ptrIface);
       
   887 				
       
   888 			// image processing interface pointers
       
   889 			case KECamMCameraImageProcessingUidValue:
       
   890 				{
       
   891 				return static_cast<MCameraImageProcessing*>(ptrIface);
       
   892 				}
       
   893 				
       
   894 			case KECamMCameraImageProcessing2UidValue:
       
   895 				{
       
   896 				return static_cast<MCameraImageProcessing2*>(ptrIface);
       
   897 				}
       
   898 				
       
   899 			default:
       
   900 				return NULL;
       
   901 			}
       
   902 		}
       
   903 	else
       
   904 		{
       
   905 		return NULL;		
       
   906 		}
       
   907 	}
       
   908 
       
   909 void CTestCamera::CustomInterfaceL(TAny*& aIface, TUid aInterface)
       
   910 	{
       
   911 	switch(aInterface.iUid)
       
   912 		{
       
   913 		// advanced settings interface pointers
       
   914 		case KECamMCameraAdvancedSettingsUidValue:
       
   915 			{
       
   916 			iAdvSettingsImpl = CTestCamAdvSet::NewL(*this);
       
   917 			aIface = static_cast<MCameraAdvancedSettings*>(iAdvSettingsImpl);
       
   918 			break;
       
   919 			}
       
   920 		case KECamMCameraAdvancedSettings2UidValue:
       
   921 			{
       
   922 			iAdvSettingsImpl = CTestCamAdvSet::NewL(*this);
       
   923 			aIface = static_cast<MCameraAdvancedSettings2*>(iAdvSettingsImpl);			
       
   924 			break;
       
   925 			}
       
   926 		case KECamMCameraAdvancedSettings3UidValue:
       
   927 			{
       
   928 			iAdvSettingsImpl = CTestCamAdvSet::NewL(*this);
       
   929 			aIface = static_cast<MCameraAdvancedSettings3*>(iAdvSettingsImpl);
       
   930 			break;
       
   931 			}
       
   932 		
       
   933 		// snapshot interface pointers	
       
   934 		case KECamMCameraSnapshotUidValue:
       
   935 			{
       
   936 			iSnapshotImpl = CTestCamSnapshot::NewL(*this);
       
   937 			aIface = static_cast<MCameraSnapshot*>(iSnapshotImpl);
       
   938 			break;
       
   939 			}
       
   940 		// preset interface pointers	
       
   941 		case KECamMCameraPresetsUidValue:
       
   942 			{
       
   943 			aIface = static_cast<MCameraPresets*>(CTestCamPresets::NewL(*this));
       
   944 			break;
       
   945 			}
       
   946 			
       
   947 		// image processing interface pointers
       
   948 		case KECamMCameraImageProcessingUidValue:
       
   949 			{
       
   950 			iImgProcImpl = CTestCamImgProc::NewL(*this);	
       
   951 			aIface = static_cast<MCameraImageProcessing*>(iImgProcImpl);
       
   952 			break;
       
   953 			}
       
   954 			
       
   955 		case KECamMCameraImageProcessing2UidValue:
       
   956 			{
       
   957 			iImgProcImpl = CTestCamImgProc::NewL(*this);	
       
   958 			aIface = static_cast<MCameraImageProcessing2*>(iImgProcImpl);
       
   959 			break;
       
   960 			}
       
   961 			
       
   962 		default:
       
   963 			aIface = NULL;
       
   964 		}
       
   965 	}
       
   966 
       
   967 void CTestCamera::AbortNow(RDirectScreenAccess::TTerminationReasons /*aReason*/)
       
   968 	{
       
   969 	iViewFinderActive = EFalse;
       
   970 	}
       
   971 
       
   972 void CTestCamera::Restart(RDirectScreenAccess::TTerminationReasons /*aReason*/)
       
   973 	{
       
   974 	TRAPD(error,iDSA->StartL());
       
   975 	if (error != KErrNone)
       
   976 		{
       
   977 		return;
       
   978 		}
       
   979 	iDSA->Gc()->SetOrigin(); // Set Origin to top left of screen (0,0)
       
   980 
       
   981 	if (!iClipRect.IsEmpty())
       
   982 		{
       
   983 		iDSA->Gc()->SetClippingRect(iClipRect);
       
   984 		}
       
   985 	else
       
   986 		{
       
   987 		iDSA->Gc()->CancelClippingRect();
       
   988 		}
       
   989 
       
   990 	iViewFinderActive = ETrue;
       
   991 	}
       
   992 
       
   993 TInt CTestCamera::TimerCallBack(TAny* aThis)
       
   994 	{
       
   995 	static_cast<CTestCamera*>(aThis)->FrameReady();
       
   996 	return KErrNone;
       
   997 	}
       
   998 
       
   999 void CTestCamera::FrameReady()
       
  1000 	{
       
  1001 	if (iVideoPreparedLast)
       
  1002 		{
       
  1003 		iVideoFramePos.iX += KFramePosIncrement;
       
  1004 		iVideoFramePos.iY += KFramePosIncrement;
       
  1005 
       
  1006 		if (iVideoFramePos.iX >= iVideoFrameSize.iWidth)
       
  1007 			{
       
  1008 			iVideoFramePos.iX = 0;
       
  1009 			}
       
  1010 			
       
  1011 		if (iVideoFramePos.iY >= iVideoFrameSize.iHeight)
       
  1012 			{
       
  1013 			iVideoFramePos.iY = 0;
       
  1014 			}
       
  1015 		}
       
  1016 	else
       
  1017 		{
       
  1018 		iStillImagePos.iX += KFramePosIncrement;
       
  1019 		iStillImagePos.iY += KFramePosIncrement;
       
  1020 
       
  1021 		if (iStillImagePos.iX >= iStillImageSize.iWidth)
       
  1022 			{
       
  1023 			iStillImagePos.iX = 0;
       
  1024 			}
       
  1025 			
       
  1026 		if (iStillImagePos.iY >= iStillImageSize.iHeight)
       
  1027 			{
       
  1028 			iStillImagePos.iY = 0;
       
  1029 			}
       
  1030 		}
       
  1031 
       
  1032 	if (iImageCaptureActive)
       
  1033 		{
       
  1034 		if (!iImageCapturePrepared)
       
  1035 			{
       
  1036 			iImageCaptureActive = EFalse;
       
  1037 			if (iObserver2)
       
  1038 				{
       
  1039 				iObserver2->ImageBufferReady(iFrameCameraBuffer1,KErrNotReady);
       
  1040 				}
       
  1041 			else
       
  1042 				{
       
  1043 				iObserver->ImageReady(NULL,NULL,KErrNotReady);
       
  1044 				}
       
  1045 			}
       
  1046 		else
       
  1047 			{
       
  1048 			if(iDriveMode == CCamera::CCameraAdvancedSettings::EDriveModeBurst)
       
  1049 				{
       
  1050 				for (TInt index =0; index < iBurstImages -1; index++)
       
  1051 					{
       
  1052 					if(iSnapshotImpl != NULL)
       
  1053 						{
       
  1054 						if(iSnapshotImpl->iSnapshotActive)
       
  1055 							{
       
  1056 							GetFrame(*(iSnapshotImpl->iSnapshotImageGc), iStillImagePos);
       
  1057 							iSnapshotImpl->ServiceBurstImageSnapshot(*(iSnapshotImpl->iSnapshotImageGc));
       
  1058 							}
       
  1059 						}
       
  1060 					
       
  1061 					GetImgProcessedFrame(*iStillImageGc, iStillImagePos);
       
  1062 					ServiceBurstImageCapture(*iStillImageGc);
       
  1063 					}
       
  1064 				}
       
  1065 				
       
  1066 			// normal case, single shot and last image from burst mode
       
  1067 			if(iSnapshotImpl != NULL)
       
  1068 				{
       
  1069 				if(iSnapshotImpl->iSnapshotActive)
       
  1070 					{
       
  1071 					GetFrame(*iSnapshotImpl->iSnapshotImageGc, iStillImagePos);
       
  1072 					iSnapshotImpl->ServiceSnapshot(*(iSnapshotImpl->iSnapshotImageGc));
       
  1073 					}
       
  1074 				}
       
  1075 				
       
  1076 			GetImgProcessedFrame(*iStillImageGc, iStillImagePos);
       
  1077 			ServiceImageCapture(*iStillImageGc);	
       
  1078 							
       
  1079 			if (iVideoPreparedLast)
       
  1080 				{
       
  1081 				GetFrame(*iVideoFrameGc1, iVideoFramePos);
       
  1082 				if (iViewFinderActive)
       
  1083 					{
       
  1084 					ServiceViewFinder(iVideoFrame1);
       
  1085 					}	
       
  1086 				}
       
  1087 			else
       
  1088 				{
       
  1089 				if (iViewFinderActive)
       
  1090 					{
       
  1091 					ServiceViewFinder(iStillImage);
       
  1092 					}
       
  1093 				}
       
  1094 			}
       
  1095 		}
       
  1096 
       
  1097 	else if (iVideoCaptureActive)
       
  1098 		{
       
  1099 		if (!iVideoCapturePrepared)
       
  1100 			{
       
  1101 			iVideoCaptureActive = EFalse;
       
  1102 			if (iObserver2)
       
  1103 				{
       
  1104 				iObserver2->VideoBufferReady(iFrameCameraBuffer1,KErrNotReady);
       
  1105 				}
       
  1106 			else
       
  1107 				{
       
  1108 				iObserver->FrameBufferReady(NULL,KErrNotReady);
       
  1109 				}
       
  1110 			}
       
  1111 		else
       
  1112 			{
       
  1113 			if (iObserver2)
       
  1114 				{
       
  1115 				if (iFrameCameraBuffer1.iAvailable)
       
  1116 					{
       
  1117 					GetFrame(*iVideoFrameGc1, iVideoFramePos);
       
  1118 					ServiceVideo(1);
       
  1119 					if (iViewFinderActive)
       
  1120 						{
       
  1121 						ServiceViewFinder(iVideoFrame1);
       
  1122 						}
       
  1123 					}
       
  1124 				else if (iFrameCameraBuffer2.iAvailable && iBuffersInUse == 2)
       
  1125 					{
       
  1126 					GetFrame(*iVideoFrameGc2, iVideoFramePos);
       
  1127 					ServiceVideo(2);
       
  1128 					if (iViewFinderActive)
       
  1129 						{
       
  1130 						ServiceViewFinder(iVideoFrame2);
       
  1131 						}
       
  1132 					}
       
  1133 				}
       
  1134 			else
       
  1135 				{
       
  1136 				if (iFrameBuffer1.iAvailable)
       
  1137 					{
       
  1138 					GetFrame(*iVideoFrameGc1, iVideoFramePos);
       
  1139 					ServiceVideo(1);
       
  1140 					if (iViewFinderActive)
       
  1141 						{
       
  1142 						ServiceViewFinder(iVideoFrame1);
       
  1143 						}
       
  1144 					}
       
  1145 				else if (iFrameBuffer2.iAvailable && iBuffersInUse == 2)
       
  1146 					{
       
  1147 					GetFrame(*iVideoFrameGc2, iVideoFramePos);
       
  1148 					ServiceVideo(2);
       
  1149 					if (iViewFinderActive)
       
  1150 						{
       
  1151 						ServiceViewFinder(iVideoFrame2);
       
  1152 						}
       
  1153 					}
       
  1154 				}
       
  1155 			}
       
  1156 	}
       
  1157 
       
  1158 	else if (iViewFinderActive)
       
  1159 		{
       
  1160 		if (iVideoPreparedLast)
       
  1161 			{
       
  1162 			GetFrame(*iVideoFrameGc1, iVideoFramePos);
       
  1163 			ServiceViewFinder(iVideoFrame1);
       
  1164 			}
       
  1165 			else
       
  1166 			{
       
  1167 			GetFrame(*iStillImageGc, iStillImagePos);
       
  1168 			ServiceViewFinder(iStillImage);
       
  1169 			}
       
  1170 		}
       
  1171 	}
       
  1172 
       
  1173 void CTestCamera::GetFrame(CFbsBitGc& aGc, TPoint& aPos) const
       
  1174 	{
       
  1175 	TInt black = (100 - iContrast) * 127 / 200;
       
  1176 	TInt white = ((100 + iContrast) * 128 / 200) + 127;
       
  1177 
       
  1178 	const TInt brightAdjust = iBrightness * 255 / 100;
       
  1179 	black += brightAdjust;
       
  1180 	white += brightAdjust;
       
  1181 
       
  1182 	black = Min(Max(black,0),255);
       
  1183 	white = Min(Max(white,0),255);
       
  1184 
       
  1185 	aGc.SetFadingParameters(TUint8(black),TUint8(white));
       
  1186 	aGc.Clear();
       
  1187 	aGc.DrawRect(TRect(aPos,TSize(KFrameFeatureSize,KFrameFeatureSize)));
       
  1188 	}
       
  1189 	
       
  1190 void CTestCamera::GetImgProcessedFrame(CFbsBitGc& aGc, TPoint& aPos) const
       
  1191 	{
       
  1192 	TInt contrast = iContrast;
       
  1193 	TInt brightness = iBrightness;
       
  1194 	
       
  1195 	if(iImgProcImpl != NULL)
       
  1196 		{
       
  1197 		for(TInt index=0; index<iImgProcImpl->iActiveTransformations.Count(); index++)
       
  1198 			{
       
  1199 			switch(iImgProcImpl->iActiveTransformations[index].iUid)
       
  1200 				{
       
  1201 				case KUidECamEventImageProcessingAdjustBrightnessUidValue:
       
  1202 					{
       
  1203 					brightness = iImgProcBrightness;
       
  1204 					break;
       
  1205 					}
       
  1206 				case KUidECamEventImageProcessingAdjustContrastUidValue:
       
  1207 					{
       
  1208 					contrast = iImgProcContrast;
       
  1209 					break;
       
  1210 					}
       
  1211 				default:
       
  1212 					{
       
  1213 					break;
       
  1214 					}
       
  1215 				}
       
  1216 			}
       
  1217 		}
       
  1218 	
       
  1219 	TInt black = (100 - contrast) * 127 / 200;
       
  1220 	TInt white = ((100 + contrast) * 128 / 200) + 127;
       
  1221 
       
  1222 	const TInt brightAdjust = brightness * 255 / 100;
       
  1223 	black += brightAdjust;
       
  1224 	white += brightAdjust;
       
  1225 
       
  1226 	black = Min(Max(black,0),255);
       
  1227 	white = Min(Max(white,0),255);
       
  1228 
       
  1229 	aGc.SetFadingParameters(TUint8(black),TUint8(white));
       
  1230 	aGc.Clear();
       
  1231 	aGc.DrawRect(TRect(aPos,TSize(KFrameFeatureSize,KFrameFeatureSize)));
       
  1232 	}
       
  1233 	
       
  1234 void CTestCamera::ServiceVideo(TInt aBufferNum)
       
  1235 	{
       
  1236 	iFrameIndex++;
       
  1237 	iElapsedTime = iElapsedTime.Int64() + (TInt64(1000000) / TInt64(iVideoFrameRate));
       
  1238 
       
  1239 	if (aBufferNum == 1)
       
  1240 		{
       
  1241 		if (iObserver2)
       
  1242 			{
       
  1243 			iFrameCameraBuffer1.iIndexOfFirstFrameInBuffer = iFrameIndex;
       
  1244 			iFrameCameraBuffer1.iElapsedTime = iElapsedTime;
       
  1245 			iFrameCameraBuffer1.iAvailable = EFalse;
       
  1246 			}
       
  1247 		else
       
  1248 			{
       
  1249 			iFrameBuffer1.iIndexOfFirstFrameInBuffer = iFrameIndex;
       
  1250 			iFrameBuffer1.iElapsedTime = iElapsedTime;
       
  1251 			iFrameBuffer1.iAvailable = EFalse;
       
  1252 			}
       
  1253 			
       
  1254 		if (iObserver2)
       
  1255 			{
       
  1256 			iObserver2->VideoBufferReady(iFrameCameraBuffer1,KErrNone);
       
  1257 			}
       
  1258 		else
       
  1259 			{
       
  1260 			iObserver->FrameBufferReady(&iFrameBuffer1,KErrNone);
       
  1261 			}
       
  1262 		}
       
  1263 	else if (aBufferNum == 2)
       
  1264 		{
       
  1265 		if (iObserver2)
       
  1266 			{
       
  1267 			iFrameCameraBuffer2.iIndexOfFirstFrameInBuffer = iFrameIndex;
       
  1268 			iFrameCameraBuffer2.iElapsedTime = iElapsedTime;
       
  1269 			iFrameCameraBuffer2.iAvailable = EFalse;
       
  1270 			}
       
  1271 		else
       
  1272 			{
       
  1273 			iFrameBuffer2.iIndexOfFirstFrameInBuffer = iFrameIndex;
       
  1274 			iFrameBuffer2.iElapsedTime = iElapsedTime;
       
  1275 			iFrameBuffer2.iAvailable = EFalse;
       
  1276 			}
       
  1277 			
       
  1278 		if (iObserver2)
       
  1279 			{
       
  1280 			iObserver2->VideoBufferReady(iFrameCameraBuffer2,KErrNone);
       
  1281 			}
       
  1282 		else
       
  1283 			{
       
  1284 			iObserver->FrameBufferReady(&iFrameBuffer2,KErrNone);
       
  1285 			}
       
  1286 		}
       
  1287 	}
       
  1288 
       
  1289 void CTestCamera::ServiceViewFinder(CFbsBitmap* aSourceFrame)
       
  1290 	{
       
  1291 	if (iDSA)
       
  1292 		{
       
  1293 		iDSA->Gc()->DrawBitmap(iScreenRect,aSourceFrame);
       
  1294 		iDSA->ScreenDevice()->Update();
       
  1295 		}
       
  1296 	else if (iViewFinderBitmap)
       
  1297 		{
       
  1298 		if (iViewFinderBitmapGc)
       
  1299 			{
       
  1300 			if (!iClipRect.IsEmpty())
       
  1301 				{
       
  1302 				TReal32 xRatio = static_cast<TReal32>(aSourceFrame->SizeInPixels().iWidth) / 
       
  1303 								 static_cast<TReal32>(iClipRect.Size().iWidth);
       
  1304 
       
  1305 				TReal32 yRatio = static_cast<TReal32>(aSourceFrame->SizeInPixels().iHeight) / 
       
  1306 								 static_cast<TReal32>(iClipRect.Size().iHeight);
       
  1307 
       
  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)));
       
  1312 
       
  1313 				TRect destRect(TPoint(0,0), iClipRect.Size());
       
  1314 
       
  1315 				iViewFinderBitmapGc->DrawBitmap(destRect,
       
  1316 												aSourceFrame,
       
  1317 												sourceRect);
       
  1318 				}
       
  1319 			else
       
  1320 				{
       
  1321 				TRect destRect(TPoint(0,0), iViewFinderBitmap->SizeInPixels());
       
  1322 				iViewFinderBitmapGc->DrawBitmap(destRect, aSourceFrame);
       
  1323 				}
       
  1324 				
       
  1325 			if (iObserver2)
       
  1326 				{
       
  1327 				iObserver2->ViewFinderReady(iFrameCameraBuffer1,KErrNone);
       
  1328 				}
       
  1329 			else
       
  1330 				{
       
  1331 				iObserver->ViewFinderFrameReady(*iViewFinderBitmap);
       
  1332 				}
       
  1333 		
       
  1334 			}
       
  1335 		}
       
  1336 	else
       
  1337 		{
       
  1338 		iScreenGc->DrawBitmap(iClipRect,aSourceFrame);
       
  1339 		iScreenDev->Update();
       
  1340 		}
       
  1341 	}
       
  1342 
       
  1343 void CTestCamera::ServiceImageCapture(const CFbsBitGc& aSourceBitmapGc)
       
  1344 	{
       
  1345 	iImageCaptureActive = EFalse;
       
  1346 	iGc->BitBlt(TPoint(0,0), aSourceBitmapGc);
       
  1347 	CFbsBitmap* image = iImage;
       
  1348 	RTestCameraFrameBuffer frameBuffer(image);
       
  1349 	delete iGc;
       
  1350 	iGc = NULL;
       
  1351 	delete iDev;
       
  1352 	iDev = NULL;
       
  1353 	if (iObserver2 != NULL)
       
  1354 		{
       
  1355 		iObserver2->ImageBufferReady(frameBuffer,KErrNone);
       
  1356 		}
       
  1357 	else
       
  1358 		{
       
  1359 		iImage = NULL;
       
  1360 		iObserver->ImageReady(image,NULL,KErrNone);
       
  1361 		}
       
  1362 	}
       
  1363 	
       
  1364 void CTestCamera::ServiceBurstImageCapture(const CFbsBitGc& aSourceBitmapGc)
       
  1365 	{
       
  1366 	iGc->BitBlt(TPoint(0,0), aSourceBitmapGc);
       
  1367 	if (iObserver2 != NULL)
       
  1368 		{
       
  1369 		CFbsBitmap* image = iImage;
       
  1370 		RTestCameraFrameBuffer frameBuffer(image);
       
  1371 		iObserver2->ImageBufferReady(frameBuffer,KErrNone);
       
  1372 		}
       
  1373 	else//not for MCameraObserver
       
  1374 		{
       
  1375 		return;
       
  1376 		}
       
  1377 	
       
  1378 	if(iSnapshotImpl)
       
  1379 		{
       
  1380 		if(iSnapshotImpl->iSnapshotActive)
       
  1381 			{
       
  1382 			return;
       
  1383 			}
       
  1384 		}
       
  1385 	User::After(500000);
       
  1386 	iStillImagePos.iX += KFramePosIncrement;
       
  1387 	iStillImagePos.iY += KFramePosIncrement;
       
  1388 
       
  1389 	if (iStillImagePos.iX >= iStillImageSize.iWidth)
       
  1390 		{
       
  1391 		iStillImagePos.iX = 0;
       
  1392 		}
       
  1393 			
       
  1394 	if (iStillImagePos.iY >= iStillImageSize.iHeight)
       
  1395 		{
       
  1396 		iStillImagePos.iY = 0;
       
  1397 		}
       
  1398 	}
       
  1399 
       
  1400 void CTestCamera::CheckReserveAndPowerL()
       
  1401 	{
       
  1402 	if (!iReserved)
       
  1403 		{
       
  1404 		User::Leave(KErrInUse);
       
  1405 		}
       
  1406 		
       
  1407 	if (!iPowerOn)
       
  1408 		{
       
  1409 		User::Leave(KErrNotReady);
       
  1410 		}	
       
  1411 	}
       
  1412 
       
  1413 TInt CTestCamera::CheckReserveAndPower() const
       
  1414 	{
       
  1415 	if (!iReserved)
       
  1416 		{
       
  1417 		return KErrInUse;
       
  1418 		}
       
  1419 		
       
  1420 	if (!iPowerOn)
       
  1421 		{
       
  1422 		return KErrNotReady;
       
  1423 		}	
       
  1424 	
       
  1425 	return KErrNone;
       
  1426 	}
       
  1427 
       
  1428 TInt CTestCamera::ReserveCallBack(TAny* aThis)
       
  1429 	{
       
  1430 	const TECAMEvent event(KUidECamEventReserveComplete,KErrNone);
       
  1431 	CTestCamera* testCamera = static_cast<CTestCamera*>(aThis);
       
  1432 	if (testCamera->iObserver2)
       
  1433 		{
       
  1434 		testCamera->iObserver2->HandleEvent(event);
       
  1435 		}
       
  1436 	else
       
  1437 		{
       
  1438 		testCamera->iObserver->ReserveComplete(KErrNone);
       
  1439 		}
       
  1440 	return KErrNone;
       
  1441 	}
       
  1442 
       
  1443 TInt CTestCamera::PowerOnCallBack(TAny* aThis)
       
  1444 	{
       
  1445 	TECAMEvent event(KUidECamEventPowerOnComplete,KErrNone);
       
  1446 	CTestCamera* testCamera = static_cast<CTestCamera*>(aThis);
       
  1447 	if (testCamera->iObserver2)
       
  1448 		{
       
  1449 		testCamera->iObserver2->HandleEvent(event);
       
  1450 		}
       
  1451 	else
       
  1452 		{
       
  1453 		testCamera->iObserver->PowerOnComplete(testCamera->iPowerOn ? KErrNone : KErrInUse);
       
  1454 		}
       
  1455 	return KErrNone;
       
  1456 	}
       
  1457 
       
  1458 TInt CTestCamera::ImageCaptureCallBack(TAny* aThis)
       
  1459 	{
       
  1460 	CTestCamera* testCamera = static_cast<CTestCamera*>(aThis);
       
  1461 	if (testCamera->iObserver2)
       
  1462 		{
       
  1463 		testCamera->iObserver2->ImageBufferReady((static_cast<CTestCamera*>(aThis))->iFrameCameraBuffer1,testCamera->iStillCaptureErr);
       
  1464 		}
       
  1465 	else
       
  1466 		{
       
  1467 		testCamera->iObserver->ImageReady(NULL,NULL,testCamera->iStillCaptureErr);
       
  1468 		}
       
  1469 	testCamera->iStillCaptureErr = KErrNone;
       
  1470 	return KErrNone;
       
  1471 	}
       
  1472 
       
  1473 TInt CTestCamera::VideoCaptureCallBack(TAny* aThis)
       
  1474 	{
       
  1475 	CTestCamera* testCamera = static_cast<CTestCamera*>(aThis);
       
  1476 	if (testCamera->iObserver2)
       
  1477 		{
       
  1478 		testCamera->iObserver2->VideoBufferReady((static_cast<CTestCamera*>(aThis))->iFrameCameraBuffer1,testCamera->iVideoCaptureErr);
       
  1479 		}
       
  1480 	else
       
  1481 		{
       
  1482 		testCamera->iObserver->FrameBufferReady(NULL,testCamera->iVideoCaptureErr);
       
  1483 		}
       
  1484 	testCamera->iVideoCaptureErr = KErrNone;
       
  1485 	return KErrNone;
       
  1486 	}
       
  1487 	
       
  1488 TInt CTestCamera::HandleEventCallBack(TAny* aThis)
       
  1489 	{
       
  1490 	CTestCamera* testCamera = static_cast<CTestCamera*>(aThis);
       
  1491 	if (testCamera->iObserver2)
       
  1492 		{
       
  1493 		testCamera->iObserver2->HandleEvent(testCamera->iECamEvent);
       
  1494 		}
       
  1495 	
       
  1496 	return KErrNone;
       
  1497 	}
       
  1498 
       
  1499 TInt CTestCamera::HandleEvent2CallBack(TAny* aThis)
       
  1500 	{
       
  1501 	CTestCamera* testCamera = static_cast<CTestCamera*>(aThis);
       
  1502 	if (testCamera->iObserver2)
       
  1503 		{
       
  1504 		testCamera->iObserver2->HandleEvent(testCamera->iECamEvent2);
       
  1505 		}
       
  1506 	
       
  1507 	return KErrNone;
       
  1508 	}
       
  1509 
       
  1510 //
       
  1511 // CTestCameraInfo
       
  1512 //
       
  1513 
       
  1514 CTestCameraInfo::CTestCameraInfo()
       
  1515 	{
       
  1516 	}
       
  1517 	
       
  1518 CTestCameraInfo::~CTestCameraInfo()
       
  1519 	{
       
  1520 	}
       
  1521 	
       
  1522 CTestCameraInfo* CTestCameraInfo::NewL()
       
  1523 	{
       
  1524 	FileDependencyUtil::CheckFileDependencyL();
       
  1525 	return new (ELeave) CTestCameraInfo;
       
  1526 	}
       
  1527 	
       
  1528 TInt CTestCameraInfo::CamerasAvailable()
       
  1529 	{
       
  1530 	return 1;
       
  1531 	}
       
  1532 
       
  1533 //void CTestCamera::CheckFileDependencyL()
       
  1534 void FileDependencyUtil::CheckFileDependencyL()
       
  1535 	{	
       
  1536 	RFs fsSession;
       
  1537   	RFile file;
       
  1538     CleanupClosePushL(fsSession);
       
  1539   	User::LeaveIfError(fsSession.Connect());
       
  1540     TInt err = file.Open(fsSession, KTestCameraPluginName, EFileRead);
       
  1541   	file.Close();
       
  1542   	if(err != KErrNone)
       
  1543   		{
       
  1544 	    User::LeaveIfError(KErrNotSupported);
       
  1545   		}
       
  1546   	CleanupStack::PopAndDestroy(); //fsSession 
       
  1547 	}
       
  1548 
       
  1549 // __________________________________________________________________________
       
  1550 // Exported proxy for instantiation method resolution
       
  1551 // Define the interface UIDs
       
  1552 const TImplementationProxy ImplementationTable[] = 
       
  1553 	{
       
  1554 	IMPLEMENTATION_PROXY_ENTRY(KUidOnboardCameraTestPlugin,	CTestCamera::NewL),
       
  1555 	IMPLEMENTATION_PROXY_ENTRY(KUidOnboardCameraTestInfo,	CTestCameraInfo::NewL)
       
  1556 	};
       
  1557 
       
  1558 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
  1559 	{
       
  1560 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
  1561 
       
  1562 	return ImplementationTable;
       
  1563 	}
       
  1564