camerauis/cameraxui/cxengine/src/dummyengine/cxedummycamera.cpp
changeset 19 d9aefe59d544
child 42 feebad15db8c
equal deleted inserted replaced
3:8b2d6d0384b0 19:d9aefe59d544
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cxedummycamera.h"
       
    19 
       
    20 #if defined(CXE_USE_DUMMY_CAMERA) || defined(__WINSCW__)
       
    21 
       
    22 #include <bitdev.h>
       
    23 
       
    24 #include "cxutils.h"
       
    25 
       
    26 // Disable warnings about unused arguments
       
    27 #pragma warn_unusedarg off
       
    28 
       
    29 namespace
       
    30 {
       
    31     static const TSize IMAGE_CAPTURE_SIZES[] =
       
    32         {
       
    33         TSize(4000,3000),
       
    34         TSize(4000,2248),
       
    35         TSize(3264,2448),
       
    36         TSize(3264,1832),
       
    37         TSize(2592,1944),
       
    38         TSize(2592,1456),
       
    39         TSize(2048,1536),
       
    40         TSize(1600,1200),
       
    41         TSize(1280,960),
       
    42         TSize(1024,768),
       
    43         TSize(640,480)
       
    44         };
       
    45     static const int IMAGE_CAPTURE_SIZE_COUNT = sizeof(IMAGE_CAPTURE_SIZES)/sizeof(TSize);
       
    46 }
       
    47 
       
    48 
       
    49 CxeDummyCamera* CxeDummyCamera::NewL(MCameraObserver2& aObserver,TInt aCameraIndex,TInt aPriority, TInt aCameraVersion)
       
    50 {
       
    51     return new (ELeave) CxeDummyCamera( aObserver, aCameraIndex, aPriority, aCameraVersion );
       
    52 }
       
    53 
       
    54 
       
    55 CxeDummyCamera::CxeDummyCamera(MCameraObserver2& aObserver,TInt aCameraIndex,TInt aPriority, TInt aCameraVersion)
       
    56 : iObserver( aObserver ), iAdvancedSettings(0), iSnapshot(0), iStillImage(0), iImageProcessing(0)
       
    57 {
       
    58     iCommandTimer = CPeriodic::NewL(0);
       
    59 
       
    60     iInfo.iMaxZoom = 5;
       
    61     iInfo.iMaxDigitalZoom = 5;
       
    62     iInfo.iMaxDigitalZoomFactor = 0;
       
    63     iInfo.iMaxZoomFactor = 0;
       
    64     iInfo.iMinZoomFactor = 0;
       
    65     iInfo.iMinZoom = 0;
       
    66 
       
    67     iInfo.iNumImageSizesSupported = IMAGE_CAPTURE_SIZE_COUNT;
       
    68 }
       
    69 
       
    70 CxeDummyCamera::~CxeDummyCamera()
       
    71     {
       
    72     delete iCommandTimer;
       
    73     delete iAdvancedSettings;
       
    74     delete iSnapshot;
       
    75     delete iStillImage;
       
    76     delete iImageProcessing;
       
    77     }
       
    78 
       
    79 void CxeDummyCamera::doCommand( TCxeDummyCommand aCmd )
       
    80 {
       
    81     iCommandBuf.Insert( aCmd, 0 );
       
    82     if ( !iCommandTimer->IsActive() )
       
    83         {
       
    84         iCommandTimer->Start(100, 100, TCallBack(CxeDummyCamera::callBack, this));
       
    85         }
       
    86 }
       
    87 
       
    88 TInt CxeDummyCamera::callBack( TAny* aParam )
       
    89 {
       
    90     CxeDummyCamera* self = (CxeDummyCamera*)aParam;
       
    91     return self->doHandleCallback();
       
    92 }
       
    93 
       
    94 void CxeDummyCamera::CaptureImage()
       
    95 {
       
    96     doCommand( EProvideStillImage );
       
    97 
       
    98     if ( iSnapshot && iSnapshot->IsSnapshotActive() )
       
    99         {
       
   100         doCommand( EProvideSnapshot );
       
   101         }
       
   102 }
       
   103 
       
   104 void CxeDummyCamera::EnumerateCaptureSizes(TSize& aSize,TInt aSizeIndex,TFormat aFormat) const
       
   105 {
       
   106     if(aSizeIndex < IMAGE_CAPTURE_SIZE_COUNT)
       
   107         {
       
   108         aSize = IMAGE_CAPTURE_SIZES[aSizeIndex];
       
   109         }
       
   110     else
       
   111         {
       
   112         aSize = TSize(0,0);
       
   113         }
       
   114 }
       
   115 
       
   116 TInt CxeDummyCamera::doHandleCallback()
       
   117 {
       
   118     TCxeDummyCommand cmd = iCommandBuf[ 0 ];
       
   119     iCommandBuf.Remove( 0 );
       
   120 
       
   121     switch ( cmd )
       
   122         {
       
   123         case EReserve:
       
   124             {
       
   125             iState = EStReserved;
       
   126             TECAMEvent e( KUidECamEventReserveComplete, KErrNone );
       
   127             iObserver.HandleEvent( e );
       
   128             break;
       
   129             }
       
   130         case EPowerOn:
       
   131             {
       
   132             iState = EStPowerOn;
       
   133             TECAMEvent e( KUidECamEventPowerOnComplete, KErrNone );
       
   134             iObserver.HandleEvent( e );
       
   135             break;
       
   136             }
       
   137         case EProvideStillImage:
       
   138             {
       
   139             if ( !iStillImage )
       
   140                 {
       
   141                 iStillImage = new (ELeave) CxeDummyBuffer();
       
   142                 }
       
   143             iObserver.ImageBufferReady(*iStillImage, KErrNone);
       
   144             break;
       
   145             }
       
   146         case EProvideSnapshot:
       
   147             {
       
   148             TECAMEvent e( KUidECamEventCameraSnapshot, KErrNone );
       
   149             iObserver.HandleEvent( e );
       
   150             break;
       
   151             }
       
   152         }
       
   153 
       
   154     if ( !iCommandBuf.Count() )
       
   155         {
       
   156         iCommandTimer->Cancel();
       
   157         }
       
   158 
       
   159     return KErrNone;
       
   160 }
       
   161 
       
   162 void CxeDummyCamera::Reserve()
       
   163 {
       
   164     CX_DEBUG_ENTER_FUNCTION();
       
   165     iState = EStReserving;
       
   166     doCommand( EReserve );
       
   167     CX_DEBUG_EXIT_FUNCTION();
       
   168 }
       
   169 
       
   170 void CxeDummyCamera::Release()
       
   171 {
       
   172     CX_DEBUG_ENTER_FUNCTION();
       
   173     iState = EStReleased;
       
   174     CX_DEBUG_EXIT_FUNCTION();
       
   175 }
       
   176 
       
   177 void CxeDummyCamera::PowerOn()
       
   178 {
       
   179     iState = EStPoweringOn;
       
   180     doCommand( EPowerOn );
       
   181 }
       
   182 
       
   183 void CxeDummyCamera::PowerOff()
       
   184 {
       
   185     iState = EStReserved;
       
   186 }
       
   187 
       
   188 TAny* CxeDummyCamera::CustomInterface(TUid aInterface)
       
   189     {
       
   190     CX_DEBUG_ENTER_FUNCTION();
       
   191     CX_DEBUG(("CxeDummyCamera::CustomInterface: request for interface uid %x", aInterface));
       
   192 
       
   193     if ( aInterface == KECamMCameraAdvancedSettingsUid )
       
   194         {
       
   195         CX_DEBUG(("Advanced settings custom interface requested"));
       
   196         if ( !iAdvancedSettings )
       
   197             {
       
   198             iAdvancedSettings = new ( ELeave ) CxeDummyAdvancedSettings(this);
       
   199             }
       
   200         CX_DEBUG_EXIT_FUNCTION();
       
   201         return static_cast<MCameraAdvancedSettings*>( iAdvancedSettings );
       
   202         }
       
   203     else if (aInterface == KECamMCameraAdvancedSettings3Uid)
       
   204         {
       
   205         CX_DEBUG(("Advanced settings 3 custom interface requested"));
       
   206         if (!iAdvancedSettings)
       
   207             {
       
   208             iAdvancedSettings = new (ELeave) CxeDummyAdvancedSettings(this);
       
   209             }
       
   210         CX_DEBUG_EXIT_FUNCTION();
       
   211         return static_cast<MCameraAdvancedSettings3*> (iAdvancedSettings);
       
   212         }
       
   213     else if ( aInterface == KECamMCameraSnapshotUid )
       
   214         {
       
   215         CX_DEBUG(("Snapshot custom interface requested"));
       
   216         if ( !iSnapshot )
       
   217             {
       
   218             iSnapshot = new ( ELeave ) CxeDummySnapshot();
       
   219             }
       
   220         CX_DEBUG_EXIT_FUNCTION();
       
   221         return static_cast<MCameraSnapshot*>( iSnapshot );
       
   222         }
       
   223     else if ( aInterface == KECamMCameraDirectViewFinderUid )
       
   224         {
       
   225         CX_DEBUG(("Direct viewfinder custom interface requested"));
       
   226         if( !iDirectViewfinder )
       
   227             {
       
   228             iDirectViewfinder = new ( ELeave ) CxeDummyDirectViewfinder();
       
   229             }
       
   230         return static_cast<MCameraDirectViewFinder*>( iDirectViewfinder );
       
   231         }
       
   232     else if ( aInterface == KECamMCameraImageProcessingUid )
       
   233         {
       
   234         CX_DEBUG(("Image processing custom interface requested"));
       
   235         if (!iImageProcessing )
       
   236             {
       
   237             iImageProcessing = new ( ELeave ) CxeDummyImageProcessing;
       
   238             }
       
   239         return static_cast<MCameraImageProcessing*>( iImageProcessing );
       
   240         }
       
   241     CX_DEBUG_EXIT_FUNCTION();
       
   242     return NULL;
       
   243     }
       
   244 
       
   245 
       
   246 void CxeDummyBuffer::CreateBitmapL( const TSize& aSize )
       
   247     {
       
   248     CX_DEBUG_ENTER_FUNCTION();
       
   249 
       
   250     delete iBitmap;
       
   251     iBitmap = NULL;
       
   252 
       
   253     iBitmap = new (ELeave) CFbsBitmap();
       
   254     User::LeaveIfError( iBitmap->Create( aSize, EColor16MU ) );
       
   255     CFbsBitmapDevice* device = CFbsBitmapDevice::NewL( iBitmap );
       
   256     CleanupStack::PushL( device );
       
   257     CFbsBitGc* gc;
       
   258     User::LeaveIfError( device->CreateContext(gc) );
       
   259     CleanupStack::PushL(gc);
       
   260 
       
   261     const TInt gridsize = 16;
       
   262 
       
   263     gc->SetPenStyle( CGraphicsContext::ENullPen );
       
   264     gc->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   265 
       
   266     for ( TInt x = 0; x < aSize.iWidth/16; x++ )
       
   267         {
       
   268         for ( TInt y = 0; y < aSize.iWidth/16; y++ )
       
   269             {
       
   270             gc->SetBrushColor( ( ( x + y ) & 1 ) ? 0x00AAAAAA : 0x00888888 );
       
   271             gc->DrawRect( TRect( TPoint( x * 16, y * 16 ), TSize( gridsize, gridsize ) ) );
       
   272             }
       
   273         }
       
   274 
       
   275     CleanupStack::PopAndDestroy(gc);
       
   276     CleanupStack::PopAndDestroy(device);
       
   277 
       
   278     CX_DEBUG_EXIT_FUNCTION();
       
   279     }
       
   280 
       
   281 void CxeDummySnapshot::PrepareSnapshotL(CCamera::TFormat aFormat, const TPoint& aPosition, const TSize& aSize, const TRgb& aBgColor, TBool aMaintainAspectRatio)
       
   282 {
       
   283     CX_DEBUG_ENTER_FUNCTION();
       
   284     PrepareSnapshotL( aFormat, aSize, aMaintainAspectRatio );
       
   285     CX_DEBUG_EXIT_FUNCTION();
       
   286 }
       
   287 
       
   288 void CxeDummySnapshot::PrepareSnapshotL(CCamera::TFormat aFormat, const TSize& aSize, TBool aMaintainAspectRatio)
       
   289 {
       
   290     CX_DEBUG_ENTER_FUNCTION();
       
   291     if ( !iBuffer )
       
   292         {
       
   293         iBuffer = new ( ELeave ) CxeDummyBuffer();
       
   294         }
       
   295     iBuffer->CreateBitmapL( aSize );
       
   296     CX_DEBUG_EXIT_FUNCTION();
       
   297 }
       
   298 
       
   299 
       
   300 // CxeDummyDirectViewfinder
       
   301 
       
   302 CxeDummyDirectViewfinder::CxeDummyDirectViewfinder()
       
   303     : iState(CCamera::CCameraDirectViewFinder::EViewFinderInActive)
       
   304     {
       
   305     CX_DEBUG_IN_FUNCTION();
       
   306     }
       
   307 
       
   308 CxeDummyDirectViewfinder::~CxeDummyDirectViewfinder()
       
   309     {
       
   310     CX_DEBUG_ENTER_FUNCTION();
       
   311     CX_DEBUG_EXIT_FUNCTION();
       
   312     }
       
   313 
       
   314 void CxeDummyDirectViewfinder::Release()
       
   315     {
       
   316     iState = CCamera::CCameraDirectViewFinder::EViewFinderInActive;
       
   317     }
       
   318 
       
   319 void CxeDummyDirectViewfinder::PauseViewFinderDirectL()
       
   320     {
       
   321     if( iState != CCamera::CCameraDirectViewFinder::EViewFinderActive )
       
   322         {
       
   323         User::Leave( KErrGeneral );
       
   324         }
       
   325     iState = CCamera::CCameraDirectViewFinder::EViewFinderPause;
       
   326     }
       
   327 
       
   328 void CxeDummyDirectViewfinder::ResumeViewFinderDirectL()
       
   329     {
       
   330     if( iState != CCamera::CCameraDirectViewFinder::EViewFinderPause )
       
   331         {
       
   332         User::Leave( KErrGeneral );
       
   333         }
       
   334     iState = CCamera::CCameraDirectViewFinder::EViewFinderActive;
       
   335     }
       
   336 
       
   337 CCamera::CCameraDirectViewFinder::TViewFinderState CxeDummyDirectViewfinder::ViewFinderState() const
       
   338     {
       
   339     return iState;
       
   340     }
       
   341 
       
   342 
       
   343 // CxeDummyAdvancedSettings
       
   344 
       
   345 CxeDummyAdvancedSettings::CxeDummyAdvancedSettings(CCamera* aCamera)
       
   346     : iCamera( aCamera )
       
   347 {
       
   348     QT_TRANSLATE_SYMBIAN_LEAVE_TO_EXCEPTION(iNotificationTimer = CPeriodic::NewL(0));
       
   349     iZoomValue = 0;
       
   350 }
       
   351 
       
   352 CxeDummyAdvancedSettings::~CxeDummyAdvancedSettings()
       
   353 {
       
   354     delete iNotificationTimer;
       
   355     iNotificationTimer = NULL;
       
   356 
       
   357     iClientNofications.Reset();
       
   358     iClientNofications.Close();
       
   359 }
       
   360 
       
   361 void CxeDummyAdvancedSettings::GetDigitalZoomStepsForStillL(RArray<TInt>& aDigitalZoomSteps, TValueInfo& aInfo, TInt aSizeIndex,
       
   362                 CCamera::TFormat aFormat, TBool& aIsInfluencePossible) const
       
   363 {
       
   364 
       
   365     aDigitalZoomSteps.Reset();
       
   366     aDigitalZoomSteps.AppendL(0);
       
   367     aDigitalZoomSteps.AppendL(1);
       
   368     aDigitalZoomSteps.AppendL(2);
       
   369     aDigitalZoomSteps.AppendL(3);
       
   370     aDigitalZoomSteps.AppendL(4);
       
   371     aDigitalZoomSteps.AppendL(5);
       
   372 
       
   373 }
       
   374 
       
   375 void CxeDummyAdvancedSettings::GetDigitalZoomStepsL(RArray<TInt>& aDigitalZoomSteps, TValueInfo& aInfo) const
       
   376 {
       
   377     aDigitalZoomSteps.Reset();
       
   378     aDigitalZoomSteps.AppendL(0);
       
   379     aDigitalZoomSteps.AppendL(1);
       
   380     aDigitalZoomSteps.AppendL(2);
       
   381     aDigitalZoomSteps.AppendL(3);
       
   382     aDigitalZoomSteps.AppendL(4);
       
   383     aDigitalZoomSteps.AppendL(5);
       
   384 }
       
   385 
       
   386 
       
   387 TInt CxeDummyAdvancedSettings::SupportedFocusModes() const
       
   388 {
       
   389     return CCamera::CCameraAdvancedSettings::EFocusModeAuto;
       
   390 }
       
   391 
       
   392 CCamera::CCameraAdvancedSettings::TFocusMode CxeDummyAdvancedSettings::FocusMode() const
       
   393 {
       
   394     return iFocusMode;
       
   395 }
       
   396 
       
   397 void CxeDummyAdvancedSettings::SetFocusMode(CCamera::CCameraAdvancedSettings::TFocusMode aFocusMode)
       
   398 {
       
   399     iFocusMode = aFocusMode;
       
   400 
       
   401     // notify client with relevant event..
       
   402     queueClientNotification(KUidECamEventCameraSettingFocusMode, KErrNone);
       
   403 }
       
   404 
       
   405 TInt CxeDummyAdvancedSettings::SupportedFocusRanges() const
       
   406 {
       
   407     return CCamera::CCameraAdvancedSettings::EFocusRangeAuto
       
   408          | CCamera::CCameraAdvancedSettings::EFocusRangeHyperfocal
       
   409          | CCamera::CCameraAdvancedSettings::EFocusRangeInfinite
       
   410          | CCamera::CCameraAdvancedSettings::EFocusRangeMacro
       
   411          | CCamera::CCameraAdvancedSettings::EFocusRangeNormal
       
   412          | CCamera::CCameraAdvancedSettings::EFocusRangePortrait
       
   413          | CCamera::CCameraAdvancedSettings::EFocusRangeSuperMacro
       
   414          | CCamera::CCameraAdvancedSettings::EFocusRangeTele;
       
   415 }
       
   416 
       
   417 CCamera::CCameraAdvancedSettings::TFocusRange CxeDummyAdvancedSettings::FocusRange() const
       
   418 {
       
   419     return iFocusRange;
       
   420 }
       
   421 
       
   422 void CxeDummyAdvancedSettings::SetFocusRange(CCamera::CCameraAdvancedSettings::TFocusRange aFocusRange)
       
   423 {
       
   424     iFocusRange = aFocusRange;
       
   425     queueClientNotification(KUidECamEventCameraSettingFocusRange2, KErrNone);
       
   426 }
       
   427 
       
   428 TInt CxeDummyAdvancedSettings::SupportedAutoFocusTypes() const
       
   429 {
       
   430     return CCamera::CCameraAdvancedSettings::EAutoFocusTypeSingle
       
   431          | CCamera::CCameraAdvancedSettings::EAutoFocusTypeOff;
       
   432 }
       
   433 
       
   434 CCamera::CCameraAdvancedSettings::TAutoFocusType CxeDummyAdvancedSettings::AutoFocusType() const
       
   435 {
       
   436     return iFocusType;
       
   437 }
       
   438 
       
   439 void CxeDummyAdvancedSettings::SetAutoFocusType(CCamera::CCameraAdvancedSettings::TAutoFocusType aAutoFocusType)
       
   440 {
       
   441     iFocusType = aAutoFocusType;
       
   442     queueClientNotification(KUidECamEventCameraSettingAutoFocusType2, KErrNone);
       
   443 
       
   444     // If AF set to OFF, remove any "optimal focus" events from earlier
       
   445     // started focusing.
       
   446     if (iFocusType == CCamera::CCameraAdvancedSettings::EAutoFocusTypeOff) {
       
   447         for (TInt i = iClientNofications.Count()-1; i >= 0; i--) {
       
   448              if (iClientNofications[i].iEventUid == KUidECamEventCameraSettingsOptimalFocus) {
       
   449                  iClientNofications.Remove(i);
       
   450              }
       
   451         }
       
   452     }
       
   453     else {
       
   454         // Otherwise queue optimal focus event for this focusing request.
       
   455         queueClientNotification(KUidECamEventCameraSettingsOptimalFocus, KErrNone);
       
   456     }
       
   457 }
       
   458 
       
   459 
       
   460 
       
   461 
       
   462 
       
   463 
       
   464 
       
   465 
       
   466 void CxeDummyAdvancedSettings::queueClientNotification(TUid aUid, TInt aStatus)
       
   467 {
       
   468     CX_DEBUG_ENTER_FUNCTION();
       
   469     iClientNofications.Append(TCxeDummyNotification(aUid,aStatus));
       
   470     if (iNotificationTimer == NULL) {
       
   471         QT_TRANSLATE_SYMBIAN_LEAVE_TO_EXCEPTION(iNotificationTimer = CPeriodic::NewL(0));
       
   472     }
       
   473 
       
   474     if (!iNotificationTimer->IsActive()) {
       
   475         TCallBack cb(CxeDummyAdvancedSettings::clientNotificationCallback, this);
       
   476         iNotificationTimer->Start(100, 100, cb);
       
   477     }
       
   478     CX_DEBUG_EXIT_FUNCTION();
       
   479 }
       
   480 
       
   481 void CxeDummyAdvancedSettings::doClientNotification( )
       
   482 {
       
   483     CX_DEBUG_ENTER_FUNCTION();
       
   484     const TInt count(iClientNofications.Count());
       
   485 
       
   486     if (count != 0) {
       
   487         const TCxeDummyNotification& notify(iClientNofications[count-1]);
       
   488         const TECAMEvent event(notify.iEventUid, notify.iStatus);
       
   489         iClientNofications.Remove(count-1);
       
   490         (static_cast<CxeDummyCamera*>(iCamera))->iObserver.HandleEvent(event);
       
   491     }
       
   492     else {
       
   493         delete iNotificationTimer;
       
   494         iNotificationTimer = NULL;
       
   495     }
       
   496     CX_DEBUG_EXIT_FUNCTION();
       
   497 }
       
   498 
       
   499 TInt CxeDummyAdvancedSettings::clientNotificationCallback(TAny* aParam)
       
   500 {
       
   501     (static_cast<CxeDummyAdvancedSettings*>(aParam))->doClientNotification();
       
   502     return 1; // Not used by CPeriodic
       
   503 }
       
   504 
       
   505 
       
   506 #endif // defined(CXE_USE_DUMMY_CAMERA) || defined(__WINSCW__)