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