1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmplugins/cameraplugins/source/testcamera/TestCamera.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1564 @@
1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <w32std.h>
1.20 +#include <ecom/ecom.h>
1.21 +#include <ecom/implementationproxy.h>
1.22 +#include <f32file.h>
1.23 +#include "TestCamera.h"
1.24 +#include "test_advanced_settings.h"
1.25 +#include "test_snapshot.h"
1.26 +#include "test_image_processing.h"
1.27 +#include "TestCameraUids.hrh"
1.28 +#include <ecam.h>
1.29 +
1.30 +//
1.31 +// Main stuff
1.32 +//
1.33 +//
1.34 +// 2nd stage ConstructL calls called by framework
1.35 +//
1.36 +CTestCamera* CTestCamera::NewL()
1.37 + {
1.38 + FileDependencyUtil::CheckFileDependencyL();
1.39 + CTestCamera* self = new(ELeave) CTestCamera;
1.40 + CleanupStack::PushL(self);
1.41 + self->ConstructL();
1.42 + CleanupStack::Pop(self);
1.43 + return self;
1.44 + }
1.45 +
1.46 +void CTestCamera::Construct2L(MCameraObserver& aObserver,TInt aCameraIndex)
1.47 + {
1.48 + iObserver = &aObserver;
1.49 + iCameraIndex = aCameraIndex;
1.50 + }
1.51 +
1.52 +void CTestCamera::Construct2DupL(MCameraObserver& aObserver,TInt aCameraHandle)
1.53 + {
1.54 + iObserver = &aObserver;
1.55 + iCameraHandle = aCameraHandle;
1.56 + }
1.57 +
1.58 +void CTestCamera::ConstructL()
1.59 + {
1.60 +
1.61 + TInt err;
1.62 + TRAP(err, iScreenDev = CFbsScreenDevice::NewL(_L(""),EColor16MA));
1.63 + if (err == KErrNotSupported)
1.64 + {
1.65 + TRAP(err, iScreenDev = CFbsScreenDevice::NewL(_L(""),EColor16M));
1.66 + }
1.67 + if (err == KErrNotSupported)
1.68 + {
1.69 + TRAP(err, iScreenDev = CFbsScreenDevice::NewL(_L(""),EColor64K));
1.70 + }
1.71 + if (err == KErrNotSupported)
1.72 + {
1.73 + TRAP(err, iScreenDev = CFbsScreenDevice::NewL(_L(""),EColor4K));
1.74 + }
1.75 + if (err == KErrNotSupported)
1.76 + {
1.77 + TRAP(err, iScreenDev = CFbsScreenDevice::NewL(_L(""),EColor256));
1.78 + }
1.79 + if (err == KErrNotSupported)
1.80 + {
1.81 + iScreenDev = CFbsScreenDevice::NewL(_L(""),EColor16MAP);
1.82 + }
1.83 + else
1.84 + {
1.85 + User::LeaveIfError(err);
1.86 + }
1.87 +
1.88 + User::LeaveIfError(iScreenDev->CreateContext(iScreenGc));
1.89 + User::LeaveIfError(iImageSizes.Append( TSize(640, 480) )); // VGA
1.90 + User::LeaveIfError(iImageSizes.Append( TSize(160, 120) )); // QQVGA
1.91 + iInfo.iNumImageSizesSupported = iImageSizes.Count();
1.92 + iStillImageSize = iImageSizes[1]; // Defaults to QQVGA
1.93 +
1.94 + User::LeaveIfError(iVideoFrameSizes.Append( TSize(176, 144) )); // QCIF
1.95 + User::LeaveIfError(iVideoFrameSizes.Append( TSize(128, 96) )); // subQCIF
1.96 + iInfo.iNumVideoFrameSizesSupported = iVideoFrameSizes.Count();
1.97 + User::LeaveIfError(iVideoFrameRates.Append( 10.00 ));
1.98 + User::LeaveIfError(iVideoFrameRates.Append( 5.00 ));
1.99 + User::LeaveIfError(iVideoFrameRates.Append( 1.00 ));
1.100 + iInfo.iNumVideoFrameRatesSupported = iVideoFrameRates.Count();
1.101 + iVideoFrameRate = iVideoFrameRates[0];
1.102 + // Still image used as view finder source if not defined otherwise
1.103 + iStillImage = new(ELeave) CFbsBitmap;
1.104 + User::LeaveIfError(iStillImage->Create(iStillImageSize, KViewFinderDisplayMode));
1.105 + iStillImageDev = CFbsBitmapDevice::NewL(iStillImage);
1.106 + User::LeaveIfError(iStillImageDev->CreateContext(iStillImageGc));
1.107 + iStillImageGc->SetPenColor(KRgbBlack);
1.108 + iStillImageGc->SetPenSize(TSize(KFrameFeatureBorderThickness, KFrameFeatureBorderThickness));
1.109 + iStillImageGc->SetBrushColor(KRgbWhite);
1.110 + iStillImageGc->SetFaded(ETrue);
1.111 + iVideoPreparedLast = EFalse;
1.112 + iTimer = CPeriodic::NewL(CActive::EPriorityHigh);
1.113 + }
1.114 +
1.115 +
1.116 +void CTestCamera::Construct2L(MCameraObserver2& aObserver,TInt aCameraIndex,TInt aPriority)
1.117 + {
1.118 + iObserver2 = &aObserver;
1.119 + iCameraIndex = aCameraIndex;
1.120 + iPriority = aPriority;
1.121 + }
1.122 +
1.123 +void CTestCamera::Construct2DupL(MCameraObserver2& aObserver,TInt aCameraHandle)
1.124 + {
1.125 + iObserver2 = &aObserver;
1.126 + iCameraHandle = aCameraHandle;
1.127 + }
1.128 +
1.129 +
1.130 +CTestCamera::CTestCamera():
1.131 + iStillImageFormat(KInitialViewFinderFormat),
1.132 + iReserveAsync(CActive::EPriorityStandard),
1.133 + iPowerOnAsync(CActive::EPriorityStandard),
1.134 + iImageCaptureAsync(CActive::EPriorityStandard),
1.135 + iVideoCaptureAsync(CActive::EPriorityStandard),
1.136 + iHandleEventAsync(CActive::EPriorityStandard),
1.137 + iHandleEvent2Async(CActive::EPriorityStandard),
1.138 + iFrameBuffer1(iVideoFrame1),
1.139 + iFrameBuffer2(iVideoFrame2),
1.140 + iFrameCameraBuffer1(iVideoFrame1),
1.141 + iFrameCameraBuffer2(iVideoFrame2),
1.142 + iContrast(0),
1.143 + iBrightness(0),
1.144 + iImgProcBrightness(0),
1.145 + iImgProcContrast(0),
1.146 + iVideoCaptureActive(EFalse),
1.147 + iImageCaptureActive(EFalse),
1.148 + iVideoPreparedLast(EFalse),
1.149 + iVideoCapturePrepared(EFalse),
1.150 + iImageCapturePrepared(EFalse),
1.151 + iECamEvent(KNullUid, KErrNone),
1.152 + iECamEvent2(KNullUid, KErrNone, 0),
1.153 + iAdvSettingsImpl(NULL),
1.154 + iSnapshotImpl(NULL),
1.155 + iImgProcImpl(NULL),
1.156 + iDriveMode(KDefaultDriveMode),
1.157 + iBurstImages(KBurstImages)
1.158 + {
1.159 + TCallBack reserveCallBack(ReserveCallBack,this);
1.160 + iReserveAsync.Set(reserveCallBack);
1.161 + TCallBack powerOnCallBack(PowerOnCallBack,this);
1.162 + iPowerOnAsync.Set(powerOnCallBack);
1.163 + TCallBack imageCaptureCallBack(ImageCaptureCallBack,this);
1.164 + iImageCaptureAsync.Set(imageCaptureCallBack);
1.165 + TCallBack videoCaptureCallBack(VideoCaptureCallBack,this);
1.166 + iVideoCaptureAsync.Set(videoCaptureCallBack);
1.167 + TCallBack handleEventCallBack(HandleEventCallBack,this);
1.168 + iHandleEventAsync.Set(handleEventCallBack);
1.169 + TCallBack handleEvent2CallBack(HandleEvent2CallBack,this);
1.170 + iHandleEvent2Async.Set(handleEvent2CallBack);
1.171 +
1.172 + iInfo.iHardwareVersion.iMajor = 0;
1.173 + iInfo.iHardwareVersion.iMinor = 0;
1.174 + iInfo.iHardwareVersion.iBuild = 0;
1.175 + iInfo.iSoftwareVersion.iMajor = 0;
1.176 + iInfo.iSoftwareVersion.iMinor = 0;
1.177 + iInfo.iSoftwareVersion.iBuild = 0;
1.178 + iInfo.iOrientation = TCameraInfo::EOrientationOutwards;
1.179 +
1.180 + iInfo.iOptionsSupported = 0;
1.181 + iInfo.iOptionsSupported |= TCameraInfo::EViewFinderDirectSupported;
1.182 + iInfo.iOptionsSupported |= TCameraInfo::EViewFinderBitmapsSupported;
1.183 + iInfo.iOptionsSupported |= TCameraInfo::EImageCaptureSupported;
1.184 + iInfo.iOptionsSupported |= TCameraInfo::EVideoCaptureSupported;
1.185 + iInfo.iOptionsSupported |= TCameraInfo::EContrastSupported;
1.186 + iInfo.iOptionsSupported |= TCameraInfo::EBrightnessSupported;
1.187 + iInfo.iOptionsSupported |= TCameraInfo::EViewFinderClippingSupported;
1.188 +
1.189 + iInfo.iFlashModesSupported = 0; // Bitfield of TFlash values
1.190 + iInfo.iExposureModesSupported = 0; // Bitfield of TExposure values
1.191 + iInfo.iWhiteBalanceModesSupported = 0; // Bitfield of TWhiteBalance values
1.192 +
1.193 + iInfo.iMinZoom = KMinTestCameraZoom;
1.194 + // KMinTestCameraZoom is zero or negative
1.195 + // note the algorithm for creating of zoom factor
1.196 + iInfo.iMinZoomFactor = TReal32(1)/TReal32(1 << -KMinTestCameraZoom);
1.197 + iInfo.iMaxZoom = KMaxTestCameraZoom;
1.198 + iInfo.iMaxZoomFactor = 1 << KMaxTestCameraZoom;
1.199 +
1.200 + iInfo.iMaxDigitalZoom = KMaxTestCameraDigitalZoom;
1.201 + iInfo.iMaxDigitalZoomFactor = KMaxTestCameraDigitalZoomFactor;
1.202 +
1.203 + iInfo.iImageFormatsSupported = 0;
1.204 + iInfo.iImageFormatsSupported |= EFormatFbsBitmapColor4K;
1.205 + iInfo.iImageFormatsSupported |= EFormatFbsBitmapColor64K;
1.206 + iInfo.iImageFormatsSupported |= EFormatFbsBitmapColor16M;
1.207 +
1.208 + iInfo.iVideoFrameFormatsSupported = 0;
1.209 + iInfo.iVideoFrameFormatsSupported |= EFormatFbsBitmapColor4K;
1.210 + iInfo.iVideoFrameFormatsSupported |= EFormatFbsBitmapColor64K;
1.211 + iInfo.iVideoFrameFormatsSupported |= EFormatFbsBitmapColor16M;
1.212 + iInfo.iMaxFramesPerBufferSupported = 1;
1.213 + iInfo.iMaxBuffersSupported = 2;
1.214 +
1.215 + iScreenRect = TRect(TPoint(0,0), TPoint(0,0));
1.216 +
1.217 + iEventError = KErrNone;
1.218 + }
1.219 +
1.220 +CTestCamera::~CTestCamera()
1.221 + {
1.222 + delete iTimer;
1.223 + delete iStillImage;
1.224 + delete iStillImageGc;
1.225 + delete iStillImageDev;
1.226 + delete iVideoFrame1;
1.227 + delete iVideoFrameGc1;
1.228 + delete iVideoFrameDev1;
1.229 + delete iVideoFrame2;
1.230 + delete iVideoFrameGc2;
1.231 + delete iVideoFrameDev2;
1.232 + delete iViewFinderBitmapGc;
1.233 + delete iViewFinderBitmapDev;
1.234 + delete iViewFinderBitmap;
1.235 + delete iDSA;
1.236 + delete iScreenGc;
1.237 + delete iScreenDev;
1.238 + delete iGc;
1.239 + delete iDev;
1.240 + delete iImage;
1.241 + delete iAdvSettingsImpl;
1.242 + delete iSnapshotImpl;
1.243 + delete iImgProcImpl;
1.244 + iImageSizes.Reset();
1.245 + iVideoFrameSizes.Reset();
1.246 + iVideoFrameRates.Reset();
1.247 + }
1.248 +
1.249 +void CTestCamera::CameraInfo(TCameraInfo& aInfo) const
1.250 + {
1.251 + aInfo = iInfo;
1.252 + }
1.253 +
1.254 +void CTestCamera::Reserve()
1.255 + {
1.256 + iReserved = ETrue;
1.257 + iReserveAsync.CallBack();
1.258 + }
1.259 +
1.260 +void CTestCamera::Release()
1.261 + {
1.262 + iReserved = EFalse;
1.263 + iTimer->Cancel();
1.264 + }
1.265 +
1.266 +void CTestCamera::PowerOn()
1.267 + {
1.268 + if (!iReserved || iPowerOn)
1.269 + {
1.270 + iPowerOnAsync.CallBack();
1.271 + return;
1.272 + }
1.273 +
1.274 + iPowerOn = ETrue;
1.275 + TCallBack callback(TimerCallBack,this);
1.276 + iTimer->Start(0,TInt(TReal32(1000000) / iVideoFrameRate), callback);
1.277 + iPowerOnAsync.CallBack();
1.278 + }
1.279 +
1.280 +void CTestCamera::PowerOff()
1.281 + {
1.282 + iPowerOn = EFalse;
1.283 + iTimer->Cancel();
1.284 + }
1.285 +
1.286 +TInt CTestCamera::Handle()
1.287 + {
1.288 + return 0;
1.289 + }
1.290 +
1.291 +void CTestCamera::SetZoomFactorL(TInt aZoomFactor)
1.292 + {
1.293 + // it is equivalent to comparing with iInfo members as they are initialised with the same constants
1.294 + // if (aZoomFactor < iInfo.iMinZoom || aZoomFactor > iInfo.iMaxZoom)
1.295 + if (aZoomFactor < KMinTestCameraZoom || aZoomFactor > KMaxTestCameraZoom)
1.296 + {
1.297 + User::Leave(KErrNotSupported);
1.298 + }
1.299 +
1.300 + iZoom = aZoomFactor;
1.301 + }
1.302 +
1.303 +TInt CTestCamera::ZoomFactor() const
1.304 + {
1.305 + // default value is 0
1.306 + return iZoom;
1.307 + }
1.308 +
1.309 +void CTestCamera::SetDigitalZoomFactorL(TInt aDigitalZoomFactor)
1.310 + {
1.311 + CheckReserveAndPowerL();
1.312 + // it is equivalent to comparing with iInfo member as it is initialised with the same constant
1.313 + // if (aDigitalZoomFactor < 0 || aDigitalZoomFactor > iInfo.iMaxDigitalZoom)
1.314 + if (aDigitalZoomFactor < 0 || aDigitalZoomFactor > KMaxTestCameraDigitalZoom)
1.315 + {
1.316 + User::Leave(KErrNotSupported);
1.317 + }
1.318 +
1.319 + iDigitalZoom = aDigitalZoomFactor;
1.320 + }
1.321 +
1.322 +TInt CTestCamera::DigitalZoomFactor() const
1.323 + {
1.324 + // default value is 0
1.325 + return iDigitalZoom;
1.326 + }
1.327 +
1.328 +void CTestCamera::SetContrastL(TInt aContrast)
1.329 + {
1.330 + CheckReserveAndPowerL();
1.331 +
1.332 + iContrast = Min(Max(aContrast,-100),100);
1.333 + }
1.334 +
1.335 +TInt CTestCamera::Contrast() const
1.336 + {
1.337 + return iContrast;
1.338 + }
1.339 +
1.340 +void CTestCamera::SetBrightnessL(TInt aBrightness)
1.341 + {
1.342 + CheckReserveAndPowerL();
1.343 +
1.344 + iBrightness = Min(Max(aBrightness,-100),100);
1.345 + }
1.346 +
1.347 +TInt CTestCamera::Brightness() const
1.348 + {
1.349 + return iBrightness;
1.350 + }
1.351 +
1.352 +void CTestCamera::SetFlashL(TFlash aFlash)
1.353 + {
1.354 + CheckReserveAndPowerL();
1.355 +
1.356 + if (aFlash != EFlashNone)
1.357 + {
1.358 + User::Leave(KErrNotSupported);
1.359 + }
1.360 + }
1.361 +
1.362 +CCamera::TFlash CTestCamera::Flash() const
1.363 + {
1.364 + return EFlashNone;
1.365 + }
1.366 +
1.367 +void CTestCamera::SetExposureL(TExposure aExposure)
1.368 + {
1.369 + CheckReserveAndPowerL();
1.370 +
1.371 + if (aExposure != EExposureAuto)
1.372 + {
1.373 + User::Leave(KErrNotSupported);
1.374 + }
1.375 + }
1.376 +
1.377 +CCamera::TExposure CTestCamera::Exposure() const
1.378 + {
1.379 + return EExposureAuto;
1.380 + }
1.381 +
1.382 +void CTestCamera::SetWhiteBalanceL(TWhiteBalance aWhiteBalance)
1.383 + {
1.384 + CheckReserveAndPowerL();
1.385 +
1.386 + if (aWhiteBalance != EWBAuto)
1.387 + {
1.388 + User::Leave(KErrNotSupported);
1.389 + }
1.390 + }
1.391 +
1.392 +CCamera::TWhiteBalance CTestCamera::WhiteBalance() const
1.393 + {
1.394 + return EWBAuto;
1.395 + }
1.396 +
1.397 +void CTestCamera::StartViewFinderDirectL(RWsSession& aWs,CWsScreenDevice& aScreenDevice,RWindowBase& aWindow,TRect& aScreenRect)
1.398 + {
1.399 + TRect emptyRect;
1.400 + StartViewFinderDirectL(aWs,aScreenDevice,aWindow,aScreenRect,emptyRect);
1.401 + }
1.402 +
1.403 +void CTestCamera::StartViewFinderDirectL(RWsSession& aWs,CWsScreenDevice& aScreenDevice,RWindowBase& aWindow,TRect& aScreenRect,TRect& aClipRect)
1.404 + {
1.405 + if (!iReserved)
1.406 + {
1.407 + User::Leave(KErrInUse);
1.408 + }
1.409 +
1.410 + if (!iPowerOn || iViewFinderActive)
1.411 + {
1.412 + User::Leave(KErrNotReady);
1.413 + }
1.414 +
1.415 + iScreenRect = aScreenRect;
1.416 + iClipRect = aClipRect;
1.417 +
1.418 + delete iDSA;
1.419 + iDSA = NULL;
1.420 + iViewFinderActive = EFalse;
1.421 + iDSA = CDirectScreenAccess::NewL(aWs,aScreenDevice,aWindow,*this);
1.422 + iDSA->StartL();
1.423 + iViewFinderActive = ETrue;
1.424 + iDSA->Gc()->SetOrigin(); // Set Origin to top left of screen (0,0)
1.425 +
1.426 + if (!iClipRect.IsEmpty())
1.427 + {
1.428 + iDSA->Gc()->SetClippingRect(iClipRect);
1.429 + }
1.430 + }
1.431 +
1.432 +void CTestCamera::StartViewFinderBitmapsL(TSize& aSize)
1.433 + {
1.434 + TRect emptyRect;
1.435 + StartViewFinderBitmapsL(aSize,emptyRect);
1.436 + }
1.437 +
1.438 +void CTestCamera::StartViewFinderBitmapsL(TSize& aSize, TRect& aClipRect)
1.439 + {
1.440 + if (!iReserved)
1.441 + {
1.442 + User::Leave(KErrInUse);
1.443 + }
1.444 + if (!iPowerOn || iViewFinderActive)
1.445 + {
1.446 + User::Leave(KErrNotReady);
1.447 + }
1.448 +
1.449 + iViewFinderActive = ETrue;
1.450 + iScreenRect = TRect(TPoint(0,0), aSize);
1.451 + iClipRect = aClipRect;
1.452 + iClipRect.Intersection(iScreenRect);
1.453 +
1.454 + delete iViewFinderBitmapGc;
1.455 + iViewFinderBitmapGc = NULL;
1.456 + delete iViewFinderBitmapDev;
1.457 + iViewFinderBitmapDev = NULL;
1.458 + delete iViewFinderBitmap;
1.459 + iViewFinderBitmap = NULL;
1.460 +
1.461 + iViewFinderBitmap = new(ELeave) CFbsBitmap;
1.462 + if (!iClipRect.IsEmpty())
1.463 + {
1.464 + User::LeaveIfError(iViewFinderBitmap->Create(iClipRect.Size(), KViewFinderDisplayMode));
1.465 + }
1.466 + else
1.467 + {
1.468 + User::LeaveIfError(iViewFinderBitmap->Create(aSize, KViewFinderDisplayMode));
1.469 + }
1.470 + iViewFinderBitmapDev = CFbsBitmapDevice::NewL(iViewFinderBitmap);
1.471 + User::LeaveIfError(iViewFinderBitmapDev->CreateContext(iViewFinderBitmapGc));
1.472 + }
1.473 +
1.474 +void CTestCamera::StartViewFinderL(TFormat aImageFormat,TSize& aSize)
1.475 + {
1.476 + TRect emptyRect;
1.477 + StartViewFinderL(aImageFormat,aSize,emptyRect);
1.478 + }
1.479 +
1.480 +void CTestCamera::StartViewFinderL(TFormat aImageFormat,TSize& /*aSize*/,TRect& aClipRect)
1.481 + {
1.482 + if(!iReserved)
1.483 + {
1.484 + User::Leave(KErrInUse);
1.485 + }
1.486 + if(!iPowerOn || iViewFinderActive)
1.487 + {
1.488 + User::Leave(KErrNotReady);
1.489 + }
1.490 +
1.491 + iViewFinderActive = ETrue;
1.492 + iClipRect = aClipRect;
1.493 + if(!(aImageFormat & iInfo.iImageFormatsSupported))
1.494 + {
1.495 + User::Leave(KErrNotSupported);
1.496 + }
1.497 + }
1.498 +
1.499 +
1.500 +void CTestCamera::StopViewFinder()
1.501 + {
1.502 + iViewFinderActive = EFalse;
1.503 + delete iDSA;
1.504 + iDSA = NULL;
1.505 +
1.506 + delete iViewFinderBitmapGc;
1.507 + iViewFinderBitmapGc = NULL;
1.508 + delete iViewFinderBitmapDev;
1.509 + iViewFinderBitmapDev = NULL;
1.510 + delete iViewFinderBitmap;
1.511 + iViewFinderBitmap = NULL;
1.512 + }
1.513 +
1.514 +TBool CTestCamera::ViewFinderActive() const
1.515 + {
1.516 + return iViewFinderActive;
1.517 + }
1.518 +
1.519 +void CTestCamera::SetViewFinderMirrorL(TBool aMirror)
1.520 + {
1.521 + if (aMirror)
1.522 + {
1.523 + User::Leave(KErrNotSupported);
1.524 + }
1.525 + }
1.526 +
1.527 +TBool CTestCamera::ViewFinderMirror() const
1.528 + {
1.529 + return EFalse;
1.530 + }
1.531 +
1.532 +void CTestCamera::PrepareImageCaptureL(TFormat aImageFormat,TInt aSizeIndex)
1.533 + {
1.534 + if (!iReserved)
1.535 + {
1.536 + User::Leave(KErrInUse);
1.537 + }
1.538 +
1.539 + if (!iPowerOn || iVideoCaptureActive || iImageCaptureActive)
1.540 + {
1.541 + User::Leave(KErrNotReady);
1.542 + }
1.543 +
1.544 +
1.545 + if (!(aImageFormat & iInfo.iImageFormatsSupported) || aSizeIndex < 0
1.546 + || aSizeIndex >= iInfo.iNumImageSizesSupported)
1.547 + {
1.548 + User::Leave(KErrNotSupported);
1.549 + }
1.550 +
1.551 + iVideoPreparedLast = EFalse;
1.552 +
1.553 + if (iImageCapturePrepared
1.554 + && iStillImageSize == iImageSizes[aSizeIndex]
1.555 + && iStillImageFormat == aImageFormat)
1.556 + {
1.557 + return;
1.558 + }
1.559 +
1.560 + iStillImageSize = iImageSizes[aSizeIndex];
1.561 + iStillImageFormat = aImageFormat;
1.562 +
1.563 + TDisplayMode displayMode = ENone;
1.564 + switch (iStillImageFormat)
1.565 + {
1.566 + case EFormatFbsBitmapColor4K :
1.567 + displayMode = EColor4K;
1.568 + break;
1.569 + case EFormatFbsBitmapColor64K :
1.570 + displayMode = EColor64K;
1.571 + break;
1.572 + case EFormatFbsBitmapColor16M :
1.573 + displayMode = EColor16M;
1.574 + break;
1.575 + default :
1.576 + User::Leave(KErrNotSupported);
1.577 + break;
1.578 + }
1.579 +
1.580 + delete iStillImageGc;
1.581 + iStillImageGc = NULL;
1.582 + delete iStillImageDev;
1.583 + iStillImageDev = NULL;
1.584 + delete iStillImage;
1.585 + iStillImage = NULL;
1.586 +
1.587 + iStillImage = new(ELeave) CFbsBitmap;
1.588 + User::LeaveIfError(iStillImage->Create(iStillImageSize, displayMode));
1.589 + iStillImageDev = CFbsBitmapDevice::NewL(iStillImage);
1.590 + User::LeaveIfError(iStillImageDev->CreateContext(iStillImageGc));
1.591 + iStillImageGc->SetPenColor(KRgbBlack);
1.592 + iStillImageGc->SetPenSize(TSize(KFrameFeatureBorderThickness, KFrameFeatureBorderThickness));
1.593 + iStillImageGc->SetBrushColor(KRgbWhite);
1.594 + iStillImageGc->SetFaded(ETrue);
1.595 + iImageCapturePrepared = ETrue;
1.596 + }
1.597 +
1.598 +void CTestCamera::PrepareImageCaptureL(TFormat /*aImageFormat*/,TInt /*aSizeIndex*/,const TRect& /*aClipRect*/)
1.599 + {
1.600 + User::Leave(KErrNotSupported);
1.601 + }
1.602 +
1.603 +void CTestCamera::CaptureImage()
1.604 + {
1.605 + if (!iReserved)
1.606 + {
1.607 + iStillCaptureErr = KErrInUse;
1.608 + }
1.609 +
1.610 + if (!iPowerOn || iImageCaptureActive || iVideoCaptureActive || !iImageCapturePrepared)
1.611 + {
1.612 + iStillCaptureErr = KErrNotReady;
1.613 + }
1.614 +
1.615 + if (iStillCaptureErr == KErrNone)
1.616 + {
1.617 + TRAP(iStillCaptureErr,DoCaptureImageL());
1.618 + }
1.619 +
1.620 + if (iStillCaptureErr == KErrNone)
1.621 + {
1.622 + iImageCaptureActive = ETrue;
1.623 + }
1.624 + else
1.625 + {
1.626 + iImageCaptureAsync.CallBack();
1.627 + }
1.628 + }
1.629 +
1.630 +void CTestCamera::DoCaptureImageL()
1.631 + {
1.632 + delete iGc;
1.633 + iGc = NULL;
1.634 + delete iDev;
1.635 + iDev = NULL;
1.636 + delete iImage;
1.637 + iImage = NULL;
1.638 +
1.639 + CFbsBitmap* image = new(ELeave) CFbsBitmap;
1.640 + CleanupStack::PushL(image);
1.641 + User::LeaveIfError(image->Create(iStillImageSize, iStillImage->DisplayMode()));
1.642 + CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL(image);
1.643 + CleanupStack::PushL(dev);
1.644 + CFbsBitGc* gc = NULL;
1.645 + User::LeaveIfError(dev->CreateContext(gc));
1.646 + CleanupStack::Pop(dev);
1.647 + CleanupStack::Pop(image);
1.648 +
1.649 + iImage = image;
1.650 + iDev = dev;
1.651 + iGc = gc;
1.652 + }
1.653 +
1.654 +void CTestCamera::CancelCaptureImage()
1.655 + {
1.656 + iImageCaptureActive = EFalse;
1.657 + }
1.658 +
1.659 +void CTestCamera::EnumerateCaptureSizes(TSize& aSize,TInt aSizeIndex,TFormat aFormat) const
1.660 + {
1.661 + if (aSizeIndex < 0 || aSizeIndex >= iInfo.iNumImageSizesSupported ||
1.662 + !(aFormat & iInfo.iImageFormatsSupported) )
1.663 + {
1.664 + aSize = TSize(0,0);
1.665 + }
1.666 + else
1.667 + {
1.668 + aSize = iImageSizes[aSizeIndex];
1.669 + }
1.670 + }
1.671 +
1.672 +void CTestCamera::PrepareVideoCaptureL(TFormat aFormat,TInt aSizeIndex,TInt aRateIndex,TInt aBuffersToUse,TInt aFramesPerBuffer)
1.673 + {
1.674 + if (!iReserved)
1.675 + {
1.676 + User::Leave(KErrInUse);
1.677 + }
1.678 +
1.679 + if (!iPowerOn || iVideoCaptureActive || iImageCaptureActive)
1.680 + {
1.681 + User::Leave(KErrNotReady);
1.682 + }
1.683 +
1.684 + if (!(aFormat & iInfo.iVideoFrameFormatsSupported)
1.685 + || aSizeIndex < 0 || aSizeIndex >= iInfo.iNumVideoFrameSizesSupported
1.686 + || aRateIndex < 0 || aRateIndex >= iInfo.iNumVideoFrameRatesSupported
1.687 + || aBuffersToUse != 2 || aFramesPerBuffer != 1)
1.688 + {
1.689 + User::Leave(KErrNotSupported);
1.690 + }
1.691 +
1.692 + iVideoPreparedLast = ETrue;
1.693 +
1.694 + if (iVideoCapturePrepared
1.695 + && iVideoFrameSize == iVideoFrameSizes[aSizeIndex]
1.696 + && iVideoFrameFormat == aFormat)
1.697 + {
1.698 + return;
1.699 + }
1.700 +
1.701 + TDisplayMode displayMode = ENone;
1.702 + switch (aFormat)
1.703 + {
1.704 + case EFormatFbsBitmapColor4K :
1.705 + displayMode = EColor4K;
1.706 + break;
1.707 + case EFormatFbsBitmapColor64K :
1.708 + displayMode = EColor64K;
1.709 + break;
1.710 + case EFormatFbsBitmapColor16M :
1.711 + displayMode = EColor16M;
1.712 + break;
1.713 + default :
1.714 + User::Leave(KErrNotSupported);
1.715 + break;
1.716 + }
1.717 +
1.718 + iVideoFrameSize = iVideoFrameSizes[aSizeIndex];
1.719 + iVideoFrameRate = iVideoFrameRates[aRateIndex];
1.720 + iVideoFrameFormat = aFormat;
1.721 + iBuffersInUse = aBuffersToUse;
1.722 +
1.723 + delete iVideoFrameGc1;
1.724 + iVideoFrameGc1 = NULL;
1.725 + delete iVideoFrameDev1;
1.726 + iVideoFrameDev1 = NULL;
1.727 + delete iVideoFrame1;
1.728 + iVideoFrame1 = NULL;
1.729 +
1.730 + delete iVideoFrameGc2;
1.731 + iVideoFrameGc2 = NULL;
1.732 + delete iVideoFrameDev2;
1.733 + iVideoFrameDev2 = NULL;
1.734 + delete iVideoFrame2;
1.735 + iVideoFrame2 = NULL;
1.736 +
1.737 + iVideoFrame1 = new(ELeave) CFbsBitmap;
1.738 + User::LeaveIfError(iVideoFrame1->Create(iVideoFrameSize, displayMode));
1.739 + iVideoFrameDev1 = CFbsBitmapDevice::NewL(iVideoFrame1);
1.740 + User::LeaveIfError(iVideoFrameDev1->CreateContext(iVideoFrameGc1));
1.741 + iVideoFrameGc1->SetPenColor(KRgbBlack);
1.742 + iVideoFrameGc1->SetPenSize(TSize(KFrameFeatureBorderThickness, KFrameFeatureBorderThickness));
1.743 + iVideoFrameGc1->SetBrushColor(KRgbWhite);
1.744 + iVideoFrameGc1->SetFaded(ETrue);
1.745 +
1.746 + if (iBuffersInUse == 2)
1.747 + {
1.748 + iVideoFrame2 = new(ELeave) CFbsBitmap;
1.749 + User::LeaveIfError(iVideoFrame2->Create(iVideoFrameSize, displayMode));
1.750 + iVideoFrameDev2 = CFbsBitmapDevice::NewL(iVideoFrame2);
1.751 + User::LeaveIfError(iVideoFrameDev1->CreateContext(iVideoFrameGc2));
1.752 + iVideoFrameGc2->SetPenColor(KRgbBlack);
1.753 + iVideoFrameGc2->SetPenSize(TSize(KFrameFeatureBorderThickness, KFrameFeatureBorderThickness));
1.754 + iVideoFrameGc2->SetBrushColor(KRgbWhite);
1.755 + iVideoFrameGc2->SetFaded(ETrue);
1.756 + }
1.757 +
1.758 + iVideoCapturePrepared = ETrue;
1.759 + }
1.760 +
1.761 +void CTestCamera::PrepareVideoCaptureL(TFormat /*aFormat*/,TInt /*aSizeIndex*/,TInt /*aRateIndex*/,TInt /*aBuffersToUse*/,TInt /*aFramesPerBuffer*/,const TRect& /*aClipRect*/)
1.762 + {
1.763 + User::Leave(KErrNotSupported);
1.764 + }
1.765 +
1.766 +void CTestCamera::StartVideoCapture()
1.767 + {
1.768 + if (!iReserved)
1.769 + {
1.770 + iVideoCaptureErr = KErrInUse;
1.771 + }
1.772 +
1.773 + if (!iPowerOn || iImageCaptureActive || iVideoCaptureActive || !iVideoCapturePrepared)
1.774 + {
1.775 + iVideoCaptureErr = KErrNotReady;
1.776 + }
1.777 +
1.778 + if (iVideoCaptureErr == KErrNone)
1.779 + {
1.780 + iVideoCaptureActive = ETrue;
1.781 + }
1.782 +
1.783 + else
1.784 + {
1.785 + iVideoCaptureAsync.CallBack();
1.786 + }
1.787 + }
1.788 +
1.789 +void CTestCamera::StopVideoCapture()
1.790 + {
1.791 + iVideoCaptureActive = EFalse;
1.792 + iFrameIndex = 0;
1.793 + iElapsedTime = 0;
1.794 + }
1.795 +
1.796 +TBool CTestCamera::VideoCaptureActive() const
1.797 + {
1.798 + return iVideoCaptureActive;
1.799 + }
1.800 +
1.801 +void CTestCamera::EnumerateVideoFrameSizes(TSize& aSize,TInt aSizeIndex,TFormat aFormat) const
1.802 + {
1.803 + if (aSizeIndex < 0 || aSizeIndex >= iInfo.iNumVideoFrameSizesSupported ||
1.804 + !(aFormat & iInfo.iVideoFrameFormatsSupported))
1.805 + {
1.806 + aSize = TSize(0,0);
1.807 + }
1.808 + else
1.809 + {
1.810 + aSize = iVideoFrameSizes[aSizeIndex];
1.811 + }
1.812 + }
1.813 +
1.814 +void CTestCamera::EnumerateVideoFrameRates(TReal32& aRate,TInt aRateIndex,TFormat aFormat,TInt aSizeIndex,TExposure aExposure) const
1.815 + {
1.816 + if (aRateIndex < 0 || aRateIndex >= iInfo.iNumVideoFrameRatesSupported ||
1.817 + aSizeIndex < 0 || aSizeIndex >= iInfo.iNumVideoFrameSizesSupported ||
1.818 + !(aFormat & iInfo.iVideoFrameFormatsSupported) ||
1.819 + (!(aExposure & iInfo.iExposureModesSupported) && aExposure != CCamera::EExposureAuto))
1.820 + {
1.821 + aRate = 0.0;
1.822 + }
1.823 + else
1.824 + {
1.825 + aRate = iVideoFrameRates[aRateIndex];
1.826 + }
1.827 + }
1.828 +
1.829 +void CTestCamera::GetFrameSize(TSize& aSize) const
1.830 + {
1.831 + aSize = iVideoFrameSize;
1.832 + }
1.833 +
1.834 +TReal32 CTestCamera::FrameRate() const
1.835 + {
1.836 + return iVideoFrameRate;
1.837 + }
1.838 +
1.839 +TInt CTestCamera::BuffersInUse() const
1.840 + {
1.841 + return iBuffersInUse;
1.842 + }
1.843 +
1.844 +TInt CTestCamera::FramesPerBuffer() const
1.845 + {
1.846 + return 1;
1.847 + }
1.848 +
1.849 +void CTestCamera::SetJpegQuality(TInt /*aQuality*/)
1.850 + {
1.851 + }
1.852 +
1.853 +TInt CTestCamera::JpegQuality() const
1.854 + {
1.855 + return 0;
1.856 + }
1.857 +
1.858 +TAny* CTestCamera::CustomInterface(TUid aInterface)
1.859 + {
1.860 + TAny* ptrIface = NULL;
1.861 + TRAPD(error,CustomInterfaceL(ptrIface, aInterface));
1.862 +
1.863 + if(error == KErrNone)
1.864 + {
1.865 + switch(aInterface.iUid)
1.866 + {
1.867 + // advanced settings interface pointers
1.868 + case KECamMCameraAdvancedSettingsUidValue:
1.869 + {
1.870 + return static_cast<MCameraAdvancedSettings*>(ptrIface);
1.871 + }
1.872 + case KECamMCameraAdvancedSettings2UidValue:
1.873 + {
1.874 + return static_cast<MCameraAdvancedSettings2*>(ptrIface);
1.875 + }
1.876 + case KECamMCameraAdvancedSettings3UidValue:
1.877 + {
1.878 + return static_cast<MCameraAdvancedSettings3*>(ptrIface);
1.879 + }
1.880 +
1.881 + // snapshot interface pointers
1.882 + case KECamMCameraSnapshotUidValue:
1.883 + {
1.884 + return static_cast<MCameraSnapshot*>(ptrIface);
1.885 + }
1.886 +
1.887 + // preset interface pointers
1.888 + case KECamMCameraPresetsUidValue:
1.889 + return static_cast<MCameraPresets*>(ptrIface);
1.890 +
1.891 + // image processing interface pointers
1.892 + case KECamMCameraImageProcessingUidValue:
1.893 + {
1.894 + return static_cast<MCameraImageProcessing*>(ptrIface);
1.895 + }
1.896 +
1.897 + case KECamMCameraImageProcessing2UidValue:
1.898 + {
1.899 + return static_cast<MCameraImageProcessing2*>(ptrIface);
1.900 + }
1.901 +
1.902 + default:
1.903 + return NULL;
1.904 + }
1.905 + }
1.906 + else
1.907 + {
1.908 + return NULL;
1.909 + }
1.910 + }
1.911 +
1.912 +void CTestCamera::CustomInterfaceL(TAny*& aIface, TUid aInterface)
1.913 + {
1.914 + switch(aInterface.iUid)
1.915 + {
1.916 + // advanced settings interface pointers
1.917 + case KECamMCameraAdvancedSettingsUidValue:
1.918 + {
1.919 + iAdvSettingsImpl = CTestCamAdvSet::NewL(*this);
1.920 + aIface = static_cast<MCameraAdvancedSettings*>(iAdvSettingsImpl);
1.921 + break;
1.922 + }
1.923 + case KECamMCameraAdvancedSettings2UidValue:
1.924 + {
1.925 + iAdvSettingsImpl = CTestCamAdvSet::NewL(*this);
1.926 + aIface = static_cast<MCameraAdvancedSettings2*>(iAdvSettingsImpl);
1.927 + break;
1.928 + }
1.929 + case KECamMCameraAdvancedSettings3UidValue:
1.930 + {
1.931 + iAdvSettingsImpl = CTestCamAdvSet::NewL(*this);
1.932 + aIface = static_cast<MCameraAdvancedSettings3*>(iAdvSettingsImpl);
1.933 + break;
1.934 + }
1.935 +
1.936 + // snapshot interface pointers
1.937 + case KECamMCameraSnapshotUidValue:
1.938 + {
1.939 + iSnapshotImpl = CTestCamSnapshot::NewL(*this);
1.940 + aIface = static_cast<MCameraSnapshot*>(iSnapshotImpl);
1.941 + break;
1.942 + }
1.943 + // preset interface pointers
1.944 + case KECamMCameraPresetsUidValue:
1.945 + {
1.946 + aIface = static_cast<MCameraPresets*>(CTestCamPresets::NewL(*this));
1.947 + break;
1.948 + }
1.949 +
1.950 + // image processing interface pointers
1.951 + case KECamMCameraImageProcessingUidValue:
1.952 + {
1.953 + iImgProcImpl = CTestCamImgProc::NewL(*this);
1.954 + aIface = static_cast<MCameraImageProcessing*>(iImgProcImpl);
1.955 + break;
1.956 + }
1.957 +
1.958 + case KECamMCameraImageProcessing2UidValue:
1.959 + {
1.960 + iImgProcImpl = CTestCamImgProc::NewL(*this);
1.961 + aIface = static_cast<MCameraImageProcessing2*>(iImgProcImpl);
1.962 + break;
1.963 + }
1.964 +
1.965 + default:
1.966 + aIface = NULL;
1.967 + }
1.968 + }
1.969 +
1.970 +void CTestCamera::AbortNow(RDirectScreenAccess::TTerminationReasons /*aReason*/)
1.971 + {
1.972 + iViewFinderActive = EFalse;
1.973 + }
1.974 +
1.975 +void CTestCamera::Restart(RDirectScreenAccess::TTerminationReasons /*aReason*/)
1.976 + {
1.977 + TRAPD(error,iDSA->StartL());
1.978 + if (error != KErrNone)
1.979 + {
1.980 + return;
1.981 + }
1.982 + iDSA->Gc()->SetOrigin(); // Set Origin to top left of screen (0,0)
1.983 +
1.984 + if (!iClipRect.IsEmpty())
1.985 + {
1.986 + iDSA->Gc()->SetClippingRect(iClipRect);
1.987 + }
1.988 + else
1.989 + {
1.990 + iDSA->Gc()->CancelClippingRect();
1.991 + }
1.992 +
1.993 + iViewFinderActive = ETrue;
1.994 + }
1.995 +
1.996 +TInt CTestCamera::TimerCallBack(TAny* aThis)
1.997 + {
1.998 + static_cast<CTestCamera*>(aThis)->FrameReady();
1.999 + return KErrNone;
1.1000 + }
1.1001 +
1.1002 +void CTestCamera::FrameReady()
1.1003 + {
1.1004 + if (iVideoPreparedLast)
1.1005 + {
1.1006 + iVideoFramePos.iX += KFramePosIncrement;
1.1007 + iVideoFramePos.iY += KFramePosIncrement;
1.1008 +
1.1009 + if (iVideoFramePos.iX >= iVideoFrameSize.iWidth)
1.1010 + {
1.1011 + iVideoFramePos.iX = 0;
1.1012 + }
1.1013 +
1.1014 + if (iVideoFramePos.iY >= iVideoFrameSize.iHeight)
1.1015 + {
1.1016 + iVideoFramePos.iY = 0;
1.1017 + }
1.1018 + }
1.1019 + else
1.1020 + {
1.1021 + iStillImagePos.iX += KFramePosIncrement;
1.1022 + iStillImagePos.iY += KFramePosIncrement;
1.1023 +
1.1024 + if (iStillImagePos.iX >= iStillImageSize.iWidth)
1.1025 + {
1.1026 + iStillImagePos.iX = 0;
1.1027 + }
1.1028 +
1.1029 + if (iStillImagePos.iY >= iStillImageSize.iHeight)
1.1030 + {
1.1031 + iStillImagePos.iY = 0;
1.1032 + }
1.1033 + }
1.1034 +
1.1035 + if (iImageCaptureActive)
1.1036 + {
1.1037 + if (!iImageCapturePrepared)
1.1038 + {
1.1039 + iImageCaptureActive = EFalse;
1.1040 + if (iObserver2)
1.1041 + {
1.1042 + iObserver2->ImageBufferReady(iFrameCameraBuffer1,KErrNotReady);
1.1043 + }
1.1044 + else
1.1045 + {
1.1046 + iObserver->ImageReady(NULL,NULL,KErrNotReady);
1.1047 + }
1.1048 + }
1.1049 + else
1.1050 + {
1.1051 + if(iDriveMode == CCamera::CCameraAdvancedSettings::EDriveModeBurst)
1.1052 + {
1.1053 + for (TInt index =0; index < iBurstImages -1; index++)
1.1054 + {
1.1055 + if(iSnapshotImpl != NULL)
1.1056 + {
1.1057 + if(iSnapshotImpl->iSnapshotActive)
1.1058 + {
1.1059 + GetFrame(*(iSnapshotImpl->iSnapshotImageGc), iStillImagePos);
1.1060 + iSnapshotImpl->ServiceBurstImageSnapshot(*(iSnapshotImpl->iSnapshotImageGc));
1.1061 + }
1.1062 + }
1.1063 +
1.1064 + GetImgProcessedFrame(*iStillImageGc, iStillImagePos);
1.1065 + ServiceBurstImageCapture(*iStillImageGc);
1.1066 + }
1.1067 + }
1.1068 +
1.1069 + // normal case, single shot and last image from burst mode
1.1070 + if(iSnapshotImpl != NULL)
1.1071 + {
1.1072 + if(iSnapshotImpl->iSnapshotActive)
1.1073 + {
1.1074 + GetFrame(*iSnapshotImpl->iSnapshotImageGc, iStillImagePos);
1.1075 + iSnapshotImpl->ServiceSnapshot(*(iSnapshotImpl->iSnapshotImageGc));
1.1076 + }
1.1077 + }
1.1078 +
1.1079 + GetImgProcessedFrame(*iStillImageGc, iStillImagePos);
1.1080 + ServiceImageCapture(*iStillImageGc);
1.1081 +
1.1082 + if (iVideoPreparedLast)
1.1083 + {
1.1084 + GetFrame(*iVideoFrameGc1, iVideoFramePos);
1.1085 + if (iViewFinderActive)
1.1086 + {
1.1087 + ServiceViewFinder(iVideoFrame1);
1.1088 + }
1.1089 + }
1.1090 + else
1.1091 + {
1.1092 + if (iViewFinderActive)
1.1093 + {
1.1094 + ServiceViewFinder(iStillImage);
1.1095 + }
1.1096 + }
1.1097 + }
1.1098 + }
1.1099 +
1.1100 + else if (iVideoCaptureActive)
1.1101 + {
1.1102 + if (!iVideoCapturePrepared)
1.1103 + {
1.1104 + iVideoCaptureActive = EFalse;
1.1105 + if (iObserver2)
1.1106 + {
1.1107 + iObserver2->VideoBufferReady(iFrameCameraBuffer1,KErrNotReady);
1.1108 + }
1.1109 + else
1.1110 + {
1.1111 + iObserver->FrameBufferReady(NULL,KErrNotReady);
1.1112 + }
1.1113 + }
1.1114 + else
1.1115 + {
1.1116 + if (iObserver2)
1.1117 + {
1.1118 + if (iFrameCameraBuffer1.iAvailable)
1.1119 + {
1.1120 + GetFrame(*iVideoFrameGc1, iVideoFramePos);
1.1121 + ServiceVideo(1);
1.1122 + if (iViewFinderActive)
1.1123 + {
1.1124 + ServiceViewFinder(iVideoFrame1);
1.1125 + }
1.1126 + }
1.1127 + else if (iFrameCameraBuffer2.iAvailable && iBuffersInUse == 2)
1.1128 + {
1.1129 + GetFrame(*iVideoFrameGc2, iVideoFramePos);
1.1130 + ServiceVideo(2);
1.1131 + if (iViewFinderActive)
1.1132 + {
1.1133 + ServiceViewFinder(iVideoFrame2);
1.1134 + }
1.1135 + }
1.1136 + }
1.1137 + else
1.1138 + {
1.1139 + if (iFrameBuffer1.iAvailable)
1.1140 + {
1.1141 + GetFrame(*iVideoFrameGc1, iVideoFramePos);
1.1142 + ServiceVideo(1);
1.1143 + if (iViewFinderActive)
1.1144 + {
1.1145 + ServiceViewFinder(iVideoFrame1);
1.1146 + }
1.1147 + }
1.1148 + else if (iFrameBuffer2.iAvailable && iBuffersInUse == 2)
1.1149 + {
1.1150 + GetFrame(*iVideoFrameGc2, iVideoFramePos);
1.1151 + ServiceVideo(2);
1.1152 + if (iViewFinderActive)
1.1153 + {
1.1154 + ServiceViewFinder(iVideoFrame2);
1.1155 + }
1.1156 + }
1.1157 + }
1.1158 + }
1.1159 + }
1.1160 +
1.1161 + else if (iViewFinderActive)
1.1162 + {
1.1163 + if (iVideoPreparedLast)
1.1164 + {
1.1165 + GetFrame(*iVideoFrameGc1, iVideoFramePos);
1.1166 + ServiceViewFinder(iVideoFrame1);
1.1167 + }
1.1168 + else
1.1169 + {
1.1170 + GetFrame(*iStillImageGc, iStillImagePos);
1.1171 + ServiceViewFinder(iStillImage);
1.1172 + }
1.1173 + }
1.1174 + }
1.1175 +
1.1176 +void CTestCamera::GetFrame(CFbsBitGc& aGc, TPoint& aPos) const
1.1177 + {
1.1178 + TInt black = (100 - iContrast) * 127 / 200;
1.1179 + TInt white = ((100 + iContrast) * 128 / 200) + 127;
1.1180 +
1.1181 + const TInt brightAdjust = iBrightness * 255 / 100;
1.1182 + black += brightAdjust;
1.1183 + white += brightAdjust;
1.1184 +
1.1185 + black = Min(Max(black,0),255);
1.1186 + white = Min(Max(white,0),255);
1.1187 +
1.1188 + aGc.SetFadingParameters(TUint8(black),TUint8(white));
1.1189 + aGc.Clear();
1.1190 + aGc.DrawRect(TRect(aPos,TSize(KFrameFeatureSize,KFrameFeatureSize)));
1.1191 + }
1.1192 +
1.1193 +void CTestCamera::GetImgProcessedFrame(CFbsBitGc& aGc, TPoint& aPos) const
1.1194 + {
1.1195 + TInt contrast = iContrast;
1.1196 + TInt brightness = iBrightness;
1.1197 +
1.1198 + if(iImgProcImpl != NULL)
1.1199 + {
1.1200 + for(TInt index=0; index<iImgProcImpl->iActiveTransformations.Count(); index++)
1.1201 + {
1.1202 + switch(iImgProcImpl->iActiveTransformations[index].iUid)
1.1203 + {
1.1204 + case KUidECamEventImageProcessingAdjustBrightnessUidValue:
1.1205 + {
1.1206 + brightness = iImgProcBrightness;
1.1207 + break;
1.1208 + }
1.1209 + case KUidECamEventImageProcessingAdjustContrastUidValue:
1.1210 + {
1.1211 + contrast = iImgProcContrast;
1.1212 + break;
1.1213 + }
1.1214 + default:
1.1215 + {
1.1216 + break;
1.1217 + }
1.1218 + }
1.1219 + }
1.1220 + }
1.1221 +
1.1222 + TInt black = (100 - contrast) * 127 / 200;
1.1223 + TInt white = ((100 + contrast) * 128 / 200) + 127;
1.1224 +
1.1225 + const TInt brightAdjust = brightness * 255 / 100;
1.1226 + black += brightAdjust;
1.1227 + white += brightAdjust;
1.1228 +
1.1229 + black = Min(Max(black,0),255);
1.1230 + white = Min(Max(white,0),255);
1.1231 +
1.1232 + aGc.SetFadingParameters(TUint8(black),TUint8(white));
1.1233 + aGc.Clear();
1.1234 + aGc.DrawRect(TRect(aPos,TSize(KFrameFeatureSize,KFrameFeatureSize)));
1.1235 + }
1.1236 +
1.1237 +void CTestCamera::ServiceVideo(TInt aBufferNum)
1.1238 + {
1.1239 + iFrameIndex++;
1.1240 + iElapsedTime = iElapsedTime.Int64() + (TInt64(1000000) / TInt64(iVideoFrameRate));
1.1241 +
1.1242 + if (aBufferNum == 1)
1.1243 + {
1.1244 + if (iObserver2)
1.1245 + {
1.1246 + iFrameCameraBuffer1.iIndexOfFirstFrameInBuffer = iFrameIndex;
1.1247 + iFrameCameraBuffer1.iElapsedTime = iElapsedTime;
1.1248 + iFrameCameraBuffer1.iAvailable = EFalse;
1.1249 + }
1.1250 + else
1.1251 + {
1.1252 + iFrameBuffer1.iIndexOfFirstFrameInBuffer = iFrameIndex;
1.1253 + iFrameBuffer1.iElapsedTime = iElapsedTime;
1.1254 + iFrameBuffer1.iAvailable = EFalse;
1.1255 + }
1.1256 +
1.1257 + if (iObserver2)
1.1258 + {
1.1259 + iObserver2->VideoBufferReady(iFrameCameraBuffer1,KErrNone);
1.1260 + }
1.1261 + else
1.1262 + {
1.1263 + iObserver->FrameBufferReady(&iFrameBuffer1,KErrNone);
1.1264 + }
1.1265 + }
1.1266 + else if (aBufferNum == 2)
1.1267 + {
1.1268 + if (iObserver2)
1.1269 + {
1.1270 + iFrameCameraBuffer2.iIndexOfFirstFrameInBuffer = iFrameIndex;
1.1271 + iFrameCameraBuffer2.iElapsedTime = iElapsedTime;
1.1272 + iFrameCameraBuffer2.iAvailable = EFalse;
1.1273 + }
1.1274 + else
1.1275 + {
1.1276 + iFrameBuffer2.iIndexOfFirstFrameInBuffer = iFrameIndex;
1.1277 + iFrameBuffer2.iElapsedTime = iElapsedTime;
1.1278 + iFrameBuffer2.iAvailable = EFalse;
1.1279 + }
1.1280 +
1.1281 + if (iObserver2)
1.1282 + {
1.1283 + iObserver2->VideoBufferReady(iFrameCameraBuffer2,KErrNone);
1.1284 + }
1.1285 + else
1.1286 + {
1.1287 + iObserver->FrameBufferReady(&iFrameBuffer2,KErrNone);
1.1288 + }
1.1289 + }
1.1290 + }
1.1291 +
1.1292 +void CTestCamera::ServiceViewFinder(CFbsBitmap* aSourceFrame)
1.1293 + {
1.1294 + if (iDSA)
1.1295 + {
1.1296 + iDSA->Gc()->DrawBitmap(iScreenRect,aSourceFrame);
1.1297 + iDSA->ScreenDevice()->Update();
1.1298 + }
1.1299 + else if (iViewFinderBitmap)
1.1300 + {
1.1301 + if (iViewFinderBitmapGc)
1.1302 + {
1.1303 + if (!iClipRect.IsEmpty())
1.1304 + {
1.1305 + TReal32 xRatio = static_cast<TReal32>(aSourceFrame->SizeInPixels().iWidth) /
1.1306 + static_cast<TReal32>(iClipRect.Size().iWidth);
1.1307 +
1.1308 + TReal32 yRatio = static_cast<TReal32>(aSourceFrame->SizeInPixels().iHeight) /
1.1309 + static_cast<TReal32>(iClipRect.Size().iHeight);
1.1310 +
1.1311 + TRect sourceRect(TPoint(static_cast<TInt>(xRatio*iClipRect.iTl.iX),
1.1312 + static_cast<TInt>(yRatio*iClipRect.iTl.iY)),
1.1313 + TPoint(static_cast<TInt>(xRatio*iClipRect.iBr.iX),
1.1314 + static_cast<TInt>(yRatio*iClipRect.iBr.iY)));
1.1315 +
1.1316 + TRect destRect(TPoint(0,0), iClipRect.Size());
1.1317 +
1.1318 + iViewFinderBitmapGc->DrawBitmap(destRect,
1.1319 + aSourceFrame,
1.1320 + sourceRect);
1.1321 + }
1.1322 + else
1.1323 + {
1.1324 + TRect destRect(TPoint(0,0), iViewFinderBitmap->SizeInPixels());
1.1325 + iViewFinderBitmapGc->DrawBitmap(destRect, aSourceFrame);
1.1326 + }
1.1327 +
1.1328 + if (iObserver2)
1.1329 + {
1.1330 + iObserver2->ViewFinderReady(iFrameCameraBuffer1,KErrNone);
1.1331 + }
1.1332 + else
1.1333 + {
1.1334 + iObserver->ViewFinderFrameReady(*iViewFinderBitmap);
1.1335 + }
1.1336 +
1.1337 + }
1.1338 + }
1.1339 + else
1.1340 + {
1.1341 + iScreenGc->DrawBitmap(iClipRect,aSourceFrame);
1.1342 + iScreenDev->Update();
1.1343 + }
1.1344 + }
1.1345 +
1.1346 +void CTestCamera::ServiceImageCapture(const CFbsBitGc& aSourceBitmapGc)
1.1347 + {
1.1348 + iImageCaptureActive = EFalse;
1.1349 + iGc->BitBlt(TPoint(0,0), aSourceBitmapGc);
1.1350 + CFbsBitmap* image = iImage;
1.1351 + RTestCameraFrameBuffer frameBuffer(image);
1.1352 + delete iGc;
1.1353 + iGc = NULL;
1.1354 + delete iDev;
1.1355 + iDev = NULL;
1.1356 + if (iObserver2 != NULL)
1.1357 + {
1.1358 + iObserver2->ImageBufferReady(frameBuffer,KErrNone);
1.1359 + }
1.1360 + else
1.1361 + {
1.1362 + iImage = NULL;
1.1363 + iObserver->ImageReady(image,NULL,KErrNone);
1.1364 + }
1.1365 + }
1.1366 +
1.1367 +void CTestCamera::ServiceBurstImageCapture(const CFbsBitGc& aSourceBitmapGc)
1.1368 + {
1.1369 + iGc->BitBlt(TPoint(0,0), aSourceBitmapGc);
1.1370 + if (iObserver2 != NULL)
1.1371 + {
1.1372 + CFbsBitmap* image = iImage;
1.1373 + RTestCameraFrameBuffer frameBuffer(image);
1.1374 + iObserver2->ImageBufferReady(frameBuffer,KErrNone);
1.1375 + }
1.1376 + else//not for MCameraObserver
1.1377 + {
1.1378 + return;
1.1379 + }
1.1380 +
1.1381 + if(iSnapshotImpl)
1.1382 + {
1.1383 + if(iSnapshotImpl->iSnapshotActive)
1.1384 + {
1.1385 + return;
1.1386 + }
1.1387 + }
1.1388 + User::After(500000);
1.1389 + iStillImagePos.iX += KFramePosIncrement;
1.1390 + iStillImagePos.iY += KFramePosIncrement;
1.1391 +
1.1392 + if (iStillImagePos.iX >= iStillImageSize.iWidth)
1.1393 + {
1.1394 + iStillImagePos.iX = 0;
1.1395 + }
1.1396 +
1.1397 + if (iStillImagePos.iY >= iStillImageSize.iHeight)
1.1398 + {
1.1399 + iStillImagePos.iY = 0;
1.1400 + }
1.1401 + }
1.1402 +
1.1403 +void CTestCamera::CheckReserveAndPowerL()
1.1404 + {
1.1405 + if (!iReserved)
1.1406 + {
1.1407 + User::Leave(KErrInUse);
1.1408 + }
1.1409 +
1.1410 + if (!iPowerOn)
1.1411 + {
1.1412 + User::Leave(KErrNotReady);
1.1413 + }
1.1414 + }
1.1415 +
1.1416 +TInt CTestCamera::CheckReserveAndPower() const
1.1417 + {
1.1418 + if (!iReserved)
1.1419 + {
1.1420 + return KErrInUse;
1.1421 + }
1.1422 +
1.1423 + if (!iPowerOn)
1.1424 + {
1.1425 + return KErrNotReady;
1.1426 + }
1.1427 +
1.1428 + return KErrNone;
1.1429 + }
1.1430 +
1.1431 +TInt CTestCamera::ReserveCallBack(TAny* aThis)
1.1432 + {
1.1433 + const TECAMEvent event(KUidECamEventReserveComplete,KErrNone);
1.1434 + CTestCamera* testCamera = static_cast<CTestCamera*>(aThis);
1.1435 + if (testCamera->iObserver2)
1.1436 + {
1.1437 + testCamera->iObserver2->HandleEvent(event);
1.1438 + }
1.1439 + else
1.1440 + {
1.1441 + testCamera->iObserver->ReserveComplete(KErrNone);
1.1442 + }
1.1443 + return KErrNone;
1.1444 + }
1.1445 +
1.1446 +TInt CTestCamera::PowerOnCallBack(TAny* aThis)
1.1447 + {
1.1448 + TECAMEvent event(KUidECamEventPowerOnComplete,KErrNone);
1.1449 + CTestCamera* testCamera = static_cast<CTestCamera*>(aThis);
1.1450 + if (testCamera->iObserver2)
1.1451 + {
1.1452 + testCamera->iObserver2->HandleEvent(event);
1.1453 + }
1.1454 + else
1.1455 + {
1.1456 + testCamera->iObserver->PowerOnComplete(testCamera->iPowerOn ? KErrNone : KErrInUse);
1.1457 + }
1.1458 + return KErrNone;
1.1459 + }
1.1460 +
1.1461 +TInt CTestCamera::ImageCaptureCallBack(TAny* aThis)
1.1462 + {
1.1463 + CTestCamera* testCamera = static_cast<CTestCamera*>(aThis);
1.1464 + if (testCamera->iObserver2)
1.1465 + {
1.1466 + testCamera->iObserver2->ImageBufferReady((static_cast<CTestCamera*>(aThis))->iFrameCameraBuffer1,testCamera->iStillCaptureErr);
1.1467 + }
1.1468 + else
1.1469 + {
1.1470 + testCamera->iObserver->ImageReady(NULL,NULL,testCamera->iStillCaptureErr);
1.1471 + }
1.1472 + testCamera->iStillCaptureErr = KErrNone;
1.1473 + return KErrNone;
1.1474 + }
1.1475 +
1.1476 +TInt CTestCamera::VideoCaptureCallBack(TAny* aThis)
1.1477 + {
1.1478 + CTestCamera* testCamera = static_cast<CTestCamera*>(aThis);
1.1479 + if (testCamera->iObserver2)
1.1480 + {
1.1481 + testCamera->iObserver2->VideoBufferReady((static_cast<CTestCamera*>(aThis))->iFrameCameraBuffer1,testCamera->iVideoCaptureErr);
1.1482 + }
1.1483 + else
1.1484 + {
1.1485 + testCamera->iObserver->FrameBufferReady(NULL,testCamera->iVideoCaptureErr);
1.1486 + }
1.1487 + testCamera->iVideoCaptureErr = KErrNone;
1.1488 + return KErrNone;
1.1489 + }
1.1490 +
1.1491 +TInt CTestCamera::HandleEventCallBack(TAny* aThis)
1.1492 + {
1.1493 + CTestCamera* testCamera = static_cast<CTestCamera*>(aThis);
1.1494 + if (testCamera->iObserver2)
1.1495 + {
1.1496 + testCamera->iObserver2->HandleEvent(testCamera->iECamEvent);
1.1497 + }
1.1498 +
1.1499 + return KErrNone;
1.1500 + }
1.1501 +
1.1502 +TInt CTestCamera::HandleEvent2CallBack(TAny* aThis)
1.1503 + {
1.1504 + CTestCamera* testCamera = static_cast<CTestCamera*>(aThis);
1.1505 + if (testCamera->iObserver2)
1.1506 + {
1.1507 + testCamera->iObserver2->HandleEvent(testCamera->iECamEvent2);
1.1508 + }
1.1509 +
1.1510 + return KErrNone;
1.1511 + }
1.1512 +
1.1513 +//
1.1514 +// CTestCameraInfo
1.1515 +//
1.1516 +
1.1517 +CTestCameraInfo::CTestCameraInfo()
1.1518 + {
1.1519 + }
1.1520 +
1.1521 +CTestCameraInfo::~CTestCameraInfo()
1.1522 + {
1.1523 + }
1.1524 +
1.1525 +CTestCameraInfo* CTestCameraInfo::NewL()
1.1526 + {
1.1527 + FileDependencyUtil::CheckFileDependencyL();
1.1528 + return new (ELeave) CTestCameraInfo;
1.1529 + }
1.1530 +
1.1531 +TInt CTestCameraInfo::CamerasAvailable()
1.1532 + {
1.1533 + return 1;
1.1534 + }
1.1535 +
1.1536 +//void CTestCamera::CheckFileDependencyL()
1.1537 +void FileDependencyUtil::CheckFileDependencyL()
1.1538 + {
1.1539 + RFs fsSession;
1.1540 + RFile file;
1.1541 + CleanupClosePushL(fsSession);
1.1542 + User::LeaveIfError(fsSession.Connect());
1.1543 + TInt err = file.Open(fsSession, KTestCameraPluginName, EFileRead);
1.1544 + file.Close();
1.1545 + if(err != KErrNone)
1.1546 + {
1.1547 + User::LeaveIfError(KErrNotSupported);
1.1548 + }
1.1549 + CleanupStack::PopAndDestroy(); //fsSession
1.1550 + }
1.1551 +
1.1552 +// __________________________________________________________________________
1.1553 +// Exported proxy for instantiation method resolution
1.1554 +// Define the interface UIDs
1.1555 +const TImplementationProxy ImplementationTable[] =
1.1556 + {
1.1557 + IMPLEMENTATION_PROXY_ENTRY(KUidOnboardCameraTestPlugin, CTestCamera::NewL),
1.1558 + IMPLEMENTATION_PROXY_ENTRY(KUidOnboardCameraTestInfo, CTestCameraInfo::NewL)
1.1559 + };
1.1560 +
1.1561 +EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
1.1562 + {
1.1563 + aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
1.1564 +
1.1565 + return ImplementationTable;
1.1566 + }
1.1567 +