camerauis/cameraapp/generic/src/cameracontroller/camcameracontroller.cpp
branchRCL_3
changeset 10 8c55c525d5d7
parent 9 792dfc98fb3b
child 11 d486e5e3cc9a
equal deleted inserted replaced
9:792dfc98fb3b 10:8c55c525d5d7
     1 /*
     1 /*
     2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    53 // Custom interfaces
    53 // Custom interfaces
    54 #include <ECamOrientationCustomInterface2.h>
    54 #include <ECamOrientationCustomInterface2.h>
    55 #include <ECamUIOrientationOverrideCustomAPI.h>
    55 #include <ECamUIOrientationOverrideCustomAPI.h>
    56 
    56 
    57 #include <ecamfacetrackingcustomapi.h>
    57 #include <ecamfacetrackingcustomapi.h>
    58 #include <akntoolbar.h> 
    58 #include <akntoolbar.h>
    59 // -------------------------------------
    59 // -------------------------------------
    60 // Own
    60 // Own
    61 #include "camcameracontroller.pan"
    61 #include "camcameracontroller.pan"
    62 #include "camlogging.h"
    62 #include "camlogging.h"
    63 #include "cambuffershare.h"
    63 #include "cambuffershare.h"
    64 #include "cambuffersharecleanup.h"
    64 #include "cambuffersharecleanup.h"
    65 #include "cambuffercleanup.h"
    65 #include "cambuffercleanup.h"
    66 #include "cambuffer.h"  
    66 #include "cambuffer.h"
    67 
    67 
    68 #include "camsnapshotprovider.h"
    68 #include "camsnapshotprovider.h"
    69 #include "camimageencoder.h"
    69 #include "camimageencoder.h"
    70 
    70 
    71 #include "mcamsettingprovider.h"
    71 #include "mcamsettingprovider.h"
    97 #include "CameraUiConfigManager.h"
    97 #include "CameraUiConfigManager.h"
    98 #include "CamViewBase.h"
    98 #include "CamViewBase.h"
    99 #include "CamPanic.h"
    99 #include "CamPanic.h"
   100 // ===========================================================================
   100 // ===========================================================================
   101 // Local constants
   101 // Local constants
   102 const TInt KIveRecoveryCountMax = 2;  
   102 const TInt KIveRecoveryCountMax = 2;
   103 typedef CCamera::CCameraAdvancedSettings CAS;
   103 typedef CCamera::CCameraAdvancedSettings CAS;
   104 typedef CCamera::CCameraImageProcessing  CIP;
   104 typedef CCamera::CCameraImageProcessing  CIP;
   105 
   105 
   106 namespace NCamCameraController
   106 namespace NCamCameraController
   107   {
   107   {
   108   static const TInt               KPrimaryCameraIndex         =  0;
   108   static const TInt               KPrimaryCameraIndex         =  0;
   109   //static const TInt               KSecondaryCameraIndex       =  1;
   109   //static const TInt               KSecondaryCameraIndex       =  1;
   110   static const TInt               KInvalidCameraIndex         = -1;
   110   static const TInt               KInvalidCameraIndex         = -1;
   111   
   111 
   112   #ifdef CAMERAAPP_CAE_FOR_VIDEO
   112   #ifdef CAMERAAPP_CAE_FOR_VIDEO
   113   //  static const TInt             KCameraDisplayIndex         = 0;
   113   //  static const TInt             KCameraDisplayIndex         = 0;
   114   #endif
   114   #endif
   115   #ifdef CAMERAAPP_CAPI_V2
   115   #ifdef CAMERAAPP_CAPI_V2
   116     static const TInt             KCameraClientPriority       = 100; // -100...100
   116     static const TInt             KCameraClientPriority       = 100; // -100...100
   117   #endif
   117   #endif
   118   
   118 
   119   static const TInt               KCamCallBackPriority        = EPriorityHigh;
   119   static const TInt               KCamCallBackPriority        = EPriorityHigh;
   120   
   120 
   121   static const TInt               KCamSequenceGranularity     =  2;
   121   static const TInt               KCamSequenceGranularity     =  2;
   122   static const TInt               KResolutionArrayGranularity =  8;
   122   static const TInt               KResolutionArrayGranularity =  8;
   123   #ifdef CAMERAAPP_CAPI_V2_ADV
   123   #ifdef CAMERAAPP_CAPI_V2_ADV
   124     static const TInt             KAdvArrayGranularity        =  5;
   124     static const TInt             KAdvArrayGranularity        =  5;
   125   #endif  
   125   #endif
   126   
   126 
   127   static const CCamera::TFormat   KCamJpegAlternativeFormat1  = CCamera::EFormatFbsBitmapColor16M;
   127   static const CCamera::TFormat   KCamJpegAlternativeFormat1  = CCamera::EFormatFbsBitmapColor16M;
   128   static const CCamera::TFormat   KCamJpegAlternativeFormat2  = CCamera::EFormatFbsBitmapColor64K;
   128   static const CCamera::TFormat   KCamJpegAlternativeFormat2  = CCamera::EFormatFbsBitmapColor64K;
   129   
   129 
   130   static const TInt             KCamReserveTryAgainMaxCount     = 50;
   130   static const TInt             KCamReserveTryAgainMaxCount     = 50;
   131   static const TInt             KCamReserveTryAgainWaitInterval = 50000; // 50 milliseconds
   131   static const TInt             KCamReserveTryAgainWaitInterval = 50000; // 50 milliseconds
   132   #ifdef _DEBUG
   132   #ifdef _DEBUG
   133   _LIT( KCamDriveModeNameBurst,   "EDriveModeBurst"      );
   133   _LIT( KCamDriveModeNameBurst,   "EDriveModeBurst"      );
   134   _LIT( KCamDriveModeNameSingle,  "EDriveModeSingleShot" );
   134   _LIT( KCamDriveModeNameSingle,  "EDriveModeSingleShot" );
   151   #define CAMERAAPP_PERF_CONTROLLER_STARTNEW( AAA, BBB )
   151   #define CAMERAAPP_PERF_CONTROLLER_STARTNEW( AAA, BBB )
   152   #define CAMERAAPP_PERF_CONTROLLER_STOP( AAA )
   152   #define CAMERAAPP_PERF_CONTROLLER_STOP( AAA )
   153   #define CAMERAAPP_PERF_CONTROLLER_STOP_ONCE( AAA, BBB )
   153   #define CAMERAAPP_PERF_CONTROLLER_STOP_ONCE( AAA, BBB )
   154 #endif // CAMERAAPP_PERFORMANCE_CONTROLLER
   154 #endif // CAMERAAPP_PERFORMANCE_CONTROLLER
   155 
   155 
   156 // Helper methods 
   156 // Helper methods
   157 #include "camflagutility.inl"
   157 #include "camflagutility.inl"
   158 #include "campointerutility.inl"
   158 #include "campointerutility.inl"
   159 
   159 
   160 
   160 
   161 namespace NCamCameraController
   161 namespace NCamCameraController
   162   {
   162   {
   163   /*
   163   /*
   164   inline void SetFalse( TAny* aTBool )
   164   inline void SetFalse( TAny* aTBool )
   165     {
   165     {
   166     TBool* boolean = static_cast<TBool*>( aTBool );
   166     TBool* boolean = static_cast<TBool*>( aTBool );
   167   
   167 
   168     if( boolean )
   168     if( boolean )
   169       *boolean = EFalse;
   169       *boolean = EFalse;
   170     }
   170     }
   171   */
   171   */
   172   
   172 
   173   inline void SetNotBusy( TAny* aTUint )
   173   inline void SetNotBusy( TAny* aTUint )
   174     {
   174     {
   175     TUint* flags = static_cast<TUint*>( aTUint );
   175     TUint* flags = static_cast<TUint*>( aTUint );
   176   
   176 
   177     if( flags )
   177     if( flags )
   178       *flags = ECamBusyOff;
   178       *flags = ECamBusyOff;
   179     };
   179     };
   180   
   180 
   181   inline void ReleaseAndNull( MCameraBuffer*& aBuffer )
   181   inline void ReleaseAndNull( MCameraBuffer*& aBuffer )
   182     {
   182     {
   183     if( aBuffer )
   183     if( aBuffer )
   184       {
   184       {
   185       aBuffer->Release();
   185       aBuffer->Release();
   187       }
   187       }
   188     };
   188     };
   189 #ifdef CAMERAAPP_CAPI_V2_ADV
   189 #ifdef CAMERAAPP_CAPI_V2_ADV
   190   inline void ResetInfo( TAny* aInfo )
   190   inline void ResetInfo( TAny* aInfo )
   191     {
   191     {
   192     TCamAdvancedSettingInfo* info = 
   192     TCamAdvancedSettingInfo* info =
   193       static_cast<TCamAdvancedSettingInfo*>( aInfo );
   193       static_cast<TCamAdvancedSettingInfo*>( aInfo );
   194 
   194 
   195     if( info )
   195     if( info )
   196       {
   196       {
   197       info->Reset();
   197       info->Reset();
   198       }      
   198       }
   199     };
   199     };
   200 
   200 
   201 
   201 
   202   inline const TDesC& DriveModeName( TInt aMode )
   202   inline const TDesC& DriveModeName( TInt aMode )
   203     {
   203     {
   250   iSnapshotFormat         = CCamera::EFormatFbsBitmapColor16M;
   250   iSnapshotFormat         = CCamera::EFormatFbsBitmapColor16M;
   251   iSnapshotAspectMaintain = EFalse;
   251   iSnapshotAspectMaintain = EFalse;
   252 
   252 
   253   if( !aPreserveBusyFlag )
   253   if( !aPreserveBusyFlag )
   254     {
   254     {
   255     iBusy = ECamBusyOff;  
   255     iBusy = ECamBusyOff;
   256     }
   256     }
   257   }
   257   }
   258 
   258 
   259 // ---------------------------------------------------------------------------
   259 // ---------------------------------------------------------------------------
   260 // PrintInfo
   260 // PrintInfo
   261 // ---------------------------------------------------------------------------
   261 // ---------------------------------------------------------------------------
   262 //
   262 //
   263 void 
   263 void
   264 TCamControllerInfo::PrintInfo() const
   264 TCamControllerInfo::PrintInfo() const
   265   {
   265   {
   266   PRINT ( _L("Camera <> --------------------------------------------------") );
   266   PRINT ( _L("Camera <> --------------------------------------------------") );
   267   PRINT ( _L("Camera <> TCamControllerInfo")                                 );
   267   PRINT ( _L("Camera <> TCamControllerInfo")                                 );
   268   PRINT ( _L("Camera <> ")                                                   );
   268   PRINT ( _L("Camera <> ")                                                   );
   303 TCamCameraResolutionSupport::~TCamCameraResolutionSupport()
   303 TCamCameraResolutionSupport::~TCamCameraResolutionSupport()
   304   {
   304   {
   305   iResolutions.Close();
   305   iResolutions.Close();
   306   }
   306   }
   307 
   307 
   308 void 
   308 void
   309 TCamCameraResolutionSupport::Reset()
   309 TCamCameraResolutionSupport::Reset()
   310   {
   310   {
   311   iForCameraIndex  = KInvalidCameraIndex;
   311   iForCameraIndex  = KInvalidCameraIndex;
   312   iForCameraFormat = -1;
   312   iForCameraFormat = -1;
   313   iResolutions.Reset();
   313   iResolutions.Reset();
   328   {
   328   {
   329   iEvStepsSupport.Close();
   329   iEvStepsSupport.Close();
   330   iIsoRatesSupport.Close();
   330   iIsoRatesSupport.Close();
   331   }
   331   }
   332 
   332 
   333 void 
   333 void
   334 TCamAdvancedSettingInfo::Reset()
   334 TCamAdvancedSettingInfo::Reset()
   335   {
   335   {
   336   iForCameraIndex = KInvalidCameraIndex;
   336   iForCameraIndex = KInvalidCameraIndex;
   337 
   337 
   338   iEvModesSupport = 0;
   338   iEvModesSupport = 0;
   359 
   359 
   360 // ---------------------------------------------------------------------------
   360 // ---------------------------------------------------------------------------
   361 // PrintInfo
   361 // PrintInfo
   362 // ---------------------------------------------------------------------------
   362 // ---------------------------------------------------------------------------
   363 //
   363 //
   364 void 
   364 void
   365 TCamAdvancedSettingInfo::PrintInfo() const
   365 TCamAdvancedSettingInfo::PrintInfo() const
   366   {
   366   {
   367 #ifdef _DEBUG
   367 #ifdef _DEBUG
   368   PRINT ( _L("Camera <> --------------------------------------------------") );
   368   PRINT ( _L("Camera <> --------------------------------------------------") );
   369   PRINT ( _L("Camera <> Value infos:")                                       );
   369   PRINT ( _L("Camera <> Value infos:")                                       );
   396   for( TInt i = 0; i < iEvStepsSupport.Count(); i++ )
   396   for( TInt i = 0; i < iEvStepsSupport.Count(); i++ )
   397     {
   397     {
   398     PRINT2( _L("Camera <> step[%3d]: %4d"), i, iEvStepsSupport[i] );
   398     PRINT2( _L("Camera <> step[%3d]: %4d"), i, iEvStepsSupport[i] );
   399     }
   399     }
   400 
   400 
   401   PRINT ( _L("Camera <> --------------------------------------------------") );    
   401   PRINT ( _L("Camera <> --------------------------------------------------") );
   402   PRINT1( _L("Camera <> Advanced EV modes support : %016b"), iEvModesSupport                    );
   402   PRINT1( _L("Camera <> Advanced EV modes support : %016b"), iEvModesSupport                    );
   403   PRINT1( _L("Camera <> EExposureAuto             : %016b"), CCamera::EExposureAuto             );
   403   PRINT1( _L("Camera <> EExposureAuto             : %016b"), CCamera::EExposureAuto             );
   404   PRINT1( _L("Camera <> EExposureNight            : %016b"), CCamera::EExposureNight            );
   404   PRINT1( _L("Camera <> EExposureNight            : %016b"), CCamera::EExposureNight            );
   405   PRINT1( _L("Camera <> EExposureBacklight        : %016b"), CCamera::EExposureBacklight        );
   405   PRINT1( _L("Camera <> EExposureBacklight        : %016b"), CCamera::EExposureBacklight        );
   406   PRINT1( _L("Camera <> EExposureCenter           : %016b"), CCamera::EExposureCenter           );
   406   PRINT1( _L("Camera <> EExposureCenter           : %016b"), CCamera::EExposureCenter           );
   438   PRINT1( _L("Camera <> EEffectVivid          : %016b"), CIP::EEffectVivid           );
   438   PRINT1( _L("Camera <> EEffectVivid          : %016b"), CIP::EEffectVivid           );
   439   PRINT1( _L("Camera <> EEffectLowSharpening  : %016b"), CIP::EEffectLowSharpening   );
   439   PRINT1( _L("Camera <> EEffectLowSharpening  : %016b"), CIP::EEffectLowSharpening   );
   440   PRINT ( _L("Camera <> --------------------------------------------------") );
   440   PRINT ( _L("Camera <> --------------------------------------------------") );
   441 #endif // CAMERAAPP_CAPI_V2_IP
   441 #endif // CAMERAAPP_CAPI_V2_IP
   442 
   442 
   443   PRINT ( _L("Camera <> --------------------------------------------------") );    
   443   PRINT ( _L("Camera <> --------------------------------------------------") );
   444   PRINT1( _L("Camera <> Stabilization modes support      : %016b"), iStabilizationModeSupport           );
   444   PRINT1( _L("Camera <> Stabilization modes support      : %016b"), iStabilizationModeSupport           );
   445   PRINT1( _L("Camera <>   EStabilizationModeOff          : %016b"), CAS::EStabilizationModeOff          );
   445   PRINT1( _L("Camera <>   EStabilizationModeOff          : %016b"), CAS::EStabilizationModeOff          );
   446   PRINT1( _L("Camera <>   EStabilizationModeHorizontal   : %016b"), CAS::EStabilizationModeHorizontal   );
   446   PRINT1( _L("Camera <>   EStabilizationModeHorizontal   : %016b"), CAS::EStabilizationModeHorizontal   );
   447   PRINT1( _L("Camera <>   EStabilizationModeVertical     : %016b"), CAS::EStabilizationModeVertical     );
   447   PRINT1( _L("Camera <>   EStabilizationModeVertical     : %016b"), CAS::EStabilizationModeVertical     );
   448   PRINT1( _L("Camera <>   EStabilizationModeRotation     : %016b"), CAS::EStabilizationModeRotation     );
   448   PRINT1( _L("Camera <>   EStabilizationModeRotation     : %016b"), CAS::EStabilizationModeRotation     );
   457   PRINT1( _L("Camera <> Stabilization complexity support : %016b"), iStabilizationComplexitySupport     );
   457   PRINT1( _L("Camera <> Stabilization complexity support : %016b"), iStabilizationComplexitySupport     );
   458   PRINT1( _L("Camera <>   EStabilizationComplexityAuto   : %016b"), CAS::EStabilizationComplexityAuto   );
   458   PRINT1( _L("Camera <>   EStabilizationComplexityAuto   : %016b"), CAS::EStabilizationComplexityAuto   );
   459   PRINT1( _L("Camera <>   EStabilizationComplexityLow    : %016b"), CAS::EStabilizationComplexityLow    );
   459   PRINT1( _L("Camera <>   EStabilizationComplexityLow    : %016b"), CAS::EStabilizationComplexityLow    );
   460   PRINT1( _L("Camera <>   EStabilizationComplexityMedium : %016b"), CAS::EStabilizationComplexityMedium );
   460   PRINT1( _L("Camera <>   EStabilizationComplexityMedium : %016b"), CAS::EStabilizationComplexityMedium );
   461   PRINT1( _L("Camera <>   EStabilizationComplexityHigh   : %016b"), CAS::EStabilizationComplexityHigh   );
   461   PRINT1( _L("Camera <>   EStabilizationComplexityHigh   : %016b"), CAS::EStabilizationComplexityHigh   );
   462   PRINT ( _L("Camera <> --------------------------------------------------") );    
   462   PRINT ( _L("Camera <> --------------------------------------------------") );
   463 #endif // _DEBUG
   463 #endif // _DEBUG
   464   }
   464   }
   465 
   465 
   466 #endif // CAMERAAPP_CAPI_V2_ADV
   466 #endif // CAMERAAPP_CAPI_V2_ADV
   467 
   467 
   472 // ---------------------------------------------------------------------------
   472 // ---------------------------------------------------------------------------
   473 // static 2-phase constructor
   473 // static 2-phase constructor
   474 // ---------------------------------------------------------------------------
   474 // ---------------------------------------------------------------------------
   475 //
   475 //
   476 CCamCameraController*
   476 CCamCameraController*
   477 CCamCameraController::NewL( MCamSettingProvider& aProvider, 
   477 CCamCameraController::NewL( MCamSettingProvider& aProvider,
   478                             CCamAppController& aAppController, 
   478                             CCamAppController& aAppController,
   479                             TInt aCameraIndex /*= 0*/ )  
   479                             TInt aCameraIndex /*= 0*/ )
   480   {
   480   {
   481   CCamCameraController* self 
   481   CCamCameraController* self
   482       = new (ELeave) CCamCameraController( aProvider, aAppController );  
   482       = new (ELeave) CCamCameraController( aProvider, aAppController );
   483 
   483 
   484   CleanupStack::PushL( self );
   484   CleanupStack::PushL( self );
   485   self->ConstructL( aCameraIndex );
   485   self->ConstructL( aCameraIndex );
   486   CleanupStack::Pop( self );
   486   CleanupStack::Pop( self );
   487 
   487 
   488   return self;
   488   return self;
   489   }
   489   }
   490     
   490 
   491 
   491 
   492 
   492 
   493 // ---------------------------------------------------------------------------
   493 // ---------------------------------------------------------------------------
   494 //
   494 //
   495 // ---------------------------------------------------------------------------
   495 // ---------------------------------------------------------------------------
   498   {
   498   {
   499   PRINT( _L("Camera => ~CCamCameraController") );
   499   PRINT( _L("Camera => ~CCamCameraController") );
   500 
   500 
   501 #ifdef CAMERAAPP_FLASH_SIMULATOR
   501 #ifdef CAMERAAPP_FLASH_SIMULATOR
   502   delete iFlashSimulator;
   502   delete iFlashSimulator;
   503 #endif 
   503 #endif
   504 
   504 
   505 #ifdef CAMERAAPP_PERFORMANCE_CONTROLLER
   505 #ifdef CAMERAAPP_PERFORMANCE_CONTROLLER
   506   delete iPerformanceLogger;
   506   delete iPerformanceLogger;
   507 #endif // CAMERAAPP_PERFORMANCE_CONTROLLER
   507 #endif // CAMERAAPP_PERFORMANCE_CONTROLLER
   508   
   508 
   509   delete iIdle; 
   509   delete iIdle;
   510   iSettingArray.Close();
   510   iSettingArray.Close();
   511 
   511 
   512   // Remove all observers.
   512   // Remove all observers.
   513   // We do not want to broadcast events anymore in this phase.
   513   // We do not want to broadcast events anymore in this phase.
   514   iObservers.Reset();
   514   iObservers.Reset();
   516 
   516 
   517   ClearRequestQueue();
   517   ClearRequestQueue();
   518   ClearSettingQueue();
   518   ClearSettingQueue();
   519 
   519 
   520 
   520 
   521   PRINT( _L("Camera <> CCamCameraController: release current camera..") );  
   521   PRINT( _L("Camera <> CCamCameraController: release current camera..") );
   522   // Release and null CCamera related objects.
   522   // Release and null CCamera related objects.
   523   ReleaseCurrentCamera();
   523   ReleaseCurrentCamera();
   524   PRINT( _L("Camera <> CCamCameraController: ..done") );  
   524   PRINT( _L("Camera <> CCamCameraController: ..done") );
   525 
   525 
   526   delete iActive;
   526   delete iActive;
   527 
   527 
   528   iObservers.Close();
   528   iObservers.Close();
   529   iObserverInterests.Close();
   529   iObserverInterests.Close();
   545 
   545 
   546 // ---------------------------------------------------------------------------
   546 // ---------------------------------------------------------------------------
   547 // HandleEvent
   547 // HandleEvent
   548 // ---------------------------------------------------------------------------
   548 // ---------------------------------------------------------------------------
   549 //
   549 //
   550 void 
   550 void
   551 CCamCameraController::HandleEvent( const TECAMEvent& aEvent )
   551 CCamCameraController::HandleEvent( const TECAMEvent& aEvent )
   552   {
   552   {
   553   // TUid iEventType;
   553   // TUid iEventType;
   554   // TInt iErrorCode;
   554   // TInt iErrorCode;
   555   PRINT2( _L("Camera => CCamCameraController::HandleEvent, event uid(0x%08x) error(%d)"), 
   555   PRINT2( _L("Camera => CCamCameraController::HandleEvent, event uid(0x%08x) error(%d)"),
   556           aEvent.iEventType.iUid, 
   556           aEvent.iEventType.iUid,
   557           aEvent.iErrorCode );
   557           aEvent.iErrorCode );
   558 
   558 
   559   // If we are getting zoom event while saving video,
   559   // If we are getting zoom event while saving video,
   560   // we must not handle the event 
   560   // we must not handle the event
   561   TInt uidValue( aEvent.iEventType.iUid );
   561   TInt uidValue( aEvent.iEventType.iUid );
   562   if ( uidValue == KUidECamEventCameraSettingDigitalZoomUidValue 
   562   if ( uidValue == KUidECamEventCameraSettingDigitalZoomUidValue
   563     && IsFlagOn( iInfo.iBusy, ECamBusySingle ) )
   563     && IsFlagOn( iInfo.iBusy, ECamBusySingle ) )
   564       {
   564       {
   565        return;
   565        return;
   566       }
   566       }
   567 
   567 
   582     {
   582     {
   583     HandleReserveLostEvent( aEvent.iErrorCode );
   583     HandleReserveLostEvent( aEvent.iErrorCode );
   584     }
   584     }
   585   // -------------------------------------------------------
   585   // -------------------------------------------------------
   586   else if( !(IsFlagOn( iInfo.iState , ECamPowerOn )))
   586   else if( !(IsFlagOn( iInfo.iState , ECamPowerOn )))
   587     {    
   587     {
   588     //If camera is in background then all the rest events will be ignored. Should return without leaving
   588     //If camera is in background then all the rest events will be ignored. Should return without leaving
   589     return;   	
   589     return;
   590     }   
   590     }
   591   // -------------------------------------------------------
   591   // -------------------------------------------------------
   592   else if( aEvent.iEventType == KUidECamEventCameraSnapshot )
   592   else if( aEvent.iEventType == KUidECamEventCameraSnapshot )
   593     {
   593     {
   594     HandleSnapshotEvent( aEvent.iErrorCode );
   594     HandleSnapshotEvent( aEvent.iErrorCode );
   595     }
   595     }
   596   // -------------------------------------------------------
   596   // -------------------------------------------------------
   597   else if( aEvent.iEventType == KUidECamEventCameraSettingsOptimalFocus 
   597   else if( aEvent.iEventType == KUidECamEventCameraSettingsOptimalFocus
   598         || aEvent.iEventType == KUidECamEventCameraSettingAutoFocusType2 )
   598         || aEvent.iEventType == KUidECamEventCameraSettingAutoFocusType2 )
   599     {
   599     {
   600     HandleAutoFocusEvent( aEvent.iErrorCode, aEvent.iEventType );
   600     HandleAutoFocusEvent( aEvent.iErrorCode, aEvent.iEventType );
   601     }  
   601     }
   602   // -------------------------------------------------------   
   602   // -------------------------------------------------------
   603   else
   603   else
   604     {
   604     {
   605 #ifdef CAMERAAPP_CAPI_V2_ADV
   605 #ifdef CAMERAAPP_CAPI_V2_ADV
   606     TInt uidValue( aEvent.iEventType.iUid );
   606     TInt uidValue( aEvent.iEventType.iUid );
   607     switch( uidValue )
   607     switch( uidValue )
   620       case KUidECamEventCameraSettingOpticalZoomUidValue:
   620       case KUidECamEventCameraSettingOpticalZoomUidValue:
   621       case KUidECamEventImageProcessingAdjustSharpnessUidValue:
   621       case KUidECamEventImageProcessingAdjustSharpnessUidValue:
   622       case KUidECamEventImageProcessingEffectUidValue:
   622       case KUidECamEventImageProcessingEffectUidValue:
   623       case KUidECamEventSettingsStabilizationAlgorithmComplexityUidValue:
   623       case KUidECamEventSettingsStabilizationAlgorithmComplexityUidValue:
   624         {
   624         {
   625         TCamCameraSettingId id = 
   625         TCamCameraSettingId id =
   626             CCamSettingConversion::Map2CameraSetting( uidValue );
   626             CCamSettingConversion::Map2CameraSetting( uidValue );
   627 
   627 
   628         HandleCallbackEvent( aEvent.iErrorCode, 
   628         HandleCallbackEvent( aEvent.iErrorCode,
   629                              ECamCameraEventSettingsSingle, 
   629                              ECamCameraEventSettingsSingle,
   630                              ECamCameraEventClassSettings, 
   630                              ECamCameraEventClassSettings,
   631                              &id );
   631                              &id );
   632         break;
   632         break;
   633         }
   633         }
   634       // -------------------------------
   634       // -------------------------------
   635       // Flash status info
   635       // Flash status info
   638         break;
   638         break;
   639       case KUidECamEventFlashNotReadyUidValue:
   639       case KUidECamEventFlashNotReadyUidValue:
   640         HandleFlashStatusEvent( aEvent.iErrorCode, ECamCameraEventFlashNotReady );
   640         HandleFlashStatusEvent( aEvent.iErrorCode, ECamCameraEventFlashNotReady );
   641         break;
   641         break;
   642       // -------------------------------
   642       // -------------------------------
   643       default: 
   643       default:
   644         break;
   644         break;
   645       // -------------------------------
   645       // -------------------------------
   646       }
   646       }
   647 #endif // CAMERAAPP_CAPI_V2_ADV
   647 #endif // CAMERAAPP_CAPI_V2_ADV
   648     }
   648     }
   669 
   669 
   670 // ---------------------------------------------------------------------------
   670 // ---------------------------------------------------------------------------
   671 // ViewFinderReady
   671 // ViewFinderReady
   672 // ---------------------------------------------------------------------------
   672 // ---------------------------------------------------------------------------
   673 //
   673 //
   674 void 
   674 void
   675 CCamCameraController::ViewFinderReady( MCameraBuffer& aCameraBuffer, TInt aError )
   675 CCamCameraController::ViewFinderReady( MCameraBuffer& aCameraBuffer, TInt aError )
   676   {
   676   {
   677   HandleViewfinderEvent( &aCameraBuffer, aError );
   677   HandleViewfinderEvent( &aCameraBuffer, aError );
   678   }
   678   }
   679 
   679 
   680 
   680 
   681 // ---------------------------------------------------------------------------
   681 // ---------------------------------------------------------------------------
   682 // ImageBufferReady
   682 // ImageBufferReady
   683 // ---------------------------------------------------------------------------
   683 // ---------------------------------------------------------------------------
   684 //
   684 //
   685 void 
   685 void
   686 CCamCameraController::ImageBufferReady( MCameraBuffer& aCameraBuffer, TInt aError )
   686 CCamCameraController::ImageBufferReady( MCameraBuffer& aCameraBuffer, TInt aError )
   687   {
   687   {
   688   HandleImageCaptureEvent( &aCameraBuffer, aError );
   688   HandleImageCaptureEvent( &aCameraBuffer, aError );
   689   }
   689   }
   690 
   690 
   691 
   691 
   692 // ---------------------------------------------------------------------------
   692 // ---------------------------------------------------------------------------
   693 // VideoBufferReady
   693 // VideoBufferReady
   694 // ---------------------------------------------------------------------------
   694 // ---------------------------------------------------------------------------
   695 //
   695 //
   696 void 
   696 void
   697 CCamCameraController::VideoBufferReady( MCameraBuffer& aCameraBuffer, TInt aError )
   697 CCamCameraController::VideoBufferReady( MCameraBuffer& aCameraBuffer, TInt aError )
   698   {
   698   {
   699   if( KErrNone == aError )
   699   if( KErrNone == aError )
   700     {
   700     {
   701     aCameraBuffer.Release();
   701     aCameraBuffer.Release();
   711 
   711 
   712 // ---------------------------------------------------------------------------
   712 // ---------------------------------------------------------------------------
   713 // ReserveComplete
   713 // ReserveComplete
   714 // ---------------------------------------------------------------------------
   714 // ---------------------------------------------------------------------------
   715 //
   715 //
   716 void 
   716 void
   717 CCamCameraController::ReserveComplete( TInt aError ) 
   717 CCamCameraController::ReserveComplete( TInt aError )
   718   {
   718   {
   719   HandleReserveGainEvent( aError );
   719   HandleReserveGainEvent( aError );
   720   }
   720   }
   721 
   721 
   722 
   722 
   723 // ---------------------------------------------------------------------------
   723 // ---------------------------------------------------------------------------
   724 // PowerOnComplete
   724 // PowerOnComplete
   725 // ---------------------------------------------------------------------------
   725 // ---------------------------------------------------------------------------
   726 //
   726 //
   727 void 
   727 void
   728 CCamCameraController::PowerOnComplete( TInt aError )
   728 CCamCameraController::PowerOnComplete( TInt aError )
   729   {
   729   {
   730   HandlePowerOnEvent( aError );
   730   HandlePowerOnEvent( aError );
   731   }
   731   }
   732 
   732 
   733 
   733 
   734 // ---------------------------------------------------------------------------
   734 // ---------------------------------------------------------------------------
   735 // ViewFinderFrameReady
   735 // ViewFinderFrameReady
   736 // ---------------------------------------------------------------------------
   736 // ---------------------------------------------------------------------------
   737 //
   737 //
   738 void 
   738 void
   739 CCamCameraController::ViewFinderFrameReady( CFbsBitmap& aFrame )
   739 CCamCameraController::ViewFinderFrameReady( CFbsBitmap& aFrame )
   740   {
   740   {
   741   PRINT( _L("CamTest => CCamCameraController::ViewFinderFrameReady") );
   741   PRINT( _L("CamTest => CCamCameraController::ViewFinderFrameReady") );
   742 
   742 
   743   CCamBuffer* buffer = NULL;
   743   CCamBuffer* buffer = NULL;
   744   
   744 
   745   TRAPD( error, buffer = CCamBuffer::NewL( aFrame, NULL ) );
   745   TRAPD( error, buffer = CCamBuffer::NewL( aFrame, NULL ) );
   746 
   746 
   747   // Releases buffer
   747   // Releases buffer
   748   HandleViewfinderEvent( buffer, error );
   748   HandleViewfinderEvent( buffer, error );
   749  
   749 
   750   PRINT( _L("CamTest <= CCamCameraController::ViewFinderFrameReady") );
   750   PRINT( _L("CamTest <= CCamCameraController::ViewFinderFrameReady") );
   751   }
   751   }
   752 
   752 
   753 
   753 
   754 // ---------------------------------------------------------------------------
   754 // ---------------------------------------------------------------------------
   755 // ImageReady
   755 // ImageReady
   756 // ---------------------------------------------------------------------------
   756 // ---------------------------------------------------------------------------
   757 //
   757 //
   758 void 
   758 void
   759 CCamCameraController::ImageReady( CFbsBitmap* aBitmap, 
   759 CCamCameraController::ImageReady( CFbsBitmap* aBitmap,
   760                                   HBufC8*    aData,
   760                                   HBufC8*    aData,
   761                                   TInt       aError )
   761                                   TInt       aError )
   762   {
   762   {
   763   PRINT( _L("Camera => CCamCameraController::ImageReady") );
   763   PRINT( _L("Camera => CCamCameraController::ImageReady") );
   764 
   764 
   765   CCamBuffer* buffer = NULL;
   765   CCamBuffer* buffer = NULL;
   766  
   766 
   767   // If no error so far, wrap the data to MCameraBuffer compatible wrapper.
   767   // If no error so far, wrap the data to MCameraBuffer compatible wrapper.
   768   // New API provides these buffers already from CCamera callbacks.
   768   // New API provides these buffers already from CCamera callbacks.
   769   if( KErrNone == aError )
   769   if( KErrNone == aError )
   770     {
   770     {
   771     TRAP( aError,
   771     TRAP( aError,
   792 
   792 
   793 // ---------------------------------------------------------------------------
   793 // ---------------------------------------------------------------------------
   794 // FrameBufferReady
   794 // FrameBufferReady
   795 // ---------------------------------------------------------------------------
   795 // ---------------------------------------------------------------------------
   796 //
   796 //
   797 void 
   797 void
   798 CCamCameraController::FrameBufferReady( MFrameBuffer* aFrameBuffer, 
   798 CCamCameraController::FrameBufferReady( MFrameBuffer* aFrameBuffer,
   799                                         TInt          /*aError*/ )
   799                                         TInt          /*aError*/ )
   800   {
   800   {
   801   // Release the buffer if one is provided to make sure
   801   // Release the buffer if one is provided to make sure
   802   // CCamera can reuse it.
   802   // CCamera can reuse it.
   803   if( aFrameBuffer )
   803   if( aFrameBuffer )
   814 
   814 
   815 // ---------------------------------------------------------------------------
   815 // ---------------------------------------------------------------------------
   816 // McaeoInitComplete
   816 // McaeoInitComplete
   817 // ---------------------------------------------------------------------------
   817 // ---------------------------------------------------------------------------
   818 //
   818 //
   819 void 
   819 void
   820 CCamCameraController::McaeoInitComplete( TInt aError )
   820 CCamCameraController::McaeoInitComplete( TInt aError )
   821   {
   821   {
   822   PRINT( _L("Camera => CCamCameraController::McaeoInitComplete") );
   822   PRINT( _L("Camera => CCamCameraController::McaeoInitComplete") );
   823   // Only interested on this callback, if CCamera duplicate
   823   // Only interested on this callback, if CCamera duplicate
   824   // cannot be used with CAE. Otherwise we follow this event through
   824   // cannot be used with CAE. Otherwise we follow this event through
   831 
   831 
   832 // ---------------------------------------------------------------------------
   832 // ---------------------------------------------------------------------------
   833 // McaeoStillPrepareComplete
   833 // McaeoStillPrepareComplete
   834 // ---------------------------------------------------------------------------
   834 // ---------------------------------------------------------------------------
   835 //
   835 //
   836 void 
   836 void
   837 CCamCameraController::McaeoStillPrepareComplete( TInt /*aError*/ )
   837 CCamCameraController::McaeoStillPrepareComplete( TInt /*aError*/ )
   838   {
   838   {
   839   PRINT( _L("Camera =><= CCamCameraController::McaeoStillPrepareComplete, PANIC!") );
   839   PRINT( _L("Camera =><= CCamCameraController::McaeoStillPrepareComplete, PANIC!") );
   840   // Still capture not done through CCaeEngine.
   840   // Still capture not done through CCaeEngine.
   841   __ASSERT_DEBUG( EFalse, Panic( ECamCameraControllerCaeUnsupported ) );
   841   __ASSERT_DEBUG( EFalse, Panic( ECamCameraControllerCaeUnsupported ) );
   842   }
   842   }
   843 
   843 
   844 // ---------------------------------------------------------------------------
   844 // ---------------------------------------------------------------------------
   845 // McaeoVideoPrepareComplete
   845 // McaeoVideoPrepareComplete
   846 // 
   846 //
   847 // This method is called asynchronously after a call has been made to
   847 // This method is called asynchronously after a call has been made to
   848 // CCaeEngine::PrepareVideoRecordingL.
   848 // CCaeEngine::PrepareVideoRecordingL.
   849 // ---------------------------------------------------------------------------
   849 // ---------------------------------------------------------------------------
   850 //
   850 //
   851 void 
   851 void
   852 CCamCameraController::McaeoVideoPrepareComplete( TInt aError )
   852 CCamCameraController::McaeoVideoPrepareComplete( TInt aError )
   853   {
   853   {
   854   PRINT( _L("Camera => CCamCameraController::McaeoVideoPrepareComplete") );
   854   PRINT( _L("Camera => CCamCameraController::McaeoVideoPrepareComplete") );
   855 #ifdef CAMERAAPP_CAE_ERR_SIMULATION  
   855 #ifdef CAMERAAPP_CAE_ERR_SIMULATION
   856   HandleVideoEvent( ECamCameraEventVideoInit, aError );
   856   HandleVideoEvent( ECamCameraEventVideoInit, aError );
   857   // DelayCallback( ECamCameraEventVideoInit, aError, 500000 );
   857   // DelayCallback( ECamCameraEventVideoInit, aError, 500000 );
   858 #else 
   858 #else
   859   if( aError &&
   859   if( aError &&
   860       ( iIveCancel || ( !iIveSequenceActive && iIveRecoveryOngoing ) ) )
   860       ( iIveCancel || ( !iIveSequenceActive && iIveRecoveryOngoing ) ) )
   861       // Return if error and recovering process has been started, 
   861       // Return if error and recovering process has been started,
   862       // but this video prepare complete is not part of recovery 
   862       // but this video prepare complete is not part of recovery
   863       // i.e. iIveSequenceActive is not active yet. 
   863       // i.e. iIveSequenceActive is not active yet.
   864     {
   864     {
   865     PRINT1( _L("Camera => CCamCameraController::McaeoVideoPrepareComplete - Ignore err %d"), aError );
   865     PRINT1( _L("Camera => CCamCameraController::McaeoVideoPrepareComplete - Ignore err %d"), aError );
   866     return; 
   866     return;
   867     }
   867     }
   868   HandleVideoEvent( ECamCameraEventVideoInit, aError );  
   868   HandleVideoEvent( ECamCameraEventVideoInit, aError );
   869 #endif // CAMERAAPP_CAE_ERR_SIMULATION
   869 #endif // CAMERAAPP_CAE_ERR_SIMULATION
   870 
   870 
   871   PRINT( _L("Camera <= CCamCameraController::McaeoVideoPrepareComplete") );
   871   PRINT( _L("Camera <= CCamCameraController::McaeoVideoPrepareComplete") );
   872   }
   872   }
   873 
   873 
   874 // ---------------------------------------------------------------------------
   874 // ---------------------------------------------------------------------------
   875 // McaeoViewFinderFrameReady
   875 // McaeoViewFinderFrameReady
   876 // ---------------------------------------------------------------------------
   876 // ---------------------------------------------------------------------------
   877 //
   877 //
   878 void 
   878 void
   879 CCamCameraController::McaeoViewFinderFrameReady( CFbsBitmap& aFrame, 
   879 CCamCameraController::McaeoViewFinderFrameReady( CFbsBitmap& aFrame,
   880                                                  TInt        aError )
   880                                                  TInt        aError )
   881   {
   881   {
   882   PRINT( _L("Camera => CCamCameraController::McaeoViewFinderFrameReady") );
   882   PRINT( _L("Camera => CCamCameraController::McaeoViewFinderFrameReady") );
   883   CCamBuffer* buffer = NULL;
   883   CCamBuffer* buffer = NULL;
   884   if( KErrNone == aError )
   884   if( KErrNone == aError )
   894 
   894 
   895 // ---------------------------------------------------------------------------
   895 // ---------------------------------------------------------------------------
   896 // McaeoSnapImageReady
   896 // McaeoSnapImageReady
   897 // ---------------------------------------------------------------------------
   897 // ---------------------------------------------------------------------------
   898 //
   898 //
   899 void 
   899 void
   900 CCamCameraController::McaeoSnapImageReady( const CFbsBitmap& aBitmap, 
   900 CCamCameraController::McaeoSnapImageReady( const CFbsBitmap& aBitmap,
   901                                                  TInt        aError  )
   901                                                  TInt        aError  )
   902   {
   902   {
   903   PRINT1( _L("Camera => CCamCameraController::McaeoSnapImageReady, status: %d"), aError );
   903   PRINT1( _L("Camera => CCamCameraController::McaeoSnapImageReady, status: %d"), aError );
   904   //__ASSERT_DEBUG( EFalse, Panic( ECamCameraControllerCaeUnsupported ) );
   904   //__ASSERT_DEBUG( EFalse, Panic( ECamCameraControllerCaeUnsupported ) );
   905   if( 
   905   if(
   906 #ifdef CAMERAAPP_CAE_FIX
   906 #ifdef CAMERAAPP_CAE_FIX
   907       ECamModeChangeInactive == iModeChange &&
   907       ECamModeChangeInactive == iModeChange &&
   908 #endif
   908 #endif
   909       IsFlagOn( iInfo.iState, ECamVideoOn ) 
   909       IsFlagOn( iInfo.iState, ECamVideoOn )
   910     )
   910     )
   911     {
   911     {
   912     CAMERAAPP_PERF_CONTROLLER_STOP( ECamRequestSsStart );
   912     CAMERAAPP_PERF_CONTROLLER_STOP( ECamRequestSsStart );
   913 
   913 
   914     CFbsBitmap* copy( NULL );
   914     CFbsBitmap* copy( NULL );
   922       }
   922       }
   923 
   923 
   924     NotifyObservers( aError,
   924     NotifyObservers( aError,
   925                      ECamCameraEventSsReady,
   925                      ECamCameraEventSsReady,
   926                      ECamCameraEventClassSsData,
   926                      ECamCameraEventClassSsData,
   927                      copy );    
   927                      copy );
   928     delete copy;
   928     delete copy;
   929     copy = NULL;
   929     copy = NULL;
   930     }
   930     }
   931   PRINT( _L("Camera <= CCamCameraController::McaeoSnapImageReady") );
   931   PRINT( _L("Camera <= CCamCameraController::McaeoSnapImageReady") );
   932   }
   932   }
   933 
   933 
   934 // ---------------------------------------------------------------------------
   934 // ---------------------------------------------------------------------------
   935 // McaeoStillImageReady
   935 // McaeoStillImageReady
   936 // ---------------------------------------------------------------------------
   936 // ---------------------------------------------------------------------------
   937 //
   937 //
   938 void 
   938 void
   939 CCamCameraController::McaeoStillImageReady( CFbsBitmap* /*aBitmap*/, 
   939 CCamCameraController::McaeoStillImageReady( CFbsBitmap* /*aBitmap*/,
   940                                             HBufC8*     /*aData  */, 
   940                                             HBufC8*     /*aData  */,
   941                                             TInt        /*aError */ )
   941                                             TInt        /*aError */ )
   942   {
   942   {
   943   // Still images are not captured through CCaeEngine.
   943   // Still images are not captured through CCaeEngine.
   944   __ASSERT_DEBUG( EFalse, Panic( ECamCameraControllerCaeUnsupported ) );
   944   __ASSERT_DEBUG( EFalse, Panic( ECamCameraControllerCaeUnsupported ) );
   945   }
   945   }
   946 
   946 
   947 // ---------------------------------------------------------------------------
   947 // ---------------------------------------------------------------------------
   948 // McaeoVideoRecordingOn
   948 // McaeoVideoRecordingOn
   949 // ---------------------------------------------------------------------------
   949 // ---------------------------------------------------------------------------
   950 //
   950 //
   951 void 
   951 void
   952 CCamCameraController::McaeoVideoRecordingOn( TInt aError )
   952 CCamCameraController::McaeoVideoRecordingOn( TInt aError )
   953   {
   953   {
   954   PRINT( _L("Camera => CCamCameraController::McaeoVideoRecordingOn") );
   954   PRINT( _L("Camera => CCamCameraController::McaeoVideoRecordingOn") );
   955 
   955 
   956 #ifdef CAMERAAPP_CAE_ERR_SIMULATION
   956 #ifdef CAMERAAPP_CAE_ERR_SIMULATION
   957   HandleVideoEvent( ECamCameraEventVideoStart, aError );
   957   HandleVideoEvent( ECamCameraEventVideoStart, aError );
   958 #else
   958 #else
   959   HandleVideoEvent( ECamCameraEventVideoStart, aError );  
   959   HandleVideoEvent( ECamCameraEventVideoStart, aError );
   960 #endif // CAMERAAPP_CAE_ERR_SIMULATION
   960 #endif // CAMERAAPP_CAE_ERR_SIMULATION
   961   
   961 
   962   PRINT( _L("Camera <= CCamCameraController::McaeoVideoRecordingOn") );
   962   PRINT( _L("Camera <= CCamCameraController::McaeoVideoRecordingOn") );
   963 
   963 
   964   }
   964   }
   965 
   965 
   966 // ---------------------------------------------------------------------------
   966 // ---------------------------------------------------------------------------
   967 // McaeoVideoRecordingPaused
   967 // McaeoVideoRecordingPaused
   968 // ---------------------------------------------------------------------------
   968 // ---------------------------------------------------------------------------
   969 //
   969 //
   970 void 
   970 void
   971 CCamCameraController::McaeoVideoRecordingPaused( TInt aError )
   971 CCamCameraController::McaeoVideoRecordingPaused( TInt aError )
   972   {
   972   {
   973   PRINT( _L("Camera => CCamCameraController::McaeoVideoRecordingPaused") );
   973   PRINT( _L("Camera => CCamCameraController::McaeoVideoRecordingPaused") );
   974 
   974 
   975 #ifdef CAMERAAPP_CAE_ERR_SIMULATION
   975 #ifdef CAMERAAPP_CAE_ERR_SIMULATION
   976   HandleVideoEvent( ECamCameraEventVideoPause, KErrUnknown );
   976   HandleVideoEvent( ECamCameraEventVideoPause, KErrUnknown );
   977 #else
   977 #else
   978   HandleVideoEvent( ECamCameraEventVideoPause, aError );
   978   HandleVideoEvent( ECamCameraEventVideoPause, aError );
   979 #endif // CAMERAAPP_CAE_ERR_SIMULATION
   979 #endif // CAMERAAPP_CAE_ERR_SIMULATION
   980   
   980 
   981   PRINT( _L("Camera <= CCamCameraController::McaeoVideoRecordingPaused") );
   981   PRINT( _L("Camera <= CCamCameraController::McaeoVideoRecordingPaused") );
   982 
   982 
   983   }
   983   }
   984 
   984 
   985 // ---------------------------------------------------------------------------
   985 // ---------------------------------------------------------------------------
   986 // McaeoVideoRecordingComplete
   986 // McaeoVideoRecordingComplete
   987 // ---------------------------------------------------------------------------
   987 // ---------------------------------------------------------------------------
   988 //
   988 //
   989 void 
   989 void
   990 CCamCameraController::McaeoVideoRecordingComplete( TInt aError )
   990 CCamCameraController::McaeoVideoRecordingComplete( TInt aError )
   991   {
   991   {
   992   PRINT( _L("Camera => CCamCameraController::McaeoVideoRecordingComplete") );
   992   PRINT( _L("Camera => CCamCameraController::McaeoVideoRecordingComplete") );
   993 
   993 
   994 #ifdef CAMERAAPP_CAE_ERR_SIMULATION
   994 #ifdef CAMERAAPP_CAE_ERR_SIMULATION
  1003         {
  1003         {
  1004         iCaeEngine->SetAsyncVideoStopMode( EFalse );
  1004         iCaeEngine->SetAsyncVideoStopMode( EFalse );
  1005         }
  1005         }
  1006     iAsyncVideoStopModeSupported = EFalse;
  1006     iAsyncVideoStopModeSupported = EFalse;
  1007     }
  1007     }
  1008   
  1008 
  1009   PRINT( _L("Camera <= CCamCameraController::McaeoVideoRecordingComplete") );  
  1009   PRINT( _L("Camera <= CCamCameraController::McaeoVideoRecordingComplete") );
  1010 
  1010 
  1011   }
  1011   }
  1012 
  1012 
  1013 // ---------------------------------------------------------------------------
  1013 // ---------------------------------------------------------------------------
  1014 // McaeoVideoRecordingTimes
  1014 // McaeoVideoRecordingTimes
  1015 // ---------------------------------------------------------------------------
  1015 // ---------------------------------------------------------------------------
  1016 //
  1016 //
  1017 void 
  1017 void
  1018 CCamCameraController::McaeoVideoRecordingTimes( 
  1018 CCamCameraController::McaeoVideoRecordingTimes(
  1019     TTimeIntervalMicroSeconds aTimeElapsed, 
  1019     TTimeIntervalMicroSeconds aTimeElapsed,
  1020     TTimeIntervalMicroSeconds aTimeRemaining, 
  1020     TTimeIntervalMicroSeconds aTimeRemaining,
  1021     TInt aError )
  1021     TInt aError )
  1022   {
  1022   {
  1023   HandleVideoTimeEvent( aError, aTimeElapsed, aTimeRemaining );
  1023   HandleVideoTimeEvent( aError, aTimeElapsed, aTimeRemaining );
  1024   }
  1024   }
  1025 
  1025 
  1026 // ---------------------------------------------------------------------------
  1026 // ---------------------------------------------------------------------------
  1027 // McaeoVideoRecordingStopped
  1027 // McaeoVideoRecordingStopped
  1028 // ---------------------------------------------------------------------------
  1028 // ---------------------------------------------------------------------------
  1029 //
  1029 //
  1030 void 
  1030 void
  1031 CCamCameraController::McaeoVideoRecordingStopped()
  1031 CCamCameraController::McaeoVideoRecordingStopped()
  1032   {
  1032   {
  1033   PRINT( _L("Camera => CCamCameraController::McaeoVideoRecordingStopped") );
  1033   PRINT( _L("Camera => CCamCameraController::McaeoVideoRecordingStopped") );
  1034 
  1034 
  1035 #ifdef CAMERAAPP_CAE_ERR_SIMULATION
  1035 #ifdef CAMERAAPP_CAE_ERR_SIMULATION
  1047 
  1047 
  1048 // ---------------------------------------------------------------------------
  1048 // ---------------------------------------------------------------------------
  1049 // ImageEncoded
  1049 // ImageEncoded
  1050 // ---------------------------------------------------------------------------
  1050 // ---------------------------------------------------------------------------
  1051 //
  1051 //
  1052 void 
  1052 void
  1053 CCamCameraController::ImageEncoded( TInt aStatus, HBufC8* aData )
  1053 CCamCameraController::ImageEncoded( TInt aStatus, HBufC8* aData )
  1054   {
  1054   {
  1055   PRINT( _L("Camera => CCamCameraController::ImageEncoded") );
  1055   PRINT( _L("Camera => CCamCameraController::ImageEncoded") );
  1056   MCameraBuffer* buffer = NULL;
  1056   MCameraBuffer* buffer = NULL;
  1057 
  1057 
  1067         aData  = NULL; // ownership to buffer
  1067         aData  = NULL; // ownership to buffer
  1068         });
  1068         });
  1069       }
  1069       }
  1070     else
  1070     else
  1071       {
  1071       {
  1072       aStatus = KErrNotFound;      
  1072       aStatus = KErrNotFound;
  1073       }    
  1073       }
  1074     }
  1074     }
  1075   else
  1075   else
  1076     {
  1076     {
  1077     // Just delete on errors
  1077     // Just delete on errors
  1078     delete aData;
  1078     delete aData;
  1090 
  1090 
  1091 // ---------------------------------------------------------------------------
  1091 // ---------------------------------------------------------------------------
  1092 // AttachObserverL
  1092 // AttachObserverL
  1093 // ---------------------------------------------------------------------------
  1093 // ---------------------------------------------------------------------------
  1094 //
  1094 //
  1095 void 
  1095 void
  1096 CCamCameraController::AttachObserverL( const MCamCameraObserver* aObserver,
  1096 CCamCameraController::AttachObserverL( const MCamCameraObserver* aObserver,
  1097                                        const TUint&              aInterest )
  1097                                        const TUint&              aInterest )
  1098   {
  1098   {
  1099   // Only add the observer once. NULL pointer only checked here.
  1099   // Only add the observer once. NULL pointer only checked here.
  1100   // Observer not added, if no notifications would be sent due to
  1100   // Observer not added, if no notifications would be sent due to
  1101   // event interest being ECamCameraEventClassNone.
  1101   // event interest being ECamCameraEventClassNone.
  1102   if( aObserver
  1102   if( aObserver
  1103    && ECamCameraEventClassNone != aInterest
  1103    && ECamCameraEventClassNone != aInterest
  1104    && KErrNotFound             == iObservers.Find( aObserver ) 
  1104    && KErrNotFound             == iObservers.Find( aObserver )
  1105     )
  1105     )
  1106     {
  1106     {
  1107     // Try to add the observer to our list.
  1107     // Try to add the observer to our list.
  1108     TInt error = iObservers.Append( aObserver );
  1108     TInt error = iObservers.Append( aObserver );
  1109 
  1109 
  1110     // If we manage to add the observer, make sure the interest info gets set.
  1110     // If we manage to add the observer, make sure the interest info gets set.
  1111     if( KErrNone == error )
  1111     if( KErrNone == error )
  1112       {
  1112       {
  1113       error = iObserverInterests.Append( aInterest );
  1113       error = iObserverInterests.Append( aInterest );
  1114       // If we are unable to add the interest info,
  1114       // If we are unable to add the interest info,
  1115       // remove also the observer. 
  1115       // remove also the observer.
  1116       if( KErrNone != error )
  1116       if( KErrNone != error )
  1117         {
  1117         {
  1118         iObservers.Remove( iObservers.Count() - 1 );
  1118         iObservers.Remove( iObservers.Count() - 1 );
  1119         }
  1119         }
  1120       }
  1120       }
  1121 
  1121 
  1122     User::LeaveIfError( error );
  1122     User::LeaveIfError( error );
  1123     }
  1123     }
  1124   }
  1124   }
  1125     
  1125 
  1126 // ---------------------------------------------------------------------------
  1126 // ---------------------------------------------------------------------------
  1127 // DetachObserver
  1127 // DetachObserver
  1128 // ---------------------------------------------------------------------------
  1128 // ---------------------------------------------------------------------------
  1129 //
  1129 //
  1130 void 
  1130 void
  1131 CCamCameraController::DetachObserver( const MCamCameraObserver* aObserver )
  1131 CCamCameraController::DetachObserver( const MCamCameraObserver* aObserver )
  1132   {
  1132   {
  1133   if( aObserver )
  1133   if( aObserver )
  1134     {
  1134     {
  1135     // Ignore error if not found among observers
  1135     // Ignore error if not found among observers
  1147 // RequestL
  1147 // RequestL
  1148 //
  1148 //
  1149 // Issue request for one operation.
  1149 // Issue request for one operation.
  1150 // ---------------------------------------------------------------------------
  1150 // ---------------------------------------------------------------------------
  1151 //
  1151 //
  1152 void 
  1152 void
  1153 CCamCameraController::RequestL( const TCamCameraRequestId& aRequestId )
  1153 CCamCameraController::RequestL( const TCamCameraRequestId& aRequestId )
  1154   {
  1154   {
  1155   PRINT1( _L("Camera => CCamCameraController::RequestL, request:[%s]"), KCamRequestNames[aRequestId] );
  1155   PRINT1( _L("Camera => CCamCameraController::RequestL, request:[%s]"), KCamRequestNames[aRequestId] );
  1156   CheckEqualsL( iInfo.iBusy, ECamBusyOff,  KErrInUse );
  1156   CheckEqualsL( iInfo.iBusy, ECamBusyOff,  KErrInUse );
  1157   SetFlags    ( iInfo.iBusy, ECamBusySingle );
  1157   SetFlags    ( iInfo.iBusy, ECamBusySingle );
  1161   // If the request leaves, need to reset busy flag.
  1161   // If the request leaves, need to reset busy flag.
  1162   CleanupStack::PushL( TCleanupItem( SetNotBusy, &iInfo.iBusy ) );
  1162   CleanupStack::PushL( TCleanupItem( SetNotBusy, &iInfo.iBusy ) );
  1163   PRINT( _L("Camera <> process request..") );
  1163   PRINT( _L("Camera <> process request..") );
  1164   proceed = ProcessOneRequestL( aRequestId );
  1164   proceed = ProcessOneRequestL( aRequestId );
  1165   CleanupStack::Pop();
  1165   CleanupStack::Pop();
  1166   
  1166 
  1167   // If this request will be responded through MCameraObserver(2) callback,
  1167   // If this request will be responded through MCameraObserver(2) callback,
  1168   // new requests cannot be accepted until that call arrives and
  1168   // new requests cannot be accepted until that call arrives and
  1169   // notification to our observers will be sent there.
  1169   // notification to our observers will be sent there.
  1170   // Otherwise the request is fully processed from our point of view,
  1170   // Otherwise the request is fully processed from our point of view,
  1171   // and new request can be accepted.
  1171   // and new request can be accepted.
  1174     PRINT( _L("Camera <> ..Request has no callback from CCamera, ready for new request.") );
  1174     PRINT( _L("Camera <> ..Request has no callback from CCamera, ready for new request.") );
  1175     // Need to clear the busy flag before notification,
  1175     // Need to clear the busy flag before notification,
  1176     // as observer might want to issue a new request during
  1176     // as observer might want to issue a new request during
  1177     // the notification callback.
  1177     // the notification callback.
  1178     ClearFlags( iInfo.iBusy, ECamBusySingle );
  1178     ClearFlags( iInfo.iBusy, ECamBusySingle );
  1179     
  1179 
  1180     if( ECamRequestVideoStop == aRequestId
  1180     if( ECamRequestVideoStop == aRequestId
  1181      || ECamRequestSetAsyncVideoStopMode == aRequestId
  1181      || ECamRequestSetAsyncVideoStopMode == aRequestId
  1182      || ECamRequestImageCancel == aRequestId )
  1182      || ECamRequestImageCancel == aRequestId )
  1183       {
  1183       {
  1184       // For video stop request, callback has already happened and notification
  1184       // For video stop request, callback has already happened and notification
  1185       // has been given. No need to do anything here.
  1185       // has been given. No need to do anything here.
  1186       }
  1186       }
  1187     else
  1187     else
  1188       {  
  1188       {
  1189       // Give notification to observers  
  1189       // Give notification to observers
  1190       TCamCameraEventId event( Request2Event( aRequestId ) );
  1190       TCamCameraEventId event( Request2Event( aRequestId ) );
  1191       NotifyObservers( KErrNone, event, EventClass( event ) );
  1191       NotifyObservers( KErrNone, event, EventClass( event ) );
  1192       }
  1192       }
  1193     }
  1193     }
  1194   else
  1194   else
  1199   PRINT( _L("Camera <= CCamCameraController::RequestL") );
  1199   PRINT( _L("Camera <= CCamCameraController::RequestL") );
  1200   }
  1200   }
  1201 
  1201 
  1202 // ---------------------------------------------------------------------------
  1202 // ---------------------------------------------------------------------------
  1203 // DirectRequestL
  1203 // DirectRequestL
  1204 // 
  1204 //
  1205 // Issue request even when busy.
  1205 // Issue request even when busy.
  1206 // ---------------------------------------------------------------------------
  1206 // ---------------------------------------------------------------------------
  1207 //
  1207 //
  1208 void 
  1208 void
  1209 CCamCameraController::DirectRequestL( const TCamCameraRequestId& aRequestId )
  1209 CCamCameraController::DirectRequestL( const TCamCameraRequestId& aRequestId )
  1210   {
  1210   {
  1211   PRINT( _L("Camera => CCamCameraController::DirectRequestL") );
  1211   PRINT( _L("Camera => CCamCameraController::DirectRequestL") );
  1212 
  1212 
  1213   TBool notify( ETrue );
  1213   TBool notify( ETrue );
  1267       ProcessImageRequestL( ECamRequestImageInit );
  1267       ProcessImageRequestL( ECamRequestImageInit );
  1268       break;
  1268       break;
  1269     // -----------------------------------------------------
  1269     // -----------------------------------------------------
  1270     default:
  1270     default:
  1271       Panic( ECamCameraControllerUnsupported );
  1271       Panic( ECamCameraControllerUnsupported );
  1272       break;      
  1272       break;
  1273     }
  1273     }
  1274 
  1274 
  1275   if( notify )
  1275   if( notify )
  1276     {
  1276     {
  1277     TCamCameraEventId event( Request2Event( aRequestId ) );
  1277     TCamCameraEventId event( Request2Event( aRequestId ) );
  1288 //
  1288 //
  1289 // Operations done during the sequence will be notified with
  1289 // Operations done during the sequence will be notified with
  1290 // associated event codes to observers. If any errors happen during the
  1290 // associated event codes to observers. If any errors happen during the
  1291 // sequence, the notification will reflect this with the status code.
  1291 // sequence, the notification will reflect this with the status code.
  1292 // When sequence ends, observers will be notified with event
  1292 // When sequence ends, observers will be notified with event
  1293 // ECamCameraEventSequenceEnd. No new requests are accepted before 
  1293 // ECamCameraEventSequenceEnd. No new requests are accepted before
  1294 // ECamCameraEventSequenceEnd notification is sent.
  1294 // ECamCameraEventSequenceEnd notification is sent.
  1295 // ---------------------------------------------------------------------------
  1295 // ---------------------------------------------------------------------------
  1296 //
  1296 //
  1297 void 
  1297 void
  1298 CCamCameraController
  1298 CCamCameraController
  1299 ::RequestSequenceL( const RCamRequestArray& aSequence )
  1299 ::RequestSequenceL( const RCamRequestArray& aSequence )
  1300   {
  1300   {
  1301   PRINT( _L("Camera => CCamCameraController::RequestSequence") );
  1301   PRINT( _L("Camera => CCamCameraController::RequestSequence") );
  1302   CheckEqualsL( iInfo.iBusy, ECamBusyOff,  KErrInUse );
  1302   CheckEqualsL( iInfo.iBusy, ECamBusyOff,  KErrInUse );
  1320 
  1320 
  1321 // ---------------------------------------------------------------------------
  1321 // ---------------------------------------------------------------------------
  1322 // RequestSettingsChangeL
  1322 // RequestSettingsChangeL
  1323 // ---------------------------------------------------------------------------
  1323 // ---------------------------------------------------------------------------
  1324 //
  1324 //
  1325 void 
  1325 void
  1326 CCamCameraController::RequestSettingsChangeL()
  1326 CCamCameraController::RequestSettingsChangeL()
  1327   {
  1327   {
  1328   PRINT ( _L("Camera => CCamCameraController::RequestSettingsChangeL") );
  1328   PRINT ( _L("Camera => CCamCameraController::RequestSettingsChangeL") );
  1329   CheckEqualsL( iInfo.iBusy, ECamBusyOff,  KErrInUse    );
  1329   CheckEqualsL( iInfo.iBusy, ECamBusyOff,  KErrInUse    );
  1330   CheckFlagOnL( iInfo.iState, ECamReserved, KErrNotReady );
  1330   CheckFlagOnL( iInfo.iState, ECamReserved, KErrNotReady );
  1356   TBool callback = ProcessSettingL( aSettingId );
  1356   TBool callback = ProcessSettingL( aSettingId );
  1357   // If there is a callback, do notification there.
  1357   // If there is a callback, do notification there.
  1358   if( !callback )
  1358   if( !callback )
  1359     {
  1359     {
  1360     TCamCameraSettingId setting = aSettingId;
  1360     TCamCameraSettingId setting = aSettingId;
  1361     NotifyObservers( KErrNone, 
  1361     NotifyObservers( KErrNone,
  1362                      ECamCameraEventSettingsSingle,
  1362                      ECamCameraEventSettingsSingle,
  1363                      ECamCameraEventClassSettings,
  1363                      ECamCameraEventClassSettings,
  1364                      &setting );
  1364                      &setting );
  1365     }
  1365     }
  1366 
  1366 
  1370 
  1370 
  1371 // ---------------------------------------------------------------------------
  1371 // ---------------------------------------------------------------------------
  1372 // CancelSequence
  1372 // CancelSequence
  1373 // ---------------------------------------------------------------------------
  1373 // ---------------------------------------------------------------------------
  1374 //
  1374 //
  1375 void 
  1375 void
  1376 CCamCameraController::CancelSequence()
  1376 CCamCameraController::CancelSequence()
  1377   {
  1377   {
  1378   PRINT( _L("Camera => CCamCameraController::CancelSequence") );
  1378   PRINT( _L("Camera => CCamCameraController::CancelSequence") );
  1379   if( iActive &&
  1379   if( iActive &&
  1380       iActive->IsActive() )
  1380       iActive->IsActive() )
  1391     {
  1391     {
  1392     PRINT( _L("Camera <> Busy, call EndSequence()..") );
  1392     PRINT( _L("Camera <> Busy, call EndSequence()..") );
  1393     // Clears busy flag, if we were processing a sequence of requests / settings.
  1393     // Clears busy flag, if we were processing a sequence of requests / settings.
  1394     // If iBusy is set because one request is on the way,
  1394     // If iBusy is set because one request is on the way,
  1395     // we must not clear it here - when that request is processed,
  1395     // we must not clear it here - when that request is processed,
  1396     // the flag will be cleared. 
  1396     // the flag will be cleared.
  1397     EndSequence( KErrCancel );
  1397     EndSequence( KErrCancel );
  1398     }    
  1398     }
  1399   PRINT( _L("Camera <= CCamCameraController::CancelSequence") );
  1399   PRINT( _L("Camera <= CCamCameraController::CancelSequence") );
  1400   }
  1400   }
  1401 
  1401 
  1402 // ---------------------------------------------------------------------------
  1402 // ---------------------------------------------------------------------------
  1403 // SwitchCameraL
  1403 // SwitchCameraL
  1406 void
  1406 void
  1407 CCamCameraController::SwitchCameraL( TInt aCameraIndex )
  1407 CCamCameraController::SwitchCameraL( TInt aCameraIndex )
  1408   {
  1408   {
  1409   PRINT1( _L("Camera => CCamCameraController::SwitchCameraL%d"),aCameraIndex );
  1409   PRINT1( _L("Camera => CCamCameraController::SwitchCameraL%d"),aCameraIndex );
  1410   #ifdef _DEBUG
  1410   #ifdef _DEBUG
  1411   if( aCameraIndex == iInfo.iCurrentCamera ) 
  1411   if( aCameraIndex == iInfo.iCurrentCamera )
  1412     {
  1412     {
  1413     PRINT( _L("Camera <> CCamCameraController::SwitchCameraL - Changing Secondary camera orientation") );
  1413     PRINT( _L("Camera <> CCamCameraController::SwitchCameraL - Changing Secondary camera orientation") );
  1414     }
  1414     }
  1415   #endif // _DEBUG
  1415   #endif // _DEBUG
  1416   
  1416 
  1417   if( aCameraIndex < 0 || aCameraIndex >= CamerasAvailable() )
  1417   if( aCameraIndex < 0 || aCameraIndex >= CamerasAvailable() )
  1418     {
  1418     {
  1419     User::Leave( KErrNotSupported );
  1419     User::Leave( KErrNotSupported );
  1420     }
  1420     }
  1421   else
  1421   else
  1424     // First free old camera resources
  1424     // First free old camera resources
  1425     if( iCamera )
  1425     if( iCamera )
  1426       {
  1426       {
  1427       ReleaseCurrentCamera();
  1427       ReleaseCurrentCamera();
  1428       }
  1428       }
  1429      
  1429 
  1430     // used in CompleteSwitchCamera  
  1430     // used in CompleteSwitchCamera
  1431     iCurrentCameraIndex = aCameraIndex;
  1431     iCurrentCameraIndex = aCameraIndex;
  1432     
  1432 
  1433     // -----------------------------------------------------
  1433     // -----------------------------------------------------
  1434     // Then create new camera:
  1434     // Then create new camera:
  1435     PRINT ( _L("############################################################") );
  1435     PRINT ( _L("############################################################") );
  1436 #ifdef CAMERAAPP_CAE_FOR_VIDEO
  1436 #ifdef CAMERAAPP_CAE_FOR_VIDEO
  1437 
  1437 
  1438     PRINT1( _L("Camera <> Creating CCaeEngine, camera index: %d .."), aCameraIndex );
  1438     PRINT1( _L("Camera <> Creating CCaeEngine, camera index: %d .."), aCameraIndex );
  1439     iCaeEngine = NewCaeEngineL( aCameraIndex ); 
  1439     iCaeEngine = NewCaeEngineL( aCameraIndex );
  1440 
  1440 
  1441 #else
  1441 #else
  1442 
  1442 
  1443     PRINT ( _L("Camera <> Note: CCamera only in use, no CCaeEngine") );
  1443     PRINT ( _L("Camera <> Note: CCamera only in use, no CCaeEngine") );
  1444     PRINT1( _L("Camera <> Creating CCamera, camera index: %d .."), aCameraIndex );
  1444     PRINT1( _L("Camera <> Creating CCamera, camera index: %d .."), aCameraIndex );
  1465   else if( iCurrentCameraIndex == iInfo.iCurrentCamera )
  1465   else if( iCurrentCameraIndex == iInfo.iCurrentCamera )
  1466     {
  1466     {
  1467     return;
  1467     return;
  1468     }
  1468     }
  1469 
  1469 
  1470 #ifdef CAMERAAPP_CAE_FOR_VIDEO    
  1470 #ifdef CAMERAAPP_CAE_FOR_VIDEO
  1471   #ifdef CAMERAAPP_CAE_FIX
  1471   #ifdef CAMERAAPP_CAE_FIX
  1472     PRINT ( _L("Camera <> Creating new CCamera..") );
  1472     PRINT ( _L("Camera <> Creating new CCamera..") );
  1473     iCamera    = NewCameraL( iCurrentCameraIndex );
  1473     iCamera    = NewCameraL( iCurrentCameraIndex );
  1474   #else
  1474   #else
  1475     PRINT1( _L("Camera <> Creating CCamera duplicate, camera handle: %d .."), iCaeEngine->CCameraHandle() );
  1475     PRINT1( _L("Camera <> Creating CCamera duplicate, camera handle: %d .."), iCaeEngine->CCameraHandle() );
  1486     iAdvancedSettings = CCamera::CCameraAdvancedSettings::NewL( *iCamera );
  1486     iAdvancedSettings = CCamera::CCameraAdvancedSettings::NewL( *iCamera );
  1487 #ifdef CAMERAAPP_CAPI_V2_IP
  1487 #ifdef CAMERAAPP_CAPI_V2_IP
  1488     if( KPrimaryCameraIndex == iInfo.iCurrentCamera )
  1488     if( KPrimaryCameraIndex == iInfo.iCurrentCamera )
  1489       {
  1489       {
  1490       // Support only for primary camera.
  1490       // Support only for primary camera.
  1491       // Ignore error in instantiation: If NewL leaves, there's no 
  1491       // Ignore error in instantiation: If NewL leaves, there's no
  1492       // support for Image Processing available. Report error to client
  1492       // support for Image Processing available. Report error to client
  1493       // if settings requiring it are used.
  1493       // if settings requiring it are used.
  1494       PRINT ( _L("Camera <> Create CCameraImageProcessing..") );
  1494       PRINT ( _L("Camera <> Create CCameraImageProcessing..") );
  1495       TRAP_IGNORE( iImageProcessor = CCamera::CCameraImageProcessing::NewL( *iCamera ) );
  1495       TRAP_IGNORE( iImageProcessor = CCamera::CCameraImageProcessing::NewL( *iCamera ) );
  1496       PRINT1( _L("Camera <> Image Processor pointer: %d"), iImageProcessor );
  1496       PRINT1( _L("Camera <> Image Processor pointer: %d"), iImageProcessor );
  1501     // support for several setting. Not supported settings will not
  1501     // support for several setting. Not supported settings will not
  1502     // cause this method to leave, only more serious errors.
  1502     // cause this method to leave, only more serious errors.
  1503     GetAdvancedSettingsInfoL();
  1503     GetAdvancedSettingsInfoL();
  1504 
  1504 
  1505     PRINT ( _L("Camera <> Get i/f MCameraOrientation..") )
  1505     PRINT ( _L("Camera <> Get i/f MCameraOrientation..") )
  1506     iCustomInterfaceOrientation = 
  1506     iCustomInterfaceOrientation =
  1507       static_cast <MCameraOrientation*>( 
  1507       static_cast <MCameraOrientation*>(
  1508   	    iCamera->CustomInterface( KCameraOrientationUid ) );
  1508   	    iCamera->CustomInterface( KCameraOrientationUid ) );
  1509     PRINT1( _L("Camera <> Orientation custom i/f pointer:%d"), iCustomInterfaceOrientation );
  1509     PRINT1( _L("Camera <> Orientation custom i/f pointer:%d"), iCustomInterfaceOrientation );
  1510 
  1510 
  1511 #endif // CAMERAAPP_CAPI_V2_ADV
  1511 #endif // CAMERAAPP_CAPI_V2_ADV
  1512 
  1512 
  1530 CCamCameraController::SetOrientationModeL( TInt aOrientation )
  1530 CCamCameraController::SetOrientationModeL( TInt aOrientation )
  1531   {
  1531   {
  1532   PRINT1( _L("Camera => CCamCameraController::SetOrientationModeL %d"), aOrientation );
  1532   PRINT1( _L("Camera => CCamCameraController::SetOrientationModeL %d"), aOrientation );
  1533 #ifdef CAMERAAPP_CAE_FOR_VIDEO
  1533 #ifdef CAMERAAPP_CAE_FOR_VIDEO
  1534     PRINT( _L("Camera <> CCameraController: Get i/f MUIOrientationOverride from iCaeEngine..") )
  1534     PRINT( _L("Camera <> CCameraController: Get i/f MUIOrientationOverride from iCaeEngine..") )
  1535     iCustomInterfaceUIOrientationOverride = 
  1535     iCustomInterfaceUIOrientationOverride =
  1536       static_cast <MCameraUIOrientationOverride*>( 
  1536       static_cast <MCameraUIOrientationOverride*>(
  1537   	    iCaeEngine->CustomInterface( KCameraUIOrientationOverrideUid ) );
  1537   	    iCaeEngine->CustomInterface( KCameraUIOrientationOverrideUid ) );
  1538 #else
  1538 #else
  1539     PRINT( _L("Camera <> CCameraController: Get i/f MUIOrientationOverride from iCamera..") )
  1539     PRINT( _L("Camera <> CCameraController: Get i/f MUIOrientationOverride from iCamera..") )
  1540     iCustomInterfaceUIOrientationOverride = 
  1540     iCustomInterfaceUIOrientationOverride =
  1541       static_cast <MCameraUIOrientationOverride*>( 
  1541       static_cast <MCameraUIOrientationOverride*>(
  1542   	    iCamera->CustomInterface( KCameraUIOrientationOverrideUid ) );
  1542   	    iCamera->CustomInterface( KCameraUIOrientationOverrideUid ) );
  1543 #endif // CAMERAAPP_CAE_FOR_VIDEO
  1543 #endif // CAMERAAPP_CAE_FOR_VIDEO
  1544 
  1544 
  1545     PRINT1( _L("Camera <> OrientationOverride custom i/f pointer:%d"), iCustomInterfaceUIOrientationOverride );
  1545     PRINT1( _L("Camera <> OrientationOverride custom i/f pointer:%d"), iCustomInterfaceUIOrientationOverride );
  1546     TRAP_IGNORE(iCustomInterfaceUIOrientationOverride->SetOrientationModeL( aOrientation ));
  1546     TRAP_IGNORE(iCustomInterfaceUIOrientationOverride->SetOrientationModeL( aOrientation ));
  1547     
  1547 
  1548   PRINT( _L("Camera <= CCamCameraController::SetOrientationModeL") );
  1548   PRINT( _L("Camera <= CCamCameraController::SetOrientationModeL") );
  1549   }
  1549   }
  1550 
  1550 
  1551 // ---------------------------------------------------------------------------
  1551 // ---------------------------------------------------------------------------
  1552 // CamerasAvailable <<static>> 
  1552 // CamerasAvailable <<static>>
  1553 // ---------------------------------------------------------------------------
  1553 // ---------------------------------------------------------------------------
  1554 //
  1554 //
  1555 TInt 
  1555 TInt
  1556 CCamCameraController::CamerasAvailable() 
  1556 CCamCameraController::CamerasAvailable()
  1557   { 
  1557   {
  1558 #ifndef CAMERAAPP_CAPI_EMULATOR    
  1558 #ifndef CAMERAAPP_CAPI_EMULATOR
  1559   return CCamera::CamerasAvailable();
  1559   return CCamera::CamerasAvailable();
  1560 #else
  1560 #else
  1561   // Temporary
  1561   // Temporary
  1562   return 2;
  1562   return 2;
  1563 #endif  
  1563 #endif
  1564   }
  1564   }
  1565 
  1565 
  1566 // ---------------------------------------------------------------------------
  1566 // ---------------------------------------------------------------------------
  1567 // CameraHandle
  1567 // CameraHandle
  1568 // ---------------------------------------------------------------------------
  1568 // ---------------------------------------------------------------------------
  1569 //
  1569 //
  1570 TInt 
  1570 TInt
  1571 CCamCameraController::CameraHandle()
  1571 CCamCameraController::CameraHandle()
  1572   {
  1572   {
  1573   if( iCamera )
  1573   if( iCamera )
  1574     return iCamera->Handle();
  1574     return iCamera->Handle();
  1575   else
  1575   else
  1579 
  1579 
  1580 // ---------------------------------------------------------------------------
  1580 // ---------------------------------------------------------------------------
  1581 // CameraInfo
  1581 // CameraInfo
  1582 // ---------------------------------------------------------------------------
  1582 // ---------------------------------------------------------------------------
  1583 //
  1583 //
  1584 const TCameraInfo& 
  1584 const TCameraInfo&
  1585 CCamCameraController::CameraInfo() const
  1585 CCamCameraController::CameraInfo() const
  1586   {
  1586   {
  1587   return iCameraInfo;
  1587   return iCameraInfo;
  1588   }
  1588   }
  1589 
  1589 
  1590 // ---------------------------------------------------------------------------
  1590 // ---------------------------------------------------------------------------
  1591 // ControllerInfo
  1591 // ControllerInfo
  1592 // ---------------------------------------------------------------------------
  1592 // ---------------------------------------------------------------------------
  1593 //
  1593 //
  1594 const TCamControllerInfo& 
  1594 const TCamControllerInfo&
  1595 CCamCameraController::ControllerInfo() const
  1595 CCamCameraController::ControllerInfo() const
  1596   {
  1596   {
  1597   return iInfo;
  1597   return iInfo;
  1598   }
  1598   }
  1599 
  1599 
  1600 // ---------------------------------------------------------------------------
  1600 // ---------------------------------------------------------------------------
  1601 //
  1601 //
  1602 // ---------------------------------------------------------------------------
  1602 // ---------------------------------------------------------------------------
  1603 //
  1603 //
  1604 TUint 
  1604 TUint
  1605 CCamCameraController::State() const
  1605 CCamCameraController::State() const
  1606   {
  1606   {
  1607   return iInfo.iState;
  1607   return iInfo.iState;
  1608   }
  1608   }
  1609 
  1609 
  1610 // ---------------------------------------------------------------------------
  1610 // ---------------------------------------------------------------------------
  1611 //
  1611 //
  1612 // ---------------------------------------------------------------------------
  1612 // ---------------------------------------------------------------------------
  1613 //
  1613 //
  1614 TCamViewfinderMode 
  1614 TCamViewfinderMode
  1615 CCamCameraController::ViewfinderMode()  const
  1615 CCamCameraController::ViewfinderMode()  const
  1616   {
  1616   {
  1617   return iInfo.iVfMode;
  1617   return iInfo.iVfMode;
  1618   }
  1618   }
  1619 
  1619 
  1625 CCamCameraController::ViewfinderState() const
  1625 CCamCameraController::ViewfinderState() const
  1626   {
  1626   {
  1627   return iInfo.iVfState;
  1627   return iInfo.iVfState;
  1628   }
  1628   }
  1629 
  1629 
  1630   
  1630 
  1631 // ---------------------------------------------------------------------------
  1631 // ---------------------------------------------------------------------------
  1632 //
  1632 //
  1633 // ---------------------------------------------------------------------------
  1633 // ---------------------------------------------------------------------------
  1634 //
  1634 //
  1635 TCamCameraTriState
  1635 TCamCameraTriState
  1636 CCamCameraController::SnapshotState() const
  1636 CCamCameraController::SnapshotState() const
  1637   {
  1637   {
  1638   return iInfo.iSsState;  
  1638   return iInfo.iSsState;
  1639   }
  1639   }
  1640 
  1640 
  1641 
  1641 
  1642 // ---------------------------------------------------------------------------
  1642 // ---------------------------------------------------------------------------
  1643 //
  1643 //
  1644 // ---------------------------------------------------------------------------
  1644 // ---------------------------------------------------------------------------
  1645 //
  1645 //
  1646 TCamCameraReadyState 
  1646 TCamCameraReadyState
  1647 CCamCameraController::FlashState() const
  1647 CCamCameraController::FlashState() const
  1648   {
  1648   {
  1649   TCamCameraReadyState state = ECamUnknown;
  1649   TCamCameraReadyState state = ECamUnknown;
  1650   
  1650 
  1651 #ifdef CAMERAAPP_CAPI_V2_ADV
  1651 #ifdef CAMERAAPP_CAPI_V2_ADV
  1652   if( iAdvancedSettings )
  1652   if( iAdvancedSettings )
  1653     {
  1653     {
  1654     TBool ready       = EFalse;
  1654     TBool ready       = EFalse;
  1655     TInt  queryStatus = iAdvancedSettings->IsFlashReady( ready );
  1655     TInt  queryStatus = iAdvancedSettings->IsFlashReady( ready );
  1696       }
  1696       }
  1697     // -----------------------------------------------------
  1697     // -----------------------------------------------------
  1698     case ECameraSettingExposure:
  1698     case ECameraSettingExposure:
  1699     case ECameraUserSceneSettingExposure:
  1699     case ECameraUserSceneSettingExposure:
  1700       {
  1700       {
  1701       TPckgBuf<TCamSettingDataExposure>* exposure = 
  1701       TPckgBuf<TCamSettingDataExposure>* exposure =
  1702           static_cast<TPckgBuf<TCamSettingDataExposure>*>( aSettingData );
  1702           static_cast<TPckgBuf<TCamSettingDataExposure>*>( aSettingData );
  1703 #ifdef CAMERAAPP_CAE_FIX
  1703 #ifdef CAMERAAPP_CAE_FIX
  1704       if( iCaeInUse )
  1704       if( iCaeInUse )
  1705         (*exposure)().iExposureMode = iCaeEngine->ExposureMode();
  1705         (*exposure)().iExposureMode = iCaeEngine->ExposureMode();
  1706       else
  1706       else
  1722       {
  1722       {
  1723       TInt* iso = static_cast<TInt*>( aSettingData );
  1723       TInt* iso = static_cast<TInt*>( aSettingData );
  1724       *iso = iAdvancedSettings->IsoRate();
  1724       *iso = iAdvancedSettings->IsoRate();
  1725       break;
  1725       break;
  1726       }
  1726       }
  1727     case ECameraSettingContAF:   
  1727     case ECameraSettingContAF:
  1728       {
  1728       {
  1729       TInt* contAF = static_cast<TInt*>( aSettingData );
  1729       TInt* contAF = static_cast<TInt*>( aSettingData );
  1730       *contAF = iAdvancedSettings->AutoFocusType() &  //bitwise
  1730       *contAF = iAdvancedSettings->AutoFocusType() &  //bitwise
  1731                 CAS::EAutoFocusTypeContinuous; 
  1731                 CAS::EAutoFocusTypeContinuous;
  1732       break;
  1732       break;
  1733       }
  1733       }
  1734 #endif
  1734 #endif
  1735     // -----------------------------------------------------
  1735     // -----------------------------------------------------
  1736     case ECameraSettingWhiteBalance:
  1736     case ECameraSettingWhiteBalance:
  1737     case ECameraUserSceneSettingWhiteBalance:
  1737     case ECameraUserSceneSettingWhiteBalance:
  1738       {
  1738       {
  1739       TPckgBuf<TCamSettingDataWhiteBalance>* wb = 
  1739       TPckgBuf<TCamSettingDataWhiteBalance>* wb =
  1740           static_cast<TPckgBuf<TCamSettingDataWhiteBalance>*>( aSettingData );
  1740           static_cast<TPckgBuf<TCamSettingDataWhiteBalance>*>( aSettingData );
  1741 
  1741 
  1742 #ifdef CAMERAAPP_CAE_FIX
  1742 #ifdef CAMERAAPP_CAE_FIX
  1743       if( iCaeInUse )
  1743       if( iCaeInUse )
  1744         (*wb)().iWhiteBalanceMode = iCaeEngine->WhiteBalanceMode();
  1744         (*wb)().iWhiteBalanceMode = iCaeEngine->WhiteBalanceMode();
  1755     case ECameraUserSceneSettingColourEffect:
  1755     case ECameraUserSceneSettingColourEffect:
  1756       {
  1756       {
  1757       CheckNonNullL( iImageProcessor, KErrNotSupported );
  1757       CheckNonNullL( iImageProcessor, KErrNotSupported );
  1758 
  1758 
  1759       CIP::TEffect* effect = static_cast<CIP::TEffect*>( aSettingData );
  1759       CIP::TEffect* effect = static_cast<CIP::TEffect*>( aSettingData );
  1760       *effect = 
  1760       *effect =
  1761         (CIP::TEffect)
  1761         (CIP::TEffect)
  1762           iImageProcessor->TransformationValue( KUidECamEventImageProcessingEffect );
  1762           iImageProcessor->TransformationValue( KUidECamEventImageProcessingEffect );
  1763       break;
  1763       break;
  1764       }
  1764       }
  1765     // -----------------------------------------------------
  1765     // -----------------------------------------------------
  1850       }
  1850       }
  1851     // -----------------------------------------------------
  1851     // -----------------------------------------------------
  1852     case ECameraSettingBrightness:
  1852     case ECameraSettingBrightness:
  1853     case ECameraUserSceneSettingBrightness:
  1853     case ECameraUserSceneSettingBrightness:
  1854       {
  1854       {
  1855       CCamera::TBrightness* brightness = 
  1855       CCamera::TBrightness* brightness =
  1856           static_cast<CCamera::TBrightness*>( aSettingData );
  1856           static_cast<CCamera::TBrightness*>( aSettingData );
  1857 #ifdef CAMERAAPP_CAE_FIX
  1857 #ifdef CAMERAAPP_CAE_FIX
  1858       if( iCaeInUse )
  1858       if( iCaeInUse )
  1859         *brightness = (CCamera::TBrightness)iCaeEngine->Brightness();
  1859         *brightness = (CCamera::TBrightness)iCaeEngine->Brightness();
  1860       else
  1860       else
  1864       }
  1864       }
  1865     // -----------------------------------------------------
  1865     // -----------------------------------------------------
  1866     case ECameraSettingContrast:
  1866     case ECameraSettingContrast:
  1867     case ECameraUserSceneSettingContrast:
  1867     case ECameraUserSceneSettingContrast:
  1868       {
  1868       {
  1869       CCamera::TContrast* contrast = 
  1869       CCamera::TContrast* contrast =
  1870           static_cast<CCamera::TContrast*>( aSettingData );
  1870           static_cast<CCamera::TContrast*>( aSettingData );
  1871 #ifdef CAMERAAPP_CAE_FIX
  1871 #ifdef CAMERAAPP_CAE_FIX
  1872       if( iCaeInUse )
  1872       if( iCaeInUse )
  1873         *contrast = (CCamera::TContrast)iCaeEngine->Contrast();
  1873         *contrast = (CCamera::TContrast)iCaeEngine->Contrast();
  1874       else
  1874       else
  1878       }
  1878       }
  1879 #ifdef CAMERAAPP_CAPI_V2_ADV
  1879 #ifdef CAMERAAPP_CAPI_V2_ADV
  1880     // -----------------------------------------------------
  1880     // -----------------------------------------------------
  1881     case ECameraSettingStabilization:
  1881     case ECameraSettingStabilization:
  1882       {
  1882       {
  1883       TPckgBuf<TCamSettingDataStabilization>* pckg = 
  1883       TPckgBuf<TCamSettingDataStabilization>* pckg =
  1884           static_cast<TPckgBuf<TCamSettingDataStabilization>*>( aSettingData );
  1884           static_cast<TPckgBuf<TCamSettingDataStabilization>*>( aSettingData );
  1885       TCamSettingDataStabilization& stabilization = (*pckg)();
  1885       TCamSettingDataStabilization& stabilization = (*pckg)();
  1886 
  1886 
  1887       stabilization.iMode       = iAdvancedSettings->StabilizationMode();
  1887       stabilization.iMode       = iAdvancedSettings->StabilizationMode();
  1888       stabilization.iEffect     = iAdvancedSettings->StabilizationEffect();
  1888       stabilization.iEffect     = iAdvancedSettings->StabilizationEffect();
  1893     // -----------------------------------------------------
  1893     // -----------------------------------------------------
  1894     // Image orientation
  1894     // Image orientation
  1895     case ECameraSettingOrientation:
  1895     case ECameraSettingOrientation:
  1896       {
  1896       {
  1897       CheckNonNullL( iCustomInterfaceOrientation, KErrNotSupported );
  1897       CheckNonNullL( iCustomInterfaceOrientation, KErrNotSupported );
  1898       
  1898 
  1899       MCameraOrientation::TOrientation* orientation =
  1899       MCameraOrientation::TOrientation* orientation =
  1900           static_cast<MCameraOrientation::TOrientation*>( aSettingData );
  1900           static_cast<MCameraOrientation::TOrientation*>( aSettingData );
  1901 
  1901 
  1902       *orientation = iCustomInterfaceOrientation->Orientation();
  1902       *orientation = iCustomInterfaceOrientation->Orientation();
  1903       break;
  1903       break;
  1925 // If the request made to CCamera has a callback, more calls from iActive
  1925 // If the request made to CCamera has a callback, more calls from iActive
  1926 // will not be requested here, but in those callbacks.
  1926 // will not be requested here, but in those callbacks.
  1927 // Leave here will cause iActive to call EndSequence with the error code.
  1927 // Leave here will cause iActive to call EndSequence with the error code.
  1928 // ---------------------------------------------------------------------------
  1928 // ---------------------------------------------------------------------------
  1929 //
  1929 //
  1930 TInt 
  1930 TInt
  1931 CCamCameraController::ProcessNextRequestL()
  1931 CCamCameraController::ProcessNextRequestL()
  1932   {
  1932   {
  1933   PRINT( _L("Camera => CCamCameraController::ProcessNextRequestL") );
  1933   PRINT( _L("Camera => CCamCameraController::ProcessNextRequestL") );
  1934   TInt readyForNextStep( EFalse );
  1934   TInt readyForNextStep( EFalse );
  1935 
  1935 
  1968 
  1968 
  1969     iSequenceIndex++;
  1969     iSequenceIndex++;
  1970     if( iSequenceIndex < iSequenceArray.Count() )
  1970     if( iSequenceIndex < iSequenceArray.Count() )
  1971       {
  1971       {
  1972       const TCamCameraRequestId& requestId( iSequenceArray[iSequenceIndex] );
  1972       const TCamCameraRequestId& requestId( iSequenceArray[iSequenceIndex] );
  1973   
  1973 
  1974       PRINT( _L("Camera <> process request..") );
  1974       PRINT( _L("Camera <> process request..") );
  1975       // If this request will be responded through MCameraObserver(2) callback,
  1975       // If this request will be responded through MCameraObserver(2) callback,
  1976       // iActive will be requested a new callback there and also
  1976       // iActive will be requested a new callback there and also
  1977       // the notification to our observers will be sent there.
  1977       // the notification to our observers will be sent there.
  1978       // Otherwise we do both of those right away.
  1978       // Otherwise we do both of those right away.
  1979       readyForNextStep = ProcessOneRequestL( requestId );
  1979       readyForNextStep = ProcessOneRequestL( requestId );
  1980 
  1980 
  1981       if( readyForNextStep )
  1981       if( readyForNextStep )
  1982         {        
  1982         {
  1983         if( ECamRequestVideoStop == requestId
  1983         if( ECamRequestVideoStop == requestId
  1984          || ECamRequestImageCancel == requestId )
  1984          || ECamRequestImageCancel == requestId )
  1985           {
  1985           {
  1986           // For video stop request, callback has already happened and notification
  1986           // For video stop request, callback has already happened and notification
  1987           // has been given. No need to do anything here.
  1987           // has been given. No need to do anything here.
  1988           PRINT( _L("Camera <> CCamCameraController::RequestL .. Skipping commmon notification, is done already.") );
  1988           PRINT( _L("Camera <> CCamCameraController::RequestL .. Skipping commmon notification, is done already.") );
  1989           }
  1989           }
  1990         else
  1990         else
  1991           {  
  1991           {
  1992           TCamCameraEventId event( Request2Event( requestId ) );  
  1992           TCamCameraEventId event( Request2Event( requestId ) );
  1993           NotifyObservers( KErrNone, event, EventClass( event ) );
  1993           NotifyObservers( KErrNone, event, EventClass( event ) );
  1994           }
  1994           }
  1995         }
  1995         }
  1996       }
  1996       }
  1997     else
  1997     else
  2016 
  2016 
  2017 // ---------------------------------------------------------------------------
  2017 // ---------------------------------------------------------------------------
  2018 // ProcessSettingL
  2018 // ProcessSettingL
  2019 // ---------------------------------------------------------------------------
  2019 // ---------------------------------------------------------------------------
  2020 //
  2020 //
  2021 TInt 
  2021 TInt
  2022 CCamCameraController::ProcessSettingL( const TCamCameraSettingId& aSettingId )
  2022 CCamCameraController::ProcessSettingL( const TCamCameraSettingId& aSettingId )
  2023   {
  2023   {
  2024   PRINT1( _L("Camera => CCamCameraController::ProcessSettingL [%s]"), 
  2024   PRINT1( _L("Camera => CCamCameraController::ProcessSettingL [%s]"),
  2025           KCameraSettingNames[aSettingId] );
  2025           KCameraSettingNames[aSettingId] );
  2026 
  2026 
  2027   TInt callback( EFalse );
  2027   TInt callback( EFalse );
  2028   switch( aSettingId )
  2028   switch( aSettingId )
  2029     {
  2029     {
  2035       }
  2035       }
  2036     // -------------------------------
  2036     // -------------------------------
  2037     case ECameraSettingFlash:
  2037     case ECameraSettingFlash:
  2038     case ECameraUserSceneSettingFlash:
  2038     case ECameraUserSceneSettingFlash:
  2039       {
  2039       {
  2040       if ( IsFlagOn( iInfo.iState, ECamVideoOn ) ) 
  2040       if ( IsFlagOn( iInfo.iState, ECamVideoOn ) )
  2041         {
  2041         {
  2042         CCamera::TFlash flash( CCamera::EFlashNone );
  2042         CCamera::TFlash flash( CCamera::EFlashNone );
  2043         TCamFlashId currentFlashSetting( ECamFlashOff ); 
  2043         TCamFlashId currentFlashSetting( ECamFlashOff );
  2044         // Video light setting has values ECamFlashOff/ECamFlashForced
  2044         // Video light setting has values ECamFlashOff/ECamFlashForced
  2045         iSettingProvider.ProvideCameraSettingL( aSettingId, 
  2045         iSettingProvider.ProvideCameraSettingL( aSettingId,
  2046                                                 &currentFlashSetting ); 
  2046                                                 &currentFlashSetting );
  2047         PRINT2( _L("Camera => Video Flash now = %d, new = %d"), 
  2047         PRINT2( _L("Camera => Video Flash now = %d, new = %d"),
  2048                                        iCamera->Flash(), currentFlashSetting );
  2048                                        iCamera->Flash(), currentFlashSetting );
  2049         // Camera uses values EFlashNone/EFlashVideoLight
  2049         // Camera uses values EFlashNone/EFlashVideoLight
  2050         flash = (currentFlashSetting == ECamFlashOff)?  
  2050         flash = (currentFlashSetting == ECamFlashOff)?
  2051                 CCamera::EFlashNone:CCamera::EFlashVideoLight;
  2051                 CCamera::EFlashNone:CCamera::EFlashVideoLight;
  2052         PRINT1( _L("Camera => iCamera->SetFlashL( %d )"), flash );      
  2052         PRINT1( _L("Camera => iCamera->SetFlashL( %d )"), flash );
  2053         iCamera->SetFlashL( flash );
  2053         iCamera->SetFlashL( flash );
  2054         }
  2054         }
  2055       else
  2055       else
  2056         {
  2056         {
  2057         // Still image flash 
  2057         // Still image flash
  2058         CCamera::TFlash flash( CCamera::EFlashAuto );
  2058         CCamera::TFlash flash( CCamera::EFlashAuto );
  2059       iSettingProvider.ProvideCameraSettingL( aSettingId, &flash );
  2059       iSettingProvider.ProvideCameraSettingL( aSettingId, &flash );
  2060 #ifdef CAMERAAPP_CAE_FIX
  2060 #ifdef CAMERAAPP_CAE_FIX
  2061       if( iCaeInUse )
  2061       if( iCaeInUse )
  2062             {
  2062             {
  2063             iCaeEngine->SetFlashModeL( flash );  
  2063             iCaeEngine->SetFlashModeL( flash );
  2064             }
  2064             }
  2065       else
  2065       else
  2066 #endif
  2066 #endif
  2067         {
  2067         {
  2068         if( iCamera->Flash() != flash )
  2068         if( iCamera->Flash() != flash )
  2095       // (CCamera::EExposureAuto)
  2095       // (CCamera::EExposureAuto)
  2096       if( mode == CCamera::EExposureAuto || mode & iAdvancedSettingInfo.iEvModesSupport )
  2096       if( mode == CCamera::EExposureAuto || mode & iAdvancedSettingInfo.iEvModesSupport )
  2097         {
  2097         {
  2098         iAdvancedSettings->SetExposureMode( mode );
  2098         iAdvancedSettings->SetExposureMode( mode );
  2099         // iCamera->SetExposureL( mode );
  2099         // iCamera->SetExposureL( mode );
  2100   
  2100 
  2101         TInt step = ResolveEvStep( params().iExposureStep );
  2101         TInt step = ResolveEvStep( params().iExposureStep );
  2102         // Value needs to be multiplied by KECamFineResolutionFactor.
  2102         // Value needs to be multiplied by KECamFineResolutionFactor.
  2103         // Setting provider does this for us.
  2103         // Setting provider does this for us.
  2104         PRINT( _L("Calling iAdvancedSettings->SetExposureCompensationStep..") );
  2104         PRINT( _L("Calling iAdvancedSettings->SetExposureCompensationStep..") );
  2105         iAdvancedSettings->SetExposureCompensationStep( step );
  2105         iAdvancedSettings->SetExposureCompensationStep( step );
  2127       iAdvancedSettings->GetSupportedIsoRatesL( ISOarray );
  2127       iAdvancedSettings->GetSupportedIsoRatesL( ISOarray );
  2128       iSettingProvider.SetSupportedISORatesL( ISOarray );
  2128       iSettingProvider.SetSupportedISORatesL( ISOarray );
  2129       iSettingProvider.ProvideCameraSettingL( aSettingId, &iso );
  2129       iSettingProvider.ProvideCameraSettingL( aSettingId, &iso );
  2130       callback = ETrue;
  2130       callback = ETrue;
  2131       CleanupStack::PopAndDestroy( &ISOarray );
  2131       CleanupStack::PopAndDestroy( &ISOarray );
  2132       
  2132 
  2133       PRINT1( _L("Camera <> Setting ISO rate to: %d"), iso );
  2133       PRINT1( _L("Camera <> Setting ISO rate to: %d"), iso );
  2134       if( !iso )
  2134       if( !iso )
  2135         {
  2135         {
  2136         // ISO Auto
  2136         // ISO Auto
  2137         iAdvancedSettings->SetISORateL( 
  2137         iAdvancedSettings->SetISORateL(
  2138                 CCamera::CCameraAdvancedSettings::EISOAutoUnPrioritised, iso );  
  2138                 CCamera::CCameraAdvancedSettings::EISOAutoUnPrioritised, iso );
  2139         }
  2139         }
  2140       else if( IsSupportedValue( iso, 
  2140       else if( IsSupportedValue( iso,
  2141                                  iAdvancedSettingInfo.iIsoRatesSupport,
  2141                                  iAdvancedSettingInfo.iIsoRatesSupport,
  2142                                  EDiscreteSteps ) ) 
  2142                                  EDiscreteSteps ) )
  2143         {
  2143         {
  2144         // Selected ISO rate  
  2144         // Selected ISO rate
  2145         iAdvancedSettings->SetISORateL( 
  2145         iAdvancedSettings->SetISORateL(
  2146                 CCamera::CCameraAdvancedSettings::EISOManual, iso );
  2146                 CCamera::CCameraAdvancedSettings::EISOManual, iso );
  2147         }
  2147         }
  2148       else
  2148       else
  2149         {
  2149         {
  2150         User::Leave( KErrNotSupported );  
  2150         User::Leave( KErrNotSupported );
  2151         }
  2151         }
  2152       break;
  2152       break;
  2153       }
  2153       }
  2154 #endif
  2154 #endif
  2155     // -------------------------------
  2155     // -------------------------------
  2165 #endif // CAMERAAPP_CAE_FIX
  2165 #endif // CAMERAAPP_CAE_FIX
  2166         {
  2166         {
  2167         iCamera->SetWhiteBalanceL( params().iWhiteBalanceMode );
  2167         iCamera->SetWhiteBalanceL( params().iWhiteBalanceMode );
  2168 #ifdef CAMERAAPP_CAPI_V2
  2168 #ifdef CAMERAAPP_CAPI_V2
  2169         callback = ETrue;
  2169         callback = ETrue;
  2170 #endif      
  2170 #endif
  2171         }
  2171         }
  2172       break;
  2172       break;
  2173       }
  2173       }
  2174     // -------------------------------
  2174     // -------------------------------
  2175 #ifdef CAMERAAPP_CAPI_V2_IP
  2175 #ifdef CAMERAAPP_CAPI_V2_IP
  2178       {
  2178       {
  2179       CheckNonNullL( iImageProcessor, KErrNotSupported );
  2179       CheckNonNullL( iImageProcessor, KErrNotSupported );
  2180       CIP::TEffect effect( CIP::EEffectNone );
  2180       CIP::TEffect effect( CIP::EEffectNone );
  2181       iSettingProvider.ProvideCameraSettingL( aSettingId, &effect );
  2181       iSettingProvider.ProvideCameraSettingL( aSettingId, &effect );
  2182 
  2182 
  2183       if( IsSupportedValue( effect, 
  2183       if( IsSupportedValue( effect,
  2184                             iAdvancedSettingInfo.iColourEffectSupport, 
  2184                             iAdvancedSettingInfo.iColourEffectSupport,
  2185                             iAdvancedSettingInfo.iColourEffectValueInfo ) )
  2185                             iAdvancedSettingInfo.iColourEffectValueInfo ) )
  2186         {
  2186         {
  2187         iImageProcessor->SetTransformationValue( KUidECamEventImageProcessingEffect, effect );
  2187         iImageProcessor->SetTransformationValue( KUidECamEventImageProcessingEffect, effect );
  2188         callback = ETrue;
  2188         callback = ETrue;
  2189         }
  2189         }
  2197       {
  2197       {
  2198       CheckNonNullL( iImageProcessor, KErrNotSupported );
  2198       CheckNonNullL( iImageProcessor, KErrNotSupported );
  2199       TInt sharpness( 0 );
  2199       TInt sharpness( 0 );
  2200       iSettingProvider.ProvideCameraSettingL( aSettingId, &sharpness );
  2200       iSettingProvider.ProvideCameraSettingL( aSettingId, &sharpness );
  2201 
  2201 
  2202       if( IsSupportedValue( sharpness, 
  2202       if( IsSupportedValue( sharpness,
  2203                             iAdvancedSettingInfo.iSharpnessSupport, 
  2203                             iAdvancedSettingInfo.iSharpnessSupport,
  2204                             iAdvancedSettingInfo.iSharpnessValueInfo ) )
  2204                             iAdvancedSettingInfo.iSharpnessValueInfo ) )
  2205         {
  2205         {
  2206         iImageProcessor->SetTransformationValue( KUidECamEventImageProcessingAdjustSharpness, sharpness );
  2206         iImageProcessor->SetTransformationValue( KUidECamEventImageProcessingAdjustSharpness, sharpness );
  2207         callback = ETrue;
  2207         callback = ETrue;
  2208         }
  2208         }
  2242 #endif
  2242 #endif
  2243         {
  2243         {
  2244 #ifdef CAMERAAPP_CAPI_V2_ADV
  2244 #ifdef CAMERAAPP_CAPI_V2_ADV
  2245         if( iAdvancedSettingInfo.iDigitalZoomSupport.Count() > zoom )
  2245         if( iAdvancedSettingInfo.iDigitalZoomSupport.Count() > zoom )
  2246             iAdvancedSettings->SetDigitalZoom( iAdvancedSettingInfo.iDigitalZoomSupport[zoom] );
  2246             iAdvancedSettings->SetDigitalZoom( iAdvancedSettingInfo.iDigitalZoomSupport[zoom] );
  2247           else 
  2247           else
  2248             User::Leave( KErrNotSupported );
  2248             User::Leave( KErrNotSupported );
  2249         callback = ETrue;
  2249         callback = ETrue;
  2250         
  2250 
  2251 #else
  2251 #else
  2252         // Note: Even if the method is misleadingly named
  2252         // Note: Even if the method is misleadingly named
  2253         //       CCamera::SetDigitalZoomFactorL, the values are
  2253         //       CCamera::SetDigitalZoomFactorL, the values are
  2254         //       zoom steps, not zoom factors.
  2254         //       zoom steps, not zoom factors.
  2255         iCamera->SetDigitalZoomFactorL( zoom );
  2255         iCamera->SetDigitalZoomFactorL( zoom );
  2256 #endif
  2256 #endif
  2257       
  2257 
  2258         }
  2258         }
  2259       break;
  2259       break;
  2260       }
  2260       }
  2261     // -------------------------------
  2261     // -------------------------------
  2262 #ifdef CAMERAAPP_CAPI_V2_ADV
  2262 #ifdef CAMERAAPP_CAPI_V2_ADV
  2273     case ECameraSettingStabilization:
  2273     case ECameraSettingStabilization:
  2274       {
  2274       {
  2275       PRINT( _L("Camera <> CCamCameraController::ProcessSettingL ECameraSettingStabilization") );
  2275       PRINT( _L("Camera <> CCamCameraController::ProcessSettingL ECameraSettingStabilization") );
  2276       TPckgBuf<TCamSettingDataStabilization> stabilization;
  2276       TPckgBuf<TCamSettingDataStabilization> stabilization;
  2277       iSettingProvider.ProvideCameraSettingL( aSettingId, &stabilization );
  2277       iSettingProvider.ProvideCameraSettingL( aSettingId, &stabilization );
  2278       
  2278 
  2279       // Check that the values are supported..
  2279       // Check that the values are supported..
  2280       TBool modeOk    = ( CAS::EStabilizationModeOff == stabilization().iMode
  2280       TBool modeOk    = ( CAS::EStabilizationModeOff == stabilization().iMode
  2281                        || iAdvancedSettingInfo.iStabilizationModeSupport & stabilization().iMode );
  2281                        || iAdvancedSettingInfo.iStabilizationModeSupport & stabilization().iMode );
  2282       TBool effectOk  = ( CAS::EStabilizationOff     == stabilization().iEffect
  2282       TBool effectOk  = ( CAS::EStabilizationOff     == stabilization().iEffect
  2283                        || iAdvancedSettingInfo.iStabilizationEffectSupport & stabilization().iEffect );
  2283                        || iAdvancedSettingInfo.iStabilizationEffectSupport & stabilization().iEffect );
  2284       TBool complexOk = ( CAS::EStabilizationComplexityAuto == stabilization().iComplexity 
  2284       TBool complexOk = ( CAS::EStabilizationComplexityAuto == stabilization().iComplexity
  2285                        || iAdvancedSettingInfo.iStabilizationComplexitySupport & stabilization().iComplexity );
  2285                        || iAdvancedSettingInfo.iStabilizationComplexitySupport & stabilization().iComplexity );
  2286 
  2286 
  2287       if( modeOk && effectOk && complexOk )
  2287       if( modeOk && effectOk && complexOk )
  2288         {
  2288         {
  2289         PRINT1( _L("Camera <> CCamCameraController::ProcessSettingL set stabilization mode=%d"), stabilization().iMode );
  2289         PRINT1( _L("Camera <> CCamCameraController::ProcessSettingL set stabilization mode=%d"), stabilization().iMode );
  2290         iAdvancedSettings->SetStabilizationMode      ( stabilization().iMode       );
  2290         iAdvancedSettings->SetStabilizationMode      ( stabilization().iMode       );
  2291         iAdvancedSettings->SetStabilizationEffect    ( stabilization().iEffect     );
  2291         iAdvancedSettings->SetStabilizationEffect    ( stabilization().iEffect     );
  2292         iAdvancedSettings->SetStabilizationComplexity( stabilization().iComplexity );
  2292         iAdvancedSettings->SetStabilizationComplexity( stabilization().iComplexity );
  2293         // Events:
  2293         // Events:
  2294         //   KUidECamEventCameraSettingStabilizationMode 
  2294         //   KUidECamEventCameraSettingStabilizationMode
  2295         //   KUidECamEventCameraSettingsStabilizationEffect 
  2295         //   KUidECamEventCameraSettingsStabilizationEffect
  2296         //   KUidECamEventSettingsStabilizationAlgorithmComplexity 
  2296         //   KUidECamEventSettingsStabilizationAlgorithmComplexity
  2297         // We use the latest one to determine when we can continue.
  2297         // We use the latest one to determine when we can continue.
  2298         // Do not change above order unless CCamSettingConversion::Map2EventUidValue
  2298         // Do not change above order unless CCamSettingConversion::Map2EventUidValue
  2299         // is edited..
  2299         // is edited..
  2300         }
  2300         }
  2301       else
  2301       else
  2305 
  2305 
  2306       callback = ETrue;
  2306       callback = ETrue;
  2307       break;
  2307       break;
  2308       }
  2308       }
  2309     // -------------------------------
  2309     // -------------------------------
  2310     case ECameraSettingContAF:  
  2310     case ECameraSettingContAF:
  2311       {
  2311       {
  2312       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
  2312       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
  2313       if ( appUi->AppController().UiConfigManagerPtr()->IsContinuosAutofocusSupported() )
  2313       if ( appUi->AppController().UiConfigManagerPtr()->IsContinuosAutofocusSupported() )
  2314          {
  2314          {
  2315          TBool isContAFon( iAdvancedSettings->AutoFocusType() & 
  2315          TBool isContAFon( iAdvancedSettings->AutoFocusType() &
  2316                            CAS::EAutoFocusTypeContinuous );
  2316                            CAS::EAutoFocusTypeContinuous );
  2317          if( IsFlagOn( iInfo.iState, ECamVideoOn ) )
  2317          if( IsFlagOn( iInfo.iState, ECamVideoOn ) )
  2318             {
  2318             {
  2319             TBool contAF( ETrue );
  2319             TBool contAF( ETrue );
  2320             iSettingProvider.ProvideCameraSettingL( aSettingId, &contAF );
  2320             iSettingProvider.ProvideCameraSettingL( aSettingId, &contAF );
  2347           callback = IsFlagOn( iInfo.iState, ECamVideoOn );
  2347           callback = IsFlagOn( iInfo.iState, ECamVideoOn );
  2348           }
  2348           }
  2349         }
  2349         }
  2350       else
  2350       else
  2351         {
  2351         {
  2352         // 
  2352         //
  2353         PRINT( _L("Camera <> Video file size too early, NOT SET!!") );        
  2353         PRINT( _L("Camera <> Video file size too early, NOT SET!!") );
  2354         }
  2354         }
  2355       break;
  2355       break;
  2356       }
  2356       }
  2357     // -------------------------------
  2357     // -------------------------------
  2358     case ECameraSettingFileName:
  2358     case ECameraSettingFileName:
  2374         // and needs to be waited.
  2374         // and needs to be waited.
  2375         callback = IsFlagOn( iInfo.iState, ECamVideoOn );
  2375         callback = IsFlagOn( iInfo.iState, ECamVideoOn );
  2376         }
  2376         }
  2377       else
  2377       else
  2378         {
  2378         {
  2379         PRINT( _L("Camera <> Video name too early, NOT SET!!") );        
  2379         PRINT( _L("Camera <> Video name too early, NOT SET!!") );
  2380         }
  2380         }
  2381       break;
  2381       break;
  2382       }
  2382       }
  2383     // -------------------------------
  2383     // -------------------------------
  2384     case ECameraSettingAudioMute:
  2384     case ECameraSettingAudioMute:
  2396           callback = IsFlagOn( iInfo.iState, ECamVideoOn );
  2396           callback = IsFlagOn( iInfo.iState, ECamVideoOn );
  2397           }
  2397           }
  2398         }
  2398         }
  2399       else
  2399       else
  2400         {
  2400         {
  2401         PRINT( _L("Camera <> Video mute too early, NOT SET!!") );        
  2401         PRINT( _L("Camera <> Video mute too early, NOT SET!!") );
  2402         }        
  2402         }
  2403       break;
  2403       break;
  2404       }
  2404       }
  2405     // -------------------------------
  2405     // -------------------------------
  2406     case ECameraSettingFacetracking:
  2406     case ECameraSettingFacetracking:
  2407       {
  2407       {
  2419     // -------------------------------
  2419     // -------------------------------
  2420     // Image orientation
  2420     // Image orientation
  2421     case ECameraSettingOrientation:
  2421     case ECameraSettingOrientation:
  2422       {
  2422       {
  2423       CheckNonNullL( iCustomInterfaceOrientation, KErrNotSupported );
  2423       CheckNonNullL( iCustomInterfaceOrientation, KErrNotSupported );
  2424       MCameraOrientation::TOrientation 
  2424       MCameraOrientation::TOrientation
  2425         orientation( MCameraOrientation::EOrientation0 );
  2425         orientation( MCameraOrientation::EOrientation0 );
  2426       iSettingProvider.ProvideCameraSettingL( aSettingId, &orientation );
  2426       iSettingProvider.ProvideCameraSettingL( aSettingId, &orientation );
  2427 
  2427 
  2428       if ( iInfo.iCurrentCamera != KPrimaryCameraIndex && 
  2428       if ( iInfo.iCurrentCamera != KPrimaryCameraIndex &&
  2429            orientation == MCameraOrientation::EOrientation90 )
  2429            orientation == MCameraOrientation::EOrientation90 )
  2430         {
  2430         {
  2431         PRINT( _L("Camera <> Rotate portrait secondary camera image 270 degrees") );
  2431         PRINT( _L("Camera <> Rotate portrait secondary camera image 270 degrees") );
  2432         orientation = MCameraOrientation::EOrientation270;
  2432         orientation = MCameraOrientation::EOrientation270;
  2433         }
  2433         }
  2456 
  2456 
  2457 // ---------------------------------------------------------------------------
  2457 // ---------------------------------------------------------------------------
  2458 //
  2458 //
  2459 // ---------------------------------------------------------------------------
  2459 // ---------------------------------------------------------------------------
  2460 //
  2460 //
  2461 TInt 
  2461 TInt
  2462 CCamCameraController
  2462 CCamCameraController
  2463 ::ProcessOneRequestL( const TCamCameraRequestId& aRequestId )
  2463 ::ProcessOneRequestL( const TCamCameraRequestId& aRequestId )
  2464   {
  2464   {
  2465   PRINT( _L("Camera => CCamCameraController::ProcessOneRequestL") );
  2465   PRINT( _L("Camera => CCamCameraController::ProcessOneRequestL") );
  2466   PRINT2( _L("Camera <> processing request [%s] id:%d "), 
  2466   PRINT2( _L("Camera <> processing request [%s] id:%d "),
  2467           KCamRequestNames[aRequestId], 
  2467           KCamRequestNames[aRequestId],
  2468           aRequestId );
  2468           aRequestId );
  2469 
  2469 
  2470   TInt readyForNext( ETrue );
  2470   TInt readyForNext( ETrue );
  2471   
  2471 
  2472   // Order from most time critical / frequent 
  2472   // Order from most time critical / frequent
  2473   // to less time critical / seldom.
  2473   // to less time critical / seldom.
  2474   // Handled in submethods to preserve readability.
  2474   // Handled in submethods to preserve readability.
  2475   // -----------------------------------------------------
  2475   // -----------------------------------------------------
  2476   switch( aRequestId )
  2476   switch( aRequestId )
  2477     {
  2477     {
  2528 
  2528 
  2529 // ---------------------------------------------------------------------------
  2529 // ---------------------------------------------------------------------------
  2530 // ProcessControlStartupRequestL
  2530 // ProcessControlStartupRequestL
  2531 // ---------------------------------------------------------------------------
  2531 // ---------------------------------------------------------------------------
  2532 //
  2532 //
  2533 TInt 
  2533 TInt
  2534 CCamCameraController
  2534 CCamCameraController
  2535 ::ProcessControlStartupRequestL( const TCamCameraRequestId& aRequestId )
  2535 ::ProcessControlStartupRequestL( const TCamCameraRequestId& aRequestId )
  2536   {
  2536   {
  2537   PRINT1( _L("Camera => CCamCameraController::ProcessControlStartupRequestL [%s]"),
  2537   PRINT1( _L("Camera => CCamCameraController::ProcessControlStartupRequestL [%s]"),
  2538           KCamRequestNames[aRequestId] );
  2538           KCamRequestNames[aRequestId] );
  2545     CAMERAAPP_PERF_CONTROLLER_START( ECamRequestReserve );
  2545     CAMERAAPP_PERF_CONTROLLER_START( ECamRequestReserve );
  2546     iCamera->Reserve();
  2546     iCamera->Reserve();
  2547     // If UIOrientationOverrideAPI is used, ui construction is completed while
  2547     // If UIOrientationOverrideAPI is used, ui construction is completed while
  2548     // waiting for Reserve to complete, event sent here to continue ui construction
  2548     // waiting for Reserve to complete, event sent here to continue ui construction
  2549     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
  2549     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
  2550     if ( appUi->AppController().UiConfigManagerPtr()->IsUIOrientationOverrideSupported() )    
  2550     if ( appUi->AppController().UiConfigManagerPtr()->IsUIOrientationOverrideSupported() )
  2551       {
  2551       {
  2552       NotifyObservers( KErrNone, 
  2552       NotifyObservers( KErrNone,
  2553                        ECamCameraEventReserveRequested,
  2553                        ECamCameraEventReserveRequested,
  2554                        ECamCameraEventClassBasicControl );
  2554                        ECamCameraEventClassBasicControl );
  2555       }
  2555       }
  2556     }
  2556     }
  2557   // -------------------------------------------------------
  2557   // -------------------------------------------------------
  2561     CheckFlagOnL ( iInfo.iState, ECamReserved, KErrNotReady );
  2561     CheckFlagOnL ( iInfo.iState, ECamReserved, KErrNotReady );
  2562     CheckFlagOffL( iInfo.iState, ECamPowerOn,  KErrInUse    );
  2562     CheckFlagOffL( iInfo.iState, ECamPowerOn,  KErrInUse    );
  2563 
  2563 
  2564     CAMERAAPP_PERF_CONTROLLER_START( ECamRequestPowerOn );
  2564     CAMERAAPP_PERF_CONTROLLER_START( ECamRequestPowerOn );
  2565 
  2565 
  2566     iCamera->PowerOn(); 
  2566     iCamera->PowerOn();
  2567     }
  2567     }
  2568   // -------------------------------------------------------
  2568   // -------------------------------------------------------
  2569   // Unknown
  2569   // Unknown
  2570   else
  2570   else
  2571     {
  2571     {
  2572     Panic( ECamCameraControllerCorrupt );
  2572     Panic( ECamCameraControllerCorrupt );
  2573     }
  2573     }
  2574   // -------------------------------------------------------
  2574   // -------------------------------------------------------
  2575   iReleasedByUi = EFalse;  
  2575   iReleasedByUi = EFalse;
  2576   PRINT( _L("Camera <= CCamCameraController::ProcessControlStartupRequestL") );
  2576   PRINT( _L("Camera <= CCamCameraController::ProcessControlStartupRequestL") );
  2577   // Callback needs to be received before we can continue.
  2577   // Callback needs to be received before we can continue.
  2578   return EFalse;
  2578   return EFalse;
  2579   }
  2579   }
  2580 
  2580 
  2581 // ---------------------------------------------------------------------------
  2581 // ---------------------------------------------------------------------------
  2582 // ProcessControlShutdownRequest
  2582 // ProcessControlShutdownRequest
  2583 // ---------------------------------------------------------------------------
  2583 // ---------------------------------------------------------------------------
  2584 //
  2584 //
  2585 TInt 
  2585 TInt
  2586 CCamCameraController
  2586 CCamCameraController
  2587 ::ProcessControlShutdownRequest( const TCamCameraRequestId& aRequestId )
  2587 ::ProcessControlShutdownRequest( const TCamCameraRequestId& aRequestId )
  2588   {
  2588   {
  2589   PRINT( _L("Camera => CCamCameraController::ProcessControlShutdownRequest") );  
  2589   PRINT( _L("Camera => CCamCameraController::ProcessControlShutdownRequest") );
  2590   // -------------------------------------------------------
  2590   // -------------------------------------------------------
  2591   // Power off
  2591   // Power off
  2592   if( ECamRequestPowerOff == aRequestId )
  2592   if( ECamRequestPowerOff == aRequestId )
  2593     {
  2593     {
  2594     if( IsFlagOn( iInfo.iState, ECamPowerOn ) ) 
  2594     if( IsFlagOn( iInfo.iState, ECamPowerOn ) )
  2595       {
  2595       {
  2596       // -------------------------------
  2596       // -------------------------------
  2597       // Release image or video capture
  2597       // Release image or video capture
  2598       if( IsFlagOn( iInfo.iState, ECamImageOn ) )
  2598       if( IsFlagOn( iInfo.iState, ECamImageOn ) )
  2599         {
  2599         {
  2600         // Leaves only if state is wrong (already checked here).
  2600         // Leaves only if state is wrong (already checked here).
  2601         ProcessImageShutdownRequest( ECamRequestImageRelease );
  2601         ProcessImageShutdownRequest( ECamRequestImageRelease );
  2602         NotifyObservers( KErrNone, 
  2602         NotifyObservers( KErrNone,
  2603                          ECamCameraEventImageRelease,
  2603                          ECamCameraEventImageRelease,
  2604                          ECamCameraEventClassImage );
  2604                          ECamCameraEventClassImage );
  2605         }
  2605         }
  2606       else if( IsFlagOn( iInfo.iState, ECamVideoOn ) )
  2606       else if( IsFlagOn( iInfo.iState, ECamVideoOn ) )
  2607         {
  2607         {
  2608         TRAP_IGNORE( ProcessVideoRequestL( ECamRequestVideoRelease ) );
  2608         TRAP_IGNORE( ProcessVideoRequestL( ECamRequestVideoRelease ) );
  2609         NotifyObservers( KErrNone, 
  2609         NotifyObservers( KErrNone,
  2610                          ECamCameraEventVideoRelease,
  2610                          ECamCameraEventVideoRelease,
  2611                          ECamCameraEventClassVideo );
  2611                          ECamCameraEventClassVideo );
  2612         }
  2612         }
  2613       else
  2613       else
  2614         {
  2614         {
  2637 #ifdef CAMERAAPP_CAE_FIX
  2637 #ifdef CAMERAAPP_CAE_FIX
  2638       if( iCaeInUse )
  2638       if( iCaeInUse )
  2639         {
  2639         {
  2640         iCaeEngine->PowerOff();
  2640         iCaeEngine->PowerOff();
  2641         }
  2641         }
  2642       else      
  2642       else
  2643 #endif // CAMERAAPP_CAE_FIX
  2643 #endif // CAMERAAPP_CAE_FIX
  2644         {
  2644         {
  2645         iCamera->PowerOff(); 
  2645         iCamera->PowerOff();
  2646         }
  2646         }
  2647       // -------------------------------
  2647       // -------------------------------
  2648       }
  2648       }
  2649     ClearFlags( iInfo.iState, ECamPowerOn );
  2649     ClearFlags( iInfo.iState, ECamPowerOn );
  2650     }
  2650     }
  2672         }
  2672         }
  2673       else
  2673       else
  2674 #endif // CAMERAAPP_CAE_FIX
  2674 #endif // CAMERAAPP_CAE_FIX
  2675         {
  2675         {
  2676         iCamera->Release();
  2676         iCamera->Release();
  2677         iReleasedByUi = ETrue;  
  2677         iReleasedByUi = ETrue;
  2678         if( iIveRecoveryCount > 0 )
  2678         if( iIveRecoveryCount > 0 )
  2679             {
  2679             {
  2680             HandleReserveLostEvent( KErrNone );
  2680             HandleReserveLostEvent( KErrNone );
  2681             }
  2681             }
  2682         }
  2682         }
  2683       }
  2683       }
  2684     PRINT( _L("Camera <> released, reset info") );  
  2684     PRINT( _L("Camera <> released, reset info") );
  2685 
  2685 
  2686     // Reset our info, but preserve busy flag and camera index.
  2686     // Reset our info, but preserve busy flag and camera index.
  2687     // Sets iInfo.iState to ECamIdle.
  2687     // Sets iInfo.iState to ECamIdle.
  2688     iInfo.Reset( ETrue, ETrue ); 
  2688     iInfo.Reset( ETrue, ETrue );
  2689     }
  2689     }
  2690   // -------------------------------------------------------
  2690   // -------------------------------------------------------
  2691   // Unknown
  2691   // Unknown
  2692   else
  2692   else
  2693     {
  2693     {
  2694     Panic( ECamCameraControllerCorrupt );
  2694     Panic( ECamCameraControllerCorrupt );
  2695     }
  2695     }
  2696   // -------------------------------------------------------
  2696   // -------------------------------------------------------
  2697   PRINT( _L("Camera <= CCamCameraController::ProcessControlShutdownRequest") );  
  2697   PRINT( _L("Camera <= CCamCameraController::ProcessControlShutdownRequest") );
  2698   
  2698 
  2699   // No callback needs to be waited.
  2699   // No callback needs to be waited.
  2700   return ETrue;
  2700   return ETrue;
  2701   }
  2701   }
  2702 
  2702 
  2703 // ---------------------------------------------------------------------------
  2703 // ---------------------------------------------------------------------------
  2704 // ProcessViewfinderRequestL
  2704 // ProcessViewfinderRequestL
  2705 // ---------------------------------------------------------------------------
  2705 // ---------------------------------------------------------------------------
  2706 //
  2706 //
  2707 TInt 
  2707 TInt
  2708 CCamCameraController
  2708 CCamCameraController
  2709 ::ProcessVfRequestL( const TCamCameraRequestId& aRequestId )
  2709 ::ProcessVfRequestL( const TCamCameraRequestId& aRequestId )
  2710   {
  2710   {
  2711   CheckFlagOnL( iInfo.iState, ECamPowerOn, KErrNotReady );
  2711   CheckFlagOnL( iInfo.iState, ECamPowerOn, KErrNotReady );
  2712 
  2712 
  2750 // ---------------------------------------------------------------------------
  2750 // ---------------------------------------------------------------------------
  2751 //
  2751 //
  2752 void
  2752 void
  2753 CCamCameraController::InitViewfinderL( const TCamViewfinderMode& aMode )
  2753 CCamCameraController::InitViewfinderL( const TCamViewfinderMode& aMode )
  2754   {
  2754   {
  2755   PRINT( _L("Camera => CCamCameraController::InitViewfinderL") );  
  2755   PRINT( _L("Camera => CCamCameraController::InitViewfinderL") );
  2756 
  2756 
  2757   // Check the old viewfinder is released now.
  2757   // Check the old viewfinder is released now.
  2758   // No further checks made here.
  2758   // No further checks made here.
  2759   __ASSERT_DEBUG( ECamTriIdle == iInfo.iVfState, Panic( ECamCameraControllerCorrupt ) );
  2759   __ASSERT_DEBUG( ECamTriIdle == iInfo.iVfState, Panic( ECamCameraControllerCorrupt ) );
  2760 
  2760 
  2763     {
  2763     {
  2764     // ---------------------------------
  2764     // ---------------------------------
  2765     case ECamViewfinderDirect:
  2765     case ECamViewfinderDirect:
  2766       {
  2766       {
  2767       // Don't proceed if not supported by camera.
  2767       // Don't proceed if not supported by camera.
  2768       CheckFlagOnL( iCameraInfo.iOptionsSupported, 
  2768       CheckFlagOnL( iCameraInfo.iOptionsSupported,
  2769                     TCameraInfo::EViewFinderDirectSupported,
  2769                     TCameraInfo::EViewFinderDirectSupported,
  2770                     KErrNotSupported );
  2770                     KErrNotSupported );
  2771       
  2771 
  2772   #ifdef CAMERAAPP_CAPI_V2_DVF
  2772   #ifdef CAMERAAPP_CAPI_V2_DVF
  2773       PRINT( _L("Camera <> Creating CCameraDirectViewFinder instance") );
  2773       PRINT( _L("Camera <> Creating CCameraDirectViewFinder instance") );
  2774       if( iDirectViewfinder )
  2774       if( iDirectViewfinder )
  2775         {
  2775         {
  2776         	delete iDirectViewfinder;
  2776         	delete iDirectViewfinder;
  2777         	iDirectViewfinder=NULL;
  2777         	iDirectViewfinder=NULL;
  2778         }
  2778         }
  2779       iDirectViewfinder = CCamera::CCameraDirectViewFinder::NewL( *iCamera );
  2779       iDirectViewfinder = CCamera::CCameraDirectViewFinder::NewL( *iCamera );
  2780   #else
  2780   #else
  2781       // not implemented 
  2781       // not implemented
  2782       Panic( ECamCameraControllerUnsupported );      
  2782       Panic( ECamCameraControllerUnsupported );
  2783   #endif
  2783   #endif
  2784       iInfo.iVfState  = ECamTriInactive;
  2784       iInfo.iVfState  = ECamTriInactive;
  2785       iInfo.iVfMode   = ECamViewfinderDirect;
  2785       iInfo.iVfMode   = ECamViewfinderDirect;
  2786       break;
  2786       break;
  2787       }
  2787       }
  2788     // ---------------------------------
  2788     // ---------------------------------
  2789     case ECamViewfinderBitmap:
  2789     case ECamViewfinderBitmap:
  2790       {
  2790       {
  2791       // Don't proceed if not supported by camera.
  2791       // Don't proceed if not supported by camera.
  2792       CheckFlagOnL( iCameraInfo.iOptionsSupported, 
  2792       CheckFlagOnL( iCameraInfo.iOptionsSupported,
  2793                     TCameraInfo::EViewFinderBitmapsSupported,
  2793                     TCameraInfo::EViewFinderBitmapsSupported,
  2794                     KErrNotSupported );
  2794                     KErrNotSupported );
  2795   
  2795 
  2796       iInfo.iVfState  = ECamTriInactive;
  2796       iInfo.iVfState  = ECamTriInactive;
  2797       iInfo.iVfMode   = ECamViewfinderBitmap;
  2797       iInfo.iVfMode   = ECamViewfinderBitmap;
  2798       break;
  2798       break;
  2799       }
  2799       }
  2800     // ---------------------------------
  2800     // ---------------------------------
  2802       // Mode is "none", so no init needed.
  2802       // Mode is "none", so no init needed.
  2803       break;
  2803       break;
  2804     // ---------------------------------
  2804     // ---------------------------------
  2805     default:
  2805     default:
  2806       // Unknown mode
  2806       // Unknown mode
  2807       Panic( ECamCameraControllerUnsupported );     
  2807       Panic( ECamCameraControllerUnsupported );
  2808       break;      
  2808       break;
  2809     // ---------------------------------
  2809     // ---------------------------------
  2810     }
  2810     }
  2811   PRINT( _L("Camera <= CCamCameraController::InitViewfinderL") );  
  2811   PRINT( _L("Camera <= CCamCameraController::InitViewfinderL") );
  2812   }
  2812   }
  2813 
  2813 
  2814 // ---------------------------------------------------------------------------
  2814 // ---------------------------------------------------------------------------
  2815 // ---------------------------------------------------------------------------
  2815 // ---------------------------------------------------------------------------
  2816 void
  2816 void
  2819   {
  2819   {
  2820   PRINT( _L("Camera => CCamCameraController::ProcessVfStartRequestL") );
  2820   PRINT( _L("Camera => CCamCameraController::ProcessVfStartRequestL") );
  2821 
  2821 
  2822 #ifdef __WINSCW__
  2822 #ifdef __WINSCW__
  2823   const TCamViewfinderMode KTargetMode( ECamViewfinderBitmap );
  2823   const TCamViewfinderMode KTargetMode( ECamViewfinderBitmap );
  2824 #else    
  2824 #else
  2825     
  2825 
  2826   TPckgBuf<TCamViewfinderMode> mode;
  2826   TPckgBuf<TCamViewfinderMode> mode;
  2827   iSettingProvider.ProvideCameraParamL( ECameraParamVfMode, &mode );
  2827   iSettingProvider.ProvideCameraParamL( ECameraParamVfMode, &mode );
  2828   
  2828 
  2829   // If the viewfinder mode needs to be changed,
  2829   // If the viewfinder mode needs to be changed,
  2830   // first stop and release resources related to the old viewfinder type.
  2830   // first stop and release resources related to the old viewfinder type.
  2831   const TCamViewfinderMode KTargetMode( mode() );
  2831   const TCamViewfinderMode KTargetMode( mode() );
  2832 #endif
  2832 #endif
  2833 
  2833 
  2835    && KTargetMode        != iInfo.iVfMode )
  2835    && KTargetMode        != iInfo.iVfMode )
  2836     {
  2836     {
  2837     ProcessVfRelaseRequest();
  2837     ProcessVfRelaseRequest();
  2838     }
  2838     }
  2839 
  2839 
  2840   // Check that application is still in foreground, if not then return
  2840   // Check that application is still in foreground, if not, then vf not started.
  2841   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
  2841   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
  2842 
  2842   if ( appUi && appUi->AppInBackground( ETrue ) )
  2843   if ( !appUi->AppInBackground( ETrue ) )
  2843     {
       
  2844     // Notify appUi that we did not start viewfinder although asked to do so.
       
  2845     appUi->SetViewFinderStoppedStatus( iInfo.iVfState != ECamTriActive );
       
  2846     }
       
  2847   else
  2844     {
  2848     {
  2845     switch( iInfo.iVfState )
  2849     switch( iInfo.iVfState )
  2846       {
  2850       {
  2847       // -----------------------------------------------------
  2851       // -----------------------------------------------------
  2848       case ECamTriIdle:
  2852       case ECamTriIdle:
  2849        PRINT( _L("Camera <> case ECamTriIdle") );
  2853        PRINT( _L("Camera <> case ECamTriIdle") );
  2850   
  2854 
  2851         InitViewfinderL( KTargetMode );
  2855         InitViewfinderL( KTargetMode );
  2852         // << fall through >>
  2856         // << fall through >>
  2853   
  2857 
  2854       case ECamTriInactive:
  2858       case ECamTriInactive:
  2855         {
  2859         {
  2856         // -------------------------------
  2860         // -------------------------------
  2857         PRINT( _L("Camera <> case ECamTriInactive") );
  2861         PRINT( _L("Camera <> case ECamTriInactive") );
  2858   
  2862 
  2859         if( ECamViewfinderDirect == iInfo.iVfMode )
  2863         if( ECamViewfinderDirect == iInfo.iVfMode )
  2860 #ifdef CAMERAAPP_CAPI_V2_DVF
  2864 #ifdef CAMERAAPP_CAPI_V2_DVF
  2861           {
  2865           {
  2862           switch( iDirectViewfinder->ViewFinderState() )
  2866           switch( iDirectViewfinder->ViewFinderState() )
  2863             {
  2867             {
  2866               if ( !iViewfinderWindow )
  2870               if ( !iViewfinderWindow )
  2867                   {
  2871                   {
  2868                   PRINT( _L("Camera <> CCamCameraController::iViewfinderWindow is NULL - cannot start VF!") );
  2872                   PRINT( _L("Camera <> CCamCameraController::iViewfinderWindow is NULL - cannot start VF!") );
  2869                   User::Leave( KErrNotReady );
  2873                   User::Leave( KErrNotReady );
  2870                   }
  2874                   }
  2871   
  2875 
  2872               // Use the same viewfinder position and size as for bitmap viewfinder
  2876               // Use the same viewfinder position and size as for bitmap viewfinder
  2873               TPckgBuf<TCamParamsVfBitmap> params;
  2877               TPckgBuf<TCamParamsVfBitmap> params;
  2874               iSettingProvider.ProvideCameraParamL( ECameraParamVfBitmap, &params );
  2878               iSettingProvider.ProvideCameraParamL( ECameraParamVfBitmap, &params );
  2875   
  2879 
  2876               CEikonEnv* env = CEikonEnv::Static();
  2880               CEikonEnv* env = CEikonEnv::Static();
  2877   
  2881 
  2878               OstTrace0( CAMERAAPP_PERFORMANCE, CCAMCAMERACONTROLLER_PROCESSVFSTARTREQUESTL, "e_CAM_APP_VF_INIT 0" ); //CCORAPP_APP_VF_INIT_END
  2882               OstTrace0( CAMERAAPP_PERFORMANCE, CCAMCAMERACONTROLLER_PROCESSVFSTARTREQUESTL, "e_CAM_APP_VF_INIT 0" ); //CCORAPP_APP_VF_INIT_END
  2879               OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMCAMERACONTROLLER_PROCESSVFSTARTREQUESTL, "e_CAM_APP_OVERLAY_INIT 0" ); //CCORAPP_APP_OVERLAY_INIT_END
  2883               OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMCAMERACONTROLLER_PROCESSVFSTARTREQUESTL, "e_CAM_APP_OVERLAY_INIT 0" ); //CCORAPP_APP_OVERLAY_INIT_END
  2880   
  2884 
  2881               TInt orgPos = SetVfWindowOrdinal(); // Set visible
  2885               TInt orgPos = SetVfWindowOrdinal(); // Set visible
  2882               iCamera->StartViewFinderDirectL(
  2886               iCamera->StartViewFinderDirectL(
  2883                   env->WsSession(),
  2887                   env->WsSession(),
  2884                   *env->ScreenDevice(),
  2888                   *env->ScreenDevice(),
  2885                   *iViewfinderWindow,
  2889                   *iViewfinderWindow,
  2886                   params().iRect );
  2890                   params().iRect );
  2887               (void) SetVfWindowOrdinal( orgPos ); // back to original
  2891               (void) SetVfWindowOrdinal( orgPos ); // back to original
  2888   
  2892 
  2889               CCamAppUi* appUi = static_cast<CCamAppUi*>( env->AppUi() );
  2893               if ( ECamActiveCameraSecondary == appUi->ActiveCamera() )
  2890               if ( ECamActiveCameraSecondary == appUi->ActiveCamera() ) 
       
  2891                   {
  2894                   {
  2892                   iCamera->SetViewFinderMirrorL(ETrue); 
  2895                   iCamera->SetViewFinderMirrorL(ETrue);
  2893                   }
  2896                   }
  2894               // VF started succesfully, reset recovery counter
  2897               // VF started succesfully, reset recovery counter
  2895               delete iIdle;  
  2898               delete iIdle;
  2896               iIdle = NULL;
  2899               iIdle = NULL;
  2897               iIveRecoveryCount = KIveRecoveryCountMax;  
  2900               iIveRecoveryCount = KIveRecoveryCountMax;
  2898               break;
  2901               break;
  2899               }
  2902               }
  2900             case CCamera::CCameraDirectViewFinder::EViewFinderPause:
  2903             case CCamera::CCameraDirectViewFinder::EViewFinderPause:
  2901               {
  2904               {
  2902               iDirectViewfinder->ResumeViewFinderDirectL();
  2905               iDirectViewfinder->ResumeViewFinderDirectL();
  2904               }
  2907               }
  2905             case CCamera::CCameraDirectViewFinder::EViewFinderActive:
  2908             case CCamera::CCameraDirectViewFinder::EViewFinderActive:
  2906               {
  2909               {
  2907               // Already running. Not considered as error.
  2910               // Already running. Not considered as error.
  2908               break;
  2911               break;
  2909               }          
  2912               }
  2910             default:
  2913             default:
  2911               {
  2914               {
  2912               Panic( ECamCameraControllerUnsupported );
  2915               Panic( ECamCameraControllerUnsupported );
  2913               break;
  2916               break;
  2914               }
  2917               }
  2915             }
  2918             }
  2916           }
  2919           }
  2917 #else // CAMERAAPP_CAPI_V2_DVF
  2920 #else // CAMERAAPP_CAPI_V2_DVF
  2918           {
  2921           {
  2919           // No controller support for direct vf.
  2922           // No controller support for direct vf.
  2920           Panic( ECamCameraControllerUnsupported );     
  2923           Panic( ECamCameraControllerUnsupported );
  2921           }
  2924           }
  2922 #endif // CAMERAAPP_CAPI_V2_DVF
  2925 #endif // CAMERAAPP_CAPI_V2_DVF
  2923         // -------------------------------
  2926         // -------------------------------
  2924         else
  2927         else
  2925           {
  2928           {
  2926           PRINT( _L("Camera <> Get bitmap vf details..") );
  2929           PRINT( _L("Camera <> Get bitmap vf details..") );
  2927             
  2930 
  2928           TPckgBuf<TCamParamsVfBitmap> params;
  2931           TPckgBuf<TCamParamsVfBitmap> params;
  2929           iSettingProvider.ProvideCameraParamL( ECameraParamVfBitmap, &params );
  2932           iSettingProvider.ProvideCameraParamL( ECameraParamVfBitmap, &params );
  2930           iInfo.iViewfinderFormat = params().iFormat;
  2933           iInfo.iViewfinderFormat = params().iFormat;
  2931           iInfo.iViewfinderSize   = params().iRect.Size();
  2934           iInfo.iViewfinderSize   = params().iRect.Size();
  2932 #ifdef CAMERAAPP_CAE_FIX
  2935 #ifdef CAMERAAPP_CAE_FIX
  2933           if( iCaeInUse )
  2936           if( iCaeInUse )
  2934             {
  2937             {
  2935             PRINT( _L("Camera <> Call CCaeEngine::StartViewFinderBitmapsL..") );
  2938             PRINT( _L("Camera <> Call CCaeEngine::StartViewFinderBitmapsL..") );
  2936   
  2939 
  2937             OstTrace0( CAMERAAPP_PERFORMANCE, DUP2_CCAMCAMERACONTROLLER_PROCESSVFSTARTREQUESTL, "e_CAM_APP_VF_INIT 0" ); //CCORAPP_APP_VF_INIT_END
  2940             OstTrace0( CAMERAAPP_PERFORMANCE, DUP2_CCAMCAMERACONTROLLER_PROCESSVFSTARTREQUESTL, "e_CAM_APP_VF_INIT 0" ); //CCORAPP_APP_VF_INIT_END
  2938             OstTrace0( CAMERAAPP_PERFORMANCE, DUP3_CCAMCAMERACONTROLLER_PROCESSVFSTARTREQUESTL, "e_CAM_APP_OVERLAY_INIT 0" ); //CCORAPP_APP_OVERLAY_INIT_END
  2941             OstTrace0( CAMERAAPP_PERFORMANCE, DUP3_CCAMCAMERACONTROLLER_PROCESSVFSTARTREQUESTL, "e_CAM_APP_OVERLAY_INIT 0" ); //CCORAPP_APP_OVERLAY_INIT_END
  2939             iCaeEngine->StartViewFinderBitmapsL( iInfo.iViewfinderSize );
  2942             iCaeEngine->StartViewFinderBitmapsL( iInfo.iViewfinderSize );
  2940             }
  2943             }
  2941           else
  2944           else
  2942 #endif // CAMERAAPP_CAE_FIX
  2945 #endif // CAMERAAPP_CAE_FIX
  2943             {
  2946             {
  2944             PRINT( _L("Camera <> Call CCamera::StartViewFinderBitmapsL..") );
  2947             PRINT( _L("Camera <> Call CCamera::StartViewFinderBitmapsL..") );
  2945             OstTrace0( CAMERAAPP_PERFORMANCE, DUP4_CCAMCAMERACONTROLLER_PROCESSVFSTARTREQUESTL, "e_CAM_APP_VF_INIT 0" );  //CCORAPP_APP_VF_INIT_END
  2948             OstTrace0( CAMERAAPP_PERFORMANCE, DUP4_CCAMCAMERACONTROLLER_PROCESSVFSTARTREQUESTL, "e_CAM_APP_VF_INIT 0" );  //CCORAPP_APP_VF_INIT_END
  2946             OstTrace0( CAMERAAPP_PERFORMANCE, DUP5_CCAMCAMERACONTROLLER_PROCESSVFSTARTREQUESTL, "e_CAM_APP_OVERLAY_INIT 0" ); //CCORAPP_APP_OVERLAY_INIT_END
  2949             OstTrace0( CAMERAAPP_PERFORMANCE, DUP5_CCAMCAMERACONTROLLER_PROCESSVFSTARTREQUESTL, "e_CAM_APP_OVERLAY_INIT 0" ); //CCORAPP_APP_OVERLAY_INIT_END
  2947             iCamera->StartViewFinderBitmapsL( iInfo.iViewfinderSize );      
  2950             iCamera->StartViewFinderBitmapsL( iInfo.iViewfinderSize );
  2948   		  
  2951 
  2949   		  if ( params().iMirrorImage )
  2952   		  if ( params().iMirrorImage )
  2950   		  	{
  2953   		  	{
  2951   		   	iCamera->SetViewFinderMirrorL( params().iMirrorImage );	
  2954   		   	iCamera->SetViewFinderMirrorL( params().iMirrorImage );
  2952   		   	}
  2955   		   	}
  2953             }
  2956             }
  2954           }
  2957           }
  2955         // -------------------------------
  2958         // -------------------------------
  2956   
  2959 
  2957         iInfo.iVfState = ECamTriActive;
  2960         iInfo.iVfState = ECamTriActive;
  2958         //view finder started now(set stop status as false)
  2961         //view finder started now(set stop status as false)
  2959         appUi->SetViewFinderStoppedStatus( EFalse );
  2962         appUi->SetViewFinderStoppedStatus( EFalse );
  2960         break;
  2963         break;
  2961         }
  2964         }
  2970       // -----------------------------------------------------
  2973       // -----------------------------------------------------
  2971       default:
  2974       default:
  2972         Panic( ECamCameraControllerCorrupt );
  2975         Panic( ECamCameraControllerCorrupt );
  2973         break;
  2976         break;
  2974       // -----------------------------------------------------
  2977       // -----------------------------------------------------
  2975       } 
  2978       }
  2976     }   
  2979     }
  2977   PRINT( _L("Camera <= CCamCameraController::ProcessVfStartRequestL") );
  2980   PRINT( _L("Camera <= CCamCameraController::ProcessVfStartRequestL") );
  2978   }
  2981   }
  2979 
  2982 
  2980 
  2983 
  2981 
  2984 
  3076     case ECamTriActive:
  3079     case ECamTriActive:
  3077       {
  3080       {
  3078       // Do the stopping first and continue then with release.
  3081       // Do the stopping first and continue then with release.
  3079       // Leaves only if iVfState is ECamVfIdle, which is not the case here.
  3082       // Leaves only if iVfState is ECamVfIdle, which is not the case here.
  3080       TRAP_IGNORE( ProcessVfStopRequestL() );
  3083       TRAP_IGNORE( ProcessVfStopRequestL() );
  3081       
  3084 
  3082       // Need to notify here, because done as a part of other request.
  3085       // Need to notify here, because done as a part of other request.
  3083       NotifyObservers( KErrNone, 
  3086       NotifyObservers( KErrNone,
  3084                        ECamCameraEventVfStop,
  3087                        ECamCameraEventVfStop,
  3085                        ECamCameraEventClassVfControl );
  3088                        ECamCameraEventClassVfControl );
  3086       // << fall through >>
  3089       // << fall through >>
  3087       }
  3090       }
  3088     // -----------------------------------------------------
  3091     // -----------------------------------------------------
  3099         {
  3102         {
  3100         // No further actions needed for bitmap viewfinding.
  3103         // No further actions needed for bitmap viewfinding.
  3101         }
  3104         }
  3102       // These may very well remain as they are.
  3105       // These may very well remain as they are.
  3103       // Atleast for the format there is no "zero" value available.
  3106       // Atleast for the format there is no "zero" value available.
  3104       //    iInfo.iViewfinderSize  
  3107       //    iInfo.iViewfinderSize
  3105       //    iInfo.iViewfinderFormat
  3108       //    iInfo.iViewfinderFormat
  3106       iInfo.iVfState          = ECamTriIdle;
  3109       iInfo.iVfState          = ECamTriIdle;
  3107       iInfo.iVfMode           = ECamViewfinderNone;
  3110       iInfo.iVfMode           = ECamViewfinderNone;
  3108       break;
  3111       break;
  3109       }
  3112       }
  3122 
  3125 
  3123 // ---------------------------------------------------------------------------
  3126 // ---------------------------------------------------------------------------
  3124 // ProcessImageRequestL
  3127 // ProcessImageRequestL
  3125 // ---------------------------------------------------------------------------
  3128 // ---------------------------------------------------------------------------
  3126 //
  3129 //
  3127 TInt 
  3130 TInt
  3128 CCamCameraController
  3131 CCamCameraController
  3129 ::ProcessImageRequestL( const TCamCameraRequestId& aRequestId )
  3132 ::ProcessImageRequestL( const TCamCameraRequestId& aRequestId )
  3130   {
  3133   {
  3131   PRINT( _L("Camera => CCamCameraController::ProcessImageRequestL") );
  3134   PRINT( _L("Camera => CCamCameraController::ProcessImageRequestL") );
  3132   CheckFlagOnL( iInfo.iState, ECamPowerOn, KErrNotReady );
  3135   CheckFlagOnL( iInfo.iState, ECamPowerOn, KErrNotReady );
  3136     {
  3139     {
  3137     // -----------------------------------------------------
  3140     // -----------------------------------------------------
  3138     case ECamRequestImageInit:
  3141     case ECamRequestImageInit:
  3139       {
  3142       {
  3140       // When camera engine still capture don't Init a new capture
  3143       // When camera engine still capture don't Init a new capture
  3141       
  3144 
  3142       if ( ECamCaptureOn == iInfo.iCaptureState )
  3145       if ( ECamCaptureOn == iInfo.iCaptureState )
  3143       	{
  3146       	{
  3144       	return EFalse;
  3147       	return EFalse;
  3145       	}
  3148       	}
  3146       CAMERAAPP_PERF_CONTROLLER_START( ECamRequestImageInit );
  3149       CAMERAAPP_PERF_CONTROLLER_START( ECamRequestImageInit );
  3150       if( iCaeInUse )
  3153       if( iCaeInUse )
  3151         {
  3154         {
  3152         iModeChange       = ECamModeChangeVideo2Image;
  3155         iModeChange       = ECamModeChangeVideo2Image;
  3153         iModeChangePhase  = ECamModeChangePhaseIdle;   // incremented before first step
  3156         iModeChangePhase  = ECamModeChangePhaseIdle;   // incremented before first step
  3154         iModeChangeStatus = KErrNone;
  3157         iModeChangeStatus = KErrNone;
  3155         iActive->IssueRequest();        
  3158         iActive->IssueRequest();
  3156         }
  3159         }
  3157       else 
  3160       else
  3158   #else
  3161   #else
  3159       if( IsFlagOn( iInfo.iState, ECamVideoOn ) )
  3162       if( IsFlagOn( iInfo.iState, ECamVideoOn ) )
  3160         {
  3163         {
  3161         // Release any video recording resources
  3164         // Release any video recording resources
  3162         iCaeEngine->CloseVideoRecording();
  3165         iCaeEngine->CloseVideoRecording();
  3167         {
  3170         {
  3168       PRINT( _L("Camera <> Checking that image capture not ongoing..") );
  3171       PRINT( _L("Camera <> Checking that image capture not ongoing..") );
  3169       CheckEqualsL( iInfo.iCaptureState, ECamCaptureOff, KErrInUse    );
  3172       CheckEqualsL( iInfo.iCaptureState, ECamCaptureOff, KErrInUse    );
  3170 
  3173 
  3171       PRINT( _L("Camera <> Checking that image capture supported..") );
  3174       PRINT( _L("Camera <> Checking that image capture supported..") );
  3172       CheckFlagOnL( iCameraInfo.iOptionsSupported, 
  3175       CheckFlagOnL( iCameraInfo.iOptionsSupported,
  3173                     TCameraInfo::EImageCaptureSupported, 
  3176                     TCameraInfo::EImageCaptureSupported,
  3174                     KErrNotSupported );
  3177                     KErrNotSupported );
  3175 
  3178 
  3176       PRINT( _L("Camera <> Ask image parameters..") );
  3179       PRINT( _L("Camera <> Ask image parameters..") );
  3177       TPckgBuf<TCamParamsImage> params;
  3180       TPckgBuf<TCamParamsImage> params;
  3178       iSettingProvider.ProvideCameraParamL( ECameraParamImage, &params );
  3181       iSettingProvider.ProvideCameraParamL( ECameraParamImage, &params );
  3185       CCamera::TFormat format( params().iFormat );
  3188       CCamera::TFormat format( params().iFormat );
  3186       TInt index = GetResolutionIndexL( format, params().iSize );
  3189       TInt index = GetResolutionIndexL( format, params().iSize );
  3187       User::LeaveIfError( index );
  3190       User::LeaveIfError( index );
  3188 
  3191 
  3189       PRINT( _L("Camera <> Call CCamera::PrepareImageCaptureL..") );
  3192       PRINT( _L("Camera <> Call CCamera::PrepareImageCaptureL..") );
  3190       PRINT2( _L("Camera <> Image size: (%d, %d)"), 
  3193       PRINT2( _L("Camera <> Image size: (%d, %d)"),
  3191                   params().iSize.iWidth,
  3194                   params().iSize.iWidth,
  3192                   params().iSize.iHeight );
  3195                   params().iSize.iHeight );
  3193       
  3196 
  3194       OstTrace0( CAMERAAPP_PERFORMANCE, CCAMCAMERACONTROLLER_PROCESSIMAGEREQUESTL, "e_CAM_APP_CONFIGURATIONS 0" );  //CCORAPP_APP_CONFIGS_END
  3197       OstTrace0( CAMERAAPP_PERFORMANCE, CCAMCAMERACONTROLLER_PROCESSIMAGEREQUESTL, "e_CAM_APP_CONFIGURATIONS 0" );  //CCORAPP_APP_CONFIGS_END
  3195       iCamera->PrepareImageCaptureL( format, index );
  3198       iCamera->PrepareImageCaptureL( format, index );
  3196       OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMCAMERACONTROLLER_PROCESSIMAGEREQUESTL, "e_CAM_APP_STILL_INIT 0" ); //CCORAPP_APP_STILL_INIT_END
  3199       OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMCAMERACONTROLLER_PROCESSIMAGEREQUESTL, "e_CAM_APP_STILL_INIT 0" ); //CCORAPP_APP_STILL_INIT_END
  3197       OstTrace0( CAMERAAPP_PERFORMANCE, DUP2_CCAMCAMERACONTROLLER_PROCESSIMAGEREQUESTL, "e_CAM_APP_OVERLAY_INIT 1" );   //CCORAPP_APP_OVERLAY_INIT_START
  3200       OstTrace0( CAMERAAPP_PERFORMANCE, DUP2_CCAMCAMERACONTROLLER_PROCESSIMAGEREQUESTL, "e_CAM_APP_OVERLAY_INIT 1" );   //CCORAPP_APP_OVERLAY_INIT_START
  3198       
  3201 
  3199       iCamera->SetJpegQuality( params().iQualityFactor );
  3202       iCamera->SetJpegQuality( params().iQualityFactor );
  3200 
  3203 
  3201       SetFlags( iInfo.iState, ECamImageOn );
  3204       SetFlags( iInfo.iState, ECamImageOn );
  3202       
  3205 
  3203 #ifdef CAMERAAPP_CAPI_V2_ADV      
  3206 #ifdef CAMERAAPP_CAPI_V2_ADV
  3204       // Set current autofocus range to invalid value to force focusing
  3207       // Set current autofocus range to invalid value to force focusing
  3205       iInfo.iCurrentFocusRange = static_cast<CAS::TFocusRange>( -1 );    
  3208       iInfo.iCurrentFocusRange = static_cast<CAS::TFocusRange>( -1 );
  3206       GetAdvancedSettingsInfoL();
  3209       GetAdvancedSettingsInfoL();
  3207 #endif // CAMERAAPP_CAPI_V2_ADV
  3210 #endif // CAMERAAPP_CAPI_V2_ADV
  3208       
  3211 
  3209       iInfo.iCaptureCount  = 0;
  3212       iInfo.iCaptureCount  = 0;
  3210       iInfo.iSnapshotCount = 0;
  3213       iInfo.iSnapshotCount = 0;
  3211       callback = EFalse; // No callback to wait for.
  3214       callback = EFalse; // No callback to wait for.
  3212       CAMERAAPP_PERF_CONTROLLER_STOP( ECamRequestImageInit );
  3215       CAMERAAPP_PERF_CONTROLLER_STOP( ECamRequestImageInit );
  3213         }
  3216         }
  3225       iInfo.iSnapshotCount = 0;
  3228       iInfo.iSnapshotCount = 0;
  3226       iInfo.iCaptureState  = ECamCaptureOn;
  3229       iInfo.iCaptureState  = ECamCaptureOn;
  3227 
  3230 
  3228       PRINT1( _L("Camera <> CCamCameraController .. About to start capture, total shared buffers in use: %d"), CCamBufferShare::TotalBufferShareCount() );
  3231       PRINT1( _L("Camera <> CCamCameraController .. About to start capture, total shared buffers in use: %d"), CCamBufferShare::TotalBufferShareCount() );
  3229       iCamera->CaptureImage();
  3232       iCamera->CaptureImage();
  3230       
  3233 
  3231       // When image data is received from CCamera,
  3234       // When image data is received from CCamera,
  3232       // an event is generated for that. We need to notify
  3235       // an event is generated for that. We need to notify
  3233       // here as other places check if the request has associated 
  3236       // here as other places check if the request has associated
  3234       // callback, and send no notification yet if callback exist.
  3237       // callback, and send no notification yet if callback exist.
  3235       NotifyObservers( KErrNone, 
  3238       NotifyObservers( KErrNone,
  3236                        ECamCameraEventImageStart,
  3239                        ECamCameraEventImageStart,
  3237                        ECamCameraEventClassImage );
  3240                        ECamCameraEventClassImage );
  3238       break;
  3241       break;
  3239       }
  3242       }
  3240     // -----------------------------------------------------
  3243     // -----------------------------------------------------
  3245       }
  3248       }
  3246     // -----------------------------------------------------
  3249     // -----------------------------------------------------
  3247     }
  3250     }
  3248   PRINT1( _L("Camera <= CCamCameraController::ProcessImageRequestL, continue now:%d"), !callback );
  3251   PRINT1( _L("Camera <= CCamCameraController::ProcessImageRequestL, continue now:%d"), !callback );
  3249   return !callback;
  3252   return !callback;
  3250   }    
  3253   }
  3251 
  3254 
  3252 
  3255 
  3253 // ---------------------------------------------------------------------------
  3256 // ---------------------------------------------------------------------------
  3254 // ProcessImageShutdownRequest
  3257 // ProcessImageShutdownRequest
  3255 // ---------------------------------------------------------------------------
  3258 // ---------------------------------------------------------------------------
  3256 //
  3259 //
  3257 TInt 
  3260 TInt
  3258 CCamCameraController
  3261 CCamCameraController
  3259 ::ProcessImageShutdownRequest( const TCamCameraRequestId& aRequestId )
  3262 ::ProcessImageShutdownRequest( const TCamCameraRequestId& aRequestId )
  3260   {
  3263   {
  3261   PRINT( _L("Camera => CCamCameraController::ProcessImageShutdownRequest") );
  3264   PRINT( _L("Camera => CCamCameraController::ProcessImageShutdownRequest") );
  3262 
  3265 
  3264     {
  3267     {
  3265     // -----------------------------------------------------
  3268     // -----------------------------------------------------
  3266     case ECamRequestImageCancel:
  3269     case ECamRequestImageCancel:
  3267       {
  3270       {
  3268       if( IsFlagOn( iInfo.iState, ECamImageOn )
  3271       if( IsFlagOn( iInfo.iState, ECamImageOn )
  3269 //      && ECamCaptureOn == iInfo.iCaptureState  
  3272 //      && ECamCaptureOn == iInfo.iCaptureState
  3270         )
  3273         )
  3271         {
  3274         {
  3272         const TCamCameraCaptureState previousState( iInfo.iCaptureState );
  3275         const TCamCameraCaptureState previousState( iInfo.iCaptureState );
  3273 
  3276 
  3274         if( iEncoder ) 
  3277         if( iEncoder )
  3275           {
  3278           {
  3276           iEncoder->Cancel();
  3279           iEncoder->Cancel();
  3277 
  3280 
  3278           delete iEncoder;
  3281           delete iEncoder;
  3279           iEncoder = NULL;
  3282           iEncoder = NULL;
  3280           }
  3283           }
  3281       
  3284 
  3282         PRINT( _L("Camera <> Calling iCamera->CancelCaptureImage()") );
  3285         PRINT( _L("Camera <> Calling iCamera->CancelCaptureImage()") );
  3283         iCamera->CancelCaptureImage();
  3286         iCamera->CancelCaptureImage();
  3284 
  3287 
  3285         iInfo.iCaptureState = ECamCaptureOff;
  3288         iInfo.iCaptureState = ECamCaptureOff;
  3286 
  3289 
  3291           // Capturing image was stopped here.
  3294           // Capturing image was stopped here.
  3292           // If single request was ongoing, it must be "capture image".
  3295           // If single request was ongoing, it must be "capture image".
  3293           ClearFlags( iInfo.iBusy, ECamBusySingle );
  3296           ClearFlags( iInfo.iBusy, ECamBusySingle );
  3294 
  3297 
  3295           TInt fullCaptures( Min( iInfo.iCaptureCount, iInfo.iSnapshotCount ) );
  3298           TInt fullCaptures( Min( iInfo.iCaptureCount, iInfo.iSnapshotCount ) );
  3296           NotifyObservers( KErrNone, 
  3299           NotifyObservers( KErrNone,
  3297                            ECamCameraEventImageStop, 
  3300                            ECamCameraEventImageStop,
  3298                            ECamCameraEventClassImage,
  3301                            ECamCameraEventClassImage,
  3299                            &fullCaptures );
  3302                            &fullCaptures );
  3300           }
  3303           }
  3301         }
  3304         }
  3302       break;
  3305       break;
  3306       {
  3309       {
  3307       // Cancel any pending capture.
  3310       // Cancel any pending capture.
  3308       ProcessImageShutdownRequest( ECamRequestImageCancel );
  3311       ProcessImageShutdownRequest( ECamRequestImageCancel );
  3309 
  3312 
  3310       // Nothing else really needed for image, just set flags.
  3313       // Nothing else really needed for image, just set flags.
  3311       ClearFlags( iInfo.iState, ECamImageOn ); 
  3314       ClearFlags( iInfo.iState, ECamImageOn );
  3312       iInfo.iCaptureCount  = 0;
  3315       iInfo.iCaptureCount  = 0;
  3313       iInfo.iSnapshotCount = 0;
  3316       iInfo.iSnapshotCount = 0;
  3314       iInfo.iCaptureState  = ECamCaptureOff;
  3317       iInfo.iCaptureState  = ECamCaptureOff;
  3315 
  3318 
  3316       break;
  3319       break;
  3323       }
  3326       }
  3324     // -----------------------------------------------------
  3327     // -----------------------------------------------------
  3325     }
  3328     }
  3326   PRINT( _L("Camera <= CCamCameraController::ProcessImageShutdownRequest") );
  3329   PRINT( _L("Camera <= CCamCameraController::ProcessImageShutdownRequest") );
  3327   return ETrue; // can continue sequence, if needed
  3330   return ETrue; // can continue sequence, if needed
  3328   }    
  3331   }
  3329 
  3332 
  3330 
  3333 
  3331 
  3334 
  3332 // ---------------------------------------------------------------------------
  3335 // ---------------------------------------------------------------------------
  3333 // ProcessVideoRequestL
  3336 // ProcessVideoRequestL
  3334 // ---------------------------------------------------------------------------
  3337 // ---------------------------------------------------------------------------
  3335 //
  3338 //
  3336 TInt 
  3339 TInt
  3337 CCamCameraController
  3340 CCamCameraController
  3338 ::ProcessVideoRequestL( const TCamCameraRequestId& aRequestId )
  3341 ::ProcessVideoRequestL( const TCamCameraRequestId& aRequestId )
  3339   {
  3342   {
  3340   PRINT( _L("Camera => CCamCameraController::ProcessVideoRequestL") );
  3343   PRINT( _L("Camera => CCamCameraController::ProcessVideoRequestL") );
  3341   CheckFlagOnL( iInfo.iState, ECamPowerOn, KErrNotReady );
  3344   CheckFlagOnL( iInfo.iState, ECamPowerOn, KErrNotReady );
  3381         TPtr   ptr     ( filename->Des()              );
  3384         TPtr   ptr     ( filename->Des()              );
  3382         iSettingProvider.ProvideCameraSettingL( ECameraSettingFileName, &ptr );
  3385         iSettingProvider.ProvideCameraSettingL( ECameraSettingFileName, &ptr );
  3383         // _LIT( KTempFilename, "C:\\video.3gp" );
  3386         // _LIT( KTempFilename, "C:\\video.3gp" );
  3384         // TPtrC ptr;
  3387         // TPtrC ptr;
  3385         // ptr.Set( KTempFilename() );
  3388         // ptr.Set( KTempFilename() );
  3386         PRINT1( _L("Camera <> Set filename [%S]"), &ptr );        
  3389         PRINT1( _L("Camera <> Set filename [%S]"), &ptr );
  3387         iCaeEngine->SetVideoRecordingFileNameL( ptr );
  3390         iCaeEngine->SetVideoRecordingFileNameL( ptr );
  3388         CleanupStack::PopAndDestroy( filename );
  3391         CleanupStack::PopAndDestroy( filename );
  3389         
  3392 
  3390         // Set max video clip size
  3393         // Set max video clip size
  3391         ProcessSettingL( ECameraSettingFileMaxSize );          
  3394         ProcessSettingL( ECameraSettingFileMaxSize );
  3392 
  3395 
  3393         TPckgBuf<TCamParamsVideoCae> params;
  3396         TPckgBuf<TCamParamsVideoCae> params;
  3394         PRINT( _L("Camera <> Getting params from setting provider..") );
  3397         PRINT( _L("Camera <> Getting params from setting provider..") );
  3395         iSettingProvider.ProvideCameraParamL( ECameraParamVideoCae, &params );
  3398         iSettingProvider.ProvideCameraParamL( ECameraParamVideoCae, &params );
  3396         // The audioOn value is defined On==0 and Off==1, but the engine expects 
  3399         // The audioOn value is defined On==0 and Off==1, but the engine expects
  3397         // ETrue if audio recording is On
  3400         // ETrue if audio recording is On
  3398         params().iAudioOn = ( ECamSettOn == params().iAudioOn )
  3401         params().iAudioOn = ( ECamSettOn == params().iAudioOn )
  3399         											? ETrue
  3402         											? ETrue
  3400         											: EFalse;
  3403         											: EFalse;
  3401         PRINT( _L("Camera <> Calling PrepareVideoRecordingL..") );
  3404         PRINT( _L("Camera <> Calling PrepareVideoRecordingL..") );
  3412                     params().iMimeType,
  3415                     params().iMimeType,
  3413                     params().iSupplier,
  3416                     params().iSupplier,
  3414                     params().iVideoType,
  3417                     params().iVideoType,
  3415                     params().iAudioType );
  3418                     params().iAudioType );
  3416             }
  3419             }
  3417                                           
  3420 
  3418 #ifdef CAMERAAPP_CAPI_V2_ADV                                          
  3421 #ifdef CAMERAAPP_CAPI_V2_ADV
  3419       // Set current autofocus range to invalid value to force focusing
  3422       // Set current autofocus range to invalid value to force focusing
  3420       iInfo.iCurrentFocusRange = static_cast<CAS::TFocusRange>( -1 );                                          
  3423       iInfo.iCurrentFocusRange = static_cast<CAS::TFocusRange>( -1 );
  3421 #endif // CAMERAAPP_CAPI_V2_ADV
  3424 #endif // CAMERAAPP_CAPI_V2_ADV
  3422                                           
  3425 
  3423         iAppController.SetVideoInitNeeded( EFalse );
  3426         iAppController.SetVideoInitNeeded( EFalse );
  3424         // iState is updated in the callback.
  3427         // iState is updated in the callback.
  3425         PRINT( _L("Camera <> ..waiting for callback") );
  3428         PRINT( _L("Camera <> ..waiting for callback") );
  3426         }
  3429         }
  3427       break;
  3430       break;
  3435         {
  3438         {
  3436         case ECamCaptureOn:     User::Leave( KErrInUse );           break;
  3439         case ECamCaptureOn:     User::Leave( KErrInUse );           break;
  3437         case ECamCaptureOff:    iCaeEngine->StartVideoRecording();  break;
  3440         case ECamCaptureOff:    iCaeEngine->StartVideoRecording();  break;
  3438         //case ECamCaptureOff:    iCaeEngine->ResumeVideoRecording();  break;
  3441         //case ECamCaptureOff:    iCaeEngine->ResumeVideoRecording();  break;
  3439         case ECamCapturePaused: iCaeEngine->ResumeVideoRecording(); break;
  3442         case ECamCapturePaused: iCaeEngine->ResumeVideoRecording(); break;
  3440         default:                
  3443         default:
  3441           Panic( ECamCameraControllerCorrupt );
  3444           Panic( ECamCameraControllerCorrupt );
  3442           break;
  3445           break;
  3443         }
  3446         }
  3444       // iCaptureState is updated in McaeoVideoRecordingOn.
  3447       // iCaptureState is updated in McaeoVideoRecordingOn.
  3445       break;
  3448       break;
  3458       {
  3461       {
  3459       PRINT( _L("Camera <> case ECamRequestVideoStop") );
  3462       PRINT( _L("Camera <> case ECamRequestVideoStop") );
  3460       switch( iInfo.iCaptureState )
  3463       switch( iInfo.iCaptureState )
  3461         {
  3464         {
  3462         case ECamCaptureOn:     // << fall through >>
  3465         case ECamCaptureOn:     // << fall through >>
  3463         case ECamCapturePaused: 
  3466         case ECamCapturePaused:
  3464           PRINT( _L("Camera <> call CCaeEngine::StopVideoRecording..") );
  3467           PRINT( _L("Camera <> call CCaeEngine::StopVideoRecording..") );
  3465           iCaeEngine->StopVideoRecording(); 
  3468           iCaeEngine->StopVideoRecording();
  3466           // If we got the callback during above call,
  3469           // If we got the callback during above call,
  3467           // we should not wait for it anymore.
  3470           // we should not wait for it anymore.
  3468           // Check the capture state to be sure.
  3471           // Check the capture state to be sure.
  3469           callback = (ECamCaptureOff != iInfo.iCaptureState);
  3472           callback = (ECamCaptureOff != iInfo.iCaptureState);
  3470           break;
  3473           break;
  3471         case ECamCaptureOff:    
  3474         case ECamCaptureOff:
  3472           // no action, already stopped
  3475           // no action, already stopped
  3473           break;
  3476           break;
  3474         default:                
  3477         default:
  3475           Panic( ECamCameraControllerCorrupt );
  3478           Panic( ECamCameraControllerCorrupt );
  3476           break;
  3479           break;
  3477         }
  3480         }
  3478       // iCaptureState is updated in McaeoVideoRecordingComplete.
  3481       // iCaptureState is updated in McaeoVideoRecordingComplete.
  3479       break;
  3482       break;
  3481     // -----------------------------------------------------
  3484     // -----------------------------------------------------
  3482     case ECamRequestVideoRelease:
  3485     case ECamRequestVideoRelease:
  3483       {
  3486       {
  3484       // Need to be stopped.
  3487       // Need to be stopped.
  3485       CheckEqualsL( iInfo.iCaptureState, ECamCaptureOff, KErrInUse );
  3488       CheckEqualsL( iInfo.iCaptureState, ECamCaptureOff, KErrInUse );
  3486   
  3489 
  3487       if( IsFlagOn( iInfo.iState, ECamVideoOn ) )
  3490       if( IsFlagOn( iInfo.iState, ECamVideoOn ) )
  3488         iCaeEngine->CloseVideoRecording();
  3491         iCaeEngine->CloseVideoRecording();
  3489         
  3492 
  3490       ClearFlags( iInfo.iState, ECamVideoOn );
  3493       ClearFlags( iInfo.iState, ECamVideoOn );
  3491       callback = EFalse;
  3494       callback = EFalse;
  3492 #ifdef CAMERAAPP_CAPI_V2_ADV
  3495 #ifdef CAMERAAPP_CAPI_V2_ADV
  3493       GetAdvancedSettingsInfoL();
  3496       GetAdvancedSettingsInfoL();
  3494 #endif
  3497 #endif
  3502       iAsyncVideoStopModeSupported = !err; // Use async stop if KErrNone
  3505       iAsyncVideoStopModeSupported = !err; // Use async stop if KErrNone
  3503       callback = EFalse;
  3506       callback = EFalse;
  3504       break;
  3507       break;
  3505       }
  3508       }
  3506     // -----------------------------------------------------
  3509     // -----------------------------------------------------
  3507     default: 
  3510     default:
  3508       Panic( ECamCameraControllerCorrupt ); 
  3511       Panic( ECamCameraControllerCorrupt );
  3509       break;
  3512       break;
  3510     // -----------------------------------------------------
  3513     // -----------------------------------------------------
  3511     }
  3514     }
  3512 #else
  3515 #else
  3513   #pragma message("CCamCameraController::ProcessVideoRequestL not implemented!")
  3516   #pragma message("CCamCameraController::ProcessVideoRequestL not implemented!")
  3523 
  3526 
  3524 // ---------------------------------------------------------------------------
  3527 // ---------------------------------------------------------------------------
  3525 // ProcessSnapshotRequestL
  3528 // ProcessSnapshotRequestL
  3526 // ---------------------------------------------------------------------------
  3529 // ---------------------------------------------------------------------------
  3527 //
  3530 //
  3528 TInt 
  3531 TInt
  3529 CCamCameraController
  3532 CCamCameraController
  3530 ::ProcessSnapshotRequestL( const TCamCameraRequestId& aRequestId )
  3533 ::ProcessSnapshotRequestL( const TCamCameraRequestId& aRequestId )
  3531   {
  3534   {
  3532   PRINT( _L("Camera => CCamCameraController::ProcessSnapshotRequestL") );
  3535   PRINT( _L("Camera => CCamCameraController::ProcessSnapshotRequestL") );
  3533   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, CCAMCAMERACONTROLLER_PROCESSSNAPSHOTREQUESTL, "e_CCamCameraController_ProcessSnapshotRequestL 1" );
  3536   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, CCAMCAMERACONTROLLER_PROCESSSNAPSHOTREQUESTL, "e_CCamCameraController_ProcessSnapshotRequestL 1" );
  3545           PRINT( _L("Camera <> ECamTriIdle") );
  3548           PRINT( _L("Camera <> ECamTriIdle") );
  3546           InitSnapshotL();
  3549           InitSnapshotL();
  3547           // << fall through >>
  3550           // << fall through >>
  3548         case ECamTriInactive:
  3551         case ECamTriInactive:
  3549           {
  3552           {
  3550           PRINT( _L("Camera <> ECamTriInactive") );  
  3553           PRINT( _L("Camera <> ECamTriInactive") );
  3551           iSnapshotProvider->StartSnapshot();
  3554           iSnapshotProvider->StartSnapshot();
  3552           break;
  3555           break;
  3553           }
  3556           }
  3554         case ECamTriActive: // Already active, no action  
  3557         case ECamTriActive: // Already active, no action
  3555           PRINT( _L("Camera <> ECamTriActive") ); 
  3558           PRINT( _L("Camera <> ECamTriActive") );
  3556           break;
  3559           break;
  3557         default:
  3560         default:
  3558           Panic( ECamCameraControllerCorrupt ); 
  3561           Panic( ECamCameraControllerCorrupt );
  3559           break;
  3562           break;
  3560         }
  3563         }
  3561       iInfo.iSsState = ECamTriActive;
  3564       iInfo.iSsState = ECamTriActive;
  3562       break;
  3565       break;
  3563       }
  3566       }
  3601     {
  3604     {
  3602     case ECamTriIdle:     // Not even initialized yet. No action needed.
  3605     case ECamTriIdle:     // Not even initialized yet. No action needed.
  3603     case ECamTriInactive: // Already inactive, no action.
  3606     case ECamTriInactive: // Already inactive, no action.
  3604       PRINT( _L("Camera <> Snapshot idle/inactive, no need to stop") );
  3607       PRINT( _L("Camera <> Snapshot idle/inactive, no need to stop") );
  3605       break;
  3608       break;
  3606     case ECamTriActive:   
  3609     case ECamTriActive:
  3607       PRINT( _L("Camera <> Snapshot ECamTriActive -> need to stop") );
  3610       PRINT( _L("Camera <> Snapshot ECamTriActive -> need to stop") );
  3608       iSnapshotProvider->StopSnapshot();
  3611       iSnapshotProvider->StopSnapshot();
  3609       break;
  3612       break;
  3610     default:
  3613     default:
  3611       Panic( ECamCameraControllerCorrupt ); 
  3614       Panic( ECamCameraControllerCorrupt );
  3612       break;
  3615       break;
  3613     }
  3616     }
  3614   iInfo.iSsState = ECamTriInactive;
  3617   iInfo.iSsState = ECamTriInactive;
  3615   PRINT( _L("Camera <= CCamCameraController::ProcessSsStopRequest") );
  3618   PRINT( _L("Camera <= CCamCameraController::ProcessSsStopRequest") );
  3616   }
  3619   }
  3627     {
  3630     {
  3628     case ECamTriIdle:    // No action needed
  3631     case ECamTriIdle:    // No action needed
  3629       break;
  3632       break;
  3630     case ECamTriActive:
  3633     case ECamTriActive:
  3631       iSnapshotProvider->StopSnapshot();
  3634       iSnapshotProvider->StopSnapshot();
  3632       NotifyObservers( KErrNone, 
  3635       NotifyObservers( KErrNone,
  3633                        ECamCameraEventSsStop, 
  3636                        ECamCameraEventSsStop,
  3634                        ECamCameraEventClassSsControl );
  3637                        ECamCameraEventClassSsControl );
  3635       // << fall through >>
  3638       // << fall through >>
  3636     case ECamTriInactive:
  3639     case ECamTriInactive:
  3637       delete iSnapshotProvider;
  3640       delete iSnapshotProvider;
  3638       iSnapshotProvider = NULL;
  3641       iSnapshotProvider = NULL;
  3639       break;
  3642       break;
  3640     default:              
  3643     default:
  3641       Panic( ECamCameraControllerCorrupt ); 
  3644       Panic( ECamCameraControllerCorrupt );
  3642       break;
  3645       break;
  3643     }
  3646     }
  3644 
  3647 
  3645   iInfo.iSsState = ECamTriIdle;
  3648   iInfo.iSsState = ECamTriIdle;
  3646   PRINT( _L("Camera <= CCamCameraController::ProcessSsReleaseRequest") );
  3649   PRINT( _L("Camera <= CCamCameraController::ProcessSsReleaseRequest") );
  3647   } 
  3650   }
  3648 
  3651 
  3649 // ---------------------------------------------------------------------------
  3652 // ---------------------------------------------------------------------------
  3650 // InitSnapshotL
  3653 // InitSnapshotL
  3651 // ---------------------------------------------------------------------------
  3654 // ---------------------------------------------------------------------------
  3652 //
  3655 //
  3653 void 
  3656 void
  3654 CCamCameraController::InitSnapshotL()
  3657 CCamCameraController::InitSnapshotL()
  3655   {
  3658   {
  3656   PRINT( _L("Camera => CCamCameraController::InitSnapshotL") );
  3659   PRINT( _L("Camera => CCamCameraController::InitSnapshotL") );
  3657 
  3660 
  3658   // Check the snapshot state here. No further checks made.
  3661   // Check the snapshot state here. No further checks made.
  3669   PrintSnapshotInfo();
  3672   PrintSnapshotInfo();
  3670 #endif // _DEBUG
  3673 #endif // _DEBUG
  3671 
  3674 
  3672 
  3675 
  3673   // -------------------------------------------------------
  3676   // -------------------------------------------------------
  3674   // Initialize the snapshot parameters      
  3677   // Initialize the snapshot parameters
  3675   TPckgBuf<TCamParamsSnapshot> params;
  3678   TPckgBuf<TCamParamsSnapshot> params;
  3676   iSettingProvider.ProvideCameraParamL( ECameraParamSnapshot, &params );
  3679   iSettingProvider.ProvideCameraParamL( ECameraParamSnapshot, &params );
  3677 
  3680 
  3678   // Try to get the best, still supported, snapshot format.       
  3681   // Try to get the best, still supported, snapshot format.
  3679   iInfo.iSnapshotFormat         = ResolveSnapshotFormatL( params().iFormat );
  3682   iInfo.iSnapshotFormat         = ResolveSnapshotFormatL( params().iFormat );
  3680   iInfo.iSnapshotSize           = params().iSize;
  3683   iInfo.iSnapshotSize           = params().iSize;
  3681   iInfo.iSnapshotAspectMaintain = params().iMaintainAspect;
  3684   iInfo.iSnapshotAspectMaintain = params().iMaintainAspect;
  3682 
  3685 
  3683   PRINT( _L("Camera <> Prepare snapshot..") );
  3686   PRINT( _L("Camera <> Prepare snapshot..") );
  3695 // CCamCameraController::ProcessAutofocusRequestL
  3698 // CCamCameraController::ProcessAutofocusRequestL
  3696 // ---------------------------------------------------------------------------
  3699 // ---------------------------------------------------------------------------
  3697 //
  3700 //
  3698 void CCamCameraController::ProcessAutofocusRequestL( const TCamCameraRequestId& aRequestId )
  3701 void CCamCameraController::ProcessAutofocusRequestL( const TCamCameraRequestId& aRequestId )
  3699   {
  3702   {
  3700   PRINT( _L("Camera => CCamCameraController::ProcessAutofocusRequestL") );  
  3703   PRINT( _L("Camera => CCamCameraController::ProcessAutofocusRequestL") );
  3701 #ifdef CAMERAAPP_CAPI_V2_ADV
  3704 #ifdef CAMERAAPP_CAPI_V2_ADV
  3702  CheckNonNullL( iAdvancedSettings, KErrNotReady );
  3705  CheckNonNullL( iAdvancedSettings, KErrNotReady );
  3703   if( ECamRequestStartAutofocus == aRequestId )
  3706   if( ECamRequestStartAutofocus == aRequestId )
  3704     {
  3707     {
  3705     PRINT( _L("Camera <> SetAutoFocusType( EAutoFocusTypeSingle )") );    
  3708     PRINT( _L("Camera <> SetAutoFocusType( EAutoFocusTypeSingle )") );
  3706     iAdvancedSettings->SetAutoFocusType( CAS::EAutoFocusTypeSingle );  
  3709     iAdvancedSettings->SetAutoFocusType( CAS::EAutoFocusTypeSingle );
  3707     iAfInProgress = ETrue; 
  3710     iAfInProgress = ETrue;
  3708     iFirstAfEventReceived = EFalse;
  3711     iFirstAfEventReceived = EFalse;
  3709     }
  3712     }
  3710   else if( ECamRequestCancelAutofocus == aRequestId )
  3713   else if( ECamRequestCancelAutofocus == aRequestId )
  3711     {
  3714     {
  3712     if( iAfInProgress ) 
  3715     if( iAfInProgress )
  3713       {
  3716       {
  3714       // Autofocus in progress, need to cancel it before setting range to hyperfocal
  3717       // Autofocus in progress, need to cancel it before setting range to hyperfocal
  3715       PRINT( _L("Camera <> Cancel ongoing autofocus request") );
  3718       PRINT( _L("Camera <> Cancel ongoing autofocus request") );
  3716       iAdvancedSettings->SetAutoFocusType( CAS::EAutoFocusTypeOff );
  3719       iAdvancedSettings->SetAutoFocusType( CAS::EAutoFocusTypeOff );
  3717       iAfHyperfocalPending = ETrue;
  3720       iAfHyperfocalPending = ETrue;
  3718       }
  3721       }
  3719     else 
  3722     else
  3720       { 
  3723       {
  3721       // If focustype is set to continuous, need to change it to off
  3724       // If focustype is set to continuous, need to change it to off
  3722 	  // before continuing
  3725 	  // before continuing
  3723 
  3726 
  3724       PRINT( _L("Camera <> SetAutoFocusType( EAutoFocusTypeOff )") ); 
  3727       PRINT( _L("Camera <> SetAutoFocusType( EAutoFocusTypeOff )") );
  3725       if ( iAdvancedSettings->AutoFocusType() & CAS::EAutoFocusTypeContinuous )
  3728       if ( iAdvancedSettings->AutoFocusType() & CAS::EAutoFocusTypeContinuous )
  3726         {
  3729         {
  3727         iAdvancedSettings->SetAutoFocusType( CAS::EAutoFocusTypeOff );     
  3730         iAdvancedSettings->SetAutoFocusType( CAS::EAutoFocusTypeOff );
  3728         }
  3731         }
  3729                             
  3732 
  3730       PRINT( _L("Camera <> Cancel autofocus - set focus range to hyperfocal") );    
  3733       PRINT( _L("Camera <> Cancel autofocus - set focus range to hyperfocal") );
  3731       iInfo.iCurrentFocusRange = CAS::EFocusRangeHyperfocal;   
  3734       iInfo.iCurrentFocusRange = CAS::EFocusRangeHyperfocal;
  3732       iAdvancedSettings->SetFocusRange( CAS::EFocusRangeHyperfocal );  
  3735       iAdvancedSettings->SetFocusRange( CAS::EFocusRangeHyperfocal );
  3733       
  3736 
  3734       // Then start the focus. The callback of this cancel request sets 
  3737       // Then start the focus. The callback of this cancel request sets
  3735       // a boolean in CamAppController, so the resulting optimal
  3738       // a boolean in CamAppController, so the resulting optimal
  3736       // focus event does not change reticule/focus state.
  3739       // focus event does not change reticule/focus state.
  3737       iAdvancedSettings->SetAutoFocusType( CAS::EAutoFocusTypeSingle );   
  3740       iAdvancedSettings->SetAutoFocusType( CAS::EAutoFocusTypeSingle );
  3738       iAfInProgress = ETrue; 
  3741       iAfInProgress = ETrue;
  3739       }
  3742       }
  3740     }
  3743     }
  3741   else if( ECamRequestSetAfRange == aRequestId )
  3744   else if( ECamRequestSetAfRange == aRequestId )
  3742     {
  3745     {
  3743     PRINT( _L("Camera <> Set autofocus range") );
  3746     PRINT( _L("Camera <> Set autofocus range") );
  3744     // Get autofocus mode from settings provider
  3747     // Get autofocus mode from settings provider
  3745     
  3748 
  3746     CAS::TFocusRange afRange;
  3749     CAS::TFocusRange afRange;
  3747     iSettingProvider.ProvideCameraSettingL( ECameraSettingFocusRange, &afRange );
  3750     iSettingProvider.ProvideCameraSettingL( ECameraSettingFocusRange, &afRange );
  3748     
  3751 
  3749     if( iInfo.iCurrentFocusRange != afRange )
  3752     if( iInfo.iCurrentFocusRange != afRange )
  3750       {      
  3753       {
  3751       iAdvancedSettings->SetFocusRange( afRange );
  3754       iAdvancedSettings->SetFocusRange( afRange );
  3752       
  3755 
  3753       // Should this be done in the callback?:
  3756       // Should this be done in the callback?:
  3754       iInfo.iCurrentFocusRange = afRange;
  3757       iInfo.iCurrentFocusRange = afRange;
  3755       }
  3758       }
  3756     else
  3759     else
  3757       {
  3760       {
  3758       // Correct range already set. No need to do anything.  
  3761       // Correct range already set. No need to do anything.
  3759       }
  3762       }
  3760     }
  3763     }
  3761   else
  3764   else
  3762     {
  3765     {
  3763     // Other request must not end up here
  3766     // Other request must not end up here
  3764     __ASSERT_DEBUG( EFalse, Panic( ECamCameraControllerCorrupt ) );
  3767     __ASSERT_DEBUG( EFalse, Panic( ECamCameraControllerCorrupt ) );
  3765     }
  3768     }
  3766 #endif // CAMERAAPP_CAPI_V2_ADV   
  3769 #endif // CAMERAAPP_CAPI_V2_ADV
  3767   
  3770 
  3768   (void)aRequestId; // removes compiler warning
  3771   (void)aRequestId; // removes compiler warning
  3769   PRINT( _L("Camera <= CCamCameraController::ProcessAutofocusRequestL") );
  3772   PRINT( _L("Camera <= CCamCameraController::ProcessAutofocusRequestL") );
  3770   }
  3773   }
  3771 
  3774 
  3772 
  3775 
  3780   {
  3783   {
  3781   PRINT ( _L("Camera => CCamCameraController::ProcessCaptureLimitSettingL") );
  3784   PRINT ( _L("Camera => CCamCameraController::ProcessCaptureLimitSettingL") );
  3782 #ifdef CAMERAAPP_CAPI_V2_ADV
  3785 #ifdef CAMERAAPP_CAPI_V2_ADV
  3783   // Check that we are prepared for image mode.
  3786   // Check that we are prepared for image mode.
  3784   CheckFlagOnL( iInfo.iState, ECamImageOn, KErrNotReady );
  3787   CheckFlagOnL( iInfo.iState, ECamImageOn, KErrNotReady );
  3785     
  3788 
  3786   // Get requested capture count and determine current and target drive modes.
  3789   // Get requested capture count and determine current and target drive modes.
  3787   TInt requestedLimit( 1 );
  3790   TInt requestedLimit( 1 );
  3788   iSettingProvider.ProvideCameraSettingL( ECameraSettingCaptureLimit, &requestedLimit );  
  3791   iSettingProvider.ProvideCameraSettingL( ECameraSettingCaptureLimit, &requestedLimit );
  3789   if( requestedLimit < 1 ) User::Leave( KErrArgument );
  3792   if( requestedLimit < 1 ) User::Leave( KErrArgument );
  3790 
  3793 
  3791   const CAS::TDriveMode& currentMode( iAdvancedSettings->DriveMode() );
  3794   const CAS::TDriveMode& currentMode( iAdvancedSettings->DriveMode() );
  3792   const CAS::TDriveMode  targetMode ( requestedLimit <= 1
  3795   const CAS::TDriveMode  targetMode ( requestedLimit <= 1
  3793                                     ? CAS::EDriveModeSingleShot
  3796                                     ? CAS::EDriveModeSingleShot
  3804   PRINT1( _L("Camera <> CCamCameraController .. target  drive mode       : [%S]"), &DriveModeName( targetMode  ) );
  3807   PRINT1( _L("Camera <> CCamCameraController .. target  drive mode       : [%S]"), &DriveModeName( targetMode  ) );
  3805   PRINT ( _L("Camera <> CCamCameraController .. --------------------------------------") );
  3808   PRINT ( _L("Camera <> CCamCameraController .. --------------------------------------") );
  3806 
  3809 
  3807   // -------------------------------------------------------
  3810   // -------------------------------------------------------
  3808   // Determine needed changes and when to issue them
  3811   // Determine needed changes and when to issue them
  3809   // 
  3812   //
  3810   // During burst capture, we may receive snapshots and
  3813   // During burst capture, we may receive snapshots and
  3811   // image data on mixed order, e.g:
  3814   // image data on mixed order, e.g:
  3812   //
  3815   //
  3813   //   [ ss#1 | img#1 | ss#2 | ss#3 | img2 | img3 ]
  3816   //   [ ss#1 | img#1 | ss#2 | ss#3 | img2 | img3 ]
  3814   //   --------------^^--------------------------^^
  3817   //   --------------^^--------------------------^^
  3815   //
  3818   //
  3816   // C-API starts new burst capture when we adjust the
  3819   // C-API starts new burst capture when we adjust the
  3817   // capture limit. To avoid problems and to get equal 
  3820   // capture limit. To avoid problems and to get equal
  3818   // amount of snapshots and images, capture count is 
  3821   // amount of snapshots and images, capture count is
  3819   // only changed when we image data is received, 
  3822   // only changed when we image data is received,
  3820   // and as many images as snapshots have arrived.
  3823   // and as many images as snapshots have arrived.
  3821   // In the chart above ^ marks a place where capture limit
  3824   // In the chart above ^ marks a place where capture limit
  3822   // can be updated.
  3825   // can be updated.
  3823   TBool callback( EFalse );
  3826   TBool callback( EFalse );
  3824 
  3827 
  3831       {
  3834       {
  3832       // Cannot change drive mode during capturing.
  3835       // Cannot change drive mode during capturing.
  3833       PRINT( _L("Camera <> CCamCameraController .. Drive mode update not possible now, LEAVE!") );
  3836       PRINT( _L("Camera <> CCamCameraController .. Drive mode update not possible now, LEAVE!") );
  3834       User::Leave( KErrInUse );
  3837       User::Leave( KErrInUse );
  3835       }
  3838       }
  3836     else if ( CAS::EDriveModeBurst == currentMode )    
  3839     else if ( CAS::EDriveModeBurst == currentMode )
  3837       {
  3840       {
  3838       if( cameraLimit != requestedLimit )
  3841       if( cameraLimit != requestedLimit )
  3839         {
  3842         {
  3840         PRINT( _L("Camera <> CCamCameraController .. Adjusting capture limit during burst..") );
  3843         PRINT( _L("Camera <> CCamCameraController .. Adjusting capture limit during burst..") );
  3841         // Set limit locally and react on next image data event.
  3844         // Set limit locally and react on next image data event.
  3849       }
  3852       }
  3850     else
  3853     else
  3851       {
  3854       {
  3852       // No action needed. Capture limit of 1 image kept.
  3855       // No action needed. Capture limit of 1 image kept.
  3853       PRINT( _L("Camera <> CCamCameraController .. Single shot mode kept, no action") );
  3856       PRINT( _L("Camera <> CCamCameraController .. Single shot mode kept, no action") );
  3854       }    
  3857       }
  3855     }
  3858     }
  3856   // -----------------------------------
  3859   // -----------------------------------
  3857   // Not capturing 
  3860   // Not capturing
  3858   //   
  3861   //
  3859   else
  3862   else
  3860     {
  3863     {
  3861     PRINT( _L("Camera <> CCamCameraController .. No capture ongoing..") );
  3864     PRINT( _L("Camera <> CCamCameraController .. No capture ongoing..") );
  3862 
  3865 
  3863     iInfo.iCaptureLimit = requestedLimit;
  3866     iInfo.iCaptureLimit = requestedLimit;
  3864     // Capture limit has changed, 
  3867     // Capture limit has changed,
  3865     // check if drive mode also needs to be changed..
  3868     // check if drive mode also needs to be changed..
  3866     if( targetMode != currentMode )
  3869     if( targetMode != currentMode )
  3867       {
  3870       {
  3868       PRINT1( _L("Camera <> CCamCameraController .. Calling SetDriveMode([%S])"), &DriveModeName( targetMode  ) );
  3871       PRINT1( _L("Camera <> CCamCameraController .. Calling SetDriveMode([%S])"), &DriveModeName( targetMode  ) );
  3869       iAdvancedSettings->SetDriveMode( targetMode );
  3872       iAdvancedSettings->SetDriveMode( targetMode );
  3874       iAdvancedSettings->SetBurstImages( iInfo.iCaptureLimit );
  3877       iAdvancedSettings->SetBurstImages( iInfo.iCaptureLimit );
  3875       }
  3878       }
  3876     }
  3879     }
  3877 
  3880 
  3878   // -------------------------------------------------------
  3881   // -------------------------------------------------------
  3879   // Notify user that the change is done  
  3882   // Notify user that the change is done
  3880   // or wait for camera callbacks to finish.
  3883   // or wait for camera callbacks to finish.
  3881   PRINT1( _L("Camera <> CCamCameraController .. Should wait callback = %d"), callback );
  3884   PRINT1( _L("Camera <> CCamCameraController .. Should wait callback = %d"), callback );
  3882   if( !callback )
  3885   if( !callback )
  3883     {
  3886     {
  3884     TInt setting( ECameraSettingCaptureLimit );
  3887     TInt setting( ECameraSettingCaptureLimit );
  3885     NotifyObservers( KErrNone, 
  3888     NotifyObservers( KErrNone,
  3886                      ECamCameraEventSettingsSingle,
  3889                      ECamCameraEventSettingsSingle,
  3887                      ECamCameraEventClassSettings,
  3890                      ECamCameraEventClassSettings,
  3888                      &setting );
  3891                      &setting );
  3889     }
  3892     }
  3890 #else
  3893 #else
  3897 
  3900 
  3898 // ---------------------------------------------------------------------------
  3901 // ---------------------------------------------------------------------------
  3899 // EndSequence
  3902 // EndSequence
  3900 // ---------------------------------------------------------------------------
  3903 // ---------------------------------------------------------------------------
  3901 //
  3904 //
  3902 void 
  3905 void
  3903 CCamCameraController::EndSequence( TInt aStatus )
  3906 CCamCameraController::EndSequence( TInt aStatus )
  3904   {
  3907   {
  3905   PRINT1( _L("Camera => CCamCameraController::EndSequence, status:%d"), aStatus );
  3908   PRINT1( _L("Camera => CCamCameraController::EndSequence, status:%d"), aStatus );
  3906 
  3909 
  3907   iIveRecoveryOngoing = EFalse;
  3910   iIveRecoveryOngoing = EFalse;
  3920 
  3923 
  3921     PRINT( _L("Camera <> ending sequence..") );
  3924     PRINT( _L("Camera <> ending sequence..") );
  3922     ClearRequestQueue();
  3925     ClearRequestQueue();
  3923     iReserveTryAgainCount = KCamReserveTryAgainMaxCount;
  3926     iReserveTryAgainCount = KCamReserveTryAgainMaxCount;
  3924 
  3927 
  3925     
  3928 
  3926     // Need to first clear busy flag as observer might issue
  3929     // Need to first clear busy flag as observer might issue
  3927     // new requests in notification callback.
  3930     // new requests in notification callback.
  3928     ClearFlags( iInfo.iBusy, ECamBusySequence );
  3931     ClearFlags( iInfo.iBusy, ECamBusySequence );
  3929 
  3932 
  3930     PRINT( _L("Camera <> send notification..") );
  3933     PRINT( _L("Camera <> send notification..") );
  3931     NotifyObservers( aStatus, 
  3934     NotifyObservers( aStatus,
  3932                      ECamCameraEventSequenceEnd, 
  3935                      ECamCameraEventSequenceEnd,
  3933                      ECamCameraEventClassBasicControl );
  3936                      ECamCameraEventClassBasicControl );
  3934     }
  3937     }
  3935   // -------------------------------------------------------
  3938   // -------------------------------------------------------
  3936   else if( IsFlagOn( iInfo.iBusy, ECamBusySetting ) )
  3939   else if( IsFlagOn( iInfo.iBusy, ECamBusySetting ) )
  3937     {
  3940     {
  3947          }
  3950          }
  3948       }
  3951       }
  3949     ClearSettingQueue();
  3952     ClearSettingQueue();
  3950 
  3953 
  3951     ClearFlags( iInfo.iBusy, ECamBusySetting );
  3954     ClearFlags( iInfo.iBusy, ECamBusySetting );
  3952     
  3955 
  3953     NotifyObservers( aStatus, 
  3956     NotifyObservers( aStatus,
  3954                      ECamCameraEventSettingsDone,
  3957                      ECamCameraEventSettingsDone,
  3955                      ECamCameraEventClassSettings,
  3958                      ECamCameraEventClassSettings,
  3956                      &last );
  3959                      &last );
  3957     }
  3960     }
  3958   // -------------------------------------------------------
  3961   // -------------------------------------------------------
  3971 // ---------------------------------------------------------------------------
  3974 // ---------------------------------------------------------------------------
  3972 //
  3975 //
  3973 void
  3976 void
  3974 CCamCameraController::ClearRequestQueue()
  3977 CCamCameraController::ClearRequestQueue()
  3975   {
  3978   {
  3976   iSequenceArray.Reset(); 
  3979   iSequenceArray.Reset();
  3977   iSequenceIndex = -1;
  3980   iSequenceIndex = -1;
  3978   }
  3981   }
  3979 
  3982 
  3980 // ---------------------------------------------------------------------------
  3983 // ---------------------------------------------------------------------------
  3981 // ClearSettingQueue
  3984 // ClearSettingQueue
  3982 // ---------------------------------------------------------------------------
  3985 // ---------------------------------------------------------------------------
  3983 //
  3986 //
  3984 void
  3987 void
  3985 CCamCameraController::ClearSettingQueue()
  3988 CCamCameraController::ClearSettingQueue()
  3986   {
  3989   {
  3987   iSettingArray.Reset(); 
  3990   iSettingArray.Reset();
  3988   iSettingIndex = -1;
  3991   iSettingIndex = -1;
  3989   }
  3992   }
  3990 
  3993 
  3991 
  3994 
  3992 
  3995 
  4006 
  4009 
  4007   OstTrace0( CAMERAAPP_PERFORMANCE, CCAMCAMERACONTROLLER_HANDLEPOWERONEVENT, "e_CAM_APP_INIT 0" );  //CCORAPP_APP_INIT_END
  4010   OstTrace0( CAMERAAPP_PERFORMANCE, CCAMCAMERACONTROLLER_HANDLEPOWERONEVENT, "e_CAM_APP_INIT 0" );  //CCORAPP_APP_INIT_END
  4008   OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMCAMERACONTROLLER_HANDLEPOWERONEVENT, "e_CAM_APP_VF_INIT 1" );  //CCORAPP_APP_VF_INIT_START
  4011   OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMCAMERACONTROLLER_HANDLEPOWERONEVENT, "e_CAM_APP_VF_INIT 1" );  //CCORAPP_APP_VF_INIT_START
  4009   OstTrace0( CAMERAAPP_PERFORMANCE, DUP2_CCAMCAMERACONTROLLER_HANDLEPOWERONEVENT, "e_CAM_APP_CONFIGURATIONS 1" );   //CCORAPP_APP_CONFIGS_START
  4012   OstTrace0( CAMERAAPP_PERFORMANCE, DUP2_CCAMCAMERACONTROLLER_HANDLEPOWERONEVENT, "e_CAM_APP_CONFIGURATIONS 1" );   //CCORAPP_APP_CONFIGS_START
  4010   OstTrace0( CAMERAAPP_PERFORMANCE, DUP3_CCAMCAMERACONTROLLER_HANDLEPOWERONEVENT, "e_CAM_APP_STILL_INIT 1" );   //CCORAPP_APP_STILL_INIT_START
  4013   OstTrace0( CAMERAAPP_PERFORMANCE, DUP3_CCAMCAMERACONTROLLER_HANDLEPOWERONEVENT, "e_CAM_APP_STILL_INIT 1" );   //CCORAPP_APP_STILL_INIT_START
  4011   
  4014 
  4012   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
  4015   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
  4013   
  4016 
  4014   if ( appUi->AppController().UiConfigManagerPtr()->IsFaceTrackingSupported() )
  4017   if ( appUi->AppController().UiConfigManagerPtr()->IsFaceTrackingSupported() )
  4015       {
  4018       {
  4016       PRINT( _L("Camera <> CCamAppController: Get i/f MCameraFaceTracking..") )
  4019       PRINT( _L("Camera <> CCamAppController: Get i/f MCameraFaceTracking..") )
  4017       iCustomInterfaceFaceTracking = 
  4020       iCustomInterfaceFaceTracking =
  4018           static_cast <MCameraFaceTracking*>( 
  4021           static_cast <MCameraFaceTracking*>(
  4019             iCamera->CustomInterface( KCameraFaceTrackingUid ) );
  4022             iCamera->CustomInterface( KCameraFaceTrackingUid ) );
  4020       PRINT1( _L("Camera <> Face Tracking custom i/f pointer:%d"), iCustomInterfaceFaceTracking );
  4023       PRINT1( _L("Camera <> Face Tracking custom i/f pointer:%d"), iCustomInterfaceFaceTracking );
  4021       }
  4024       }
  4022   
  4025 
  4023   if( KErrNone == aStatus )
  4026   if( KErrNone == aStatus )
  4024     {
  4027     {
  4025     SetFlags( iInfo.iState, ECamPowerOn|ECamReserved );
  4028     SetFlags( iInfo.iState, ECamPowerOn|ECamReserved );
  4026     
  4029 
  4027     TRAP_IGNORE( SetFaceTrackingL() );
  4030     TRAP_IGNORE( SetFaceTrackingL() );
  4028 #if defined( CAMERAAPP_CAE_FOR_VIDEO ) && !defined( CAMERAAPP_CAE_FIX )
  4031 #if defined( CAMERAAPP_CAE_FOR_VIDEO ) && !defined( CAMERAAPP_CAE_FIX )
  4029     // We need to tell to CCaeEngine that the CCamera has been reserved 
  4032     // We need to tell to CCaeEngine that the CCamera has been reserved
  4030     // and powered on "behind its back".
  4033     // and powered on "behind its back".
  4031     if( iCaeEngine )
  4034     if( iCaeEngine )
  4032       {
  4035       {
  4033       iCaeEngine->EnableVideoRecording();
  4036       iCaeEngine->EnableVideoRecording();
  4034       }
  4037       }
  4066     }
  4069     }
  4067   else
  4070   else
  4068     {
  4071     {
  4069     PRINT( _L("Camera <> no mode change ongoing") );
  4072     PRINT( _L("Camera <> no mode change ongoing") );
  4070     HandleCallbackEvent( aStatus,
  4073     HandleCallbackEvent( aStatus,
  4071                          ECamCameraEventPowerOn, 
  4074                          ECamCameraEventPowerOn,
  4072                          ECamCameraEventClassBasicControl );
  4075                          ECamCameraEventClassBasicControl );
  4073     }
  4076     }
  4074 #else
  4077 #else
  4075 
  4078 
  4076   HandleCallbackEvent( aStatus,
  4079   HandleCallbackEvent( aStatus,
  4077                        ECamCameraEventPowerOn, 
  4080                        ECamCameraEventPowerOn,
  4078                        ECamCameraEventClassBasicControl );
  4081                        ECamCameraEventClassBasicControl );
  4079 
  4082 
  4080 #endif // CAMERAAPP_CAE_FIX
  4083 #endif // CAMERAAPP_CAE_FIX
  4081   
  4084 
  4082   if ( appUi->AppController().UiConfigManagerPtr()->IsOrientationSensorSupported() )
  4085   if ( appUi->AppController().UiConfigManagerPtr()->IsOrientationSensorSupported() )
  4083       {
  4086       {
  4084       PRINT( _L("Camera <> CCamCameraController: Get i/f MCameraOrientation..") )
  4087       PRINT( _L("Camera <> CCamCameraController: Get i/f MCameraOrientation..") )
  4085       
  4088 
  4086       if(!iCustomInterfaceOrientation )
  4089       if(!iCustomInterfaceOrientation )
  4087           {
  4090           {
  4088           iCustomInterfaceOrientation = 
  4091           iCustomInterfaceOrientation =
  4089           static_cast <MCameraOrientation*>( 
  4092           static_cast <MCameraOrientation*>(
  4090           iCamera->CustomInterface( KCameraOrientationUid ) );
  4093           iCamera->CustomInterface( KCameraOrientationUid ) );
  4091           }
  4094           }
  4092         
  4095 
  4093       PRINT1( _L("Camera <> Orientation custom i/f pointer:%d"), iCustomInterfaceOrientation );      
  4096       PRINT1( _L("Camera <> Orientation custom i/f pointer:%d"), iCustomInterfaceOrientation );
  4094       }  
  4097       }
  4095   
  4098 
  4096   PRINT( _L("Camera <= CCamCameraController::HandlePowerOnEvent") );
  4099   PRINT( _L("Camera <= CCamCameraController::HandlePowerOnEvent") );
  4097   }
  4100   }
  4098 
  4101 
  4099 // ---------------------------------------------------------------------------
  4102 // ---------------------------------------------------------------------------
  4100 // HandleReserveGainEvent
  4103 // HandleReserveGainEvent
  4141     }
  4144     }
  4142   else
  4145   else
  4143     {
  4146     {
  4144     PRINT( _L("Camera <> no mode change ongoing") );
  4147     PRINT( _L("Camera <> no mode change ongoing") );
  4145     HandleCallbackEvent( aStatus,
  4148     HandleCallbackEvent( aStatus,
  4146                          ECamCameraEventReserveGain, 
  4149                          ECamCameraEventReserveGain,
  4147                          ECamCameraEventClassBasicControl );
  4150                          ECamCameraEventClassBasicControl );
  4148     }
  4151     }
  4149 #else
  4152 #else
  4150   HandleCallbackEvent( aStatus,
  4153   HandleCallbackEvent( aStatus,
  4151                        ECamCameraEventReserveGain, 
  4154                        ECamCameraEventReserveGain,
  4152                        ECamCameraEventClassBasicControl );
  4155                        ECamCameraEventClassBasicControl );
  4153 #endif // CAMERAAPP_CAE_FIX
  4156 #endif // CAMERAAPP_CAE_FIX
  4154   PRINT( _L("Camera <= CCamCameraController::HandleReserveGainEvent") );
  4157   PRINT( _L("Camera <= CCamCameraController::HandleReserveGainEvent") );
  4155   }
  4158   }
  4156 
  4159 
  4165   {
  4168   {
  4166   PRINT1( _L("Camera => CCamCameraController::HandleReserveLostEvent, status:%d"), aStatus );
  4169   PRINT1( _L("Camera => CCamCameraController::HandleReserveLostEvent, status:%d"), aStatus );
  4167   iInfo.iState   = ECamIdle;
  4170   iInfo.iState   = ECamIdle;
  4168   iInfo.iVfState = ECamTriIdle;
  4171   iInfo.iVfState = ECamTriIdle;
  4169   iInfo.iSsState = ECamTriIdle;
  4172   iInfo.iSsState = ECamTriIdle;
  4170   
  4173 
  4171 #pragma message("CCamCameraController: Reserve lost event does not stop sequence")
  4174 #pragma message("CCamCameraController: Reserve lost event does not stop sequence")
  4172 
  4175 
  4173   // These are not valid anymore.
  4176   // These are not valid anymore.
  4174   ReleaseCustomInterfaces();
  4177   ReleaseCustomInterfaces();
  4175 
  4178 
  4187     }
  4190     }
  4188   else
  4191   else
  4189 #endif // CAMERAAPP_CAPI_V2
  4192 #endif // CAMERAAPP_CAPI_V2
  4190     {
  4193     {
  4191     PRINT( _L("Camera <> no mode change ongoing") );
  4194     PRINT( _L("Camera <> no mode change ongoing") );
  4192     NotifyObservers( aStatus, 
  4195     NotifyObservers( aStatus,
  4193                      ECamCameraEventReserveLose,
  4196                      ECamCameraEventReserveLose,
  4194                      ECamCameraEventClassBasicControl );
  4197                      ECamCameraEventClassBasicControl );
  4195     }
  4198     }
  4196 
  4199 
  4197 #else // CAMERAAPP_CAE_FIX
  4200 #else // CAMERAAPP_CAE_FIX
  4198 /*
  4201 /*
  4199   // We need to tell to CCaeEngine that the CCamera 
  4202   // We need to tell to CCaeEngine that the CCamera
  4200   // has been released "behind its back".
  4203   // has been released "behind its back".
  4201   if( iCaeEngine )
  4204   if( iCaeEngine )
  4202     {
  4205     {
  4203     iCaeEngine->DisableVideoRecording();
  4206     iCaeEngine->DisableVideoRecording();
  4204     }
  4207     }
  4205 */    
  4208 */
  4206 #endif // CAMERAAPP_CAE_FIX
  4209 #endif // CAMERAAPP_CAE_FIX
  4207   // -------------------------------------------------------
  4210   // -------------------------------------------------------
  4208 #else
  4211 #else
  4209 
  4212 
  4210   NotifyObservers( aStatus, 
  4213   NotifyObservers( aStatus,
  4211                    ECamCameraEventReserveLose,
  4214                    ECamCameraEventReserveLose,
  4212                    ECamCameraEventClassBasicControl );
  4215                    ECamCameraEventClassBasicControl );
  4213   // -------------------------------------------------------
  4216   // -------------------------------------------------------
  4214 #endif // CAMERAAPP_CAE_FOR_VIDEO
  4217 #endif // CAMERAAPP_CAE_FOR_VIDEO
  4215 
  4218 
  4224   if ( !err && iIdle && !iIdle->IsActive() && // Recovering already
  4227   if ( !err && iIdle && !iIdle->IsActive() && // Recovering already
  4225        iAppController.IsAppUiAvailable()  && // Exit mode
  4228        iAppController.IsAppUiAvailable()  && // Exit mode
  4226        iIveRecoveryCount &&                   // Give up eventually
  4229        iIveRecoveryCount &&                   // Give up eventually
  4227        !appUi->AppInBackground( EFalse ) &&   // Only if on the foreground
  4230        !appUi->AppInBackground( EFalse ) &&   // Only if on the foreground
  4228        ( !iReleasedByUi ||             // Try recover if unknown reason
  4231        ( !iReleasedByUi ||             // Try recover if unknown reason
  4229          appUi->StandbyStatus() ) &&    // or known error 
  4232          appUi->StandbyStatus() ) &&    // or known error
  4230          !iAppController.InVideocallOrRinging() && // Video telephony parallel use case
  4233          !iAppController.InVideocallOrRinging() && // Video telephony parallel use case
  4231          !iIveRecoveryOngoing        //  processing recovery sequence
  4234          !iIveRecoveryOngoing        //  processing recovery sequence
  4232          )
  4235          )
  4233     {
  4236     {
  4234     PRINT( _L("Camera <> CCamCameraController::HandleReserveLostEvent - Start recovery") );
  4237     PRINT( _L("Camera <> CCamCameraController::HandleReserveLostEvent - Start recovery") );
  4235     NotifyObservers( aStatus, 
  4238     NotifyObservers( aStatus,
  4236                      ECamCameraEventReserveLose,
  4239                      ECamCameraEventReserveLose,
  4237                      ECamCameraEventClassBasicControl );
  4240                      ECamCameraEventClassBasicControl );
  4238     iIdle->Start( TCallBack( IdleCallback, this ) );  
  4241     iIdle->Start( TCallBack( IdleCallback, this ) );
  4239     }
  4242     }
  4240   PRINT( _L("Camera <= CCamCameraController::HandleReserveLostEvent") );
  4243   PRINT( _L("Camera <= CCamCameraController::HandleReserveLostEvent") );
  4241   }
  4244   }
  4242 
  4245 
  4243 // ---------------------------------------------------------------------------
  4246 // ---------------------------------------------------------------------------
  4244 // HandleViewfinderEvent
  4247 // HandleViewfinderEvent
  4245 // ---------------------------------------------------------------------------
  4248 // ---------------------------------------------------------------------------
  4246 //
  4249 //
  4247 void
  4250 void
  4248 CCamCameraController::HandleViewfinderEvent( MCameraBuffer* aCameraBuffer, 
  4251 CCamCameraController::HandleViewfinderEvent( MCameraBuffer* aCameraBuffer,
  4249                                              TInt           aStatus )
  4252                                              TInt           aStatus )
  4250   {
  4253   {
  4251   PRINT_FRQ1( _L("Camera => CCamCameraController::HandleViewfinderEvent, status in:%d"), aStatus );
  4254   PRINT_FRQ1( _L("Camera => CCamCameraController::HandleViewfinderEvent, status in:%d"), aStatus );
  4252 
  4255 
  4253   CAMERAAPP_PERF_CONTROLLER_STOP_ONCE( ECamRequestVfStart, iFirstVfFrameReceived );
  4256   CAMERAAPP_PERF_CONTROLLER_STOP_ONCE( ECamRequestVfStart, iFirstVfFrameReceived );
  4263       {
  4266       {
  4264       vfFrame = &(aCameraBuffer->BitmapL( 0 ));
  4267       vfFrame = &(aCameraBuffer->BitmapL( 0 ));
  4265       });
  4268       });
  4266     PRINT_FRQ1( _L("Camera <> ..status after getting bitmap data: %d"), aStatus );
  4269     PRINT_FRQ1( _L("Camera <> ..status after getting bitmap data: %d"), aStatus );
  4267     }
  4270     }
  4268      
  4271 
  4269   NotifyObservers( aStatus, 
  4272   NotifyObservers( aStatus,
  4270                    ECamCameraEventVfFrameReady, 
  4273                    ECamCameraEventVfFrameReady,
  4271                    ECamCameraEventClassVfData, 
  4274                    ECamCameraEventClassVfData,
  4272                    vfFrame );
  4275                    vfFrame );
  4273 
  4276 
  4274   ReleaseAndNull( aCameraBuffer );
  4277   ReleaseAndNull( aCameraBuffer );
  4275 
  4278 
  4276   PRINT_FRQ( _L("Camera <= CCamCameraController::HandleViewfinderEvent") );
  4279   PRINT_FRQ( _L("Camera <= CCamCameraController::HandleViewfinderEvent") );
  4280 // ---------------------------------------------------------------------------
  4283 // ---------------------------------------------------------------------------
  4281 // HandleImageCaptureEvent
  4284 // HandleImageCaptureEvent
  4282 // ---------------------------------------------------------------------------
  4285 // ---------------------------------------------------------------------------
  4283 //
  4286 //
  4284 void
  4287 void
  4285 CCamCameraController::HandleImageCaptureEvent( MCameraBuffer* aCameraBuffer, 
  4288 CCamCameraController::HandleImageCaptureEvent( MCameraBuffer* aCameraBuffer,
  4286                                                TInt           aStatus )
  4289                                                TInt           aStatus )
  4287   {
  4290   {
  4288   PRINT1( _L("Camera => CCamCameraController::HandleImageCaptureEvent, status in: %d"), aStatus );
  4291   PRINT1( _L("Camera => CCamCameraController::HandleImageCaptureEvent, status in: %d"), aStatus );
  4289 
  4292 
  4290 
  4293 
  4291   // Check that we are expecting images..
  4294   // Check that we are expecting images..
  4292   if( ECamCaptureOn == iInfo.iCaptureState )
  4295   if( ECamCaptureOn == iInfo.iCaptureState )
  4293     {
  4296     {
  4294     // Store flags
  4297     // Store flags
  4295     TUint busyFlags( iInfo.iBusy ); 
  4298     TUint busyFlags( iInfo.iBusy );
  4296       
  4299 
  4297     // -----------------------------------------------------
  4300     // -----------------------------------------------------
  4298     // Try to get the image data.
  4301     // Try to get the image data.
  4299     if( KErrNone == aStatus )
  4302     if( KErrNone == aStatus )
  4300       {
  4303       {
  4301       // Takes ownership of aCameraBuffer and NULLs the pointer.
  4304       // Takes ownership of aCameraBuffer and NULLs the pointer.
  4302       TRAP( aStatus, HandleImageCaptureEventL( aCameraBuffer ) );
  4305       TRAP( aStatus, HandleImageCaptureEventL( aCameraBuffer ) );
  4303       PRINT1( _L("Camera <> status after handling data: %d"), aStatus );
  4306       PRINT1( _L("Camera <> status after handling data: %d"), aStatus );
  4304       }    
  4307       }
  4305     
  4308 
  4306     // Release if not NULLed in HandleImageCaptureEventL.
  4309     // Release if not NULLed in HandleImageCaptureEventL.
  4307     ReleaseAndNull( aCameraBuffer );
  4310     ReleaseAndNull( aCameraBuffer );
  4308 
  4311 
  4309     // -----------------------------------------------------
  4312     // -----------------------------------------------------
  4310     // Errors in or in handling
  4313     // Errors in or in handling
  4316       iInfo.iCaptureState = ECamCaptureOff;
  4319       iInfo.iCaptureState = ECamCaptureOff;
  4317 
  4320 
  4318       // See HandleCallbackEvent for comments.
  4321       // See HandleCallbackEvent for comments.
  4319       // ClearFlags( iInfo.iBusy, ECamBusySingle );
  4322       // ClearFlags( iInfo.iBusy, ECamBusySingle );
  4320 
  4323 
  4321       NotifyObservers( aStatus, 
  4324       NotifyObservers( aStatus,
  4322                        ECamCameraEventImageData, 
  4325                        ECamCameraEventImageData,
  4323                        ECamCameraEventClassImage );
  4326                        ECamCameraEventClassImage );
  4324       }
  4327       }
  4325     // -----------------------------------------------------
  4328     // -----------------------------------------------------
  4326 
  4329 
  4327     // If capture state was just changed to OFF,
  4330     // If capture state was just changed to OFF,
  4330       {
  4333       {
  4331       // See HandleCallbackEvent for comments.
  4334       // See HandleCallbackEvent for comments.
  4332       ClearFlags( iInfo.iBusy, ECamBusySingle );
  4335       ClearFlags( iInfo.iBusy, ECamBusySingle );
  4333 
  4336 
  4334       TInt fullCaptures( Min( iInfo.iCaptureCount, iInfo.iSnapshotCount ) );
  4337       TInt fullCaptures( Min( iInfo.iCaptureCount, iInfo.iSnapshotCount ) );
  4335       NotifyObservers( aStatus, 
  4338       NotifyObservers( aStatus,
  4336                        ECamCameraEventImageStop, 
  4339                        ECamCameraEventImageStop,
  4337                        ECamCameraEventClassImage,
  4340                        ECamCameraEventClassImage,
  4338                        &fullCaptures );
  4341                        &fullCaptures );
  4339 
  4342 
  4340       // Now we can actually continue, if necessary.
  4343       // Now we can actually continue, if necessary.
  4341       if( IsFlagOn( busyFlags, ECamBusySequence ) )
  4344       if( IsFlagOn( busyFlags, ECamBusySequence ) )
  4347     }
  4350     }
  4348   else
  4351   else
  4349     {
  4352     {
  4350     PRINT( _L("Camera <> CCamCameraController ... [WARNING] Unexpected image data event!") );
  4353     PRINT( _L("Camera <> CCamCameraController ... [WARNING] Unexpected image data event!") );
  4351     iInfo.PrintInfo();
  4354     iInfo.PrintInfo();
  4352     
  4355 
  4353     // Stop capture to be safe.
  4356     // Stop capture to be safe.
  4354     PRINT( _L("Camera <> CCamCameraController ... Calling CancelCaptureImage..") );
  4357     PRINT( _L("Camera <> CCamCameraController ... Calling CancelCaptureImage..") );
  4355     iCamera->CancelCaptureImage();
  4358     iCamera->CancelCaptureImage();
  4356 
  4359 
  4357     // Not expecting image data at this time.
  4360     // Not expecting image data at this time.
  4382 
  4385 
  4383   share->Reserve();
  4386   share->Reserve();
  4384   CleanupStack::PushL( TCleanupItem( CamBufferShareCleanup, share ) );
  4387   CleanupStack::PushL( TCleanupItem( CamBufferShareCleanup, share ) );
  4385 
  4388 
  4386   PRINT( _L("Camera <> CCamCameraController .. Checking encoded data availability..") );
  4389   PRINT( _L("Camera <> CCamCameraController .. Checking encoded data availability..") );
  4387   TRAPD( dataStatus, 
  4390   TRAPD( dataStatus,
  4388     {
  4391     {
  4389     TDesC8* data = share->SharedBuffer()->DataL( 0 );
  4392     TDesC8* data = share->SharedBuffer()->DataL( 0 );
  4390     if( !data ) 
  4393     if( !data )
  4391       User::Leave( KErrNotFound );
  4394       User::Leave( KErrNotFound );
  4392     });
  4395     });
  4393 
  4396 
  4394   // -------------------------------------------------------
  4397   // -------------------------------------------------------
  4395   // Normal capture format case
  4398   // Normal capture format case
  4400     // Increase received images count. Needed in burst drive mode.
  4403     // Increase received images count. Needed in burst drive mode.
  4401     iInfo.iCaptureCount++;
  4404     iInfo.iCaptureCount++;
  4402     PRINT1( _L("Camera <> CCamCameraController ... Incremented capture counter to: %d"), iInfo.iCaptureCount );
  4405     PRINT1( _L("Camera <> CCamCameraController ... Incremented capture counter to: %d"), iInfo.iCaptureCount );
  4403 
  4406 
  4404     // If we have needed amount of snapshots and images, end capture.
  4407     // If we have needed amount of snapshots and images, end capture.
  4405     if( iInfo.iCaptureCount  >= iInfo.iCaptureLimit 
  4408     if( iInfo.iCaptureCount  >= iInfo.iCaptureLimit
  4406      && ( (iInfo.iSnapshotCount >= iInfo.iCaptureLimit) || iInfo.iSsState != ECamTriActive ) )
  4409      && ( (iInfo.iSnapshotCount >= iInfo.iCaptureLimit) || iInfo.iSsState != ECamTriActive ) )
  4407       {
  4410       {
  4408       PRINT( _L("Camera <> CCamCameraController ... Capture limit met, calling CancelCaptureImage..") );
  4411       PRINT( _L("Camera <> CCamCameraController ... Capture limit met, calling CancelCaptureImage..") );
  4409       iCamera->CancelCaptureImage();
  4412       iCamera->CancelCaptureImage();
  4410 
  4413 
  4413       }
  4416       }
  4414 #ifdef CAMERAAPP_CAPI_V2_ADV
  4417 #ifdef CAMERAAPP_CAPI_V2_ADV
  4415     // If we are in burst mode and need to increase capture limit,
  4418     // If we are in burst mode and need to increase capture limit,
  4416     // do it now. If we have just decreased the capture limit,
  4419     // do it now. If we have just decreased the capture limit,
  4417     // we just cancel once the limit is met.
  4420     // we just cancel once the limit is met.
  4418     else if( iAdvancedSettings 
  4421     else if( iAdvancedSettings
  4419           && iAdvancedSettings->DriveMode() == CAS::EDriveModeBurst )
  4422           && iAdvancedSettings->DriveMode() == CAS::EDriveModeBurst )
  4420       {
  4423       {
  4421       const TInt cameraLimit( iAdvancedSettings->BurstImages() );
  4424       const TInt cameraLimit( iAdvancedSettings->BurstImages() );
  4422 
  4425 
  4423       PRINT1( _L("Camera <> CCamCameraController ... Camera capture limit: %d"), cameraLimit         );
  4426       PRINT1( _L("Camera <> CCamCameraController ... Camera capture limit: %d"), cameraLimit         );
  4439       }
  4442       }
  4440 
  4443 
  4441     // See HandleCallbackEvent for comments.
  4444     // See HandleCallbackEvent for comments.
  4442     // ClearFlags( iInfo.iBusy, ECamBusySingle );
  4445     // ClearFlags( iInfo.iBusy, ECamBusySingle );
  4443 
  4446 
  4444     NotifyObservers( KErrNone, 
  4447     NotifyObservers( KErrNone,
  4445                      ECamCameraEventImageData,
  4448                      ECamCameraEventImageData,
  4446                      ECamCameraEventClassImage, 
  4449                      ECamCameraEventClassImage,
  4447                      share );
  4450                      share );
  4448     }
  4451     }
  4449   // -------------------------------------------------------
  4452   // -------------------------------------------------------
  4450   // Bitmap format case. Need to encode first.
  4453   // Bitmap format case. Need to encode first.
  4451   else if( iAlternateFormatInUse )
  4454   else if( iAlternateFormatInUse )
  4484 
  4487 
  4485   // Check that we are in right state to handle snapshot.
  4488   // Check that we are in right state to handle snapshot.
  4486   // CCameraSnapshot sends atleast event with KErrCancel status
  4489   // CCameraSnapshot sends atleast event with KErrCancel status
  4487   // when releasing the camera.
  4490   // when releasing the camera.
  4488   TBool videoSsExpected( IsFlagOn( iInfo.iState, ECamVideoOn ) );
  4491   TBool videoSsExpected( IsFlagOn( iInfo.iState, ECamVideoOn ) );
  4489   TBool imageSsExpected( IsFlagOn( iInfo.iState, ECamImageOn ) 
  4492   TBool imageSsExpected( IsFlagOn( iInfo.iState, ECamImageOn )
  4490                       && ECamCaptureOn        == iInfo.iCaptureState
  4493                       && ECamCaptureOn        == iInfo.iCaptureState
  4491                       && iInfo.iSnapshotCount <  iInfo.iCaptureLimit );
  4494                       && iInfo.iSnapshotCount <  iInfo.iCaptureLimit );
  4492 
  4495 
  4493   if( 
  4496   if(
  4494 #ifdef CAMERAAPP_CAE_FIX
  4497 #ifdef CAMERAAPP_CAE_FIX
  4495       ECamModeChangeInactive == iModeChange &&
  4498       ECamModeChangeInactive == iModeChange &&
  4496 #endif
  4499 #endif
  4497       (videoSsExpected||imageSsExpected)
  4500       (videoSsExpected||imageSsExpected)
  4498     )
  4501     )
  4504     if( KErrNone == aStatus )
  4507     if( KErrNone == aStatus )
  4505       {
  4508       {
  4506       TRAP( aStatus, HandleSnapshotEventL() );
  4509       TRAP( aStatus, HandleSnapshotEventL() );
  4507       PRINT1( _L("Camera <> CCamCameraController ... status after handling snapshot data: %d"), aStatus );
  4510       PRINT1( _L("Camera <> CCamCameraController ... status after handling snapshot data: %d"), aStatus );
  4508       }
  4511       }
  4509   
  4512 
  4510     // -----------------------------------------------------
  4513     // -----------------------------------------------------
  4511     // If snapshot was received and notified ok,
  4514     // If snapshot was received and notified ok,
  4512     // check if capture ended.
  4515     // check if capture ended.
  4513     if( KErrNone == aStatus )
  4516     if( KErrNone == aStatus )
  4514       {
  4517       {
  4515       // If we have needed amount of snapshots and images, end capture.
  4518       // If we have needed amount of snapshots and images, end capture.
  4516       if( iInfo.iCaptureCount  >= iInfo.iCaptureLimit 
  4519       if( iInfo.iCaptureCount  >= iInfo.iCaptureLimit
  4517        && iInfo.iSnapshotCount >= iInfo.iCaptureLimit )
  4520        && iInfo.iSnapshotCount >= iInfo.iCaptureLimit )
  4518         {
  4521         {
  4519         PRINT( _L("Camera <> CCamCameraController ... Setting capture state to OFF..") );
  4522         PRINT( _L("Camera <> CCamCameraController ... Setting capture state to OFF..") );
  4520         iInfo.iCaptureState = ECamCaptureOff;
  4523         iInfo.iCaptureState = ECamCaptureOff;
  4521         }
  4524         }
  4523     // -----------------------------------------------------
  4526     // -----------------------------------------------------
  4524     // If any error, stop capture.
  4527     // If any error, stop capture.
  4525     else
  4528     else
  4526       {
  4529       {
  4527       PRINT( _L("Camera <> CCamCameraController ... error encountered, notify and set capture state off..") );
  4530       PRINT( _L("Camera <> CCamCameraController ... error encountered, notify and set capture state off..") );
  4528       NotifyObservers( aStatus, 
  4531       NotifyObservers( aStatus,
  4529                        ECamCameraEventSsReady, 
  4532                        ECamCameraEventSsReady,
  4530                        ECamCameraEventClassSsData );
  4533                        ECamCameraEventClassSsData );
  4531       iInfo.iCaptureState = ECamCaptureOff;
  4534       iInfo.iCaptureState = ECamCaptureOff;
  4532       }
  4535       }
  4533 
  4536 
  4534     // -----------------------------------------------------
  4537     // -----------------------------------------------------
  4539       {
  4542       {
  4540       // See HandleCallbackEvent for comments.
  4543       // See HandleCallbackEvent for comments.
  4541       ClearFlags( iInfo.iBusy, ECamBusySingle );
  4544       ClearFlags( iInfo.iBusy, ECamBusySingle );
  4542 
  4545 
  4543       TInt fullCaptures( Min( iInfo.iCaptureCount, iInfo.iSnapshotCount ) );
  4546       TInt fullCaptures( Min( iInfo.iCaptureCount, iInfo.iSnapshotCount ) );
  4544       NotifyObservers( aStatus, 
  4547       NotifyObservers( aStatus,
  4545                        ECamCameraEventImageStop, 
  4548                        ECamCameraEventImageStop,
  4546                        ECamCameraEventClassImage,
  4549                        ECamCameraEventClassImage,
  4547                        &fullCaptures );
  4550                        &fullCaptures );
  4548       }
  4551       }
  4549     // -----------------------------------------------------
  4552     // -----------------------------------------------------
  4550     }
  4553     }
  4555 
  4558 
  4556     if( iInfo.iSnapshotCount > iInfo.iCaptureLimit )
  4559     if( iInfo.iSnapshotCount > iInfo.iCaptureLimit )
  4557       {
  4560       {
  4558       // For burst stopping:
  4561       // For burst stopping:
  4559       //   We have more snapshots already than requested..
  4562       //   We have more snapshots already than requested..
  4560       //   All needed captures have to have started, 
  4563       //   All needed captures have to have started,
  4561       //   so we can call cancel here.
  4564       //   so we can call cancel here.
  4562       // Note: 
  4565       // Note:
  4563       //   Cannot use ">=" as last image might not be provided then.
  4566       //   Cannot use ">=" as last image might not be provided then.
  4564       //   
  4567       //
  4565       PRINT( _L("Camera <> CCamCameraController ... Snapshot limit passed, calling CancelCaptureImage..") );
  4568       PRINT( _L("Camera <> CCamCameraController ... Snapshot limit passed, calling CancelCaptureImage..") );
  4566       iCamera->CancelCaptureImage();
  4569       iCamera->CancelCaptureImage();
  4567       }
  4570       }
  4568 
  4571 
  4569     PRINT( _L("Camera <> CCamCameraController ... [WARNING] Snapshot ignored!") );
  4572     PRINT( _L("Camera <> CCamCameraController ... [WARNING] Snapshot ignored!") );
  4578 // HandleSnapshotEventL
  4581 // HandleSnapshotEventL
  4579 //
  4582 //
  4580 // Helper method for leaving part of HandleSnapshotEvent.
  4583 // Helper method for leaving part of HandleSnapshotEvent.
  4581 // ---------------------------------------------------------------------------
  4584 // ---------------------------------------------------------------------------
  4582 //
  4585 //
  4583 void 
  4586 void
  4584 CCamCameraController::HandleSnapshotEventL( TBool aIgnore )
  4587 CCamCameraController::HandleSnapshotEventL( TBool aIgnore )
  4585   {
  4588   {
  4586    PRINT1( _L("Camera => CCamCameraController::HandleSnapshotEventL ignore %d"),aIgnore);
  4589    PRINT1( _L("Camera => CCamCameraController::HandleSnapshotEventL ignore %d"),aIgnore);
  4587   __ASSERT_DEBUG( iSnapshotProvider, Panic( ECamCameraControllerCorrupt ) );
  4590   __ASSERT_DEBUG( iSnapshotProvider, Panic( ECamCameraControllerCorrupt ) );
  4588   RArray<TInt> temp;
  4591   RArray<TInt> temp;
  4593 
  4596 
  4594   TInt firstImageIndex = temp.Find( 0 );
  4597   TInt firstImageIndex = temp.Find( 0 );
  4595   CleanupStack::PopAndDestroy(); // temp.Close()
  4598   CleanupStack::PopAndDestroy(); // temp.Close()
  4596 
  4599 
  4597   if( !aIgnore )
  4600   if( !aIgnore )
  4598       { 
  4601       {
  4599 
  4602 
  4600       CleanupStack::PushL( TCleanupItem( CameraBufferCleanup, buffer ) );
  4603       CleanupStack::PushL( TCleanupItem( CameraBufferCleanup, buffer ) );
  4601       CFbsBitmap& snapshot = buffer->BitmapL( firstImageIndex );
  4604       CFbsBitmap& snapshot = buffer->BitmapL( firstImageIndex );
  4602       PRINT2( _L("Camera <> CCamCameraController ... snapshot size: (%dx%d)"), 
  4605       PRINT2( _L("Camera <> CCamCameraController ... snapshot size: (%dx%d)"),
  4603               snapshot.SizeInPixels().iWidth, snapshot.SizeInPixels().iHeight );
  4606               snapshot.SizeInPixels().iWidth, snapshot.SizeInPixels().iHeight );
  4604 
  4607 
  4605       // Increase received snapshots count.
  4608       // Increase received snapshots count.
  4606       // Needed in burst drive mode.
  4609       // Needed in burst drive mode.
  4607       iInfo.iSnapshotCount++;
  4610       iInfo.iSnapshotCount++;
  4614               ECamCameraEventClassSsData,
  4617               ECamCameraEventClassSsData,
  4615               &snapshot );
  4618               &snapshot );
  4616 
  4619 
  4617       CleanupStack::PopAndDestroy(); // buffer->Release()
  4620       CleanupStack::PopAndDestroy(); // buffer->Release()
  4618       }
  4621       }
  4619   else 
  4622   else
  4620       {
  4623       {
  4621       ReleaseAndNull(buffer);
  4624       ReleaseAndNull(buffer);
  4622       }
  4625       }
  4623   PRINT( _L("Camera <= CCamCameraController::HandleSnapshotEventL"));
  4626   PRINT( _L("Camera <= CCamCameraController::HandleSnapshotEventL"));
  4624   }
  4627   }
  4628 
  4631 
  4629 // ---------------------------------------------------------------------------
  4632 // ---------------------------------------------------------------------------
  4630 // HandleVideoInitEvent
  4633 // HandleVideoInitEvent
  4631 // ---------------------------------------------------------------------------
  4634 // ---------------------------------------------------------------------------
  4632 //
  4635 //
  4633 void 
  4636 void
  4634 CCamCameraController::HandleVideoEvent( const TCamCameraEventId& aEventId,
  4637 CCamCameraController::HandleVideoEvent( const TCamCameraEventId& aEventId,
  4635                                               TInt               aStatus   )
  4638                                               TInt               aStatus   )
  4636   {
  4639   {
  4637   PRINT2( _L("Camera => CCamCameraController::HandleVideoEvent, status:%d, event[%s]"), 
  4640   PRINT2( _L("Camera => CCamCameraController::HandleVideoEvent, status:%d, event[%s]"),
  4638           aStatus, 
  4641           aStatus,
  4639           KCamCameraEventNames[aEventId] );
  4642           KCamCameraEventNames[aEventId] );
  4640   
  4643 
  4641   // Only video stop of these events may come without our explicit request.
  4644   // Only video stop of these events may come without our explicit request.
  4642 /*
  4645 /*
  4643   if( ECamCameraEventVideoStop != aEventId )
  4646   if( ECamCameraEventVideoStop != aEventId )
  4644     {
  4647     {
  4645     if( ECamBusyOff != iInfo.iBusy )
  4648     if( ECamBusyOff != iInfo.iBusy )
  4657         CAMERAAPP_PERF_CONTROLLER_STOP( ECamRequestVideoInit );
  4660         CAMERAAPP_PERF_CONTROLLER_STOP( ECamRequestVideoInit );
  4658         if( KErrNone == aStatus ) SetFlags  ( iInfo.iState, ECamVideoOn );
  4661         if( KErrNone == aStatus ) SetFlags  ( iInfo.iState, ECamVideoOn );
  4659         else                      ClearFlags( iInfo.iState, ECamVideoOn );
  4662         else                      ClearFlags( iInfo.iState, ECamVideoOn );
  4660         }
  4663         }
  4661 #ifdef CAMERAAPP_CAPI_V2_ADV
  4664 #ifdef CAMERAAPP_CAPI_V2_ADV
  4662         TRAP_IGNORE( GetAdvancedSettingsInfoL() );  
  4665         TRAP_IGNORE( GetAdvancedSettingsInfoL() );
  4663 #endif
  4666 #endif
  4664 #ifdef CAMERAAPP_CAE_FIX
  4667 #ifdef CAMERAAPP_CAE_FIX
  4665       if( ECamModeChangeImage2Video == iModeChange )
  4668       if( ECamModeChangeImage2Video == iModeChange )
  4666         {
  4669         {
  4667         iModeChangeStatus = aStatus;
  4670         iModeChangeStatus = aStatus;
  4670         }
  4673         }
  4671 #endif // CAMERAAPP_CAE_FIX
  4674 #endif // CAMERAAPP_CAE_FIX
  4672       break;
  4675       break;
  4673     // -----------------------------------------------------
  4676     // -----------------------------------------------------
  4674     case ECamCameraEventVideoStart:
  4677     case ECamCameraEventVideoStart:
  4675       if( KErrNone == aStatus ) 
  4678       if( KErrNone == aStatus )
  4676         {
  4679         {
  4677         iInfo.iCaptureState = ECamCaptureOn;
  4680         iInfo.iCaptureState = ECamCaptureOn;
  4678         }
  4681         }
  4679       break;
  4682       break;
  4680     // -----------------------------------------------------
  4683     // -----------------------------------------------------
  4681     case ECamCameraEventVideoPause:
  4684     case ECamCameraEventVideoPause:
  4682       if( KErrNone == aStatus ) 
  4685       if( KErrNone == aStatus )
  4683         {
  4686         {
  4684         iInfo.iCaptureState = ECamCapturePaused;
  4687         iInfo.iCaptureState = ECamCapturePaused;
  4685         }
  4688         }
  4686       else
  4689       else
  4687         {
  4690         {
  4694       // Even if error we have done what we can for stopping.
  4697       // Even if error we have done what we can for stopping.
  4695       // Update internal capture state anyway.
  4698       // Update internal capture state anyway.
  4696       iInfo.iCaptureState = ECamCaptureOff;
  4699       iInfo.iCaptureState = ECamCaptureOff;
  4697       // We may receive this event from CCaeEngine, even though we have not
  4700       // We may receive this event from CCaeEngine, even though we have not
  4698       // issued a request to stop the video recording. If e.g. there is not
  4701       // issued a request to stop the video recording. If e.g. there is not
  4699       // enough space in the disk to continue recording, this event is 
  4702       // enough space in the disk to continue recording, this event is
  4700       // generated without explicit request.
  4703       // generated without explicit request.
  4701       //
  4704       //
  4702       // We must not continue any pending operations if this event is not 
  4705       // We must not continue any pending operations if this event is not
  4703       // a response to our stop request. 
  4706       // a response to our stop request.
  4704       // HandleCallbackEvent takes care of that.
  4707       // HandleCallbackEvent takes care of that.
  4705       break;
  4708       break;
  4706     // -----------------------------------------------------
  4709     // -----------------------------------------------------
  4707     case ECamCameraEventVideoAsyncStop:
  4710     case ECamCameraEventVideoAsyncStop:
  4708       PRINT( _L("Camera <> CCamCameraController::HandleVideoEvent case ECamCameraEventVideoAsyncStop") );
  4711       PRINT( _L("Camera <> CCamCameraController::HandleVideoEvent case ECamCameraEventVideoAsyncStop") );
  4715       break;
  4718       break;
  4716       }
  4719       }
  4717     // -----------------------------------------------------
  4720     // -----------------------------------------------------
  4718     }
  4721     }
  4719 
  4722 
  4720   HandleCallbackEvent( aStatus, 
  4723   HandleCallbackEvent( aStatus,
  4721                        aEventId, 
  4724                        aEventId,
  4722                        ECamCameraEventClassVideo );
  4725                        ECamCameraEventClassVideo );
  4723   PRINT( _L("Camera <= CCamCameraController::HandleVideoEvent") );
  4726   PRINT( _L("Camera <= CCamCameraController::HandleVideoEvent") );
  4724   }
  4727   }
  4725 
  4728 
  4726 
  4729 
  4727 #ifdef CAMERAAPP_CAE_FOR_VIDEO
  4730 #ifdef CAMERAAPP_CAE_FOR_VIDEO
  4728 // ---------------------------------------------------------------------------
  4731 // ---------------------------------------------------------------------------
  4729 // HandleVideoTimeEvent
  4732 // HandleVideoTimeEvent
  4730 // ---------------------------------------------------------------------------
  4733 // ---------------------------------------------------------------------------
  4731 //
  4734 //
  4732 void 
  4735 void
  4733 CCamCameraController
  4736 CCamCameraController
  4734 ::HandleVideoTimeEvent( TInt aStatus, 
  4737 ::HandleVideoTimeEvent( TInt aStatus,
  4735                         TTimeIntervalMicroSeconds aTimeElapsed, 
  4738                         TTimeIntervalMicroSeconds aTimeElapsed,
  4736                         TTimeIntervalMicroSeconds aTimeRemaining )
  4739                         TTimeIntervalMicroSeconds aTimeRemaining )
  4737   {
  4740   {
  4738   // If capture has already stopped, we don't echo this to our observers.
  4741   // If capture has already stopped, we don't echo this to our observers.
  4739   if( ECamCaptureOff != iInfo.iCaptureState )
  4742   if( ECamCaptureOff != iInfo.iCaptureState )
  4740     {
  4743     {
  4741     iVideoTimes.iTimeElapsed   = aTimeElapsed.Int64();
  4744     iVideoTimes.iTimeElapsed   = aTimeElapsed.Int64();
  4742     iVideoTimes.iTimeRemaining = aTimeRemaining.Int64();
  4745     iVideoTimes.iTimeRemaining = aTimeRemaining.Int64();
  4743     
  4746 
  4744     NotifyObservers( aStatus, 
  4747     NotifyObservers( aStatus,
  4745                      ECamCameraEventVideoTimes, 
  4748                      ECamCameraEventVideoTimes,
  4746                      ECamCameraEventClassVideoTimes,
  4749                      ECamCameraEventClassVideoTimes,
  4747                      &iVideoTimes );
  4750                      &iVideoTimes );
  4748     }
  4751     }
  4749   }
  4752   }
  4750 #endif
  4753 #endif
  4752 // ---------------------------------------------------------------------------
  4755 // ---------------------------------------------------------------------------
  4753 // HandleAutoFocusEvent
  4756 // HandleAutoFocusEvent
  4754 //
  4757 //
  4755 // ---------------------------------------------------------------------------
  4758 // ---------------------------------------------------------------------------
  4756 //
  4759 //
  4757 void 
  4760 void
  4758 CCamCameraController::HandleAutoFocusEvent( TInt aStatus, const TUid& aEventUid )
  4761 CCamCameraController::HandleAutoFocusEvent( TInt aStatus, const TUid& aEventUid )
  4759   {
  4762   {
  4760   PRINT1( _L("Camera => CCamCameraController::HandleAutoFocusEvent, status: %d"), aStatus ); 
  4763   PRINT1( _L("Camera => CCamCameraController::HandleAutoFocusEvent, status: %d"), aStatus );
  4761   TBool proceed = EFalse;
  4764   TBool proceed = EFalse;
  4762 
  4765 
  4763   // -------------------------------------------------------
  4766   // -------------------------------------------------------
  4764   // Check the event 
  4767   // Check the event
  4765   if( KUidECamEventCameraSettingsOptimalFocus == aEventUid )
  4768   if( KUidECamEventCameraSettingsOptimalFocus == aEventUid )
  4766     {
  4769     {
  4767     PRINT( _L("Camera <> CCamCameraController: event KUidECamEventCameraSettingsOptimalFocus") );
  4770     PRINT( _L("Camera <> CCamCameraController: event KUidECamEventCameraSettingsOptimalFocus") );
  4768     if( !iAfHyperfocalPending )
  4771     if( !iAfHyperfocalPending )
  4769       {
  4772       {
  4772       iFirstAfEventReceived = EFalse;
  4775       iFirstAfEventReceived = EFalse;
  4773       }
  4776       }
  4774     }
  4777     }
  4775   else if( KUidECamEventCameraSettingAutoFocusType2 == aEventUid )
  4778   else if( KUidECamEventCameraSettingAutoFocusType2 == aEventUid )
  4776     {
  4779     {
  4777     PRINT( _L("Camera <> CCamCameraController: event KUidECamEventCameraSettingsAutoFocusType2") );      
  4780     PRINT( _L("Camera <> CCamCameraController: event KUidECamEventCameraSettingsAutoFocusType2") );
  4778     // If AF started and canceled before finishing
  4781     // If AF started and canceled before finishing
  4779     if( iAfInProgress && iAfHyperfocalPending && iFirstAfEventReceived )
  4782     if( iAfInProgress && iAfHyperfocalPending && iFirstAfEventReceived )
  4780       {
  4783       {
  4781       // continue to set focus to hyperfocal    
  4784       // continue to set focus to hyperfocal
  4782       proceed = ETrue;    
  4785       proceed = ETrue;
  4783       }
  4786       }
  4784     if( !iFirstAfEventReceived )  
  4787     if( !iFirstAfEventReceived )
  4785       {
  4788       {
  4786       // For the first time, this event means that the autofocusing has been started
  4789       // For the first time, this event means that the autofocusing has been started
  4787       iFirstAfEventReceived = ETrue;  
  4790       iFirstAfEventReceived = ETrue;
  4788       PRINT( _L("Camera <> CCamCameraController: event KUidECamEventCameraSettingAutoFocusType2 - first time, set iFirstAfEventReceived ") );
  4791       PRINT( _L("Camera <> CCamCameraController: event KUidECamEventCameraSettingAutoFocusType2 - first time, set iFirstAfEventReceived ") );
  4789       }
  4792       }
  4790     else
  4793     else
  4791       {
  4794       {
  4792       iFirstAfEventReceived = EFalse;      
  4795       iFirstAfEventReceived = EFalse;
  4793       PRINT( _L("Camera <> CCamCameraController: event KUidECamEventCameraSettingAutoFocusType2 - second time") );    
  4796       PRINT( _L("Camera <> CCamCameraController: event KUidECamEventCameraSettingAutoFocusType2 - second time") );
  4794       }        
  4797       }
  4795     }
  4798     }
  4796   else
  4799   else
  4797     {
  4800     {
  4798     // No other event acceptable here..
  4801     // No other event acceptable here..
  4799     __ASSERT_DEBUG( EFalse, Panic( ECamCameraControllerCorrupt ) );
  4802     __ASSERT_DEBUG( EFalse, Panic( ECamCameraControllerCorrupt ) );
  4804     {
  4807     {
  4805     TCamCameraEventId  event = ( KErrNone == aStatus )
  4808     TCamCameraEventId  event = ( KErrNone == aStatus )
  4806                              ? ECamCameraEventAutofocusSuccessful
  4809                              ? ECamCameraEventAutofocusSuccessful
  4807                              : ECamCameraEventAutofocusFailed;
  4810                              : ECamCameraEventAutofocusFailed;
  4808     if( iAfHyperfocalPending )
  4811     if( iAfHyperfocalPending )
  4809       {                         
  4812       {
  4810       PRINT( _L("Camera <> Cancelled active autofocus request.") );
  4813       PRINT( _L("Camera <> Cancelled active autofocus request.") );
  4811       PRINT( _L("Camera <> Setting focus range to hyperfocal, no event to observers yet") );       
  4814       PRINT( _L("Camera <> Setting focus range to hyperfocal, no event to observers yet") );
  4812       iAfHyperfocalPending = EFalse; 
  4815       iAfHyperfocalPending = EFalse;
  4813       iAfInProgress = EFalse;
  4816       iAfInProgress = EFalse;
  4814       TRAP_IGNORE( ProcessAutofocusRequestL( ECamRequestCancelAutofocus ) );
  4817       TRAP_IGNORE( ProcessAutofocusRequestL( ECamRequestCancelAutofocus ) );
  4815       }       
  4818       }
  4816     else 
  4819     else
  4817       {
  4820       {
  4818       HandleCallbackEvent( KErrNone,
  4821       HandleCallbackEvent( KErrNone,
  4819                            event, 
  4822                            event,
  4820                            ECamCameraEventClassAutofocus );
  4823                            ECamCameraEventClassAutofocus );
  4821       }                  
  4824       }
  4822                
  4825 
  4823     }
  4826     }
  4824   else if(iFirstAfEventReceived && (aStatus != KErrNone) )
  4827   else if(iFirstAfEventReceived && (aStatus != KErrNone) )
  4825     {
  4828     {
  4826     //There might have been error when first event was received
  4829     //There might have been error when first event was received
  4827     //and no further autofocus events would occur.
  4830     //and no further autofocus events would occur.
  4828     iFirstAfEventReceived = EFalse;
  4831     iFirstAfEventReceived = EFalse;
  4829     iAfInProgress = EFalse;
  4832     iAfInProgress = EFalse;
  4830     
  4833 
  4831     if( iAfHyperfocalPending )
  4834     if( iAfHyperfocalPending )
  4832       {                         
  4835       {
  4833       PRINT( _L("Camera <> Cancelled active autofocus request.") );
  4836       PRINT( _L("Camera <> Cancelled active autofocus request.") );
  4834       PRINT( _L("Camera <> Set focus range to hyperfocal, no event to observers yet") );       
  4837       PRINT( _L("Camera <> Set focus range to hyperfocal, no event to observers yet") );
  4835       iAfHyperfocalPending = EFalse; 
  4838       iAfHyperfocalPending = EFalse;
  4836       TRAP_IGNORE( ProcessAutofocusRequestL( ECamRequestCancelAutofocus ) );
  4839       TRAP_IGNORE( ProcessAutofocusRequestL( ECamRequestCancelAutofocus ) );
  4837       }       
  4840       }
  4838     else
  4841     else
  4839       {
  4842       {
  4840       HandleCallbackEvent( KErrNone,
  4843       HandleCallbackEvent( KErrNone,
  4841                            ECamCameraEventAutofocusFailed, 
  4844                            ECamCameraEventAutofocusFailed,
  4842                            ECamCameraEventClassAutofocus );           
  4845                            ECamCameraEventClassAutofocus );
  4843       }                                      
  4846       }
  4844     }
  4847     }
  4845   // -------------------------------------------------------
  4848   // -------------------------------------------------------
  4846   PRINT( _L("Camera <= CCamCameraController::HandleAutoFocusEvent") ); 
  4849   PRINT( _L("Camera <= CCamCameraController::HandleAutoFocusEvent") );
  4847   }
  4850   }
  4848 
  4851 
  4849 
  4852 
  4850 
  4853 
  4851 // ---------------------------------------------------------------------------
  4854 // ---------------------------------------------------------------------------
  4852 //
  4855 //
  4853 // HandleFlashStatusEvent
  4856 // HandleFlashStatusEvent
  4854 //
  4857 //
  4855 // Helper method to handle flash status updates.
  4858 // Helper method to handle flash status updates.
  4856 // 
  4859 //
  4857 // ---------------------------------------------------------------------------
  4860 // ---------------------------------------------------------------------------
  4858 void
  4861 void
  4859 CCamCameraController::HandleFlashStatusEvent( TInt                     aStatus,
  4862 CCamCameraController::HandleFlashStatusEvent( TInt                     aStatus,
  4860                                               const TCamCameraEventId& aEventId )
  4863                                               const TCamCameraEventId& aEventId )
  4861   {
  4864   {
  4862   PRINT2( _L("Camera => CCamCameraController::HandleFlashStatusEvent, event[%s] status:%d"), KCamCameraEventNames[aEventId], aStatus ); 
  4865   PRINT2( _L("Camera => CCamCameraController::HandleFlashStatusEvent, event[%s] status:%d"), KCamCameraEventNames[aEventId], aStatus );
  4863   NotifyObservers( aStatus, 
  4866   NotifyObservers( aStatus,
  4864                    aEventId,
  4867                    aEventId,
  4865                    EventClass( aEventId ) );
  4868                    EventClass( aEventId ) );
  4866   PRINT ( _L("Camera <= CCamCameraController::HandleFlashStatusEvent" ) ); 
  4869   PRINT ( _L("Camera <= CCamCameraController::HandleFlashStatusEvent" ) );
  4867   }
  4870   }
  4868 
  4871 
  4869 
  4872 
  4870 
  4873 
  4871 // ---------------------------------------------------------------------------
  4874 // ---------------------------------------------------------------------------
  4875 // Notifies observers and checks if we should proceed with the sequence.
  4878 // Notifies observers and checks if we should proceed with the sequence.
  4876 // ---------------------------------------------------------------------------
  4879 // ---------------------------------------------------------------------------
  4877 //
  4880 //
  4878 void
  4881 void
  4879 CCamCameraController
  4882 CCamCameraController
  4880 ::HandleCallbackEvent(       TInt                    aStatus, 
  4883 ::HandleCallbackEvent(       TInt                    aStatus,
  4881                        const TCamCameraEventId&      aEventId, 
  4884                        const TCamCameraEventId&      aEventId,
  4882                        const TCamCameraEventClassId& aEventClass,
  4885                        const TCamCameraEventClassId& aEventClass,
  4883                              TAny*                   aEventData /*= NULL*/ )
  4886                              TAny*                   aEventData /*= NULL*/ )
  4884   {
  4887   {
  4885   PRINT1( _L("Camera => CCamCameraController::HandleCallbackEvent, event[%s]"), 
  4888   PRINT1( _L("Camera => CCamCameraController::HandleCallbackEvent, event[%s]"),
  4886           KCamCameraEventNames[aEventId] );
  4889           KCamCameraEventNames[aEventId] );
  4887   // -------------------------------------------------------
  4890   // -------------------------------------------------------
  4888   // Clear single request busy flag before notification to observers,
  4891   // Clear single request busy flag before notification to observers,
  4889   // in case client wishes to issue new request during the notification.
  4892   // in case client wishes to issue new request during the notification.
  4890   // Sequence busy flag can only be cleared in EndSequence
  4893   // Sequence busy flag can only be cleared in EndSequence
  4891   ClearFlags( iInfo.iBusy, ECamBusySingle );
  4894   ClearFlags( iInfo.iBusy, ECamBusySingle );
  4892 
  4895 
  4893   // Observers might issue a new sequence during notification.
  4896   // Observers might issue a new sequence during notification.
  4894   // We need to decide if sequence needs to continue here 
  4897   // We need to decide if sequence needs to continue here
  4895   // based on the status *before* notification.
  4898   // based on the status *before* notification.
  4896   TBool proceedSequence = EFalse;
  4899   TBool proceedSequence = EFalse;
  4897   TBool notify          = ETrue;
  4900   TBool notify          = ETrue;
  4898 
  4901 
  4899   // -------------------------------------------------------
  4902   // -------------------------------------------------------
  4901   // 1) Processing sequence is ongoing.
  4904   // 1) Processing sequence is ongoing.
  4902   // 2) The received event is exact response to our request.
  4905   // 2) The received event is exact response to our request.
  4903   //    There are events like "video stopped" or "reserve lost"
  4906   //    There are events like "video stopped" or "reserve lost"
  4904   //    that may be received without our associated request.
  4907   //    that may be received without our associated request.
  4905   //    In that case we must not proceed sequence processing now.
  4908   //    In that case we must not proceed sequence processing now.
  4906   // 3) In case that aStatus is KErrInUse and the current event is 
  4909   // 3) In case that aStatus is KErrInUse and the current event is
  4907   //    Reserve, it means reserve failed for some reason 
  4910   //    Reserve, it means reserve failed for some reason
  4908   if( IsFlagOn( iInfo.iBusy, ECamBusySequence ) ) // 1
  4911   if( IsFlagOn( iInfo.iBusy, ECamBusySequence ) ) // 1
  4909     {
  4912     {
  4910     PRINT( _L("Camera <> Sequence is active") );
  4913     PRINT( _L("Camera <> Sequence is active") );
  4911     PRINT2( _L("Camera <> seq index: %d, seq array len: %d"), iSequenceIndex, iSequenceArray.Count() );
  4914     PRINT2( _L("Camera <> seq index: %d, seq array len: %d"), iSequenceIndex, iSequenceArray.Count() );
  4912     if( KErrNone != aStatus )
  4915     if( KErrNone != aStatus )
  4913         {
  4916         {
  4914       
  4917 
  4915         if ( KErrInUse == aStatus               // 3
  4918         if ( KErrInUse == aStatus               // 3
  4916             && aEventId == ECamCameraEventReserveGain 
  4919             && aEventId == ECamCameraEventReserveGain
  4917             && iSequenceIndex >= 0
  4920             && iSequenceIndex >= 0
  4918             && Request2Event( iSequenceArray[iSequenceIndex] ) == ECamCameraEventReserveGain 
  4921             && Request2Event( iSequenceArray[iSequenceIndex] ) == ECamCameraEventReserveGain
  4919             && iReserveTryAgainCount > 0 )
  4922             && iReserveTryAgainCount > 0 )
  4920             {
  4923             {
  4921             // Handle here only if reserve gain with error is part of a sequence and try again count is not zero
  4924             // Handle here only if reserve gain with error is part of a sequence and try again count is not zero
  4922             
  4925 
  4923             iReserveTryAgainCount--;
  4926             iReserveTryAgainCount--;
  4924             User::After( KCamReserveTryAgainWaitInterval );
  4927             User::After( KCamReserveTryAgainWaitInterval );
  4925             
  4928 
  4926             // decrease index, to get the same request handled again
  4929             // decrease index, to get the same request handled again
  4927             iSequenceIndex--;
  4930             iSequenceIndex--;
  4928             notify          = EFalse;
  4931             notify          = EFalse;
  4929             proceedSequence = ETrue;
  4932             proceedSequence = ETrue;
  4930             PRINT1( _L( "Camera <> CCamCameraController::HandleCallbackEvent - %d reserve try again left" ), iReserveTryAgainCount );
  4933             PRINT1( _L( "Camera <> CCamCameraController::HandleCallbackEvent - %d reserve try again left" ), iReserveTryAgainCount );
  4931             
  4934 
  4932             } 
  4935             }
  4933         else 
  4936         else
  4934             {
  4937             {
  4935 
  4938 
  4936             notify          = EFalse;
  4939             notify          = EFalse;
  4937             proceedSequence = EFalse;
  4940             proceedSequence = EFalse;
  4938             EndSequence( aStatus );      
  4941             EndSequence( aStatus );
  4939 
  4942 
  4940             }
  4943             }
  4941    
  4944 
  4942         }
  4945         }
  4943     else if( iSequenceIndex >= 0 &&  // Sequence has started 
  4946     else if( iSequenceIndex >= 0 &&  // Sequence has started
  4944              Request2Event( iSequenceArray[iSequenceIndex] ) == aEventId ) // 2
  4947              Request2Event( iSequenceArray[iSequenceIndex] ) == aEventId ) // 2
  4945         {
  4948         {
  4946         notify          = ETrue;
  4949         notify          = ETrue;
  4947         proceedSequence = ETrue;
  4950         proceedSequence = ETrue;
  4948         }
  4951         }
  4949     else
  4952     else
  4950         {
  4953         {
  4951          // Not the event we need yet.
  4954          // Not the event we need yet.
  4952         }
  4955         }
  4953         
  4956 
  4954     }
  4957     }
  4955   // -------------------------------------------------------
  4958   // -------------------------------------------------------
  4956   // Setting sequence ongoing
  4959   // Setting sequence ongoing
  4957   else if( IsFlagOn( iInfo.iBusy, ECamBusySetting ) 
  4960   else if( IsFlagOn( iInfo.iBusy, ECamBusySetting )
  4958            && iSettingIndex >= 0 )
  4961            && iSettingIndex >= 0 )
  4959     {
  4962     {
  4960     PRINT( _L("Camera <> Settings change ongoing..") );
  4963     PRINT( _L("Camera <> Settings change ongoing..") );
  4961 
  4964 
  4962     // Default is no notification
  4965     // Default is no notification
  4968       {
  4971       {
  4969       PRINT( _L("Camera <> error in, end settings sequence!") );
  4972       PRINT( _L("Camera <> error in, end settings sequence!") );
  4970       proceedSequence = EFalse;
  4973       proceedSequence = EFalse;
  4971       EndSequence( aStatus ); // does one notification
  4974       EndSequence( aStatus ); // does one notification
  4972       }
  4975       }
  4973     else if( ECamCameraEventSettingsSingle == aEventId 
  4976     else if( ECamCameraEventSettingsSingle == aEventId
  4974           && aEventData 
  4977           && aEventData
  4975           && iSettingArray[iSettingIndex] == *( static_cast<TInt*>( aEventData ) )
  4978           && iSettingArray[iSettingIndex] == *( static_cast<TInt*>( aEventData ) )
  4976            )
  4979            )
  4977       {
  4980       {
  4978       // We have checked already in HandleEvent that this is 
  4981       // We have checked already in HandleEvent that this is
  4979       // the right event for the setting we wait to finish.
  4982       // the right event for the setting we wait to finish.
  4980       // Notification can be sent with the given data.
  4983       // Notification can be sent with the given data.
  4981       PRINT( _L("Camera <> One setting finished, continue sequence") );
  4984       PRINT( _L("Camera <> One setting finished, continue sequence") );
  4982       proceedSequence = ETrue;
  4985       proceedSequence = ETrue;
  4983       }
  4986       }
  4984     // Video init event repeated when filename or max file size set
  4987     // Video init event repeated when filename or max file size set
  4985     // after init already done
  4988     // after init already done
  4986     else if( IsFlagOn( iInfo.iState, ECamVideoOn )
  4989     else if( IsFlagOn( iInfo.iState, ECamVideoOn )
  4987           && ECamCameraEventVideoInit == aEventId 
  4990           && ECamCameraEventVideoInit == aEventId
  4988           && ( ECameraSettingFileName    == iSettingArray[iSettingIndex] 
  4991           && ( ECameraSettingFileName    == iSettingArray[iSettingIndex]
  4989             || ECameraSettingFileMaxSize == iSettingArray[iSettingIndex]
  4992             || ECameraSettingFileMaxSize == iSettingArray[iSettingIndex]
  4990             || ECameraSettingAudioMute   == iSettingArray[iSettingIndex] ) )
  4993             || ECameraSettingAudioMute   == iSettingArray[iSettingIndex] ) )
  4991       {
  4994       {
  4992       PRINT( _L("Camera <> One setting finished, continue sequence") );
  4995       PRINT( _L("Camera <> One setting finished, continue sequence") );
  4993       proceedSequence = ETrue;
  4996       proceedSequence = ETrue;
  5013 
  5016 
  5014   // -------------------------------------------------------
  5017   // -------------------------------------------------------
  5015   // Notify the observers with data from the event.
  5018   // Notify the observers with data from the event.
  5016   if( notify )
  5019   if( notify )
  5017     {
  5020     {
  5018     NotifyObservers( aStatus, aEventId, aEventClass, aEventData ); 
  5021     NotifyObservers( aStatus, aEventId, aEventClass, aEventData );
  5019     }
  5022     }
  5020 
  5023 
  5021   // -------------------------------------------------------
  5024   // -------------------------------------------------------
  5022   // If this is part of sequence, continue processing.
  5025   // If this is part of sequence, continue processing.
  5023   if( proceedSequence )
  5026   if( proceedSequence )
  5035 
  5038 
  5036 // ---------------------------------------------------------------------------
  5039 // ---------------------------------------------------------------------------
  5037 // Notify all our observers of an event.
  5040 // Notify all our observers of an event.
  5038 // ---------------------------------------------------------------------------
  5041 // ---------------------------------------------------------------------------
  5039 //
  5042 //
  5040 void 
  5043 void
  5041 CCamCameraController
  5044 CCamCameraController
  5042 ::NotifyObservers( TInt                   aStatus, 
  5045 ::NotifyObservers( TInt                   aStatus,
  5043                    TCamCameraEventId      aEventId,
  5046                    TCamCameraEventId      aEventId,
  5044                    TCamCameraEventClassId aEventClass,
  5047                    TCamCameraEventClassId aEventClass,
  5045                    TAny*                  aEventData /*=NULL*/ )
  5048                    TAny*                  aEventData /*=NULL*/ )
  5046   {
  5049   {
  5047 //  PRINT ( _L("Camera => CCamCameraController::NotifyObservers") );
  5050 //  PRINT ( _L("Camera => CCamCameraController::NotifyObservers") );
  5048 //  PRINT3( _L("Camera <> status:% 3d event:% 3d class:%032b"), aStatus, aEventId, aEventClass );
  5051 //  PRINT3( _L("Camera <> status:% 3d event:% 3d class:%032b"), aStatus, aEventId, aEventClass );
  5049 
  5052 
  5050   // NOTE:
  5053   // NOTE:
  5051   //   We might skip an observer, if during the notification some observer 
  5054   //   We might skip an observer, if during the notification some observer
  5052   //   is removed from the array (from smaller index than current one).
  5055   //   is removed from the array (from smaller index than current one).
  5053   //   This is a commmon problem for all observable classes in this application.
  5056   //   This is a commmon problem for all observable classes in this application.
  5054   for( TInt i = 0; i < iObservers.Count(); i++ )
  5057   for( TInt i = 0; i < iObservers.Count(); i++ )
  5055     {
  5058     {
  5056     // Observer defines which events it is interested in.
  5059     // Observer defines which events it is interested in.
  5071 // ---------------------------------------------------------------------------
  5074 // ---------------------------------------------------------------------------
  5072 //
  5075 //
  5073 void
  5076 void
  5074 CCamCameraController::ReleaseCurrentCamera()
  5077 CCamCameraController::ReleaseCurrentCamera()
  5075   {
  5078   {
  5076   PRINT( _L("Camera => CCamCameraController::ReleaseCurrentCamera") );  
  5079   PRINT( _L("Camera => CCamCameraController::ReleaseCurrentCamera") );
  5077   // Cancel any outstanding sequence.
  5080   // Cancel any outstanding sequence.
  5078   if( IsFlagOn( iInfo.iBusy, ECamBusySequence )
  5081   if( IsFlagOn( iInfo.iBusy, ECamBusySequence )
  5079 #ifdef CAMERAAPP_CAE_FIX
  5082 #ifdef CAMERAAPP_CAE_FIX
  5080    // Mode change calls this method possibly in the middle
  5083    // Mode change calls this method possibly in the middle
  5081    // of request sequence. Must not try to cancel then.
  5084    // of request sequence. Must not try to cancel then.
  5086     CancelSequence();
  5089     CancelSequence();
  5087     }
  5090     }
  5088 
  5091 
  5089   if( IsFlagOn( iInfo.iState, ECamReserved ) )
  5092   if( IsFlagOn( iInfo.iState, ECamReserved ) )
  5090     {
  5093     {
  5091     // Releases viewfinder and snapshot, cancels capture, 
  5094     // Releases viewfinder and snapshot, cancels capture,
  5092     // powers off and releases CCamera if needed.
  5095     // powers off and releases CCamera if needed.
  5093     ProcessControlShutdownRequest( ECamRequestRelease );
  5096     ProcessControlShutdownRequest( ECamRequestRelease );
  5094     }
  5097     }
  5095 
  5098 
  5096   // Custom interfaces (not owned)
  5099   // Custom interfaces (not owned)
  5130   iInfo.Reset();
  5133   iInfo.Reset();
  5131 #endif
  5134 #endif
  5132   iResolutionSupport.Reset();
  5135   iResolutionSupport.Reset();
  5133   iInfo.iState = ECamIdle;
  5136   iInfo.iState = ECamIdle;
  5134 
  5137 
  5135   PRINT( _L("Camera <= CCamCameraController::ReleaseCurrentCamera") );  
  5138   PRINT( _L("Camera <= CCamCameraController::ReleaseCurrentCamera") );
  5136   }
  5139   }
  5137 
  5140 
  5138 
  5141 
  5139 // ---------------------------------------------------------------------------
  5142 // ---------------------------------------------------------------------------
  5140 // ReleaseCustomInterfaces
  5143 // ReleaseCustomInterfaces
  5159 
  5162 
  5160 // ---------------------------------------------------------------------------
  5163 // ---------------------------------------------------------------------------
  5161 // GetResolutionIndexL
  5164 // GetResolutionIndexL
  5162 //
  5165 //
  5163 // Get quality index for prepare with given format and size.
  5166 // Get quality index for prepare with given format and size.
  5164 // If current info is not for the given format, update the 
  5167 // If current info is not for the given format, update the
  5165 // supported resolutions info. After the support info is up to date,
  5168 // supported resolutions info. After the support info is up to date,
  5166 // find the index. Return KErrNotFound if not supported size.
  5169 // find the index. Return KErrNotFound if not supported size.
  5167 //
  5170 //
  5168 // For JPEG format we try two alternate bitmap formats, if
  5171 // For JPEG format we try two alternate bitmap formats, if
  5169 // the given resolution is not supported in JPEG format.
  5172 // the given resolution is not supported in JPEG format.
  5187 
  5190 
  5188     // Reset all old resolution info
  5191     // Reset all old resolution info
  5189     iResolutionSupport.Reset();
  5192     iResolutionSupport.Reset();
  5190 
  5193 
  5191     // Get the resolution info for current camera with given format.
  5194     // Get the resolution info for current camera with given format.
  5192     const TInt KResolutionCount( iCameraInfo.iNumImageSizesSupported );  
  5195     const TInt KResolutionCount( iCameraInfo.iNumImageSizesSupported );
  5193     RArray<TSize>& resolutions( iResolutionSupport.iResolutions );
  5196     RArray<TSize>& resolutions( iResolutionSupport.iResolutions );
  5194 
  5197 
  5195     resolutions.ReserveL( KResolutionCount );
  5198     resolutions.ReserveL( KResolutionCount );
  5196     for( TInt i = 0; i < KResolutionCount; i++ )
  5199     for( TInt i = 0; i < KResolutionCount; i++ )
  5197       {
  5200       {
  5198       // Reserve called, so should not leave.      
  5201       // Reserve called, so should not leave.
  5199       resolutions.AppendL( TSize() );
  5202       resolutions.AppendL( TSize() );
  5200       iCamera->EnumerateCaptureSizes( resolutions[i], i, aFormat );
  5203       iCamera->EnumerateCaptureSizes( resolutions[i], i, aFormat );
  5201       }
  5204       }
  5202 
  5205 
  5203     // Set these after successful filling of the array
  5206     // Set these after successful filling of the array
  5217   PRINT1( _L("Camera <> EFormatFbsBitmapColor16M : %032b"  ), CCamera::EFormatFbsBitmapColor16M  );
  5220   PRINT1( _L("Camera <> EFormatFbsBitmapColor16M : %032b"  ), CCamera::EFormatFbsBitmapColor16M  );
  5218   PRINT1( _L("Camera <> EFormatFbsBitmapColor16MU: %032b"  ), CCamera::EFormatFbsBitmapColor16MU );
  5221   PRINT1( _L("Camera <> EFormatFbsBitmapColor16MU: %032b"  ), CCamera::EFormatFbsBitmapColor16MU );
  5219   for( TInt i = 0; i < iResolutionSupport.iResolutions.Count(); i++ )
  5222   for( TInt i = 0; i < iResolutionSupport.iResolutions.Count(); i++ )
  5220     {
  5223     {
  5221     const TSize& size( iResolutionSupport.iResolutions[i] );
  5224     const TSize& size( iResolutionSupport.iResolutions[i] );
  5222     PRINT3( _L("Camera <> Size (%d): (%d,%d)"), i, size.iWidth, size.iHeight ); 
  5225     PRINT3( _L("Camera <> Size (%d): (%d,%d)"), i, size.iWidth, size.iHeight );
  5223     }
  5226     }
  5224   PRINT ( _L("Camera <> ==================================================") );
  5227   PRINT ( _L("Camera <> ==================================================") );
  5225 #endif
  5228 #endif
  5226 
  5229 
  5227   TIdentityRelation<TSize> compareFunc( CCamCameraController::CompareSize );
  5230   TIdentityRelation<TSize> compareFunc( CCamCameraController::CompareSize );
  5229 
  5232 
  5230   // Exception for JPEG format:
  5233   // Exception for JPEG format:
  5231   //   If JPEG format is not supported, but bitmap format is,
  5234   //   If JPEG format is not supported, but bitmap format is,
  5232   //   pretend to support the format anyway.
  5235   //   pretend to support the format anyway.
  5233   //   When capturing, we encode the JPEG from the bitmap.
  5236   //   When capturing, we encode the JPEG from the bitmap.
  5234   if( CCamera::EFormatJpeg == aFormat 
  5237   if( CCamera::EFormatJpeg == aFormat
  5235    && KErrNotFound         == index )
  5238    && KErrNotFound         == index )
  5236     {    
  5239     {
  5237     PRINT ( _L("Camera <> Jpeg not supported, trying bitmap format 1..") );
  5240     PRINT ( _L("Camera <> Jpeg not supported, trying bitmap format 1..") );
  5238     aFormat = KCamJpegAlternativeFormat1;
  5241     aFormat = KCamJpegAlternativeFormat1;
  5239     index   = GetResolutionIndexL( aFormat, aSize );
  5242     index   = GetResolutionIndexL( aFormat, aSize );
  5240 
  5243 
  5241     if( KErrNotFound == index )
  5244     if( KErrNotFound == index )
  5270 //
  5273 //
  5271 void
  5274 void
  5272 CCamCameraController::GetAdvancedSettingsInfoL()
  5275 CCamCameraController::GetAdvancedSettingsInfoL()
  5273   {
  5276   {
  5274   PRINT ( _L("Camera => CCamCameraController::GetAdvancedSettingsInfoL") );
  5277   PRINT ( _L("Camera => CCamCameraController::GetAdvancedSettingsInfoL") );
  5275   PRINT2( _L("Camera <> current camera:%d, latest info for:%d"), 
  5278   PRINT2( _L("Camera <> current camera:%d, latest info for:%d"),
  5276           iInfo.iCurrentCamera, 
  5279           iInfo.iCurrentCamera,
  5277           iAdvancedSettingInfo.iForCameraIndex );
  5280           iAdvancedSettingInfo.iForCameraIndex );
  5278 
  5281 
  5279 
  5282 
  5280     CheckNonNullL( iAdvancedSettings, KErrNotReady );
  5283     CheckNonNullL( iAdvancedSettings, KErrNotReady );
  5281     iAdvancedSettingInfo.Reset();
  5284     iAdvancedSettingInfo.Reset();
  5296       TInt             index ( GetResolutionIndexL( format, params().iSize ) );
  5299       TInt             index ( GetResolutionIndexL( format, params().iSize ) );
  5297       User::LeaveIfError( index );
  5300       User::LeaveIfError( index );
  5298       TBool isInfluencePossible; // Not used
  5301       TBool isInfluencePossible; // Not used
  5299 
  5302 
  5300       PRINT( _L("Camera <> Get zoom steps for image") );
  5303       PRINT( _L("Camera <> Get zoom steps for image") );
  5301       TRAP( error, iAdvancedSettings->GetDigitalZoomStepsForStillL ( 
  5304       TRAP( error, iAdvancedSettings->GetDigitalZoomStepsForStillL (
  5302                       iAdvancedSettingInfo.iDigitalZoomSupport, 
  5305                       iAdvancedSettingInfo.iDigitalZoomSupport,
  5303                       iAdvancedSettingInfo.iDigitalZoomValueInfo, 
  5306                       iAdvancedSettingInfo.iDigitalZoomValueInfo,
  5304                       index, 
  5307                       index,
  5305                       format, 
  5308                       format,
  5306                       isInfluencePossible  ) );
  5309                       isInfluencePossible  ) );
  5307       
  5310 
  5308       if( KErrNotSupported != error ) User::LeaveIfError( error );
  5311       if( KErrNotSupported != error ) User::LeaveIfError( error );
  5309       }
  5312       }
  5310     else if( IsFlagOn( iInfo.iState, ECamVideoOn ) ) 
  5313     else if( IsFlagOn( iInfo.iState, ECamVideoOn ) )
  5311       {
  5314       {
  5312       PRINT( _L("Camera <> Get zoom steps for video") );
  5315       PRINT( _L("Camera <> Get zoom steps for video") );
  5313       TRAP( error, iAdvancedSettings->GetDigitalZoomStepsL( 
  5316       TRAP( error, iAdvancedSettings->GetDigitalZoomStepsL(
  5314                       iAdvancedSettingInfo.iDigitalZoomSupport, 
  5317                       iAdvancedSettingInfo.iDigitalZoomSupport,
  5315                       iAdvancedSettingInfo.iDigitalZoomValueInfo ) );
  5318                       iAdvancedSettingInfo.iDigitalZoomValueInfo ) );
  5316       if( KErrNotSupported != error ) User::LeaveIfError( error );
  5319       if( KErrNotSupported != error ) User::LeaveIfError( error );
  5317       }
  5320       }
  5318 
  5321 
  5319     // -----------------------------------------------------
  5322     // -----------------------------------------------------
  5320     // EV steps multiplied by KECamFineResolutionFactor.
  5323     // EV steps multiplied by KECamFineResolutionFactor.
  5321     PRINT( _L("Camera <> Get EV support..") );
  5324     PRINT( _L("Camera <> Get EV support..") );
  5322     iAdvancedSettingInfo.iEvModesSupport = 
  5325     iAdvancedSettingInfo.iEvModesSupport =
  5323         iAdvancedSettings->SupportedExposureModes();
  5326         iAdvancedSettings->SupportedExposureModes();
  5324 
  5327 
  5325     TRAP( error, iAdvancedSettings->GetExposureCompensationStepsL( 
  5328     TRAP( error, iAdvancedSettings->GetExposureCompensationStepsL(
  5326                     iAdvancedSettingInfo.iEvStepsSupport, 
  5329                     iAdvancedSettingInfo.iEvStepsSupport,
  5327                     iAdvancedSettingInfo.iEvStepsValueInfo ) );
  5330                     iAdvancedSettingInfo.iEvStepsValueInfo ) );
  5328     // Ignore error if just not supported.
  5331     // Ignore error if just not supported.
  5329     // We check the support when setting is requested.
  5332     // We check the support when setting is requested.
  5330     if( KErrNotSupported != error ) User::LeaveIfError( error );
  5333     if( KErrNotSupported != error ) User::LeaveIfError( error );
  5331 
  5334 
  5332     // -----------------------------------------------------
  5335     // -----------------------------------------------------
  5333     // ISO rates (.. 50, 100, 200, ..)
  5336     // ISO rates (.. 50, 100, 200, ..)
  5334     PRINT( _L("Camera <> Get ISO rates..") );
  5337     PRINT( _L("Camera <> Get ISO rates..") );
  5335     TRAP( error, iAdvancedSettings->GetSupportedIsoRatesL( 
  5338     TRAP( error, iAdvancedSettings->GetSupportedIsoRatesL(
  5336                     iAdvancedSettingInfo.iIsoRatesSupport ) );
  5339                     iAdvancedSettingInfo.iIsoRatesSupport ) );
  5337     if( KErrNotSupported != error ) User::LeaveIfError( error );
  5340     if( KErrNotSupported != error ) User::LeaveIfError( error );
  5338 
  5341 
  5339     // -----------------------------------------------------
  5342     // -----------------------------------------------------
  5340     // Stabilization
  5343     // Stabilization
  5341     PRINT( _L("Camera <> Get Stabilization info..") );
  5344     PRINT( _L("Camera <> Get Stabilization info..") );
  5342     iAdvancedSettingInfo.iStabilizationModeSupport = 
  5345     iAdvancedSettingInfo.iStabilizationModeSupport =
  5343         iAdvancedSettings->SupportedStabilizationModes();
  5346         iAdvancedSettings->SupportedStabilizationModes();
  5344 
  5347 
  5345     iAdvancedSettingInfo.iStabilizationEffectSupport = 
  5348     iAdvancedSettingInfo.iStabilizationEffectSupport =
  5346         iAdvancedSettings->SupportedStabilizationEffects();
  5349         iAdvancedSettings->SupportedStabilizationEffects();
  5347 
  5350 
  5348     iAdvancedSettingInfo.iStabilizationComplexitySupport = 
  5351     iAdvancedSettingInfo.iStabilizationComplexitySupport =
  5349         iAdvancedSettings->SupportedStabilizationComplexityValues();
  5352         iAdvancedSettings->SupportedStabilizationComplexityValues();
  5350     // -----------------------------------------------------
  5353     // -----------------------------------------------------
  5351 
  5354 
  5352 #ifdef CAMERAAPP_CAPI_V2_IP
  5355 #ifdef CAMERAAPP_CAPI_V2_IP
  5353     // Image Processor only for primary camera
  5356     // Image Processor only for primary camera
  5354     if( KPrimaryCameraIndex == iInfo.iCurrentCamera )
  5357     if( KPrimaryCameraIndex == iInfo.iCurrentCamera )
  5355       {
  5358       {
  5356       PRINT( _L("Camera <> Get image processing info..") );
  5359       PRINT( _L("Camera <> Get image processing info..") );
  5357    
  5360 
  5358       if( iImageProcessor != NULL )
  5361       if( iImageProcessor != NULL )
  5359         {
  5362         {
  5360         // -----------------------------------------------------
  5363         // -----------------------------------------------------
  5361         PRINT( _L("Camera <> Get sharpness support..") );
  5364         PRINT( _L("Camera <> Get sharpness support..") );
  5362         TRAP( error, iImageProcessor->GetTransformationSupportedValuesL( 
  5365         TRAP( error, iImageProcessor->GetTransformationSupportedValuesL(
  5363                         KUidECamEventImageProcessingAdjustSharpness,
  5366                         KUidECamEventImageProcessingAdjustSharpness,
  5364                         iAdvancedSettingInfo.iSharpnessSupport,
  5367                         iAdvancedSettingInfo.iSharpnessSupport,
  5365                         iAdvancedSettingInfo.iSharpnessValueInfo ) );
  5368                         iAdvancedSettingInfo.iSharpnessValueInfo ) );
  5366         if( KErrNotSupported != error ) User::LeaveIfError( error );
  5369         if( KErrNotSupported != error ) User::LeaveIfError( error );
  5367     
  5370 
  5368         // -----------------------------------------------------
  5371         // -----------------------------------------------------
  5369         PRINT( _L("Camera <> Get colour effect support..") );
  5372         PRINT( _L("Camera <> Get colour effect support..") );
  5370         TRAP( error, iImageProcessor->GetTransformationSupportedValuesL( 
  5373         TRAP( error, iImageProcessor->GetTransformationSupportedValuesL(
  5371                           KUidECamEventImageProcessingEffect,
  5374                           KUidECamEventImageProcessingEffect,
  5372                           iAdvancedSettingInfo.iColourEffectSupport,
  5375                           iAdvancedSettingInfo.iColourEffectSupport,
  5373                           iAdvancedSettingInfo.iColourEffectValueInfo ) );
  5376                           iAdvancedSettingInfo.iColourEffectValueInfo ) );
  5374         if( KErrNotSupported != error ) User::LeaveIfError( error );
  5377         if( KErrNotSupported != error ) User::LeaveIfError( error );
  5375         }
  5378         }
  5376       else 
  5379       else
  5377         {
  5380         {
  5378         PRINT( _L("Camera <> [WARNING] Image processing not supported") );          
  5381         PRINT( _L("Camera <> [WARNING] Image processing not supported") );
  5379         }
  5382         }
  5380       }
  5383       }
  5381 #endif // CAMERAAPP_CAPI_V2_IP
  5384 #endif // CAMERAAPP_CAPI_V2_IP
  5382     // -----------------------------------------------------
  5385     // -----------------------------------------------------
  5383     PRINT( _L("Camera <> ..done") );
  5386     PRINT( _L("Camera <> ..done") );
  5387     iAdvancedSettingInfo.iForCameraIndex = iInfo.iCurrentCamera;
  5390     iAdvancedSettingInfo.iForCameraIndex = iInfo.iCurrentCamera;
  5388 
  5391 
  5389 #ifdef _DEBUG
  5392 #ifdef _DEBUG
  5390     iAdvancedSettingInfo.PrintInfo();
  5393     iAdvancedSettingInfo.PrintInfo();
  5391 #endif
  5394 #endif
  5392     
  5395 
  5393   PRINT ( _L("Camera <= CCamCameraController::GetAdvancedSettingsInfoL") );
  5396   PRINT ( _L("Camera <= CCamCameraController::GetAdvancedSettingsInfoL") );
  5394   }
  5397   }
  5395 
  5398 
  5396 
  5399 
  5397 
  5400 
  5398 // ---------------------------------------------------------------------------
  5401 // ---------------------------------------------------------------------------
  5399 // ResolveEvStep
  5402 // ResolveEvStep
  5400 //
  5403 //
  5401 // ---------------------------------------------------------------------------
  5404 // ---------------------------------------------------------------------------
  5402 //
  5405 //
  5403 TInt 
  5406 TInt
  5404 CCamCameraController::ResolveEvStep( TInt aEvProposedStep ) const
  5407 CCamCameraController::ResolveEvStep( TInt aEvProposedStep ) const
  5405   {
  5408   {
  5406   PRINT1( _L("Camera => CCamCameraController::ResolveEvStep( %d )"), aEvProposedStep );
  5409   PRINT1( _L("Camera => CCamCameraController::ResolveEvStep( %d )"), aEvProposedStep );
  5407 
  5410 
  5408   TInt delta ( KMaxTInt );
  5411   TInt delta ( KMaxTInt );
  5429 // ---------------------------------------------------------------------------
  5432 // ---------------------------------------------------------------------------
  5430 // IsSupportedValue <<static>>
  5433 // IsSupportedValue <<static>>
  5431 // ---------------------------------------------------------------------------
  5434 // ---------------------------------------------------------------------------
  5432 //
  5435 //
  5433 TBool
  5436 TBool
  5434 CCamCameraController::IsSupportedValue( const TInt&         aValue, 
  5437 CCamCameraController::IsSupportedValue( const TInt&         aValue,
  5435                                         const RArray<TInt>& aValueList, 
  5438                                         const RArray<TInt>& aValueList,
  5436                                         const TValueInfo&   aValueInfo )
  5439                                         const TValueInfo&   aValueInfo )
  5437   {
  5440   {
  5438   TBool support( EFalse );
  5441   TBool support( EFalse );
  5439 
  5442 
  5440   switch( aValueInfo )
  5443   switch( aValueInfo )
  5446       // Compare the support bitfield and the setting value.
  5449       // Compare the support bitfield and the setting value.
  5447       // Default value for these settings is zero (0) and
  5450       // Default value for these settings is zero (0) and
  5448       // that is always supported.
  5451       // that is always supported.
  5449       // Array: [0] bitfield of supported bits
  5452       // Array: [0] bitfield of supported bits
  5450       support = ( 1 <= aValueList.Count()
  5453       support = ( 1 <= aValueList.Count()
  5451                && ( !aValue 
  5454                && ( !aValue
  5452                  || (aValue & aValueList[0]) // 0 always supported
  5455                  || (aValue & aValueList[0]) // 0 always supported
  5453                   )
  5456                   )
  5454                 );
  5457                 );
  5455       break;
  5458       break;
  5456       }
  5459       }
  5483       {
  5486       {
  5484       // Support is described by min and max value,
  5487       // Support is described by min and max value,
  5485       // continuous range of values within those two is supported.
  5488       // continuous range of values within those two is supported.
  5486       // Array: [0] min supported value
  5489       // Array: [0] min supported value
  5487       //        [1] max supported value
  5490       //        [1] max supported value
  5488       support = 
  5491       support =
  5489         ( 2      <= aValueList.Count() // We need 2 items.
  5492         ( 2      <= aValueList.Count() // We need 2 items.
  5490        && aValue >= aValueList[0]      // aValue >= min
  5493        && aValue >= aValueList[0]      // aValue >= min
  5491        && aValue <= aValueList[1]      // aValue <= max
  5494        && aValue <= aValueList[1]      // aValue <= max
  5492         );
  5495         );
  5493       break;
  5496       break;
  5516 ::ResolveSnapshotFormatL( CCamera::TFormat aPreferredFormat ) const
  5519 ::ResolveSnapshotFormatL( CCamera::TFormat aPreferredFormat ) const
  5517   {
  5520   {
  5518   PRINT ( _L("Camera => CCamCameraController::ResolveSnapshotFormatL") );
  5521   PRINT ( _L("Camera => CCamCameraController::ResolveSnapshotFormatL") );
  5519 
  5522 
  5520   CheckNonNullL( iSnapshotProvider, KErrNotReady );
  5523   CheckNonNullL( iSnapshotProvider, KErrNotReady );
  5521   
  5524 
  5522   const TUint32    support = iSnapshotProvider->SupportedFormats();
  5525   const TUint32    support = iSnapshotProvider->SupportedFormats();
  5523   CCamera::TFormat final   = aPreferredFormat;
  5526   CCamera::TFormat final   = aPreferredFormat;
  5524   
  5527 
  5525   // Return the preferred format if it is supported.
  5528   // Return the preferred format if it is supported.
  5526   // Otherwise return the "best" supported format.
  5529   // Otherwise return the "best" supported format.
  5527   if      ( support & aPreferredFormat                   ) final = aPreferredFormat;
  5530   if      ( support & aPreferredFormat                   ) final = aPreferredFormat;
  5528   else if ( support & CCamera::EFormatFbsBitmapColor16MU ) final = CCamera::EFormatFbsBitmapColor16MU;
  5531   else if ( support & CCamera::EFormatFbsBitmapColor16MU ) final = CCamera::EFormatFbsBitmapColor16MU;
  5529   else if ( support & CCamera::EFormatFbsBitmapColor16M  ) final = CCamera::EFormatFbsBitmapColor16M;
  5532   else if ( support & CCamera::EFormatFbsBitmapColor16M  ) final = CCamera::EFormatFbsBitmapColor16M;
  5533     {
  5536     {
  5534     // No known acceptable format supported
  5537     // No known acceptable format supported
  5535     PRINT( _L("Camera <> CCamCameraController: No acceptable format available, LEAVE!") );
  5538     PRINT( _L("Camera <> CCamCameraController: No acceptable format available, LEAVE!") );
  5536     User::Leave( KErrNotSupported );
  5539     User::Leave( KErrNotSupported );
  5537     }
  5540     }
  5538   
  5541 
  5539   PRINT1( _L("Camera <> Preferred format : %032b"), aPreferredFormat  );
  5542   PRINT1( _L("Camera <> Preferred format : %032b"), aPreferredFormat  );
  5540   PRINT1( _L("Camera <> Supported formats: %032b"), support           );
  5543   PRINT1( _L("Camera <> Supported formats: %032b"), support           );
  5541   PRINT1( _L("Camera <> Selected  format : %032b"), final             );
  5544   PRINT1( _L("Camera <> Selected  format : %032b"), final             );
  5542   PRINT ( _L("Camera <= CCamCameraController::ResolveSnapshotFormatL") );
  5545   PRINT ( _L("Camera <= CCamCameraController::ResolveSnapshotFormatL") );
  5543   return final;
  5546   return final;
  5586     case ECamRequestVideoStop:     return ECamCameraEventVideoStop;
  5589     case ECamRequestVideoStop:     return ECamCameraEventVideoStop;
  5587     case ECamRequestVideoRelease:  return ECamCameraEventVideoRelease;
  5590     case ECamRequestVideoRelease:  return ECamCameraEventVideoRelease;
  5588     // -----------------------------------------------------
  5591     // -----------------------------------------------------
  5589     // Autofocus
  5592     // Autofocus
  5590     case ECamRequestStartAutofocus:   return ECamCameraEventStartAutofocus;
  5593     case ECamRequestStartAutofocus:   return ECamCameraEventStartAutofocus;
  5591     case ECamRequestCancelAutofocus:  return ECamCameraEventCancelAutofocus; 
  5594     case ECamRequestCancelAutofocus:  return ECamCameraEventCancelAutofocus;
  5592     case ECamRequestSetAfRange:       return ECamCameraEventSetAfRange;
  5595     case ECamRequestSetAfRange:       return ECamCameraEventSetAfRange;
  5593     // -----------------------------------------------------
  5596     // -----------------------------------------------------
  5594     
  5597 
  5595     // Unrecognised      
  5598     // Unrecognised
  5596     default:
  5599     default:
  5597       {
  5600       {
  5598       Panic( ECamCameraControllerUnknownRequest );
  5601       Panic( ECamCameraControllerUnknownRequest );
  5599       return ECamCameraEventNone;
  5602       return ECamCameraEventNone;
  5600       }
  5603       }
  5601     // -----------------------------------------------------
  5604     // -----------------------------------------------------
  5602     }        
  5605     }
  5603   }
  5606   }
  5604 
  5607 
  5605 
  5608 
  5606 // ---------------------------------------------------------------------------
  5609 // ---------------------------------------------------------------------------
  5607 // EventClass <<static>>
  5610 // EventClass <<static>>
  5625     case ECamCameraEventVfStart:
  5628     case ECamCameraEventVfStart:
  5626     case ECamCameraEventVfStop:
  5629     case ECamCameraEventVfStop:
  5627     case ECamCameraEventVfRelease:
  5630     case ECamCameraEventVfRelease:
  5628       return ECamCameraEventClassVfControl;
  5631       return ECamCameraEventClassVfControl;
  5629     // -------------------------------------------------------
  5632     // -------------------------------------------------------
  5630     case ECamCameraEventVfFrameReady: 
  5633     case ECamCameraEventVfFrameReady:
  5631       return ECamCameraEventClassVfData;
  5634       return ECamCameraEventClassVfData;
  5632     // -------------------------------------------------------
  5635     // -------------------------------------------------------
  5633     case ECamCameraEventSsStart:
  5636     case ECamCameraEventSsStart:
  5634     case ECamCameraEventSsStop:
  5637     case ECamCameraEventSsStop:
  5635     case ECamCameraEventSsRelease:
  5638     case ECamCameraEventSsRelease:
  5636       return ECamCameraEventClassSsControl;
  5639       return ECamCameraEventClassSsControl;
  5637     // -------------------------------------------------------
  5640     // -------------------------------------------------------
  5638     case ECamCameraEventSsReady:      
  5641     case ECamCameraEventSsReady:
  5639       return ECamCameraEventClassSsData;
  5642       return ECamCameraEventClassSsData;
  5640     // -------------------------------------------------------
  5643     // -------------------------------------------------------
  5641     case ECamCameraEventImageInit:
  5644     case ECamCameraEventImageInit:
  5642     case ECamCameraEventImageStart:
  5645     case ECamCameraEventImageStart:
  5643     case ECamCameraEventImageStop:
  5646     case ECamCameraEventImageStop:
  5651     case ECamCameraEventVideoStop:
  5654     case ECamCameraEventVideoStop:
  5652     case ECamCameraEventVideoRelease:
  5655     case ECamCameraEventVideoRelease:
  5653       return ECamCameraEventClassVideo;
  5656       return ECamCameraEventClassVideo;
  5654     // -------------------------------------------------------
  5657     // -------------------------------------------------------
  5655     case ECamCameraEventVideoTimes:
  5658     case ECamCameraEventVideoTimes:
  5656       return ECamCameraEventClassVideoTimes;  
  5659       return ECamCameraEventClassVideoTimes;
  5657     // -------------------------------------------------------
  5660     // -------------------------------------------------------
  5658     case ECamCameraEventSettingsSingle:
  5661     case ECamCameraEventSettingsSingle:
  5659     case ECamCameraEventSettingsDone:
  5662     case ECamCameraEventSettingsDone:
  5660       return ECamCameraEventClassSettings;
  5663       return ECamCameraEventClassSettings;
  5661     // -------------------------------------------------------
  5664     // -------------------------------------------------------
  5670     case ECamCameraEventFlashNotReady:
  5673     case ECamCameraEventFlashNotReady:
  5671       return ECamCameraEventClassFlashStatus;
  5674       return ECamCameraEventClassFlashStatus;
  5672     // -------------------------------------------------------
  5675     // -------------------------------------------------------
  5673     default:
  5676     default:
  5674       {
  5677       {
  5675     #ifdef _DEBUG      
  5678     #ifdef _DEBUG
  5676       Panic( ECamCameraControllerCorrupt );
  5679       Panic( ECamCameraControllerCorrupt );
  5677     #endif
  5680     #endif
  5678       return ECamCameraEventClassAll;
  5681       return ECamCameraEventClassAll;
  5679       }
  5682       }
  5680     }
  5683     }
  5717 
  5720 
  5718 // ---------------------------------------------------------------------------
  5721 // ---------------------------------------------------------------------------
  5719 // CurrentSettingHasCallback
  5722 // CurrentSettingHasCallback
  5720 // ---------------------------------------------------------------------------
  5723 // ---------------------------------------------------------------------------
  5721 //
  5724 //
  5722 TBool 
  5725 TBool
  5723 CCamCameraController::CurrentSettingHasCallback()
  5726 CCamCameraController::CurrentSettingHasCallback()
  5724   {
  5727   {
  5725   TBool callback( EFalse );
  5728   TBool callback( EFalse );
  5726 #ifdef CAMERAAPP_CAE_FOR_VIDEO
  5729 #ifdef CAMERAAPP_CAE_FOR_VIDEO
  5727   if( IsFlagOn( iInfo.iState, ECamVideoOn ) )
  5730   if( IsFlagOn( iInfo.iState, ECamVideoOn ) )
  5747 #ifdef CAMERAAPP_CAE_FOR_VIDEO
  5750 #ifdef CAMERAAPP_CAE_FOR_VIDEO
  5748 // ---------------------------------------------------------------------------
  5751 // ---------------------------------------------------------------------------
  5749 // NewCaeEngineL
  5752 // NewCaeEngineL
  5750 // ---------------------------------------------------------------------------
  5753 // ---------------------------------------------------------------------------
  5751 //
  5754 //
  5752 CCaeEngine* 
  5755 CCaeEngine*
  5753 CCamCameraController::NewCaeEngineL( TInt aCameraIndex )
  5756 CCamCameraController::NewCaeEngineL( TInt aCameraIndex )
  5754   {
  5757   {
  5755   PRINT( _L("Camera => CCamCameraController::NewCaeEngineL") );
  5758   PRINT( _L("Camera => CCamCameraController::NewCaeEngineL") );
  5756   
  5759 
  5757 #ifndef FORCE_DUMMY_ENGINE  
  5760 #ifndef FORCE_DUMMY_ENGINE
  5758   CCaeEngine* engine = CCaeEngine::NewL( aCameraIndex ); 
  5761   CCaeEngine* engine = CCaeEngine::NewL( aCameraIndex );
  5759 #else
  5762 #else
  5760   (void)aCameraIndex; // remove compiler warning
  5763   (void)aCameraIndex; // remove compiler warning
  5761   CCaeEngine* engine = CCameraappDummyEngine::NewL();
  5764   CCaeEngine* engine = CCameraappDummyEngine::NewL();
  5762 #endif
  5765 #endif
  5763   
  5766 
  5764   engine->SetCamAppEngineObserver( *this );
  5767   engine->SetCamAppEngineObserver( *this );
  5765 
  5768 
  5766   PRINT( _L("Camera <= CCamCameraController::NewCaeEngineL") );
  5769   PRINT( _L("Camera <= CCamCameraController::NewCaeEngineL") );
  5767   return engine;
  5770   return engine;
  5768   }
  5771   }
  5770 
  5773 
  5771 // ---------------------------------------------------------------------------
  5774 // ---------------------------------------------------------------------------
  5772 // NewCameraL
  5775 // NewCameraL
  5773 // ---------------------------------------------------------------------------
  5776 // ---------------------------------------------------------------------------
  5774 //
  5777 //
  5775 CAMERA* 
  5778 CAMERA*
  5776 CCamCameraController::NewCameraL( TInt aCameraIndex )
  5779 CCamCameraController::NewCameraL( TInt aCameraIndex )
  5777   {
  5780   {
  5778   PRINT( _L("Camera => CCamCameraController::NewCameraL") );
  5781   PRINT( _L("Camera => CCamCameraController::NewCameraL") );
  5779   CAMERA* camera( NULL );
  5782   CAMERA* camera( NULL );
  5780 #ifdef CAMERAAPP_CAPI_V2
  5783 #ifdef CAMERAAPP_CAPI_V2
  5781   camera = CAMERA::New2L( *this, aCameraIndex, KCameraClientPriority );
  5784   camera = CAMERA::New2L( *this, aCameraIndex, KCameraClientPriority );
  5782 #else
  5785 #else
  5783 
  5786 
  5784   // Both v1 and v2 observer interface implemented
  5787   // Both v1 and v2 observer interface implemented
  5785   // Need to cast to avoid ambiguous call.
  5788   // Need to cast to avoid ambiguous call.
  5786   MCameraObserver* self( this );  
  5789   MCameraObserver* self( this );
  5787   PRINT1( _L("Camera <> Give observer pointer: %d"), self );
  5790   PRINT1( _L("Camera <> Give observer pointer: %d"), self );
  5788   
  5791 
  5789   camera = CAMERA::NewL ( *self, aCameraIndex );
  5792   camera = CAMERA::NewL ( *self, aCameraIndex );
  5790   
  5793 
  5791 #endif // CAMERAAPP_CAPI_V2
  5794 #endif // CAMERAAPP_CAPI_V2
  5792 
  5795 
  5793   PRINT( _L("Camera <= CCamCameraController::NewCameraL") );
  5796   PRINT( _L("Camera <= CCamCameraController::NewCameraL") );
  5794   return camera;
  5797   return camera;
  5795   }
  5798   }
  5796 
  5799 
  5797 // ---------------------------------------------------------------------------
  5800 // ---------------------------------------------------------------------------
  5798 // NewDuplicateCameraL
  5801 // NewDuplicateCameraL
  5799 // ---------------------------------------------------------------------------
  5802 // ---------------------------------------------------------------------------
  5800 //
  5803 //
  5801 CAMERA* 
  5804 CAMERA*
  5802 CCamCameraController::NewDuplicateCameraL( TInt aCameraHandle )
  5805 CCamCameraController::NewDuplicateCameraL( TInt aCameraHandle )
  5803   {
  5806   {
  5804   PRINT1( _L("Camera => CCamCameraController::NewDuplicateCameraL( %d )"), aCameraHandle );
  5807   PRINT1( _L("Camera => CCamCameraController::NewDuplicateCameraL( %d )"), aCameraHandle );
  5805   CAMERA* camera( NULL );
  5808   CAMERA* camera( NULL );
  5806 
  5809 
  5851 // ---------------------------------------------------------------------------
  5854 // ---------------------------------------------------------------------------
  5852 // 1st phase constructor
  5855 // 1st phase constructor
  5853 // ---------------------------------------------------------------------------
  5856 // ---------------------------------------------------------------------------
  5854 //
  5857 //
  5855 CCamCameraController
  5858 CCamCameraController
  5856 ::CCamCameraController( MCamSettingProvider& aSettingProvider, 
  5859 ::CCamCameraController( MCamSettingProvider& aSettingProvider,
  5857                         CCamAppController& aAppController )
  5860                         CCamAppController& aAppController )
  5858   : iSequenceArray       ( KCamSequenceGranularity     ),
  5861   : iSequenceArray       ( KCamSequenceGranularity     ),
  5859     iReserveTryAgainCount( KCamReserveTryAgainMaxCount ),
  5862     iReserveTryAgainCount( KCamReserveTryAgainMaxCount ),
  5860     iSettingProvider     ( aSettingProvider            ),
  5863     iSettingProvider     ( aSettingProvider            ),
  5861     iAppController       ( aAppController              )    
  5864     iAppController       ( aAppController              )
  5862   { 
  5865   {
  5863   }
  5866   }
  5864 
  5867 
  5865 
  5868 
  5866 // ===========================================================================
  5869 // ===========================================================================
  5867 // Workaround for CCaeEngine with no support for CCamera sharing
  5870 // Workaround for CCaeEngine with no support for CCamera sharing
  5873 TInt
  5876 TInt
  5874 CCamCameraController::ProceedModeSwitch()
  5877 CCamCameraController::ProceedModeSwitch()
  5875   {
  5878   {
  5876   PRINT1( _L("Camera => CCamCameraController::ProceedModeSwitch, status in:%d"), iModeChangeStatus );
  5879   PRINT1( _L("Camera => CCamCameraController::ProceedModeSwitch, status in:%d"), iModeChangeStatus );
  5877   TInt proceed( EFalse );
  5880   TInt proceed( EFalse );
  5878   
  5881 
  5879   // Update only after here, so any events arriving
  5882   // Update only after here, so any events arriving
  5880   // in the middle get ignored if wanted.
  5883   // in the middle get ignored if wanted.
  5881   ++iModeChangePhase;
  5884   ++iModeChangePhase;
  5882   
  5885 
  5883   if( KErrNone == iModeChangeStatus )
  5886   if( KErrNone == iModeChangeStatus )
  5884     {
  5887     {
  5885     TRAP( iModeChangeStatus, proceed = DoProceedModeSwitchL() );
  5888     TRAP( iModeChangeStatus, proceed = DoProceedModeSwitchL() );
  5886     }
  5889     }
  5887 
  5890 
  5966 //        iSettingProvider.ProvideCameraSettingL( ECameraSettingFileName, &ptr );
  5969 //        iSettingProvider.ProvideCameraSettingL( ECameraSettingFileName, &ptr );
  5967         _LIT( KTempFilename, "C:\\video.3gp" );
  5970         _LIT( KTempFilename, "C:\\video.3gp" );
  5968         TPtrC ptr;
  5971         TPtrC ptr;
  5969         ptr.Set( KTempFilename() );
  5972         ptr.Set( KTempFilename() );
  5970 #pragma message( "Camera Controller: video filename hardcoded" )
  5973 #pragma message( "Camera Controller: video filename hardcoded" )
  5971         PRINT1( _L("Camera <> Set filename [%S]"), &ptr );        
  5974         PRINT1( _L("Camera <> Set filename [%S]"), &ptr );
  5972         iCaeEngine->SetVideoRecordingFileNameL( ptr );
  5975         iCaeEngine->SetVideoRecordingFileNameL( ptr );
  5973 //        CleanupStack::PopAndDestroy( filename );
  5976 //        CleanupStack::PopAndDestroy( filename );
  5974 
  5977 
  5975 
  5978 
  5976         // Set max video clip size
  5979         // Set max video clip size
  5977         ProcessSettingL( ECameraSettingFileMaxSize );        
  5980         ProcessSettingL( ECameraSettingFileMaxSize );
  5978 
  5981 
  5979 
  5982 
  5980         TPckgBuf<TCamParamsVideoCae> params;
  5983         TPckgBuf<TCamParamsVideoCae> params;
  5981         iSettingProvider.ProvideCameraParamL( ECameraParamVideoCae, &params );
  5984         iSettingProvider.ProvideCameraParamL( ECameraParamVideoCae, &params );
  5982         // The audioOn value is defined On==0 and Off==1, but the engine expects 
  5985         // The audioOn value is defined On==0 and Off==1, but the engine expects
  5983         // ETrue if audio recording is On
  5986         // ETrue if audio recording is On
  5984         params().iAudioOn = ( ECamSettOn == params().iAudioOn )
  5987         params().iAudioOn = ( ECamSettOn == params().iAudioOn )
  5985         											? ETrue
  5988         											? ETrue
  5986         											: EFalse;  
  5989         											: EFalse;
  5987         PRINT( _L("Camera <> Call prepare..") );
  5990         PRINT( _L("Camera <> Call prepare..") );
  5988         // McaeoVideoPrepareComplete will be called when prepare is ready.
  5991         // McaeoVideoPrepareComplete will be called when prepare is ready.
  5989         // The callback is allowed to come also *during* this call.
  5992         // The callback is allowed to come also *during* this call.
  5990         iCaeEngine->PrepareVideoRecordingL( params().iFrameSize,
  5993         iCaeEngine->PrepareVideoRecordingL( params().iFrameSize,
  5991                                             params().iFrameRate,
  5994                                             params().iFrameRate,
  6007         PRINT( _L("Camera <> Phase3: Notifying..") );
  6010         PRINT( _L("Camera <> Phase3: Notifying..") );
  6008         iModeChange      = ECamModeChangeInactive;
  6011         iModeChange      = ECamModeChangeInactive;
  6009         iModeChangePhase = ECamModeChangePhaseIdle;
  6012         iModeChangePhase = ECamModeChangePhaseIdle;
  6010         callback         = EFalse;
  6013         callback         = EFalse;
  6011 
  6014 
  6012         NotifyObservers( iModeChangeStatus, 
  6015         NotifyObservers( iModeChangeStatus,
  6013                          ECamCameraEventVideoInit, 
  6016                          ECamCameraEventVideoInit,
  6014                          ECamCameraEventClassVideo );
  6017                          ECamCameraEventClassVideo );
  6015         break;
  6018         break;
  6016         }
  6019         }
  6017       // -------------------------------
  6020       // -------------------------------
  6018       default:
  6021       default:
  6031       {
  6034       {
  6032       // -------------------------------
  6035       // -------------------------------
  6033       case ECamModeChangePhase0:
  6036       case ECamModeChangePhase0:
  6034         {
  6037         {
  6035         PRINT( _L("Camera <> Phase0: Release camera..") );
  6038         PRINT( _L("Camera <> Phase0: Release camera..") );
  6036         TInt cameraIndex = iInfo.iCurrentCamera; 
  6039         TInt cameraIndex = iInfo.iCurrentCamera;
  6037         ReleaseCurrentCamera();
  6040         ReleaseCurrentCamera();
  6038         SwitchCameraL( cameraIndex );
  6041         SwitchCameraL( cameraIndex );
  6039         CompleteSwitchCameraL();
  6042         CompleteSwitchCameraL();
  6040         callback = EFalse;
  6043         callback = EFalse;
  6041         break;
  6044         break;
  6059       case ECamModeChangePhase3:
  6062       case ECamModeChangePhase3:
  6060         {
  6063         {
  6061         PRINT( _L("Camera <> Phase3: Prepare image..") );
  6064         PRINT( _L("Camera <> Phase3: Prepare image..") );
  6062         TPckgBuf<TCamParamsImage> params;
  6065         TPckgBuf<TCamParamsImage> params;
  6063         iSettingProvider.ProvideCameraParamL( ECameraParamImage, &params );
  6066         iSettingProvider.ProvideCameraParamL( ECameraParamImage, &params );
  6064   
  6067 
  6065         // Query the supported resolutions for the selected format.
  6068         // Query the supported resolutions for the selected format.
  6066         TInt index = GetResolutionIndexL( params().iFormat, params().iSize );
  6069         TInt index = GetResolutionIndexL( params().iFormat, params().iSize );
  6067         User::LeaveIfError( index );
  6070         User::LeaveIfError( index );
  6068 
  6071 
  6069         PRINT2( _L("Camera <> Image size: (%d, %d)"), 
  6072         PRINT2( _L("Camera <> Image size: (%d, %d)"),
  6070                   params().iSize.iWidth,
  6073                   params().iSize.iWidth,
  6071                   params().iSize.iHeight );
  6074                   params().iSize.iHeight );
  6072         iCamera->PrepareImageCaptureL( params().iFormat, index );
  6075         iCamera->PrepareImageCaptureL( params().iFormat, index );
  6073         iCamera->SetJpegQuality( params().iQualityFactor );
  6076         iCamera->SetJpegQuality( params().iQualityFactor );
  6074   
  6077 
  6075         SetFlags( iInfo.iState, ECamImageOn );
  6078         SetFlags( iInfo.iState, ECamImageOn );
  6076 
  6079 
  6077         callback  = EFalse;
  6080         callback  = EFalse;
  6078         break;
  6081         break;
  6079         }
  6082         }
  6083         PRINT( _L("Camera <> Phase4: Notifying..") );
  6086         PRINT( _L("Camera <> Phase4: Notifying..") );
  6084         iModeChange      = ECamModeChangeInactive;
  6087         iModeChange      = ECamModeChangeInactive;
  6085         iModeChangePhase = ECamModeChangePhaseIdle;
  6088         iModeChangePhase = ECamModeChangePhaseIdle;
  6086         callback         = EFalse;
  6089         callback         = EFalse;
  6087 
  6090 
  6088         NotifyObservers( iModeChangeStatus, 
  6091         NotifyObservers( iModeChangeStatus,
  6089                          ECamCameraEventImageInit,
  6092                          ECamCameraEventImageInit,
  6090                          ECamCameraEventClassImage );
  6093                          ECamCameraEventClassImage );
  6091                          
  6094 
  6092         break;
  6095         break;
  6093         }
  6096         }
  6094       // -------------------------------
  6097       // -------------------------------
  6095       default:
  6098       default:
  6096         {
  6099         {
  6116 /**
  6119 /**
  6117 * CCamCameraController::RemainingVideoRecordingTime()
  6120 * CCamCameraController::RemainingVideoRecordingTime()
  6118 * Method to retrieve Remaining Recording time from CCaeEngine
  6121 * Method to retrieve Remaining Recording time from CCaeEngine
  6119 * which is used in AppController and AppUi during Video Rec Operation
  6122 * which is used in AppController and AppUi during Video Rec Operation
  6120 */
  6123 */
  6121 TTimeIntervalMicroSeconds 
  6124 TTimeIntervalMicroSeconds
  6122 CCamCameraController::RemainingVideoRecordingTime()
  6125 CCamCameraController::RemainingVideoRecordingTime()
  6123 	{
  6126 	{
  6124 	if( iCaeEngine )
  6127 	if( iCaeEngine )
  6125   	return iCaeEngine->RemainingVideoRecordingTime();
  6128   	return iCaeEngine->RemainingVideoRecordingTime();
  6126   else
  6129   else
  6128 	}
  6131 	}
  6129 
  6132 
  6130 
  6133 
  6131 // ===========================================================================
  6134 // ===========================================================================
  6132 // Performance measurement related
  6135 // Performance measurement related
  6133    
  6136 
  6134 #ifdef CAMERAAPP_PERFORMANCE_CONTROLLER
  6137 #ifdef CAMERAAPP_PERFORMANCE_CONTROLLER
  6135 
  6138 
  6136 // ---------------------------------------------------------------------------
  6139 // ---------------------------------------------------------------------------
  6137 // PerformanceLogger()
  6140 // PerformanceLogger()
  6138 //
  6141 //
  6139 // Return the performance logger instance.
  6142 // Return the performance logger instance.
  6140 // Used to record performance measurement data.
  6143 // Used to record performance measurement data.
  6141 // ---------------------------------------------------------------------------
  6144 // ---------------------------------------------------------------------------
  6142 //
  6145 //
  6143 const CCamPerformanceLogger* 
  6146 const CCamPerformanceLogger*
  6144 CCamCameraController::PerformanceLogger() const
  6147 CCamCameraController::PerformanceLogger() const
  6145   {
  6148   {
  6146   return iPerformanceLogger;
  6149   return iPerformanceLogger;
  6147   }
  6150   }
  6148 
  6151 
  6156 #ifdef _DEBUG
  6159 #ifdef _DEBUG
  6157 // ---------------------------------------------------------------------------
  6160 // ---------------------------------------------------------------------------
  6158 // PrintCameraInfo
  6161 // PrintCameraInfo
  6159 // ---------------------------------------------------------------------------
  6162 // ---------------------------------------------------------------------------
  6160 //
  6163 //
  6161 void 
  6164 void
  6162 CCamCameraController::PrintCameraInfo() const
  6165 CCamCameraController::PrintCameraInfo() const
  6163   {
  6166   {
  6164   PRINT ( _L("Camera <> ==================================================") );
  6167   PRINT ( _L("Camera <> ==================================================") );
  6165   PRINT ( _L("Camera <> Camera info:") ); 
  6168   PRINT ( _L("Camera <> Camera info:") );
  6166   PRINT3( _L("Camera <> Camera hw version[%d.%d.%d]"), 
  6169   PRINT3( _L("Camera <> Camera hw version[%d.%d.%d]"),
  6167           iCameraInfo.iHardwareVersion.iMajor,
  6170           iCameraInfo.iHardwareVersion.iMajor,
  6168           iCameraInfo.iHardwareVersion.iMinor,
  6171           iCameraInfo.iHardwareVersion.iMinor,
  6169           iCameraInfo.iHardwareVersion.iBuild );
  6172           iCameraInfo.iHardwareVersion.iBuild );
  6170   PRINT3( _L("Camera <> Camera sw version[%d.%d.%d]"), 
  6173   PRINT3( _L("Camera <> Camera sw version[%d.%d.%d]"),
  6171           iCameraInfo.iSoftwareVersion.iMajor,
  6174           iCameraInfo.iSoftwareVersion.iMajor,
  6172           iCameraInfo.iSoftwareVersion.iMinor,
  6175           iCameraInfo.iSoftwareVersion.iMinor,
  6173           iCameraInfo.iSoftwareVersion.iBuild );  
  6176           iCameraInfo.iSoftwareVersion.iBuild );
  6174   PRINT1( _L("Camera <> TCameraInfo.iMinZoom             : %d"), iCameraInfo.iMinZoom );
  6177   PRINT1( _L("Camera <> TCameraInfo.iMinZoom             : %d"), iCameraInfo.iMinZoom );
  6175   PRINT1( _L("Camera <> TCameraInfo.iMaxZoom             : %d"), iCameraInfo.iMaxZoom ); 
  6178   PRINT1( _L("Camera <> TCameraInfo.iMaxZoom             : %d"), iCameraInfo.iMaxZoom );
  6176   PRINT1( _L("Camera <> TCameraInfo.iMaxDigitalZoom      : %d"), iCameraInfo.iMaxDigitalZoom ); 
  6179   PRINT1( _L("Camera <> TCameraInfo.iMaxDigitalZoom      : %d"), iCameraInfo.iMaxDigitalZoom );
  6177   PRINT1( _L("Camera <> TCameraInfo.iMinZoomFactor       : %f"), iCameraInfo.iMinZoomFactor );
  6180   PRINT1( _L("Camera <> TCameraInfo.iMinZoomFactor       : %f"), iCameraInfo.iMinZoomFactor );
  6178   PRINT1( _L("Camera <> TCameraInfo.iMaxZoomFactor       : %f"), iCameraInfo.iMaxZoomFactor ); 
  6181   PRINT1( _L("Camera <> TCameraInfo.iMaxZoomFactor       : %f"), iCameraInfo.iMaxZoomFactor );
  6179   PRINT1( _L("Camera <> TCameraInfo.iMaxDigitalZoomFactor: %f"), iCameraInfo.iMaxDigitalZoomFactor ); 
  6182   PRINT1( _L("Camera <> TCameraInfo.iMaxDigitalZoomFactor: %f"), iCameraInfo.iMaxDigitalZoomFactor );
  6180   PRINT ( _L("Camera <> ==================================================") );
  6183   PRINT ( _L("Camera <> ==================================================") );
  6181   }
  6184   }
  6182 
  6185 
  6183 
  6186 
  6184 // ---------------------------------------------------------------------------
  6187 // ---------------------------------------------------------------------------
  6203 
  6206 
  6204 // ---------------------------------------------------------------------------
  6207 // ---------------------------------------------------------------------------
  6205 // CCamCameraController::SettingValueUpToDateL
  6208 // CCamCameraController::SettingValueUpToDateL
  6206 // ---------------------------------------------------------------------------
  6209 // ---------------------------------------------------------------------------
  6207 //
  6210 //
  6208 TBool 
  6211 TBool
  6209 CCamCameraController::SettingValueUpToDateL( const NCamCameraController::TCamCameraSettingId& aSettingId )
  6212 CCamCameraController::SettingValueUpToDateL( const NCamCameraController::TCamCameraSettingId& aSettingId )
  6210   {
  6213   {
  6211   PRINT( _L("Camera => CCamCameraController::SettingValueUpToDate") );
  6214   PRINT( _L("Camera => CCamCameraController::SettingValueUpToDate") );
  6212   TBool upToDate = ETrue;
  6215   TBool upToDate = ETrue;
  6213     
  6216 
  6214   switch( aSettingId )
  6217   switch( aSettingId )
  6215     {      
  6218     {
  6216     case ECameraSettingFlash:
  6219     case ECameraSettingFlash:
  6217     case ECameraUserSceneSettingFlash:
  6220     case ECameraUserSceneSettingFlash:
  6218       {
  6221       {
  6219       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingFlash") );        
  6222       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingFlash") );
  6220       
  6223 
  6221       // Supposed setting value from settings provider      
  6224       // Supposed setting value from settings provider
  6222       CCamera::TFlash flashSetting( CCamera::EFlashNone );
  6225       CCamera::TFlash flashSetting( CCamera::EFlashNone );
  6223       iSettingProvider.ProvideCameraSettingL( aSettingId, &flashSetting );
  6226       iSettingProvider.ProvideCameraSettingL( aSettingId, &flashSetting );
  6224       
  6227 
  6225       // Real settings value from camera  
  6228       // Real settings value from camera
  6226       CCamera::TFlash flashValue( CCamera::EFlashNone );
  6229       CCamera::TFlash flashValue( CCamera::EFlashNone );
  6227       GetCameraSettingValueL( aSettingId, &flashValue );   
  6230       GetCameraSettingValueL( aSettingId, &flashValue );
  6228       
  6231 
  6229       PRINT2( _L("Camera <> flashValue = %d, flashSetting = %d"), flashValue, flashSetting );
  6232       PRINT2( _L("Camera <> flashValue = %d, flashSetting = %d"), flashValue, flashSetting );
  6230       upToDate = ( flashValue == flashSetting );           
  6233       upToDate = ( flashValue == flashSetting );
  6231       break;  
  6234       break;
  6232       }    
  6235       }
  6233     case ECameraSettingExposure:
  6236     case ECameraSettingExposure:
  6234     case ECameraUserSceneSettingExposure:
  6237     case ECameraUserSceneSettingExposure:
  6235       {
  6238       {
  6236       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingExposure") );
  6239       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingExposure") );
  6237       TPckgBuf<TCamSettingDataExposure> exposureSetting;
  6240       TPckgBuf<TCamSettingDataExposure> exposureSetting;
  6238       iSettingProvider.ProvideCameraSettingL( aSettingId, &exposureSetting );
  6241       iSettingProvider.ProvideCameraSettingL( aSettingId, &exposureSetting );
  6239       
  6242 
  6240       TPckgBuf<TCamSettingDataExposure> exposureValue;
  6243       TPckgBuf<TCamSettingDataExposure> exposureValue;
  6241       GetCameraSettingValueL( aSettingId, &exposureValue ); 
  6244       GetCameraSettingValueL( aSettingId, &exposureValue );
  6242       
  6245 
  6243       if ( exposureSetting().iExposureMode != exposureValue().iExposureMode ||
  6246       if ( exposureSetting().iExposureMode != exposureValue().iExposureMode ||
  6244            exposureSetting().iExposureStep != exposureValue().iExposureStep )
  6247            exposureSetting().iExposureStep != exposureValue().iExposureStep )
  6245         {
  6248         {
  6246         upToDate = EFalse;  
  6249         upToDate = EFalse;
  6247         }
  6250         }
  6248       
  6251 
  6249       break;
  6252       break;
  6250       }    
  6253       }
  6251     case ECameraSettingLightSensitivity:
  6254     case ECameraSettingLightSensitivity:
  6252     case ECameraUserSceneSettingLightSensitivity:
  6255     case ECameraUserSceneSettingLightSensitivity:
  6253       {        
  6256       {
  6254       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingLightSensitivity") );  
  6257       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingLightSensitivity") );
  6255       
  6258 
  6256       RArray<TInt> ISOarray;
  6259       RArray<TInt> ISOarray;
  6257       CleanupClosePushL( ISOarray );
  6260       CleanupClosePushL( ISOarray );
  6258 #ifdef CAMERAAPP_CAPI_V2
  6261 #ifdef CAMERAAPP_CAPI_V2
  6259       iAdvancedSettings->GetSupportedIsoRatesL( ISOarray );
  6262       iAdvancedSettings->GetSupportedIsoRatesL( ISOarray );
  6260 #endif
  6263 #endif
  6262 
  6265 
  6263       TInt* isoSetting = 0;
  6266       TInt* isoSetting = 0;
  6264       iSettingProvider.ProvideCameraSettingL( aSettingId, &isoSetting );
  6267       iSettingProvider.ProvideCameraSettingL( aSettingId, &isoSetting );
  6265       CleanupStack::PopAndDestroy( &ISOarray );
  6268       CleanupStack::PopAndDestroy( &ISOarray );
  6266 
  6269 
  6267       
  6270 
  6268       TInt* isoValue = 0;
  6271       TInt* isoValue = 0;
  6269       GetCameraSettingValueL( aSettingId, &isoValue );
  6272       GetCameraSettingValueL( aSettingId, &isoValue );
  6270       
  6273 
  6271       upToDate = ( isoSetting == isoValue );      
  6274       upToDate = ( isoSetting == isoValue );
  6272       break;  
  6275       break;
  6273       }    
  6276       }
  6274     case ECameraSettingWhiteBalance:
  6277     case ECameraSettingWhiteBalance:
  6275     case ECameraUserSceneSettingWhiteBalance:
  6278     case ECameraUserSceneSettingWhiteBalance:
  6276       {
  6279       {
  6277       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingWhiteBalance") );  
  6280       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingWhiteBalance") );
  6278       
  6281 
  6279       TPckgBuf<TCamSettingDataWhiteBalance> wbSetting;
  6282       TPckgBuf<TCamSettingDataWhiteBalance> wbSetting;
  6280       iSettingProvider.ProvideCameraSettingL( aSettingId, &wbSetting );
  6283       iSettingProvider.ProvideCameraSettingL( aSettingId, &wbSetting );
  6281       
  6284 
  6282       TPckgBuf<TCamSettingDataWhiteBalance> wbValue;
  6285       TPckgBuf<TCamSettingDataWhiteBalance> wbValue;
  6283       GetCameraSettingValueL( aSettingId, &wbValue );      
  6286       GetCameraSettingValueL( aSettingId, &wbValue );
  6284       
  6287 
  6285       upToDate = ( wbSetting().iWhiteBalanceMode == wbValue().iWhiteBalanceMode );
  6288       upToDate = ( wbSetting().iWhiteBalanceMode == wbValue().iWhiteBalanceMode );
  6286       break;  
  6289       break;
  6287       }    
  6290       }
  6288     case ECameraSettingColourEffect:
  6291     case ECameraSettingColourEffect:
  6289     case ECameraUserSceneSettingColourEffect:	
  6292     case ECameraUserSceneSettingColourEffect:
  6290       {
  6293       {
  6291       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingColourEffect") );  
  6294       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingColourEffect") );
  6292       
  6295 
  6293       CIP::TEffect effectSetting( CIP::EEffectNone );
  6296       CIP::TEffect effectSetting( CIP::EEffectNone );
  6294       iSettingProvider.ProvideCameraSettingL( aSettingId, &effectSetting );
  6297       iSettingProvider.ProvideCameraSettingL( aSettingId, &effectSetting );
  6295       
  6298 
  6296       CIP::TEffect effectValue( CIP::EEffectNone );
  6299       CIP::TEffect effectValue( CIP::EEffectNone );
  6297       // Can't leave here or other settings won't be restored  
  6300       // Can't leave here or other settings won't be restored
  6298       TRAP_IGNORE( GetCameraSettingValueL( aSettingId, &effectValue ) ); 
  6301       TRAP_IGNORE( GetCameraSettingValueL( aSettingId, &effectValue ) );
  6299       
  6302 
  6300       upToDate = ( effectSetting == effectValue );      
  6303       upToDate = ( effectSetting == effectValue );
  6301       break;  
  6304       break;
  6302       }    
  6305       }
  6303     case ECameraSettingBrightness:
  6306     case ECameraSettingBrightness:
  6304     case ECameraUserSceneSettingBrightness:
  6307     case ECameraUserSceneSettingBrightness:
  6305       {                 
  6308       {
  6306       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingBrightness") );        
  6309       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingBrightness") );
  6307       CCamera::TBrightness brightnessSetting;
  6310       CCamera::TBrightness brightnessSetting;
  6308       iSettingProvider.ProvideCameraSettingL( aSettingId, &brightnessSetting );
  6311       iSettingProvider.ProvideCameraSettingL( aSettingId, &brightnessSetting );
  6309             
  6312 
  6310       CCamera::TBrightness brightnessValue;  
  6313       CCamera::TBrightness brightnessValue;
  6311       GetCameraSettingValueL( aSettingId, &brightnessValue ); 
  6314       GetCameraSettingValueL( aSettingId, &brightnessValue );
  6312       
  6315 
  6313       upToDate = ( brightnessSetting == brightnessValue );  
  6316       upToDate = ( brightnessSetting == brightnessValue );
  6314       break;
  6317       break;
  6315       }      
  6318       }
  6316     case ECameraSettingContrast:
  6319     case ECameraSettingContrast:
  6317     case ECameraUserSceneSettingContrast:
  6320     case ECameraUserSceneSettingContrast:
  6318       {
  6321       {
  6319       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingContrast") ); 
  6322       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingContrast") );
  6320       CCamera::TContrast contrastSetting( CCamera::EContrastAuto );
  6323       CCamera::TContrast contrastSetting( CCamera::EContrastAuto );
  6321       iSettingProvider.ProvideCameraSettingL( aSettingId, &contrastSetting );
  6324       iSettingProvider.ProvideCameraSettingL( aSettingId, &contrastSetting );
  6322       
  6325 
  6323       CCamera::TContrast contrastValue( CCamera::EContrastAuto );
  6326       CCamera::TContrast contrastValue( CCamera::EContrastAuto );
  6324       GetCameraSettingValueL( aSettingId, &contrastValue ); 
  6327       GetCameraSettingValueL( aSettingId, &contrastValue );
  6325       
  6328 
  6326       upToDate = ( contrastSetting == contrastValue );  
  6329       upToDate = ( contrastSetting == contrastValue );
  6327       break;  
  6330       break;
  6328       }    
  6331       }
  6329     case ECameraSettingSharpness:
  6332     case ECameraSettingSharpness:
  6330     case ECameraUserSceneSettingSharpness:
  6333     case ECameraUserSceneSettingSharpness:
  6331       {
  6334       {
  6332       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingSharpness") ); 
  6335       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingSharpness") );
  6333       TInt sharpnessSetting( 0 );
  6336       TInt sharpnessSetting( 0 );
  6334       iSettingProvider.ProvideCameraSettingL( aSettingId, &sharpnessSetting );
  6337       iSettingProvider.ProvideCameraSettingL( aSettingId, &sharpnessSetting );
  6335       
  6338 
  6336       TInt sharpnessValue( 0 );
  6339       TInt sharpnessValue( 0 );
  6337       // Can't leave here or other settings won't be restored  
  6340       // Can't leave here or other settings won't be restored
  6338       TRAP_IGNORE( GetCameraSettingValueL( aSettingId, &sharpnessValue ) ); 
  6341       TRAP_IGNORE( GetCameraSettingValueL( aSettingId, &sharpnessValue ) );
  6339       
  6342 
  6340       upToDate = ( sharpnessSetting == sharpnessValue );  
  6343       upToDate = ( sharpnessSetting == sharpnessValue );
  6341       break;
  6344       break;
  6342       }
  6345       }
  6343     case ECameraSettingDigitalZoom:
  6346     case ECameraSettingDigitalZoom:
  6344       {
  6347       {
  6345       TInt zoomSetting( 0 );
  6348       TInt zoomSetting( 0 );
  6346       iSettingProvider.ProvideCameraSettingL( aSettingId, &zoomSetting );      
  6349       iSettingProvider.ProvideCameraSettingL( aSettingId, &zoomSetting );
  6347       
  6350 
  6348       TInt zoomValue( 0 );
  6351       TInt zoomValue( 0 );
  6349       GetCameraSettingValueL( aSettingId, &zoomValue );            
  6352       GetCameraSettingValueL( aSettingId, &zoomValue );
  6350       
  6353 
  6351       upToDate = ( zoomSetting == zoomValue );
  6354       upToDate = ( zoomSetting == zoomValue );
  6352       break;
  6355       break;
  6353       } 
  6356       }
  6354 #ifdef CAMERAAPP_CAPI_V2
  6357 #ifdef CAMERAAPP_CAPI_V2
  6355     case ECameraSettingStabilization:
  6358     case ECameraSettingStabilization:
  6356       {
  6359       {
  6357       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingStabilization") ); 
  6360       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingStabilization") );
  6358       
  6361 
  6359       TPckgBuf<TCamSettingDataStabilization> stabilizationSetting;
  6362       TPckgBuf<TCamSettingDataStabilization> stabilizationSetting;
  6360       iSettingProvider.ProvideCameraSettingL( aSettingId, &stabilizationSetting );
  6363       iSettingProvider.ProvideCameraSettingL( aSettingId, &stabilizationSetting );
  6361       
  6364 
  6362       TPckgBuf<TCamSettingDataStabilization> stabilizationValue;
  6365       TPckgBuf<TCamSettingDataStabilization> stabilizationValue;
  6363       GetCameraSettingValueL( aSettingId, &stabilizationValue );
  6366       GetCameraSettingValueL( aSettingId, &stabilizationValue );
  6364       if ( stabilizationSetting().iMode != stabilizationValue().iMode ||
  6367       if ( stabilizationSetting().iMode != stabilizationValue().iMode ||
  6365               stabilizationSetting().iEffect != stabilizationValue().iEffect ||
  6368               stabilizationSetting().iEffect != stabilizationValue().iEffect ||
  6366               stabilizationSetting().iComplexity != stabilizationValue().iComplexity )
  6369               stabilizationSetting().iComplexity != stabilizationValue().iComplexity )
  6367         {
  6370         {
  6368         upToDate = EFalse;  
  6371         upToDate = EFalse;
  6369         }
  6372         }
  6370       break;
  6373       break;
  6371       }
  6374       }
  6372     case ECameraSettingContAF: 
  6375     case ECameraSettingContAF:
  6373       {
  6376       {
  6374       TBool isContAFon( iAdvancedSettings->AutoFocusType() & 
  6377       TBool isContAFon( iAdvancedSettings->AutoFocusType() &
  6375                         CAS::EAutoFocusTypeContinuous );
  6378                         CAS::EAutoFocusTypeContinuous );
  6376       if( IsFlagOn( iInfo.iState, ECamVideoOn ) )
  6379       if( IsFlagOn( iInfo.iState, ECamVideoOn ) )
  6377         {
  6380         {
  6378         TBool contAF( ETrue );
  6381         TBool contAF( ETrue );
  6379         iSettingProvider.ProvideCameraSettingL( aSettingId, &contAF );
  6382         iSettingProvider.ProvideCameraSettingL( aSettingId, &contAF );
  6380         if( contAF != isContAFon )
  6383         if( contAF != isContAFon )
  6381           {
  6384           {
  6382           upToDate = EFalse; 
  6385           upToDate = EFalse;
  6383           }
  6386           }
  6384         }
  6387         }
  6385       else
  6388       else
  6386         {
  6389         {
  6387         //Do nothing
  6390         //Do nothing
  6388         
  6391 
  6389         }     
  6392         }
  6390       break;
  6393       break;
  6391       }
  6394       }
  6392 #endif      
  6395 #endif
  6393     default:
  6396     default:
  6394       {
  6397       {
  6395       PRINT1( _L("CCamCameraController::SettingValueUpToDate - unknown setting id: %d"), aSettingId );
  6398       PRINT1( _L("CCamCameraController::SettingValueUpToDate - unknown setting id: %d"), aSettingId );
  6396       }
  6399       }
  6397     
  6400 
  6398     }  
  6401     }
  6399     
  6402 
  6400   PRINT1( _L("Camera <= CCamCameraController::SettingValueUpToDate returning %d"), upToDate );
  6403   PRINT1( _L("Camera <= CCamCameraController::SettingValueUpToDate returning %d"), upToDate );
  6401   return upToDate;
  6404   return upToDate;
  6402   }
  6405   }
  6403 
  6406 
  6404 
  6407 
  6420         PRINT( _L("Camera <> viewfinder active and window handle changed, restarting viewfinder...") );
  6423         PRINT( _L("Camera <> viewfinder active and window handle changed, restarting viewfinder...") );
  6421         iCamera->StopViewFinder();
  6424         iCamera->StopViewFinder();
  6422         iInfo.iVfState = ECamTriInactive;
  6425         iInfo.iVfState = ECamTriInactive;
  6423 
  6426 
  6424         // restart viewfinder
  6427         // restart viewfinder
  6425         //TRAP_IGNORE( ProcessVfStartRequestL() );  
  6428         //TRAP_IGNORE( ProcessVfStartRequestL() );
  6426 		iAppController.EnterViewfinderMode(iAppController.CurrentMode());
  6429 		iAppController.EnterViewfinderMode(iAppController.CurrentMode());
  6427         }
  6430         }
  6428     iViewfinderWindow = aWindow;
  6431     iViewfinderWindow = aWindow;
  6429 
  6432 
  6430     PRINT( _L("Camera <= CCamCameraController::SetViewfinderWindowHandle") );
  6433     PRINT( _L("Camera <= CCamCameraController::SetViewfinderWindowHandle") );
  6457 
  6460 
  6458 // ---------------------------------------------------------------------------
  6461 // ---------------------------------------------------------------------------
  6459 // CCamCameraController::SetVfWindowOrdinal
  6462 // CCamCameraController::SetVfWindowOrdinal
  6460 // ---------------------------------------------------------------------------
  6463 // ---------------------------------------------------------------------------
  6461 //
  6464 //
  6462 TInt CCamCameraController::SetVfWindowOrdinal( TInt aOrdinalPosition )  
  6465 TInt CCamCameraController::SetVfWindowOrdinal( TInt aOrdinalPosition )
  6463     {
  6466     {
  6464     TInt orgPos( KErrUnknown ); 
  6467     TInt orgPos( KErrUnknown );
  6465     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
  6468     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
  6466     if ( iViewfinderWindow )
  6469     if ( iViewfinderWindow )
  6467         {
  6470         {
  6468         TInt cbaPos(0);
  6471         TInt cbaPos(0);
  6469         TInt toolbarPos(0);
  6472         TInt toolbarPos(0);
  6470         CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
  6473         CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
  6477         else if ( appUi )
  6480         else if ( appUi )
  6478             {
  6481             {
  6479             // Find out other windows ordinal positions
  6482             // Find out other windows ordinal positions
  6480             if ( cba )
  6483             if ( cba )
  6481                 {
  6484                 {
  6482                 cbaPos =  cba->DrawableWindow()->OrdinalPosition(); 
  6485                 cbaPos =  cba->DrawableWindow()->OrdinalPosition();
  6483                 }
  6486                 }
  6484             CAknToolbar* toolbar = appUi->CurrentFixedToolbar();
  6487             CAknToolbar* toolbar = appUi->CurrentFixedToolbar();
  6485             if ( toolbar )
  6488             if ( toolbar )
  6486                 {
  6489                 {
  6487                 RDrawableWindow* toolbarwindow = toolbar->DrawableWindow();
  6490                 RDrawableWindow* toolbarwindow = toolbar->DrawableWindow();
  6488                 if ( toolbarwindow )
  6491                 if ( toolbarwindow )
  6489                     {
  6492                     {
  6490                     toolbarPos = toolbarwindow->OrdinalPosition();
  6493                     toolbarPos = toolbarwindow->OrdinalPosition();
  6491                     }
  6494                     }
  6492                 } 
  6495                 }
  6493             // Calculate new viewfinder position,
  6496             // Calculate new viewfinder position,
  6494             // just under fixed toolbar and CBA buttons
  6497             // just under fixed toolbar and CBA buttons
  6495             TInt newPos = Max( toolbarPos, cbaPos ) + 1;
  6498             TInt newPos = Max( toolbarPos, cbaPos ) + 1;
  6496             // Use new position if viefinder window is not visible already
  6499             // Use new position if viefinder window is not visible already
  6497             iViewfinderWindow->SetOrdinalPosition( Min( orgPos, newPos ) );
  6500             iViewfinderWindow->SetOrdinalPosition( Min( orgPos, newPos ) );
  6505 // ---------------------------------------------------------------------------
  6508 // ---------------------------------------------------------------------------
  6506 // CCamCameraController::DelayedCaeCallback
  6509 // CCamCameraController::DelayedCaeCallback
  6507 // Static function called when the timer expires
  6510 // Static function called when the timer expires
  6508 // ---------------------------------------------------------------------------
  6511 // ---------------------------------------------------------------------------
  6509 //
  6512 //
  6510 TInt 
  6513 TInt
  6511 CCamCameraController::DelayedCaeCallback( TAny* aController )
  6514 CCamCameraController::DelayedCaeCallback( TAny* aController )
  6512     {
  6515     {
  6513     CCamCameraController* self = static_cast<CCamCameraController*>( aController );
  6516     CCamCameraController* self = static_cast<CCamCameraController*>( aController );
  6514     self->CallAppropriateCallback();
  6517     self->CallAppropriateCallback();
  6515     
  6518 
  6516     return KErrNone;
  6519     return KErrNone;
  6517     }
  6520     }
  6518 
  6521 
  6519 // ---------------------------------------------------------------------------
  6522 // ---------------------------------------------------------------------------
  6520 // CCamCameraController::CallAppropriateCallback
  6523 // CCamCameraController::CallAppropriateCallback
  6521 // Helper function to call the appropriate callback handler.
  6524 // Helper function to call the appropriate callback handler.
  6522 // ---------------------------------------------------------------------------
  6525 // ---------------------------------------------------------------------------
  6523 //
  6526 //
  6524 void 
  6527 void
  6525 CCamCameraController::CallAppropriateCallback( const TCamCameraEventId aEventId,
  6528 CCamCameraController::CallAppropriateCallback( const TCamCameraEventId aEventId,
  6526                                                      TInt              aStatus )
  6529                                                      TInt              aStatus )
  6527     {
  6530     {
  6528     PRINT2( _L("Camera => CCamCameraController::CallAppropriateCallback, event:%d, status:%d"), aEventId, aStatus ) 
  6531     PRINT2( _L("Camera => CCamCameraController::CallAppropriateCallback, event:%d, status:%d"), aEventId, aStatus )
  6529     
  6532 
  6530     switch ( iSimEventId )
  6533     switch ( iSimEventId )
  6531         {
  6534         {
  6532         case ECamCameraEventVideoInit:
  6535         case ECamCameraEventVideoInit:
  6533         case ECamCameraEventVideoStart:  // fallthrough
  6536         case ECamCameraEventVideoStart:  // fallthrough
  6534         case ECamCameraEventVideoPause:  // fallthrough
  6537         case ECamCameraEventVideoPause:  // fallthrough
  6536             if( aEventId == ECamCameraEventNone )
  6539             if( aEventId == ECamCameraEventNone )
  6537                 {
  6540                 {
  6538                 PRINT( _L("Camera <> CCamCameraController::CallAppropriateCallback - calling handler after delay") )
  6541                 PRINT( _L("Camera <> CCamCameraController::CallAppropriateCallback - calling handler after delay") )
  6539                 HandleVideoEvent( iSimEventId, iSimStatus );
  6542                 HandleVideoEvent( iSimEventId, iSimStatus );
  6540                 }
  6543                 }
  6541             else 
  6544             else
  6542                 {
  6545                 {
  6543                 PRINT( _L("Camera <> CCamCameraController::CallAppropriateCallback - calling handler without delay") )
  6546                 PRINT( _L("Camera <> CCamCameraController::CallAppropriateCallback - calling handler without delay") )
  6544                 HandleVideoEvent( aEventId, aStatus );
  6547                 HandleVideoEvent( aEventId, aStatus );
  6545                 }           
  6548                 }
  6546             break;
  6549             break;
  6547         default:
  6550         default:
  6548             break;
  6551             break;
  6549         }
  6552         }
  6550     
  6553 
  6551     // In case of being called by timer, stop and destro the timer 
  6554     // In case of being called by timer, stop and destro the timer
  6552     if( aEventId == ECamCameraEventNone && iCallbackTimer )
  6555     if( aEventId == ECamCameraEventNone && iCallbackTimer )
  6553         {
  6556         {
  6554         iCallbackTimer->Cancel();
  6557         iCallbackTimer->Cancel();
  6555         delete iCallbackTimer;
  6558         delete iCallbackTimer;
  6556         iCallbackTimer = NULL;
  6559         iCallbackTimer = NULL;
  6557         }
  6560         }
  6558     
  6561 
  6559     PRINT( _L("Camera <= CCamCameraController::CallAppropriateCallback") )  
  6562     PRINT( _L("Camera <= CCamCameraController::CallAppropriateCallback") )
  6560     }
  6563     }
  6561 
  6564 
  6562 #endif // CAMERAAPP_CAE_ERR_SIMULATION
  6565 #endif // CAMERAAPP_CAE_ERR_SIMULATION
  6563 
  6566 
  6564 // ---------------------------------------------------------------------------
  6567 // ---------------------------------------------------------------------------
  6565 // CCamCameraController::AsyncVideoStopModeSupported
  6568 // CCamCameraController::AsyncVideoStopModeSupported
  6566 // ---------------------------------------------------------------------------
  6569 // ---------------------------------------------------------------------------
  6567 //
  6570 //
  6568 TBool 
  6571 TBool
  6569 CCamCameraController::AsyncVideoStopModeSupported()
  6572 CCamCameraController::AsyncVideoStopModeSupported()
  6570   {
  6573   {
  6571   PRINT1( _L("Camera <> CCamCameraController::AsyncVideoStopModeSupported = %d "), iAsyncVideoStopModeSupported );
  6574   PRINT1( _L("Camera <> CCamCameraController::AsyncVideoStopModeSupported = %d "), iAsyncVideoStopModeSupported );
  6572   return( iAsyncVideoStopModeSupported );
  6575   return( iAsyncVideoStopModeSupported );
  6573   }
  6576   }
  6574 
  6577 
  6575 // ---------------------------------------------------------------------------
  6578 // ---------------------------------------------------------------------------
  6576 // IdleCallback <<static>>
  6579 // IdleCallback <<static>>
  6577 // ---------------------------------------------------------------------------
  6580 // ---------------------------------------------------------------------------
  6578 //
  6581 //
  6579 // static 
  6582 // static
  6580 TInt CCamCameraController::IdleCallback( TAny* aSelf )
  6583 TInt CCamCameraController::IdleCallback( TAny* aSelf )
  6581     {
  6584     {
  6582     CCamCameraController* self( static_cast<CCamCameraController*>( aSelf ) );
  6585     CCamCameraController* self( static_cast<CCamCameraController*>( aSelf ) );
  6583     self->DoIveRecovery();
  6586     self->DoIveRecovery();
  6584 
  6587 
  6590 // ---------------------------------------------------------------------------
  6593 // ---------------------------------------------------------------------------
  6591 //
  6594 //
  6592 void CCamCameraController::DoIveRecovery()
  6595 void CCamCameraController::DoIveRecovery()
  6593     {
  6596     {
  6594     PRINT( _L("Camera => CCamCameraController::DoIveRecovery") )
  6597     PRINT( _L("Camera => CCamCameraController::DoIveRecovery") )
  6595     if( iAppController.IsAppUiAvailable() 
  6598     if( iAppController.IsAppUiAvailable()
  6596             && !( iAppController.IsInShutdownMode() || iAppController.CheckExitStatus() ) )
  6599             && !( iAppController.IsInShutdownMode() || iAppController.CheckExitStatus() ) )
  6597         {
  6600         {
  6598         CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
  6601         CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
  6599         __ASSERT_DEBUG(appUi, CamPanic(ECamPanicNullPointer));
  6602         __ASSERT_DEBUG(appUi, CamPanic(ECamPanicNullPointer));
  6600 		TVwsViewId activeView;
  6603 		TVwsViewId activeView;
  6606             }
  6609             }
  6607         else
  6610         else
  6608             {
  6611             {
  6609             //There was an error when getting active view ID. Propably camera
  6612             //There was an error when getting active view ID. Propably camera
  6610             //application went to background. In that case just return because
  6613             //application went to background. In that case just return because
  6611             //camera resource should be released when going to background.             
  6614             //camera resource should be released when going to background.
  6612             return;
  6615             return;
  6613             }
  6616             }
  6614 		__ASSERT_DEBUG(view, CamPanic(ECamPanicNullPointer));
  6617 		__ASSERT_DEBUG(view, CamPanic(ECamPanicNullPointer));
  6615         if ( appUi->StandbyStatus() && view->IsInStandbyMode() ) 
  6618         if ( appUi->StandbyStatus() && view->IsInStandbyMode() )
  6616             {
  6619             {
  6617             PRINT( _L("Camera <> CCamCameraController::DoIveRecovery - Standby mode active, try to exit") )  
  6620             PRINT( _L("Camera <> CCamCameraController::DoIveRecovery - Standby mode active, try to exit") )
  6618             TRAP_IGNORE( appUi->HandleControllerEventL(  ECamEventCameraChanged, 
  6621             TRAP_IGNORE( appUi->HandleControllerEventL(  ECamEventCameraChanged,
  6619                                                          KErrNone ) );
  6622                                                          KErrNone ) );
  6620             }
  6623             }
  6621         else
  6624         else
  6622             {
  6625             {
  6623             PRINT( _L("Camera <> CCamCameraController::DoIveRecovery - Start recovering from beginning") )  
  6626             PRINT( _L("Camera <> CCamCameraController::DoIveRecovery - Start recovering from beginning") )
  6624             iIveSequenceActive = EFalse;
  6627             iIveSequenceActive = EFalse;
  6625             if( IsFlagOn( iInfo.iBusy, ECamBusySequence|ECamBusySetting ) )
  6628             if( IsFlagOn( iInfo.iBusy, ECamBusySequence|ECamBusySetting ) )
  6626                 {
  6629                 {
  6627                 if( iActive &&
  6630                 if( iActive &&
  6628                     iActive->IsActive() )
  6631                     iActive->IsActive() )
  6629                     {
  6632                     {
  6630                     iActive->Cancel();
  6633                     iActive->Cancel();
  6631                     }
  6634                     }
  6632                 iIveCancel = ETrue;
  6635                 iIveCancel = ETrue;
  6633                 EndSequence( KErrNone ); // Clears iIveRecoveryOngoing and iIveSequenceActive
  6636                 EndSequence( KErrNone ); // Clears iIveRecoveryOngoing and iIveSequenceActive
  6634                 }  
  6637                 }
  6635             NotifyObservers( KErrNone, ECamCameraEventIveRecover, 
  6638             NotifyObservers( KErrNone, ECamCameraEventIveRecover,
  6636                              ECamCameraEventClassBasicControl );
  6639                              ECamCameraEventClassBasicControl );
  6637             }
  6640             }
  6638         iIveRecoveryCount--;
  6641         iIveRecoveryCount--;
  6639         iIveRecoveryOngoing = ETrue;
  6642         iIveRecoveryOngoing = ETrue;
  6640         iIveCancel = EFalse;
  6643         iIveCancel = EFalse;
  6641         }
  6644         }
  6642     PRINT1( _L("Camera <= CCamCameraController::DoIveRecovery iIveRecoveryCount%d"),iIveRecoveryCount )  
  6645     PRINT1( _L("Camera <= CCamCameraController::DoIveRecovery iIveRecoveryCount%d"),iIveRecoveryCount )
  6643     }
  6646     }
  6644 
  6647 
  6645 // ---------------------------------------------------------------------------
  6648 // ---------------------------------------------------------------------------
  6646 // CCamCameraController::IsWaitingIveResources
  6649 // CCamCameraController::IsWaitingIveResources
  6647 // ---------------------------------------------------------------------------
  6650 // ---------------------------------------------------------------------------
  6648 //
  6651 //
  6649 TBool CCamCameraController::IsWaitingIveResources()
  6652 TBool CCamCameraController::IsWaitingIveResources()
  6650     {
  6653     {
  6651     // ETrue if recovery is started, but not completed.
  6654     // ETrue if recovery is started, but not completed.
  6652     // iIveRecoveryOngoing is set to false when last recovery command is executed
  6655     // iIveRecoveryOngoing is set to false when last recovery command is executed
  6653     return (iIdle && iIdle->IsActive()) || 
  6656     return (iIdle && iIdle->IsActive()) ||
  6654             iIveCancel || iIveRecoveryOngoing || iIveSequenceActive;
  6657             iIveCancel || iIveRecoveryOngoing || iIveSequenceActive;
  6655     }
  6658     }
  6656 
  6659 
  6657 
  6660 
  6658 // ---------------------------------------------------------------------------
  6661 // ---------------------------------------------------------------------------
  6659 // CCamCameraController::SetFaceTrackingL
  6662 // CCamCameraController::SetFaceTrackingL
  6660 // ---------------------------------------------------------------------------
  6663 // ---------------------------------------------------------------------------
  6661 //
  6664 //
  6662 void CCamCameraController::SetFaceTrackingL()
  6665 void CCamCameraController::SetFaceTrackingL()
  6663     {
  6666     {
  6664     if( iCustomInterfaceFaceTracking && 
  6667     if( iCustomInterfaceFaceTracking &&
  6665         KPrimaryCameraIndex == iInfo.iCurrentCamera )
  6668         KPrimaryCameraIndex == iInfo.iCurrentCamera )
  6666       {
  6669       {
  6667       TBool ftOn( EFalse );
  6670       TBool ftOn( EFalse );
  6668       iSettingProvider.ProvideCameraSettingL( ECameraSettingFacetracking, &ftOn );
  6671       iSettingProvider.ProvideCameraSettingL( ECameraSettingFacetracking, &ftOn );
  6669       PRINT1( _L("Camera <> Set facetracking: %d"), ftOn )
  6672       PRINT1( _L("Camera <> Set facetracking: %d"), ftOn )