camappengine/Engine/Src/CaeEngineImpStillAndVf.cpp
changeset 15 50d5061ee01e
parent 14 34024902876b
child 17 880d946921e4
equal deleted inserted replaced
14:34024902876b 15:50d5061ee01e
     1 /*
       
     2 * Copyright (c) 2002-2007 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:  Camera Application Engine implementation still capturing, 
       
    15 *                settings, and view finder methods
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include <fbs.h>                            // For CFbsBitmap
       
    24 
       
    25 #include "CaeEngineImp.h"                   // Engine implementation header.
       
    26 #include "CaeStillQualityLevels.h"          // For still capturing quality levels.
       
    27 #include "CaeVideoQualityLevels.h"          // Needed just in destructor.
       
    28 #include "CaeVideoTimes.h"                  // Needed just in destructor.
       
    29 #include "CaeStillStatesActive.h"                
       
    30 
       
    31 #ifdef CAE_TEST_VERSION
       
    32 #include "CaeEngineImpTestErrors.h"         // For TEST_VERSION compilation only
       
    33 #endif
       
    34 
       
    35 #include "OstTraceDefinitions.h"
       
    36 #ifdef OST_TRACE_COMPILER_IN_USE
       
    37 #include "CaeEngineImpStillAndVfTraces.h"
       
    38 #endif
       
    39 
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ===============================
       
    42 
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CCaeEngine::NewL
       
    46 // Two-phased constructor. Calls CCaeEngineImp's NewL().
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 EXPORT_C CCaeEngine* CCaeEngine::NewL()
       
    50     {
       
    51     return CCaeEngineImp::NewL();
       
    52     }
       
    53 
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CCaeEngineImp::CCaeEngineImp
       
    57 // Default constructor.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CCaeEngineImp::CCaeEngineImp(): 
       
    61     iZoomMode( EZoomModeDigital ), 
       
    62     iExposureMode( CCamera::EExposureAuto ),
       
    63     iWhiteBalanceMode( CCamera::EWBAuto ), 
       
    64     iFlashMode( CCamera::EFlashNone ),
       
    65     iVideoTimesInterval( KVideoTimesIntervalDefault ), 
       
    66     iMaxClipSizeInBytes( KMMFNoMaxClipSize ), 
       
    67     iMaxClipSizeInBytesPrep( KMMFNoMaxClipSize )
       
    68     {
       
    69     }
       
    70 
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CCaeEngineImp::~CCaeEngineImp
       
    74 // Destructor.
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 CCaeEngineImp::~CCaeEngineImp()
       
    78     {
       
    79     LOGTEXT( _L( "Cae: CCaeEngineImp::~CCaeEngineImp() entering" ) );
       
    80 
       
    81     // Cancels/closes/stops still capturing, video recording, and view finding.
       
    82     CancelAllActivities();
       
    83 
       
    84     // Delete extension implementations
       
    85 	iExtension.ResetAndDestroy();
       
    86 
       
    87     // Delete the state machine
       
    88     // Note: This must be done after destroying extensions because there is some
       
    89     // validity checking in the iStillStatesActive destructor.
       
    90     delete( iStillStatesActive );
       
    91 
       
    92     // Delete interface implementation lists. 
       
    93 	// Close for each iImplementations before closing 
       
    94 	// iExtInterfaceImplementationLists.
       
    95 	for ( TInt i = 0; i < iExtInterfaceImplementationLists.Count(); i++ )
       
    96 		{
       
    97 		iExtInterfaceImplementationLists[i].iImplementations->Close();
       
    98 		delete( iExtInterfaceImplementationLists[i].iImplementations );
       
    99 		}
       
   100 	iExtInterfaceImplementationLists.Close();
       
   101 
       
   102     // Delete custom interface list items
       
   103 	iExtCustomInterfaceImplementations.Close();
       
   104 
       
   105     delete iVideoType;
       
   106     delete iVideoClipFileName;
       
   107 
       
   108     // Turn camera power off first, then release camera.
       
   109     if ( iCamera ) 
       
   110         {
       
   111         if ( iReserved ) 
       
   112             {
       
   113             if ( iPowerOn ) 
       
   114                 {
       
   115                 iCamera->PowerOff();
       
   116                 }
       
   117             iCamera->Release();
       
   118             }
       
   119         }
       
   120 
       
   121     delete iVideoFrameSizePrep;
       
   122     delete iVideoFrameSize;
       
   123 
       
   124     delete iVideoTimes;
       
   125     delete iVideoTimesCallback;
       
   126     delete iVideoRecorder;
       
   127 
       
   128     delete iVideoQualityLevelsCont;
       
   129     delete iStillQualityLevelsCont;
       
   130     
       
   131     delete iCallbackActive;
       
   132 
       
   133     delete iInfo;
       
   134 
       
   135     delete iCamera;
       
   136 
       
   137 	REComSession::FinalClose();
       
   138 
       
   139     LOGTEXT( _L( "Cae: CCaeEngineImp::~CCaeEngineImp() returning" ) );
       
   140 
       
   141     // For RTRT code coverage analysis.
       
   142     // #pragma attol insert _ATCPQ_DUMP(0);
       
   143     }
       
   144 
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CCaeEngineImp::ConstructL
       
   148 // Symbian 2nd phase constructor that can leave.
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 void CCaeEngineImp::ConstructL( TInt aCameraIndex, TInt aDisplayIndex )
       
   152     {
       
   153     LOGTEXT2( _L( "Cae: CCaeEngineImp::ConstructL() entering with camera index %d" ), 
       
   154     	aCameraIndex );
       
   155     
       
   156     OstTrace0( CAMERASRV_PERFORMANCE, CCAEENGINEIMP_CONSTRUCTL, "e_CAM_ENG_INIT 1" );   //CAE_ENGINE_INIT_START
       
   157         
       
   158     if ( ( aCameraIndex < 0 ) || 
       
   159          ( aCameraIndex >= CCamera::CamerasAvailable() ) )
       
   160         {
       
   161         LOGTEXT2( _L( "Cae: CCaeEngineImp::ConstructL leaving KErrHardwareNotAvailable, aCameraIndex=%d" ), aCameraIndex );
       
   162         User::Leave( KErrHardwareNotAvailable );
       
   163         }
       
   164 
       
   165     // Create a new Camera API implementation object, if supported
       
   166     TRAPD( err, iCamera = CCamera::New2L( static_cast<MCameraObserver2&>(*this), aCameraIndex, KCameraPriority ) );
       
   167     if ( err )
       
   168         {
       
   169         LOGTEXT2( _L( "Cae: CCaeEngineImp::ConstructL() CCamera::New2L return code=%d" ), err ); 
       
   170 
       
   171         // Create old Camera API implementation object.
       
   172         iCamera = CCamera::NewL( static_cast<MCameraObserver&>(*this), aCameraIndex );
       
   173         LOGTEXT( _L( "Cae: CCaeEngineImp::ConstructL() using MCameraObserver" )); 
       
   174         }
       
   175     else
       
   176         {
       
   177         LOGTEXT( _L( "Cae: CCaeEngineImp::ConstructL() using MCameraObserver2" )); 
       
   178         }
       
   179 
       
   180 
       
   181     // Get camera handle.
       
   182     iCameraHandle = iCamera->Handle();
       
   183 
       
   184     // Set display index
       
   185     iDisplayIndex = aDisplayIndex;
       
   186 
       
   187     // Create and initialize info object.
       
   188     iInfo = new( ELeave ) TCamAppEngineInfo;
       
   189     InitializeInfo( *iCamera );
       
   190 
       
   191     // Create active object for calling methods from callbacks.
       
   192     iCallbackActive = CCaeCallbackActive::NewL( *this );
       
   193 
       
   194     // Create still quality levels container object.
       
   195     iStillQualityLevelsCont = CCaeStillQualityLevelsCont::NewL();
       
   196 
       
   197     // Set default value for video recording stopping 
       
   198     iAsyncVideoStopEnabled = EFalse;
       
   199     
       
   200 	// Create interface lists. 
       
   201 	// The order of interface lists in iExtInterfaceImplementationLists
       
   202 	// should not be changed later as the order must always match to 
       
   203 	// TCaeExtensionInterfaceIndexes enum.
       
   204 	for ( TInt i = 0; KCaeSupportedExtensionInterfaceUids[i].iUid != NULL; i++ )
       
   205 		{
       
   206 		TCaeExtensionInterfaceImplListItem listItem;
       
   207 
       
   208 		RArray<TCaeExtensionInterfaceImplItem>* emptyImplementationArray = 
       
   209 			new(ELeave) RArray<TCaeExtensionInterfaceImplItem>(
       
   210 			TCaeExtensionInterfaceImplItemGranularity );
       
   211 
       
   212 		listItem.iInterfaceUid = KCaeSupportedExtensionInterfaceUids[i];
       
   213 		listItem.iImplementations = emptyImplementationArray; 
       
   214 		
       
   215 		// Copy the list item to the end of the list.Give ownership of 
       
   216         // emptyImplementationArray.
       
   217         CleanupStack::PushL( emptyImplementationArray );
       
   218 		iExtInterfaceImplementationLists.AppendL( listItem ); 
       
   219         CleanupStack::Pop( emptyImplementationArray );
       
   220 		}
       
   221 
       
   222     // Create the state machine for still capturing
       
   223     iStillStatesActive = CCaeStillStatesActive::NewL( *iCamera, *iInfo,
       
   224         *( iExtInterfaceImplementationLists[KCaeExtProcessImageInterfaceIndex].iImplementations  ) );
       
   225 
       
   226 	// Create extensions and populate the extension array 
       
   227 	PopulateExtensionArrayL();
       
   228     
       
   229     OstTrace0( CAMERASRV_PERFORMANCE, DUP1_CCAEENGINEIMP_CONSTRUCTL, "e_CAM_ENG_INIT 0" );  //CAE_ENGINE_INIT_END
       
   230     
       
   231     LOGTEXT( _L( "Cae: CCaeEngineImp::ConstructL() returning" ) );
       
   232     }
       
   233 
       
   234 
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // CCaeEngineImp::NewL
       
   238 // Two-phased constructor.
       
   239 // -----------------------------------------------------------------------------
       
   240 //
       
   241 CCaeEngineImp* CCaeEngineImp::NewL()
       
   242     {
       
   243     LOGTEXT( _L( "Cae: CCaeEngineImp::NewL() entering" ) );
       
   244 
       
   245     CCaeEngineImp* self = new( ELeave ) CCaeEngineImp();
       
   246 
       
   247     CleanupStack::PushL( self );
       
   248     self->ConstructL( 0, 0 ); // Construct with default camera index 0 and display index 0
       
   249     CleanupStack::Pop( self );
       
   250 
       
   251     LOGTEXT( _L( "Cae: CCaeEngineImp::NewL() returning" ) );
       
   252 
       
   253     return self;
       
   254     }
       
   255 
       
   256     
       
   257 // -----------------------------------------------------------------------------
       
   258 // CCaeEngineImp::PopulateExtensionArrayL
       
   259 // Get a list of extension implementations via ECom, construct the extensions and 
       
   260 // add those the the array.
       
   261 // -----------------------------------------------------------------------------
       
   262 //
       
   263 void CCaeEngineImp::PopulateExtensionArrayL()
       
   264 	{
       
   265 	LOGTEXT( _L( "Cae: CCaeEngineImp::PopulateExtensionArrayL() entering" ) );
       
   266 
       
   267 	// Get a list of all extensions from ECom
       
   268 	TEComResolverParams resolverParams;
       
   269 	resolverParams.SetDataType ( KExtensionTypeStringDesc );
       
   270 	resolverParams.SetWildcardMatch ( EFalse );
       
   271 	RImplInfoPtrArray implInfoArray;
       
   272 	REComSession::ListImplementationsL( KExtensionInterfaceUid, resolverParams, 
       
   273 		implInfoArray );
       
   274 	// This should be called only after ListImplementationsL
       
   275 	CleanupResetAndDestroyPushL( implInfoArray ); 
       
   276     
       
   277 	LOGTEXT2( _L( "Cae: CCaeEngineImp::PopulateExtensionArrayL: extension count: %d" ),
       
   278 		implInfoArray.Count());
       
   279 	
       
   280 	// Create each extension via ECom and add it to the list 
       
   281 	for ( TInt i = 0; i < implInfoArray.Count(); i++ )
       
   282 		{		
       
   283 		MExtension* extension = NULL;
       
   284 		
       
   285 		// Trap the construction as if one extension fails to construct it 
       
   286 		// should not stop others from constructing
       
   287     	LOGTEXT2( _L( "Cae: CCaeEngineImp::PopulateExtensionArrayL: load extension uid=%x" ),
       
   288 	    	implInfoArray[i]->ImplementationUid().iUid);
       
   289 		
       
   290 		TRAPD( error, extension = MExtension::NewExtensionL( 
       
   291 			implInfoArray[i]->ImplementationUid(), 
       
   292 			(MExtensionCallbackInterface*) this ));
       
   293 
       
   294 		if ( error || !extension)
       
   295 			{
       
   296 			// If one extension is failing we skip that.
       
   297 			#ifdef _DEBUG
       
   298 			TBuf<256> text;
       
   299 			text.Format(_L( "Cae: CCaeEngineImp::PopulateExtensionArrayL: NewExtensionL leaved, uid=%x, error=%d, extension=%x" ),
       
   300 				implInfoArray[i]->ImplementationUid().iUid, error, extension );
       
   301 			LOGTEXT( text );
       
   302 			#endif
       
   303 
       
   304 			delete( extension );
       
   305 			}
       
   306 		else
       
   307 			{
       
   308 			iExtension.AppendL( extension );
       
   309 			}
       
   310 		}
       
   311 
       
   312 	CleanupStack::PopAndDestroy( &implInfoArray );
       
   313 
       
   314 	LOGTEXT( _L( "Cae: CCaeEngineImp::PopulateExtensionArrayL() returning" ) );
       
   315 	}
       
   316 
       
   317 
       
   318 // -----------------------------------------------------------------------------
       
   319 // CCaeEngineImp::SetCamAppEngineObserver
       
   320 // -----------------------------------------------------------------------------
       
   321 //
       
   322 void CCaeEngineImp::SetCamAppEngineObserver( MCamAppEngineObserver& aObserver )
       
   323     {
       
   324     LOGTEXT( _L( "Cae: CCaeEngineImp::SetCamAppEngineObserver()" ) );
       
   325 
       
   326     iCaeObserver = &aObserver;
       
   327     iStillStatesActive->SetCamAppEngineObserver( aObserver );
       
   328     }
       
   329 
       
   330 
       
   331 // -----------------------------------------------------------------------------
       
   332 // CCaeEngineImp::GetInfo
       
   333 // -----------------------------------------------------------------------------
       
   334 //
       
   335 void CCaeEngineImp::GetInfo( TCamAppEngineInfo& aInfo ) const
       
   336     {
       
   337     LOGTEXT( _L( "Cae: CCaeEngineImp::GetInfo()" ) );
       
   338  
       
   339     aInfo = *iInfo;
       
   340     }
       
   341 
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 // CCaeEngineImp::InitL
       
   345 // Initialise the engine for still image capturing using default parameters.
       
   346 // -----------------------------------------------------------------------------
       
   347 //
       
   348 void CCaeEngineImp::InitL( TBool aCreateSnapImage )
       
   349     {
       
   350     LOGTEXT( _L( "Cae: CCaeEngineImp::InitL() entering" ) );
       
   351 
       
   352     iStillStatesActive->SetSnapImageCreation( aCreateSnapImage );
       
   353 
       
   354     // To allow re-initialization, release the camera (first cancels possible 
       
   355     // activities and turns camera power off).
       
   356     Release();
       
   357 
       
   358     // Init to default quality levels.
       
   359     iInfo->iNumStillQualityLevelsSupported = 
       
   360         iStillQualityLevelsCont->InitDefaultsL();
       
   361 
       
   362     // Reserve camera (and after succesfull reserve, camera power will be 
       
   363     // turned on).
       
   364 
       
   365     iResetToPreviousSettings = ETrue; // This requests here to set the camera
       
   366                                       // to default settings after power is on.
       
   367     iCamera->Reserve();
       
   368 
       
   369     LOGTEXT( _L( "Cae: CCaeEngineImp::InitL() returning" ) );
       
   370     }
       
   371 
       
   372 
       
   373 // -----------------------------------------------------------------------------
       
   374 // CCaeEngineImp::InitL
       
   375 // Initialise the engine for still image capturing either using default 
       
   376 // parameters or parameters from ini-file.
       
   377 // -----------------------------------------------------------------------------
       
   378 //
       
   379 void CCaeEngineImp::InitL( 
       
   380     TUid aSdUidStillQltyLevels, 
       
   381     TBool aCreateSnapImage )
       
   382     {
       
   383     if( aSdUidStillQltyLevels == KNullUid )
       
   384         {
       
   385         InitL( aCreateSnapImage );
       
   386         }
       
   387     else
       
   388         {
       
   389         LOGTEXT( _L( "Cae: CCaeEngineImp::InitL(aSdUidStillQltyLevels): NOT SUPPORTED, leaving" ) );
       
   390         User::Leave( KErrNotSupported );
       
   391         }
       
   392     }
       
   393 
       
   394 
       
   395 // -----------------------------------------------------------------------------
       
   396 // CCaeEngineImp::Reserve
       
   397 // Calls Camera API Reserve().
       
   398 // -----------------------------------------------------------------------------
       
   399 //
       
   400 void CCaeEngineImp::Reserve()
       
   401     {
       
   402     LOGTEXT( _L( "Cae: CCaeEngineImp::Reserve() entering" ) );
       
   403 
       
   404     if ( !iReserved ) 
       
   405         {
       
   406         iResetToPreviousSettings = ETrue;
       
   407         iCamera->Reserve();
       
   408         }
       
   409     else if ( !iPowerOn ) // in case previous reserve ok, but poweron failed
       
   410         {
       
   411         PowerOn();
       
   412         }
       
   413 
       
   414 
       
   415     LOGTEXT( _L( "Cae: CCaeEngineImp::Reserve() returning" ) );
       
   416     }
       
   417 
       
   418 
       
   419 // -----------------------------------------------------------------------------
       
   420 // CCaeEngineImp::Release
       
   421 // Calls Camera API Release().
       
   422 // -----------------------------------------------------------------------------
       
   423 //
       
   424 void CCaeEngineImp::Release()
       
   425     {
       
   426     LOGTEXT( _L( "Cae: CCaeEngineImp::Release() entering" ) );
       
   427 
       
   428     if ( iReserved ) 
       
   429         {
       
   430         PowerOff();         // Cancel all activities (if any) and turn power off.
       
   431         iCamera->Release(); // Release Camera HW.
       
   432         iReserved = EFalse;
       
   433         iStillPrepared = EFalse;
       
   434         iVideoPrepared = EFalse;
       
   435         iVideoOpened = EFalse;
       
   436         }
       
   437 
       
   438     LOGTEXT( _L( "Cae: CCaeEngineImp::Release() returning" ) );
       
   439     }
       
   440 
       
   441 
       
   442 // -----------------------------------------------------------------------------
       
   443 // CCaeEngineImp::PowerOn
       
   444 // Calls Camera API PowerOn().
       
   445 // -----------------------------------------------------------------------------
       
   446 //
       
   447 void CCaeEngineImp::PowerOn()
       
   448     {
       
   449     LOGTEXT( _L( "Cae: CCaeEngineImp::PowerOn() entering" ) );
       
   450 
       
   451     if ( iReserved && !iPowerOn ) 
       
   452         {
       
   453         iCamera->PowerOn();
       
   454         }
       
   455 
       
   456     LOGTEXT( _L( "Cae: CCaeEngineImp::PowerOn() returning" ) );
       
   457     }
       
   458 
       
   459 
       
   460 // -----------------------------------------------------------------------------
       
   461 // CCaeEngineImp::PowerOff
       
   462 // Calls Camera API PowerOff().
       
   463 // -----------------------------------------------------------------------------
       
   464 //
       
   465 void CCaeEngineImp::PowerOff()
       
   466     {
       
   467     LOGTEXT( _L( "Cae: CCaeEngineImp::PowerOff() entering" ) );
       
   468 
       
   469     if ( iPowerOn ) 
       
   470         {
       
   471         CancelAllActivities();
       
   472         iCamera->PowerOff();
       
   473         iPowerOn = EFalse;
       
   474         }
       
   475 
       
   476     LOGTEXT( _L( "Cae: CCaeEngineImp::PowerOff() returning" ) );
       
   477     }
       
   478 
       
   479 
       
   480 // -----------------------------------------------------------------------------
       
   481 // CCaeEngineImp::SetZoomModeL
       
   482 // -----------------------------------------------------------------------------
       
   483 //
       
   484 void CCaeEngineImp::SetZoomModeL( 
       
   485     TZoomMode aZoomMode )
       
   486     {
       
   487     LOGTEXT( _L( "Cae: CCaeEngineImp::SetZoomModeL() entering" ) );
       
   488 
       
   489     // Currently supporting digital and optical zooms, not EZoomModeOpticalDigital.
       
   490     if ( ( aZoomMode != EZoomModeDigital ) && ( aZoomMode != EZoomModeOptical ) )
       
   491         {
       
   492         LOGTEXT2( _L( "Cae: CCaeEngineImp::SetZoomModeL leaving KErrNotSupported, aZoomMode=%d" ), aZoomMode );
       
   493         User::Leave( KErrNotSupported );
       
   494         }
       
   495 
       
   496     iZoomMode = aZoomMode;
       
   497 
       
   498     LOGTEXT( _L( "Cae: CCaeEngineImp::SetZoomModeL() returning" ) );
       
   499     }
       
   500 
       
   501 
       
   502 // -----------------------------------------------------------------------------
       
   503 // CCaeEngineImp::ZoomMode
       
   504 // -----------------------------------------------------------------------------
       
   505 //
       
   506 CCaeEngine::TZoomMode CCaeEngineImp::ZoomMode() const
       
   507     {
       
   508     LOGTEXT( _L( "Cae: CCaeEngineImp::ZoomMode()" ) );
       
   509 
       
   510     return iZoomMode;
       
   511     }
       
   512 
       
   513 
       
   514 // -----------------------------------------------------------------------------
       
   515 // CCaeEngineImp::SetZoomValueL
       
   516 // Calls Camera API SetDigitalZoomFactorL() or SetZoomFactorL().
       
   517 // -----------------------------------------------------------------------------
       
   518 //
       
   519 void CCaeEngineImp::SetZoomValueL( 
       
   520     TInt aZoomValue )
       
   521     {
       
   522     LOGTEXT( _L( "Cae: CCaeEngineImp::SetZoomValueL() entering" ) );
       
   523 
       
   524     CheckPowerL();
       
   525 
       
   526     switch ( iZoomMode )
       
   527         {
       
   528         case EZoomModeDigital:
       
   529             // Leave if zoom factor is out of range.
       
   530             if ( ( aZoomValue < 0 ) || 
       
   531                  ( aZoomValue > iInfo->iMaxDigitalZoom ) )
       
   532                 {
       
   533                 LOGTEXT2( _L( "Cae: CCaeEngineImp::SetZoomValueL leaving KErrArgument, aZoomValue=%d" ), aZoomValue );
       
   534                 User::Leave( KErrArgument );
       
   535                 }
       
   536             // Set DIGITAL zoom value.
       
   537             iCamera->SetDigitalZoomFactorL( aZoomValue );
       
   538             iZoomValue = aZoomValue;
       
   539             break;
       
   540         case EZoomModeOptical:
       
   541             // Leave if zoom factor is out of range.
       
   542             if ( ( aZoomValue < iInfo->iMinZoom ) || 
       
   543                  ( aZoomValue > iInfo->iMaxZoom ) )
       
   544                 {
       
   545                 LOGTEXT2( _L( "Cae: CCaeEngineImp::SetZoomValueL leaving KErrArgument, aZoomValue=%d" ), aZoomValue );
       
   546                 User::Leave( KErrArgument );
       
   547                 }
       
   548             // Set OPTICAL zoom value.
       
   549             iCamera->SetZoomFactorL( aZoomValue );
       
   550             iZoomValue = aZoomValue;
       
   551             break;
       
   552         default:
       
   553             // EZoomModeOpticalDigital not supported
       
   554             LOGTEXT2( _L( "Cae: CCaeEngineImp::SetZoomValueL leaving KErrNotSupported, iZoomMode=%d" ), iZoomMode );
       
   555             User::Leave( KErrNotSupported );
       
   556             break;
       
   557         }
       
   558 
       
   559     LOGTEXT( _L( "Cae: CCaeEngineImp::SetZoomValueL() returning" ) );
       
   560     }
       
   561 
       
   562 
       
   563 // -----------------------------------------------------------------------------
       
   564 // CCaeEngineImp::ZoomValue
       
   565 // Calls Camera API DigitalZoomFactor() or ZoomFactor().
       
   566 // -----------------------------------------------------------------------------
       
   567 //
       
   568 TInt CCaeEngineImp::ZoomValue() const
       
   569     {
       
   570     LOGTEXT( _L( "Cae: CCaeEngineImp::ZoomValue()" ) );
       
   571 
       
   572     TInt zoomValue( 0 );
       
   573     if ( iPowerOn )
       
   574         {
       
   575         switch ( iZoomMode )
       
   576             {
       
   577             case EZoomModeDigital:
       
   578                 zoomValue = iCamera->DigitalZoomFactor();
       
   579                 break;
       
   580             case EZoomModeOptical:
       
   581                 zoomValue = iCamera->ZoomFactor();
       
   582                 break;
       
   583             default:
       
   584                 // EZoomModeOpticalDigital not supported
       
   585                 break;
       
   586             }
       
   587         }
       
   588     return zoomValue;
       
   589     }
       
   590 
       
   591 
       
   592 // -----------------------------------------------------------------------------
       
   593 // CCaeEngineImp::SetBrightnessL
       
   594 // Calls Camera API SetBrightnessL().
       
   595 // -----------------------------------------------------------------------------
       
   596 //
       
   597 void CCaeEngineImp::SetBrightnessL( 
       
   598     TInt aBrightness )
       
   599     {
       
   600     LOGTEXT( _L( "Cae: CCaeEngineImp::SetBrightnessL() entering" ) );
       
   601 
       
   602     // Leave if not supported.
       
   603     if ( !( iInfo->iOptionsSupported & TCameraInfo::EBrightnessSupported ) )
       
   604         {
       
   605         LOGTEXT2( _L( "Cae: CCaeEngineImp::SetBrightnessL leaving KErrNotSupported, aBrightness=%d" ), aBrightness );
       
   606         User::Leave( KErrNotSupported );
       
   607         }
       
   608 
       
   609     CheckPowerL();
       
   610 
       
   611     iCamera->SetBrightnessL( aBrightness );
       
   612     iBrightness = aBrightness;
       
   613 
       
   614     LOGTEXT( _L( "Cae: CCaeEngineImp::SetBrightnessL() returning" ) );
       
   615     }
       
   616 
       
   617 
       
   618 // -----------------------------------------------------------------------------
       
   619 // CCaeEngineImp::Brightness
       
   620 // Calls Camera API Brightness().
       
   621 // -----------------------------------------------------------------------------
       
   622 //
       
   623 TInt CCaeEngineImp::Brightness() const
       
   624     {
       
   625     LOGTEXT( _L( "Cae: CCaeEngineImp::Brightness()" ) );
       
   626 
       
   627     TInt brightness( 0 );
       
   628     if ( iPowerOn && ( iInfo->iOptionsSupported & TCameraInfo::EBrightnessSupported ) )
       
   629         {
       
   630         brightness = iCamera->Brightness();
       
   631         }
       
   632     return brightness;
       
   633     }
       
   634 
       
   635 
       
   636 // -----------------------------------------------------------------------------
       
   637 // CCaeEngineImp::SetContrastL
       
   638 // Calls Camera API SetContrastL().
       
   639 // -----------------------------------------------------------------------------
       
   640 //
       
   641 void CCaeEngineImp::SetContrastL( 
       
   642     TInt aContrast )
       
   643     {
       
   644     LOGTEXT( _L( "Cae: CCaeEngineImp::SetContrastL() entering" ) );
       
   645 
       
   646     // Leave if not supported.
       
   647     if ( !( iInfo->iOptionsSupported & TCameraInfo::EContrastSupported ) )
       
   648         {
       
   649         LOGTEXT2( _L( "Cae: CCaeEngineImp::SetContrastL leaving KErrNotSupported, aContrast=%d" ), aContrast );
       
   650         User::Leave( KErrNotSupported );
       
   651         }
       
   652 
       
   653     CheckPowerL();
       
   654 
       
   655     iCamera->SetContrastL( aContrast );
       
   656     iContrast = aContrast;
       
   657 
       
   658     LOGTEXT( _L( "Cae: CCaeEngineImp::SetContrastL() returning" ) );
       
   659     }
       
   660 
       
   661 
       
   662 // -----------------------------------------------------------------------------
       
   663 // CCaeEngineImp::Contrast
       
   664 // Calls Camera API Contrast().
       
   665 // -----------------------------------------------------------------------------
       
   666 //
       
   667 TInt CCaeEngineImp::Contrast() const
       
   668     {
       
   669     LOGTEXT( _L( "Cae: CCaeEngineImp::Contrast()" ) );
       
   670 
       
   671     TInt contrast( 0 );
       
   672     if ( iPowerOn && ( iInfo->iOptionsSupported & TCameraInfo::EContrastSupported ) )
       
   673         {
       
   674         contrast = iCamera->Contrast();
       
   675         }
       
   676     return contrast;
       
   677     }
       
   678 
       
   679 
       
   680 // -----------------------------------------------------------------------------
       
   681 // CCaeEngineImp::SetExposureModeL
       
   682 // Calls Camera API SetExposureModeL().
       
   683 // -----------------------------------------------------------------------------
       
   684 //
       
   685 void CCaeEngineImp::SetExposureModeL( 
       
   686     CCamera::TExposure aExposureMode )
       
   687     {
       
   688     LOGTEXT( _L( "Cae: CCaeEngineImp::SetExposureModeL() entering" ) );
       
   689 
       
   690     // Leave is requested exposure mode is not supported, 
       
   691     // EExposureAuto should be always supported.
       
   692     if ( ( ( aExposureMode != CCamera::EExposureAuto ) && 
       
   693           !( aExposureMode & iInfo->iExposureModesSupported ) ) ||
       
   694            ( aExposureMode < 0 ) )
       
   695         {
       
   696         LOGTEXT2( _L( "Cae: CCaeEngineImp::SetExposureModeL leaving KErrNotSupported, aExposureMode=%d" ), aExposureMode );
       
   697         User::Leave( KErrNotSupported );
       
   698         }
       
   699 
       
   700     CheckPowerL();
       
   701 
       
   702     iCamera->SetExposureL( aExposureMode );
       
   703     iExposureMode = aExposureMode;
       
   704 
       
   705     LOGTEXT( _L( "Cae: CCaeEngineImp::SetExposureModeL() returning" ) );
       
   706     }
       
   707 
       
   708 
       
   709 // -----------------------------------------------------------------------------
       
   710 // CCaeEngineImp::ExposureMode
       
   711 // Calls Camera API Exposure().
       
   712 // -----------------------------------------------------------------------------
       
   713 //
       
   714 CCamera::TExposure CCaeEngineImp::ExposureMode() const
       
   715     {
       
   716     LOGTEXT( _L( "Cae: CCaeEngineImp::ExposureMode()" ) );
       
   717 
       
   718     CCamera::TExposure exposureMode( CCamera::EExposureAuto );
       
   719     if ( iPowerOn )
       
   720         {
       
   721         exposureMode = iCamera->Exposure();
       
   722         }
       
   723     return exposureMode;
       
   724     }
       
   725 
       
   726 // -----------------------------------------------------------------------------
       
   727 // CCaeEngineImp::SetEvCompensationL
       
   728 // If the interface exists, calls Camera API SetEvCompensationL().
       
   729 // -----------------------------------------------------------------------------
       
   730 //
       
   731 void CCaeEngineImp::SetEvCompensationL( 
       
   732     TInt /*aEvIndex*/ )
       
   733     {
       
   734     LOGTEXT( _L( "Cae: CCaeEngineImp::SetEvCompensationL() (not supported) leaving" ) );
       
   735 
       
   736     User::Leave( KErrNotSupported );
       
   737     }
       
   738 
       
   739 // -----------------------------------------------------------------------------
       
   740 // CCaeEngineImp::EvCompensation
       
   741 // If the interface exists, calls Camera API EvCompensation().
       
   742 // -----------------------------------------------------------------------------
       
   743 //
       
   744 TInt CCaeEngineImp::EvCompensation() const
       
   745     {
       
   746     LOGTEXT( _L( "Cae: CCaeEngineImp::EvCompensation() (not supported!)" ) );
       
   747 
       
   748     return( 0 );
       
   749     }
       
   750 
       
   751 // -----------------------------------------------------------------------------
       
   752 // CCaeEngineImp::SetWhiteBalanceModeL
       
   753 // Calls Camera API SetWhiteBalanceL().
       
   754 // -----------------------------------------------------------------------------
       
   755 //
       
   756 void CCaeEngineImp::SetWhiteBalanceModeL( 
       
   757     CCamera::TWhiteBalance aWhiteBalanceMode )
       
   758     {
       
   759     LOGTEXT( _L( "Cae: CCaeEngineImp::SetWhiteBalanceModeL() entering" ) );
       
   760 
       
   761     // Leave is requested WB mode is not supported. 
       
   762     // EWBAuto is always supported.
       
   763     if ( ( ( aWhiteBalanceMode != CCamera::EWBAuto ) && 
       
   764           !( aWhiteBalanceMode & iInfo->iWhiteBalanceModesSupported ) ) ||
       
   765            ( aWhiteBalanceMode < 0 ) )
       
   766         {
       
   767         LOGTEXT2( _L( "Cae: CCaeEngineImp::SetWhiteBalanceModeL leaving KErrNotSupported, aWhiteBalanceMode=%d" ), aWhiteBalanceMode );
       
   768         User::Leave( KErrNotSupported );
       
   769         }
       
   770     
       
   771     CheckPowerL();
       
   772 
       
   773     iCamera->SetWhiteBalanceL( aWhiteBalanceMode );
       
   774     iWhiteBalanceMode = aWhiteBalanceMode;
       
   775 
       
   776     LOGTEXT( _L( "Cae: CCaeEngineImp::SetWhiteBalanceModeL() returning" ) );
       
   777     }
       
   778 
       
   779 
       
   780 // -----------------------------------------------------------------------------
       
   781 // CCaeEngineImp::WhiteBalanceMode
       
   782 // Calls Camera API WhiteBalance().
       
   783 // -----------------------------------------------------------------------------
       
   784 //
       
   785 CCamera::TWhiteBalance CCaeEngineImp::WhiteBalanceMode() const
       
   786     {
       
   787     LOGTEXT( _L( "Cae: CCaeEngineImp::WhiteBalanceMode()" ) );
       
   788 
       
   789     CCamera::TWhiteBalance whiteBalanceMode( CCamera::EWBAuto );
       
   790     if ( iPowerOn )
       
   791         {
       
   792         whiteBalanceMode = iCamera->WhiteBalance();
       
   793         }
       
   794     return whiteBalanceMode;
       
   795     }
       
   796 
       
   797 
       
   798 // -----------------------------------------------------------------------------
       
   799 // CCaeEngineImp::SetFlashModeL
       
   800 // Calls Camera API SetFlashL().
       
   801 // -----------------------------------------------------------------------------
       
   802 //
       
   803 void CCaeEngineImp::SetFlashModeL( 
       
   804     CCamera::TFlash aFlashMode )
       
   805     {
       
   806     LOGTEXT2( _L( "Cae: CCaeEngineImp::SetFlashModeL() entering, mode=%d" ), aFlashMode );
       
   807 
       
   808     // Leave is requested flash mode is not supported. 
       
   809     // EFlashNone is always supported.
       
   810     if ( ( ( aFlashMode != CCamera::EFlashNone ) && 
       
   811           !( aFlashMode & iInfo->iFlashModesSupported ) ) || 
       
   812            ( aFlashMode < 0 ) )
       
   813         {
       
   814         LOGTEXT2( _L( "Cae: CCaeEngineImp::SetFlashModeL leaving KErrNotSupported, aFlashMode=%d" ), aFlashMode );
       
   815         User::Leave( KErrNotSupported );
       
   816         }
       
   817 
       
   818     CheckPowerL();
       
   819 
       
   820     iCamera->SetFlashL( aFlashMode );
       
   821     iFlashMode = aFlashMode;
       
   822 
       
   823     LOGTEXT( _L( "Cae: CCaeEngineImp::SetFlashModeL() returning" ) );
       
   824     }
       
   825 
       
   826 
       
   827 // -----------------------------------------------------------------------------
       
   828 // CCaeEngineImp::FlashMode
       
   829 // Calls Camera API Flash().
       
   830 // -----------------------------------------------------------------------------
       
   831 //
       
   832 CCamera::TFlash CCaeEngineImp::FlashMode() const
       
   833     {
       
   834     LOGTEXT( _L( "Cae: CCaeEngineImp::FlashMode()" ) );
       
   835 
       
   836     CCamera::TFlash flashMode( CCamera::EFlashNone );
       
   837     if ( iPowerOn )
       
   838         {
       
   839         flashMode = iCamera->Flash();
       
   840         }
       
   841     return flashMode;
       
   842     }
       
   843 
       
   844 
       
   845 // -----------------------------------------------------------------------------
       
   846 // CCaeEngineImp::ResetToDefaultsL
       
   847 // Resets the following settings: exposure mode, white balance mode, 
       
   848 // zoom mode, zoom value, flash mode, brightness, and contrast.
       
   849 // -----------------------------------------------------------------------------
       
   850 //
       
   851 void CCaeEngineImp::ResetToDefaultsL()
       
   852     {
       
   853     LOGTEXT( _L( "Cae: CCaeEngineImp::ResetToDefaultsL() entering" ) );
       
   854 
       
   855     SetExposureModeL();
       
   856     SetWhiteBalanceModeL();
       
   857     SetZoomModeL();
       
   858     SetZoomValueL();
       
   859     SetFlashModeL();
       
   860 
       
   861     // Reset this setting only if it is supported by Camera API.
       
   862     if ( iInfo->iOptionsSupported & TCameraInfo::EBrightnessSupported )
       
   863         {
       
   864         SetBrightnessL();
       
   865         }
       
   866 
       
   867     // Reset this setting only if it is supported by Camera API.
       
   868     if ( iInfo->iOptionsSupported & TCameraInfo::EContrastSupported )
       
   869         {
       
   870         SetContrastL();
       
   871         }
       
   872 
       
   873  	// Process extensions
       
   874 	RArray<TCaeExtensionInterfaceImplItem>* settingsImplementationList = 
       
   875 		iExtInterfaceImplementationLists[KCaeExtSettingsInterfaceIndex].iImplementations;
       
   876 
       
   877 	for ( TInt i = 0; i < settingsImplementationList->Count(); i++ )
       
   878 		{
       
   879 		TRAPD(err, STATIC_CAST( MCaeExtSettingsInterface*, 
       
   880 		(*settingsImplementationList)[i].iImplPtr )->ResetToDefaultsL() );
       
   881 
       
   882 	    #ifdef _DEBUG
       
   883 		if ( err )
       
   884 		    {
       
   885 			LOGTEXT3(_L("Cae: CCaeEngineImp::ResetToDefaultsL(). Error %d in ResetToDefaultsL() for Extension %x"),
       
   886 			    err, (*settingsImplementationList)[i].iImplUid.iUid );
       
   887 			}
       
   888 		#endif
       
   889 		
       
   890 		User::LeaveIfError( err ); 
       
   891 		}
       
   892 
       
   893    LOGTEXT( _L( "Cae: CCaeEngineImp::ResetToDefaultsL() returning" ) );
       
   894     }
       
   895 
       
   896 
       
   897 // -----------------------------------------------------------------------------
       
   898 // CCaeEngineImp::SetViewFinderMirrorL
       
   899 // Calls Camera API SetViewFinderMirrorL().
       
   900 // -----------------------------------------------------------------------------
       
   901 //
       
   902 void CCaeEngineImp::SetViewFinderMirrorL( 
       
   903     TBool aMirror )
       
   904     {
       
   905     LOGTEXT( _L( "Cae: CCaeEngineImp::SetViewFinderMirrorL() entering" ) );
       
   906 
       
   907     // Leave if not supported.
       
   908     if ( !( iInfo->iOptionsSupported & TCameraInfo::EViewFinderMirrorSupported ) )
       
   909         {
       
   910         LOGTEXT2( _L( "Cae: CCaeEngineImp::SetViewFinderMirrorL leaving KErrNotSupported, aMirror=%d" ), aMirror );
       
   911         User::Leave( KErrNotSupported );
       
   912         }
       
   913         
       
   914     CheckPowerL();
       
   915 
       
   916     iCamera->SetViewFinderMirrorL( aMirror );    
       
   917 
       
   918     LOGTEXT( _L( "Cae: CCaeEngineImp::SetViewFinderMirrorL() returning" ) );
       
   919     }
       
   920 
       
   921 
       
   922 // -----------------------------------------------------------------------------
       
   923 // CCaeEngineImp::ViewFinderMirror
       
   924 // Calls Camera API ViewFinderMirror().
       
   925 // -----------------------------------------------------------------------------
       
   926 //
       
   927 TBool CCaeEngineImp::ViewFinderMirror() const
       
   928     {
       
   929     LOGTEXT( _L( "Cae: CCaeEngineImp::ViewFinderMirror()" ) );
       
   930 
       
   931     // If supported, query the setting from Camera API.
       
   932     TBool viewFinderMirror( EFalse );
       
   933     if ( iPowerOn && ( iInfo->iOptionsSupported & TCameraInfo::EViewFinderMirrorSupported ) )
       
   934         {
       
   935         viewFinderMirror = iCamera->ViewFinderMirror();
       
   936         }
       
   937     return viewFinderMirror;
       
   938     }
       
   939 
       
   940 
       
   941 // -----------------------------------------------------------------------------
       
   942 // CCaeEngineImp::StartViewFinderBitmapsL
       
   943 // Calls Camera API StartViewFinderBitmapsL().
       
   944 // -----------------------------------------------------------------------------
       
   945 //
       
   946 void CCaeEngineImp::StartViewFinderBitmapsL( 
       
   947     TSize& aVfFrameSize )
       
   948     {
       
   949     LOGTEXT3( _L( "Cae: CCaeEngineImp::StartViewFinderBitmapsL() entering aVfFrameSize wxh=%dx%d" ),
       
   950             aVfFrameSize.iWidth, aVfFrameSize.iHeight );
       
   951 
       
   952     // Leave if not supported.
       
   953     if ( !( iInfo->iOptionsSupported & TCameraInfo::EViewFinderBitmapsSupported ) )
       
   954         {
       
   955         LOGTEXT( _L( "Cae: CCaeEngineImp::StartViewFinderBitmapsL leaving KErrNotSupported" ));
       
   956         User::Leave( KErrNotSupported );
       
   957         }
       
   958 
       
   959     if ( iPowerOn ) 
       
   960         {
       
   961         if ( !iCamera->ViewFinderActive() ) 
       
   962             {
       
   963             iTrueViewFinderSize = aVfFrameSize;
       
   964             iCamera->StartViewFinderBitmapsL( iTrueViewFinderSize );
       
   965             iViewFinderRunning = ETrue;
       
   966             iStillStatesActive->SetViewFinderMode( iViewFinderRunning );
       
   967             }
       
   968         }
       
   969 
       
   970     if ( !iViewFinderRunning )
       
   971         {
       
   972         LOGTEXT( _L( "Cae: CCaeEngineImp::StartViewFinderBitmapsL leaving KErrNotReady (iViewFinderRunning)" ));
       
   973         User::Leave( KErrNotReady );
       
   974         }
       
   975 
       
   976     LOGTEXT( _L( "Cae: CCaeEngineImp::StartViewFinderBitmapsL() returning" ) );
       
   977     }
       
   978 
       
   979 
       
   980 // -----------------------------------------------------------------------------
       
   981 // CCaeEngineImp::StartViewFinderBitmapsL
       
   982 // Cropped version.
       
   983 // Calls Camera API StartViewFinderBitmapsL().
       
   984 // -----------------------------------------------------------------------------
       
   985 //
       
   986 void CCaeEngineImp::StartViewFinderBitmapsL( 
       
   987     TSize& aVfFrameSize, 
       
   988     TRect& aCropRect )
       
   989     {
       
   990     LOGTEXT3( _L( "Cae: CCaeEngineImp::StartViewFinderBitmapsL() entering aVfFrameSize wxh=%dx%d" ),
       
   991             aVfFrameSize.iWidth, aVfFrameSize.iHeight );
       
   992 
       
   993     // Leave if not supported.
       
   994     if ( !( iInfo->iOptionsSupported & TCameraInfo::EViewFinderBitmapsSupported ) || 
       
   995          !( iInfo->iOptionsSupported & TCameraInfo::EViewFinderClippingSupported )  )
       
   996         {
       
   997         LOGTEXT( _L( "Cae: CCaeEngineImp::StartViewFinderBitmapsL (cropped) leaving KErrNotSupported" ));
       
   998         User::Leave( KErrNotSupported );
       
   999         }
       
  1000 
       
  1001     if ( iPowerOn ) 
       
  1002         {
       
  1003         if ( !iCamera->ViewFinderActive() ) 
       
  1004             {
       
  1005             iTrueViewFinderSize = aVfFrameSize;
       
  1006             iCamera->StartViewFinderBitmapsL( iTrueViewFinderSize, aCropRect );
       
  1007             iViewFinderRunning = ETrue;
       
  1008             iStillStatesActive->SetViewFinderMode( iViewFinderRunning );
       
  1009             }
       
  1010         }
       
  1011 
       
  1012     if ( !iViewFinderRunning )
       
  1013         {
       
  1014         LOGTEXT( _L( "Cae: CCaeEngineImp::StartViewFinderBitmapsL (cropped) leaving KErrNotReady" ));
       
  1015         User::Leave( KErrNotReady );
       
  1016         }
       
  1017 
       
  1018     LOGTEXT( _L( "Cae: CCaeEngineImp::StartViewFinderBitmapsL() returning" ) );
       
  1019     }
       
  1020 
       
  1021 
       
  1022 // -----------------------------------------------------------------------------
       
  1023 // CCaeEngineImp::StartViewFinderDirectL
       
  1024 // Calls Camera API StartViewFinderDirectL().
       
  1025 // -----------------------------------------------------------------------------
       
  1026 //
       
  1027 void CCaeEngineImp::StartViewFinderDirectL( 
       
  1028     RWsSession& aWs, 
       
  1029     CWsScreenDevice& aScreenDevice, 
       
  1030     RWindowBase& aWindow, 
       
  1031     TRect& aScreenRect )
       
  1032     {
       
  1033     LOGTEXT( _L( "Cae: CCaeEngineImp::StartViewFinderDirectL() entering" ) );
       
  1034 
       
  1035     // Leave if not supported.
       
  1036     if ( !( iInfo->iOptionsSupported & TCameraInfo::EViewFinderDirectSupported ) )
       
  1037         {
       
  1038         LOGTEXT2( _L( "Cae: CCaeEngineImp::StartViewFinderDirectL leaving KErrNotSupported, iOptionsSupported=0x%x" ), iInfo->iOptionsSupported );
       
  1039         User::Leave( KErrNotSupported );
       
  1040         }
       
  1041 
       
  1042     if ( iPowerOn )
       
  1043         {
       
  1044         if ( !iCamera->ViewFinderActive() )
       
  1045             {
       
  1046             iCamera->StartViewFinderDirectL( aWs, aScreenDevice, aWindow, aScreenRect );
       
  1047             iViewFinderRunning = ETrue;
       
  1048             iStillStatesActive->SetViewFinderMode( iViewFinderRunning );
       
  1049             }
       
  1050         }
       
  1051     
       
  1052     if ( !iViewFinderRunning )
       
  1053         {
       
  1054         LOGTEXT( _L( "Cae: CCaeEngineImp::StartViewFinderDirectL leaving KErrNotReady" ));
       
  1055         User::Leave( KErrNotReady );
       
  1056         }
       
  1057 
       
  1058     LOGTEXT( _L( "Cae: CCaeEngineImp::StartViewFinderDirectL() returning" ) );
       
  1059     }
       
  1060 
       
  1061 
       
  1062 // -----------------------------------------------------------------------------
       
  1063 // CCaeEngineImp::StartViewFinderDirectL
       
  1064 // Cropped version.
       
  1065 // Calls Camera API StartViewFinderDirectL().
       
  1066 // -----------------------------------------------------------------------------
       
  1067 //
       
  1068 void CCaeEngineImp::StartViewFinderDirectL( 
       
  1069     RWsSession& aWs,
       
  1070     CWsScreenDevice& aScreenDevice,
       
  1071     RWindowBase& aWindow,
       
  1072     TRect& aScreenRect,
       
  1073     TRect& aCropRect )
       
  1074     {
       
  1075     LOGTEXT( _L( "Cae: CCaeEngineImp::StartViewFinderDirectL() entering" ) );
       
  1076 
       
  1077     // Leave if not supported.
       
  1078     if ( !( iInfo->iOptionsSupported & TCameraInfo::EViewFinderDirectSupported ) || 
       
  1079          !( iInfo->iOptionsSupported & TCameraInfo::EViewFinderClippingSupported ) )
       
  1080         {
       
  1081         LOGTEXT2( _L( "Cae: CCaeEngineImp::StartViewFinderDirectL (cropped) leaving KErrNotSupported, iOptionsSupported=0x%x" ), iInfo->iOptionsSupported );
       
  1082         User::Leave( KErrNotSupported );
       
  1083         }
       
  1084 
       
  1085     if ( iPowerOn )
       
  1086         {
       
  1087         if ( !iCamera->ViewFinderActive() )
       
  1088             {
       
  1089             iCamera->StartViewFinderDirectL( aWs, aScreenDevice, aWindow, aScreenRect, aCropRect );
       
  1090             iViewFinderRunning = ETrue;
       
  1091             iStillStatesActive->SetViewFinderMode( iViewFinderRunning );
       
  1092            }
       
  1093         }
       
  1094 
       
  1095     if ( !iViewFinderRunning )
       
  1096         {
       
  1097         LOGTEXT( _L( "Cae: CCaeEngineImp::StartViewFinderDirectL (cropped) leaving KErrNotReady" ));
       
  1098         User::Leave( KErrNotReady );
       
  1099         }
       
  1100 
       
  1101     LOGTEXT( _L( "Cae: CCaeEngineImp::StartViewFinderDirectL() returning" ) );
       
  1102     }
       
  1103 
       
  1104 
       
  1105 // -----------------------------------------------------------------------------
       
  1106 // CCaeEngineImp::StopViewFinder
       
  1107 // Calls Camera API ViewFinderActive() and StopViewFinder().
       
  1108 // -----------------------------------------------------------------------------
       
  1109 //
       
  1110 void CCaeEngineImp::StopViewFinder()
       
  1111     {
       
  1112     LOGTEXT( _L( "Cae: CCaeEngineImp::StopViewFinder() entering" ) );
       
  1113 
       
  1114     if ( iPowerOn )
       
  1115         {
       
  1116         if ( iCamera->ViewFinderActive() )
       
  1117             {
       
  1118             iCamera->StopViewFinder();
       
  1119             iViewFinderRunning = EFalse;
       
  1120             iStillStatesActive->SetViewFinderMode( iViewFinderRunning );
       
  1121             }
       
  1122         }
       
  1123 
       
  1124     LOGTEXT( _L( "Cae: CCaeEngineImp::StopViewFinder() returning" ) );
       
  1125     }
       
  1126 
       
  1127 
       
  1128 // -----------------------------------------------------------------------------
       
  1129 // CCaeEngineImp::IsViewFinding
       
  1130 // Calls Camera API ViewFinderActive().
       
  1131 // -----------------------------------------------------------------------------
       
  1132 //
       
  1133 TBool CCaeEngineImp::IsViewFinding() const
       
  1134     {
       
  1135     LOGTEXT( _L( "Cae: CCaeEngineImp::IsViewFinding()" ) );
       
  1136 
       
  1137     TBool isViewFinding( EFalse );
       
  1138     if ( iPowerOn ) 
       
  1139         {
       
  1140         isViewFinding = iCamera->ViewFinderActive();
       
  1141         }
       
  1142     return isViewFinding;
       
  1143     }
       
  1144 
       
  1145 
       
  1146 // -----------------------------------------------------------------------------
       
  1147 // CCaeEngineImp::GetViewFinderSize
       
  1148 // -----------------------------------------------------------------------------
       
  1149 //
       
  1150 void CCaeEngineImp::GetViewFinderSize( 
       
  1151     TSize& aVfFrameSize )
       
  1152     {
       
  1153     LOGTEXT( _L( "Cae: CCaeEngineImp::GetViewFinderSize()" ) );
       
  1154 
       
  1155     aVfFrameSize = iTrueViewFinderSize;
       
  1156     }
       
  1157 
       
  1158 // -----------------------------------------------------------------------------
       
  1159 // CCaeEngineImp::SetCaeStillBurstObserver
       
  1160 // -----------------------------------------------------------------------------
       
  1161 //
       
  1162 void CCaeEngineImp::SetCaeStillBurstObserver( 
       
  1163     MCaeStillBurstObserver& aObserver )
       
  1164     {
       
  1165     iStillStatesActive->SetCaeStillBurstObserver( aObserver );
       
  1166     }
       
  1167 
       
  1168 
       
  1169 // -----------------------------------------------------------------------------
       
  1170 // CCaeEngineImp::SetStillCaptureImageCountL
       
  1171 // -----------------------------------------------------------------------------
       
  1172 //
       
  1173 TInt CCaeEngineImp::SetStillCaptureImageCountL( 
       
  1174     TInt aImageCount )
       
  1175     {
       
  1176     return ( iStillStatesActive->SetStillCaptureImageCountL( aImageCount ) );
       
  1177     }
       
  1178 
       
  1179 // -----------------------------------------------------------------------------
       
  1180 // CCaeEngineImp::StillCaptureImageCount
       
  1181 // -----------------------------------------------------------------------------
       
  1182 //
       
  1183 TInt CCaeEngineImp::StillCaptureImageCount() const
       
  1184     {
       
  1185     return ( iStillStatesActive->StillCaptureImageCount() );
       
  1186     }
       
  1187 
       
  1188 // -----------------------------------------------------------------------------
       
  1189 // CCaeEngineImp::SetStillBurstCaptureIntervalL
       
  1190 // -----------------------------------------------------------------------------
       
  1191 //
       
  1192 void CCaeEngineImp::SetStillBurstCaptureIntervalL( 
       
  1193     TTimeIntervalMicroSeconds aInterval )
       
  1194     {
       
  1195     iStillStatesActive->SetStillBurstCaptureIntervalL( aInterval );
       
  1196     }
       
  1197 
       
  1198 // -----------------------------------------------------------------------------
       
  1199 // CCaeEngineImp::StillBurstCaptureInterval
       
  1200 // -----------------------------------------------------------------------------
       
  1201 //
       
  1202 TTimeIntervalMicroSeconds CCaeEngineImp::StillBurstCaptureInterval() const 
       
  1203     {
       
  1204     return ( iStillStatesActive->StillBurstCaptureInterval() );
       
  1205     }
       
  1206 
       
  1207 
       
  1208 // -----------------------------------------------------------------------------
       
  1209 // CCaeEngineImp::StopStillBurstCapture
       
  1210 // -----------------------------------------------------------------------------
       
  1211 //
       
  1212 void CCaeEngineImp::StopStillBurstCapture()
       
  1213     {
       
  1214     iStillStatesActive->StopStillBurstCapture();
       
  1215     }
       
  1216 
       
  1217 
       
  1218 // -----------------------------------------------------------------------------
       
  1219 // CCaeEngineImp::StillBurstSupport()
       
  1220 // Return option flag for still burst support.
       
  1221 // -----------------------------------------------------------------------------
       
  1222 //
       
  1223 TCamAppEngineInfo::TOptions CCaeEngineImp::StillBurstSupport()
       
  1224     {
       
  1225     return TCamAppEngineInfo::EStillBurstSupported;
       
  1226     }
       
  1227 
       
  1228 
       
  1229 // -----------------------------------------------------------------------------
       
  1230 // CCaeEngineImp::PrepareStillCaptureL
       
  1231 // Retrieves parameters for the specified quality level and calls 
       
  1232 // overloading PrepareStillCaptureL().
       
  1233 // -----------------------------------------------------------------------------
       
  1234 //
       
  1235 void CCaeEngineImp::PrepareStillCaptureL( 
       
  1236     TInt aStillQualityIndex )
       
  1237     {
       
  1238     TSize size = iStillStatesActive->SnapImageSize();
       
  1239     PrepareStillCaptureL( aStillQualityIndex, size);
       
  1240     }
       
  1241 
       
  1242 // -----------------------------------------------------------------------------
       
  1243 // CCaeEngineImp::PrepareStillCaptureL
       
  1244 // Retrieves parameters for the specified quality level and calls 
       
  1245 // overloading PrepareStillCaptureL().
       
  1246 // -----------------------------------------------------------------------------
       
  1247 //
       
  1248 void CCaeEngineImp::PrepareStillCaptureL( 
       
  1249     TInt         aStillQualityIndex, 
       
  1250     TSize&       aSnapSize )
       
  1251     {
       
  1252     LOGTEXT3( _L( "Cae: CCaeEngineImp::PrepareStillCaptureL() entering aSnapSize wxh=%dx%d" ),
       
  1253             aSnapSize.iWidth, aSnapSize.iHeight );
       
  1254 
       
  1255     if ( aStillQualityIndex < 0 || 
       
  1256          aStillQualityIndex >= iStillQualityLevelsCont->Count() ) 
       
  1257         {
       
  1258         LOGTEXT2( _L( "Cae: CCaeEngineImp::PrepareStillCaptureL leaving KErrArgument, aStillQualityIndex=%d" ), aStillQualityIndex );
       
  1259         User::Leave( KErrArgument );
       
  1260         }
       
  1261 
       
  1262     TSize frameSize         = iStillQualityLevelsCont->At( aStillQualityIndex ).iFrameSize;
       
  1263     CCamera::TFormat format = iStillQualityLevelsCont->At( aStillQualityIndex ).iOutputFormat;
       
  1264     TInt compressionQuality = iStillQualityLevelsCont->At( aStillQualityIndex ).iCompressionQuality;
       
  1265     TRect fullRect( frameSize );
       
  1266     
       
  1267     PrepareStillCaptureL( frameSize, format, compressionQuality, fullRect, aSnapSize );
       
  1268     
       
  1269     iStillQualityIndex = aStillQualityIndex;
       
  1270 
       
  1271     LOGTEXT( _L( "Cae: CCaeEngineImp::PrepareStillCaptureL() returning" ) );
       
  1272     }
       
  1273 
       
  1274 
       
  1275 // -----------------------------------------------------------------------------
       
  1276 // CCaeEngineImp::PrepareStillCaptureL
       
  1277 // Cropped version.
       
  1278 // Not supported.
       
  1279 // -----------------------------------------------------------------------------
       
  1280 //
       
  1281 void CCaeEngineImp::PrepareStillCaptureL( 
       
  1282     TInt /*aStillQualityIndex*/, 
       
  1283     const TRect& /*aCropRect*/ )
       
  1284     {
       
  1285     LOGTEXT( _L( "Cae: CCaeEngineImp::PrepareStillCaptureL() cropped leaving KErrNotSupported" ) );
       
  1286 
       
  1287     User::Leave( KErrNotSupported );
       
  1288     }
       
  1289 
       
  1290 
       
  1291 
       
  1292 // -----------------------------------------------------------------------------
       
  1293 // CCaeEngineImp::PrepareStillCaptureL
       
  1294 // -----------------------------------------------------------------------------
       
  1295 //
       
  1296 void CCaeEngineImp::PrepareStillCaptureL( 
       
  1297     const TSize&      aFrameSize,
       
  1298     CCamera::TFormat  aFormat,  
       
  1299     TInt              aCompressionQuality )
       
  1300     {    
       
  1301     TRect fullRect( aFrameSize );
       
  1302     PrepareStillCaptureL( aFrameSize, aFormat, aCompressionQuality, fullRect );
       
  1303     }
       
  1304 
       
  1305 
       
  1306 // -----------------------------------------------------------------------------
       
  1307 // CCaeEngineImp::PrepareStillCaptureL
       
  1308 // Cropped version. Using cropping only if supported by Camera API impl.
       
  1309 // Calls RetrieveStillSizeIndex() that calls Camera API EnumerateCaptureSizes().
       
  1310 // Calls Camera API PrepareImageCaptureL().
       
  1311 // Optionally calls Camera API SetJpegQuality().
       
  1312 // Finally calls McaeoStillPrepareComplete call-back.
       
  1313 // -----------------------------------------------------------------------------
       
  1314 //
       
  1315 void CCaeEngineImp::PrepareStillCaptureL( 
       
  1316     const TSize&      aFrameSize, 
       
  1317     CCamera::TFormat  aFormat, 
       
  1318     TInt              aCompressionQuality, 
       
  1319     const TRect&      aCropRect )
       
  1320     {
       
  1321     TSize snapSize = iStillStatesActive->SnapImageSize();
       
  1322     PrepareStillCaptureL(aFrameSize, aFormat, aCompressionQuality, aCropRect, snapSize );
       
  1323     }
       
  1324 
       
  1325 
       
  1326 // -----------------------------------------------------------------------------
       
  1327 // CCaeEngineImp::PrepareStillCaptureL
       
  1328 // Cropped version. Using cropping only if supported by Camera API impl.
       
  1329 // Calls RetrieveStillSizeIndex() that calls Camera API EnumerateCaptureSizes().
       
  1330 // Calls Camera API PrepareImageCaptureL().
       
  1331 // Optionally calls Camera API SetJpegQuality().
       
  1332 // Finally calls McaeoStillPrepareComplete call-back.
       
  1333 // -----------------------------------------------------------------------------
       
  1334 //
       
  1335 void CCaeEngineImp::PrepareStillCaptureL( 
       
  1336     const TSize&      aFrameSize, 
       
  1337     CCamera::TFormat  aFormat, 
       
  1338     TInt              aCompressionQuality, 
       
  1339     const TRect&      aCropRect,
       
  1340     TSize&            aSnapSize )
       
  1341     {
       
  1342     LOGTEXT3( _L( "Cae: CCaeEngineImp::PrepareStillCaptureL() entering aFrameSize wxh=%dx%d" ),
       
  1343             aFrameSize.iWidth, aFrameSize.iHeight );
       
  1344 
       
  1345     OstTrace0( CAMERASRV_PERFORMANCE, CCAEENGINEIMP_PREPARESTILLCAPTUREL, "e_CAM_ENG_STILL_INIT 1" );   //CAE_ENGINE_STILL_INIT_START
       
  1346 
       
  1347     // Leave if not supported.
       
  1348     if ( !( iInfo->iOptionsSupported & TCameraInfo::EImageCaptureSupported ) )
       
  1349         {
       
  1350         LOGTEXT( _L( "Cae: CCaeEngineImp::PrepareStillCaptureL() leaving KErrNotSupported (EImageCaptureSupported)" ) );
       
  1351         User::Leave( KErrNotSupported );
       
  1352         }
       
  1353 
       
  1354     CheckPowerL();
       
  1355 
       
  1356     // Leave if still capturing or video recording is running.
       
  1357     if ( iStillStatesActive->IsRunning() || iVideoRecordingRunning ) 
       
  1358         {
       
  1359         LOGTEXT( _L( "Cae: CCaeEngineImp::PrepareStillCaptureL() leaving KErrNotReady (IsRunning)" ) );
       
  1360         User::Leave( KErrNotReady );
       
  1361         }
       
  1362 
       
  1363     if ( ( aFormat == CCamera::EFormatJpeg ) || ( aFormat == CCamera::EFormatExif ) ) 
       
  1364         {
       
  1365     	SetJpegQuality( aCompressionQuality ); 
       
  1366         }
       
  1367     
       
  1368     iStillStatesActive->PrepareStillCaptureL( aFrameSize, aFormat, aCropRect, aSnapSize );
       
  1369 
       
  1370     // Prepare ready now.
       
  1371     iStillPrepared = ETrue;
       
  1372 
       
  1373     OstTrace0( CAMERASRV_PERFORMANCE, DUP1_CCAEENGINEIMP_PREPARESTILLCAPTUREL, "e_CAM_ENG_STILL_INIT 0" );  //CAE_ENGINE_STILL_INIT_END
       
  1374 
       
  1375     // Inform client about the success.
       
  1376     iCaeObserver->McaeoStillPrepareComplete( KErrNone );
       
  1377     }
       
  1378 
       
  1379 
       
  1380 // -----------------------------------------------------------------------------
       
  1381 // CCaeEngineImp::StillQualityIndex
       
  1382 // -----------------------------------------------------------------------------
       
  1383 //
       
  1384 TInt CCaeEngineImp::StillQualityIndex() const
       
  1385     {
       
  1386     LOGTEXT( _L( "Cae: CCaeEngineImp::StillQualityIndex()" ) );    
       
  1387 
       
  1388     TInt qualityIndex( -1 );
       
  1389     if ( iStillPrepared )
       
  1390         {
       
  1391         qualityIndex = iStillQualityIndex;
       
  1392         }
       
  1393     return qualityIndex;
       
  1394     }
       
  1395 
       
  1396 
       
  1397 // -----------------------------------------------------------------------------
       
  1398 // CCaeEngineImp::GetStillFrameSize
       
  1399 // -----------------------------------------------------------------------------
       
  1400 //
       
  1401 void CCaeEngineImp::GetStillFrameSize( 
       
  1402     TInt aStillQualityIndex, 
       
  1403     TSize& aFrameSize ) const
       
  1404     {
       
  1405     LOGTEXT( _L( "Cae: CCaeEngineImp::GetStillFrameSize()" ) );
       
  1406     
       
  1407     if ( aStillQualityIndex >= 0 &&  
       
  1408          aStillQualityIndex < iStillQualityLevelsCont->Count() )
       
  1409         {
       
  1410         aFrameSize = iStillQualityLevelsCont->At( aStillQualityIndex ).iFrameSize;
       
  1411         }
       
  1412     }
       
  1413 
       
  1414 
       
  1415 // -----------------------------------------------------------------------------
       
  1416 // CCaeEngineImp::EstimatedStillSizeInBytes
       
  1417 // -----------------------------------------------------------------------------
       
  1418 //
       
  1419 TInt CCaeEngineImp::EstimatedStillSizeInBytes( 
       
  1420     TInt aStillQualityIndex ) const
       
  1421     {
       
  1422     LOGTEXT( _L( "Cae: CCaeEngineImp::EstimatedStillSizeInBytes()" ) );
       
  1423 
       
  1424     TInt byteSize( 0 );
       
  1425     if ( aStillQualityIndex >= 0 &&  
       
  1426          aStillQualityIndex < iStillQualityLevelsCont->Count() )
       
  1427         {
       
  1428         byteSize = iStillQualityLevelsCont->At( aStillQualityIndex ).iByteSize;
       
  1429         }
       
  1430     return byteSize;
       
  1431     }
       
  1432 
       
  1433 
       
  1434 // -----------------------------------------------------------------------------
       
  1435 // CCaeEngineImp::CaptureStill
       
  1436 // Starts still capturing.
       
  1437 // -----------------------------------------------------------------------------
       
  1438 //
       
  1439 void CCaeEngineImp::CaptureStill()
       
  1440     {
       
  1441     LOGTEXT( _L( "Cae: CCaeEngineImp::CaptureStill() entering" ) );
       
  1442 
       
  1443     OstTrace0( CAMERASRV_PERFORMANCE, CCAEENGINEIMP_CAPTURESTILL, "e_CAM_ENG_SHOT_TO_STILL 1" );    //CAE_ENGINE_SHOT_TO_STILL_START
       
  1444 
       
  1445     if ( !iStillStatesActive->IsRunning() ) 
       
  1446         {
       
  1447         if ( iStillPrepared && iPowerOn && !iVideoRecordingRunning ) 
       
  1448             {
       
  1449                 // Call CAPI without active object delay (for perf reasons)
       
  1450                 iStillStatesActive->StartQuickCapture();
       
  1451 
       
  1452             }
       
  1453         else
       
  1454             {
       
  1455             // Handle error
       
  1456             iStillStatesActive->ErrorRecovery( KErrNotReady );
       
  1457             }    
       
  1458         }
       
  1459 
       
  1460     LOGTEXT( _L( "Cae: CCaeEngineImp::CaptureStill() returning" ) );
       
  1461     }
       
  1462 
       
  1463 
       
  1464 // -----------------------------------------------------------------------------
       
  1465 // CCaeEngineImp::CancelCaptureStill
       
  1466 // -----------------------------------------------------------------------------
       
  1467 //
       
  1468 void CCaeEngineImp::CancelCaptureStill()
       
  1469     {
       
  1470     LOGTEXT( _L( "Cae: CCaeEngineImp::CancelCaptureStill() entering" ) );
       
  1471 
       
  1472     if ( iStillStatesActive ) 
       
  1473         {
       
  1474         iStillStatesActive->CancelCaptureStill();
       
  1475         }
       
  1476 
       
  1477     if ( iCallbackActive ) 
       
  1478         {
       
  1479         iCallbackActive->Cancel();
       
  1480         }
       
  1481 
       
  1482     if ( iCamera ) 
       
  1483         {
       
  1484         iCamera->CancelCaptureImage();
       
  1485         }
       
  1486 
       
  1487     LOGTEXT( _L( "Cae: CCaeEngineImp::CancelCaptureStill() returning" ) );
       
  1488     }
       
  1489 
       
  1490 
       
  1491 // -----------------------------------------------------------------------------
       
  1492 // CCaeEngineImp::SetSnapImageCreation
       
  1493 // Sets snap image creation on/off.
       
  1494 // -----------------------------------------------------------------------------
       
  1495 //
       
  1496 void CCaeEngineImp::SetSnapImageCreation( 
       
  1497     TBool aCreateSnapImage )
       
  1498     {
       
  1499     iStillStatesActive->SetSnapImageCreation( aCreateSnapImage );
       
  1500     }
       
  1501 
       
  1502 // -----------------------------------------------------------------------------
       
  1503 // CCaeEngineImp::SetSnapImageSource
       
  1504 // Sets snap image source.
       
  1505 // -----------------------------------------------------------------------------
       
  1506 //
       
  1507 void CCaeEngineImp::SetSnapImageSourceL( 
       
  1508     CCaeEngine::TSnapImageSource aSnapImageSource )
       
  1509     {
       
  1510     iStillStatesActive->SetSnapImageSourceL( aSnapImageSource );
       
  1511     }
       
  1512 
       
  1513 
       
  1514 // -----------------------------------------------------------------------------
       
  1515 
       
  1516 // -----------------------------------------------------------------------------
       
  1517 // CCaeEngineImp::SetSnapImageSizeL
       
  1518 // Sets the size of the snap image.
       
  1519 // -----------------------------------------------------------------------------
       
  1520 //
       
  1521 void CCaeEngineImp::SetSnapImageSizeL( 
       
  1522     TSize& aSize )
       
  1523     {
       
  1524     iStillStatesActive->SetSnapImageSizeL( aSize );
       
  1525     }
       
  1526 
       
  1527 
       
  1528 // -----------------------------------------------------------------------------
       
  1529 // CCaeEngineImp::SetSnapImageColorMode
       
  1530 // Sets the color mode of the snap image.
       
  1531 // -----------------------------------------------------------------------------
       
  1532 //
       
  1533 void CCaeEngineImp::SetSnapImageColorMode( 
       
  1534     TDisplayMode aMode )
       
  1535     {
       
  1536     iStillStatesActive->SetSnapImageColorMode( aMode );
       
  1537     }
       
  1538 
       
  1539 
       
  1540 // -----------------------------------------------------------------------------
       
  1541 // CCaeEngine::NewL
       
  1542 // Two-phased constructor. Calls CCaeEngineImp's NewL() with camera index and
       
  1543 // default display index 0.
       
  1544 // -----------------------------------------------------------------------------
       
  1545 //
       
  1546 EXPORT_C CCaeEngine* CCaeEngine::NewL( 
       
  1547     TInt aCameraIndex )
       
  1548     {
       
  1549     return CCaeEngineImp::NewL( aCameraIndex, 0 );
       
  1550     }
       
  1551 
       
  1552 
       
  1553 // -----------------------------------------------------------------------------
       
  1554 // CCaeEngine::NewL
       
  1555 // Two-phased constructor. Calls CCaeEngineImp's NewL() with camera index.
       
  1556 // -----------------------------------------------------------------------------
       
  1557 //
       
  1558 EXPORT_C CCaeEngine* CCaeEngine::NewL( 
       
  1559     TInt aCameraIndex, TInt aDisplayIndex )
       
  1560     {
       
  1561     return CCaeEngineImp::NewL( aCameraIndex, aDisplayIndex );
       
  1562     }
       
  1563 
       
  1564 
       
  1565 // -----------------------------------------------------------------------------
       
  1566 // CCaeEngine::CamerasAvailable
       
  1567 // Determines the number of cameras on the device.
       
  1568 // -----------------------------------------------------------------------------
       
  1569 //
       
  1570 EXPORT_C TInt CCaeEngine::CamerasAvailable()
       
  1571     {
       
  1572     LOGTEXT2( _L( "Cae: CCaeEngine::CamerasAvailable(): %d" ), CCamera::CamerasAvailable() );
       
  1573     return CCamera::CamerasAvailable();
       
  1574     }
       
  1575 
       
  1576 
       
  1577 // -----------------------------------------------------------------------------
       
  1578 // CCaeEngineImp::NewL
       
  1579 // Two-phased constructor. Inputs camera index.
       
  1580 // -----------------------------------------------------------------------------
       
  1581 //
       
  1582 CCaeEngineImp* CCaeEngineImp::NewL( 
       
  1583     TInt aCameraIndex, TInt aDisplayIndex )
       
  1584     {
       
  1585     LOGTEXT2( _L( "Cae: CCaeEngineImp::NewL() entering with camera index %d" ), aCameraIndex );
       
  1586 
       
  1587     CCaeEngineImp* self = new( ELeave ) CCaeEngineImp();
       
  1588 
       
  1589     CleanupStack::PushL( self );
       
  1590     self->ConstructL( aCameraIndex, aDisplayIndex );
       
  1591     CleanupStack::Pop( self );
       
  1592 
       
  1593     LOGTEXT( _L( "Cae: CCaeEngineImp::NewL() returning" ) );
       
  1594 
       
  1595     return self;
       
  1596     }
       
  1597 
       
  1598 
       
  1599 // -----------------------------------------------------------------------------
       
  1600 // CCaeEngineImp::EnumerateStillCaptureSizes
       
  1601 // Enumerates through the available image capture sizes.
       
  1602 // Calls Camera API EnumerateCaptureSizes().
       
  1603 // -----------------------------------------------------------------------------
       
  1604 //
       
  1605 void CCaeEngineImp::EnumerateStillCaptureSizes( 
       
  1606     TSize& aSize, 
       
  1607     TInt aSizeIndex, 
       
  1608     CCamera::TFormat aFormat ) const
       
  1609     {
       
  1610     LOGTEXT2( _L( "Cae: CCaeEngineImp::EnumerateStillCaptureSizes() entering aSizeIndex=%d" ), aSizeIndex );
       
  1611     iCamera->EnumerateCaptureSizes( aSize, aSizeIndex, aFormat );
       
  1612     LOGTEXT3( _L( "Cae: CCaeEngineImp::EnumerateStillCaptureSizes() returning aSize wxh=%dx%d" ),
       
  1613            aSize.iWidth, aSize.iHeight );
       
  1614    }
       
  1615 
       
  1616 
       
  1617 // -----------------------------------------------------------------------------
       
  1618 // CCaeEngineImp::SetJpegQuality
       
  1619 // Sets the compression quality value to use with JPEG and Exif image formats.
       
  1620 // Calls Camera API SetJpegQuality() and the still state machine SetJpegQuality().
       
  1621 // -----------------------------------------------------------------------------
       
  1622 //
       
  1623 void CCaeEngineImp::SetJpegQuality( 
       
  1624     TInt aCompressionQuality )
       
  1625     {
       
  1626     LOGTEXT2( _L( "Cae: CCaeEngineImp::SetJpegQuality() entering with %d" ), aCompressionQuality );
       
  1627     // Clamp and memorize the image compression quality.
       
  1628     if ( aCompressionQuality < 1 )
       
  1629         {
       
  1630         aCompressionQuality = 1;
       
  1631         }
       
  1632     if ( aCompressionQuality > 100 ) 
       
  1633         {
       
  1634         aCompressionQuality = 100;
       
  1635         }
       
  1636 
       
  1637     // Set JPEG quality on Camera API.
       
  1638     iCamera->SetJpegQuality( aCompressionQuality );
       
  1639 
       
  1640     // Set JPEG quality on the state machine
       
  1641     iStillStatesActive->SetJpegQuality( aCompressionQuality );
       
  1642 
       
  1643     LOGTEXT2( _L( "Cae: CCaeEngineImp::SetJpegQuality() returning, memorized %d" ), aCompressionQuality );
       
  1644     }
       
  1645 
       
  1646 
       
  1647 // -----------------------------------------------------------------------------
       
  1648 // CCaeEngineImp::JpegQuality
       
  1649 // Gets the current compression quality value setting for 
       
  1650 // JPEG and Exif image formats.
       
  1651 // -----------------------------------------------------------------------------
       
  1652 //
       
  1653 TInt CCaeEngineImp::JpegQuality() const
       
  1654     {
       
  1655     LOGTEXT2( _L( "Cae: CCaeEngineImp::JpegQuality(): %d" ), iStillStatesActive->JpegQuality() );
       
  1656     // Memorized image compression quality, set in  
       
  1657     // SetJpegQuality() or PrepareStillCaptureL().
       
  1658     return( iStillStatesActive->JpegQuality() );
       
  1659     }
       
  1660 
       
  1661 
       
  1662 // -----------------------------------------------------------------------------
       
  1663 // CCaeEngineImp::SetImageCodecsL
       
  1664 // Sets the specific image codec implementation to be used in decoding and 
       
  1665 // encoding.
       
  1666 // -----------------------------------------------------------------------------
       
  1667 //
       
  1668 void CCaeEngineImp::SetImageCodecsL( 
       
  1669 	TUid aDecoderUid, TUid aEncoderUid )
       
  1670     {
       
  1671     LOGTEXT3( _L( "Cae: CCaeEngineImp::SetImageCodecsL(): %x, %x" ), aDecoderUid, aEncoderUid );
       
  1672     iStillStatesActive->SetImageCodecsL( aDecoderUid, aEncoderUid );
       
  1673     }
       
  1674 
       
  1675         
       
  1676 // -----------------------------------------------------------------------------
       
  1677 // CCaeEngineImp::ReserveComplete
       
  1678 // Camera reservation is complete. 
       
  1679 // Called asynchronously when CCamera::Reserve() completes.
       
  1680 // -----------------------------------------------------------------------------
       
  1681 //
       
  1682 void CCaeEngineImp::ReserveComplete(                                 
       
  1683     TInt aError )
       
  1684     {
       
  1685     LOGTEXT2( _L( "Cae: CCaeEngineImp::ReserveComplete() entering, aError=%d" ), aError );
       
  1686 
       
  1687     #ifdef CAE_TEST_VERSION
       
  1688     // For simulating errors when compiled as special "test version".
       
  1689     CaeReserveCompleteError( aError );
       
  1690     #endif    
       
  1691 
       
  1692     if ( aError == KErrNone )
       
  1693         {
       
  1694         iReserved = ETrue;
       
  1695         // Call the active object to switch the power on indirectly.
       
  1696         iCallbackActive->PowerOn();
       
  1697         }
       
  1698     else
       
  1699         {
       
  1700         iCaeObserver->McaeoInitComplete( aError );
       
  1701         }
       
  1702 
       
  1703     LOGTEXT( _L( "Cae: CCaeEngineImp::ReserveComplete() returning" ) );
       
  1704     }
       
  1705 
       
  1706 
       
  1707 // -----------------------------------------------------------------------------
       
  1708 // CCaeEngineImp::PowerOnComplete
       
  1709 // Indicates camera power on is complete.
       
  1710 // Called on completion of CCamera:PowerOn().
       
  1711 // -----------------------------------------------------------------------------
       
  1712 //
       
  1713 void CCaeEngineImp::PowerOnComplete( 
       
  1714     TInt aError )
       
  1715     {
       
  1716     LOGTEXT2( _L( "Cae: CCaeEngineImp::PowerOnComplete() entering, aError=%d" ), aError );
       
  1717 
       
  1718     #ifdef CAE_TEST_VERSION
       
  1719     // For simulating errors when compiled as special "test version".
       
  1720     CaePowerOnCompleteError( aError );
       
  1721     #endif    
       
  1722 
       
  1723     if ( aError == KErrNone ) 
       
  1724         {
       
  1725         iPowerOn = ETrue;
       
  1726         if ( iResetToPreviousSettings )
       
  1727             {
       
  1728             iResetToPreviousSettings = EFalse;
       
  1729             TRAP( aError, ResetToPreviousSettingsL() );
       
  1730             }
       
  1731         }
       
  1732     
       
  1733     iCaeObserver->McaeoInitComplete( aError );
       
  1734 
       
  1735     LOGTEXT( _L( "Cae: CCaeEngineImp::PowerOnComplete() returning" ) );
       
  1736     }
       
  1737 
       
  1738 
       
  1739 // -----------------------------------------------------------------------------
       
  1740 // CCaeEngineImp::ViewFinderFrameReady
       
  1741 // Transfers the current view finder image from the camera. The frame is 
       
  1742 // first delivered to the extensions and then to the client.
       
  1743 // Called periodically in response to the use of 
       
  1744 // CCamera::StartViewFinderBitmapsL().
       
  1745 // -----------------------------------------------------------------------------
       
  1746 //
       
  1747 void CCaeEngineImp::ViewFinderFrameReady( 
       
  1748     CFbsBitmap& aFrame )
       
  1749     {
       
  1750     //LOGTEXT( _L( "Cae: CCaeEngineImp::ViewFinderFrameReady() entering" ) );
       
  1751 
       
  1752 	// Process extensions
       
  1753 	RArray<TCaeExtensionInterfaceImplItem>* processImageImplList = 
       
  1754 		iExtInterfaceImplementationLists[KCaeExtProcessImageInterfaceIndex].iImplementations;
       
  1755 
       
  1756 	TInt extError = KErrNone;
       
  1757 	for ( TInt i = 0; i < processImageImplList->Count() && !extError; i++ )
       
  1758 		{
       
  1759 		if ( (*processImageImplList)[i].iIsActive )
       
  1760 		    {
       
  1761     		STATIC_CAST( MCaeExtProcessImageInterface*, 
       
  1762 	    	(*processImageImplList)[i].iImplPtr )->ProcessViewFinderFrame( aFrame, extError );
       
  1763 		    }
       
  1764 		else
       
  1765 		    {
       
  1766 			// LOGTEXT2(_L("Cae: CCaeEngineImp::ViewFinderFrameReady(). Skipped extension %x"), (*processImageImplList)[i].iImplUid.iUid );
       
  1767 		    }
       
  1768 		
       
  1769 	    #ifdef _DEBUG
       
  1770 		if ( extError )
       
  1771 		    {
       
  1772 			LOGTEXT3(_L("Cae: CCaeEngineImp::ViewFinderFrameReady(). Error %d in extension processing for Extension %x"),
       
  1773 			    extError, (*processImageImplList)[i].iImplUid.iUid );
       
  1774 			}
       
  1775 		#endif
       
  1776 		}
       
  1777 
       
  1778     iCaeObserver->McaeoViewFinderFrameReady( aFrame, extError );
       
  1779 
       
  1780     iStillStatesActive->ViewFinderFrameReady();
       
  1781 
       
  1782     //LOGTEXT( _L( "Cae: CCaeEngineImp::ViewFinderFrameReady() returning" ) );
       
  1783     }
       
  1784 
       
  1785 
       
  1786 // -----------------------------------------------------------------------------
       
  1787 // CCaeEngineImp::ImageReady
       
  1788 // Transfers the current image from the camera. 
       
  1789 // Called asynchronously when CCamera::CaptureImage() completes.
       
  1790 // -----------------------------------------------------------------------------
       
  1791 //
       
  1792 void CCaeEngineImp::ImageReady( 
       
  1793     CFbsBitmap* aBitmap, 
       
  1794     HBufC8*     aImageData, 
       
  1795     TInt        aError )
       
  1796     {
       
  1797     iStillStatesActive->ImageReady( aBitmap, aImageData, aError );
       
  1798     }
       
  1799 
       
  1800 
       
  1801 // -----------------------------------------------------------------------------
       
  1802 // CCaeEngineImp::CheckPowerL
       
  1803 // Leaves with KErrNotReady if power is off.
       
  1804 // -----------------------------------------------------------------------------
       
  1805 //
       
  1806 void CCaeEngineImp::CheckPowerL()
       
  1807     {
       
  1808     if ( !iPowerOn ) 
       
  1809         {
       
  1810         LOGTEXT( _L( "Cae: CCaeEngineImp::CheckPowerL() leaving KErrNotReady (iPowerOn)" ) );
       
  1811         User::Leave( KErrNotReady );
       
  1812         }
       
  1813     }
       
  1814 
       
  1815 
       
  1816 // -----------------------------------------------------------------------------
       
  1817 // CCaeEngineImp::CancelAllActivities()
       
  1818 // Cancels/closes/stops still capturing, video recording, and view finding.
       
  1819 // -----------------------------------------------------------------------------
       
  1820 //
       
  1821 void CCaeEngineImp::CancelAllActivities()
       
  1822     {
       
  1823     LOGTEXT( _L( "Cae: CCaeEngineImp::CancelAllActivities() entering" ) );
       
  1824 
       
  1825     CancelCaptureStill();
       
  1826  
       
  1827     CloseVideoRecording();
       
  1828 
       
  1829     StopViewFinder();
       
  1830 
       
  1831     LOGTEXT( _L( "Cae: CCaeEngineImp::CancelAllActivities() returning" ) );
       
  1832     }
       
  1833 
       
  1834 
       
  1835 // -----------------------------------------------------------------------------
       
  1836 // CCaeEngineImp::ResetToPreviousSettingsL
       
  1837 // Resets the following settings to the previous values: 
       
  1838 // exposure mode, white balance mode, 
       
  1839 // zoom mode, zoom value, flash mode, brightness, and contrast.
       
  1840 // -----------------------------------------------------------------------------
       
  1841 //
       
  1842 void CCaeEngineImp::ResetToPreviousSettingsL()
       
  1843     {
       
  1844     LOGTEXT( _L( "Cae: CCaeEngineImp::ResetToPreviousSettingsL() entering" ) );
       
  1845 
       
  1846     SetExposureModeL( iExposureMode );
       
  1847     SetWhiteBalanceModeL( iWhiteBalanceMode );
       
  1848     SetZoomModeL( iZoomMode );
       
  1849     SetZoomValueL( iZoomValue );
       
  1850     SetFlashModeL( iFlashMode );
       
  1851 
       
  1852     // Try to reset this setting only if it is supported by Camera API.
       
  1853     // Otherwise this could cause error when re-reserving camera.
       
  1854     if ( iInfo->iOptionsSupported & TCameraInfo::EBrightnessSupported )
       
  1855         {
       
  1856         SetBrightnessL( iBrightness );
       
  1857         }
       
  1858 
       
  1859     // Try to reset this setting only if it is supported by Camera API.
       
  1860     // Otherwise this could cause error when re-reserving camera.
       
  1861     if ( iInfo->iOptionsSupported & TCameraInfo::EContrastSupported )
       
  1862         {
       
  1863         SetContrastL( iContrast );
       
  1864         }
       
  1865 
       
  1866  	// Process extensions
       
  1867 	RArray<TCaeExtensionInterfaceImplItem>* settingsImplementationList = 
       
  1868 		iExtInterfaceImplementationLists[KCaeExtSettingsInterfaceIndex].iImplementations;
       
  1869 
       
  1870 	for ( TInt i = 0; i < settingsImplementationList->Count(); i++ )
       
  1871 		{
       
  1872 		TRAPD( err,STATIC_CAST( MCaeExtSettingsInterface*, 
       
  1873 		    (*settingsImplementationList)[i].iImplPtr )->ResetToPreviousSettingsL() );
       
  1874 		    
       
  1875 	    #ifdef _DEBUG
       
  1876 		if ( err )
       
  1877 		    {
       
  1878 			LOGTEXT3(_L("Cae: CCaeEngineImp::ResetToDefaultsL(). Error %d in ResetToDefaultsL() for Extension %x"),
       
  1879 			    err, (*settingsImplementationList)[i].iImplUid.iUid );
       
  1880 			}
       
  1881 		#endif
       
  1882 		
       
  1883 		User::LeaveIfError( err );
       
  1884 		}
       
  1885 
       
  1886     LOGTEXT( _L( "Cae: CCaeEngineImp::ResetToPreviousSettingsL() returning" ) );
       
  1887     }
       
  1888 
       
  1889 
       
  1890 // -----------------------------------------------------------------------------
       
  1891 // CCaeEngineImp::CustomInterface
       
  1892 // Returns a custom interface  that matches to the given UID.
       
  1893 // -----------------------------------------------------------------------------
       
  1894 //
       
  1895 TAny* CCaeEngineImp::CustomInterface( TUid aInterface )
       
  1896     {
       
  1897 	LOGTEXT2(_L("Cae: CCaeEngineImp::CustomInterface() entering, aIterface=%x"),aInterface.iUid );
       
  1898 	TAny* interfaceImp = NULL;
       
  1899 
       
  1900 	// At first, try to find the interface in CAE extesions
       
  1901 	TCaeCustomInterfaceImplItem item;
       
  1902 	item.iInterfaceUid = aInterface;
       
  1903 	item.iImplPtr = NULL; // This is not used by FindInUnsignedKeyOrder()
       
  1904 	TInt index = iExtCustomInterfaceImplementations.FindInUnsignedKeyOrder( item ); 
       
  1905 	if ( index >= 0 )
       
  1906 		{
       
  1907 		interfaceImp = iExtCustomInterfaceImplementations[ index ].iImplPtr;
       
  1908 		}
       
  1909 
       
  1910 	if ( !interfaceImp )
       
  1911 		{
       
  1912 		// Then, try to find the interface in Camera API
       
  1913         interfaceImp = iCamera->CustomInterface( aInterface );
       
  1914 		}
       
  1915 
       
  1916     // Check if View Finder is stopped during burst sequency to optimize speed of burst
       
  1917     // Detection of this feature is based to the fact that the CI UID (KUidBurstModeVFOptimization)
       
  1918     // is asked and found from the CAPI.
       
  1919     if ( aInterface == KUidBurstModeVFOptimization && interfaceImp )
       
  1920         {
       
  1921         iStillStatesActive->SetBurstModeVFOptimization( ETrue );
       
  1922         }
       
  1923         
       
  1924 	LOGTEXT2(_L("Cae: CCaeEngineImp::CustomInterface() returning, interfaceImp=%x"),interfaceImp );
       
  1925     return interfaceImp;
       
  1926     }
       
  1927 
       
  1928 
       
  1929 // -----------------------------------------------------------------------------
       
  1930 // CCaeEngineImp::GetOrder
       
  1931 // Populate feature array
       
  1932 // -----------------------------------------------------------------------------
       
  1933 //
       
  1934 void CCaeEngineImp::GetOrderL( RCaeOrderedFeatureList& aOrderedFeatureList )
       
  1935     {
       
  1936     TCaeOrderedFeatureListItem tmpItem;
       
  1937     aOrderedFeatureList.Reset();
       
  1938     
       
  1939 	// For all interface implementation lists
       
  1940     for ( TInt implListIndex = 0; 
       
  1941            implListIndex < iExtInterfaceImplementationLists.Count(); 
       
  1942           implListIndex++ )
       
  1943         {
       
  1944 		TCaeExtensionInterfaceImplListItem* implListItem = 
       
  1945 			&(iExtInterfaceImplementationLists[implListIndex]);
       
  1946 		RArray<TCaeExtensionInterfaceImplItem>& implementations 
       
  1947 		    = *(implListItem->iImplementations);
       
  1948 
       
  1949 		// For all implementations
       
  1950 		for ( TInt implIndex = 0; implIndex < implementations.Count(); implIndex++ )
       
  1951 			{
       
  1952 
       
  1953 			// Add to item to the feature array
       
  1954 			tmpItem.iServiceUid = implListItem->iInterfaceUid;
       
  1955 			tmpItem.iFeatureUid = implementations[implIndex].iImplUid;
       
  1956 			aOrderedFeatureList.AppendL( tmpItem );
       
  1957 			}
       
  1958         }
       
  1959     }
       
  1960 
       
  1961 
       
  1962 // -----------------------------------------------------------------------------
       
  1963 // CCaeEngineImp::SetOrderL
       
  1964 // The user must first call GetOrder() to get array. After that the user can 
       
  1965 // change the order of items and call this function. The user shall not remove 
       
  1966 // items or add new items to the array. 
       
  1967 //
       
  1968 // E.g. Typically the user finds two items from the array and switches
       
  1969 // the positions of these items to get desired effect.
       
  1970 // -----------------------------------------------------------------------------
       
  1971 //
       
  1972 void CCaeEngineImp::SetOrderL( const RCaeOrderedFeatureList& aOrderedFeatureList )
       
  1973     {
       
  1974 	TInt status = KErrNone;
       
  1975 
       
  1976 	// Check that aOrderedFeatureList is valid
       
  1977 	DoSetOrderL( aOrderedFeatureList, EFalse );
       
  1978 	
       
  1979 	// Check counts
       
  1980 	
       
  1981 	TInt totalImplCount = 0;
       
  1982 
       
  1983 	// For all interface implementation lists
       
  1984 	for ( TInt implListIndex = 0; 
       
  1985 	      implListIndex < iExtInterfaceImplementationLists.Count(); 
       
  1986 	      implListIndex++ )
       
  1987 		{
       
  1988 		TCaeExtensionInterfaceImplListItem* implListItem = 
       
  1989 			&(iExtInterfaceImplementationLists[implListIndex]);
       
  1990 		RArray<TCaeExtensionInterfaceImplItem>& implementations 
       
  1991 		    = *(implListItem->iImplementations);
       
  1992 
       
  1993 		totalImplCount += implementations.Count();
       
  1994 		}
       
  1995 
       
  1996 	if ( totalImplCount != aOrderedFeatureList.Count() )
       
  1997 		{
       
  1998 		status = KErrArgument;
       
  1999 		}
       
  2000 	else
       
  2001 		{
       
  2002 		// Check duplicates
       
  2003 		status = KErrNone;
       
  2004 		for ( TInt i =  aOrderedFeatureList.Count() - 1; 
       
  2005 		      ( i >= 0 ) && ( !status ); 
       
  2006 		      i-- )
       
  2007 			{
       
  2008 			// Find always starts at index 0
       
  2009 			TInt index = aOrderedFeatureList.Find( 
       
  2010 				aOrderedFeatureList[i], CCaeEngineImp::Match ); 
       
  2011 			if (index != i)
       
  2012 				{
       
  2013 				status = KErrAlreadyExists;
       
  2014 				}
       
  2015 			}
       
  2016 		
       
  2017 		// Finally, update internal array
       
  2018 		if ( !status )
       
  2019 			{
       
  2020 			DoSetOrderL( aOrderedFeatureList, ETrue );
       
  2021 			}
       
  2022 		}
       
  2023 
       
  2024 	User::LeaveIfError( status );
       
  2025 	}
       
  2026 
       
  2027 
       
  2028 // -----------------------------------------------------------------------------
       
  2029 // CCaeEngineImp::DoSetOrderL
       
  2030 //
       
  2031 // For each item the old item is removed and the new appended to the end of 
       
  2032 // iExtInterfaceImplementationLists[i].iImplementations.
       
  2033 // -----------------------------------------------------------------------------
       
  2034 //
       
  2035 void CCaeEngineImp::DoSetOrderL( 
       
  2036 	const RCaeOrderedFeatureList& aOrderedFeatureList, 
       
  2037 	TBool iUpdate )
       
  2038     {
       
  2039 	TInt status = KErrNone;
       
  2040 
       
  2041 	// For all items in given array
       
  2042     for (TInt i = 0; i < aOrderedFeatureList.Count() && !status; i++ )
       
  2043         {
       
  2044         TUid interfaceUid = aOrderedFeatureList[i].iServiceUid;
       
  2045         TUid itemImplUid = aOrderedFeatureList[i].iFeatureUid;
       
  2046 
       
  2047 		// Find correct interface list
       
  2048 
       
  2049 		TCaeExtensionInterfaceImplListItem listItem;
       
  2050 		listItem.iInterfaceUid = interfaceUid;
       
  2051 		listItem.iImplementations =  NULL;
       
  2052 		TInt index = iExtInterfaceImplementationLists.Find( listItem );
       
  2053 		if ( index < 0 )
       
  2054 			{
       
  2055 			status = index; // Invalid interface uid
       
  2056 			}
       
  2057 		else
       
  2058 			{
       
  2059 			
       
  2060 			// Find implementation by uid
       
  2061 
       
  2062 			TCaeExtensionInterfaceImplItem item;
       
  2063 			item.iInitialPriority = 0;
       
  2064 			item.iImplUid.iUid = itemImplUid.iUid;
       
  2065 			item.iImplPtr = 0;
       
  2066 			item.iIsActive = ETrue;
       
  2067 			RArray<TCaeExtensionInterfaceImplItem>& implementations = 
       
  2068 				*( iExtInterfaceImplementationLists[index].iImplementations );
       
  2069 
       
  2070 			TInt itemIndex = implementations.Find( item, CCaeEngineImp::MatchEqualImplUid );
       
  2071 			if ( itemIndex < 0 ) 
       
  2072 				{
       
  2073 				status = itemIndex; // Invalid feature/implementation uid
       
  2074 				}
       
  2075 			else
       
  2076 				{
       
  2077 				if ( iUpdate )
       
  2078 					{
       
  2079 					// Remove current item and add new implementation item to 
       
  2080 					// end of the array
       
  2081 
       
  2082 					item = implementations[itemIndex];
       
  2083 
       
  2084 					implementations.Remove( itemIndex );
       
  2085 
       
  2086 					status = implementations.Append( item );
       
  2087 					}
       
  2088 				}
       
  2089 			}
       
  2090         }
       
  2091 
       
  2092     User::LeaveIfError( status );
       
  2093     }
       
  2094 
       
  2095 
       
  2096 // -----------------------------------------------------------------------------
       
  2097 // CCaeEngineImp::MatchEqualImplUid 
       
  2098 // Compares two extension array items
       
  2099 // -----------------------------------------------------------------------------
       
  2100 //
       
  2101 TBool CCaeEngineImp::MatchEqualImplUid( 
       
  2102     const TCaeExtensionInterfaceImplItem& aFirst, 
       
  2103     const TCaeExtensionInterfaceImplItem& aSecond )
       
  2104     {
       
  2105 	return ( aFirst.iImplUid.iUid == aSecond.iImplUid.iUid ); 
       
  2106     }
       
  2107 
       
  2108 
       
  2109 // -----------------------------------------------------------------------------
       
  2110 // CCaeEngineImp::MatchEqualImplPtr 
       
  2111 // Compares two extension array items
       
  2112 // -----------------------------------------------------------------------------
       
  2113 //
       
  2114 TBool CCaeEngineImp::MatchEqualImplPtr( 
       
  2115     const TCaeExtensionInterfaceImplItem& aFirst, 
       
  2116     const TCaeExtensionInterfaceImplItem& aSecond )
       
  2117     {
       
  2118 	return ( aFirst.iImplPtr == aSecond.iImplPtr ); 
       
  2119     }
       
  2120 
       
  2121 
       
  2122 // -----------------------------------------------------------------------------
       
  2123 // CCaeEngineImp::MatchSmallerInitialPriorityAndImplUid 
       
  2124 // Compares two extension array items
       
  2125 // -----------------------------------------------------------------------------
       
  2126 //
       
  2127 TBool CCaeEngineImp::MatchSmallerInitialPriorityAndImplUid( 
       
  2128     const TCaeExtensionInterfaceImplItem& aFirst, 
       
  2129     const TCaeExtensionInterfaceImplItem& aSecond )
       
  2130     {
       
  2131 	if (  ( aSecond.iInitialPriority == aFirst.iInitialPriority )
       
  2132 		  && ( aSecond.iImplUid.iUid < aFirst.iImplUid.iUid ) )
       
  2133 		{
       
  2134 		return ETrue;
       
  2135 		}
       
  2136 
       
  2137 	else if ( aSecond.iInitialPriority < aFirst.iInitialPriority )
       
  2138 		{
       
  2139 		return ETrue;
       
  2140 		}
       
  2141 
       
  2142 	else
       
  2143 		{
       
  2144 		return EFalse;
       
  2145 		}
       
  2146     }
       
  2147 
       
  2148 // -----------------------------------------------------------------------------
       
  2149 // CCaeEngineImp::Match 
       
  2150 // Compares two extension array items
       
  2151 // -----------------------------------------------------------------------------
       
  2152 //
       
  2153 TBool CCaeEngineImp::Match( 
       
  2154     const TCaeOrderedFeatureListItem& aFirst, 
       
  2155     const TCaeOrderedFeatureListItem& aSecond )
       
  2156     {
       
  2157 	return ( ( aFirst.iServiceUid == aSecond.iServiceUid ) 
       
  2158 		     && ( aFirst.iFeatureUid == aSecond.iFeatureUid ) ); 
       
  2159     }
       
  2160 
       
  2161 
       
  2162 // From MCaeExtEngineInfoCallbackInterface
       
  2163 
       
  2164 // -----------------------------------------------------------------------------
       
  2165 // CCaeEngineImp::McaeExtStillImageSize
       
  2166 // Returns current still image size.
       
  2167 // -----------------------------------------------------------------------------
       
  2168 //
       
  2169 TSize CCaeEngineImp::McaeExtStillImageSize()
       
  2170 	{
       
  2171 	return( iStillStatesActive->StillImageSize() );
       
  2172 	}
       
  2173 
       
  2174 // -----------------------------------------------------------------------------
       
  2175 // CCaeEngineImp::McaeExtSnapImageSize
       
  2176 // Returns current snap image size.
       
  2177 // -----------------------------------------------------------------------------
       
  2178 //
       
  2179 TSize CCaeEngineImp::McaeExtSnapImageSize()
       
  2180 	{
       
  2181 	return( iStillStatesActive->SnapImageSize() );
       
  2182 	}
       
  2183 
       
  2184 // -----------------------------------------------------------------------------
       
  2185 // CCaeEngineImp::McaeExtViewFinderSize
       
  2186 // Returns current view finder size.
       
  2187 // -----------------------------------------------------------------------------
       
  2188 //
       
  2189 TSize CCaeEngineImp::McaeExtViewFinderSize()
       
  2190 	{
       
  2191 	return( iTrueViewFinderSize );
       
  2192 	}
       
  2193 
       
  2194 // -----------------------------------------------------------------------------
       
  2195 // CCaeEngineImp::McaeExtCheckPowerL
       
  2196 // Check camera power.
       
  2197 // -----------------------------------------------------------------------------
       
  2198 //
       
  2199 void CCaeEngineImp::McaeExtCheckPowerL()
       
  2200 	{
       
  2201 	CheckPowerL();
       
  2202 	}
       
  2203 
       
  2204 // -----------------------------------------------------------------------------
       
  2205 // CCaeEngineImp::McaeExtDisplayIndex
       
  2206 // Returns display index.
       
  2207 // -----------------------------------------------------------------------------
       
  2208 //
       
  2209 TInt CCaeEngineImp::McaeExtDisplayIndex()
       
  2210 	{
       
  2211     LOGTEXT2( _L( "Cae: CCaeEngineImp::McaeExtDisplayIndex() iDisplayIndex=%d" ), iDisplayIndex );
       
  2212 	return( iDisplayIndex );
       
  2213 	}
       
  2214 
       
  2215 // From MExtensionCallbackInterface
       
  2216 
       
  2217 // -----------------------------------------------------------------------------
       
  2218 // CCaeEngineImp::IsInterfaceSupported
       
  2219 // Check that the interface is supported. 
       
  2220 // -----------------------------------------------------------------------------
       
  2221 //
       
  2222 TBool CCaeEngineImp::IsInterfaceSupported( TUid aInterfaceUid )
       
  2223 	{
       
  2224 	TBool found = EFalse;
       
  2225 	TInt i = 0;
       
  2226 
       
  2227 	TCaeExtensionInterfaceImplListItem listItem;
       
  2228 	listItem.iInterfaceUid = aInterfaceUid;
       
  2229 	listItem.iImplementations =  NULL;
       
  2230 
       
  2231 	// Check extension interface uids
       
  2232 	if ( iExtInterfaceImplementationLists.Find( listItem ) >= 0 )
       
  2233 		{
       
  2234 		found = ETrue;
       
  2235 		}
       
  2236 
       
  2237 	// Check callback interface uids
       
  2238 	for ( i = 0; (KCaeSupportedCallbackInterfaceUids[i].iUid != NULL) && !found; i++ )
       
  2239 		{
       
  2240 		if ( KCaeSupportedCallbackInterfaceUids[i] == aInterfaceUid )
       
  2241 			{
       
  2242 			found = ETrue;
       
  2243 			}
       
  2244 		}
       
  2245 
       
  2246 	return found;
       
  2247 	}
       
  2248 
       
  2249 // -----------------------------------------------------------------------------
       
  2250 // CCaeEngineImp::AddExtensionInterface
       
  2251 // Add an extension implemented interface to the list.
       
  2252 // Note: Returns KErrNotFound if the interface is not supported.
       
  2253 // -----------------------------------------------------------------------------
       
  2254 //
       
  2255 TInt CCaeEngineImp::AddExtensionInterface( 
       
  2256 	TUid aInterfaceUid, 
       
  2257 	TUid aExtensionUid, 
       
  2258 	TAny* aImplementationPtr, 
       
  2259 	TInt aInitialPriority )
       
  2260 	{
       
  2261     LOGTEXT3( _L( "Cae: CCaeEngineImp::AddExtensionInterface() entering: ifUid=%x, exUid=%x" ), aInterfaceUid.iUid, aExtensionUid.iUid );
       
  2262 
       
  2263 	TInt status = KErrNone;
       
  2264 
       
  2265 	// Check for invalid pointer
       
  2266 	if ( !aImplementationPtr )
       
  2267 		{
       
  2268 		status = KErrArgument;
       
  2269 		}
       
  2270 	else
       
  2271 		{
       
  2272 
       
  2273 		// Add implementation to the list
       
  2274 
       
  2275 		TCaeExtensionInterfaceImplListItem listItem;
       
  2276 		listItem.iInterfaceUid = aInterfaceUid;
       
  2277 		listItem.iImplementations =  NULL;
       
  2278 
       
  2279 		TInt index = iExtInterfaceImplementationLists.Find( listItem );
       
  2280 		if ( index < 0 )
       
  2281 			{
       
  2282 			status = index; // Error code
       
  2283 			}
       
  2284 		else
       
  2285 			{
       
  2286 
       
  2287 			// Add new implementation item to the array
       
  2288 
       
  2289 			RArray<TCaeExtensionInterfaceImplItem>& implementations = 
       
  2290 				*( iExtInterfaceImplementationLists[index].iImplementations );
       
  2291 
       
  2292 			TCaeExtensionInterfaceImplItem item;
       
  2293 			item.iInitialPriority = aInitialPriority;
       
  2294 			item.iImplUid  = aExtensionUid;
       
  2295 			item.iImplPtr  = aImplementationPtr;
       
  2296 			item.iIsActive = ETrue;
       
  2297 
       
  2298 			// Check for duplicates
       
  2299 			TInt itemIndex = implementations.Find( item, CCaeEngineImp::MatchEqualImplUid );
       
  2300 			if ( itemIndex >= 0 ) 
       
  2301 				{
       
  2302 				status = KErrAlreadyExists; // Error code
       
  2303 				}
       
  2304 			else
       
  2305 				{
       
  2306 				itemIndex = implementations.Find( 
       
  2307 				    item, CCaeEngineImp::MatchSmallerInitialPriorityAndImplUid );
       
  2308 				if ( itemIndex < 0 ) 
       
  2309 					{
       
  2310 					// All have bigger or equal priority. Add to the end of list.
       
  2311 					itemIndex = implementations.Count();
       
  2312 					}
       
  2313 
       
  2314 				// Finally, add item to the list
       
  2315 				status =  implementations.Insert( item, itemIndex ); 
       
  2316 				}
       
  2317 			}
       
  2318 		}
       
  2319 
       
  2320     LOGTEXT2( _L( "Cae: CCaeEngineImp::AddExtensionInterface() returning: status=%d" ), status );
       
  2321 
       
  2322 	return( status );
       
  2323 	}
       
  2324 
       
  2325 // -----------------------------------------------------------------------------
       
  2326 // CCaeEngineImp::RemoveExtensionInterface
       
  2327 // Remove an extension implemented interface from the list.
       
  2328 // -----------------------------------------------------------------------------
       
  2329 //
       
  2330 TInt CCaeEngineImp::RemoveExtensionInterface( 
       
  2331 	TUid aInterfaceUid, 
       
  2332 	TAny* aImplementationPtr )
       
  2333 	{
       
  2334     LOGTEXT3( _L( "Cae: CCaeEngineImp::RemoveExtensionInterface() entering: ifUid=%x, ptr=%d" ), aInterfaceUid.iUid, aImplementationPtr );
       
  2335 	TInt status = KErrNone;
       
  2336 
       
  2337 	// Check for invalid pointer
       
  2338 	if ( !aImplementationPtr )
       
  2339 		{
       
  2340 		status = KErrArgument;
       
  2341 		}
       
  2342 	else
       
  2343 		{
       
  2344 		// Remove implementation to the list
       
  2345 		TCaeExtensionInterfaceImplListItem listItem;
       
  2346 		listItem.iInterfaceUid = aInterfaceUid;
       
  2347 		listItem.iImplementations =  NULL;
       
  2348 
       
  2349 		TInt index = iExtInterfaceImplementationLists.Find( listItem );
       
  2350 
       
  2351 		if ( index < 0 )
       
  2352 			{
       
  2353 			status = index; // Error code
       
  2354 			}
       
  2355 		else
       
  2356 			{
       
  2357 			TCaeExtensionInterfaceImplItem item;
       
  2358 			item.iInitialPriority = 0;
       
  2359 			item.iImplUid.iUid = 0;
       
  2360 			item.iImplPtr = aImplementationPtr;
       
  2361 			item.iIsActive = ETrue;
       
  2362 			
       
  2363 			RArray<TCaeExtensionInterfaceImplItem>& implementations = 
       
  2364 				*( iExtInterfaceImplementationLists[index].iImplementations );
       
  2365 
       
  2366 			TInt itemIndex = implementations.Find( item, CCaeEngineImp::MatchEqualImplPtr );
       
  2367 
       
  2368 			if ( itemIndex < 0 ) 
       
  2369 				{
       
  2370 				status = itemIndex; // Return error
       
  2371 				}
       
  2372 			else
       
  2373 				{
       
  2374 				implementations.Remove( itemIndex );
       
  2375 				}
       
  2376 			}
       
  2377 		}
       
  2378 
       
  2379     LOGTEXT2( _L( "Cae: CCaeEngineImp::RemoveExtensionInterface() returning: status=%d" ), status );
       
  2380 
       
  2381 	return( status );
       
  2382 	}
       
  2383 
       
  2384 // -----------------------------------------------------------------------------
       
  2385 // CCaeEngineImp::AddCustomInterface
       
  2386 // Add an extension implemented custom interface to the list.
       
  2387 // -----------------------------------------------------------------------------
       
  2388 //
       
  2389 TInt CCaeEngineImp::AddCustomInterface( 
       
  2390     TUid aInterfaceUid, 
       
  2391     TAny* aImplementationPtr )
       
  2392 	{
       
  2393     LOGTEXT3( _L( "Cae: CCaeEngineImp::AddCustomInterface() entering: ifUid=%x, ptr=%d" ), aInterfaceUid.iUid, aImplementationPtr );
       
  2394 
       
  2395 	TInt status = KErrNone;
       
  2396 
       
  2397 	if ( !aImplementationPtr )
       
  2398 		{
       
  2399 		status = KErrArgument;
       
  2400 		}
       
  2401 	else
       
  2402 		{
       
  2403 		TCaeCustomInterfaceImplItem item;
       
  2404 		item.iInterfaceUid = aInterfaceUid;
       
  2405 		item.iImplPtr = aImplementationPtr;
       
  2406 		
       
  2407 	    // Do not allow duplicate uid's
       
  2408 		status = iExtCustomInterfaceImplementations.InsertInUnsignedKeyOrder( item ); 	
       
  2409 		}
       
  2410 	
       
  2411     LOGTEXT2( _L( "Cae: CCaeEngineImp::AddCustomInterface() returning: status=%d" ), status );
       
  2412 
       
  2413 	return ( status );
       
  2414 	}
       
  2415 
       
  2416 // -----------------------------------------------------------------------------
       
  2417 // CCaeEngineImp::GetCallbackInterface
       
  2418 // Return an engine implemented callback interface.
       
  2419 // -----------------------------------------------------------------------------
       
  2420 //
       
  2421 TAny* CCaeEngineImp::GetCallbackInterface( TUid aInterfaceUid )
       
  2422 	{
       
  2423     LOGTEXT2( _L( "Cae: CCaeEngineImp::GetCallbackInterface() entering: ifUid=%x" ), aInterfaceUid.iUid );
       
  2424 	TAny* callbackInterface =  NULL;
       
  2425 
       
  2426 	if ( aInterfaceUid == KCaeExtEngineInfoCallbackInterfaceUid )
       
  2427 		{
       
  2428 		callbackInterface = (MCaeExtEngineInfoCallbackInterface*) this;
       
  2429 		}
       
  2430 
       
  2431     LOGTEXT2( _L( "Cae: CCaeEngineImp::GetCallbackInterface() returning: callbackInterface=%d" ), callbackInterface );
       
  2432 	return ( callbackInterface );
       
  2433 	}
       
  2434 
       
  2435 // -----------------------------------------------------------------------------
       
  2436 // CCaeEngineImp::RegisterFlags
       
  2437 // -----------------------------------------------------------------------------
       
  2438 //
       
  2439 void CCaeEngineImp::RegisterFlags( TUint32 aFlags )
       
  2440 	{
       
  2441     LOGTEXT2( _L( "Cae: CCaeEngineImp::RegisterFlags() aFlags=%x" ), aFlags );
       
  2442     iStillStatesActive->RegisterFlags( aFlags );
       
  2443 	}
       
  2444 
       
  2445 
       
  2446 // -----------------------------------------------------------------------------
       
  2447 // CCaeEngineImp::DeregisterFlags
       
  2448 // -----------------------------------------------------------------------------
       
  2449 //
       
  2450 void CCaeEngineImp::DeregisterFlags( TUint32 aFlags )
       
  2451     {
       
  2452     LOGTEXT2( _L( "Cae: CCaeEngineImp::DeregisterFlags() aFlags=%x" ), aFlags );
       
  2453     iStillStatesActive->DeregisterFlags( aFlags );    
       
  2454     }
       
  2455 
       
  2456 // -----------------------------------------------------------------------------
       
  2457 // CCaeEngineImp::CCameraHandle
       
  2458 // Gets handle of camera object owned by the CCaeEngine.
       
  2459 // -----------------------------------------------------------------------------
       
  2460 //
       
  2461 TInt CCaeEngineImp::CCameraHandle() const
       
  2462     {
       
  2463     LOGTEXT2( _L( "Cae: CCaeEngineImp::CCameraHandle(): %d" ), iCameraHandle );
       
  2464     return ( iCameraHandle );
       
  2465     }
       
  2466 
       
  2467 // -----------------------------------------------------------------------------
       
  2468 // CCaeEngineImp::SetCaeExtensionModeL
       
  2469 // Sets CAE to Extension mode
       
  2470 // -----------------------------------------------------------------------------
       
  2471 //
       
  2472 void CCaeEngineImp::SetCaeExtensionModeL( TBool aExtModeActive, TBool aCreateSnapImage )
       
  2473     {
       
  2474     LOGTEXT3( _L( "Cae: CCaeEngineImp::SetCaeExtensionModeL(): %d, %d" ), aExtModeActive, aCreateSnapImage );
       
  2475 
       
  2476     iStillStatesActive->SetExtModeActiveL( aExtModeActive );
       
  2477     iStillStatesActive->SetSnapImageCreation( aCreateSnapImage );
       
  2478     }
       
  2479 
       
  2480 // -----------------------------------------------------------------------------
       
  2481 // CCaeEngineImp::ProcessExtViewFinderFrameReadyL
       
  2482 // Process extension for view finder
       
  2483 // -----------------------------------------------------------------------------
       
  2484 //
       
  2485 void CCaeEngineImp::ProcessExtViewFinderFrameReadyL( CFbsBitmap& aFrame )
       
  2486     {
       
  2487     LOGTEXT( _L( "Cae: CCaeEngineImp::ProcessExtViewFinderFrameReadyL()" ));
       
  2488 
       
  2489     // Leave if not in extension mode.
       
  2490     if ( !iStillStatesActive->ExtModeActive() )
       
  2491         {
       
  2492         LOGTEXT( _L( "Cae: CCaeEngineImp::ProcessExtViewFinderFrameReadyL() leaving KErrPermissionDenied" ) );
       
  2493         User::Leave( KErrPermissionDenied );
       
  2494         }
       
  2495 
       
  2496     ViewFinderFrameReady( aFrame );
       
  2497     }
       
  2498 
       
  2499 // -----------------------------------------------------------------------------
       
  2500 // CCaeEngineImp::ProcessExtSnapImageL
       
  2501 // Process extension for snap image
       
  2502 // -----------------------------------------------------------------------------
       
  2503 //
       
  2504 void CCaeEngineImp::ProcessExtSnapImageL( CFbsBitmap& aSnapImage )
       
  2505     {
       
  2506     TSize sizeEmpty;
       
  2507     CFbsBitmap* bitmapSave = NULL;
       
  2508     TSize snapSize = aSnapImage.SizeInPixels();
       
  2509     
       
  2510     LOGTEXT3( _L( "Cae: CCaeEngineImp::ProcessExtSnapImageL() size wxh=%dx%d" ),
       
  2511             snapSize.iWidth, snapSize.iHeight );
       
  2512         
       
  2513     // Leave if not in extension mode.
       
  2514     if ( !iStillStatesActive->ExtModeActive() )
       
  2515         {
       
  2516         LOGTEXT( _L( "Cae: CCaeEngineImp::ProcessExtSnapImageL() leaving KErrPermissionDenied" ) );
       
  2517         User::Leave( KErrPermissionDenied );
       
  2518         }
       
  2519 
       
  2520     // Create a duplicate bitmap
       
  2521     if ( snapSize != sizeEmpty ) 
       
  2522         {
       
  2523         bitmapSave = new CFbsBitmap;
       
  2524         if ( bitmapSave )
       
  2525             {
       
  2526             TInt err = bitmapSave->Duplicate( aSnapImage.Handle() );
       
  2527             if ( err ) 
       
  2528                 {
       
  2529                     LOGTEXT2( _L( "Cae: CCaeEngineImp::ProcessExtSnapImageL(): Duplicate error:%d, leaving" ), err);
       
  2530                     delete bitmapSave;
       
  2531                     bitmapSave = NULL;
       
  2532                     User::Leave( err );
       
  2533                  }
       
  2534             }
       
  2535         else
       
  2536             {
       
  2537             LOGTEXT( _L( "Cae: CCaeEngineImp::ProcessExtSnapImageL(): new CFbsBitmap failed, leaving KErrNoMemory" ));
       
  2538             User::Leave( KErrNoMemory );
       
  2539             }
       
  2540         }
       
  2541     else
       
  2542         {
       
  2543         LOGTEXT( _L( "Cae: CCaeEngineImp::ProcessExtSnapImageL(): got empty bitmap, ignore" ));
       
  2544         }
       
  2545         
       
  2546     if ( bitmapSave )
       
  2547         {
       
  2548         // Send bitmap for extension handling
       
  2549         TInt result = iStillStatesActive->ProcessExtSnapImage( bitmapSave );
       
  2550         if ( result )
       
  2551             {
       
  2552             LOGTEXT2( _L( "Cae: CCaeEngineImp::ProcessExtSnapImageL(): ProcessExtSnapImage failed %d, leaving" ), result);
       
  2553             delete bitmapSave;
       
  2554             bitmapSave = NULL;
       
  2555             User::Leave( result );
       
  2556             }
       
  2557         }
       
  2558     }
       
  2559 
       
  2560 // -----------------------------------------------------------------------------
       
  2561 // CCaeEngineImp::ProcessExtCapturedImageL
       
  2562 // Process extension for captured image
       
  2563 // -----------------------------------------------------------------------------
       
  2564 //
       
  2565 void CCaeEngineImp::ProcessExtCapturedImageL( CFbsBitmap& aBitmap, TBool aLastImage )
       
  2566     {
       
  2567     TSize sizeEmpty;
       
  2568     CFbsBitmap* bitmapSave = NULL;
       
  2569     TSize bitmapSize = aBitmap.SizeInPixels();
       
  2570     
       
  2571     LOGTEXT3( _L( "Cae: CCaeEngineImp::ProcessExtCapturedImageL() CFbsBitmap ExtMode=%d, last=%d" ), iStillStatesActive->ExtModeActive(), aLastImage);
       
  2572     LOGTEXT3( _L( "Cae: CCaeEngineImp::ProcessExtCapturedImageL() bitmap size WxH=%dx%d" ), bitmapSize.iWidth, bitmapSize.iHeight );
       
  2573         
       
  2574     // Leave if not in extension mode.
       
  2575     if ( !iStillStatesActive->ExtModeActive() )
       
  2576         {
       
  2577         LOGTEXT( _L( "Cae: CCaeEngineImp::ProcessExtCapturedImageL leaving KErrPermissionDenied" ));
       
  2578         User::Leave( KErrPermissionDenied );
       
  2579         }
       
  2580 
       
  2581     // Create a duplicate bitmap
       
  2582     if ( bitmapSize != sizeEmpty )
       
  2583         {
       
  2584         bitmapSave = new CFbsBitmap;
       
  2585         if ( bitmapSave )
       
  2586             {
       
  2587             TInt err = bitmapSave->Duplicate( aBitmap.Handle() );
       
  2588             if ( err ) 
       
  2589                 {
       
  2590                     LOGTEXT2( _L( "Cae: CCaeEngineImp::ProcessExtCapturedImageL(): Duplicate error:%d, leaving" ), err);
       
  2591                     delete bitmapSave;
       
  2592                     bitmapSave = NULL;
       
  2593                     User::Leave( err );
       
  2594                  }
       
  2595             }
       
  2596         else
       
  2597             {
       
  2598             LOGTEXT( _L( "Cae: CCaeEngineImp::ProcessExtCapturedImageL(): new CFbsBitmap failed, leaving KErrNoMemory" ));
       
  2599             User::Leave( KErrNoMemory );
       
  2600             }
       
  2601 
       
  2602         }
       
  2603     else
       
  2604         {
       
  2605         LOGTEXT( _L( "Cae: CCaeEngineImp::ProcessExtCapturedImageL(): got empty bitmap, ignore" ));
       
  2606         }
       
  2607         
       
  2608     if ( bitmapSave )
       
  2609         {
       
  2610         // Send bitmap for extension handling
       
  2611         TInt result = iStillStatesActive->ProcessExtCapturedImage( bitmapSave, aLastImage );
       
  2612         if ( result )
       
  2613             {
       
  2614             LOGTEXT2( _L( "Cae: CCaeEngineImp::ProcessExtCapturedImageL(): ProcessExtCapturedImage failed %d, leaving" ), result);
       
  2615             delete bitmapSave;
       
  2616             bitmapSave = NULL;
       
  2617             User::Leave( result );
       
  2618             }
       
  2619         }
       
  2620     }
       
  2621 
       
  2622 // -----------------------------------------------------------------------------
       
  2623 // CCaeEngineImp::ProcessExtCapturedImageL
       
  2624 // Process extension for captured image
       
  2625 // -----------------------------------------------------------------------------
       
  2626 //
       
  2627 void CCaeEngineImp::ProcessExtCapturedImageL( HBufC8* aImageData, TBool aLastImage )
       
  2628     {
       
  2629     LOGTEXT3( _L( "Cae: CCaeEngineImp::ProcessExtCapturedImageL() HBufC8 ExtMode=%d, last=%d" ), iStillStatesActive->ExtModeActive(), aLastImage);
       
  2630     // Leave if not in extension mode.
       
  2631     if ( !iStillStatesActive->ExtModeActive() )
       
  2632         {
       
  2633         LOGTEXT( _L( "Cae: CCaeEngineImp::ProcessExtCapturedImageL leaving KErrPermissionDenied" ));
       
  2634         User::Leave( KErrPermissionDenied );
       
  2635         }
       
  2636     if ( aImageData )
       
  2637         {
       
  2638         LOGTEXT2( _L( "Cae: CCaeEngineImp::ProcessExtCapturedImageL() processing HBufC8 size=%d" ), aImageData->Size() );
       
  2639         TInt result = iStillStatesActive->ProcessExtCapturedImage( aImageData, aLastImage );
       
  2640         if ( result )
       
  2641             {
       
  2642             LOGTEXT2( _L( "Cae: CCaeEngineImp::ProcessExtCapturedImageL(): ProcessExtCapturedImage failed %d, leaving" ), result);
       
  2643             delete aImageData;
       
  2644             aImageData = NULL;
       
  2645             User::Leave( result );
       
  2646             }
       
  2647         }
       
  2648     else
       
  2649         {
       
  2650         LOGTEXT( _L( "Cae: CCaeEngineImp::ProcessExtCapturedImageL(): got empty HBufC8, ignore" ));
       
  2651         }
       
  2652     
       
  2653     }
       
  2654 
       
  2655 // -----------------------------------------------------------------------------
       
  2656 // CCaeEngineImp::ProcessExtCapturedImageL
       
  2657 // Process extension for captured image
       
  2658 // -----------------------------------------------------------------------------
       
  2659 //
       
  2660 void CCaeEngineImp::ProcessExtCapturedImageL( TDesC8& aImageDataDes, TBool aLastImage )
       
  2661     {
       
  2662     LOGTEXT3( _L( "Cae: CCaeEngineImp::ProcessExtCapturedImageL() TDesC8 ExtMode=%d, last=%d" ), iStillStatesActive->ExtModeActive(), aLastImage);
       
  2663     // Leave if not in extension mode.
       
  2664     if ( !iStillStatesActive->ExtModeActive() )
       
  2665         {
       
  2666         LOGTEXT( _L( "Cae: CCaeEngineImp::ProcessExtCapturedImageL leaving KErrPermissionDenied" ));
       
  2667         User::Leave( KErrPermissionDenied );
       
  2668         }
       
  2669     // TDesC8 is used with C-API V2 features
       
  2670     if ( aImageDataDes.Size() )
       
  2671         {
       
  2672         // Make a new HBufC8 copy from the TDesC8
       
  2673         HBufC8* tempImageData = aImageDataDes.AllocL();
       
  2674         // Do not delete aImageDataDes, it is part of the class MCameraBuffer
       
  2675         LOGTEXT2( _L( "Cae: CCaeEngineImp::ProcessExtCapturedImageL() New HBufC8 created, size=%d" ), tempImageData->Size() );
       
  2676         
       
  2677         TInt result = iStillStatesActive->ProcessExtCapturedImage( tempImageData, aLastImage );
       
  2678         if ( result )
       
  2679             {
       
  2680             LOGTEXT2( _L( "Cae: CCaeEngineImp::ProcessExtCapturedImageL(): ProcessExtCapturedImage failed %d, leaving" ), result);
       
  2681             delete tempImageData;
       
  2682             tempImageData = NULL;
       
  2683             User::Leave( result );
       
  2684             }
       
  2685         }
       
  2686     else
       
  2687         {
       
  2688         LOGTEXT( _L( "Cae: CCaeEngineImp::ProcessExtCapturedImageL(): got empty TDesC8, ignore" ));
       
  2689         }
       
  2690     
       
  2691     }
       
  2692 
       
  2693 // -----------------------------------------------------------------------------
       
  2694 // CCaeEngineImp::ProcessExtCancel
       
  2695 // Cancels processing
       
  2696 // -----------------------------------------------------------------------------
       
  2697 //
       
  2698 void CCaeEngineImp::ProcessExtCancel()
       
  2699     {
       
  2700     CancelCaptureStill();
       
  2701     }
       
  2702 
       
  2703 
       
  2704 // -----------------------------------------------------------------------------
       
  2705 // CCaeEngineImp::SkippedExtensionListL
       
  2706 // Get list of skipped extensions. Application may define which extensions are
       
  2707 // skipped during image processing. Only installed and skipped are listed.
       
  2708 // -----------------------------------------------------------------------------
       
  2709 //
       
  2710 void CCaeEngineImp::SkippedExtensionListL( RCaeOrderedFeatureList& aDisabledExtensions )
       
  2711     {
       
  2712     LOGTEXT( _L( "Cae: CCaeEngineImp::SkippedExtensionListL() entering" ) );
       
  2713     TCaeOrderedFeatureListItem tmpItem;
       
  2714     aDisabledExtensions.Reset();
       
  2715     
       
  2716 	// For all interface implementation lists
       
  2717     for ( TInt implListIndex = 0; 
       
  2718            implListIndex < iExtInterfaceImplementationLists.Count(); 
       
  2719           implListIndex++ )
       
  2720         {
       
  2721 		TCaeExtensionInterfaceImplListItem* implListItem = 
       
  2722 			&(iExtInterfaceImplementationLists[implListIndex]);
       
  2723 		RArray<TCaeExtensionInterfaceImplItem>& implementations 
       
  2724 		    = *(implListItem->iImplementations);
       
  2725 
       
  2726 		// For all implementations
       
  2727 		for ( TInt implIndex = 0; implIndex < implementations.Count(); implIndex++ )
       
  2728 			{
       
  2729 			// Add the item to the skipped array if it is not active
       
  2730 			if ( !implementations[implIndex].iIsActive )
       
  2731 			    {
       
  2732 			    tmpItem.iServiceUid = implListItem->iInterfaceUid;
       
  2733 			    tmpItem.iFeatureUid = implementations[implIndex].iImplUid;
       
  2734 			    aDisabledExtensions.AppendL( tmpItem );
       
  2735                 LOGTEXT3( _L( "Cae: CCaeEngineImp::SkippedExtensionListL(), serviceUid %x, featureUid %x" ),
       
  2736                     tmpItem.iServiceUid.iUid, tmpItem.iFeatureUid.iUid  );
       
  2737 			    }
       
  2738 			}
       
  2739         }
       
  2740     LOGTEXT2( _L( "Cae: CCaeEngineImp::SkippedExtensionListL() returning, count %d" ), aDisabledExtensions.Count() );
       
  2741     }
       
  2742 
       
  2743 // -----------------------------------------------------------------------------
       
  2744 // CCaeEngineImp::SetSkippedExtensionList
       
  2745 // Set list of skipped extensions. Application may define which extensions are
       
  2746 // skipped during image processing.
       
  2747 // -----------------------------------------------------------------------------
       
  2748 //
       
  2749 void CCaeEngineImp::SetSkippedExtensionList( RCaeOrderedFeatureList& aDisabledExtensions )
       
  2750     {
       
  2751     LOGTEXT2( _L( "Cae: CCaeEngineImp::SetSkippedExtensionList() entering Count %d" ), aDisabledExtensions.Count() );
       
  2752 
       
  2753 	// Set all extensions first active
       
  2754 
       
  2755 	// For all interfaces
       
  2756     for ( TInt implListIndex = 0; 
       
  2757            implListIndex < iExtInterfaceImplementationLists.Count(); 
       
  2758           implListIndex++ )
       
  2759         {
       
  2760 		TCaeExtensionInterfaceImplListItem* implListItem = 
       
  2761 			&(iExtInterfaceImplementationLists[implListIndex]);
       
  2762 		RArray<TCaeExtensionInterfaceImplItem>& implementations 
       
  2763 		    = *(implListItem->iImplementations);
       
  2764 
       
  2765 		// For all implementations
       
  2766 		for ( TInt implIndex = 0; implIndex < implementations.Count(); implIndex++ )
       
  2767 			{
       
  2768 			implementations[implIndex].iIsActive = ETrue;
       
  2769 			}
       
  2770         }
       
  2771 
       
  2772     // Disable wanted extensions
       
  2773     
       
  2774 	// For all items in given array
       
  2775     for (TInt i = 0; i < aDisabledExtensions.Count(); i++ )
       
  2776         {
       
  2777         TUid interfaceUid = aDisabledExtensions[i].iServiceUid;
       
  2778         TUid itemImplUid = aDisabledExtensions[i].iFeatureUid;
       
  2779 
       
  2780 		// Find correct interface list
       
  2781 
       
  2782 		TCaeExtensionInterfaceImplListItem listItem;
       
  2783 		listItem.iInterfaceUid = interfaceUid;
       
  2784 		listItem.iImplementations =  NULL;
       
  2785 		TInt index = iExtInterfaceImplementationLists.Find( listItem );
       
  2786 		if ( index >= 0 ) // Interface was found
       
  2787 			{
       
  2788 			// Find implementation by uid
       
  2789 
       
  2790 			TCaeExtensionInterfaceImplItem item;
       
  2791 			item.iInitialPriority = 0;
       
  2792 			item.iImplUid.iUid = itemImplUid.iUid;
       
  2793 			item.iImplPtr = 0;
       
  2794 			item.iIsActive = ETrue;
       
  2795 			RArray<TCaeExtensionInterfaceImplItem>& implementations = 
       
  2796 				*( iExtInterfaceImplementationLists[index].iImplementations );
       
  2797 
       
  2798 			TInt itemIndex = implementations.Find( item, CCaeEngineImp::MatchEqualImplUid );
       
  2799 			if ( itemIndex >= 0 ) 
       
  2800 				{
       
  2801 				implementations[itemIndex].iIsActive = EFalse;
       
  2802                 LOGTEXT3( _L( "Cae: CCaeEngineImp::SetSkippedExtensionList(), serviceUid %x, featureUid %x" ),
       
  2803                     interfaceUid.iUid, itemImplUid.iUid  );
       
  2804 				}
       
  2805 			}
       
  2806         }
       
  2807 
       
  2808     LOGTEXT( _L( "Cae: CCaeEngineImp::SetSkippedExtensionList() returning" ) );
       
  2809     }
       
  2810 
       
  2811 // -----------------------------------------------------------------------------
       
  2812 // CCaeEngineImp::EnableVideoRecording
       
  2813 // Set CAE internal camera status flags.
       
  2814 // -----------------------------------------------------------------------------
       
  2815 //
       
  2816 void CCaeEngineImp::EnableVideoRecording()
       
  2817     {
       
  2818     LOGTEXT( _L( "Cae: CCaeEngineImp::EnableVideoRecording() entering" ) );
       
  2819 
       
  2820     // Set the flags to enable the video usage without InitL() call
       
  2821     iReserved = ETrue;
       
  2822     iPowerOn = ETrue;
       
  2823 
       
  2824     LOGTEXT( _L( "Cae: CCaeEngineImp::EnableVideoRecording() returning" ) );
       
  2825     }
       
  2826 
       
  2827 
       
  2828 // -----------------------------------------------------------------------------
       
  2829 // CCaeEngineImp::DisableVideoRecording
       
  2830 // Set CAE internal camera status flags.
       
  2831 // -----------------------------------------------------------------------------
       
  2832 //
       
  2833 void CCaeEngineImp::DisableVideoRecording()
       
  2834     {
       
  2835     LOGTEXT( _L( "Cae: CCaeEngineImp::DisableVideoRecording() entering" ) );
       
  2836 
       
  2837     if ( iReserved ) 
       
  2838         {
       
  2839         if ( iPowerOn ) 
       
  2840             {
       
  2841             CancelAllActivities();
       
  2842             iPowerOn = EFalse;
       
  2843             }
       
  2844         iReserved = EFalse;
       
  2845         iStillPrepared = EFalse;
       
  2846         iVideoPrepared = EFalse;
       
  2847         iVideoOpened = EFalse;
       
  2848         }
       
  2849 
       
  2850     LOGTEXT( _L( "Cae: CCaeEngineImp::DisableVideoRecording() returning" ) );
       
  2851     }
       
  2852 
       
  2853 // -----------------------------------------------------------------------------
       
  2854 // CCaeEngineImp::HandleEvent
       
  2855 // MCameraObserver2 call-back handler
       
  2856 // -----------------------------------------------------------------------------
       
  2857 //
       
  2858 void CCaeEngineImp::HandleEvent( const TECAMEvent& aEvent)
       
  2859     {
       
  2860     LOGTEXT3( _L( "Cae: CCaeEngineImp::HandleEvent() entering, type=%x, err=%d" ), aEvent.iEventType.iUid, aEvent.iErrorCode );
       
  2861 
       
  2862     if ( iStillStatesActive->ExtModeActive() )
       
  2863         {
       
  2864         LOGTEXT( _L( "Cae: CCaeEngineImp::HandleEvent() Extension mode active, skipping event handling" ) );
       
  2865         }
       
  2866     else
       
  2867         {
       
  2868         // Cae is in use when capturing images
       
  2869         if ( aEvent.iEventType == KUidECamEventCameraNoLongerReserved )
       
  2870             {
       
  2871             LOGTEXT( _L( "Cae: CCaeEngineImp::HandleEvent() KUidECamEventCameraNoLongerReserved" ) );
       
  2872             CancelAllActivities();
       
  2873             iPowerOn = EFalse;
       
  2874             iReserved = EFalse;
       
  2875             iStillPrepared = EFalse;
       
  2876             iVideoPrepared = EFalse;
       
  2877             iVideoOpened = EFalse;
       
  2878             iCaeObserver->McaeoInitComplete( KErrInUse ); // Tell the client that other application has taken the camera
       
  2879             }
       
  2880         else if ( aEvent.iEventType == KUidECamEventPowerOnComplete )
       
  2881     	    {
       
  2882             LOGTEXT( _L( "Cae: CCaeEngineImp::HandleEvent() KUidECamEventPowerOnComplete" ) );
       
  2883             PowerOnComplete( aEvent.iErrorCode );
       
  2884 	        }
       
  2885     	else if ( aEvent.iEventType == KUidECamEventReserveComplete )
       
  2886     	    {
       
  2887             LOGTEXT( _L( "Cae: CCaeEngineImp::HandleEvent() KUidECamEventReserveComplete" ) );
       
  2888             ReserveComplete( aEvent.iErrorCode );
       
  2889     	    }
       
  2890         }
       
  2891 
       
  2892     LOGTEXT( _L( "Cae: CCaeEngineImp::HandleEvent() returning" ) );
       
  2893     }
       
  2894 
       
  2895 // -----------------------------------------------------------------------------
       
  2896 // CCaeEngineImp::ViewFinderReady
       
  2897 // MCameraObserver2 call-back handler
       
  2898 // -----------------------------------------------------------------------------
       
  2899 //
       
  2900 void CCaeEngineImp::ViewFinderReady( MCameraBuffer& aCameraBuffer, TInt aError)
       
  2901     {
       
  2902     LOGTEXT3( _L( "Cae: CCaeEngineImp::ViewFinderReady() entering, err=%d, NumFrames=%d" ), aError, aCameraBuffer.NumFrames() );
       
  2903 
       
  2904     if ( !aError )
       
  2905         {
       
  2906         if ( aCameraBuffer.NumFrames() > 0 )
       
  2907 	        {
       
  2908             CFbsBitmap* bitmap = NULL;
       
  2909 	        TRAPD( err, bitmap = &aCameraBuffer.BitmapL( 0 ) );
       
  2910 	        if ( !err )
       
  2911 	            {
       
  2912 	            ViewFinderFrameReady( *bitmap );
       
  2913 	            }
       
  2914 	        else
       
  2915 	            {
       
  2916                 LOGTEXT2( _L( "Cae: CCaeEngineImp::ViewFinderReady() BitmapL failed err=%d" ), err );
       
  2917 	            }
       
  2918 	        }
       
  2919 	    aCameraBuffer.Release();
       
  2920         }
       
  2921     }
       
  2922 
       
  2923 // -----------------------------------------------------------------------------
       
  2924 // CCaeEngineImp::ImageBufferReady
       
  2925 // MCameraObserver2 call-back handler
       
  2926 // -----------------------------------------------------------------------------
       
  2927 //
       
  2928 void CCaeEngineImp::ImageBufferReady( MCameraBuffer& aCameraBuffer, TInt aError)
       
  2929     {
       
  2930     LOGTEXT3( _L( "Cae: CCaeEngineImp::ImageBufferReady() entering, err=%d, NumFrames=%d" ), aError, aCameraBuffer.NumFrames() );
       
  2931 	
       
  2932     if ( !aError )
       
  2933         {
       
  2934         TDesC8* data = NULL;
       
  2935         TRAPD( err, data = aCameraBuffer.DataL( 0 ) );
       
  2936         if ( err == KErrNotSupported )
       
  2937             {
       
  2938             // Got the image as a CFbsBitmap
       
  2939             CFbsBitmap* bitmap = NULL;
       
  2940 
       
  2941             TRAP( err, bitmap = &aCameraBuffer.BitmapL( 0 ) );
       
  2942 
       
  2943             if ( !err )
       
  2944                 {
       
  2945                 // Create a duplicate bitmap
       
  2946                 CFbsBitmap* bitmapSave = NULL;
       
  2947                 bitmapSave = new CFbsBitmap;
       
  2948                 if ( bitmapSave )
       
  2949                     {
       
  2950                     err = bitmapSave->Duplicate( bitmap->Handle() );
       
  2951                     if ( !err ) 
       
  2952                         {
       
  2953                         // All OK, send duplicated bitmap to old observer interface
       
  2954                         ImageReady( bitmapSave, NULL, aError );
       
  2955                         }
       
  2956                     else
       
  2957                         {
       
  2958                         LOGTEXT2( _L( "Cae: CCaeEngineImp::ImageBufferReady(): Duplicate error:%d" ), err);
       
  2959                         delete bitmapSave;
       
  2960                         bitmapSave = NULL;
       
  2961                         ImageReady( NULL, NULL, err );
       
  2962                         }
       
  2963                     }
       
  2964                 else
       
  2965                     {
       
  2966                     LOGTEXT( _L( "Cae: CCaeEngineImp::ImageBufferReady(): new CFbsBitmap failed" ));
       
  2967                     ImageReady( NULL, NULL, KErrNoMemory );
       
  2968                     }
       
  2969 
       
  2970                 }
       
  2971             else
       
  2972                 {
       
  2973                 LOGTEXT( _L( "Cae: CCaeEngineImp::ImageBufferReady(): BitmapL failed" ));
       
  2974                 ImageReady( NULL, NULL, err );
       
  2975                 }
       
  2976             }
       
  2977         else if ( !err )
       
  2978             {
       
  2979             // Got the image as a descriptor
       
  2980             // Make a new HBufC8 copy from the TDesC8
       
  2981             HBufC8* tempImageData = NULL;
       
  2982             tempImageData = data->Alloc();
       
  2983             
       
  2984             if ( tempImageData )
       
  2985                 {
       
  2986                 // All OK, send buffer to old observer interface
       
  2987                 LOGTEXT2( _L( "Cae: CCaeEngineImp::ImageBufferReady() New HBufC8 created, size=%d" ), tempImageData->Size() );
       
  2988                 ImageReady( NULL, tempImageData, aError );
       
  2989                 }
       
  2990             else
       
  2991                 {
       
  2992                 LOGTEXT( _L( "Cae: CCaeEngineImp::ImageBufferReady() Alloc of HBufC8 failed" ) );
       
  2993                 ImageReady( NULL, NULL, KErrNoMemory );
       
  2994                 }
       
  2995             
       
  2996             
       
  2997             }
       
  2998         else
       
  2999             {
       
  3000             LOGTEXT2( _L( "Cae: CCaeEngineImp::ImageBufferReady() DataL returned error code=%d" ), err );
       
  3001             ImageReady( NULL, NULL, err );
       
  3002             }
       
  3003 
       
  3004         // Release buffer only when no error
       
  3005 	    aCameraBuffer.Release();
       
  3006         }
       
  3007     else
       
  3008         {
       
  3009         ImageReady( NULL, NULL, aError );
       
  3010         }
       
  3011     }
       
  3012     
       
  3013 // -----------------------------------------------------------------------------
       
  3014 // CCaeEngineImp::VideoBufferReady
       
  3015 // MCameraObserver2 call-back handler
       
  3016 // -----------------------------------------------------------------------------
       
  3017 //
       
  3018 void CCaeEngineImp::VideoBufferReady( MCameraBuffer& aCameraBuffer, TInt aError)
       
  3019     {
       
  3020     LOGTEXT2( _L( "Cae: CCaeEngineImp::VideoBufferReady() entering, err=%d" ), aError );
       
  3021 	
       
  3022     if ( !aError )
       
  3023         {
       
  3024 	    aCameraBuffer.Release();
       
  3025         }
       
  3026     }
       
  3027 
       
  3028 
       
  3029 //  End of File