camerauis/cameraapp/generic/src/cameracontroller/camcameracontroller.cpp
branchRCL_3
changeset 53 61bc0f252b2b
parent 50 f54ad444594d
child 54 bac7acad7cb3
equal deleted inserted replaced
50:f54ad444594d 53:61bc0f252b2b
     1 /*
       
     2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Camera Controller implementation.
       
    15 *              : Class handles CCamera related operations.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // ===========================================================================
       
    22 // Included headers
       
    23 
       
    24 #include "camcameracontrollerflags.hrh"
       
    25 
       
    26 // -------------------------------------
       
    27 // General
       
    28 #include <e32base.h>
       
    29 #include <e32const.h> // KNullHandle
       
    30 #include <fbs.h>
       
    31 #include <gdi.h>
       
    32 #include <aknlayoutscalable_apps.cdl.h>
       
    33 
       
    34 // -------------------------------------
       
    35 // ECAM
       
    36 #include <ecam.h>
       
    37 #ifdef CAMERAAPP_CAPI_V2
       
    38   #include <ecam/ecamdirectviewfinder.h>
       
    39   #include <ecam/camerahistogram.h>
       
    40   #include <ecam/cameraoverlay.h>
       
    41   #include <ecamadvsettings.h>
       
    42   #include <ecamadvsettingsuids.hrh>
       
    43 #endif
       
    44 #include <ecam/camerasnapshot.h> // KUidECamEventCameraSnapshot
       
    45 
       
    46 // -------------------------------------
       
    47 // Camera Application Engine (CAE)
       
    48 #ifdef CAMERAAPP_CAE_FOR_VIDEO
       
    49   #include <CaeEngine.h>
       
    50 #endif
       
    51 
       
    52 // -------------------------------------
       
    53 // Custom interfaces
       
    54 #include <ECamOrientationCustomInterface2.h>
       
    55 #include <ECamUIOrientationOverrideCustomAPI.h>
       
    56 #include <ecamusecasehintcustomapi.h>
       
    57 #include <ecamfacetrackingcustomapi.h>
       
    58 #include <akntoolbar.h>
       
    59 // -------------------------------------
       
    60 // Own
       
    61 #include "camcameracontroller.pan"
       
    62 #include "camlogging.h"
       
    63 #include "cambuffershare.h"
       
    64 #include "cambuffersharecleanup.h"
       
    65 #include "cambuffercleanup.h"
       
    66 #include "cambuffer.h"
       
    67 
       
    68 #include "camsnapshotprovider.h"
       
    69 #include "camimageencoder.h"
       
    70 
       
    71 #include "mcamsettingprovider.h"
       
    72 #include "mcamcameraobserver.h"
       
    73 #include "camsettingconversion.h"
       
    74 #include "camcameraevents.h"
       
    75 #include "camcamerarequests.h"
       
    76 #include "camcameracontrolleractive.h"
       
    77 #include "camcameracontroller.h"
       
    78 #include "OstTraceDefinitions.h"
       
    79 #ifdef OST_TRACE_COMPILER_IN_USE
       
    80 #include "camcameracontrollerTraces.h"
       
    81 #endif
       
    82 
       
    83 #ifdef FORCE_DUMMY_ENGINE
       
    84   #include "CameraappDummyEngine.h"
       
    85 #endif // FORCE_DUMMY_ENGINE
       
    86 #ifdef CAMERAAPP_CAPI_EMULATOR
       
    87   #include "CamCamera.h"
       
    88 #endif // CAMERAAPP_CAPI_EMULATOR
       
    89 #ifdef CAMERAAPP_FLASH_SIMULATOR
       
    90   #include "camflashsimulator.h"
       
    91 #endif // CAMERAAPP_FLASH_SIMULATOR
       
    92 #ifdef CAMERAAPP_CAE_ERR_SIMULATION
       
    93   #include "CamTimer.h"
       
    94 #endif // CAMERAAPP_CAE_ERR_SIMULATION
       
    95 
       
    96 #include "CamAppUi.h"
       
    97 #include "CameraUiConfigManager.h"
       
    98 #include "CamViewBase.h"
       
    99 #include "CamPanic.h"
       
   100 // ===========================================================================
       
   101 // Local constants
       
   102 const TInt KIveRecoveryCountMax = 2;
       
   103 typedef CCamera::CCameraAdvancedSettings CAS;
       
   104 typedef CCamera::CCameraImageProcessing  CIP;
       
   105 
       
   106 //for camusecasehintcustomapi
       
   107 _LIT8(KCMRMimeTypeH263, "video/H263-2000");
       
   108 _LIT8(KCMRMimeTypeMPEG4VSPL2, "video/mp4v-es; profile-level-id=2");
       
   109 _LIT8(KCMRMimeTypeMPEG4VSPL3, "video/mp4v-es; profile-level-id=3");
       
   110 _LIT8(KCMRMimeTypeMPEG4VSPL4A, "video/mp4v-es; profile-level-id=4");
       
   111 _LIT8(KCMRMimeTypeH264AVCBPL30, "video/H264; profile-level-id=42801E");
       
   112 _LIT8(KCMRMimeTypeH264AVCBPL31, "video/H264; profile-level-id=42801F");
       
   113 
       
   114 
       
   115 namespace NCamCameraController
       
   116   {
       
   117   static const TInt               KPrimaryCameraIndex         =  0;
       
   118   //static const TInt               KSecondaryCameraIndex       =  1;
       
   119   static const TInt               KInvalidCameraIndex         = -1;
       
   120 
       
   121   #ifdef CAMERAAPP_CAE_FOR_VIDEO
       
   122   //  static const TInt             KCameraDisplayIndex         = 0;
       
   123   #endif
       
   124   #ifdef CAMERAAPP_CAPI_V2
       
   125     static const TInt             KCameraClientPriority       = 100; // -100...100
       
   126   #endif
       
   127 
       
   128   static const TInt               KCamCallBackPriority        = EPriorityHigh;
       
   129 
       
   130   static const TInt               KCamSequenceGranularity     =  2;
       
   131   static const TInt               KResolutionArrayGranularity =  8;
       
   132   #ifdef CAMERAAPP_CAPI_V2_ADV
       
   133     static const TInt             KAdvArrayGranularity        =  5;
       
   134   #endif
       
   135 
       
   136   static const CCamera::TFormat   KCamJpegAlternativeFormat1  = CCamera::EFormatFbsBitmapColor16M;
       
   137   static const CCamera::TFormat   KCamJpegAlternativeFormat2  = CCamera::EFormatFbsBitmapColor64K;
       
   138 
       
   139   static const TInt             KCamReserveTryAgainMaxCount     = 50;
       
   140   static const TInt             KCamReserveTryAgainWaitInterval = 50000; // 50 milliseconds
       
   141   #ifdef _DEBUG
       
   142   _LIT( KCamDriveModeNameBurst,   "EDriveModeBurst"      );
       
   143   _LIT( KCamDriveModeNameSingle,  "EDriveModeSingleShot" );
       
   144   _LIT( KCamDriveModeNameUnknown, "Unknown drive mode!"  );
       
   145   #endif // _DEBUG
       
   146   }
       
   147 
       
   148 // ===========================================================================
       
   149 // Local methods
       
   150 
       
   151 #ifdef CAMERAAPP_PERFORMANCE_CONTROLLER
       
   152   #include "camperformancelogger.h"
       
   153 
       
   154   #define CAMERAAPP_PERF_CONTROLLER_START( AAA )          iPerformanceLogger->Requested( AAA );
       
   155   #define CAMERAAPP_PERF_CONTROLLER_STARTNEW( AAA, BBB )  BBB = EFalse; iPerformanceLogger->Requested( AAA );
       
   156   #define CAMERAAPP_PERF_CONTROLLER_STOP( AAA )           iPerformanceLogger->Completed( AAA );
       
   157   #define CAMERAAPP_PERF_CONTROLLER_STOP_ONCE( AAA, BBB ) if( !BBB ) { iPerformanceLogger->Completed( AAA ); BBB = ETrue; }
       
   158 #else
       
   159   #define CAMERAAPP_PERF_CONTROLLER_START( AAA )
       
   160   #define CAMERAAPP_PERF_CONTROLLER_STARTNEW( AAA, BBB )
       
   161   #define CAMERAAPP_PERF_CONTROLLER_STOP( AAA )
       
   162   #define CAMERAAPP_PERF_CONTROLLER_STOP_ONCE( AAA, BBB )
       
   163 #endif // CAMERAAPP_PERFORMANCE_CONTROLLER
       
   164 
       
   165 // Helper methods
       
   166 #include "camflagutility.inl"
       
   167 #include "campointerutility.inl"
       
   168 
       
   169 
       
   170 namespace NCamCameraController
       
   171   {
       
   172   /*
       
   173   inline void SetFalse( TAny* aTBool )
       
   174     {
       
   175     TBool* boolean = static_cast<TBool*>( aTBool );
       
   176 
       
   177     if( boolean )
       
   178       *boolean = EFalse;
       
   179     }
       
   180   */
       
   181 
       
   182   inline void SetNotBusy( TAny* aTUint )
       
   183     {
       
   184     TUint* flags = static_cast<TUint*>( aTUint );
       
   185 
       
   186     if( flags )
       
   187       *flags = ECamBusyOff;
       
   188     };
       
   189 
       
   190   inline void ReleaseAndNull( MCameraBuffer*& aBuffer )
       
   191     {
       
   192     if( aBuffer )
       
   193       {
       
   194       aBuffer->Release();
       
   195       aBuffer = NULL;
       
   196       }
       
   197     };
       
   198 #ifdef CAMERAAPP_CAPI_V2_ADV
       
   199   inline void ResetInfo( TAny* aInfo )
       
   200     {
       
   201     TCamAdvancedSettingInfo* info =
       
   202       static_cast<TCamAdvancedSettingInfo*>( aInfo );
       
   203 
       
   204     if( info )
       
   205       {
       
   206       info->Reset();
       
   207       }
       
   208     };
       
   209 
       
   210 
       
   211   inline const TDesC& DriveModeName( TInt aMode )
       
   212     {
       
   213 #ifdef _DEBUG
       
   214     switch( aMode )
       
   215       {
       
   216       case CAS::EDriveModeBurst:      return KCamDriveModeNameBurst;
       
   217       case CAS::EDriveModeSingleShot: return KCamDriveModeNameSingle;
       
   218       default:                        return KCamDriveModeNameUnknown;
       
   219       }
       
   220 #else
       
   221     return KNullDesC;
       
   222 #endif // _DEBUG
       
   223     };
       
   224 #endif
       
   225   }
       
   226 using namespace NCamCameraController;
       
   227 
       
   228 // ===========================================================================
       
   229 // TCamControllerInfo class methods
       
   230 TCamControllerInfo::TCamControllerInfo()
       
   231   {
       
   232   Reset();
       
   233   }
       
   234 
       
   235 void
       
   236 TCamControllerInfo::Reset( TBool aPreserveBusyFlag    /*= EFalse*/,
       
   237                            TBool aPreserveCameraIndex /*= EFalse*/ )
       
   238   {
       
   239   // When we reset the info e.g. after reserve lost event
       
   240   // we need to keep the current camera index stored.
       
   241   if( !aPreserveCameraIndex )
       
   242     {
       
   243     iCurrentCamera          = KErrNotFound;
       
   244     }
       
   245 
       
   246   iState                  = ECamIdle;
       
   247   iCaptureState           = ECamCaptureOff;
       
   248   iCaptureLimit           = 1;
       
   249   iCaptureCount           = 0;
       
   250   iSnapshotCount          = 0;
       
   251 
       
   252   iVfMode                 = ECamViewfinderNone;
       
   253   iVfState                = ECamTriIdle;
       
   254   iViewfinderSize         = TSize();
       
   255   iViewfinderFormat       = CCamera::EFormatFbsBitmapColor16M;
       
   256 
       
   257   iSsState                = ECamTriIdle;
       
   258   iSnapshotSize           = TSize();
       
   259   iSnapshotFormat         = CCamera::EFormatFbsBitmapColor16M;
       
   260   iSnapshotAspectMaintain = EFalse;
       
   261 
       
   262   if( !aPreserveBusyFlag )
       
   263     {
       
   264     iBusy = ECamBusyOff;
       
   265     }
       
   266   }
       
   267 
       
   268 // ---------------------------------------------------------------------------
       
   269 // PrintInfo
       
   270 // ---------------------------------------------------------------------------
       
   271 //
       
   272 void
       
   273 TCamControllerInfo::PrintInfo() const
       
   274   {
       
   275   PRINT ( _L("Camera <> --------------------------------------------------") );
       
   276   PRINT ( _L("Camera <> TCamControllerInfo")                                 );
       
   277   PRINT ( _L("Camera <> ")                                                   );
       
   278 
       
   279   PRINT1( _L("Camera <>   iCurrentCamera          :  %d"    ), iCurrentCamera );
       
   280   PRINT1( _L("Camera <>   iState                  :  %08b"  ), iState );
       
   281 
       
   282   PRINT1( _L("Camera <>   iCaptureState           : [%s]"   ), KCamCameraCaptureStateNames[iCaptureState] );
       
   283   PRINT1( _L("Camera <>   iCaptureLimit           :  %d"    ), iCaptureLimit );
       
   284   PRINT1( _L("Camera <>   iCaptureCount           :  %d"    ), iCaptureCount );
       
   285   PRINT1( _L("Camera <>   iSnapshotCount          :  %d"    ), iSnapshotCount );
       
   286 
       
   287   PRINT1( _L("Camera <>   iVfMode                 : [%s]"   ), KCamViewfinderModeNames    [iVfMode] );
       
   288   PRINT1( _L("Camera <>   iVfState                : [%s]"   ), KCamCameraTriStateNames    [iVfState] );
       
   289   PRINT2( _L("Camera <>   iViewfinderSize         : (%dx%d)"), iViewfinderSize.iWidth, iViewfinderSize.iHeight );
       
   290   PRINT1( _L("Camera <>   iViewfinderFormat       :  %d"    ), iViewfinderFormat );
       
   291 
       
   292   PRINT1( _L("Camera <>   iSsState                : [%s]"   ), KCamCameraTriStateNames    [iSsState] );
       
   293   PRINT2( _L("Camera <>   iSnapshotSize           : (%dx%d)"), iSnapshotSize.iWidth, iSnapshotSize.iHeight );
       
   294   PRINT1( _L("Camera <>   iSnapshotFormat         : %d"     ), iSnapshotFormat );
       
   295   PRINT1( _L("Camera <>   iSnapshotAspectMaintain : %d"     ), iSnapshotAspectMaintain );
       
   296 
       
   297   PRINT1( _L("Camera <>   iBusy                   : %08b"     ), iBusy );
       
   298 
       
   299   PRINT ( _L("Camera <> --------------------------------------------------") );
       
   300   }
       
   301 
       
   302 
       
   303 // ===========================================================================
       
   304 // TCamCameraResolutionSupport class methods
       
   305 
       
   306 TCamCameraResolutionSupport::TCamCameraResolutionSupport()
       
   307   : iResolutions( KResolutionArrayGranularity )
       
   308   {
       
   309   Reset();
       
   310   }
       
   311 
       
   312 TCamCameraResolutionSupport::~TCamCameraResolutionSupport()
       
   313   {
       
   314   iResolutions.Close();
       
   315   }
       
   316 
       
   317 void
       
   318 TCamCameraResolutionSupport::Reset()
       
   319   {
       
   320   iForCameraIndex  = KInvalidCameraIndex;
       
   321   iForCameraFormat = -1;
       
   322   iResolutions.Reset();
       
   323   }
       
   324 
       
   325 #ifdef CAMERAAPP_CAPI_V2_ADV
       
   326 // ===========================================================================
       
   327 // TCamAdvancedSettingInfo class methods
       
   328 
       
   329 TCamAdvancedSettingInfo::TCamAdvancedSettingInfo()
       
   330   : iEvStepsSupport ( KAdvArrayGranularity ),
       
   331     iIsoRatesSupport( KAdvArrayGranularity )
       
   332   {
       
   333   Reset();
       
   334   }
       
   335 
       
   336 TCamAdvancedSettingInfo::~TCamAdvancedSettingInfo()
       
   337   {
       
   338   iEvStepsSupport.Close();
       
   339   iIsoRatesSupport.Close();
       
   340   }
       
   341 
       
   342 void
       
   343 TCamAdvancedSettingInfo::Reset()
       
   344   {
       
   345   iForCameraIndex = KInvalidCameraIndex;
       
   346 
       
   347   iEvModesSupport = 0;
       
   348   iEvStepsSupport.Reset();
       
   349   iEvStepsValueInfo = ENotActive;
       
   350 
       
   351   iIsoRatesSupport.Reset();
       
   352 
       
   353   iDigitalZoomSupport.Reset();
       
   354   iDigitalZoomValueInfo = ENotActive;
       
   355 
       
   356 #ifdef CAMERAAPP_CAPI_V2_IP
       
   357   iColourEffectSupport.Reset();
       
   358   iColourEffectValueInfo = ENotActive;
       
   359 
       
   360   iSharpnessSupport.Reset();
       
   361   iSharpnessValueInfo = ENotActive;
       
   362 #endif
       
   363 
       
   364   iStabilizationModeSupport       = 0;
       
   365   iStabilizationEffectSupport     = 0;
       
   366   iStabilizationComplexitySupport = 0;
       
   367   }
       
   368 
       
   369 // ---------------------------------------------------------------------------
       
   370 // PrintInfo
       
   371 // ---------------------------------------------------------------------------
       
   372 //
       
   373 void
       
   374 TCamAdvancedSettingInfo::PrintInfo() const
       
   375   {
       
   376 #ifdef _DEBUG
       
   377   PRINT ( _L("Camera <> --------------------------------------------------") );
       
   378   PRINT ( _L("Camera <> Value infos:")                                       );
       
   379   PRINT1( _L("Camera <> EV value info            : %04b"), iEvStepsValueInfo      );
       
   380   PRINT1( _L("Camera <> Dig zoom value info      : %04b"), iDigitalZoomValueInfo  );
       
   381 #ifdef CAMERAAPP_CAPI_V2_IP
       
   382   PRINT1( _L("Camera <> Colour effct value info  : %04b"), iColourEffectValueInfo );
       
   383   PRINT1( _L("Camera <> Sharpness value info     : %04b"), iSharpnessValueInfo    );
       
   384 #endif
       
   385   PRINT1( _L("Camera <> ENotActive               : %04b"), ENotActive               );
       
   386   PRINT1( _L("Camera <> EBitField                : %04b"), EBitField                );
       
   387   PRINT1( _L("Camera <> EDiscreteSteps           : %04b"), EDiscreteSteps           );
       
   388   PRINT1( _L("Camera <> EDiscreteRangeMinMaxStep : %04b"), EDiscreteRangeMinMaxStep );
       
   389   PRINT1( _L("Camera <> EContinuousRangeMinMax   : %04b"), EContinuousRangeMinMax   );
       
   390 
       
   391   PRINT ( _L("Camera <> --------------------------------------------------") );
       
   392   PRINT ( _L("Camera <> Dig zoom ratios:") );
       
   393   for( TInt i = 0; i < iDigitalZoomSupport.Count(); i++ )
       
   394     {
       
   395     PRINT2( _L("Camera <> step[%4d]: ratio[%4f]"), i, (TReal)iDigitalZoomSupport[i]/(TReal)KECamFineResolutionFactor );
       
   396     }
       
   397   PRINT ( _L("Camera <> --------------------------------------------------") );
       
   398   PRINT ( _L("Camera <> ISO rates supported:") );
       
   399   for( TInt i = 0; i < iIsoRatesSupport.Count(); i++ )
       
   400     {
       
   401     PRINT2( _L("Camera <> rate[%3d]: %4d"), i, iIsoRatesSupport[i] );
       
   402     }
       
   403   PRINT ( _L("Camera <> --------------------------------------------------") );
       
   404   PRINT ( _L("Camera <> EV steps supported:") );
       
   405   for( TInt i = 0; i < iEvStepsSupport.Count(); i++ )
       
   406     {
       
   407     PRINT2( _L("Camera <> step[%3d]: %4d"), i, iEvStepsSupport[i] );
       
   408     }
       
   409 
       
   410   PRINT ( _L("Camera <> --------------------------------------------------") );
       
   411   PRINT1( _L("Camera <> Advanced EV modes support : %016b"), iEvModesSupport                    );
       
   412   PRINT1( _L("Camera <> EExposureAuto             : %016b"), CCamera::EExposureAuto             );
       
   413   PRINT1( _L("Camera <> EExposureNight            : %016b"), CCamera::EExposureNight            );
       
   414   PRINT1( _L("Camera <> EExposureBacklight        : %016b"), CCamera::EExposureBacklight        );
       
   415   PRINT1( _L("Camera <> EExposureCenter           : %016b"), CCamera::EExposureCenter           );
       
   416   PRINT1( _L("Camera <> EExposureSport            : %016b"), CCamera::EExposureSport            );
       
   417   PRINT1( _L("Camera <> EExposureVeryLong         : %016b"), CCamera::EExposureVeryLong         );
       
   418   PRINT1( _L("Camera <> EExposureSnow             : %016b"), CCamera::EExposureSnow             );
       
   419   PRINT1( _L("Camera <> EExposureBeach            : %016b"), CCamera::EExposureBeach            );
       
   420   PRINT1( _L("Camera <> EExposureProgram          : %016b"), CCamera::EExposureProgram          );
       
   421   PRINT1( _L("Camera <> EExposureAperturePriority : %016b"), CCamera::EExposureAperturePriority );
       
   422   PRINT1( _L("Camera <> EExposureShutterPriority  : %016b"), CCamera::EExposureShutterPriority  );
       
   423   PRINT1( _L("Camera <> EExposureManual           : %016b"), CCamera::EExposureManual           );
       
   424   PRINT1( _L("Camera <> EExposureSuperNight       : %016b"), CCamera::EExposureSuperNight       );
       
   425   PRINT1( _L("Camera <> EExposureInfra            : %016b"), CCamera::EExposureInfra            );
       
   426  PRINT ( _L("Camera <> --------------------------------------------------") );
       
   427 
       
   428 #ifdef CAMERAAPP_CAPI_V2_IP
       
   429   PRINT ( _L("Camera <> Sharpness support:") );
       
   430   for( TInt i = 0; i < iSharpnessSupport.Count(); i++ )
       
   431     {
       
   432     PRINT2( _L("Camera <> step[%3d]: %4d"), i, iSharpnessSupport[i] );
       
   433     }
       
   434   PRINT ( _L("Camera <> --------------------------------------------------") );
       
   435   PRINT ( _L("Camera <> Colour effect support:") );
       
   436   for( TInt i = 0; i < iColourEffectSupport.Count(); i++ )
       
   437     {
       
   438     PRINT2( _L("Camera <> effect[%3d]           : %016b"), i, iColourEffectSupport[i] );
       
   439     }
       
   440   PRINT1( _L("Camera <> EEffectNone           : %016b"), CIP::EEffectNone            );
       
   441   PRINT1( _L("Camera <> EEffectNegative       : %016b"), CIP::EEffectNegative        );
       
   442   PRINT1( _L("Camera <> EEffectMonochrome     : %016b"), CIP::EEffectMonochrome      );
       
   443   PRINT1( _L("Camera <> EEffectSolarize       : %016b"), CIP::EEffectSolarize        );
       
   444   PRINT1( _L("Camera <> EEffectSepia          : %016b"), CIP::EEffectSepia           );
       
   445   PRINT1( _L("Camera <> EEffectEmboss         : %016b"), CIP::EEffectEmboss          );
       
   446   PRINT1( _L("Camera <> EEffectRedEyeReduction: %016b"), CIP::EEffectRedEyeReduction );
       
   447   PRINT1( _L("Camera <> EEffectVivid          : %016b"), CIP::EEffectVivid           );
       
   448   PRINT1( _L("Camera <> EEffectLowSharpening  : %016b"), CIP::EEffectLowSharpening   );
       
   449   PRINT ( _L("Camera <> --------------------------------------------------") );
       
   450 #endif // CAMERAAPP_CAPI_V2_IP
       
   451 
       
   452   PRINT ( _L("Camera <> --------------------------------------------------") );
       
   453   PRINT1( _L("Camera <> Stabilization modes support      : %016b"), iStabilizationModeSupport           );
       
   454   PRINT1( _L("Camera <>   EStabilizationModeOff          : %016b"), CAS::EStabilizationModeOff          );
       
   455   PRINT1( _L("Camera <>   EStabilizationModeHorizontal   : %016b"), CAS::EStabilizationModeHorizontal   );
       
   456   PRINT1( _L("Camera <>   EStabilizationModeVertical     : %016b"), CAS::EStabilizationModeVertical     );
       
   457   PRINT1( _L("Camera <>   EStabilizationModeRotation     : %016b"), CAS::EStabilizationModeRotation     );
       
   458   PRINT1( _L("Camera <>   EStabilizationModeAuto         : %016b"), CAS::EStabilizationModeAuto         );
       
   459   PRINT1( _L("Camera <>   EStabilizationModeManual       : %016b"), CAS::EStabilizationModeManual       );
       
   460   PRINT1( _L("Camera <> Stabilization fx support         : %016b"), iStabilizationEffectSupport         );
       
   461   PRINT1( _L("Camera <>   EStabilizationOff              : %016b"), CAS::EStabilizationOff              );
       
   462   PRINT1( _L("Camera <>   EStabilizationAuto             : %016b"), CAS::EStabilizationAuto             );
       
   463   PRINT1( _L("Camera <>   EStabilizationFine             : %016b"), CAS::EStabilizationFine             );
       
   464   PRINT1( _L("Camera <>   EStabilizationMedium           : %016b"), CAS::EStabilizationMedium           );
       
   465   PRINT1( _L("Camera <>   EStabilizationStrong           : %016b"), CAS::EStabilizationStrong           );
       
   466   PRINT1( _L("Camera <> Stabilization complexity support : %016b"), iStabilizationComplexitySupport     );
       
   467   PRINT1( _L("Camera <>   EStabilizationComplexityAuto   : %016b"), CAS::EStabilizationComplexityAuto   );
       
   468   PRINT1( _L("Camera <>   EStabilizationComplexityLow    : %016b"), CAS::EStabilizationComplexityLow    );
       
   469   PRINT1( _L("Camera <>   EStabilizationComplexityMedium : %016b"), CAS::EStabilizationComplexityMedium );
       
   470   PRINT1( _L("Camera <>   EStabilizationComplexityHigh   : %016b"), CAS::EStabilizationComplexityHigh   );
       
   471   PRINT ( _L("Camera <> --------------------------------------------------") );
       
   472 #endif // _DEBUG
       
   473   }
       
   474 
       
   475 #endif // CAMERAAPP_CAPI_V2_ADV
       
   476 
       
   477 
       
   478 // ===========================================================================
       
   479 // CCamCameraController class methods
       
   480 
       
   481 // ---------------------------------------------------------------------------
       
   482 // static 2-phase constructor
       
   483 // ---------------------------------------------------------------------------
       
   484 //
       
   485 CCamCameraController*
       
   486 CCamCameraController::NewL( MCamSettingProvider& aProvider,
       
   487                             CCamAppController& aAppController,
       
   488                             TInt aCameraIndex /*= 0*/ )
       
   489   {
       
   490   CCamCameraController* self
       
   491       = new (ELeave) CCamCameraController( aProvider, aAppController );
       
   492 
       
   493   CleanupStack::PushL( self );
       
   494   self->ConstructL( aCameraIndex );
       
   495   CleanupStack::Pop( self );
       
   496 
       
   497   return self;
       
   498   }
       
   499 
       
   500 
       
   501 
       
   502 // ---------------------------------------------------------------------------
       
   503 //
       
   504 // ---------------------------------------------------------------------------
       
   505 //
       
   506 CCamCameraController::~CCamCameraController()
       
   507   {
       
   508   PRINT( _L("Camera => ~CCamCameraController") );
       
   509 
       
   510 #ifdef CAMERAAPP_FLASH_SIMULATOR
       
   511   delete iFlashSimulator;
       
   512 #endif
       
   513 
       
   514 #ifdef CAMERAAPP_PERFORMANCE_CONTROLLER
       
   515   delete iPerformanceLogger;
       
   516 #endif // CAMERAAPP_PERFORMANCE_CONTROLLER
       
   517 
       
   518   delete iIdle;
       
   519   iSettingArray.Close();
       
   520 
       
   521   // Remove all observers.
       
   522   // We do not want to broadcast events anymore in this phase.
       
   523   iObservers.Reset();
       
   524   iObserverInterests.Reset();
       
   525 
       
   526   ClearRequestQueue();
       
   527   ClearSettingQueue();
       
   528 
       
   529 
       
   530   PRINT( _L("Camera <> CCamCameraController: release current camera..") );
       
   531   // Release and null CCamera related objects.
       
   532   ReleaseCurrentCamera();
       
   533   PRINT( _L("Camera <> CCamCameraController: ..done") );
       
   534 
       
   535   delete iActive;
       
   536 
       
   537   iObservers.Close();
       
   538   iObserverInterests.Close();
       
   539 
       
   540 #ifdef CAMERAAPP_CAE_ERR_SIMULATION
       
   541   if( iCallbackTimer )
       
   542     {
       
   543     iCallbackTimer->Cancel();
       
   544     delete iCallbackTimer;
       
   545     }
       
   546 #endif // CAMERAAPP_CAE_ERR_SIMULATION
       
   547 
       
   548   PRINT( _L("Camera <= ~CCamCameraController") );
       
   549   }
       
   550 
       
   551 
       
   552 // ===========================================================================
       
   553 // MCameraObserver2
       
   554 
       
   555 // ---------------------------------------------------------------------------
       
   556 // HandleEvent
       
   557 // ---------------------------------------------------------------------------
       
   558 //
       
   559 void
       
   560 CCamCameraController::HandleEvent( const TECAMEvent& aEvent )
       
   561   {
       
   562   // TUid iEventType;
       
   563   // TInt iErrorCode;
       
   564   PRINT2( _L("Camera => CCamCameraController::HandleEvent, event uid(0x%08x) error(%d)"),
       
   565           aEvent.iEventType.iUid,
       
   566           aEvent.iErrorCode );
       
   567 
       
   568   // If we are getting zoom event while saving video,
       
   569   // we must not handle the event
       
   570   TInt uidValue( aEvent.iEventType.iUid );
       
   571   if ( uidValue == KUidECamEventCameraSettingDigitalZoomUidValue
       
   572     && IsFlagOn( iInfo.iBusy, ECamBusySingle ) )
       
   573       {
       
   574        return;
       
   575       }
       
   576 
       
   577 #ifdef CAMERAAPP_CAPI_V2
       
   578 
       
   579   // -------------------------------------------------------
       
   580   if( aEvent.iEventType == KUidECamEventReserveComplete )
       
   581     {
       
   582     HandleReserveGainEvent( aEvent.iErrorCode );
       
   583     }
       
   584   // -------------------------------------------------------
       
   585   else if( aEvent.iEventType == KUidECamEventPowerOnComplete )
       
   586     {
       
   587     HandlePowerOnEvent( aEvent.iErrorCode );
       
   588     }
       
   589   // -------------------------------------------------------
       
   590   else if( aEvent.iEventType == KUidECamEventCameraNoLongerReserved )
       
   591     {
       
   592     HandleReserveLostEvent( aEvent.iErrorCode );
       
   593     }
       
   594   // -------------------------------------------------------
       
   595   else if( !(IsFlagOn( iInfo.iState , ECamPowerOn )))
       
   596     {
       
   597     //If camera is in background then all the rest events will be ignored. Should return without leaving
       
   598     return;
       
   599     }
       
   600   // -------------------------------------------------------
       
   601   else if( aEvent.iEventType == KUidECamEventCameraSnapshot )
       
   602     {
       
   603     HandleSnapshotEvent( aEvent.iErrorCode );
       
   604     }
       
   605   // -------------------------------------------------------
       
   606   else if( aEvent.iEventType == KUidECamEventCameraSettingsOptimalFocus
       
   607         || aEvent.iEventType == KUidECamEventCameraSettingAutoFocusType2 )
       
   608     {
       
   609     HandleAutoFocusEvent( aEvent.iErrorCode, aEvent.iEventType );
       
   610     }
       
   611   // -------------------------------------------------------
       
   612   else
       
   613     {
       
   614 #ifdef CAMERAAPP_CAPI_V2_ADV
       
   615     TInt uidValue( aEvent.iEventType.iUid );
       
   616     switch( uidValue )
       
   617       {
       
   618       // -------------------------------
       
   619       // Settings
       
   620       //
       
   621       // case KUidECamEventCameraSettingTimerIntervalUidValue:
       
   622       // case KUidECamEventCameraSettingTimeLapseUidValue:
       
   623       //
       
   624       case KUidECamEventCameraSettingFlashModeUidValue:
       
   625       case KUidECamEventCameraSettingExposureCompensationStepUidValue:
       
   626       case KUidECamEventCameraSettingIsoRateTypeUidValue:
       
   627       case KUidECamEventCameraSettingWhiteBalanceModeUidValue:
       
   628       case KUidECamEventCameraSettingDigitalZoomUidValue:
       
   629       case KUidECamEventCameraSettingOpticalZoomUidValue:
       
   630       case KUidECamEventImageProcessingAdjustSharpnessUidValue:
       
   631       case KUidECamEventImageProcessingEffectUidValue:
       
   632       case KUidECamEventSettingsStabilizationAlgorithmComplexityUidValue:
       
   633         {
       
   634         TCamCameraSettingId id =
       
   635             CCamSettingConversion::Map2CameraSetting( uidValue );
       
   636 
       
   637         HandleCallbackEvent( aEvent.iErrorCode,
       
   638                              ECamCameraEventSettingsSingle,
       
   639                              ECamCameraEventClassSettings,
       
   640                              &id );
       
   641         break;
       
   642         }
       
   643       // -------------------------------
       
   644       // Flash status info
       
   645       case KUidECamEventFlashReadyUidValue:
       
   646         HandleFlashStatusEvent( aEvent.iErrorCode, ECamCameraEventFlashReady );
       
   647         break;
       
   648       case KUidECamEventFlashNotReadyUidValue:
       
   649         HandleFlashStatusEvent( aEvent.iErrorCode, ECamCameraEventFlashNotReady );
       
   650         break;
       
   651       // -------------------------------
       
   652       // Capture event
       
   653       case KUidECamEventImageCaptureEventUidValue:
       
   654           NotifyObservers(aEvent.iErrorCode,  ECamCameraEventImageCaptureEvent, EventClass( ECamCameraEventImageCaptureEvent ));
       
   655       break;
       
   656       default:
       
   657         break;
       
   658       // -------------------------------
       
   659       }
       
   660 #endif // CAMERAAPP_CAPI_V2_ADV
       
   661     }
       
   662 
       
   663 #else // CAMERAAPP_CAPI_V2
       
   664 
       
   665   // Only snapshot event recognized if old observer interface in
       
   666   // use towards CCamera. This one is then generated by CCamSnapshot.
       
   667   if( aEvent.iEventType == KUidECamEventCameraSnapshot )
       
   668     {
       
   669     HandleSnapshotEvent( aEvent.iErrorCode );
       
   670     }
       
   671   else
       
   672     {
       
   673     // ignore other events
       
   674     PRINT( _L("Camera <> CCamCameraController: Unknown event") );
       
   675     }
       
   676 #endif
       
   677   // -------------------------------------------------------
       
   678   PRINT( _L("Camera <= CCamCameraController::HandleEvent") );
       
   679   }
       
   680 
       
   681 
       
   682 
       
   683 // ---------------------------------------------------------------------------
       
   684 // ViewFinderReady
       
   685 // ---------------------------------------------------------------------------
       
   686 //
       
   687 void
       
   688 CCamCameraController::ViewFinderReady( MCameraBuffer& aCameraBuffer, TInt aError )
       
   689   {
       
   690   HandleViewfinderEvent( &aCameraBuffer, aError );
       
   691   }
       
   692 
       
   693 
       
   694 // ---------------------------------------------------------------------------
       
   695 // ImageBufferReady
       
   696 // ---------------------------------------------------------------------------
       
   697 //
       
   698 void
       
   699 CCamCameraController::ImageBufferReady( MCameraBuffer& aCameraBuffer, TInt aError )
       
   700   {
       
   701   HandleImageCaptureEvent( &aCameraBuffer, aError );
       
   702   }
       
   703 
       
   704 
       
   705 // ---------------------------------------------------------------------------
       
   706 // VideoBufferReady
       
   707 // ---------------------------------------------------------------------------
       
   708 //
       
   709 void
       
   710 CCamCameraController::VideoBufferReady( MCameraBuffer& aCameraBuffer, TInt aError )
       
   711   {
       
   712   if( KErrNone == aError )
       
   713     {
       
   714     aCameraBuffer.Release();
       
   715     }
       
   716   }
       
   717 
       
   718 
       
   719 
       
   720 #if !defined( CAMERAAPP_CAPI_V2 )
       
   721 // ===========================================================================
       
   722 // MCameraObserver
       
   723 
       
   724 
       
   725 // ---------------------------------------------------------------------------
       
   726 // ReserveComplete
       
   727 // ---------------------------------------------------------------------------
       
   728 //
       
   729 void
       
   730 CCamCameraController::ReserveComplete( TInt aError )
       
   731   {
       
   732   HandleReserveGainEvent( aError );
       
   733   }
       
   734 
       
   735 
       
   736 // ---------------------------------------------------------------------------
       
   737 // PowerOnComplete
       
   738 // ---------------------------------------------------------------------------
       
   739 //
       
   740 void
       
   741 CCamCameraController::PowerOnComplete( TInt aError )
       
   742   {
       
   743   HandlePowerOnEvent( aError );
       
   744   }
       
   745 
       
   746 
       
   747 // ---------------------------------------------------------------------------
       
   748 // ViewFinderFrameReady
       
   749 // ---------------------------------------------------------------------------
       
   750 //
       
   751 void
       
   752 CCamCameraController::ViewFinderFrameReady( CFbsBitmap& aFrame )
       
   753   {
       
   754   PRINT( _L("CamTest => CCamCameraController::ViewFinderFrameReady") );
       
   755 
       
   756   CCamBuffer* buffer = NULL;
       
   757 
       
   758   TRAPD( error, buffer = CCamBuffer::NewL( aFrame, NULL ) );
       
   759 
       
   760   // Releases buffer
       
   761   HandleViewfinderEvent( buffer, error );
       
   762 
       
   763   PRINT( _L("CamTest <= CCamCameraController::ViewFinderFrameReady") );
       
   764   }
       
   765 
       
   766 
       
   767 // ---------------------------------------------------------------------------
       
   768 // ImageReady
       
   769 // ---------------------------------------------------------------------------
       
   770 //
       
   771 void
       
   772 CCamCameraController::ImageReady( CFbsBitmap* aBitmap,
       
   773                                   HBufC8*    aData,
       
   774                                   TInt       aError )
       
   775   {
       
   776   PRINT( _L("Camera => CCamCameraController::ImageReady") );
       
   777 
       
   778   CCamBuffer* buffer = NULL;
       
   779 
       
   780   // If no error so far, wrap the data to MCameraBuffer compatible wrapper.
       
   781   // New API provides these buffers already from CCamera callbacks.
       
   782   if( KErrNone == aError )
       
   783     {
       
   784     TRAP( aError,
       
   785       {
       
   786       CleanupStack::PushL( aData   );
       
   787       CleanupStack::PushL( aBitmap );
       
   788       buffer = CCamBuffer::NewL( aBitmap, aData );
       
   789       CleanupStack::Pop( 2 );
       
   790       });
       
   791     }
       
   792 
       
   793   // Ownership taken by buffer, or destroyed by cleanup stack.
       
   794   aData   = NULL;
       
   795   aBitmap = NULL;
       
   796 
       
   797   PRINT1( _L("Camera <> status after buffer create(%d)"), aError );
       
   798 
       
   799   // Releases buffer
       
   800   HandleImageCaptureEvent( buffer, aError );
       
   801 
       
   802   PRINT( _L("Camera <= CCamCameraController::ImageReady") );
       
   803   }
       
   804 
       
   805 
       
   806 // ---------------------------------------------------------------------------
       
   807 // FrameBufferReady
       
   808 // ---------------------------------------------------------------------------
       
   809 //
       
   810 void
       
   811 CCamCameraController::FrameBufferReady( MFrameBuffer* aFrameBuffer,
       
   812                                         TInt          /*aError*/ )
       
   813   {
       
   814   // Release the buffer if one is provided to make sure
       
   815   // CCamera can reuse it.
       
   816   if( aFrameBuffer )
       
   817     {
       
   818     aFrameBuffer->Release();
       
   819     }
       
   820   }
       
   821 #endif // CAMERAAPP_CAPI_V2
       
   822 
       
   823 
       
   824 #ifdef CAMERAAPP_CAE_FOR_VIDEO
       
   825 // ===========================================================================
       
   826 // From MCamAppEngineObserver
       
   827 
       
   828 // ---------------------------------------------------------------------------
       
   829 // McaeoInitComplete
       
   830 // ---------------------------------------------------------------------------
       
   831 //
       
   832 void
       
   833 CCamCameraController::McaeoInitComplete( TInt aError )
       
   834   {
       
   835   PRINT( _L("Camera => CCamCameraController::McaeoInitComplete") );
       
   836   // Only interested on this callback, if CCamera duplicate
       
   837   // cannot be used with CAE. Otherwise we follow this event through
       
   838   // MCameraObserver(2) interface.
       
   839 #ifdef CAMERAAPP_CAE_FIX
       
   840   HandlePowerOnEvent( aError );
       
   841 #endif
       
   842   PRINT( _L("Camera <= CCamCameraController::McaeoInitComplete") );
       
   843   }
       
   844 
       
   845 // ---------------------------------------------------------------------------
       
   846 // McaeoStillPrepareComplete
       
   847 // ---------------------------------------------------------------------------
       
   848 //
       
   849 void
       
   850 CCamCameraController::McaeoStillPrepareComplete( TInt /*aError*/ )
       
   851   {
       
   852   PRINT( _L("Camera =><= CCamCameraController::McaeoStillPrepareComplete, PANIC!") );
       
   853   // Still capture not done through CCaeEngine.
       
   854   __ASSERT_DEBUG( EFalse, Panic( ECamCameraControllerCaeUnsupported ) );
       
   855   }
       
   856 
       
   857 // ---------------------------------------------------------------------------
       
   858 // McaeoVideoPrepareComplete
       
   859 //
       
   860 // This method is called asynchronously after a call has been made to
       
   861 // CCaeEngine::PrepareVideoRecordingL.
       
   862 // ---------------------------------------------------------------------------
       
   863 //
       
   864 void
       
   865 CCamCameraController::McaeoVideoPrepareComplete( TInt aError )
       
   866   {
       
   867   PRINT( _L("Camera => CCamCameraController::McaeoVideoPrepareComplete") );
       
   868 #ifdef CAMERAAPP_CAE_ERR_SIMULATION
       
   869   HandleVideoEvent( ECamCameraEventVideoInit, aError );
       
   870   // DelayCallback( ECamCameraEventVideoInit, aError, 500000 );
       
   871 #else
       
   872   if( aError == KErrWrite )
       
   873       {
       
   874       aError = KErrNone;
       
   875       }
       
   876   if( aError &&
       
   877       ( iIveCancel || ( !iIveSequenceActive && iIveRecoveryOngoing ) ) )
       
   878       // Return if error and recovering process has been started,
       
   879       // but this video prepare complete is not part of recovery
       
   880       // i.e. iIveSequenceActive is not active yet.
       
   881     {
       
   882     PRINT1( _L("Camera => CCamCameraController::McaeoVideoPrepareComplete - Ignore err %d"), aError );
       
   883     return;
       
   884     }
       
   885   HandleVideoEvent( ECamCameraEventVideoInit, aError );
       
   886 #endif // CAMERAAPP_CAE_ERR_SIMULATION
       
   887 
       
   888   PRINT( _L("Camera <= CCamCameraController::McaeoVideoPrepareComplete") );
       
   889   }
       
   890 
       
   891 // ---------------------------------------------------------------------------
       
   892 // McaeoViewFinderFrameReady
       
   893 // ---------------------------------------------------------------------------
       
   894 //
       
   895 void
       
   896 CCamCameraController::McaeoViewFinderFrameReady( CFbsBitmap& aFrame,
       
   897                                                  TInt        aError )
       
   898   {
       
   899   PRINT( _L("Camera => CCamCameraController::McaeoViewFinderFrameReady") );
       
   900   CCamBuffer* buffer = NULL;
       
   901   if( KErrNone == aError )
       
   902     {
       
   903     TRAP( aError, buffer = CCamBuffer::NewL( aFrame, NULL ) );
       
   904     }
       
   905 
       
   906   // Releases buffer if not NULL
       
   907   HandleViewfinderEvent( buffer, aError );
       
   908 
       
   909   PRINT( _L("Camera <= CCamCameraController::McaeoViewFinderFrameReady") );
       
   910   }
       
   911 
       
   912 // ---------------------------------------------------------------------------
       
   913 // McaeoSnapImageReady
       
   914 // ---------------------------------------------------------------------------
       
   915 //
       
   916 void
       
   917 CCamCameraController::McaeoSnapImageReady( const CFbsBitmap& aBitmap,
       
   918                                                  TInt        aError  )
       
   919   {
       
   920   PRINT1( _L("Camera => CCamCameraController::McaeoSnapImageReady, status: %d"), aError );
       
   921   //__ASSERT_DEBUG( EFalse, Panic( ECamCameraControllerCaeUnsupported ) );
       
   922   if(
       
   923 #ifdef CAMERAAPP_CAE_FIX
       
   924       ECamModeChangeInactive == iModeChange &&
       
   925 #endif
       
   926       IsFlagOn( iInfo.iState, ECamVideoOn )
       
   927     )
       
   928     {
       
   929     CAMERAAPP_PERF_CONTROLLER_STOP( ECamRequestSsStart );
       
   930 
       
   931     CFbsBitmap* copy( NULL );
       
   932     if( KErrNone == aError )
       
   933       {
       
   934       TRAP( aError,
       
   935         {
       
   936         copy = new (ELeave) CFbsBitmap;
       
   937         User::LeaveIfError( copy->Duplicate( aBitmap.Handle() ) );
       
   938         });
       
   939       }
       
   940 
       
   941     NotifyObservers( aError,
       
   942                      ECamCameraEventSsReady,
       
   943                      ECamCameraEventClassSsData,
       
   944                      copy );
       
   945     delete copy;
       
   946     copy = NULL;
       
   947     }
       
   948   PRINT( _L("Camera <= CCamCameraController::McaeoSnapImageReady") );
       
   949   }
       
   950 
       
   951 // ---------------------------------------------------------------------------
       
   952 // McaeoStillImageReady
       
   953 // ---------------------------------------------------------------------------
       
   954 //
       
   955 void
       
   956 CCamCameraController::McaeoStillImageReady( CFbsBitmap* /*aBitmap*/,
       
   957                                             HBufC8*     /*aData  */,
       
   958                                             TInt        /*aError */ )
       
   959   {
       
   960   // Still images are not captured through CCaeEngine.
       
   961   __ASSERT_DEBUG( EFalse, Panic( ECamCameraControllerCaeUnsupported ) );
       
   962   }
       
   963 
       
   964 // ---------------------------------------------------------------------------
       
   965 // McaeoVideoRecordingOn
       
   966 // ---------------------------------------------------------------------------
       
   967 //
       
   968 void
       
   969 CCamCameraController::McaeoVideoRecordingOn( TInt aError )
       
   970   {
       
   971   PRINT( _L("Camera => CCamCameraController::McaeoVideoRecordingOn") );
       
   972 
       
   973 #ifdef CAMERAAPP_CAE_ERR_SIMULATION
       
   974   HandleVideoEvent( ECamCameraEventVideoStart, aError );
       
   975 #else
       
   976   HandleVideoEvent( ECamCameraEventVideoStart, aError );
       
   977 #endif // CAMERAAPP_CAE_ERR_SIMULATION
       
   978 
       
   979   PRINT( _L("Camera <= CCamCameraController::McaeoVideoRecordingOn") );
       
   980 
       
   981   }
       
   982 
       
   983 // ---------------------------------------------------------------------------
       
   984 // McaeoVideoRecordingPaused
       
   985 // ---------------------------------------------------------------------------
       
   986 //
       
   987 void
       
   988 CCamCameraController::McaeoVideoRecordingPaused( TInt aError )
       
   989   {
       
   990   PRINT( _L("Camera => CCamCameraController::McaeoVideoRecordingPaused") );
       
   991 
       
   992 #ifdef CAMERAAPP_CAE_ERR_SIMULATION
       
   993   HandleVideoEvent( ECamCameraEventVideoPause, KErrUnknown );
       
   994 #else
       
   995   HandleVideoEvent( ECamCameraEventVideoPause, aError );
       
   996 #endif // CAMERAAPP_CAE_ERR_SIMULATION
       
   997 
       
   998   PRINT( _L("Camera <= CCamCameraController::McaeoVideoRecordingPaused") );
       
   999 
       
  1000   }
       
  1001 
       
  1002 // ---------------------------------------------------------------------------
       
  1003 // McaeoVideoRecordingComplete
       
  1004 // ---------------------------------------------------------------------------
       
  1005 //
       
  1006 void
       
  1007 CCamCameraController::McaeoVideoRecordingComplete( TInt aError )
       
  1008   {
       
  1009   PRINT( _L("Camera => CCamCameraController::McaeoVideoRecordingComplete") );
       
  1010 
       
  1011 #ifdef CAMERAAPP_CAE_ERR_SIMULATION
       
  1012   HandleVideoEvent( ECamCameraEventVideoStop, KErrUnknown );
       
  1013 #else
       
  1014   if( aError == KErrWrite )
       
  1015       {
       
  1016       aError = KErrNone;
       
  1017       }
       
  1018   HandleVideoEvent( ECamCameraEventVideoStop, aError );
       
  1019 #endif // CAMERAAPP_CAE_ERR_SIMULATION
       
  1020   // Change stopping mode back to default sync mode
       
  1021   if ( iAsyncVideoStopModeSupported )
       
  1022     {
       
  1023     if ( iCaeEngine )
       
  1024         {
       
  1025         iCaeEngine->SetAsyncVideoStopMode( EFalse );
       
  1026         }
       
  1027     iAsyncVideoStopModeSupported = EFalse;
       
  1028     }
       
  1029 
       
  1030   PRINT( _L("Camera <= CCamCameraController::McaeoVideoRecordingComplete") );
       
  1031 
       
  1032   }
       
  1033 
       
  1034 // ---------------------------------------------------------------------------
       
  1035 // McaeoVideoRecordingTimes
       
  1036 // ---------------------------------------------------------------------------
       
  1037 //
       
  1038 void
       
  1039 CCamCameraController::McaeoVideoRecordingTimes(
       
  1040     TTimeIntervalMicroSeconds aTimeElapsed,
       
  1041     TTimeIntervalMicroSeconds aTimeRemaining,
       
  1042     TInt aError )
       
  1043   {
       
  1044   HandleVideoTimeEvent( aError, aTimeElapsed, aTimeRemaining );
       
  1045   }
       
  1046 
       
  1047 // ---------------------------------------------------------------------------
       
  1048 // McaeoVideoRecordingStopped
       
  1049 // ---------------------------------------------------------------------------
       
  1050 //
       
  1051 void
       
  1052 CCamCameraController::McaeoVideoRecordingStopped()
       
  1053   {
       
  1054   PRINT( _L("Camera => CCamCameraController::McaeoVideoRecordingStopped") );
       
  1055 
       
  1056 #ifdef CAMERAAPP_CAE_ERR_SIMULATION
       
  1057   HandleVideoEvent( ECamCameraEventVideoAsyncStop, KErrUnknown );
       
  1058 #else
       
  1059   HandleVideoEvent( ECamCameraEventVideoAsyncStop, KErrNone );
       
  1060 #endif // CAMERAAPP_CAE_ERR_SIMULATION
       
  1061 
       
  1062   PRINT( _L("Camera <= CCamCameraController::McaeoVideoRecordingStopped") );
       
  1063   }
       
  1064 
       
  1065 #endif // CAMERAAPP_CAE_FOR_VIDEO
       
  1066 // ===========================================================================
       
  1067 // From MCamImageEncoderObserver
       
  1068 
       
  1069 // ---------------------------------------------------------------------------
       
  1070 // ImageEncoded
       
  1071 // ---------------------------------------------------------------------------
       
  1072 //
       
  1073 void
       
  1074 CCamCameraController::ImageEncoded( TInt aStatus, HBufC8* aData )
       
  1075   {
       
  1076   PRINT( _L("Camera => CCamCameraController::ImageEncoded") );
       
  1077   MCameraBuffer* buffer = NULL;
       
  1078 
       
  1079   if( KErrNone == aStatus )
       
  1080     {
       
  1081     if( aData )
       
  1082       {
       
  1083       TRAP( aStatus,
       
  1084         {
       
  1085         CleanupStack::PushL( aData );
       
  1086         buffer = CCamBuffer::NewL( NULL, aData );
       
  1087         CleanupStack::Pop( aData );
       
  1088         aData  = NULL; // ownership to buffer
       
  1089         });
       
  1090       }
       
  1091     else
       
  1092       {
       
  1093       aStatus = KErrNotFound;
       
  1094       }
       
  1095     }
       
  1096   else
       
  1097     {
       
  1098     // Just delete on errors
       
  1099     delete aData;
       
  1100     aData = NULL;
       
  1101     }
       
  1102 
       
  1103   // Takes ownership of buffer
       
  1104   HandleImageCaptureEvent( buffer, aStatus );
       
  1105   PRINT( _L("Camera <= CCamCameraController::ImageEncoded") );
       
  1106   }
       
  1107 
       
  1108 
       
  1109 // ===========================================================================
       
  1110 
       
  1111 
       
  1112 // ---------------------------------------------------------------------------
       
  1113 // AttachObserverL
       
  1114 // ---------------------------------------------------------------------------
       
  1115 //
       
  1116 void
       
  1117 CCamCameraController::AttachObserverL( const MCamCameraObserver* aObserver,
       
  1118                                        const TUint&              aInterest )
       
  1119   {
       
  1120   // Only add the observer once. NULL pointer only checked here.
       
  1121   // Observer not added, if no notifications would be sent due to
       
  1122   // event interest being ECamCameraEventClassNone.
       
  1123   if( aObserver
       
  1124    && ECamCameraEventClassNone != aInterest
       
  1125    && KErrNotFound             == iObservers.Find( aObserver )
       
  1126     )
       
  1127     {
       
  1128     // Try to add the observer to our list.
       
  1129     TInt error = iObservers.Append( aObserver );
       
  1130 
       
  1131     // If we manage to add the observer, make sure the interest info gets set.
       
  1132     if( KErrNone == error )
       
  1133       {
       
  1134       error = iObserverInterests.Append( aInterest );
       
  1135       // If we are unable to add the interest info,
       
  1136       // remove also the observer.
       
  1137       if( KErrNone != error )
       
  1138         {
       
  1139         iObservers.Remove( iObservers.Count() - 1 );
       
  1140         }
       
  1141       }
       
  1142 
       
  1143     User::LeaveIfError( error );
       
  1144     }
       
  1145   }
       
  1146 
       
  1147 // ---------------------------------------------------------------------------
       
  1148 // DetachObserver
       
  1149 // ---------------------------------------------------------------------------
       
  1150 //
       
  1151 void
       
  1152 CCamCameraController::DetachObserver( const MCamCameraObserver* aObserver )
       
  1153   {
       
  1154   if( aObserver )
       
  1155     {
       
  1156     // Ignore error if not found among observers
       
  1157     const TInt KObserverIndex( iObservers.Find( aObserver ) );
       
  1158     if( KErrNotFound != KObserverIndex )
       
  1159       {
       
  1160       iObservers.Remove( KObserverIndex );
       
  1161       iObserverInterests.Remove( KObserverIndex );
       
  1162       }
       
  1163     }
       
  1164   }
       
  1165 
       
  1166 
       
  1167 // ---------------------------------------------------------------------------
       
  1168 // RequestL
       
  1169 //
       
  1170 // Issue request for one operation.
       
  1171 // ---------------------------------------------------------------------------
       
  1172 //
       
  1173 void
       
  1174 CCamCameraController::RequestL( const TCamCameraRequestId& aRequestId )
       
  1175   {
       
  1176   PRINT1( _L("Camera => CCamCameraController::RequestL, request:[%s]"), KCamRequestNames[aRequestId] );
       
  1177   CheckEqualsL( iInfo.iBusy, ECamBusyOff,  KErrInUse );
       
  1178   SetFlags    ( iInfo.iBusy, ECamBusySingle );
       
  1179 
       
  1180   TInt proceed( ETrue );
       
  1181 
       
  1182   // If the request leaves, need to reset busy flag.
       
  1183   CleanupStack::PushL( TCleanupItem( SetNotBusy, &iInfo.iBusy ) );
       
  1184   PRINT( _L("Camera <> process request..") );
       
  1185   proceed = ProcessOneRequestL( aRequestId );
       
  1186   CleanupStack::Pop();
       
  1187 
       
  1188   // If this request will be responded through MCameraObserver(2) callback,
       
  1189   // new requests cannot be accepted until that call arrives and
       
  1190   // notification to our observers will be sent there.
       
  1191   // Otherwise the request is fully processed from our point of view,
       
  1192   // and new request can be accepted.
       
  1193   if( proceed )
       
  1194     {
       
  1195     PRINT( _L("Camera <> ..Request has no callback from CCamera, ready for new request.") );
       
  1196     // Need to clear the busy flag before notification,
       
  1197     // as observer might want to issue a new request during
       
  1198     // the notification callback.
       
  1199     ClearFlags( iInfo.iBusy, ECamBusySingle );
       
  1200 
       
  1201     if( ECamRequestVideoStop == aRequestId
       
  1202      || ECamRequestSetAsyncVideoStopMode == aRequestId
       
  1203      || ECamRequestImageCancel == aRequestId )
       
  1204       {
       
  1205       // For video stop request, callback has already happened and notification
       
  1206       // has been given. No need to do anything here.
       
  1207       }
       
  1208     else
       
  1209       {
       
  1210       // Give notification to observers
       
  1211       TCamCameraEventId event( Request2Event( aRequestId ) );
       
  1212       NotifyObservers( KErrNone, event, EventClass( event ) );
       
  1213       }
       
  1214     }
       
  1215   else
       
  1216     {
       
  1217     PRINT( _L("Camera <> ..Request has callback, waiting for it.") );
       
  1218     // Request is finalized in the MCameraObserver(2) callback.
       
  1219     }
       
  1220   PRINT( _L("Camera <= CCamCameraController::RequestL") );
       
  1221   }
       
  1222 
       
  1223 // ---------------------------------------------------------------------------
       
  1224 // DirectRequestL
       
  1225 //
       
  1226 // Issue request even when busy.
       
  1227 // ---------------------------------------------------------------------------
       
  1228 //
       
  1229 void
       
  1230 CCamCameraController::DirectRequestL( const TCamCameraRequestId& aRequestId )
       
  1231   {
       
  1232   PRINT( _L("Camera => CCamCameraController::DirectRequestL") );
       
  1233 
       
  1234   TBool notify( ETrue );
       
  1235   switch( aRequestId )
       
  1236     {
       
  1237     // -----------------------------------------------------
       
  1238     case ECamRequestPowerOff:
       
  1239     case ECamRequestRelease:
       
  1240       ProcessControlShutdownRequest( aRequestId );
       
  1241       break;
       
  1242     // -----------------------------------------------------
       
  1243     // Viewfinder
       
  1244     // This does not depend on prepare of video / image
       
  1245     // so even starting can be done during sequence.
       
  1246     case ECamRequestVfStart:
       
  1247       ProcessVfStartRequestL();
       
  1248       break;
       
  1249     case ECamRequestVfStop:
       
  1250       ProcessVfStopRequestL();
       
  1251       break;
       
  1252     case ECamRequestVfStopEcam:
       
  1253       ProcessVfStopEcamRequest();
       
  1254       notify = EFalse;
       
  1255       break;
       
  1256     case ECamRequestVfRelease:
       
  1257       ProcessVfRelaseRequest();
       
  1258       break;
       
  1259     // -----------------------------------------------------
       
  1260     // Snapshot
       
  1261     //   Just as viewfinder, this can be even started
       
  1262     //   during a sequence.
       
  1263     case ECamRequestSsStart:
       
  1264       ProcessSnapshotRequestL( ECamRequestSsStart );
       
  1265       break;
       
  1266     case ECamRequestSsStop:
       
  1267       ProcessSsStopRequest();
       
  1268       break;
       
  1269     case ECamRequestSsRelease:
       
  1270       ProcessSsReleaseRequest();
       
  1271       break;
       
  1272     // -----------------------------------------------------
       
  1273     // Image capture (cancel)
       
  1274     case ECamRequestImageCancel:
       
  1275       ProcessImageShutdownRequest( ECamRequestImageCancel );
       
  1276       notify = EFalse;
       
  1277       break;
       
  1278     // -----------------------------------------------------
       
  1279     // Start/cancel autofocus or set range
       
  1280     case ECamRequestStartAutofocus:
       
  1281     case ECamRequestCancelAutofocus:
       
  1282     case ECamRequestSetAfRange:
       
  1283       ProcessAutofocusRequestL( aRequestId );
       
  1284       break;
       
  1285     // -----------------------------------------------------
       
  1286     // Initialize image quality
       
  1287     case ECamRequestImageInit:
       
  1288       ProcessImageRequestL( ECamRequestImageInit );
       
  1289       break;
       
  1290     // -----------------------------------------------------
       
  1291     default:
       
  1292       Panic( ECamCameraControllerUnsupported );
       
  1293       break;
       
  1294     }
       
  1295 
       
  1296   if( notify )
       
  1297     {
       
  1298     TCamCameraEventId event( Request2Event( aRequestId ) );
       
  1299     NotifyObservers( KErrNone, event, EventClass( event ) );
       
  1300     }
       
  1301 
       
  1302   PRINT( _L("Camera <= CCamCameraController::DirectRequestL") );
       
  1303   }
       
  1304 
       
  1305 // ---------------------------------------------------------------------------
       
  1306 // RequestSequenceL
       
  1307 //
       
  1308 // Issue request for a sequence of operations.
       
  1309 //
       
  1310 // Operations done during the sequence will be notified with
       
  1311 // associated event codes to observers. If any errors happen during the
       
  1312 // sequence, the notification will reflect this with the status code.
       
  1313 // When sequence ends, observers will be notified with event
       
  1314 // ECamCameraEventSequenceEnd. No new requests are accepted before
       
  1315 // ECamCameraEventSequenceEnd notification is sent.
       
  1316 // ---------------------------------------------------------------------------
       
  1317 //
       
  1318 void
       
  1319 CCamCameraController
       
  1320 ::RequestSequenceL( const RCamRequestArray& aSequence )
       
  1321   {
       
  1322   PRINT( _L("Camera => CCamCameraController::RequestSequence") );
       
  1323   CheckEqualsL( iInfo.iBusy, ECamBusyOff,  KErrInUse );
       
  1324 
       
  1325   CAMERAAPP_PERF_CONTROLLER_START( ECamRequestNone );
       
  1326 
       
  1327   ClearRequestQueue();
       
  1328   iReserveTryAgainCount = KCamReserveTryAgainMaxCount;
       
  1329 
       
  1330   iSequenceArray.ReserveL( aSequence.Count() );
       
  1331   for( TInt i = 0; i < aSequence.Count(); i++ )
       
  1332     iSequenceArray.AppendL( aSequence[i] );
       
  1333 //  iSequenceArray.Compress();
       
  1334 
       
  1335   SetFlags( iInfo.iBusy, ECamBusySequence ); // Cleared in EndSequence
       
  1336   iActive->IssueRequest();
       
  1337 
       
  1338   PRINT( _L("Camera <= CCamCameraController::RequestSequence") );
       
  1339   }
       
  1340 
       
  1341 
       
  1342 // ---------------------------------------------------------------------------
       
  1343 // RequestSettingsChangeL
       
  1344 // ---------------------------------------------------------------------------
       
  1345 //
       
  1346 void
       
  1347 CCamCameraController::RequestSettingsChangeL()
       
  1348   {
       
  1349   PRINT ( _L("Camera => CCamCameraController::RequestSettingsChangeL") );
       
  1350   CheckEqualsL( iInfo.iBusy, ECamBusyOff,  KErrInUse    );
       
  1351   CheckFlagOnL( iInfo.iState, ECamReserved, KErrNotReady );
       
  1352 
       
  1353   PRINT ( _L("Camera <> Get changed settings..") );
       
  1354   ClearSettingQueue();
       
  1355   iSettingProvider.ProvidePendingSettingChangesL( iSettingArray );
       
  1356 
       
  1357   PRINT ( _L("Camera <> Start processing..") );
       
  1358   SetFlags( iInfo.iBusy, ECamBusySetting ); // Cleared in EndSequence
       
  1359   iActive->IssueRequest();
       
  1360 
       
  1361   PRINT ( _L("Camera <= CCamCameraController::RequestSettingsChangeL") );
       
  1362   }
       
  1363 
       
  1364 
       
  1365 // ---------------------------------------------------------------------------
       
  1366 // DirectRequestSettingsChangeL
       
  1367 // ---------------------------------------------------------------------------
       
  1368 //
       
  1369 void
       
  1370 CCamCameraController
       
  1371 ::DirectSettingsChangeL( const TCamCameraSettingId& aSettingId )
       
  1372   {
       
  1373   PRINT ( _L("Camera => CCamCameraController::DirectSettingsChangeL") );
       
  1374 
       
  1375   CheckFlagOnL( iInfo.iState, ECamReserved, KErrNotReady );
       
  1376 
       
  1377   TBool callback = ProcessSettingL( aSettingId );
       
  1378   // If there is a callback, do notification there.
       
  1379   if( !callback )
       
  1380     {
       
  1381     TCamCameraSettingId setting = aSettingId;
       
  1382     NotifyObservers( KErrNone,
       
  1383                      ECamCameraEventSettingsSingle,
       
  1384                      ECamCameraEventClassSettings,
       
  1385                      &setting );
       
  1386     }
       
  1387 
       
  1388   PRINT ( _L("Camera <= CCamCameraController::DirectSettingsChangeL") );
       
  1389   }
       
  1390 
       
  1391 
       
  1392 // ---------------------------------------------------------------------------
       
  1393 // CancelSequence
       
  1394 // ---------------------------------------------------------------------------
       
  1395 //
       
  1396 void
       
  1397 CCamCameraController::CancelSequence()
       
  1398   {
       
  1399   PRINT( _L("Camera => CCamCameraController::CancelSequence") );
       
  1400   if( iActive &&
       
  1401       iActive->IsActive() )
       
  1402     {
       
  1403     PRINT( _L("Camera <> iActive is active, call Cancel()..") );
       
  1404     // Results to call to iActive::DoCancel
       
  1405     // which in turn calls our EndSequence.
       
  1406     iActive->Cancel();
       
  1407     }
       
  1408 
       
  1409   // If busy flag is not set, we either had no sequence going on or
       
  1410   // iActive::DoCancel already handled calling EndSequence().
       
  1411   if( IsFlagOn( iInfo.iBusy, ECamBusySequence|ECamBusySetting ) )
       
  1412     {
       
  1413     PRINT( _L("Camera <> Busy, call EndSequence()..") );
       
  1414     // Clears busy flag, if we were processing a sequence of requests / settings.
       
  1415     // If iBusy is set because one request is on the way,
       
  1416     // we must not clear it here - when that request is processed,
       
  1417     // the flag will be cleared.
       
  1418     EndSequence( KErrCancel );
       
  1419     }
       
  1420   PRINT( _L("Camera <= CCamCameraController::CancelSequence") );
       
  1421   }
       
  1422 
       
  1423 // ---------------------------------------------------------------------------
       
  1424 // SwitchCameraL
       
  1425 // ---------------------------------------------------------------------------
       
  1426 //
       
  1427 void
       
  1428 CCamCameraController::SwitchCameraL( TInt aCameraIndex )
       
  1429   {
       
  1430   PRINT1( _L("Camera => CCamCameraController::SwitchCameraL%d"),aCameraIndex );
       
  1431   #ifdef _DEBUG
       
  1432   if( aCameraIndex == iInfo.iCurrentCamera )
       
  1433     {
       
  1434     PRINT( _L("Camera <> CCamCameraController::SwitchCameraL - Changing Secondary camera orientation") );
       
  1435     }
       
  1436   #endif // _DEBUG
       
  1437 
       
  1438   if( aCameraIndex < 0 || aCameraIndex >= CamerasAvailable() )
       
  1439     {
       
  1440     User::Leave( KErrNotSupported );
       
  1441     }
       
  1442   else
       
  1443     {
       
  1444     // -----------------------------------------------------
       
  1445     // First free old camera resources
       
  1446     if( iCamera )
       
  1447       {
       
  1448       ReleaseCurrentCamera();
       
  1449       }
       
  1450 
       
  1451     // used in CompleteSwitchCamera
       
  1452     iCurrentCameraIndex = aCameraIndex;
       
  1453 
       
  1454     // -----------------------------------------------------
       
  1455     // Then create new camera:
       
  1456     PRINT ( _L("############################################################") );
       
  1457 #ifdef CAMERAAPP_CAE_FOR_VIDEO
       
  1458 
       
  1459     PRINT1( _L("Camera <> Creating CCaeEngine, camera index: %d .."), aCameraIndex );
       
  1460     iCaeEngine = NewCaeEngineL( aCameraIndex );
       
  1461 
       
  1462 #else
       
  1463 
       
  1464     PRINT ( _L("Camera <> Note: CCamera only in use, no CCaeEngine") );
       
  1465     PRINT1( _L("Camera <> Creating CCamera, camera index: %d .."), aCameraIndex );
       
  1466     iCamera = NewCameraL( aCameraIndex );
       
  1467 
       
  1468 #endif // CAMERAAPP_CAE_FOR_VIDEO
       
  1469 
       
  1470 
       
  1471   PRINT( _L("Camera <= CCamCameraController::SwitchCameraL") );
       
  1472     }
       
  1473   }
       
  1474 // ---------------------------------------------------------------------------
       
  1475 // CompleteSwitchCameraL
       
  1476 // ---------------------------------------------------------------------------
       
  1477 //
       
  1478 void
       
  1479 CCamCameraController::CompleteSwitchCameraL()
       
  1480   {
       
  1481   PRINT( _L("Camera => CCamCameraController::CompleteSwitchCameraL") );
       
  1482   if( iCurrentCameraIndex < 0 || iCurrentCameraIndex >= CamerasAvailable() )
       
  1483     {
       
  1484     User::Leave( KErrNotSupported );
       
  1485     }
       
  1486   else if( iCurrentCameraIndex == iInfo.iCurrentCamera )
       
  1487     {
       
  1488     return;
       
  1489     }
       
  1490 
       
  1491 #ifdef CAMERAAPP_CAE_FOR_VIDEO
       
  1492   #ifdef CAMERAAPP_CAE_FIX
       
  1493     PRINT ( _L("Camera <> Creating new CCamera..") );
       
  1494     iCamera    = NewCameraL( iCurrentCameraIndex );
       
  1495   #else
       
  1496     PRINT1( _L("Camera <> Creating CCamera duplicate, camera handle: %d .."), iCaeEngine->CCameraHandle() );
       
  1497     iCamera    = NewDuplicateCameraL( iCaeEngine->CCameraHandle() );
       
  1498   #endif
       
  1499 #endif // CAMERAAPP_CAE_FOR_VIDEO
       
  1500     // Get the camera info and store current camera index.
       
  1501     // Camera index needed by GetAdvancedSettingsInfoL.
       
  1502     iCamera->CameraInfo( iCameraInfo );
       
  1503     iInfo.iCurrentCamera = iCurrentCameraIndex;
       
  1504 
       
  1505 #ifdef CAMERAAPP_CAPI_V2_ADV
       
  1506     PRINT ( _L("Camera <> Creating CCameraAdvancedSettings..") );
       
  1507     iAdvancedSettings = CCamera::CCameraAdvancedSettings::NewL( *iCamera );
       
  1508 #ifdef CAMERAAPP_CAPI_V2_IP
       
  1509     if( KPrimaryCameraIndex == iInfo.iCurrentCamera )
       
  1510       {
       
  1511       // Support only for primary camera.
       
  1512       // Ignore error in instantiation: If NewL leaves, there's no
       
  1513       // support for Image Processing available. Report error to client
       
  1514       // if settings requiring it are used.
       
  1515       PRINT ( _L("Camera <> Create CCameraImageProcessing..") );
       
  1516       TRAP_IGNORE( iImageProcessor = CCamera::CCameraImageProcessing::NewL( *iCamera ) );
       
  1517       PRINT1( _L("Camera <> Image Processor pointer: %d"), iImageProcessor );
       
  1518       }
       
  1519 #endif // CAMERAAPP_CAPI_V2_IP
       
  1520 
       
  1521     // Get info on CCameraAdvancedSettings and CCameraImageProcessing
       
  1522     // support for several setting. Not supported settings will not
       
  1523     // cause this method to leave, only more serious errors.
       
  1524     GetAdvancedSettingsInfoL();
       
  1525 
       
  1526     PRINT ( _L("Camera <> Get i/f MCameraOrientation..") )
       
  1527     iCustomInterfaceOrientation =
       
  1528       static_cast <MCameraOrientation*>(
       
  1529   	    iCamera->CustomInterface( KCameraOrientationUid ) );
       
  1530     PRINT1( _L("Camera <> Orientation custom i/f pointer:%d"), iCustomInterfaceOrientation );
       
  1531     
       
  1532     iCustomInterfaceUseCaseHint =
       
  1533       static_cast <MCameraUseCaseHint*>(
       
  1534   	    iCamera->CustomInterface( KCameraUseCaseHintUid ) );
       
  1535     PRINT1( _L("Camera <> UseCaseHint custom i/f pointer:%d"), iCustomInterfaceUseCaseHint );
       
  1536     
       
  1537     
       
  1538     
       
  1539 
       
  1540 #endif // CAMERAAPP_CAPI_V2_ADV
       
  1541 
       
  1542     PRINT ( _L("Camera <> ..done") );
       
  1543     PRINT ( _L("############################################################") );
       
  1544 
       
  1545     // -----------------------------------------------------
       
  1546 #ifdef _DEBUG
       
  1547     PrintCameraInfo();
       
  1548 #endif
       
  1549     // -----------------------------------------------------
       
  1550   PRINT( _L("Camera <= CCamCameraController::CompleteSwitchCameraL") );
       
  1551   }
       
  1552 
       
  1553 
       
  1554 // ---------------------------------------------------------------------------
       
  1555 // SetOrientationModeL
       
  1556 // ---------------------------------------------------------------------------
       
  1557 //
       
  1558 void
       
  1559 CCamCameraController::SetOrientationModeL( TInt aOrientation )
       
  1560   {
       
  1561   PRINT1( _L("Camera => CCamCameraController::SetOrientationModeL %d"), aOrientation );
       
  1562 #ifdef CAMERAAPP_CAE_FOR_VIDEO
       
  1563     PRINT( _L("Camera <> CCameraController: Get i/f MUIOrientationOverride from iCaeEngine..") )
       
  1564     iCustomInterfaceUIOrientationOverride =
       
  1565       static_cast <MCameraUIOrientationOverride*>(
       
  1566   	    iCaeEngine->CustomInterface( KCameraUIOrientationOverrideUid ) );
       
  1567 #else
       
  1568     PRINT( _L("Camera <> CCameraController: Get i/f MUIOrientationOverride from iCamera..") )
       
  1569     iCustomInterfaceUIOrientationOverride =
       
  1570       static_cast <MCameraUIOrientationOverride*>(
       
  1571   	    iCamera->CustomInterface( KCameraUIOrientationOverrideUid ) );
       
  1572 #endif // CAMERAAPP_CAE_FOR_VIDEO
       
  1573 
       
  1574     PRINT1( _L("Camera <> OrientationOverride custom i/f pointer:%d"), iCustomInterfaceUIOrientationOverride );
       
  1575     TRAP_IGNORE(iCustomInterfaceUIOrientationOverride->SetOrientationModeL( aOrientation ));
       
  1576 
       
  1577   PRINT( _L("Camera <= CCamCameraController::SetOrientationModeL") );
       
  1578   }
       
  1579 
       
  1580 // ---------------------------------------------------------------------------
       
  1581 // CamerasAvailable <<static>>
       
  1582 // ---------------------------------------------------------------------------
       
  1583 //
       
  1584 TInt
       
  1585 CCamCameraController::CamerasAvailable()
       
  1586   {
       
  1587 #ifndef CAMERAAPP_CAPI_EMULATOR
       
  1588   return CCamera::CamerasAvailable();
       
  1589 #else
       
  1590   // Temporary
       
  1591   return 2;
       
  1592 #endif
       
  1593   }
       
  1594 
       
  1595 // ---------------------------------------------------------------------------
       
  1596 // CameraHandle
       
  1597 // ---------------------------------------------------------------------------
       
  1598 //
       
  1599 TInt
       
  1600 CCamCameraController::CameraHandle()
       
  1601   {
       
  1602   if( iCamera )
       
  1603     return iCamera->Handle();
       
  1604   else
       
  1605     return KNullHandle;
       
  1606   }
       
  1607 
       
  1608 
       
  1609 // ---------------------------------------------------------------------------
       
  1610 // CameraInfo
       
  1611 // ---------------------------------------------------------------------------
       
  1612 //
       
  1613 const TCameraInfo&
       
  1614 CCamCameraController::CameraInfo() const
       
  1615   {
       
  1616   return iCameraInfo;
       
  1617   }
       
  1618 
       
  1619 // ---------------------------------------------------------------------------
       
  1620 // ControllerInfo
       
  1621 // ---------------------------------------------------------------------------
       
  1622 //
       
  1623 const TCamControllerInfo&
       
  1624 CCamCameraController::ControllerInfo() const
       
  1625   {
       
  1626   return iInfo;
       
  1627   }
       
  1628 
       
  1629 // ---------------------------------------------------------------------------
       
  1630 //
       
  1631 // ---------------------------------------------------------------------------
       
  1632 //
       
  1633 TUint
       
  1634 CCamCameraController::State() const
       
  1635   {
       
  1636   return iInfo.iState;
       
  1637   }
       
  1638 
       
  1639 // ---------------------------------------------------------------------------
       
  1640 //
       
  1641 // ---------------------------------------------------------------------------
       
  1642 //
       
  1643 TCamViewfinderMode
       
  1644 CCamCameraController::ViewfinderMode()  const
       
  1645   {
       
  1646   return iInfo.iVfMode;
       
  1647   }
       
  1648 
       
  1649 // ---------------------------------------------------------------------------
       
  1650 //
       
  1651 // ---------------------------------------------------------------------------
       
  1652 //
       
  1653 TCamCameraTriState
       
  1654 CCamCameraController::ViewfinderState() const
       
  1655   {
       
  1656   return iInfo.iVfState;
       
  1657   }
       
  1658 
       
  1659 
       
  1660 // ---------------------------------------------------------------------------
       
  1661 //
       
  1662 // ---------------------------------------------------------------------------
       
  1663 //
       
  1664 TCamCameraTriState
       
  1665 CCamCameraController::SnapshotState() const
       
  1666   {
       
  1667   return iInfo.iSsState;
       
  1668   }
       
  1669 
       
  1670 
       
  1671 // ---------------------------------------------------------------------------
       
  1672 //
       
  1673 // ---------------------------------------------------------------------------
       
  1674 //
       
  1675 TCamCameraReadyState
       
  1676 CCamCameraController::FlashState() const
       
  1677   {
       
  1678   TCamCameraReadyState state = ECamUnknown;
       
  1679 
       
  1680 #ifdef CAMERAAPP_CAPI_V2_ADV
       
  1681   if( iAdvancedSettings )
       
  1682     {
       
  1683     TBool ready       = EFalse;
       
  1684     TInt  queryStatus = iAdvancedSettings->IsFlashReady( ready );
       
  1685 
       
  1686     if( KErrNone == queryStatus )
       
  1687       {
       
  1688       state = ready ? ECamReady : ECamNotReady;
       
  1689       }
       
  1690     }
       
  1691 #endif // CAMERAAPP_CAPI_V2_ADV
       
  1692   return state;
       
  1693   }
       
  1694 
       
  1695 
       
  1696 
       
  1697 // ---------------------------------------------------------------------------
       
  1698 // GetCameraSettingValueL
       
  1699 // ---------------------------------------------------------------------------
       
  1700 //
       
  1701 void
       
  1702 CCamCameraController
       
  1703 ::GetCameraSettingValueL( const TCamCameraSettingId& aSettingId,
       
  1704                           TAny* aSettingData )
       
  1705   {
       
  1706   PRINT( _L("Camera => CCamCameraController::GetCameraSettingValueL") );
       
  1707   CheckNonNullL( aSettingData, KErrArgument );
       
  1708 
       
  1709   switch( aSettingId )
       
  1710     {
       
  1711     // -----------------------------------------------------
       
  1712     case ECameraSettingFlash:
       
  1713     case ECameraUserSceneSettingFlash:
       
  1714       {
       
  1715       CCamera::TFlash* flash = static_cast<CCamera::TFlash*>( aSettingData );
       
  1716 #ifdef CAMERAAPP_CAE_FIX
       
  1717       if( iCaeInUse )
       
  1718         *flash = iCaeEngine->FlashMode();
       
  1719       else
       
  1720 #endif
       
  1721         {
       
  1722         *flash = iCamera->Flash();
       
  1723         }
       
  1724       break;
       
  1725       }
       
  1726     // -----------------------------------------------------
       
  1727     case ECameraSettingExposure:
       
  1728     case ECameraUserSceneSettingExposure:
       
  1729       {
       
  1730       TPckgBuf<TCamSettingDataExposure>* exposure =
       
  1731           static_cast<TPckgBuf<TCamSettingDataExposure>*>( aSettingData );
       
  1732 #ifdef CAMERAAPP_CAE_FIX
       
  1733       if( iCaeInUse )
       
  1734         (*exposure)().iExposureMode = iCaeEngine->ExposureMode();
       
  1735       else
       
  1736 #endif // CAMERAAPP_CAE_FIX
       
  1737         {
       
  1738   #ifdef CAMERAAPP_CAPI_V2_ADV
       
  1739         (*exposure)().iExposureMode = iAdvancedSettings->ExposureMode();
       
  1740         (*exposure)().iExposureStep = iAdvancedSettings->ExposureCompensationStep();
       
  1741   #else
       
  1742         (*exposure)().iExposureMode = iCamera->Exposure();
       
  1743   #endif
       
  1744         }
       
  1745       break;
       
  1746       }
       
  1747     // -----------------------------------------------------
       
  1748 #ifdef CAMERAAPP_CAPI_V2_ADV
       
  1749     case ECameraSettingLightSensitivity:
       
  1750     case ECameraUserSceneSettingLightSensitivity:
       
  1751       {
       
  1752       TInt* iso = static_cast<TInt*>( aSettingData );
       
  1753       *iso = iAdvancedSettings->IsoRate();
       
  1754       break;
       
  1755       }
       
  1756     case ECameraSettingContAF:
       
  1757       {
       
  1758       TInt* contAF = static_cast<TInt*>( aSettingData );
       
  1759       *contAF = iAdvancedSettings->AutoFocusType() &  //bitwise
       
  1760                 CAS::EAutoFocusTypeContinuous;
       
  1761       break;
       
  1762       }
       
  1763 #endif
       
  1764     // -----------------------------------------------------
       
  1765     case ECameraSettingWhiteBalance:
       
  1766     case ECameraUserSceneSettingWhiteBalance:
       
  1767       {
       
  1768       TPckgBuf<TCamSettingDataWhiteBalance>* wb =
       
  1769           static_cast<TPckgBuf<TCamSettingDataWhiteBalance>*>( aSettingData );
       
  1770 
       
  1771 #ifdef CAMERAAPP_CAE_FIX
       
  1772       if( iCaeInUse )
       
  1773         (*wb)().iWhiteBalanceMode = iCaeEngine->WhiteBalanceMode();
       
  1774       else
       
  1775 #endif // CAMERAAPP_CAE_FIX
       
  1776         {
       
  1777         (*wb)().iWhiteBalanceMode = iCamera->WhiteBalance();
       
  1778         }
       
  1779       break;
       
  1780       }
       
  1781     // -----------------------------------------------------
       
  1782 #ifdef CAMERAAPP_CAPI_V2_IP
       
  1783     case ECameraSettingColourEffect:
       
  1784     case ECameraUserSceneSettingColourEffect:
       
  1785       {
       
  1786       CheckNonNullL( iImageProcessor, KErrNotSupported );
       
  1787 
       
  1788       CIP::TEffect* effect = static_cast<CIP::TEffect*>( aSettingData );
       
  1789       *effect =
       
  1790         (CIP::TEffect)
       
  1791           iImageProcessor->TransformationValue( KUidECamEventImageProcessingEffect );
       
  1792       break;
       
  1793       }
       
  1794     // -----------------------------------------------------
       
  1795     case ECameraSettingSharpness:
       
  1796     case ECameraUserSceneSettingSharpness:
       
  1797       {
       
  1798       CheckNonNullL( iImageProcessor, KErrNotSupported );
       
  1799 
       
  1800       TInt* sharpness = static_cast<TInt*>( aSettingData );
       
  1801       *sharpness = iImageProcessor->TransformationValue( KUidECamEventImageProcessingAdjustSharpness );
       
  1802       break;
       
  1803       }
       
  1804 #endif
       
  1805     // -----------------------------------------------------
       
  1806     case ECameraSettingDigitalZoom:
       
  1807       {
       
  1808       TInt* zoom = static_cast<TInt*>( aSettingData );
       
  1809 #ifdef CAMERAAPP_CAE_FIX
       
  1810       if( iCaeInUse )
       
  1811         *zoom = iCaeEngine->ZoomValue();
       
  1812       else
       
  1813 #endif
       
  1814         {
       
  1815         // Zoom step despite the misleading method name.
       
  1816         *zoom = iCamera->ZoomFactor();
       
  1817         }
       
  1818       break;
       
  1819       }
       
  1820     // -----------------------------------------------------
       
  1821 #ifdef CAMERAAPP_CAPI_V2_ADV
       
  1822     case ECameraSettingOpticalZoom:
       
  1823       {
       
  1824       TInt* zoom = static_cast<TInt*>( aSettingData );
       
  1825       *zoom = iAdvancedSettings->OpticalZoom();
       
  1826       break;
       
  1827       }
       
  1828 #endif
       
  1829     // -----------------------------------------------------
       
  1830 #ifdef CAMERAAPP_CAE_FOR_VIDEO
       
  1831     case ECameraSettingFileMaxSize:
       
  1832       {
       
  1833       if( iCaeEngine )
       
  1834         {
       
  1835         TInt* bytes = static_cast<TInt*>( aSettingData );
       
  1836         *bytes = iCaeEngine->VideoClipMaxSize();
       
  1837         }
       
  1838       else
       
  1839         {
       
  1840         User::Leave( KErrNotReady );
       
  1841         }
       
  1842       break;
       
  1843       }
       
  1844     // -----------------------------------------------------
       
  1845     case ECameraSettingFileName:
       
  1846       {
       
  1847       User::Leave( KErrNotSupported );
       
  1848       break;
       
  1849       }
       
  1850     // -----------------------------------------------------
       
  1851     case ECameraSettingAudioMute:
       
  1852       {
       
  1853       if( iCaeEngine )
       
  1854         {
       
  1855         TBool* mute = static_cast<TBool*>( aSettingData );
       
  1856         *mute = iCaeEngine->VideoAudio();
       
  1857         }
       
  1858       else
       
  1859         {
       
  1860         User::Leave( KErrNotReady );
       
  1861         }
       
  1862       break;
       
  1863       }
       
  1864 #endif
       
  1865     // -----------------------------------------------------
       
  1866     case ECameraSettingFacetracking:
       
  1867       {
       
  1868       if( iCustomInterfaceFaceTracking )
       
  1869         {
       
  1870         TBool* ftOn = static_cast<TBool*>( aSettingData );
       
  1871         *ftOn = iCustomInterfaceFaceTracking->FaceTrackingOn();
       
  1872         PRINT1( _L("Camera <> facetracking setting: %d"), *ftOn )
       
  1873         }
       
  1874       else
       
  1875         {
       
  1876         User::Leave( KErrNotReady );
       
  1877         }
       
  1878       break;
       
  1879       }
       
  1880     // -----------------------------------------------------
       
  1881     case ECameraSettingBrightness:
       
  1882     case ECameraUserSceneSettingBrightness:
       
  1883       {
       
  1884       CCamera::TBrightness* brightness =
       
  1885           static_cast<CCamera::TBrightness*>( aSettingData );
       
  1886 #ifdef CAMERAAPP_CAE_FIX
       
  1887       if( iCaeInUse )
       
  1888         *brightness = (CCamera::TBrightness)iCaeEngine->Brightness();
       
  1889       else
       
  1890 #endif
       
  1891         *brightness = (CCamera::TBrightness)iCamera->Brightness();
       
  1892       break;
       
  1893       }
       
  1894     // -----------------------------------------------------
       
  1895     case ECameraSettingContrast:
       
  1896     case ECameraUserSceneSettingContrast:
       
  1897       {
       
  1898       CCamera::TContrast* contrast =
       
  1899           static_cast<CCamera::TContrast*>( aSettingData );
       
  1900 #ifdef CAMERAAPP_CAE_FIX
       
  1901       if( iCaeInUse )
       
  1902         *contrast = (CCamera::TContrast)iCaeEngine->Contrast();
       
  1903       else
       
  1904 #endif
       
  1905         *contrast = (CCamera::TContrast)iCamera->Contrast();
       
  1906       break;
       
  1907       }
       
  1908 #ifdef CAMERAAPP_CAPI_V2_ADV
       
  1909     // -----------------------------------------------------
       
  1910     case ECameraSettingStabilization:
       
  1911       {
       
  1912       TPckgBuf<TCamSettingDataStabilization>* pckg =
       
  1913           static_cast<TPckgBuf<TCamSettingDataStabilization>*>( aSettingData );
       
  1914       TCamSettingDataStabilization& stabilization = (*pckg)();
       
  1915 
       
  1916       stabilization.iMode       = iAdvancedSettings->StabilizationMode();
       
  1917       stabilization.iEffect     = iAdvancedSettings->StabilizationEffect();
       
  1918       stabilization.iComplexity = iAdvancedSettings->StabilizationComplexity();
       
  1919       break;
       
  1920       }
       
  1921 #endif // CAMERAAPP_CAPI_V2_ADV
       
  1922     // -----------------------------------------------------
       
  1923     // Image orientation
       
  1924     case ECameraSettingOrientation:
       
  1925       {
       
  1926       CheckNonNullL( iCustomInterfaceOrientation, KErrNotSupported );
       
  1927 
       
  1928       MCameraOrientation::TOrientation* orientation =
       
  1929           static_cast<MCameraOrientation::TOrientation*>( aSettingData );
       
  1930 
       
  1931       *orientation = iCustomInterfaceOrientation->Orientation();
       
  1932       break;
       
  1933       }
       
  1934     // -----------------------------------------------------
       
  1935     case ECameraSettingFocusRange:
       
  1936     default:
       
  1937       {
       
  1938 #ifndef CAMERAAPP_EMULATOR_BUILD
       
  1939       PRINT ( _L("Camera <> Not supported, LEAVE!") );
       
  1940       User::Leave( KErrNotSupported );
       
  1941 #endif // not CAMERAAPP_EMULATOR_BUILD
       
  1942       break;
       
  1943       }
       
  1944     // -------------------------------
       
  1945     }
       
  1946   }
       
  1947 
       
  1948 
       
  1949 
       
  1950 // ---------------------------------------------------------------------------
       
  1951 // ProcessNextRequestL
       
  1952 //
       
  1953 // Called from iActive::RunL.
       
  1954 // If the request made to CCamera has a callback, more calls from iActive
       
  1955 // will not be requested here, but in those callbacks.
       
  1956 // Leave here will cause iActive to call EndSequence with the error code.
       
  1957 // ---------------------------------------------------------------------------
       
  1958 //
       
  1959 TInt
       
  1960 CCamCameraController::ProcessNextRequestL()
       
  1961   {
       
  1962   PRINT( _L("Camera => CCamCameraController::ProcessNextRequestL") );
       
  1963   TInt readyForNextStep( EFalse );
       
  1964 
       
  1965 
       
  1966 #ifdef CAMERAAPP_CAE_FIX
       
  1967   // -------------------------------------------------------
       
  1968   if( ECamModeChangeInactive != iModeChange )
       
  1969     {
       
  1970     readyForNextStep = ProceedModeSwitch();
       
  1971     }
       
  1972   else
       
  1973 #endif // CAMERAAPP_CAE_FIX
       
  1974 
       
  1975   // -------------------------------------------------------
       
  1976   if( IsFlagOn( iInfo.iBusy, ECamBusySetting ) )
       
  1977     {
       
  1978     PRINT( _L("Camera <> Settings ongoing") );
       
  1979 
       
  1980     iSettingIndex++;
       
  1981     if( iSettingIndex < iSettingArray.Count() )
       
  1982       {
       
  1983       const TCamCameraSettingId& setting( iSettingArray[iSettingIndex] );
       
  1984 
       
  1985       readyForNextStep = ProcessSettingL( setting );
       
  1986       // No notification sent at the moment per setting.
       
  1987       }
       
  1988     else
       
  1989       {
       
  1990       EndSequence( KErrNone );
       
  1991       }
       
  1992     }
       
  1993   // -------------------------------------------------------
       
  1994   else if( IsFlagOn( iInfo.iBusy, ECamBusySequence ) )
       
  1995     {
       
  1996     PRINT( _L("Camera <> Sequence ongoing") );
       
  1997 
       
  1998     iSequenceIndex++;
       
  1999     if( iSequenceIndex < iSequenceArray.Count() )
       
  2000       {
       
  2001       const TCamCameraRequestId& requestId( iSequenceArray[iSequenceIndex] );
       
  2002 
       
  2003       PRINT( _L("Camera <> process request..") );
       
  2004       // If this request will be responded through MCameraObserver(2) callback,
       
  2005       // iActive will be requested a new callback there and also
       
  2006       // the notification to our observers will be sent there.
       
  2007       // Otherwise we do both of those right away.
       
  2008       readyForNextStep = ProcessOneRequestL( requestId );
       
  2009 
       
  2010       if( readyForNextStep )
       
  2011         {
       
  2012         if( ECamRequestVideoStop == requestId
       
  2013          || ECamRequestImageCancel == requestId )
       
  2014           {
       
  2015           // For video stop request, callback has already happened and notification
       
  2016           // has been given. No need to do anything here.
       
  2017           PRINT( _L("Camera <> CCamCameraController::RequestL .. Skipping commmon notification, is done already.") );
       
  2018           }
       
  2019         else
       
  2020           {
       
  2021           TCamCameraEventId event( Request2Event( requestId ) );
       
  2022           NotifyObservers( KErrNone, event, EventClass( event ) );
       
  2023           }
       
  2024         }
       
  2025       }
       
  2026     else
       
  2027       {
       
  2028       PRINT( _L("Camera <> Sequence end detected") );
       
  2029       EndSequence( KErrNone );
       
  2030       }
       
  2031     }
       
  2032   // -------------------------------------------------------
       
  2033   else
       
  2034     {
       
  2035     PRINT( _L("Camera <> Nothing active!! PANIC") );
       
  2036     __ASSERT_DEBUG( EFalse, Panic( ECamCameraControllerCorrupt ) );
       
  2037     }
       
  2038   // -------------------------------------------------------
       
  2039 
       
  2040   PRINT1( _L("Camera <= CCamCameraController::ProcessNextRequestL, more calls now:%d"), readyForNextStep );
       
  2041   return readyForNextStep;
       
  2042   }
       
  2043 
       
  2044 
       
  2045 
       
  2046 // ---------------------------------------------------------------------------
       
  2047 // ProcessSettingL
       
  2048 // ---------------------------------------------------------------------------
       
  2049 //
       
  2050 TInt
       
  2051 CCamCameraController::ProcessSettingL( const TCamCameraSettingId& aSettingId )
       
  2052   {
       
  2053   PRINT1( _L("Camera => CCamCameraController::ProcessSettingL [%s]"),
       
  2054           KCameraSettingNames[aSettingId] );
       
  2055 
       
  2056   TInt callback( EFalse );
       
  2057   switch( aSettingId )
       
  2058     {
       
  2059     // -------------------------------
       
  2060     case ECameraSettingCaptureLimit:
       
  2061       {
       
  2062       ProcessCaptureLimitSettingL();
       
  2063       break;
       
  2064       }
       
  2065     // -------------------------------
       
  2066     case ECameraSettingFlash:
       
  2067     case ECameraUserSceneSettingFlash:
       
  2068       {
       
  2069       if ( IsFlagOn( iInfo.iState, ECamVideoOn ) )
       
  2070         {
       
  2071         CCamera::TFlash flash( CCamera::EFlashNone );
       
  2072         TCamFlashId currentFlashSetting( ECamFlashOff );
       
  2073         // Video light setting has values ECamFlashOff/ECamFlashForced
       
  2074         iSettingProvider.ProvideCameraSettingL( aSettingId,
       
  2075                                                 &currentFlashSetting );
       
  2076         PRINT2( _L("Camera => Video Flash now = %d, new = %d"),
       
  2077                                        iCamera->Flash(), currentFlashSetting );
       
  2078         // Camera uses values EFlashNone/EFlashVideoLight
       
  2079         flash = (currentFlashSetting == ECamFlashOff)?
       
  2080                 CCamera::EFlashNone:CCamera::EFlashVideoLight;
       
  2081         PRINT1( _L("Camera => iCamera->SetFlashL( %d )"), flash );
       
  2082         iCamera->SetFlashL( flash );
       
  2083         }
       
  2084       else
       
  2085         {
       
  2086         // Still image flash
       
  2087         CCamera::TFlash flash( CCamera::EFlashAuto );
       
  2088       iSettingProvider.ProvideCameraSettingL( aSettingId, &flash );
       
  2089 #ifdef CAMERAAPP_CAE_FIX
       
  2090       if( iCaeInUse )
       
  2091             {
       
  2092             iCaeEngine->SetFlashModeL( flash );
       
  2093             }
       
  2094       else
       
  2095 #endif
       
  2096         {
       
  2097         if( iCamera->Flash() != flash )
       
  2098           {
       
  2099           iCamera->SetFlashL( flash );
       
  2100 #ifdef CAMERAAPP_CAPI_V2
       
  2101           callback = ETrue;
       
  2102 #endif
       
  2103           }
       
  2104         }
       
  2105          }
       
  2106       break;
       
  2107       }
       
  2108     // -------------------------------
       
  2109     case ECameraSettingExposure:
       
  2110     case ECameraUserSceneSettingExposure:
       
  2111       {
       
  2112       TPckgBuf<TCamSettingDataExposure> params;
       
  2113       iSettingProvider.ProvideCameraSettingL( aSettingId, &params );
       
  2114 #ifdef CAMERAAPP_CAE_FIX
       
  2115       if( iCaeInUse )
       
  2116         iCaeEngine->SetExposureModeL( params().iExposureMode );
       
  2117       else
       
  2118 #endif // CAMERAAPP_CAE_FIX
       
  2119         {
       
  2120 #ifdef CAMERAAPP_CAPI_V2_ADV
       
  2121       PRINT( _L("Calling iAdvancedSettings->SetExposureMode..") );
       
  2122       const CCamera::TExposure& mode = params().iExposureMode;
       
  2123       // Zero value is default and always supported
       
  2124       // (CCamera::EExposureAuto)
       
  2125       if( mode == CCamera::EExposureAuto || mode & iAdvancedSettingInfo.iEvModesSupport )
       
  2126         {
       
  2127         iAdvancedSettings->SetExposureMode( mode );
       
  2128         // iCamera->SetExposureL( mode );
       
  2129 
       
  2130         TInt step = ResolveEvStep( params().iExposureStep );
       
  2131         // Value needs to be multiplied by KECamFineResolutionFactor.
       
  2132         // Setting provider does this for us.
       
  2133         PRINT( _L("Calling iAdvancedSettings->SetExposureCompensationStep..") );
       
  2134         iAdvancedSettings->SetExposureCompensationStep( step );
       
  2135 
       
  2136         callback = ETrue;
       
  2137         }
       
  2138       else
       
  2139         {
       
  2140         User::Leave( KErrNotSupported );
       
  2141         }
       
  2142 #else
       
  2143       iCamera->SetExposureL( params().iExposureMode );
       
  2144 #endif // CAMERAAPP_CAPI_V2_ADV
       
  2145         }
       
  2146       break;
       
  2147       }
       
  2148     // -------------------------------
       
  2149 #ifdef CAMERAAPP_CAPI_V2_ADV
       
  2150     case ECameraSettingLightSensitivity:
       
  2151     case ECameraUserSceneSettingLightSensitivity:
       
  2152       {
       
  2153       TInt iso( 0 );
       
  2154       RArray<TInt> ISOarray;
       
  2155       CleanupClosePushL( ISOarray );
       
  2156       iAdvancedSettings->GetSupportedIsoRatesL( ISOarray );
       
  2157       iSettingProvider.SetSupportedISORatesL( ISOarray );
       
  2158       iSettingProvider.ProvideCameraSettingL( aSettingId, &iso );
       
  2159       callback = ETrue;
       
  2160       CleanupStack::PopAndDestroy( &ISOarray );
       
  2161 
       
  2162       PRINT1( _L("Camera <> Setting ISO rate to: %d"), iso );
       
  2163       if( !iso )
       
  2164         {
       
  2165         // ISO Auto
       
  2166         iAdvancedSettings->SetISORateL(
       
  2167                 CCamera::CCameraAdvancedSettings::EISOAutoUnPrioritised, iso );
       
  2168         }
       
  2169       else if( IsSupportedValue( iso,
       
  2170                                  iAdvancedSettingInfo.iIsoRatesSupport,
       
  2171                                  EDiscreteSteps ) )
       
  2172         {
       
  2173         // Selected ISO rate
       
  2174         iAdvancedSettings->SetISORateL(
       
  2175                 CCamera::CCameraAdvancedSettings::EISOManual, iso );
       
  2176         }
       
  2177       else
       
  2178         {
       
  2179         User::Leave( KErrNotSupported );
       
  2180         }
       
  2181       break;
       
  2182       }
       
  2183 #endif
       
  2184     // -------------------------------
       
  2185     case ECameraSettingWhiteBalance:
       
  2186     case ECameraUserSceneSettingWhiteBalance:
       
  2187       {
       
  2188       TPckgBuf<TCamSettingDataWhiteBalance> params;
       
  2189       iSettingProvider.ProvideCameraSettingL( aSettingId, &params );
       
  2190 #ifdef CAMERAAPP_CAE_FIX
       
  2191       if( iCaeInUse )
       
  2192         iCaeEngine->SetWhiteBalanceModeL( params().iWhiteBalanceMode );
       
  2193       else
       
  2194 #endif // CAMERAAPP_CAE_FIX
       
  2195         {
       
  2196         iCamera->SetWhiteBalanceL( params().iWhiteBalanceMode );
       
  2197 #ifdef CAMERAAPP_CAPI_V2
       
  2198         callback = ETrue;
       
  2199 #endif
       
  2200         }
       
  2201       break;
       
  2202       }
       
  2203     // -------------------------------
       
  2204 #ifdef CAMERAAPP_CAPI_V2_IP
       
  2205     case ECameraSettingColourEffect:
       
  2206     case ECameraUserSceneSettingColourEffect:
       
  2207       {
       
  2208       CheckNonNullL( iImageProcessor, KErrNotSupported );
       
  2209       CIP::TEffect effect( CIP::EEffectNone );
       
  2210       iSettingProvider.ProvideCameraSettingL( aSettingId, &effect );
       
  2211 
       
  2212       if( IsSupportedValue( effect,
       
  2213                             iAdvancedSettingInfo.iColourEffectSupport,
       
  2214                             iAdvancedSettingInfo.iColourEffectValueInfo ) )
       
  2215         {
       
  2216         iImageProcessor->SetTransformationValue( KUidECamEventImageProcessingEffect, effect );
       
  2217         callback = ETrue;
       
  2218         }
       
  2219       else
       
  2220         User::Leave( KErrNotSupported );
       
  2221       break;
       
  2222       }
       
  2223     // -------------------------------
       
  2224     case ECameraSettingSharpness:
       
  2225     case ECameraUserSceneSettingSharpness:
       
  2226       {
       
  2227       CheckNonNullL( iImageProcessor, KErrNotSupported );
       
  2228       TInt sharpness( 0 );
       
  2229       iSettingProvider.ProvideCameraSettingL( aSettingId, &sharpness );
       
  2230 
       
  2231       if( IsSupportedValue( sharpness,
       
  2232                             iAdvancedSettingInfo.iSharpnessSupport,
       
  2233                             iAdvancedSettingInfo.iSharpnessValueInfo ) )
       
  2234         {
       
  2235         iImageProcessor->SetTransformationValue( KUidECamEventImageProcessingAdjustSharpness, sharpness );
       
  2236         callback = ETrue;
       
  2237         }
       
  2238       else
       
  2239         User::Leave( KErrNotSupported );
       
  2240       break;
       
  2241       }
       
  2242 #endif // CAMERAAPP_CAPI_V2_IP
       
  2243     // -------------------------------
       
  2244     case ECameraSettingBrightness:
       
  2245     case ECameraUserSceneSettingBrightness:
       
  2246       {
       
  2247       CCamera::TBrightness brightness( CCamera::EBrightnessAuto );
       
  2248       iSettingProvider.ProvideCameraSettingL( aSettingId, &brightness );
       
  2249       iCamera->SetBrightnessL( brightness );
       
  2250       break;
       
  2251       }
       
  2252     // -------------------------------
       
  2253     case ECameraSettingContrast:
       
  2254     case ECameraUserSceneSettingContrast:
       
  2255       {
       
  2256       CCamera::TContrast contrast( CCamera::EContrastAuto );
       
  2257       iSettingProvider.ProvideCameraSettingL( aSettingId, &contrast );
       
  2258       iCamera->SetContrastL( contrast );
       
  2259       break;
       
  2260       }
       
  2261     // -------------------------------
       
  2262     case ECameraSettingDigitalZoom:
       
  2263       {
       
  2264       TInt zoom( 0 );
       
  2265       iSettingProvider.ProvideCameraSettingL( aSettingId, &zoom );
       
  2266       PRINT1( _L("Camera <> Setting digital zoom step to: %d"), zoom );
       
  2267 #ifdef CAMERAAPP_CAE_FIX
       
  2268       if( iCaeInUse )
       
  2269         iCaeEngine->SetZoomValueL( zoom );
       
  2270       else
       
  2271 #endif
       
  2272         {
       
  2273 #ifdef CAMERAAPP_CAPI_V2_ADV
       
  2274         if( iAdvancedSettingInfo.iDigitalZoomSupport.Count() > zoom )
       
  2275             iAdvancedSettings->SetDigitalZoom( iAdvancedSettingInfo.iDigitalZoomSupport[zoom] );
       
  2276           else
       
  2277             User::Leave( KErrNotSupported );
       
  2278         callback = ETrue;
       
  2279 
       
  2280 #else
       
  2281         // Note: Even if the method is misleadingly named
       
  2282         //       CCamera::SetDigitalZoomFactorL, the values are
       
  2283         //       zoom steps, not zoom factors.
       
  2284         iCamera->SetDigitalZoomFactorL( zoom );
       
  2285 #endif
       
  2286 
       
  2287         }
       
  2288       break;
       
  2289       }
       
  2290     // -------------------------------
       
  2291 #ifdef CAMERAAPP_CAPI_V2_ADV
       
  2292     case ECameraSettingOpticalZoom:
       
  2293       {
       
  2294       TInt zoom( 0 );
       
  2295       iSettingProvider.ProvideCameraSettingL( aSettingId, &zoom );
       
  2296       PRINT1( _L("Camera <> Setting optical zoom to: %d"), zoom );
       
  2297       iAdvancedSettings->SetOpticalZoom( zoom );
       
  2298       callback = ETrue;
       
  2299       break;
       
  2300       }
       
  2301     // -----------------------------------------------------
       
  2302     case ECameraSettingStabilization:
       
  2303       {
       
  2304       PRINT( _L("Camera <> CCamCameraController::ProcessSettingL ECameraSettingStabilization") );
       
  2305       TPckgBuf<TCamSettingDataStabilization> stabilization;
       
  2306       iSettingProvider.ProvideCameraSettingL( aSettingId, &stabilization );
       
  2307 
       
  2308       // Check that the values are supported..
       
  2309       TBool modeOk    = ( CAS::EStabilizationModeOff == stabilization().iMode
       
  2310                        || iAdvancedSettingInfo.iStabilizationModeSupport & stabilization().iMode );
       
  2311       TBool effectOk  = ( CAS::EStabilizationOff     == stabilization().iEffect
       
  2312                        || iAdvancedSettingInfo.iStabilizationEffectSupport & stabilization().iEffect );
       
  2313       TBool complexOk = ( CAS::EStabilizationComplexityAuto == stabilization().iComplexity
       
  2314                        || iAdvancedSettingInfo.iStabilizationComplexitySupport & stabilization().iComplexity );
       
  2315 
       
  2316       if( modeOk && effectOk && complexOk )
       
  2317         {
       
  2318         PRINT1( _L("Camera <> CCamCameraController::ProcessSettingL set stabilization mode=%d"), stabilization().iMode );
       
  2319         iAdvancedSettings->SetStabilizationMode      ( stabilization().iMode       );
       
  2320         iAdvancedSettings->SetStabilizationEffect    ( stabilization().iEffect     );
       
  2321         iAdvancedSettings->SetStabilizationComplexity( stabilization().iComplexity );
       
  2322         // Events:
       
  2323         //   KUidECamEventCameraSettingStabilizationMode
       
  2324         //   KUidECamEventCameraSettingsStabilizationEffect
       
  2325         //   KUidECamEventSettingsStabilizationAlgorithmComplexity
       
  2326         // We use the latest one to determine when we can continue.
       
  2327         // Do not change above order unless CCamSettingConversion::Map2EventUidValue
       
  2328         // is edited..
       
  2329         }
       
  2330       else
       
  2331         {
       
  2332         User::Leave( KErrNotSupported );
       
  2333         }
       
  2334 
       
  2335       callback = ETrue;
       
  2336       break;
       
  2337       }
       
  2338     // -------------------------------
       
  2339     case ECameraSettingContAF:
       
  2340       {
       
  2341       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  2342       if ( appUi->AppController().UiConfigManagerPtr()->IsContinuosAutofocusSupported() )
       
  2343          {
       
  2344          TBool isContAFon( iAdvancedSettings->AutoFocusType() &
       
  2345                            CAS::EAutoFocusTypeContinuous );
       
  2346          if( IsFlagOn( iInfo.iState, ECamVideoOn ) )
       
  2347             {
       
  2348             TBool contAF( ETrue );
       
  2349             iSettingProvider.ProvideCameraSettingL( aSettingId, &contAF );
       
  2350             if( contAF != isContAFon )
       
  2351               {
       
  2352               CAS::TAutoFocusType type = contAF? CAS::EAutoFocusTypeContinuous:
       
  2353                                                  CAS::EAutoFocusTypeOff;
       
  2354               iAdvancedSettings->SetAutoFocusType( type );
       
  2355 			  }
       
  2356             }
       
  2357          else
       
  2358 			{
       
  2359 			// Do nothing
       
  2360 			}
       
  2361 		 }
       
  2362       break;
       
  2363       }
       
  2364 #endif // CAMERAAPP_CAPI_V2_ADV
       
  2365     // -------------------------------
       
  2366 #ifdef CAMERAAPP_CAE_FOR_VIDEO
       
  2367     case ECameraSettingFileMaxSize:
       
  2368       {
       
  2369       if( iCaeEngine )
       
  2370         {
       
  2371         TInt bytes( 0 );
       
  2372         iSettingProvider.ProvideCameraSettingL( aSettingId, &bytes );
       
  2373         if( iCaeEngine->VideoClipMaxSize() != bytes )
       
  2374           {
       
  2375           iCaeEngine->SetVideoClipMaxSizeL( bytes );
       
  2376           callback = IsFlagOn( iInfo.iState, ECamVideoOn );
       
  2377           }
       
  2378         }
       
  2379       else
       
  2380         {
       
  2381         //
       
  2382         PRINT( _L("Camera <> Video file size too early, NOT SET!!") );
       
  2383         }
       
  2384       break;
       
  2385       }
       
  2386     // -------------------------------
       
  2387     case ECameraSettingFileName:
       
  2388       {
       
  2389       if( iCaeEngine )
       
  2390         {
       
  2391         PRINT ( _L("Camera <> processing filename setting") );
       
  2392 
       
  2393         HBufC* filename = HBufC::NewLC( KMaxFileName );
       
  2394         TPtr   ptr      = filename->Des();
       
  2395         PRINT ( _L("Camera <> get filename from setting provider..") );
       
  2396         iSettingProvider.ProvideCameraSettingL( aSettingId, &ptr );
       
  2397 
       
  2398         PRINT1( _L("Camera <> set filename [%S]"), filename );
       
  2399         iCaeEngine->SetVideoRecordingFileNameL( ptr );
       
  2400 
       
  2401         CleanupStack::PopAndDestroy( filename );
       
  2402         // If video has been prepared, MCaeoVideoPrepareComplete will be repeated,
       
  2403         // and needs to be waited.
       
  2404         callback = IsFlagOn( iInfo.iState, ECamVideoOn );
       
  2405         }
       
  2406       else
       
  2407         {
       
  2408         PRINT( _L("Camera <> Video name too early, NOT SET!!") );
       
  2409         }
       
  2410       break;
       
  2411       }
       
  2412     // -------------------------------
       
  2413     case ECameraSettingAudioMute:
       
  2414       {
       
  2415       if( iCaeEngine )
       
  2416         {
       
  2417          TBool isAudioOn( EFalse );
       
  2418         iSettingProvider.ProvideCameraSettingL( aSettingId, &isAudioOn );
       
  2419         TBool audioOn( iCaeEngine->VideoAudio() );
       
  2420         // If we need to mute audio and audio is on
       
  2421         // or we need to enable audio and audio is off
       
  2422         if( isAudioOn != audioOn )
       
  2423           {
       
  2424           iCaeEngine->SetVideoAudioL( isAudioOn );
       
  2425           callback = IsFlagOn( iInfo.iState, ECamVideoOn );
       
  2426           }
       
  2427         }
       
  2428       else
       
  2429         {
       
  2430         PRINT( _L("Camera <> Video mute too early, NOT SET!!") );
       
  2431         }
       
  2432       break;
       
  2433       }
       
  2434     // -------------------------------
       
  2435     case ECameraSettingFacetracking:
       
  2436       {
       
  2437       if( iCustomInterfaceFaceTracking )
       
  2438         {
       
  2439         SetFaceTrackingL();
       
  2440         }
       
  2441       else
       
  2442         {
       
  2443         PRINT( _L("Camera <> Facetracking too early, NOT SET!!") );
       
  2444         }
       
  2445       break;
       
  2446       }
       
  2447 #endif
       
  2448     // -------------------------------
       
  2449     // Image orientation
       
  2450     case ECameraSettingOrientation:
       
  2451       {
       
  2452       CheckNonNullL( iCustomInterfaceOrientation, KErrNotSupported );
       
  2453       MCameraOrientation::TOrientation
       
  2454         orientation( MCameraOrientation::EOrientation0 );
       
  2455       iSettingProvider.ProvideCameraSettingL( aSettingId, &orientation );
       
  2456 
       
  2457       if ( iInfo.iCurrentCamera != KPrimaryCameraIndex &&
       
  2458            orientation == MCameraOrientation::EOrientation90 )
       
  2459         {
       
  2460         PRINT( _L("Camera <> Rotate portrait secondary camera image 270 degrees") );
       
  2461         orientation = MCameraOrientation::EOrientation270;
       
  2462         }
       
  2463 
       
  2464       PRINT1( _L("Camera <> setting camera orientation to [0x%02x]"), orientation );
       
  2465       iCustomInterfaceOrientation->SetOrientationL( orientation );
       
  2466       break;
       
  2467       }
       
  2468     // -------------------------------
       
  2469     case ECameraSettingFocusRange:
       
  2470     default:
       
  2471       {
       
  2472 #ifndef CAMERAAPP_EMULATOR_BUILD
       
  2473       PRINT ( _L("Camera <> Not supported, LEAVE!") );
       
  2474       User::Leave( KErrNotSupported );
       
  2475 #endif // not CAMERAAPP_EMULATOR_BUILD
       
  2476       break;
       
  2477       }
       
  2478     // -------------------------------
       
  2479     }
       
  2480 
       
  2481   PRINT1( _L("Camera <= CCamCameraController::ProcessSettingL, continue now:%d"), !callback );
       
  2482   return !callback;
       
  2483   }
       
  2484 
       
  2485 
       
  2486 // ---------------------------------------------------------------------------
       
  2487 //
       
  2488 // ---------------------------------------------------------------------------
       
  2489 //
       
  2490 TInt
       
  2491 CCamCameraController
       
  2492 ::ProcessOneRequestL( const TCamCameraRequestId& aRequestId )
       
  2493   {
       
  2494   PRINT( _L("Camera => CCamCameraController::ProcessOneRequestL") );
       
  2495   PRINT2( _L("Camera <> processing request [%s] id:%d "),
       
  2496           KCamRequestNames[aRequestId],
       
  2497           aRequestId );
       
  2498 
       
  2499   TInt readyForNext( ETrue );
       
  2500 
       
  2501   // Order from most time critical / frequent
       
  2502   // to less time critical / seldom.
       
  2503   // Handled in submethods to preserve readability.
       
  2504   // -----------------------------------------------------
       
  2505   switch( aRequestId )
       
  2506     {
       
  2507     // -------------------------------
       
  2508     case ECamRequestReserve:
       
  2509     case ECamRequestPowerOn:
       
  2510       readyForNext = ProcessControlStartupRequestL( aRequestId );
       
  2511       break;
       
  2512     case ECamRequestPowerOff:
       
  2513     case ECamRequestRelease:
       
  2514       readyForNext = ProcessControlShutdownRequest( aRequestId );
       
  2515       break;
       
  2516     // -------------------------------
       
  2517     case ECamRequestVfStart:
       
  2518     case ECamRequestVfStop:
       
  2519     case ECamRequestVfRelease:
       
  2520       readyForNext = ProcessVfRequestL( aRequestId );
       
  2521       break;
       
  2522     // -------------------------------
       
  2523     case ECamRequestSsStart:
       
  2524     case ECamRequestSsStop:
       
  2525     case ECamRequestSsRelease:
       
  2526       readyForNext = ProcessSnapshotRequestL( aRequestId );
       
  2527       break;
       
  2528     // -------------------------------
       
  2529     case ECamRequestImageInit:
       
  2530     case ECamRequestImageCapture:
       
  2531       readyForNext = ProcessImageRequestL( aRequestId );
       
  2532       break;
       
  2533     case ECamRequestImageCancel:
       
  2534     case ECamRequestImageRelease:
       
  2535       readyForNext = ProcessImageShutdownRequest( aRequestId );
       
  2536       break;
       
  2537     // -------------------------------
       
  2538     case ECamRequestVideoInit:
       
  2539     case ECamRequestVideoStart:
       
  2540     case ECamRequestVideoPause:
       
  2541     case ECamRequestVideoStop:
       
  2542     case ECamRequestVideoRelease:
       
  2543     case ECamRequestSetAsyncVideoStopMode:
       
  2544       readyForNext = ProcessVideoRequestL( aRequestId );
       
  2545       break;
       
  2546     // -------------------------------
       
  2547     default:
       
  2548       Panic( ECamCameraControllerUnknownRequest );
       
  2549       break;
       
  2550     // -------------------------------
       
  2551     }
       
  2552   // -----------------------------------------------------
       
  2553   PRINT( _L("Camera <= CCamCameraController::ProcessOneRequestL") );
       
  2554   return readyForNext;
       
  2555   }
       
  2556 
       
  2557 
       
  2558 // ---------------------------------------------------------------------------
       
  2559 // ProcessControlStartupRequestL
       
  2560 // ---------------------------------------------------------------------------
       
  2561 //
       
  2562 TInt
       
  2563 CCamCameraController
       
  2564 ::ProcessControlStartupRequestL( const TCamCameraRequestId& aRequestId )
       
  2565   {
       
  2566   PRINT1( _L("Camera => CCamCameraController::ProcessControlStartupRequestL [%s]"),
       
  2567           KCamRequestNames[aRequestId] );
       
  2568   // -------------------------------------------------------
       
  2569   // Reserve
       
  2570   if( ECamRequestReserve == aRequestId )
       
  2571     {
       
  2572     CheckFlagOffL( iInfo.iState, ECamReserved, KErrInUse );
       
  2573 
       
  2574     // tell CAPI the usecase (still or video), not fatal if fails
       
  2575     TRAPD( err, HintUseCaseL() );
       
  2576     
       
  2577     if( err ) 
       
  2578       {
       
  2579       PRINT1( _L("Camera <> CCamCameraController::ProcessControlStartupRequestL HintUseCaseL failed:%d"), err)
       
  2580       }
       
  2581 
       
  2582     CAMERAAPP_PERF_CONTROLLER_START( ECamRequestReserve );
       
  2583     iCamera->Reserve();
       
  2584     // If UIOrientationOverrideAPI is used, ui construction is completed while
       
  2585     // waiting for Reserve to complete, event sent here to continue ui construction
       
  2586     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  2587     if ( appUi->AppController().UiConfigManagerPtr()->IsUIOrientationOverrideSupported() )
       
  2588       {
       
  2589       NotifyObservers( KErrNone,
       
  2590                        ECamCameraEventReserveRequested,
       
  2591                        ECamCameraEventClassBasicControl );
       
  2592       }
       
  2593     }
       
  2594   // -------------------------------------------------------
       
  2595   // Power on
       
  2596   else if( ECamRequestPowerOn == aRequestId )
       
  2597     {
       
  2598     CheckFlagOnL ( iInfo.iState, ECamReserved, KErrNotReady );
       
  2599     CheckFlagOffL( iInfo.iState, ECamPowerOn,  KErrInUse    );
       
  2600 
       
  2601     CAMERAAPP_PERF_CONTROLLER_START( ECamRequestPowerOn );
       
  2602 
       
  2603     iCamera->PowerOn();
       
  2604     }
       
  2605   // -------------------------------------------------------
       
  2606   // Unknown
       
  2607   else
       
  2608     {
       
  2609     Panic( ECamCameraControllerCorrupt );
       
  2610     }
       
  2611   // -------------------------------------------------------
       
  2612   iReleasedByUi = EFalse;
       
  2613   PRINT( _L("Camera <= CCamCameraController::ProcessControlStartupRequestL") );
       
  2614   // Callback needs to be received before we can continue.
       
  2615   return EFalse;
       
  2616   }
       
  2617 
       
  2618 // ---------------------------------------------------------------------------
       
  2619 // ProcessControlShutdownRequest
       
  2620 // ---------------------------------------------------------------------------
       
  2621 //
       
  2622 TInt
       
  2623 CCamCameraController
       
  2624 ::ProcessControlShutdownRequest( const TCamCameraRequestId& aRequestId )
       
  2625   {
       
  2626   PRINT( _L("Camera => CCamCameraController::ProcessControlShutdownRequest") );
       
  2627   // -------------------------------------------------------
       
  2628   // Power off
       
  2629   if( ECamRequestPowerOff == aRequestId )
       
  2630     {
       
  2631     if( IsFlagOn( iInfo.iState, ECamPowerOn ) )
       
  2632       {
       
  2633       // -------------------------------
       
  2634       // Release image or video capture
       
  2635       if( IsFlagOn( iInfo.iState, ECamImageOn ) )
       
  2636         {
       
  2637         // Leaves only if state is wrong (already checked here).
       
  2638         ProcessImageShutdownRequest( ECamRequestImageRelease );
       
  2639         NotifyObservers( KErrNone,
       
  2640                          ECamCameraEventImageRelease,
       
  2641                          ECamCameraEventClassImage );
       
  2642         }
       
  2643       else if( IsFlagOn( iInfo.iState, ECamVideoOn ) )
       
  2644         {
       
  2645         TRAP_IGNORE( ProcessVideoRequestL( ECamRequestVideoRelease ) );
       
  2646         NotifyObservers( KErrNone,
       
  2647                          ECamCameraEventVideoRelease,
       
  2648                          ECamCameraEventClassVideo );
       
  2649         }
       
  2650       else
       
  2651         {
       
  2652         }
       
  2653       // -------------------------------
       
  2654       // If viewfinder is not released yet, release it now.
       
  2655       if( ECamTriIdle != iInfo.iVfState )
       
  2656         {
       
  2657         ProcessVfRelaseRequest();
       
  2658         NotifyObservers( KErrNone,
       
  2659                          ECamCameraEventVfRelease,
       
  2660                          ECamCameraEventClassVfControl );
       
  2661         }
       
  2662 
       
  2663       // -------------------------------
       
  2664       // If snapshot is not released yet, release it now.
       
  2665       if( ECamTriIdle != iInfo.iSsState )
       
  2666         {
       
  2667         ProcessSsReleaseRequest();
       
  2668         NotifyObservers( KErrNone,
       
  2669                          ECamCameraEventSsRelease,
       
  2670                          ECamCameraEventClassSsControl );
       
  2671         }
       
  2672       // -------------------------------
       
  2673       // Do the actual powering off.
       
  2674 #ifdef CAMERAAPP_CAE_FIX
       
  2675       if( iCaeInUse )
       
  2676         {
       
  2677         iCaeEngine->PowerOff();
       
  2678         }
       
  2679       else
       
  2680 #endif // CAMERAAPP_CAE_FIX
       
  2681         {
       
  2682         iCamera->PowerOff();
       
  2683         }
       
  2684       // -------------------------------
       
  2685       }
       
  2686     ClearFlags( iInfo.iState, ECamPowerOn );
       
  2687     }
       
  2688   // -------------------------------------------------------
       
  2689   // Release
       
  2690   else if( ECamRequestRelease == aRequestId )
       
  2691     {
       
  2692     if( IsFlagOn( iInfo.iState, ECamReserved ) )
       
  2693       {
       
  2694       // If power off not called yet, do it now.
       
  2695       if( IsFlagOn( iInfo.iState, ECamPowerOn ) )
       
  2696         {
       
  2697         ProcessControlShutdownRequest( ECamRequestPowerOff );
       
  2698         // Separate notification needed here, because operation done
       
  2699         // as part of handling other request.
       
  2700         NotifyObservers( KErrNone,
       
  2701                          ECamCameraEventPowerOff,
       
  2702                          ECamCameraEventClassBasicControl );
       
  2703         }
       
  2704 #ifdef CAMERAAPP_CAE_FIX
       
  2705       if( iCaeInUse )
       
  2706         {
       
  2707         iCaeEngine->Release();
       
  2708         iCaeInUse = EFalse;
       
  2709         }
       
  2710       else
       
  2711 #endif // CAMERAAPP_CAE_FIX
       
  2712         {
       
  2713         iCamera->Release();
       
  2714         iReleasedByUi = ETrue;
       
  2715         if( iIveRecoveryCount > 0 )
       
  2716             {
       
  2717             HandleReserveLostEvent( KErrNone );
       
  2718             }
       
  2719         }
       
  2720       }
       
  2721     PRINT( _L("Camera <> released, reset info") );
       
  2722 
       
  2723     // Reset our info, but preserve busy flag and camera index.
       
  2724     // Sets iInfo.iState to ECamIdle.
       
  2725     iInfo.Reset( ETrue, ETrue );
       
  2726     }
       
  2727   // -------------------------------------------------------
       
  2728   // Unknown
       
  2729   else
       
  2730     {
       
  2731     Panic( ECamCameraControllerCorrupt );
       
  2732     }
       
  2733   // -------------------------------------------------------
       
  2734   PRINT( _L("Camera <= CCamCameraController::ProcessControlShutdownRequest") );
       
  2735 
       
  2736   // No callback needs to be waited.
       
  2737   return ETrue;
       
  2738   }
       
  2739 
       
  2740 // ---------------------------------------------------------------------------
       
  2741 // ProcessViewfinderRequestL
       
  2742 // ---------------------------------------------------------------------------
       
  2743 //
       
  2744 TInt
       
  2745 CCamCameraController
       
  2746 ::ProcessVfRequestL( const TCamCameraRequestId& aRequestId )
       
  2747   {
       
  2748   CheckFlagOnL( iInfo.iState, ECamPowerOn, KErrNotReady );
       
  2749 
       
  2750   switch( aRequestId )
       
  2751     {
       
  2752     // -----------------------------------------------------
       
  2753     case ECamRequestVfStart:
       
  2754       {
       
  2755       CAMERAAPP_PERF_CONTROLLER_STARTNEW( ECamRequestVfStart, iFirstVfFrameReceived );
       
  2756       ProcessVfStartRequestL();
       
  2757       break;
       
  2758       }
       
  2759     // -----------------------------------------------------
       
  2760     case ECamRequestVfStop:
       
  2761       {
       
  2762       ProcessVfStopRequestL();
       
  2763       break;
       
  2764       }
       
  2765     // -----------------------------------------------------
       
  2766     case ECamRequestVfRelease:
       
  2767       {
       
  2768       ProcessVfRelaseRequest();
       
  2769       break;
       
  2770       }
       
  2771     // -----------------------------------------------------
       
  2772     default:
       
  2773       {
       
  2774       Panic( ECamCameraControllerCorrupt );
       
  2775       break;
       
  2776       }
       
  2777     // -----------------------------------------------------
       
  2778     }
       
  2779 
       
  2780   // No callback to be waited
       
  2781   return ETrue;
       
  2782   }
       
  2783 
       
  2784 
       
  2785 // ---------------------------------------------------------------------------
       
  2786 // InitViewfinderL
       
  2787 // ---------------------------------------------------------------------------
       
  2788 //
       
  2789 void
       
  2790 CCamCameraController::InitViewfinderL( const TCamViewfinderMode& aMode )
       
  2791   {
       
  2792   PRINT( _L("Camera => CCamCameraController::InitViewfinderL") );
       
  2793 
       
  2794   // Check the old viewfinder is released now.
       
  2795   // No further checks made here.
       
  2796   __ASSERT_DEBUG( ECamTriIdle == iInfo.iVfState, Panic( ECamCameraControllerCorrupt ) );
       
  2797 
       
  2798   // Then init the new mode
       
  2799   switch( aMode )
       
  2800     {
       
  2801     // ---------------------------------
       
  2802     case ECamViewfinderDirect:
       
  2803       {
       
  2804       // Don't proceed if not supported by camera.
       
  2805       CheckFlagOnL( iCameraInfo.iOptionsSupported,
       
  2806                     TCameraInfo::EViewFinderDirectSupported,
       
  2807                     KErrNotSupported );
       
  2808 
       
  2809   #ifdef CAMERAAPP_CAPI_V2_DVF
       
  2810       PRINT( _L("Camera <> Creating CCameraDirectViewFinder instance") );
       
  2811       if( iDirectViewfinder )
       
  2812         {
       
  2813         	delete iDirectViewfinder;
       
  2814         	iDirectViewfinder=NULL;
       
  2815         }
       
  2816       iDirectViewfinder = CCamera::CCameraDirectViewFinder::NewL( *iCamera );
       
  2817   #else
       
  2818       // not implemented
       
  2819       Panic( ECamCameraControllerUnsupported );
       
  2820   #endif
       
  2821       iInfo.iVfState  = ECamTriInactive;
       
  2822       iInfo.iVfMode   = ECamViewfinderDirect;
       
  2823       break;
       
  2824       }
       
  2825     // ---------------------------------
       
  2826     case ECamViewfinderBitmap:
       
  2827       {
       
  2828       // Don't proceed if not supported by camera.
       
  2829       CheckFlagOnL( iCameraInfo.iOptionsSupported,
       
  2830                     TCameraInfo::EViewFinderBitmapsSupported,
       
  2831                     KErrNotSupported );
       
  2832 
       
  2833       iInfo.iVfState  = ECamTriInactive;
       
  2834       iInfo.iVfMode   = ECamViewfinderBitmap;
       
  2835       break;
       
  2836       }
       
  2837     // ---------------------------------
       
  2838     case ECamViewfinderNone:
       
  2839       // Mode is "none", so no init needed.
       
  2840       break;
       
  2841     // ---------------------------------
       
  2842     default:
       
  2843       // Unknown mode
       
  2844       Panic( ECamCameraControllerUnsupported );
       
  2845       break;
       
  2846     // ---------------------------------
       
  2847     }
       
  2848   PRINT( _L("Camera <= CCamCameraController::InitViewfinderL") );
       
  2849   }
       
  2850 
       
  2851 // ---------------------------------------------------------------------------
       
  2852 // ---------------------------------------------------------------------------
       
  2853 void
       
  2854 CCamCameraController
       
  2855 ::ProcessVfStartRequestL()
       
  2856   {
       
  2857   PRINT( _L("Camera => CCamCameraController::ProcessVfStartRequestL") );
       
  2858 
       
  2859 #ifdef __WINSCW__
       
  2860   const TCamViewfinderMode KTargetMode( ECamViewfinderBitmap );
       
  2861 #else
       
  2862 
       
  2863   TPckgBuf<TCamViewfinderMode> mode;
       
  2864   iSettingProvider.ProvideCameraParamL( ECameraParamVfMode, &mode );
       
  2865 
       
  2866   // If the viewfinder mode needs to be changed,
       
  2867   // first stop and release resources related to the old viewfinder type.
       
  2868   const TCamViewfinderMode KTargetMode( mode() );
       
  2869 #endif
       
  2870 
       
  2871   if( ECamViewfinderNone != iInfo.iVfMode
       
  2872    && KTargetMode        != iInfo.iVfMode )
       
  2873     {
       
  2874     ProcessVfRelaseRequest();
       
  2875     }
       
  2876 
       
  2877   // Check that application is still in foreground, if not, then vf not started.
       
  2878   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  2879   if ( appUi && appUi->AppInBackground( ETrue ) )
       
  2880     {
       
  2881     // Notify appUi that we did not start viewfinder although asked to do so.
       
  2882     appUi->SetViewFinderStoppedStatus( iInfo.iVfState != ECamTriActive );
       
  2883     }
       
  2884   else
       
  2885     {
       
  2886     switch( iInfo.iVfState )
       
  2887       {
       
  2888       // -----------------------------------------------------
       
  2889       case ECamTriIdle:
       
  2890        PRINT( _L("Camera <> case ECamTriIdle") );
       
  2891 
       
  2892         InitViewfinderL( KTargetMode );
       
  2893         // << fall through >>
       
  2894 
       
  2895       case ECamTriInactive:
       
  2896         {
       
  2897         // -------------------------------
       
  2898         PRINT( _L("Camera <> case ECamTriInactive") );
       
  2899 
       
  2900         if( ECamViewfinderDirect == iInfo.iVfMode )
       
  2901 #ifdef CAMERAAPP_CAPI_V2_DVF
       
  2902           {
       
  2903           switch( iDirectViewfinder->ViewFinderState() )
       
  2904             {
       
  2905             case CCamera::CCameraDirectViewFinder::EViewFinderInActive:
       
  2906               {
       
  2907               if ( !iViewfinderWindow )
       
  2908                   {
       
  2909                   PRINT( _L("Camera <> CCamCameraController::iViewfinderWindow is NULL - cannot start VF!") );
       
  2910                   User::Leave( KErrNotReady );
       
  2911                   }
       
  2912 
       
  2913               // Use the same viewfinder position and size as for bitmap viewfinder
       
  2914               TPckgBuf<TCamParamsVfBitmap> params;
       
  2915               iSettingProvider.ProvideCameraParamL( ECameraParamVfBitmap, &params );
       
  2916 
       
  2917               CEikonEnv* env = CEikonEnv::Static();
       
  2918 
       
  2919               OstTrace0( CAMERAAPP_PERFORMANCE, CCAMCAMERACONTROLLER_PROCESSVFSTARTREQUESTL, "e_CAM_APP_VF_INIT 0" ); //CCORAPP_APP_VF_INIT_END
       
  2920 
       
  2921               iCamera->StartViewFinderDirectL(
       
  2922                   env->WsSession(),
       
  2923                   *env->ScreenDevice(),
       
  2924                   *iViewfinderWindow,
       
  2925                   params().iRect );
       
  2926               
       
  2927               if ( appUi && ECamActiveCameraSecondary == appUi->ActiveCamera() )
       
  2928                   {
       
  2929                   iCamera->SetViewFinderMirrorL(ETrue);
       
  2930                   }
       
  2931               // VF started succesfully, reset recovery counter
       
  2932               delete iIdle;
       
  2933               iIdle = NULL;
       
  2934               iIveRecoveryCount = KIveRecoveryCountMax;
       
  2935               break;
       
  2936               }
       
  2937             case CCamera::CCameraDirectViewFinder::EViewFinderPause:
       
  2938               {
       
  2939               iDirectViewfinder->ResumeViewFinderDirectL();
       
  2940               break;
       
  2941               }
       
  2942             case CCamera::CCameraDirectViewFinder::EViewFinderActive:
       
  2943               {
       
  2944               // Already running. Not considered as error.
       
  2945               break;
       
  2946               }
       
  2947             default:
       
  2948               {
       
  2949               Panic( ECamCameraControllerUnsupported );
       
  2950               break;
       
  2951               }
       
  2952             }
       
  2953           }
       
  2954 #else // CAMERAAPP_CAPI_V2_DVF
       
  2955           {
       
  2956           // No controller support for direct vf.
       
  2957           Panic( ECamCameraControllerUnsupported );
       
  2958           }
       
  2959 #endif // CAMERAAPP_CAPI_V2_DVF
       
  2960         // -------------------------------
       
  2961         else
       
  2962           {
       
  2963           PRINT( _L("Camera <> Get bitmap vf details..") );
       
  2964 
       
  2965           TPckgBuf<TCamParamsVfBitmap> params;
       
  2966           iSettingProvider.ProvideCameraParamL( ECameraParamVfBitmap, &params );
       
  2967           iInfo.iViewfinderFormat = params().iFormat;
       
  2968           iInfo.iViewfinderSize   = params().iRect.Size();
       
  2969 #ifdef CAMERAAPP_CAE_FIX
       
  2970           if( iCaeInUse )
       
  2971             {
       
  2972             PRINT( _L("Camera <> Call CCaeEngine::StartViewFinderBitmapsL..") );
       
  2973 
       
  2974             OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMCAMERACONTROLLER_PROCESSVFSTARTREQUESTL, "e_CAM_APP_VF_INIT 0" ); //CCORAPP_APP_VF_INIT_END
       
  2975             iCaeEngine->StartViewFinderBitmapsL( iInfo.iViewfinderSize );
       
  2976             }
       
  2977           else
       
  2978 #endif // CAMERAAPP_CAE_FIX
       
  2979             {
       
  2980             PRINT( _L("Camera <> Call CCamera::StartViewFinderBitmapsL..") );
       
  2981             OstTrace0( CAMERAAPP_PERFORMANCE, DUP2_CCAMCAMERACONTROLLER_PROCESSVFSTARTREQUESTL, "e_CAM_APP_VF_INIT 0" );  //CCORAPP_APP_VF_INIT_END
       
  2982             iCamera->StartViewFinderBitmapsL( iInfo.iViewfinderSize );
       
  2983 
       
  2984   		  if ( params().iMirrorImage )
       
  2985   		  	{
       
  2986   		   	iCamera->SetViewFinderMirrorL( params().iMirrorImage );
       
  2987   		   	}
       
  2988             }
       
  2989           }
       
  2990         // -------------------------------
       
  2991 
       
  2992         iInfo.iVfState = ECamTriActive;
       
  2993         //view finder started now(set stop status as false)
       
  2994         if ( appUi )
       
  2995             {
       
  2996             appUi->SetViewFinderStoppedStatus( EFalse );
       
  2997             }
       
  2998         break;
       
  2999         }
       
  3000       // -----------------------------------------------------
       
  3001       case ECamTriActive:
       
  3002         {
       
  3003         PRINT( _L("Camera <> case ECamTriActive") );
       
  3004         // Viewfinder started *and* the right mode
       
  3005         // no action needed.
       
  3006         break;
       
  3007         }
       
  3008       // -----------------------------------------------------
       
  3009       default:
       
  3010         Panic( ECamCameraControllerCorrupt );
       
  3011         break;
       
  3012       // -----------------------------------------------------
       
  3013       }
       
  3014     }
       
  3015   PRINT( _L("Camera <= CCamCameraController::ProcessVfStartRequestL") );
       
  3016   }
       
  3017 
       
  3018 
       
  3019 
       
  3020 // ---------------------------------------------------------------------------
       
  3021 // ProcessVfStopRequestL
       
  3022 //
       
  3023 // ---------------------------------------------------------------------------
       
  3024 //
       
  3025 void
       
  3026 CCamCameraController::ProcessVfStopRequestL()
       
  3027   {
       
  3028   PRINT( _L("Camera => CCamCameraController::ProcessVfStopRequestL") );
       
  3029 
       
  3030   switch( iInfo.iVfState )
       
  3031     {
       
  3032     case ECamTriActive:
       
  3033       {
       
  3034       ProcessVfStopEcamRequest();
       
  3035       iInfo.iVfState = ECamTriInactive;
       
  3036       break;
       
  3037       }
       
  3038     case ECamTriIdle:
       
  3039       {
       
  3040       // Viewfinder not initialized.
       
  3041       // Let this pass as our "start viewfinder" handles all states.
       
  3042       break;
       
  3043       }
       
  3044     case ECamTriInactive:
       
  3045       {
       
  3046       // Already stopped. No action needed.
       
  3047       break;
       
  3048       }
       
  3049     default:
       
  3050       {
       
  3051       Panic( ECamCameraControllerCorrupt );
       
  3052       break;
       
  3053       }
       
  3054     }
       
  3055   PRINT( _L("Camera <= CCamCameraController::ProcessVfStopRequestL") );
       
  3056   }
       
  3057 
       
  3058 
       
  3059 // ---------------------------------------------------------------------------
       
  3060 // ProcessVfStopEcamRequest
       
  3061 //
       
  3062 // ---------------------------------------------------------------------------
       
  3063 //
       
  3064 void
       
  3065 CCamCameraController::ProcessVfStopEcamRequest()
       
  3066   {
       
  3067   PRINT( _L("Camera => CCamCameraController::ProcessVfStopEcamRequest") );
       
  3068 
       
  3069   if( ECamViewfinderDirect == iInfo.iVfMode )
       
  3070     {
       
  3071 #ifdef CAMERAAPP_CAPI_V2_DVF
       
  3072     if ( iCamera )
       
  3073       {
       
  3074       PRINT( _L("Camera <> VF stop by CCamera") );
       
  3075       iCamera->StopViewFinder();
       
  3076       }
       
  3077 #else // CAMERAAPP_CAPI_V2_DVF
       
  3078     Panic( ECamCameraControllerUnsupported );
       
  3079 #endif // CAMERAAPP_CAPI_V2_DVF
       
  3080     }
       
  3081   else
       
  3082     {
       
  3083 #ifdef CAMERAAPP_CAE_FIX
       
  3084     if( iCaeInUse && iCaeEngine )
       
  3085       {
       
  3086       PRINT( _L("Camera <> stop by CAE") );
       
  3087       iCaeEngine->StopViewFinder();
       
  3088       }
       
  3089     else
       
  3090 #endif // CAMERAAPP_CAE_FIX
       
  3091       {
       
  3092       if ( iCamera )
       
  3093         {
       
  3094         PRINT( _L("Camera <> stop by CCamera") );
       
  3095         iCamera->StopViewFinder();
       
  3096         }
       
  3097       }
       
  3098     }
       
  3099   PRINT( _L("Camera <= CCamCameraController::ProcessVfStopEcamRequest") );
       
  3100   }
       
  3101 
       
  3102 
       
  3103 // ---------------------------------------------------------------------------
       
  3104 //
       
  3105 // ---------------------------------------------------------------------------
       
  3106 //
       
  3107 void
       
  3108 CCamCameraController
       
  3109 ::ProcessVfRelaseRequest()
       
  3110   {
       
  3111   switch( iInfo.iVfState )
       
  3112     {
       
  3113     // -----------------------------------------------------
       
  3114     case ECamTriActive:
       
  3115       {
       
  3116       // Do the stopping first and continue then with release.
       
  3117       // Leaves only if iVfState is ECamVfIdle, which is not the case here.
       
  3118       TRAP_IGNORE( ProcessVfStopRequestL() );
       
  3119 
       
  3120       // Need to notify here, because done as a part of other request.
       
  3121       NotifyObservers( KErrNone,
       
  3122                        ECamCameraEventVfStop,
       
  3123                        ECamCameraEventClassVfControl );
       
  3124       // << fall through >>
       
  3125       }
       
  3126     // -----------------------------------------------------
       
  3127     case ECamTriInactive:
       
  3128       {
       
  3129       if( ECamViewfinderDirect == iInfo.iVfMode )
       
  3130         {
       
  3131 #ifdef CAMERAAPP_CAPI_V2_DVF
       
  3132         delete iDirectViewfinder;
       
  3133         iDirectViewfinder = NULL;
       
  3134 #endif
       
  3135         }
       
  3136       else
       
  3137         {
       
  3138         // No further actions needed for bitmap viewfinding.
       
  3139         }
       
  3140       // These may very well remain as they are.
       
  3141       // Atleast for the format there is no "zero" value available.
       
  3142       //    iInfo.iViewfinderSize
       
  3143       //    iInfo.iViewfinderFormat
       
  3144       iInfo.iVfState          = ECamTriIdle;
       
  3145       iInfo.iVfMode           = ECamViewfinderNone;
       
  3146       break;
       
  3147       }
       
  3148     // -----------------------------------------------------
       
  3149     case ECamTriIdle:
       
  3150       // Already released.
       
  3151       break;
       
  3152     // -----------------------------------------------------
       
  3153     default:
       
  3154       Panic( ECamCameraControllerCorrupt );
       
  3155       break;
       
  3156     // -----------------------------------------------------
       
  3157     }
       
  3158   }
       
  3159 
       
  3160 
       
  3161 // ---------------------------------------------------------------------------
       
  3162 // ProcessImageRequestL
       
  3163 // ---------------------------------------------------------------------------
       
  3164 //
       
  3165 TInt
       
  3166 CCamCameraController
       
  3167 ::ProcessImageRequestL( const TCamCameraRequestId& aRequestId )
       
  3168   {
       
  3169   PRINT( _L("Camera => CCamCameraController::ProcessImageRequestL") );
       
  3170   CheckFlagOnL( iInfo.iState, ECamPowerOn, KErrNotReady );
       
  3171 
       
  3172   TInt callback( ETrue );
       
  3173   switch( aRequestId )
       
  3174     {
       
  3175     // -----------------------------------------------------
       
  3176     case ECamRequestImageInit:
       
  3177       {
       
  3178       // When camera engine still capture don't Init a new capture
       
  3179 
       
  3180       if ( ECamCaptureOn == iInfo.iCaptureState )
       
  3181       	{
       
  3182       	return EFalse;
       
  3183       	}
       
  3184       CAMERAAPP_PERF_CONTROLLER_START( ECamRequestImageInit );
       
  3185 
       
  3186 #ifdef CAMERAAPP_CAE_FOR_VIDEO
       
  3187   #ifdef CAMERAAPP_CAE_FIX
       
  3188       if( iCaeInUse )
       
  3189         {
       
  3190         iModeChange       = ECamModeChangeVideo2Image;
       
  3191         iModeChangePhase  = ECamModeChangePhaseIdle;   // incremented before first step
       
  3192         iModeChangeStatus = KErrNone;
       
  3193         iActive->IssueRequest();
       
  3194         }
       
  3195       else
       
  3196   #else
       
  3197       if( IsFlagOn( iInfo.iState, ECamVideoOn ) )
       
  3198         {
       
  3199         // Release any video recording resources
       
  3200         iCaeEngine->CloseVideoRecording();
       
  3201         ClearFlags( iInfo.iState, ECamVideoOn );
       
  3202         }
       
  3203   #endif // CAMERAAPP_CAE_FIX
       
  3204 #endif
       
  3205         {
       
  3206       PRINT( _L("Camera <> Checking that image capture not ongoing..") );
       
  3207       CheckEqualsL( iInfo.iCaptureState, ECamCaptureOff, KErrInUse    );
       
  3208 
       
  3209       PRINT( _L("Camera <> Checking that image capture supported..") );
       
  3210       CheckFlagOnL( iCameraInfo.iOptionsSupported,
       
  3211                     TCameraInfo::EImageCaptureSupported,
       
  3212                     KErrNotSupported );
       
  3213 
       
  3214       PRINT( _L("Camera <> Ask image parameters..") );
       
  3215       TPckgBuf<TCamParamsImage> params;
       
  3216       iSettingProvider.ProvideCameraParamL( ECameraParamImage, &params );
       
  3217 
       
  3218       PRINT( _L("Camera <> Enumerating capture sizes..") );
       
  3219       // Query the supported resolutions for the selected format.
       
  3220       // GetResolutionIndexL may change the format to some alternative,
       
  3221       // if we are able to convert the incoming image later to the
       
  3222       // format requested by client.
       
  3223       CCamera::TFormat format( params().iFormat );
       
  3224       TInt index = GetResolutionIndexL( format, params().iSize );
       
  3225       User::LeaveIfError( index );
       
  3226 
       
  3227       PRINT( _L("Camera <> Call CCamera::PrepareImageCaptureL..") );
       
  3228       PRINT2( _L("Camera <> Image size: (%d, %d)"),
       
  3229                   params().iSize.iWidth,
       
  3230                   params().iSize.iHeight );
       
  3231 
       
  3232       OstTrace0( CAMERAAPP_PERFORMANCE, CCAMCAMERACONTROLLER_PROCESSIMAGEREQUESTL, "e_CAM_APP_CONFIGURATIONS 0" );  //CCORAPP_APP_CONFIGS_END
       
  3233       iCamera->PrepareImageCaptureL( format, index );
       
  3234       OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMCAMERACONTROLLER_PROCESSIMAGEREQUESTL, "e_CAM_APP_STILL_INIT 0" ); //CCORAPP_APP_STILL_INIT_END
       
  3235 
       
  3236       iCamera->SetJpegQuality( params().iQualityFactor );
       
  3237 
       
  3238       SetFlags( iInfo.iState, ECamImageOn );
       
  3239 
       
  3240 #ifdef CAMERAAPP_CAPI_V2_ADV
       
  3241       // Set current autofocus range to invalid value to force focusing
       
  3242       iInfo.iCurrentFocusRange = static_cast<CAS::TFocusRange>( -1 );
       
  3243       GetAdvancedSettingsInfoL();
       
  3244 #endif // CAMERAAPP_CAPI_V2_ADV
       
  3245 
       
  3246       iInfo.iCaptureCount  = 0;
       
  3247       iInfo.iSnapshotCount = 0;
       
  3248       callback = EFalse; // No callback to wait for.
       
  3249       CAMERAAPP_PERF_CONTROLLER_STOP( ECamRequestImageInit );
       
  3250         }
       
  3251       break;
       
  3252       }
       
  3253     // -----------------------------------------------------
       
  3254     case ECamRequestImageCapture:
       
  3255       {
       
  3256       CheckFlagOnL( iInfo.iState,        ECamImageOn,    KErrNotReady );
       
  3257       CheckEqualsL( iInfo.iCaptureState, ECamCaptureOff, KErrInUse    );
       
  3258       OstTrace0( CAMERAAPP_PERFORMANCE, DUP2_CCAMCAMERACONTROLLER_PROCESSIMAGEREQUESTL, "e_CAM_APP_CAPTURE_START 0" );  //CCORAPP_CAPTURE_START_END
       
  3259 
       
  3260       // New capture starts, reset capture and snapshot counters.
       
  3261       iInfo.iCaptureCount  = 0;
       
  3262       iInfo.iSnapshotCount = 0;
       
  3263       iInfo.iCaptureState  = ECamCaptureOn;
       
  3264 
       
  3265       PRINT1( _L("Camera <> CCamCameraController .. About to start capture, total shared buffers in use: %d"), CCamBufferShare::TotalBufferShareCount() );
       
  3266       iCamera->CaptureImage();
       
  3267 
       
  3268       // When image data is received from CCamera,
       
  3269       // an event is generated for that. We need to notify
       
  3270       // here as other places check if the request has associated
       
  3271       // callback, and send no notification yet if callback exist.
       
  3272       NotifyObservers( KErrNone,
       
  3273                        ECamCameraEventImageStart,
       
  3274                        ECamCameraEventClassImage );
       
  3275       break;
       
  3276       }
       
  3277     // -----------------------------------------------------
       
  3278     default:
       
  3279       {
       
  3280       Panic( ECamCameraControllerCorrupt );
       
  3281       break;
       
  3282       }
       
  3283     // -----------------------------------------------------
       
  3284     }
       
  3285   PRINT1( _L("Camera <= CCamCameraController::ProcessImageRequestL, continue now:%d"), !callback );
       
  3286   return !callback;
       
  3287   }
       
  3288 
       
  3289 
       
  3290 // ---------------------------------------------------------------------------
       
  3291 // ProcessImageShutdownRequest
       
  3292 // ---------------------------------------------------------------------------
       
  3293 //
       
  3294 TInt
       
  3295 CCamCameraController
       
  3296 ::ProcessImageShutdownRequest( const TCamCameraRequestId& aRequestId )
       
  3297   {
       
  3298   PRINT( _L("Camera => CCamCameraController::ProcessImageShutdownRequest") );
       
  3299 
       
  3300   switch( aRequestId )
       
  3301     {
       
  3302     // -----------------------------------------------------
       
  3303     case ECamRequestImageCancel:
       
  3304       {
       
  3305       if( IsFlagOn( iInfo.iState, ECamImageOn )
       
  3306 //      && ECamCaptureOn == iInfo.iCaptureState
       
  3307         )
       
  3308         {
       
  3309         const TCamCameraCaptureState previousState( iInfo.iCaptureState );
       
  3310 
       
  3311         if( iEncoder )
       
  3312           {
       
  3313           iEncoder->Cancel();
       
  3314 
       
  3315           delete iEncoder;
       
  3316           iEncoder = NULL;
       
  3317           }
       
  3318 
       
  3319         PRINT( _L("Camera <> Calling iCamera->CancelCaptureImage()") );
       
  3320         iCamera->CancelCaptureImage();
       
  3321 
       
  3322         iInfo.iCaptureState = ECamCaptureOff;
       
  3323 
       
  3324         // Notify if we actually stopped the capturing here.
       
  3325         if( ECamCaptureOn == previousState )
       
  3326           {
       
  3327 
       
  3328           // Capturing image was stopped here.
       
  3329           // If single request was ongoing, it must be "capture image".
       
  3330           ClearFlags( iInfo.iBusy, ECamBusySingle );
       
  3331 
       
  3332           TInt fullCaptures( Min( iInfo.iCaptureCount, iInfo.iSnapshotCount ) );
       
  3333           NotifyObservers( KErrNone,
       
  3334                            ECamCameraEventImageStop,
       
  3335                            ECamCameraEventClassImage,
       
  3336                            &fullCaptures );
       
  3337           }
       
  3338         }
       
  3339       break;
       
  3340       }
       
  3341     // -----------------------------------------------------
       
  3342     case ECamRequestImageRelease:
       
  3343       {
       
  3344       // Cancel any pending capture.
       
  3345       ProcessImageShutdownRequest( ECamRequestImageCancel );
       
  3346 
       
  3347       // Nothing else really needed for image, just set flags.
       
  3348       ClearFlags( iInfo.iState, ECamImageOn );
       
  3349       iInfo.iCaptureCount  = 0;
       
  3350       iInfo.iSnapshotCount = 0;
       
  3351       iInfo.iCaptureState  = ECamCaptureOff;
       
  3352 
       
  3353       break;
       
  3354       }
       
  3355     // -----------------------------------------------------
       
  3356     default:
       
  3357       {
       
  3358       Panic( ECamCameraControllerCorrupt );
       
  3359       break;
       
  3360       }
       
  3361     // -----------------------------------------------------
       
  3362     }
       
  3363   PRINT( _L("Camera <= CCamCameraController::ProcessImageShutdownRequest") );
       
  3364   return ETrue; // can continue sequence, if needed
       
  3365   }
       
  3366 
       
  3367 
       
  3368 
       
  3369 // ---------------------------------------------------------------------------
       
  3370 // ProcessVideoRequestL
       
  3371 // ---------------------------------------------------------------------------
       
  3372 //
       
  3373 TInt
       
  3374 CCamCameraController
       
  3375 ::ProcessVideoRequestL( const TCamCameraRequestId& aRequestId )
       
  3376   {
       
  3377   PRINT( _L("Camera => CCamCameraController::ProcessVideoRequestL") );
       
  3378   CheckFlagOnL( iInfo.iState, ECamPowerOn, KErrNotReady );
       
  3379 
       
  3380   TInt callback( ETrue );
       
  3381 
       
  3382 #ifdef CAMERAAPP_CAE_FOR_VIDEO
       
  3383   switch( aRequestId )
       
  3384     {
       
  3385     // -----------------------------------------------------
       
  3386     case ECamRequestVideoInit:
       
  3387       {
       
  3388       PRINT( _L("Camera <> case ECamRequestVideoInit") );
       
  3389   #ifdef CAMERAAPP_CAE_FIX
       
  3390       PRINT( _L("Camera <> old CAE") );
       
  3391       // First init for video after image mode or startup
       
  3392       if( !IsFlagOn( iInfo.iState, ECamVideoOn ) )
       
  3393         {
       
  3394         iModeChange       = ECamModeChangeImage2Video;
       
  3395         iModeChangePhase  = ECamModeChangePhaseIdle; // incremented before first step
       
  3396         iModeChangeStatus = KErrNone;
       
  3397         iActive->IssueRequest();
       
  3398         }
       
  3399       // Just repeat prepare
       
  3400       else
       
  3401   #else
       
  3402       PRINT( _L("Camera <> new CAE, CCameraHandle + SetCameraReserved supported") );
       
  3403       if( !IsFlagOn( iInfo.iState, ECamVideoOn ) )
       
  3404         {
       
  3405         PRINT( _L("Camera <> CCaeEngine::EnableVideoRecording..") );
       
  3406         iCaeEngine->EnableVideoRecording();
       
  3407         }
       
  3408   #endif
       
  3409         {
       
  3410        if ( iAppController.VideoInitNeeded() )
       
  3411             {
       
  3412             PRINT( _L("Camera <> CCaeEngine::InitVideoRecorderL..") );
       
  3413             iCaeEngine->InitVideoRecorderL();
       
  3414             }
       
  3415 
       
  3416         PRINT( _L("Camera <> Ask filename..") );
       
  3417         HBufC* filename( HBufC::NewLC( KMaxFileName ) );
       
  3418         TPtr   ptr     ( filename->Des()              );
       
  3419         iSettingProvider.ProvideCameraSettingL( ECameraSettingFileName, &ptr );
       
  3420         // _LIT( KTempFilename, "C:\\video.3gp" );
       
  3421         // TPtrC ptr;
       
  3422         // ptr.Set( KTempFilename() );
       
  3423         PRINT1( _L("Camera <> Set filename [%S]"), &ptr );
       
  3424         iCaeEngine->SetVideoRecordingFileNameL( ptr );
       
  3425         CleanupStack::PopAndDestroy( filename );
       
  3426 
       
  3427         // Set max video clip size
       
  3428         ProcessSettingL( ECameraSettingFileMaxSize );
       
  3429 
       
  3430         TPckgBuf<TCamParamsVideoCae> params;
       
  3431         PRINT( _L("Camera <> Getting params from setting provider..") );
       
  3432         iSettingProvider.ProvideCameraParamL( ECameraParamVideoCae, &params );
       
  3433         // The audioOn value is defined On==0 and Off==1, but the engine expects
       
  3434         // ETrue if audio recording is On
       
  3435         params().iAudioOn = ( ECamSettOn == params().iAudioOn )
       
  3436         											? ETrue
       
  3437         											: EFalse;
       
  3438         PRINT( _L("Camera <> Calling PrepareVideoRecordingL..") );
       
  3439         PRINT2( _L("Camera <> FrameSize: (%d x %d)"), params().iFrameSize.iWidth, params().iFrameSize.iHeight );
       
  3440         if ( iAppController.VideoInitNeeded() )
       
  3441             {
       
  3442             // McaeoVideoPrepareComplete will be called when prepare is ready.
       
  3443             // The callback is allowed to come also *during* this call.
       
  3444             iCaeEngine->PrepareVideoRecordingL( params().iFrameSize,
       
  3445                     params().iFrameRate,
       
  3446                     params().iVideoBitRate,
       
  3447                     params().iAudioOn,
       
  3448                     params().iAudioBitRate,
       
  3449                     params().iMimeType,
       
  3450                     params().iSupplier,
       
  3451                     params().iVideoType,
       
  3452                     params().iAudioType );
       
  3453             }
       
  3454 
       
  3455 #ifdef CAMERAAPP_CAPI_V2_ADV
       
  3456       // Set current autofocus range to invalid value to force focusing
       
  3457       iInfo.iCurrentFocusRange = static_cast<CAS::TFocusRange>( -1 );
       
  3458 #endif // CAMERAAPP_CAPI_V2_ADV
       
  3459 
       
  3460         iAppController.SetVideoInitNeeded( EFalse );
       
  3461         // iState is updated in the callback.
       
  3462         PRINT( _L("Camera <> ..waiting for callback") );
       
  3463         }
       
  3464       break;
       
  3465       }
       
  3466     // -----------------------------------------------------
       
  3467     case ECamRequestVideoStart:
       
  3468       {
       
  3469       PRINT( _L("Camera <> case ECamRequestVideoStart") );
       
  3470       CheckFlagOnL( iInfo.iState, ECamVideoOn, KErrNotReady );
       
  3471       switch( iInfo.iCaptureState )
       
  3472         {
       
  3473         case ECamCaptureOn:     User::Leave( KErrInUse );           break;
       
  3474         case ECamCaptureOff:    iCaeEngine->StartVideoRecording();  break;
       
  3475         //case ECamCaptureOff:    iCaeEngine->ResumeVideoRecording();  break;
       
  3476         case ECamCapturePaused: iCaeEngine->ResumeVideoRecording(); break;
       
  3477         default:
       
  3478           Panic( ECamCameraControllerCorrupt );
       
  3479           break;
       
  3480         }
       
  3481       // iCaptureState is updated in McaeoVideoRecordingOn.
       
  3482       break;
       
  3483       }
       
  3484     // -----------------------------------------------------
       
  3485     case ECamRequestVideoPause:
       
  3486       {
       
  3487       PRINT( _L("Camera <> case ECamRequestVideoPause") );
       
  3488       CheckEqualsL( iInfo.iCaptureState, ECamCaptureOn, KErrNotReady );
       
  3489       iCaeEngine->PauseVideoRecording();
       
  3490       // iCaptureState is updated in McaeoVideoRecordingPaused.
       
  3491       break;
       
  3492       }
       
  3493     // -----------------------------------------------------
       
  3494     case ECamRequestVideoStop:
       
  3495       {
       
  3496       PRINT( _L("Camera <> case ECamRequestVideoStop") );
       
  3497       switch( iInfo.iCaptureState )
       
  3498         {
       
  3499         case ECamCaptureOn:     // << fall through >>
       
  3500         case ECamCapturePaused:
       
  3501           PRINT( _L("Camera <> call CCaeEngine::StopVideoRecording..") );
       
  3502           iCaeEngine->StopVideoRecording();
       
  3503           // If we got the callback during above call,
       
  3504           // we should not wait for it anymore.
       
  3505           // Check the capture state to be sure.
       
  3506           callback = (ECamCaptureOff != iInfo.iCaptureState);
       
  3507           break;
       
  3508         case ECamCaptureOff:
       
  3509           // no action, already stopped
       
  3510           break;
       
  3511         default:
       
  3512           Panic( ECamCameraControllerCorrupt );
       
  3513           break;
       
  3514         }
       
  3515       // iCaptureState is updated in McaeoVideoRecordingComplete.
       
  3516       break;
       
  3517       }
       
  3518     // -----------------------------------------------------
       
  3519     case ECamRequestVideoRelease:
       
  3520       {
       
  3521       // Need to be stopped.
       
  3522       CheckEqualsL( iInfo.iCaptureState, ECamCaptureOff, KErrInUse );
       
  3523 
       
  3524       if( IsFlagOn( iInfo.iState, ECamVideoOn ) )
       
  3525         iCaeEngine->CloseVideoRecording();
       
  3526 
       
  3527       ClearFlags( iInfo.iState, ECamVideoOn );
       
  3528       callback = EFalse;
       
  3529 #ifdef CAMERAAPP_CAPI_V2_ADV
       
  3530       GetAdvancedSettingsInfoL();
       
  3531 #endif
       
  3532       break;
       
  3533       }
       
  3534     // -----------------------------------------------------
       
  3535     case ECamRequestSetAsyncVideoStopMode:
       
  3536       {
       
  3537       TInt err = iCaeEngine->SetAsyncVideoStopMode( ETrue );
       
  3538       PRINT1( _L("Camera <> CCamCameraController::ProcessVideoRequestL, engine SetAsyncVideoStopMode return code:%d"), err );
       
  3539       iAsyncVideoStopModeSupported = !err; // Use async stop if KErrNone
       
  3540       callback = EFalse;
       
  3541       break;
       
  3542       }
       
  3543     // -----------------------------------------------------
       
  3544     default:
       
  3545       Panic( ECamCameraControllerCorrupt );
       
  3546       break;
       
  3547     // -----------------------------------------------------
       
  3548     }
       
  3549 #else
       
  3550   #pragma message("CCamCameraController::ProcessVideoRequestL not implemented!")
       
  3551   PRINT( _L("Camera <> Not supported, PANIC!") );
       
  3552   Panic( ECamCameraControllerUnsupported );
       
  3553 #endif // CAMERAAPP_CAE_FOR_VIDEO
       
  3554 
       
  3555   PRINT1( _L("Camera <= CCamCameraController::ProcessVideoRequestL, continue now:%d"), !callback );
       
  3556   return !callback;
       
  3557   }
       
  3558 
       
  3559 
       
  3560 
       
  3561 // ---------------------------------------------------------------------------
       
  3562 // ProcessSnapshotRequestL
       
  3563 // ---------------------------------------------------------------------------
       
  3564 //
       
  3565 TInt
       
  3566 CCamCameraController
       
  3567 ::ProcessSnapshotRequestL( const TCamCameraRequestId& aRequestId )
       
  3568   {
       
  3569   PRINT( _L("Camera => CCamCameraController::ProcessSnapshotRequestL") );
       
  3570   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, CCAMCAMERACONTROLLER_PROCESSSNAPSHOTREQUESTL, "e_CCamCameraController_ProcessSnapshotRequestL 1" );
       
  3571   CheckFlagOnL( iInfo.iState, ECamReserved, KErrNotReady );
       
  3572 
       
  3573   switch( aRequestId )
       
  3574     {
       
  3575     // -----------------------------------------------------
       
  3576     case ECamRequestSsStart:
       
  3577       {
       
  3578       PRINT( _L("Camera <> case ECamRequestSsStart") );
       
  3579       switch( iInfo.iSsState )
       
  3580         {
       
  3581         case ECamTriIdle:
       
  3582           PRINT( _L("Camera <> ECamTriIdle") );
       
  3583           InitSnapshotL();
       
  3584           // << fall through >>
       
  3585         case ECamTriInactive:
       
  3586           {
       
  3587           PRINT( _L("Camera <> ECamTriInactive") );
       
  3588           iSnapshotProvider->StartSnapshot();
       
  3589           OstTrace0( CAMERAAPP_PERFORMANCE, DUP2_CCAMCAMERACONTROLLER_PROCESSSNAPSHOTREQUESTL, "e_CAM_APP_OVERLAY_INIT 0" );   //CCORAPP_APP_OVERLAY_INIT_END
       
  3590           break;
       
  3591           }
       
  3592         case ECamTriActive: // Already active, no action
       
  3593           PRINT( _L("Camera <> ECamTriActive") );
       
  3594           break;
       
  3595         default:
       
  3596           Panic( ECamCameraControllerCorrupt );
       
  3597           break;
       
  3598         }
       
  3599       iInfo.iSsState = ECamTriActive;
       
  3600       break;
       
  3601       }
       
  3602     // -----------------------------------------------------
       
  3603     case ECamRequestSsStop:
       
  3604       {
       
  3605       PRINT( _L("Camera <> case ECamRequestSsStop") );
       
  3606       ProcessSsStopRequest();
       
  3607       break;
       
  3608       }
       
  3609     // -----------------------------------------------------
       
  3610     case ECamRequestSsRelease:
       
  3611       {
       
  3612       PRINT( _L("Camera <> case ECamRequestSsRelease") );
       
  3613       OstTrace0( CAMERAAPP_PERFORMANCE, DUP3_CCAMCAMERACONTROLLER_PROCESSSNAPSHOTREQUESTL, "e_CAM_APP_OVERLAY_INIT 1" );   //CCORAPP_APP_OVERLAY_INIT_START
       
  3614       ProcessSsReleaseRequest();
       
  3615       break;
       
  3616       }
       
  3617     // -----------------------------------------------------
       
  3618     default:
       
  3619       Panic( ECamCameraControllerCorrupt );
       
  3620       break;
       
  3621     // -----------------------------------------------------
       
  3622     }
       
  3623   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, DUP1_CCAMCAMERACONTROLLER_PROCESSSNAPSHOTREQUESTL, "e_CCamCameraController_ProcessSnapshotRequestL 0" );
       
  3624 
       
  3625   PRINT( _L("Camera <= CCamCameraController::ProcessSnapshotRequestL") );
       
  3626 
       
  3627   // No callback to wait for any of the requests => can continue now.
       
  3628   return ETrue;
       
  3629   }
       
  3630 
       
  3631 // ---------------------------------------------------------------------------
       
  3632 // ProcessSsStopRequest
       
  3633 // ---------------------------------------------------------------------------
       
  3634 //
       
  3635 void
       
  3636 CCamCameraController::ProcessSsStopRequest()
       
  3637   {
       
  3638   PRINT( _L("Camera <= CCamCameraController::ProcessSsStopRequest") );
       
  3639   switch( iInfo.iSsState )
       
  3640     {
       
  3641     case ECamTriIdle:     // Not even initialized yet. No action needed.
       
  3642     case ECamTriInactive: // Already inactive, no action.
       
  3643       PRINT( _L("Camera <> Snapshot idle/inactive, no need to stop") );
       
  3644       break;
       
  3645     case ECamTriActive:
       
  3646       PRINT( _L("Camera <> Snapshot ECamTriActive -> need to stop") );
       
  3647       iSnapshotProvider->StopSnapshot();
       
  3648       break;
       
  3649     default:
       
  3650       Panic( ECamCameraControllerCorrupt );
       
  3651       break;
       
  3652     }
       
  3653   iInfo.iSsState = ECamTriInactive;
       
  3654   PRINT( _L("Camera <= CCamCameraController::ProcessSsStopRequest") );
       
  3655   }
       
  3656 
       
  3657 // ---------------------------------------------------------------------------
       
  3658 // ProcessSsReleaseRequest
       
  3659 // ---------------------------------------------------------------------------
       
  3660 //
       
  3661 void
       
  3662 CCamCameraController::ProcessSsReleaseRequest()
       
  3663   {
       
  3664   PRINT( _L("Camera => CCamCameraController::ProcessSsReleaseRequest") );
       
  3665   switch( iInfo.iSsState )
       
  3666     {
       
  3667     case ECamTriIdle:    // No action needed
       
  3668       break;
       
  3669     case ECamTriActive:
       
  3670       iSnapshotProvider->StopSnapshot();
       
  3671       NotifyObservers( KErrNone,
       
  3672                        ECamCameraEventSsStop,
       
  3673                        ECamCameraEventClassSsControl );
       
  3674       // << fall through >>
       
  3675     case ECamTriInactive:
       
  3676       delete iSnapshotProvider;
       
  3677       iSnapshotProvider = NULL;
       
  3678       break;
       
  3679     default:
       
  3680       Panic( ECamCameraControllerCorrupt );
       
  3681       break;
       
  3682     }
       
  3683 
       
  3684   iInfo.iSsState = ECamTriIdle;
       
  3685   PRINT( _L("Camera <= CCamCameraController::ProcessSsReleaseRequest") );
       
  3686   }
       
  3687 
       
  3688 // ---------------------------------------------------------------------------
       
  3689 // InitSnapshotL
       
  3690 // ---------------------------------------------------------------------------
       
  3691 //
       
  3692 void
       
  3693 CCamCameraController::InitSnapshotL()
       
  3694   {
       
  3695   PRINT( _L("Camera => CCamCameraController::InitSnapshotL") );
       
  3696 
       
  3697   // Check the snapshot state here. No further checks made.
       
  3698   __ASSERT_DEBUG( ECamTriIdle == iInfo.iSsState, Panic( ECamCameraControllerCorrupt ) );
       
  3699 
       
  3700   // -------------------------------------------------------
       
  3701   // Create snapshot provider if not available yet.
       
  3702   if( !iSnapshotProvider )
       
  3703     {
       
  3704     iSnapshotProvider = CCamSnapshotProvider::NewL( *iCamera, *this, *this );
       
  3705     }
       
  3706 
       
  3707 #ifdef _DEBUG
       
  3708   PrintSnapshotInfo();
       
  3709 #endif // _DEBUG
       
  3710 
       
  3711 
       
  3712   // -------------------------------------------------------
       
  3713   // Initialize the snapshot parameters
       
  3714   TPckgBuf<TCamParamsSnapshot> params;
       
  3715   iSettingProvider.ProvideCameraParamL( ECameraParamSnapshot, &params );
       
  3716 
       
  3717   // Try to get the best, still supported, snapshot format.
       
  3718   iInfo.iSnapshotFormat         = ResolveSnapshotFormatL( params().iFormat );
       
  3719   iInfo.iSnapshotSize           = params().iSize;
       
  3720   iInfo.iSnapshotAspectMaintain = params().iMaintainAspect;
       
  3721 
       
  3722   PRINT( _L("Camera <> Prepare snapshot..") );
       
  3723   iSnapshotProvider->PrepareSnapshotL( iInfo.iSnapshotFormat,
       
  3724                                        iInfo.iSnapshotSize,
       
  3725                                        iInfo.iSnapshotAspectMaintain );
       
  3726 
       
  3727   iInfo.iSsState = ECamTriInactive;
       
  3728   // -------------------------------------------------------
       
  3729   PRINT( _L("Camera <= CCamCameraController::InitSnapshotL") );
       
  3730   }
       
  3731 
       
  3732 
       
  3733 // ---------------------------------------------------------------------------
       
  3734 // CCamCameraController::ProcessAutofocusRequestL
       
  3735 // ---------------------------------------------------------------------------
       
  3736 //
       
  3737 void CCamCameraController::ProcessAutofocusRequestL( const TCamCameraRequestId& aRequestId )
       
  3738   {
       
  3739   PRINT( _L("Camera => CCamCameraController::ProcessAutofocusRequestL") );
       
  3740 #ifdef CAMERAAPP_CAPI_V2_ADV
       
  3741  CheckNonNullL( iAdvancedSettings, KErrNotReady );
       
  3742   if( ECamRequestStartAutofocus == aRequestId )
       
  3743     {
       
  3744     PRINT( _L("Camera <> SetAutoFocusType( EAutoFocusTypeSingle )") );
       
  3745     iAdvancedSettings->SetAutoFocusType( CAS::EAutoFocusTypeSingle );
       
  3746     iAfInProgress = ETrue;
       
  3747     iFirstAfEventReceived = EFalse;
       
  3748     }
       
  3749   else if( ECamRequestCancelAutofocus == aRequestId )
       
  3750     {
       
  3751     if( iAfInProgress && iInfo.iCurrentCamera == KPrimaryCameraIndex )
       
  3752       {
       
  3753       // Autofocus in progress, need to cancel it before setting range to hyperfocal
       
  3754       PRINT( _L("Camera <> Cancel ongoing autofocus request") );
       
  3755       iAdvancedSettings->SetAutoFocusType( CAS::EAutoFocusTypeOff );
       
  3756       iAfHyperfocalPending = ETrue;
       
  3757       }
       
  3758     else
       
  3759       {
       
  3760       // If focustype is set to continuous, need to change it to off
       
  3761 	  // before continuing
       
  3762 
       
  3763       PRINT( _L("Camera <> SetAutoFocusType( EAutoFocusTypeOff )") );
       
  3764       if ( iAdvancedSettings->AutoFocusType() & CAS::EAutoFocusTypeContinuous )
       
  3765         {
       
  3766         iAdvancedSettings->SetAutoFocusType( CAS::EAutoFocusTypeOff );
       
  3767         }
       
  3768 
       
  3769       PRINT( _L("Camera <> Cancel autofocus - set focus range to hyperfocal") );
       
  3770       iInfo.iCurrentFocusRange = CAS::EFocusRangeHyperfocal;
       
  3771       iAdvancedSettings->SetFocusRange( CAS::EFocusRangeHyperfocal );
       
  3772 
       
  3773       // Then start the focus. The callback of this cancel request sets
       
  3774       // a boolean in CamAppController, so the resulting optimal
       
  3775       // focus event does not change reticule/focus state.
       
  3776       iAdvancedSettings->SetAutoFocusType( CAS::EAutoFocusTypeSingle );
       
  3777       iAfInProgress = ETrue;
       
  3778       }
       
  3779     }
       
  3780   else if( ECamRequestSetAfRange == aRequestId )
       
  3781     {
       
  3782     PRINT( _L("Camera <> Set autofocus range") );
       
  3783     // Get autofocus mode from settings provider
       
  3784 
       
  3785     CAS::TFocusRange afRange;
       
  3786     iSettingProvider.ProvideCameraSettingL( ECameraSettingFocusRange, &afRange );
       
  3787 
       
  3788     if( iInfo.iCurrentFocusRange != afRange )
       
  3789       {
       
  3790       iAdvancedSettings->SetFocusRange( afRange );
       
  3791 
       
  3792       // Should this be done in the callback?:
       
  3793       iInfo.iCurrentFocusRange = afRange;
       
  3794       }
       
  3795     else
       
  3796       {
       
  3797       // Correct range already set. No need to do anything.
       
  3798       }
       
  3799     }
       
  3800   else
       
  3801     {
       
  3802     // Other request must not end up here
       
  3803     __ASSERT_DEBUG( EFalse, Panic( ECamCameraControllerCorrupt ) );
       
  3804     }
       
  3805 #endif // CAMERAAPP_CAPI_V2_ADV
       
  3806 
       
  3807   (void)aRequestId; // removes compiler warning
       
  3808   PRINT( _L("Camera <= CCamCameraController::ProcessAutofocusRequestL") );
       
  3809   }
       
  3810 
       
  3811 
       
  3812 
       
  3813 // ---------------------------------------------------------------------------
       
  3814 // ProcessCaptureLimitSettingL
       
  3815 // ---------------------------------------------------------------------------
       
  3816 //
       
  3817 void
       
  3818 CCamCameraController::ProcessCaptureLimitSettingL()
       
  3819   {
       
  3820   PRINT ( _L("Camera => CCamCameraController::ProcessCaptureLimitSettingL") );
       
  3821 #ifdef CAMERAAPP_CAPI_V2_ADV
       
  3822   // Check that we are prepared for image mode.
       
  3823   CheckFlagOnL( iInfo.iState, ECamImageOn, KErrNotReady );
       
  3824 
       
  3825   // Get requested capture count and determine current and target drive modes.
       
  3826   TInt requestedLimit( 1 );
       
  3827   iSettingProvider.ProvideCameraSettingL( ECameraSettingCaptureLimit, &requestedLimit );
       
  3828   if( requestedLimit < 1 ) User::Leave( KErrArgument );
       
  3829 
       
  3830   const CAS::TDriveMode& currentMode( iAdvancedSettings->DriveMode() );
       
  3831   const CAS::TDriveMode  targetMode ( requestedLimit <= 1
       
  3832                                     ? CAS::EDriveModeSingleShot
       
  3833                                     : CAS::EDriveModeBurst      );
       
  3834   const TInt cameraLimit( iAdvancedSettings->BurstImages() );
       
  3835 
       
  3836   PRINT ( _L("Camera <> CCamCameraController .. --------------------------------------") );
       
  3837   PRINT1( _L("Camera <> CCamCameraController .. requested capture  limit   %04d"), requestedLimit                  );
       
  3838   PRINT1( _L("Camera <> CCamCameraController .. current   capture  limit : %04d"), iInfo.iCaptureLimit           );
       
  3839   PRINT1( _L("Camera <> CCamCameraController .. current   camera's limit : %04d"), cameraLimit                   );
       
  3840   PRINT1( _L("Camera <> CCamCameraController .. current   capture  count : %04d"), iInfo.iCaptureCount           );
       
  3841   PRINT1( _L("Camera <> CCamCameraController .. current   snapshot count : %04d"), iInfo.iSnapshotCount          );
       
  3842   PRINT1( _L("Camera <> CCamCameraController .. current drive mode       : [%S]"), &DriveModeName( currentMode ) );
       
  3843   PRINT1( _L("Camera <> CCamCameraController .. target  drive mode       : [%S]"), &DriveModeName( targetMode  ) );
       
  3844   PRINT ( _L("Camera <> CCamCameraController .. --------------------------------------") );
       
  3845 
       
  3846   // -------------------------------------------------------
       
  3847   // Determine needed changes and when to issue them
       
  3848   //
       
  3849   // During burst capture, we may receive snapshots and
       
  3850   // image data on mixed order, e.g:
       
  3851   //
       
  3852   //   [ ss#1 | img#1 | ss#2 | ss#3 | img2 | img3 ]
       
  3853   //   --------------^^--------------------------^^
       
  3854   //
       
  3855   // C-API starts new burst capture when we adjust the
       
  3856   // capture limit. To avoid problems and to get equal
       
  3857   // amount of snapshots and images, capture count is
       
  3858   // only changed when we image data is received,
       
  3859   // and as many images as snapshots have arrived.
       
  3860   // In the chart above ^ marks a place where capture limit
       
  3861   // can be updated.
       
  3862   TBool callback( EFalse );
       
  3863 
       
  3864   // -----------------------------------
       
  3865   // Capture ongoing..
       
  3866   if( ECamCaptureOn == iInfo.iCaptureState )
       
  3867     {
       
  3868     PRINT( _L("Camera <> CCamCameraController .. Capture ongoing..") );
       
  3869     if( targetMode != currentMode )
       
  3870       {
       
  3871       // Cannot change drive mode during capturing.
       
  3872       PRINT( _L("Camera <> CCamCameraController .. Drive mode update not possible now, LEAVE!") );
       
  3873       User::Leave( KErrInUse );
       
  3874       }
       
  3875     else if ( CAS::EDriveModeBurst == currentMode )
       
  3876       {
       
  3877       if( cameraLimit != requestedLimit )
       
  3878         {
       
  3879         PRINT( _L("Camera <> CCamCameraController .. Adjusting capture limit during burst..") );
       
  3880         // Set limit locally and react on next image data event.
       
  3881         iInfo.iCaptureLimit = Min( cameraLimit, Max( requestedLimit, iInfo.iCaptureCount+1 ) );
       
  3882         PRINT1( _L("Camera <> CCamCameraController .. Set local capture limit to %d.."), iInfo.iCaptureLimit );
       
  3883         }
       
  3884       else
       
  3885         {
       
  3886         PRINT( _L("Camera <> CCamCameraController .. Capture limit during burst already has right value.") );
       
  3887         }
       
  3888       }
       
  3889     else
       
  3890       {
       
  3891       // No action needed. Capture limit of 1 image kept.
       
  3892       PRINT( _L("Camera <> CCamCameraController .. Single shot mode kept, no action") );
       
  3893       }
       
  3894     }
       
  3895   // -----------------------------------
       
  3896   // Not capturing
       
  3897   //
       
  3898   else
       
  3899     {
       
  3900     PRINT( _L("Camera <> CCamCameraController .. No capture ongoing..") );
       
  3901 
       
  3902     iInfo.iCaptureLimit = requestedLimit;
       
  3903     // Capture limit has changed,
       
  3904     // check if drive mode also needs to be changed..
       
  3905     if( targetMode != currentMode )
       
  3906       {
       
  3907       PRINT1( _L("Camera <> CCamCameraController .. Calling SetDriveMode([%S])"), &DriveModeName( targetMode  ) );
       
  3908       iAdvancedSettings->SetDriveMode( targetMode );
       
  3909       }
       
  3910     if( CAS::EDriveModeBurst == targetMode )
       
  3911       {
       
  3912       PRINT1( _L("Camera <> CCamCameraController .. Calling SetBurstImages(%d).."), iInfo.iCaptureLimit );
       
  3913       iAdvancedSettings->SetBurstImages( iInfo.iCaptureLimit );
       
  3914       }
       
  3915     }
       
  3916 
       
  3917   // -------------------------------------------------------
       
  3918   // Notify user that the change is done
       
  3919   // or wait for camera callbacks to finish.
       
  3920   PRINT1( _L("Camera <> CCamCameraController .. Should wait callback = %d"), callback );
       
  3921   if( !callback )
       
  3922     {
       
  3923     TInt setting( ECameraSettingCaptureLimit );
       
  3924     NotifyObservers( KErrNone,
       
  3925                      ECamCameraEventSettingsSingle,
       
  3926                      ECamCameraEventClassSettings,
       
  3927                      &setting );
       
  3928     }
       
  3929 #else
       
  3930   User::Leave( KErrNotSupported );
       
  3931 #endif // CAMERAAPP_CAPI_V2_ADV
       
  3932   PRINT ( _L("Camera <= CCamCameraController::ProcessCaptureLimitSettingL") );
       
  3933   }
       
  3934 
       
  3935 
       
  3936 
       
  3937 // ---------------------------------------------------------------------------
       
  3938 // EndSequence
       
  3939 // ---------------------------------------------------------------------------
       
  3940 //
       
  3941 void
       
  3942 CCamCameraController::EndSequence( TInt aStatus )
       
  3943   {
       
  3944   PRINT1( _L("Camera => CCamCameraController::EndSequence, status:%d"), aStatus );
       
  3945 
       
  3946   iIveRecoveryOngoing = EFalse;
       
  3947   iIveSequenceActive = EFalse;
       
  3948 #ifdef CAMERAAPP_CAE_FIX
       
  3949   if( ECamModeChangeInactive != iModeChange )
       
  3950     {
       
  3951     PRINT( _L("Camera <> mode change not cleared, PANIC!!") );
       
  3952     Panic( ECamCameraControllerUnrecovableError );
       
  3953     }
       
  3954 #endif // CAMERAAPP_CAE_FIX
       
  3955   // -------------------------------------------------------
       
  3956   if( IsFlagOn( iInfo.iBusy, ECamBusySequence ) )
       
  3957     {
       
  3958     CAMERAAPP_PERF_CONTROLLER_STOP( ECamRequestNone );
       
  3959 
       
  3960     PRINT( _L("Camera <> ending sequence..") );
       
  3961     ClearRequestQueue();
       
  3962     iReserveTryAgainCount = KCamReserveTryAgainMaxCount;
       
  3963 
       
  3964 
       
  3965     // Need to first clear busy flag as observer might issue
       
  3966     // new requests in notification callback.
       
  3967     ClearFlags( iInfo.iBusy, ECamBusySequence );
       
  3968 
       
  3969     PRINT( _L("Camera <> send notification..") );
       
  3970     NotifyObservers( aStatus,
       
  3971                      ECamCameraEventSequenceEnd,
       
  3972                      ECamCameraEventClassBasicControl );
       
  3973     }
       
  3974   // -------------------------------------------------------
       
  3975   else if( IsFlagOn( iInfo.iBusy, ECamBusySetting ) )
       
  3976     {
       
  3977     PRINT( _L("Camera <> ending settings handling..") );
       
  3978 
       
  3979 
       
  3980     TCamCameraSettingId last( ECameraSettingNone );
       
  3981     if( KErrNone != aStatus )
       
  3982       {
       
  3983       if( Rng( 0, iSettingIndex, iSettingArray.Count()-1 ) )
       
  3984          {
       
  3985          last = iSettingArray[iSettingIndex];
       
  3986          }
       
  3987       }
       
  3988     ClearSettingQueue();
       
  3989 
       
  3990     ClearFlags( iInfo.iBusy, ECamBusySetting );
       
  3991 
       
  3992     NotifyObservers( aStatus,
       
  3993                      ECamCameraEventSettingsDone,
       
  3994                      ECamCameraEventClassSettings,
       
  3995                      &last );
       
  3996     }
       
  3997   // -------------------------------------------------------
       
  3998   else
       
  3999     {
       
  4000     PRINT( _L("Camera <> No active operation, no action needed") );
       
  4001     }
       
  4002   // -------------------------------------------------------
       
  4003   PRINT( _L("Camera <= CCamCameraController::EndSequence") );
       
  4004   }
       
  4005 
       
  4006 
       
  4007 
       
  4008 // ---------------------------------------------------------------------------
       
  4009 // ClearRequestQueue
       
  4010 // ---------------------------------------------------------------------------
       
  4011 //
       
  4012 void
       
  4013 CCamCameraController::ClearRequestQueue()
       
  4014   {
       
  4015   iSequenceArray.Reset();
       
  4016   iSequenceIndex = -1;
       
  4017   }
       
  4018 
       
  4019 // ---------------------------------------------------------------------------
       
  4020 // ClearSettingQueue
       
  4021 // ---------------------------------------------------------------------------
       
  4022 //
       
  4023 void
       
  4024 CCamCameraController::ClearSettingQueue()
       
  4025   {
       
  4026   iSettingArray.Reset();
       
  4027   iSettingIndex = -1;
       
  4028   }
       
  4029 
       
  4030 
       
  4031 
       
  4032 
       
  4033 // ---------------------------------------------------------------------------
       
  4034 // HandlePowerOnEvent
       
  4035 // ---------------------------------------------------------------------------
       
  4036 //
       
  4037 void
       
  4038 CCamCameraController::HandlePowerOnEvent( TInt aStatus )
       
  4039   {
       
  4040   PRINT1( _L("Camera => CCamCameraController::HandlePowerOnEvent, status:%d"), aStatus );
       
  4041 
       
  4042   // We should be blocking new request at the moment.
       
  4043   __ASSERT_DEBUG( iInfo.iBusy, Panic( ECamCameraControllerCorrupt ) );
       
  4044   CAMERAAPP_PERF_CONTROLLER_STOP( ECamRequestPowerOn );
       
  4045 
       
  4046   OstTrace0( CAMERAAPP_PERFORMANCE, CCAMCAMERACONTROLLER_HANDLEPOWERONEVENT, "e_CAM_APP_INIT 0" );  //CCORAPP_APP_INIT_END
       
  4047   OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMCAMERACONTROLLER_HANDLEPOWERONEVENT, "e_CAM_APP_VF_INIT 1" );  //CCORAPP_APP_VF_INIT_START
       
  4048   OstTrace0( CAMERAAPP_PERFORMANCE, DUP2_CCAMCAMERACONTROLLER_HANDLEPOWERONEVENT, "e_CAM_APP_CONFIGURATIONS 1" );   //CCORAPP_APP_CONFIGS_START
       
  4049   OstTrace0( CAMERAAPP_PERFORMANCE, DUP3_CCAMCAMERACONTROLLER_HANDLEPOWERONEVENT, "e_CAM_APP_STILL_INIT 1" );   //CCORAPP_APP_STILL_INIT_START
       
  4050 
       
  4051   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  4052 
       
  4053   if ( appUi->AppController().UiConfigManagerPtr()->IsFaceTrackingSupported() )
       
  4054       {
       
  4055       PRINT( _L("Camera <> CCamAppController: Get i/f MCameraFaceTracking..") )
       
  4056       iCustomInterfaceFaceTracking =
       
  4057           static_cast <MCameraFaceTracking*>(
       
  4058             iCamera->CustomInterface( KCameraFaceTrackingUid ) );
       
  4059       PRINT1( _L("Camera <> Face Tracking custom i/f pointer:%d"), iCustomInterfaceFaceTracking );
       
  4060       }
       
  4061 
       
  4062   if( KErrNone == aStatus )
       
  4063     {
       
  4064     SetFlags( iInfo.iState, ECamPowerOn|ECamReserved );
       
  4065 
       
  4066 #if defined( CAMERAAPP_CAE_FOR_VIDEO ) && !defined( CAMERAAPP_CAE_FIX )
       
  4067     // We need to tell to CCaeEngine that the CCamera has been reserved
       
  4068     // and powered on "behind its back".
       
  4069     if( iCaeEngine )
       
  4070       {
       
  4071       iCaeEngine->EnableVideoRecording();
       
  4072       }
       
  4073 #endif
       
  4074     }
       
  4075   else
       
  4076     {
       
  4077     ClearFlags( iInfo.iState, ECamPowerOn );
       
  4078     }
       
  4079 
       
  4080 #ifdef CAMERAAPP_CAE_FIX
       
  4081   if( ECamModeChangeVideo2Image == iModeChange )
       
  4082     {
       
  4083     if( ECamModeChangePhase2 == iModeChangePhase )
       
  4084       {
       
  4085       // We have called CCamera::PowerOn in phase2
       
  4086       PRINT( _L("Camera <> mode change image->video ongoing, continue") );
       
  4087       iModeChangeStatus = aStatus;
       
  4088       // Handle repeative events before iActive gets to run.
       
  4089       if( !iActive->IsActive() )
       
  4090         iActive->IssueRequest();
       
  4091       }
       
  4092     }
       
  4093   else if( ECamModeChangeImage2Video == iModeChange )
       
  4094     {
       
  4095     if( ECamModeChangePhase1 == iModeChangePhase )
       
  4096       {
       
  4097       // We have called CCaeEngine::InitL in phase1
       
  4098       PRINT( _L("Camera <> mode change image->video ongoing, continue") );
       
  4099       iModeChangeStatus = aStatus;
       
  4100       // Handle repeative events before iActive gets to run.
       
  4101       if( !iActive->IsActive() )
       
  4102         iActive->IssueRequest();
       
  4103       }
       
  4104     }
       
  4105   else
       
  4106     {
       
  4107     PRINT( _L("Camera <> no mode change ongoing") );
       
  4108     HandleCallbackEvent( aStatus,
       
  4109                          ECamCameraEventPowerOn,
       
  4110                          ECamCameraEventClassBasicControl );
       
  4111     }
       
  4112 #else
       
  4113 
       
  4114   HandleCallbackEvent( aStatus,
       
  4115                        ECamCameraEventPowerOn,
       
  4116                        ECamCameraEventClassBasicControl );
       
  4117 
       
  4118 #endif // CAMERAAPP_CAE_FIX
       
  4119 
       
  4120   if ( appUi->AppController().UiConfigManagerPtr()->IsOrientationSensorSupported() )
       
  4121       {
       
  4122       PRINT( _L("Camera <> CCamCameraController: Get i/f MCameraOrientation..") )
       
  4123 
       
  4124       if(!iCustomInterfaceOrientation )
       
  4125           {
       
  4126           iCustomInterfaceOrientation =
       
  4127           static_cast <MCameraOrientation*>(
       
  4128           iCamera->CustomInterface( KCameraOrientationUid ) );
       
  4129           }
       
  4130 
       
  4131       PRINT1( _L("Camera <> Orientation custom i/f pointer:%d"), iCustomInterfaceOrientation );
       
  4132       }
       
  4133 
       
  4134   PRINT( _L("Camera <= CCamCameraController::HandlePowerOnEvent") );
       
  4135   }
       
  4136 
       
  4137 // ---------------------------------------------------------------------------
       
  4138 // HandleReserveGainEvent
       
  4139 // ---------------------------------------------------------------------------
       
  4140 //
       
  4141 void
       
  4142 CCamCameraController::HandleReserveGainEvent( TInt aStatus )
       
  4143   {
       
  4144   PRINT1( _L("Camera => CCamCameraController::HandleReserveGainEvent, status:%d"), aStatus );
       
  4145   iAfInProgress = EFalse;  // Stop waiting autofocus events, if reserving camera.
       
  4146 
       
  4147   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  4148   if( appUi->StandbyStatus() && !appUi->IsRecoverableStatus() )
       
  4149       {
       
  4150       PRINT( _L("Camera <= CCamCameraController::HandleReserveGainEvent - return, in non recoverable standby state"));
       
  4151       return;
       
  4152       }
       
  4153   if( iIdle && iIdle->IsActive() )
       
  4154     {
       
  4155     PRINT( _L("Camera => CCamCameraController::HandleReserveGainEvent - return, recovery in progress"));
       
  4156     return;
       
  4157     }
       
  4158   if( iIveRecoveryOngoing && !iIveSequenceActive )
       
  4159     {
       
  4160     PRINT( _L("Camera => CCamCameraController::HandleReserveGainEvent - first recovering sequence command executed"));
       
  4161     iIveSequenceActive = ETrue;
       
  4162     }
       
  4163   // We should be blocking new request at the moment.
       
  4164   __ASSERT_DEBUG( iInfo.iBusy, Panic( ECamCameraControllerCorrupt ) );
       
  4165   CAMERAAPP_PERF_CONTROLLER_STOP( ECamRequestReserve );
       
  4166 
       
  4167   if( KErrNone == aStatus ) SetFlags  ( iInfo.iState, ECamReserved );
       
  4168   else                      ClearFlags( iInfo.iState, ECamReserved );
       
  4169 
       
  4170   // Make sure our priority is not downgraded
       
  4171   CEikonEnv* env = CEikonEnv::Static();
       
  4172   env->WsSession().ComputeMode(RWsSession::EPriorityControlDisabled);
       
  4173 
       
  4174 #ifdef CAMERAAPP_CAE_FIX
       
  4175   if( ECamModeChangeVideo2Image == iModeChange )
       
  4176     {
       
  4177     if( ECamModeChangePhase1 == iModeChangePhase )
       
  4178       {
       
  4179       // We have called CCamera::Reserve in phase1
       
  4180       PRINT( _L("Camera <> mode change video->image ongoing, continue") );
       
  4181       iModeChangeStatus = aStatus;
       
  4182       // Handle repeative events before iActive gets to run.
       
  4183       if( !iActive->IsActive() )
       
  4184         iActive->IssueRequest();
       
  4185       }
       
  4186     }
       
  4187   else if( ECamModeChangeImage2Video == iModeChange )
       
  4188     {
       
  4189     // No action yet, wait for power on event
       
  4190     PRINT( _L("Camera <> mode change image->video ongoing, waiting for power on event") );
       
  4191     }
       
  4192   else
       
  4193     {
       
  4194     PRINT( _L("Camera <> no mode change ongoing") );
       
  4195     HandleCallbackEvent( aStatus,
       
  4196                          ECamCameraEventReserveGain,
       
  4197                          ECamCameraEventClassBasicControl );
       
  4198     }
       
  4199 #else
       
  4200   HandleCallbackEvent( aStatus,
       
  4201                        ECamCameraEventReserveGain,
       
  4202                        ECamCameraEventClassBasicControl );
       
  4203 #endif // CAMERAAPP_CAE_FIX
       
  4204   PRINT( _L("Camera <= CCamCameraController::HandleReserveGainEvent") );
       
  4205   }
       
  4206 
       
  4207 
       
  4208 
       
  4209 // ---------------------------------------------------------------------------
       
  4210 // HandleReserveLostEvent
       
  4211 // ---------------------------------------------------------------------------
       
  4212 //
       
  4213 void
       
  4214 CCamCameraController::HandleReserveLostEvent( TInt aStatus )
       
  4215   {
       
  4216   PRINT1( _L("Camera => CCamCameraController::HandleReserveLostEvent, status:%d"), aStatus );
       
  4217   iInfo.iState   = ECamIdle;
       
  4218   iInfo.iVfState = ECamTriIdle;
       
  4219   iInfo.iSsState = ECamTriIdle;
       
  4220 
       
  4221 #pragma message("CCamCameraController: Reserve lost event does not stop sequence")
       
  4222 
       
  4223   // These are not valid anymore.
       
  4224   ReleaseCustomInterfaces();
       
  4225 
       
  4226 #ifdef CAMERAAPP_CAE_FOR_VIDEO
       
  4227   // -------------------------------------------------------
       
  4228 #ifdef CAMERAAPP_CAE_FIX
       
  4229 #ifdef CAMERAAPP_CAPI_V2
       
  4230   if( ECamModeChangeVideo2Image == iModeChange )
       
  4231     {
       
  4232     // ignore
       
  4233     }
       
  4234   else if( ECamModeChangeImage2Video == iModeChange )
       
  4235     {
       
  4236     // ignore
       
  4237     }
       
  4238   else
       
  4239 #endif // CAMERAAPP_CAPI_V2
       
  4240     {
       
  4241     PRINT( _L("Camera <> no mode change ongoing") );
       
  4242     NotifyObservers( aStatus,
       
  4243                      ECamCameraEventReserveLose,
       
  4244                      ECamCameraEventClassBasicControl );
       
  4245     }
       
  4246 
       
  4247 #else // CAMERAAPP_CAE_FIX
       
  4248 /*
       
  4249   // We need to tell to CCaeEngine that the CCamera
       
  4250   // has been released "behind its back".
       
  4251   if( iCaeEngine )
       
  4252     {
       
  4253     iCaeEngine->DisableVideoRecording();
       
  4254     }
       
  4255 */
       
  4256 #endif // CAMERAAPP_CAE_FIX
       
  4257   // -------------------------------------------------------
       
  4258 #else
       
  4259 
       
  4260   NotifyObservers( aStatus,
       
  4261                    ECamCameraEventReserveLose,
       
  4262                    ECamCameraEventClassBasicControl );
       
  4263   // -------------------------------------------------------
       
  4264 #endif // CAMERAAPP_CAE_FOR_VIDEO
       
  4265 
       
  4266   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  4267   TInt err = KErrNone;
       
  4268   if( !iIdle )
       
  4269     {
       
  4270     TRAP( err, iIdle = CIdle::NewL( CActive::EPriorityIdle ) );
       
  4271     }
       
  4272 
       
  4273   PRINT1( _L("Camera <> CCamCameraController::HandleReserveLostEvent iIveRecoveryOngoing = %d"), iIveRecoveryOngoing );
       
  4274   if ( !err && iIdle && !iIdle->IsActive() && // Recovering already
       
  4275        iAppController.IsAppUiAvailable()  && // Exit mode
       
  4276        iIveRecoveryCount &&                   // Give up eventually
       
  4277        !appUi->AppInBackground( EFalse ) &&   // Only if on the foreground
       
  4278        ( !iReleasedByUi ||             // Try recover if unknown reason
       
  4279          ( appUi->StandbyStatus() && appUi->IsRecoverableStatus() ) ) &&    // or known error 
       
  4280          !iAppController.InVideocallOrRinging() && // Video telephony parallel use case
       
  4281          !iIveRecoveryOngoing        //  processing recovery sequence
       
  4282          )
       
  4283     {
       
  4284     PRINT( _L("Camera <> CCamCameraController::HandleReserveLostEvent - Start recovery") );
       
  4285     NotifyObservers( aStatus,
       
  4286                      ECamCameraEventReserveLose,
       
  4287                      ECamCameraEventClassBasicControl );
       
  4288     iIdle->Start( TCallBack( IdleCallback, this ) );
       
  4289     }
       
  4290   PRINT( _L("Camera <= CCamCameraController::HandleReserveLostEvent") );
       
  4291   }
       
  4292 
       
  4293 // ---------------------------------------------------------------------------
       
  4294 // HandleViewfinderEvent
       
  4295 // ---------------------------------------------------------------------------
       
  4296 //
       
  4297 void
       
  4298 CCamCameraController::HandleViewfinderEvent( MCameraBuffer* aCameraBuffer,
       
  4299                                              TInt           aStatus )
       
  4300   {
       
  4301   PRINT_FRQ1( _L("Camera => CCamCameraController::HandleViewfinderEvent, status in:%d"), aStatus );
       
  4302 
       
  4303   CAMERAAPP_PERF_CONTROLLER_STOP_ONCE( ECamRequestVfStart, iFirstVfFrameReceived );
       
  4304 
       
  4305   CFbsBitmap* vfFrame = NULL;
       
  4306 
       
  4307   if( KErrNone == aStatus )
       
  4308     {
       
  4309     __ASSERT_ALWAYS( aCameraBuffer, Panic( ECamCameraControllerCorrupt ) );
       
  4310 
       
  4311     PRINT_FRQ( _L("Camera <> get new one..") );
       
  4312     TRAP( aStatus,
       
  4313       {
       
  4314       vfFrame = &(aCameraBuffer->BitmapL( 0 ));
       
  4315       });
       
  4316     PRINT_FRQ1( _L("Camera <> ..status after getting bitmap data: %d"), aStatus );
       
  4317     }
       
  4318 
       
  4319   NotifyObservers( aStatus,
       
  4320                    ECamCameraEventVfFrameReady,
       
  4321                    ECamCameraEventClassVfData,
       
  4322                    vfFrame );
       
  4323 
       
  4324   ReleaseAndNull( aCameraBuffer );
       
  4325 
       
  4326   PRINT_FRQ( _L("Camera <= CCamCameraController::HandleViewfinderEvent") );
       
  4327   }
       
  4328 
       
  4329 
       
  4330 // ---------------------------------------------------------------------------
       
  4331 // HandleImageCaptureEvent
       
  4332 // ---------------------------------------------------------------------------
       
  4333 //
       
  4334 void
       
  4335 CCamCameraController::HandleImageCaptureEvent( MCameraBuffer* aCameraBuffer,
       
  4336                                                TInt           aStatus )
       
  4337   {
       
  4338   PRINT1( _L("Camera => CCamCameraController::HandleImageCaptureEvent, status in: %d"), aStatus );
       
  4339 
       
  4340 
       
  4341   // Check that we are expecting images..
       
  4342   if( ECamCaptureOn == iInfo.iCaptureState )
       
  4343     {
       
  4344     // Store flags
       
  4345     TUint busyFlags( iInfo.iBusy );
       
  4346 
       
  4347     // -----------------------------------------------------
       
  4348     // Try to get the image data.
       
  4349     if( KErrNone == aStatus )
       
  4350       {
       
  4351       // Takes ownership of aCameraBuffer and NULLs the pointer.
       
  4352       TRAP( aStatus, HandleImageCaptureEventL( aCameraBuffer ) );
       
  4353       PRINT1( _L("Camera <> status after handling data: %d"), aStatus );
       
  4354       }
       
  4355 
       
  4356     // Release if not NULLed in HandleImageCaptureEventL.
       
  4357     ReleaseAndNull( aCameraBuffer );
       
  4358 
       
  4359     // -----------------------------------------------------
       
  4360     // Errors in or in handling
       
  4361     if( KErrNone != aStatus )
       
  4362       {
       
  4363       PRINT( _L("Camera <> CCamCameraController ... [WARNING] error in image data event!") );
       
  4364       iInfo.PrintInfo();
       
  4365 
       
  4366       iInfo.iCaptureState = ECamCaptureOff;
       
  4367 
       
  4368       // See HandleCallbackEvent for comments.
       
  4369       // ClearFlags( iInfo.iBusy, ECamBusySingle );
       
  4370 
       
  4371       NotifyObservers( aStatus,
       
  4372                        ECamCameraEventImageData,
       
  4373                        ECamCameraEventClassImage );
       
  4374       }
       
  4375     // -----------------------------------------------------
       
  4376 
       
  4377     // If capture state was just changed to OFF,
       
  4378     // send notification that capture has fully completed.
       
  4379     if( ECamCaptureOff == iInfo.iCaptureState )
       
  4380       {
       
  4381       // See HandleCallbackEvent for comments.
       
  4382       ClearFlags( iInfo.iBusy, ECamBusySingle );
       
  4383 
       
  4384       TInt fullCaptures( Min( iInfo.iCaptureCount, iInfo.iSnapshotCount ) );
       
  4385       NotifyObservers( aStatus,
       
  4386                        ECamCameraEventImageStop,
       
  4387                        ECamCameraEventClassImage,
       
  4388                        &fullCaptures );
       
  4389 
       
  4390       // Now we can actually continue, if necessary.
       
  4391       if( IsFlagOn( busyFlags, ECamBusySequence ) )
       
  4392         {
       
  4393         __ASSERT_DEBUG( iActive, Panic( ECamCameraControllerCorrupt ) );
       
  4394         iActive->IssueRequest();
       
  4395         }
       
  4396       }
       
  4397     }
       
  4398   else
       
  4399     {
       
  4400     PRINT( _L("Camera <> CCamCameraController ... [WARNING] Unexpected image data event!") );
       
  4401     iInfo.PrintInfo();
       
  4402 
       
  4403     // Stop capture to be safe.
       
  4404     PRINT( _L("Camera <> CCamCameraController ... Calling CancelCaptureImage..") );
       
  4405     iCamera->CancelCaptureImage();
       
  4406 
       
  4407     // Not expecting image data at this time.
       
  4408     // Release the buffer and ignore event.
       
  4409     ReleaseAndNull( aCameraBuffer );
       
  4410     }
       
  4411   PRINT( _L("Camera <= CCamCameraController::HandleImageCaptureEvent") );
       
  4412   }
       
  4413 
       
  4414 // ---------------------------------------------------------------------------
       
  4415 // HandleImageCaptureEventL
       
  4416 // ---------------------------------------------------------------------------
       
  4417 //
       
  4418 void
       
  4419 CCamCameraController::HandleImageCaptureEventL( MCameraBuffer*& aCameraBuffer )
       
  4420   {
       
  4421   PRINT( _L("Camera => CCamCameraController::HandleImageCaptureEventL") );
       
  4422   CheckNonNullL( aCameraBuffer, KErrNotFound );
       
  4423 
       
  4424   MCameraBuffer* temp = aCameraBuffer;
       
  4425   aCameraBuffer = NULL; // ownership taken
       
  4426 
       
  4427   PRINT( _L("Camera <> Wrap MCameraBuffer to sharable..") );
       
  4428   CleanupStack::PushL( TCleanupItem( CameraBufferCleanup, temp ) );
       
  4429   CCamBufferShare* share = new (ELeave) CCamBufferShare( temp );
       
  4430   CleanupStack::Pop(); // cleanup item
       
  4431   temp = NULL;         // ownership to share
       
  4432 
       
  4433   share->Reserve();
       
  4434   CleanupStack::PushL( TCleanupItem( CamBufferShareCleanup, share ) );
       
  4435 
       
  4436   PRINT( _L("Camera <> CCamCameraController .. Checking encoded data availability..") );
       
  4437   TRAPD( dataStatus,
       
  4438     {
       
  4439     TDesC8* data = share->SharedBuffer()->DataL( 0 );
       
  4440     if( !data )
       
  4441       User::Leave( KErrNotFound );
       
  4442     });
       
  4443 
       
  4444   // -------------------------------------------------------
       
  4445   // Normal capture format case
       
  4446   if( KErrNone == dataStatus )
       
  4447     {
       
  4448     PRINT( _L("Camera <> CCamCameraController .. Normal, encoded capture format found..") );
       
  4449 
       
  4450     // Increase received images count. Needed in burst drive mode.
       
  4451     iInfo.iCaptureCount++;
       
  4452     PRINT1( _L("Camera <> CCamCameraController ... Incremented capture counter to: %d"), iInfo.iCaptureCount );
       
  4453 
       
  4454     // If we have needed amount of snapshots and images, end capture.
       
  4455     if( iInfo.iCaptureCount  >= iInfo.iCaptureLimit
       
  4456      && ( (iInfo.iSnapshotCount >= iInfo.iCaptureLimit) || iInfo.iSsState != ECamTriActive ) )
       
  4457       {
       
  4458       PRINT( _L("Camera <> CCamCameraController ... Capture limit met, calling CancelCaptureImage..") );
       
  4459       iCamera->CancelCaptureImage();
       
  4460 
       
  4461       PRINT( _L("Camera <> CCamCameraController ... Setting capture state to OFF..") );
       
  4462       iInfo.iCaptureState = ECamCaptureOff;
       
  4463       }
       
  4464 #ifdef CAMERAAPP_CAPI_V2_ADV
       
  4465     // If we are in burst mode and need to increase capture limit,
       
  4466     // do it now. If we have just decreased the capture limit,
       
  4467     // we just cancel once the limit is met.
       
  4468     else if( iAdvancedSettings
       
  4469           && iAdvancedSettings->DriveMode() == CAS::EDriveModeBurst )
       
  4470       {
       
  4471       const TInt cameraLimit( iAdvancedSettings->BurstImages() );
       
  4472 
       
  4473       PRINT1( _L("Camera <> CCamCameraController ... Camera capture limit: %d"), cameraLimit         );
       
  4474       PRINT1( _L("Camera <> CCamCameraController ... Local  capture limit: %d"), iInfo.iCaptureLimit );
       
  4475 
       
  4476       if( cameraLimit < iInfo.iCaptureLimit )
       
  4477         {
       
  4478         TInt startedCaptures = Max( iInfo.iSnapshotCount, iInfo.iCaptureCount );
       
  4479         iInfo.iCaptureLimit  = Max( iInfo.iCaptureLimit, startedCaptures+1 );
       
  4480 
       
  4481         PRINT1( _L("Camera <> CCamCameraController ... Pending capture limit increase, calling SetBurstImages(%d).."), iInfo.iCaptureLimit );
       
  4482         iAdvancedSettings->SetBurstImages( iInfo.iCaptureLimit );
       
  4483         }
       
  4484       }
       
  4485 #endif // CAMERAAPP_CAPI_V2_ADV
       
  4486     // Normal, single capture.
       
  4487     else
       
  4488       {
       
  4489       }
       
  4490 
       
  4491     // See HandleCallbackEvent for comments.
       
  4492     // ClearFlags( iInfo.iBusy, ECamBusySingle );
       
  4493 
       
  4494     NotifyObservers( KErrNone,
       
  4495                      ECamCameraEventImageData,
       
  4496                      ECamCameraEventClassImage,
       
  4497                      share );
       
  4498     }
       
  4499   // -------------------------------------------------------
       
  4500   // Bitmap format case. Need to encode first.
       
  4501   else if( iAlternateFormatInUse )
       
  4502     {
       
  4503     PRINT( _L("Camera <> Bitmap alternative capture format in use..") );
       
  4504     // NOTE: We get another callback with encoded image data
       
  4505     //       once encoder has done the conversion.
       
  4506     PRINT( _L("Camera <> CCamCameraController ... Starting jpeg encoding..") );
       
  4507     if( !iEncoder ) iEncoder = CCamImageEncoder::NewL( *this );
       
  4508 
       
  4509     // Encoder needs to call Reserve
       
  4510     iEncoder->StartConversionL( share );
       
  4511     }
       
  4512   // -------------------------------------------------------
       
  4513   // Encoded data missing although expected.
       
  4514   else
       
  4515     {
       
  4516     User::Leave( dataStatus );
       
  4517     }
       
  4518   // -----------------------------------------------------
       
  4519   CleanupStack::PopAndDestroy(); // share->Release();
       
  4520   share = NULL;
       
  4521 
       
  4522   PRINT( _L("Camera <= CCamCameraController::HandleImageCaptureEventL") );
       
  4523   }
       
  4524 
       
  4525 
       
  4526 // ---------------------------------------------------------------------------
       
  4527 // HandleSnapshotEvent
       
  4528 // ---------------------------------------------------------------------------
       
  4529 //
       
  4530 void
       
  4531 CCamCameraController::HandleSnapshotEvent( TInt aStatus )
       
  4532   {
       
  4533   PRINT( _L("Camera => CCamCameraController::HandleSnapshotEvent") );
       
  4534 
       
  4535   // Check that we are in right state to handle snapshot.
       
  4536   // CCameraSnapshot sends atleast event with KErrCancel status
       
  4537   // when releasing the camera.
       
  4538   TBool videoSsExpected( IsFlagOn( iInfo.iState, ECamVideoOn ) );
       
  4539   TBool imageSsExpected( IsFlagOn( iInfo.iState, ECamImageOn )
       
  4540                       && ECamCaptureOn        == iInfo.iCaptureState
       
  4541                       && iInfo.iSnapshotCount <  iInfo.iCaptureLimit );
       
  4542 
       
  4543   if(
       
  4544 #ifdef CAMERAAPP_CAE_FIX
       
  4545       ECamModeChangeInactive == iModeChange &&
       
  4546 #endif
       
  4547       (videoSsExpected||imageSsExpected)
       
  4548     )
       
  4549     {
       
  4550     CAMERAAPP_PERF_CONTROLLER_STOP( ECamRequestSsStart );
       
  4551 
       
  4552     // -----------------------------------------------------
       
  4553     // Try to get snapshot data
       
  4554     if( KErrNone == aStatus )
       
  4555       {
       
  4556       TRAP( aStatus, HandleSnapshotEventL() );
       
  4557       PRINT1( _L("Camera <> CCamCameraController ... status after handling snapshot data: %d"), aStatus );
       
  4558       }
       
  4559 
       
  4560     // -----------------------------------------------------
       
  4561     // If snapshot was received and notified ok,
       
  4562     // check if capture ended.
       
  4563     if( KErrNone == aStatus )
       
  4564       {
       
  4565       // If we have needed amount of snapshots and images, end capture.
       
  4566       if( iInfo.iCaptureCount  >= iInfo.iCaptureLimit
       
  4567        && iInfo.iSnapshotCount >= iInfo.iCaptureLimit )
       
  4568         {
       
  4569         PRINT( _L("Camera <> CCamCameraController ... Setting capture state to OFF..") );
       
  4570         iInfo.iCaptureState = ECamCaptureOff;
       
  4571         }
       
  4572       }
       
  4573     // -----------------------------------------------------
       
  4574     // If any error, stop capture.
       
  4575     else
       
  4576       {
       
  4577       PRINT( _L("Camera <> CCamCameraController ... error encountered, notify and set capture state off..") );
       
  4578       NotifyObservers( aStatus,
       
  4579                        ECamCameraEventSsReady,
       
  4580                        ECamCameraEventClassSsData );
       
  4581       iInfo.iCaptureState = ECamCaptureOff;
       
  4582       }
       
  4583 
       
  4584     // -----------------------------------------------------
       
  4585     // Check if we have just completed the capture.
       
  4586     // Notify observers if so.
       
  4587     if( imageSsExpected
       
  4588      && ECamCaptureOff == iInfo.iCaptureState )
       
  4589       {
       
  4590       // See HandleCallbackEvent for comments.
       
  4591       ClearFlags( iInfo.iBusy, ECamBusySingle );
       
  4592 
       
  4593       TInt fullCaptures( Min( iInfo.iCaptureCount, iInfo.iSnapshotCount ) );
       
  4594       NotifyObservers( aStatus,
       
  4595                        ECamCameraEventImageStop,
       
  4596                        ECamCameraEventClassImage,
       
  4597                        &fullCaptures );
       
  4598       }
       
  4599     // -----------------------------------------------------
       
  4600     }
       
  4601   else
       
  4602     {
       
  4603     // Just retrieve and release camera buffer if snapshot is not expected
       
  4604     TRAP_IGNORE( HandleSnapshotEventL( ETrue ) );
       
  4605 
       
  4606     if( iInfo.iSnapshotCount > iInfo.iCaptureLimit )
       
  4607       {
       
  4608       // For burst stopping:
       
  4609       //   We have more snapshots already than requested..
       
  4610       //   All needed captures have to have started,
       
  4611       //   so we can call cancel here.
       
  4612       // Note:
       
  4613       //   Cannot use ">=" as last image might not be provided then.
       
  4614       //
       
  4615       PRINT( _L("Camera <> CCamCameraController ... Snapshot limit passed, calling CancelCaptureImage..") );
       
  4616       iCamera->CancelCaptureImage();
       
  4617       }
       
  4618 
       
  4619     PRINT( _L("Camera <> CCamCameraController ... [WARNING] Snapshot ignored!") );
       
  4620     iInfo.PrintInfo();
       
  4621     }
       
  4622 
       
  4623   PRINT( _L("Camera <= CCamCameraController::HandleSnapshotEvent") );
       
  4624   }
       
  4625 
       
  4626 
       
  4627 // ---------------------------------------------------------------------------
       
  4628 // HandleSnapshotEventL
       
  4629 //
       
  4630 // Helper method for leaving part of HandleSnapshotEvent.
       
  4631 // ---------------------------------------------------------------------------
       
  4632 //
       
  4633 void
       
  4634 CCamCameraController::HandleSnapshotEventL( TBool aIgnore )
       
  4635   {
       
  4636    PRINT1( _L("Camera => CCamCameraController::HandleSnapshotEventL ignore %d"),aIgnore);
       
  4637   __ASSERT_DEBUG( iSnapshotProvider, Panic( ECamCameraControllerCorrupt ) );
       
  4638   RArray<TInt> temp;
       
  4639   CleanupClosePushL( temp );
       
  4640   MCameraBuffer* buffer( NULL );
       
  4641 
       
  4642     buffer = &iSnapshotProvider->SnapshotDataL( temp );
       
  4643 
       
  4644   TInt firstImageIndex = temp.Find( 0 );
       
  4645   CleanupStack::PopAndDestroy(); // temp.Close()
       
  4646 
       
  4647   if( !aIgnore )
       
  4648       {
       
  4649 
       
  4650       CleanupStack::PushL( TCleanupItem( CameraBufferCleanup, buffer ) );
       
  4651       CFbsBitmap& snapshot = buffer->BitmapL( firstImageIndex );
       
  4652       PRINT2( _L("Camera <> CCamCameraController ... snapshot size: (%dx%d)"),
       
  4653               snapshot.SizeInPixels().iWidth, snapshot.SizeInPixels().iHeight );
       
  4654 
       
  4655       // Increase received snapshots count.
       
  4656       // Needed in burst drive mode.
       
  4657       iInfo.iSnapshotCount++;
       
  4658       PRINT1( _L("Camera <> CCamCameraController ... Incremented snapshot counter to: %d"), iInfo.iSnapshotCount );
       
  4659 
       
  4660       // No leaving code after notification as otherwise
       
  4661       // HandleSnapshotEvent calling this method will notify clients again.
       
  4662       NotifyObservers( KErrNone,
       
  4663               ECamCameraEventSsReady,
       
  4664               ECamCameraEventClassSsData,
       
  4665               &snapshot );
       
  4666 
       
  4667       CleanupStack::PopAndDestroy(); // buffer->Release()
       
  4668       }
       
  4669   else
       
  4670       {
       
  4671       ReleaseAndNull(buffer);
       
  4672       }
       
  4673   PRINT( _L("Camera <= CCamCameraController::HandleSnapshotEventL"));
       
  4674   }
       
  4675 
       
  4676 
       
  4677 
       
  4678 
       
  4679 // ---------------------------------------------------------------------------
       
  4680 // HandleVideoInitEvent
       
  4681 // ---------------------------------------------------------------------------
       
  4682 //
       
  4683 void
       
  4684 CCamCameraController::HandleVideoEvent( const TCamCameraEventId& aEventId,
       
  4685                                               TInt               aStatus   )
       
  4686   {
       
  4687   PRINT2( _L("Camera => CCamCameraController::HandleVideoEvent, status:%d, event[%s]"),
       
  4688           aStatus,
       
  4689           KCamCameraEventNames[aEventId] );
       
  4690 
       
  4691   // Only video stop of these events may come without our explicit request.
       
  4692 /*
       
  4693   if( ECamCameraEventVideoStop != aEventId )
       
  4694     {
       
  4695     if( ECamBusyOff != iInfo.iBusy )
       
  4696       Panic( ECamCameraControllerCorrupt );
       
  4697     }
       
  4698 */
       
  4699 
       
  4700   switch( aEventId )
       
  4701     {
       
  4702     // -----------------------------------------------------
       
  4703     case ECamCameraEventVideoInit:
       
  4704       // Some settings repeat this event if CCaeEngine in use.
       
  4705       if( !IsFlagOn( iInfo.iBusy, ECamBusySetting ) )
       
  4706         {
       
  4707         CAMERAAPP_PERF_CONTROLLER_STOP( ECamRequestVideoInit );
       
  4708         if( KErrNone == aStatus ) SetFlags  ( iInfo.iState, ECamVideoOn );
       
  4709         else                      ClearFlags( iInfo.iState, ECamVideoOn );
       
  4710         }
       
  4711 #ifdef CAMERAAPP_CAPI_V2_ADV
       
  4712         TRAP_IGNORE( GetAdvancedSettingsInfoL() );
       
  4713 #endif
       
  4714 #ifdef CAMERAAPP_CAE_FIX
       
  4715       if( ECamModeChangeImage2Video == iModeChange )
       
  4716         {
       
  4717         iModeChangeStatus = aStatus;
       
  4718         iActive->IssueRequest();
       
  4719         return;
       
  4720         }
       
  4721 #endif // CAMERAAPP_CAE_FIX
       
  4722       break;
       
  4723     // -----------------------------------------------------
       
  4724     case ECamCameraEventVideoStart:
       
  4725       if( KErrNone == aStatus )
       
  4726         {
       
  4727         iInfo.iCaptureState = ECamCaptureOn;
       
  4728         }
       
  4729       break;
       
  4730     // -----------------------------------------------------
       
  4731     case ECamCameraEventVideoPause:
       
  4732       if( KErrNone == aStatus )
       
  4733         {
       
  4734         iInfo.iCaptureState = ECamCapturePaused;
       
  4735         }
       
  4736       else
       
  4737         {
       
  4738         // Problem with pausing.
       
  4739         // Keep our capture state unchanged.
       
  4740         }
       
  4741       break;
       
  4742     // -----------------------------------------------------
       
  4743     case ECamCameraEventVideoStop:
       
  4744       // Even if error we have done what we can for stopping.
       
  4745       // Update internal capture state anyway.
       
  4746       iInfo.iCaptureState = ECamCaptureOff;
       
  4747       // We may receive this event from CCaeEngine, even though we have not
       
  4748       // issued a request to stop the video recording. If e.g. there is not
       
  4749       // enough space in the disk to continue recording, this event is
       
  4750       // generated without explicit request.
       
  4751       //
       
  4752       // We must not continue any pending operations if this event is not
       
  4753       // a response to our stop request.
       
  4754       // HandleCallbackEvent takes care of that.
       
  4755       break;
       
  4756     // -----------------------------------------------------
       
  4757     case ECamCameraEventVideoAsyncStop:
       
  4758       PRINT( _L("Camera <> CCamCameraController::HandleVideoEvent case ECamCameraEventVideoAsyncStop") );
       
  4759       // Do not change state, just play sound later
       
  4760       break;
       
  4761     // -----------------------------------------------------
       
  4762     default:
       
  4763       {
       
  4764       Panic( ECamCameraControllerCorrupt );
       
  4765       break;
       
  4766       }
       
  4767     // -----------------------------------------------------
       
  4768     }
       
  4769 
       
  4770   HandleCallbackEvent( aStatus,
       
  4771                        aEventId,
       
  4772                        ECamCameraEventClassVideo );
       
  4773   PRINT( _L("Camera <= CCamCameraController::HandleVideoEvent") );
       
  4774   }
       
  4775 
       
  4776 
       
  4777 #ifdef CAMERAAPP_CAE_FOR_VIDEO
       
  4778 // ---------------------------------------------------------------------------
       
  4779 // HandleVideoTimeEvent
       
  4780 // ---------------------------------------------------------------------------
       
  4781 //
       
  4782 void
       
  4783 CCamCameraController
       
  4784 ::HandleVideoTimeEvent( TInt aStatus,
       
  4785                         TTimeIntervalMicroSeconds aTimeElapsed,
       
  4786                         TTimeIntervalMicroSeconds aTimeRemaining )
       
  4787   {
       
  4788   // If capture has already stopped, we don't echo this to our observers.
       
  4789   if( ECamCaptureOff != iInfo.iCaptureState )
       
  4790     {
       
  4791     iVideoTimes.iTimeElapsed   = aTimeElapsed.Int64();
       
  4792     iVideoTimes.iTimeRemaining = aTimeRemaining.Int64();
       
  4793 
       
  4794     NotifyObservers( aStatus,
       
  4795                      ECamCameraEventVideoTimes,
       
  4796                      ECamCameraEventClassVideoTimes,
       
  4797                      &iVideoTimes );
       
  4798     }
       
  4799   }
       
  4800 #endif
       
  4801 
       
  4802 // ---------------------------------------------------------------------------
       
  4803 // HandleAutoFocusEvent
       
  4804 //
       
  4805 // ---------------------------------------------------------------------------
       
  4806 //
       
  4807 void
       
  4808 CCamCameraController::HandleAutoFocusEvent( TInt aStatus, const TUid& aEventUid )
       
  4809   {
       
  4810   PRINT1( _L("Camera => CCamCameraController::HandleAutoFocusEvent, status: %d"), aStatus );
       
  4811 
       
  4812  if( IsFlagOn( iInfo.iState, ECamVideoOn ) && ECamCaptureOn == iInfo.iCaptureState )
       
  4813     {
       
  4814     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  4815     if ( appUi && !appUi->AppController().UiConfigManagerPtr()->IsContinuosAutofocusSupported() )
       
  4816         {
       
  4817         // Autofocus events are not need anymore, if video recording is started already.
       
  4818         PRINT( _L("Camera <= CCamCameraController::HandleAutoFocusEvent - ignore") );
       
  4819         return;
       
  4820         }
       
  4821     }
       
  4822 
       
  4823   TBool proceed = EFalse;
       
  4824 
       
  4825   // -------------------------------------------------------
       
  4826   // Check the event
       
  4827   if( KUidECamEventCameraSettingsOptimalFocus == aEventUid )
       
  4828     {
       
  4829     PRINT( _L("Camera <> CCamCameraController: event KUidECamEventCameraSettingsOptimalFocus") );
       
  4830     if( !iAfHyperfocalPending )
       
  4831       {
       
  4832       proceed = ETrue;
       
  4833       iAfInProgress = EFalse;
       
  4834       iFirstAfEventReceived = EFalse;
       
  4835       }
       
  4836     }
       
  4837   else if( KUidECamEventCameraSettingAutoFocusType2 == aEventUid )
       
  4838     {
       
  4839     PRINT( _L("Camera <> CCamCameraController: event KUidECamEventCameraSettingsAutoFocusType2") );
       
  4840     // If AF started and canceled before finishing
       
  4841     if( iAfInProgress && iAfHyperfocalPending && iFirstAfEventReceived )
       
  4842       {
       
  4843       // continue to set focus to hyperfocal
       
  4844       proceed = ETrue;
       
  4845       }
       
  4846     if( !iFirstAfEventReceived )
       
  4847       {
       
  4848       // For the first time, this event means that the autofocusing has been started
       
  4849       iFirstAfEventReceived = ETrue;
       
  4850       PRINT( _L("Camera <> CCamCameraController: event KUidECamEventCameraSettingAutoFocusType2 - first time, set iFirstAfEventReceived ") );
       
  4851       }
       
  4852     else
       
  4853       {
       
  4854       iFirstAfEventReceived = EFalse;
       
  4855       PRINT( _L("Camera <> CCamCameraController: event KUidECamEventCameraSettingAutoFocusType2 - second time") );
       
  4856       }
       
  4857     }
       
  4858   else
       
  4859     {
       
  4860     // No other event acceptable here..
       
  4861     __ASSERT_DEBUG( EFalse, Panic( ECamCameraControllerCorrupt ) );
       
  4862     }
       
  4863   // -------------------------------------------------------
       
  4864   // Proceed if right event received
       
  4865   if( proceed )
       
  4866     {
       
  4867     TCamCameraEventId  event = ( KErrNone == aStatus )
       
  4868                              ? ECamCameraEventAutofocusSuccessful
       
  4869                              : ECamCameraEventAutofocusFailed;
       
  4870     if( iAfHyperfocalPending )
       
  4871       {
       
  4872       PRINT( _L("Camera <> Cancelled active autofocus request.") );
       
  4873       PRINT( _L("Camera <> Setting focus range to hyperfocal, no event to observers yet") );
       
  4874       iAfHyperfocalPending = EFalse;
       
  4875       iAfInProgress = EFalse;
       
  4876       TRAP_IGNORE( ProcessAutofocusRequestL( ECamRequestCancelAutofocus ) );
       
  4877       }
       
  4878     else
       
  4879       {
       
  4880       HandleCallbackEvent( KErrNone,
       
  4881                            event,
       
  4882                            ECamCameraEventClassAutofocus );
       
  4883       }
       
  4884 
       
  4885     }
       
  4886   else if(iFirstAfEventReceived && (aStatus != KErrNone) )
       
  4887     {
       
  4888     //There might have been error when first event was received
       
  4889     //and no further autofocus events would occur.
       
  4890     iFirstAfEventReceived = EFalse;
       
  4891     iAfInProgress = EFalse;
       
  4892 
       
  4893     if( iAfHyperfocalPending )
       
  4894       {
       
  4895       PRINT( _L("Camera <> Cancelled active autofocus request.") );
       
  4896       PRINT( _L("Camera <> Set focus range to hyperfocal, no event to observers yet") );
       
  4897       iAfHyperfocalPending = EFalse;
       
  4898       TRAP_IGNORE( ProcessAutofocusRequestL( ECamRequestCancelAutofocus ) );
       
  4899       }
       
  4900     else
       
  4901       {
       
  4902       HandleCallbackEvent( KErrNone,
       
  4903                            ECamCameraEventAutofocusFailed,
       
  4904                            ECamCameraEventClassAutofocus );
       
  4905       }
       
  4906     }
       
  4907   // -------------------------------------------------------
       
  4908   PRINT( _L("Camera <= CCamCameraController::HandleAutoFocusEvent") );
       
  4909   }
       
  4910 
       
  4911 
       
  4912 
       
  4913 // ---------------------------------------------------------------------------
       
  4914 //
       
  4915 // HandleFlashStatusEvent
       
  4916 //
       
  4917 // Helper method to handle flash status updates.
       
  4918 //
       
  4919 // ---------------------------------------------------------------------------
       
  4920 void
       
  4921 CCamCameraController::HandleFlashStatusEvent( TInt                     aStatus,
       
  4922                                               const TCamCameraEventId& aEventId )
       
  4923   {
       
  4924   PRINT2( _L("Camera => CCamCameraController::HandleFlashStatusEvent, event[%s] status:%d"), KCamCameraEventNames[aEventId], aStatus );
       
  4925   NotifyObservers( aStatus,
       
  4926                    aEventId,
       
  4927                    EventClass( aEventId ) );
       
  4928   PRINT ( _L("Camera <= CCamCameraController::HandleFlashStatusEvent" ) );
       
  4929   }
       
  4930 
       
  4931 
       
  4932 
       
  4933 // ---------------------------------------------------------------------------
       
  4934 // HandleCallbackEvent
       
  4935 //
       
  4936 // Helper method to handle CCamera callback events.
       
  4937 // Notifies observers and checks if we should proceed with the sequence.
       
  4938 // ---------------------------------------------------------------------------
       
  4939 //
       
  4940 void
       
  4941 CCamCameraController
       
  4942 ::HandleCallbackEvent(       TInt                    aStatus,
       
  4943                        const TCamCameraEventId&      aEventId,
       
  4944                        const TCamCameraEventClassId& aEventClass,
       
  4945                              TAny*                   aEventData /*= NULL*/ )
       
  4946   {
       
  4947   PRINT1( _L("Camera => CCamCameraController::HandleCallbackEvent, event[%s]"),
       
  4948           KCamCameraEventNames[aEventId] );
       
  4949   // -------------------------------------------------------
       
  4950   // Clear single request busy flag before notification to observers,
       
  4951   // in case client wishes to issue new request during the notification.
       
  4952   // Sequence busy flag can only be cleared in EndSequence
       
  4953   ClearFlags( iInfo.iBusy, ECamBusySingle );
       
  4954 
       
  4955   // Observers might issue a new sequence during notification.
       
  4956   // We need to decide if sequence needs to continue here
       
  4957   // based on the status *before* notification.
       
  4958   TBool proceedSequence = EFalse;
       
  4959   TBool notify          = ETrue;
       
  4960 
       
  4961   // -------------------------------------------------------
       
  4962   // Continue if:
       
  4963   // 1) Processing sequence is ongoing.
       
  4964   // 2) The received event is exact response to our request.
       
  4965   //    There are events like "video stopped" or "reserve lost"
       
  4966   //    that may be received without our associated request.
       
  4967   //    In that case we must not proceed sequence processing now.
       
  4968   // 3) In case that aStatus is KErrInUse and the current event is
       
  4969   //    Reserve, it means reserve failed for some reason
       
  4970   if( IsFlagOn( iInfo.iBusy, ECamBusySequence ) ) // 1
       
  4971     {
       
  4972     PRINT( _L("Camera <> Sequence is active") );
       
  4973     PRINT2( _L("Camera <> seq index: %d, seq array len: %d"), iSequenceIndex, iSequenceArray.Count() );
       
  4974     if( KErrNone != aStatus )
       
  4975         {
       
  4976 
       
  4977         if ( KErrInUse == aStatus               // 3
       
  4978             && aEventId == ECamCameraEventReserveGain
       
  4979             && iSequenceIndex >= 0
       
  4980             && Request2Event( iSequenceArray[iSequenceIndex] ) == ECamCameraEventReserveGain
       
  4981             && iReserveTryAgainCount > 0 )
       
  4982             {
       
  4983             // Handle here only if reserve gain with error is part of a sequence and try again count is not zero
       
  4984 
       
  4985             iReserveTryAgainCount--;
       
  4986             User::After( KCamReserveTryAgainWaitInterval );
       
  4987 
       
  4988             // decrease index, to get the same request handled again
       
  4989             iSequenceIndex--;
       
  4990             notify          = EFalse;
       
  4991             proceedSequence = ETrue;
       
  4992             PRINT1( _L( "Camera <> CCamCameraController::HandleCallbackEvent - %d reserve try again left" ), iReserveTryAgainCount );
       
  4993             }
       
  4994         else if(KErrBadName == aStatus &&
       
  4995                 iSequenceIndex >= 0 &&   
       
  4996                 Request2Event( iSequenceArray[iSequenceIndex] ) == aEventId)  
       
  4997             {
       
  4998             aStatus         = KErrNone;
       
  4999             notify          = ETrue;
       
  5000             proceedSequence = ETrue;
       
  5001             //EndSequence( aStatus );      
       
  5002             }
       
  5003         else 
       
  5004             {
       
  5005 
       
  5006             notify          = EFalse;
       
  5007             proceedSequence = EFalse;
       
  5008             EndSequence( aStatus );
       
  5009 
       
  5010             }
       
  5011 
       
  5012         }
       
  5013     else if( iSequenceIndex >= 0 &&  // Sequence has started
       
  5014              Request2Event( iSequenceArray[iSequenceIndex] ) == aEventId ) // 2
       
  5015         {
       
  5016         notify          = ETrue;
       
  5017         proceedSequence = ETrue;
       
  5018         }
       
  5019     else
       
  5020         {
       
  5021          // Not the event we need yet.
       
  5022         }
       
  5023 
       
  5024     }
       
  5025   // -------------------------------------------------------
       
  5026   // Setting sequence ongoing
       
  5027   else if( IsFlagOn( iInfo.iBusy, ECamBusySetting )
       
  5028            && iSettingIndex >= 0 )
       
  5029     {
       
  5030     PRINT( _L("Camera <> Settings change ongoing..") );
       
  5031 
       
  5032     // Default is no notification
       
  5033     if( aEventClass != ECamCameraEventClassAutofocus )
       
  5034       {
       
  5035       notify = EFalse;
       
  5036 	  }
       
  5037     if( KErrNone != aStatus )
       
  5038       {
       
  5039       PRINT( _L("Camera <> error in, end settings sequence!") );
       
  5040       proceedSequence = EFalse;
       
  5041       EndSequence( aStatus ); // does one notification
       
  5042       }
       
  5043     else if( ECamCameraEventSettingsSingle == aEventId
       
  5044           && aEventData
       
  5045           && iSettingArray[iSettingIndex] == *( static_cast<TInt*>( aEventData ) )
       
  5046            )
       
  5047       {
       
  5048       // We have checked already in HandleEvent that this is
       
  5049       // the right event for the setting we wait to finish.
       
  5050       // Notification can be sent with the given data.
       
  5051       PRINT( _L("Camera <> One setting finished, continue sequence") );
       
  5052       proceedSequence = ETrue;
       
  5053       }
       
  5054     // Video init event repeated when filename or max file size set
       
  5055     // after init already done
       
  5056     else if( IsFlagOn( iInfo.iState, ECamVideoOn )
       
  5057           && ECamCameraEventVideoInit == aEventId
       
  5058           && ( ECameraSettingFileName    == iSettingArray[iSettingIndex]
       
  5059             || ECameraSettingFileMaxSize == iSettingArray[iSettingIndex]
       
  5060             || ECameraSettingAudioMute   == iSettingArray[iSettingIndex] ) )
       
  5061       {
       
  5062       PRINT( _L("Camera <> One setting finished, continue sequence") );
       
  5063       proceedSequence = ETrue;
       
  5064       }
       
  5065     else if( ECamCameraEventVideoStop == aEventId || ECamCameraEventVideoAsyncStop == aEventId  )
       
  5066       {
       
  5067       // Video stop might come whenever.
       
  5068       // Need to notify client.
       
  5069       notify = ETrue;
       
  5070       }
       
  5071     else
       
  5072       {
       
  5073       // Not event for us yet
       
  5074       }
       
  5075     }
       
  5076   // -------------------------------------------------------
       
  5077   else
       
  5078     {
       
  5079     // Single request or no request sent
       
  5080     }
       
  5081   // -------------------------------------------------------
       
  5082 
       
  5083 
       
  5084   // -------------------------------------------------------
       
  5085   // Notify the observers with data from the event.
       
  5086   if( notify )
       
  5087     {
       
  5088     NotifyObservers( aStatus, aEventId, aEventClass, aEventData );
       
  5089     }
       
  5090 
       
  5091   // -------------------------------------------------------
       
  5092   // If this is part of sequence, continue processing.
       
  5093   if( proceedSequence )
       
  5094     {
       
  5095     PRINT ( _L("Camera <> proceeding with the sequence") );
       
  5096     __ASSERT_DEBUG( iActive, Panic( ECamCameraControllerCorrupt ) );
       
  5097     iActive->IssueRequest();
       
  5098     }
       
  5099   // -------------------------------------------------------
       
  5100   PRINT ( _L("Camera <= CCamCameraController::HandleCallbackEvent") );
       
  5101   }
       
  5102 
       
  5103 
       
  5104 // ===========================================================================
       
  5105 
       
  5106 // ---------------------------------------------------------------------------
       
  5107 // Notify all our observers of an event.
       
  5108 // ---------------------------------------------------------------------------
       
  5109 //
       
  5110 void
       
  5111 CCamCameraController
       
  5112 ::NotifyObservers( TInt                   aStatus,
       
  5113                    TCamCameraEventId      aEventId,
       
  5114                    TCamCameraEventClassId aEventClass,
       
  5115                    TAny*                  aEventData /*=NULL*/ )
       
  5116   {
       
  5117 //  PRINT ( _L("Camera => CCamCameraController::NotifyObservers") );
       
  5118 //  PRINT3( _L("Camera <> status:% 3d event:% 3d class:%032b"), aStatus, aEventId, aEventClass );
       
  5119 
       
  5120   // NOTE:
       
  5121   //   We might skip an observer, if during the notification some observer
       
  5122   //   is removed from the array (from smaller index than current one).
       
  5123   //   This is a commmon problem for all observable classes in this application.
       
  5124   for( TInt i = 0; i < iObservers.Count(); i++ )
       
  5125     {
       
  5126     // Observer defines which events it is interested in.
       
  5127 //    PRINT1( _L("Camera <>          observer interest:%032b"), iObserverInterests[i] );
       
  5128 
       
  5129     if( iObserverInterests[i] & aEventClass )
       
  5130       {
       
  5131       TRAP_IGNORE( iObservers[i]->HandleCameraEventL( aStatus, aEventId, aEventData ) );
       
  5132       }
       
  5133     }
       
  5134 //  PRINT ( _L("Camera <= CCamCameraController::NotifyObservers") );
       
  5135   }
       
  5136 
       
  5137 
       
  5138 
       
  5139 // ---------------------------------------------------------------------------
       
  5140 //
       
  5141 // ---------------------------------------------------------------------------
       
  5142 //
       
  5143 void
       
  5144 CCamCameraController::ReleaseCurrentCamera()
       
  5145   {
       
  5146   PRINT( _L("Camera => CCamCameraController::ReleaseCurrentCamera") );
       
  5147   // Cancel any outstanding sequence.
       
  5148   if( IsFlagOn( iInfo.iBusy, ECamBusySequence )
       
  5149 #ifdef CAMERAAPP_CAE_FIX
       
  5150    // Mode change calls this method possibly in the middle
       
  5151    // of request sequence. Must not try to cancel then.
       
  5152    && ECamModeChangeInactive == iModeChange
       
  5153 #endif
       
  5154     )
       
  5155     {
       
  5156     CancelSequence();
       
  5157     }
       
  5158 
       
  5159   if( IsFlagOn( iInfo.iState, ECamReserved ) )
       
  5160     {
       
  5161     // Releases viewfinder and snapshot, cancels capture,
       
  5162     // powers off and releases CCamera if needed.
       
  5163     ProcessControlShutdownRequest( ECamRequestRelease );
       
  5164     }
       
  5165 
       
  5166   // Custom interfaces (not owned)
       
  5167   ReleaseCustomInterfaces();
       
  5168 
       
  5169   delete iEncoder;            iEncoder           = NULL;
       
  5170 #ifdef CAMERAAPP_CAE_FOR_VIDEO
       
  5171   delete iCaeEngine;          iCaeEngine         = NULL;
       
  5172 #endif // CAMERAAPP_CAE_FOR_VIDEO
       
  5173 
       
  5174 #ifdef CAMERAAPP_CAPI_V2_ADV
       
  5175   delete iAdvancedSettings;   iAdvancedSettings  = NULL;
       
  5176   iAdvancedSettingInfo.Reset();
       
  5177 #endif
       
  5178 #ifdef CAMERAAPP_CAPI_V2_DVF
       
  5179   delete iDirectViewfinder;   iDirectViewfinder  = NULL;
       
  5180 #endif
       
  5181 #ifdef CAMERAAPP_CAPI_V2_OL
       
  5182   delete iOverlayProvider;    iOverlayProvider   = NULL;
       
  5183 #endif
       
  5184 #ifdef CAMERAAPP_CAPI_V2_HG
       
  5185   delete iHistogramProvider;  iHistogramProvider = NULL;
       
  5186 #endif
       
  5187 #ifdef CAMERAAPP_CAPI_V2_IP
       
  5188   delete iImageProcessor;     iImageProcessor    = NULL;
       
  5189 #endif
       
  5190   delete iSnapshotProvider;   iSnapshotProvider  = NULL;
       
  5191 
       
  5192   delete iCamera;             iCamera            = NULL;
       
  5193 
       
  5194 #ifdef CAMERAAPP_CAE_FIX
       
  5195   // Must not reset busy flags if this method is called
       
  5196   // because of mode switch.
       
  5197   TBool saveBusyFlags = (ECamModeChangeInactive != iModeChange);
       
  5198   iInfo.Reset( saveBusyFlags );
       
  5199 #else
       
  5200   iInfo.Reset();
       
  5201 #endif
       
  5202   iResolutionSupport.Reset();
       
  5203   iInfo.iState = ECamIdle;
       
  5204 
       
  5205   PRINT( _L("Camera <= CCamCameraController::ReleaseCurrentCamera") );
       
  5206   }
       
  5207 
       
  5208 
       
  5209 // ---------------------------------------------------------------------------
       
  5210 // ReleaseCustomInterfaces
       
  5211 // ---------------------------------------------------------------------------
       
  5212 //
       
  5213 void
       
  5214 CCamCameraController::ReleaseCustomInterfaces()
       
  5215   {
       
  5216   iCustomInterfaceOrientation   = NULL;
       
  5217   }
       
  5218 
       
  5219 // ---------------------------------------------------------------------------
       
  5220 // CompareSize
       
  5221 // Compare two TSize instances
       
  5222 // ---------------------------------------------------------------------------
       
  5223 //
       
  5224 TBool CCamCameraController::CompareSize( const TSize& aA, const TSize& aB )
       
  5225     {
       
  5226     return ( aA.iWidth == aB.iWidth && aA.iHeight == aB.iHeight );
       
  5227     }
       
  5228 
       
  5229 
       
  5230 // ---------------------------------------------------------------------------
       
  5231 // GetResolutionIndexL
       
  5232 //
       
  5233 // Get quality index for prepare with given format and size.
       
  5234 // If current info is not for the given format, update the
       
  5235 // supported resolutions info. After the support info is up to date,
       
  5236 // find the index. Return KErrNotFound if not supported size.
       
  5237 //
       
  5238 // For JPEG format we try two alternate bitmap formats, if
       
  5239 // the given resolution is not supported in JPEG format.
       
  5240 // If support is achieved by using one of the alternate formats,
       
  5241 // the format in use is returned in aFormat. When image is then
       
  5242 // later captured, we encode the bitmap to JPEG before handing
       
  5243 // it over to clients.
       
  5244 // ---------------------------------------------------------------------------
       
  5245 //
       
  5246 TInt
       
  5247 CCamCameraController
       
  5248 ::GetResolutionIndexL(       CCamera::TFormat& aFormat,
       
  5249                        const TSize&            aSize   )
       
  5250   {
       
  5251   PRINT ( _L("Camera => CCamCameraController::GetResolutionIndexL") );
       
  5252 
       
  5253   if( iResolutionSupport.iForCameraFormat != aFormat
       
  5254    || iResolutionSupport.iForCameraIndex  != iInfo.iCurrentCamera )
       
  5255     {
       
  5256     iAlternateFormatInUse = EFalse;
       
  5257 
       
  5258     // Reset all old resolution info
       
  5259     iResolutionSupport.Reset();
       
  5260 
       
  5261     // Get the resolution info for current camera with given format.
       
  5262     const TInt KResolutionCount( iCameraInfo.iNumImageSizesSupported );
       
  5263     RArray<TSize>& resolutions( iResolutionSupport.iResolutions );
       
  5264 
       
  5265     resolutions.ReserveL( KResolutionCount );
       
  5266     for( TInt i = 0; i < KResolutionCount; i++ )
       
  5267       {
       
  5268       // Reserve called, so should not leave.
       
  5269       resolutions.AppendL( TSize() );
       
  5270       iCamera->EnumerateCaptureSizes( resolutions[i], i, aFormat );
       
  5271       }
       
  5272 
       
  5273     // Set these after successful filling of the array
       
  5274     iResolutionSupport.iForCameraIndex  = iInfo.iCurrentCamera;
       
  5275     iResolutionSupport.iForCameraFormat = aFormat;
       
  5276     }
       
  5277 
       
  5278 #ifdef _DEBUG
       
  5279   PRINT ( _L("Camera <> ==================================================") );
       
  5280   PRINT2( _L("Camera <> Size requested           : (%d,%d)"), aSize.iWidth, aSize.iHeight        );
       
  5281   PRINT1( _L("Camera <> Formats supported        : %032b"  ), iCameraInfo.iImageFormatsSupported );
       
  5282   PRINT1( _L("Camera <> Sizes listed for         : %032b"  ), aFormat                            );
       
  5283   PRINT1( _L("Camera <> EFormatJpeg              : %032b"  ), CCamera::EFormatJpeg               );
       
  5284   PRINT1( _L("Camera <> EFormatExif              : %032b"  ), CCamera::EFormatExif               );
       
  5285   PRINT1( _L("Camera <> EFormatFbsBitmapColor4K  : %032b"  ), CCamera::EFormatFbsBitmapColor4K   );
       
  5286   PRINT1( _L("Camera <> EFormatFbsBitmapColor64K : %032b"  ), CCamera::EFormatFbsBitmapColor64K  );
       
  5287   PRINT1( _L("Camera <> EFormatFbsBitmapColor16M : %032b"  ), CCamera::EFormatFbsBitmapColor16M  );
       
  5288   PRINT1( _L("Camera <> EFormatFbsBitmapColor16MU: %032b"  ), CCamera::EFormatFbsBitmapColor16MU );
       
  5289   for( TInt i = 0; i < iResolutionSupport.iResolutions.Count(); i++ )
       
  5290     {
       
  5291     const TSize& size( iResolutionSupport.iResolutions[i] );
       
  5292     PRINT3( _L("Camera <> Size (%d): (%d,%d)"), i, size.iWidth, size.iHeight );
       
  5293     }
       
  5294   PRINT ( _L("Camera <> ==================================================") );
       
  5295 #endif
       
  5296 
       
  5297   TIdentityRelation<TSize> compareFunc( CCamCameraController::CompareSize );
       
  5298   TInt index = iResolutionSupport.iResolutions.Find( aSize, compareFunc );
       
  5299 
       
  5300   // Exception for JPEG format:
       
  5301   //   If JPEG format is not supported, but bitmap format is,
       
  5302   //   pretend to support the format anyway.
       
  5303   //   When capturing, we encode the JPEG from the bitmap.
       
  5304   if( CCamera::EFormatJpeg == aFormat
       
  5305    && KErrNotFound         == index )
       
  5306     {
       
  5307     PRINT ( _L("Camera <> Jpeg not supported, trying bitmap format 1..") );
       
  5308     aFormat = KCamJpegAlternativeFormat1;
       
  5309     index   = GetResolutionIndexL( aFormat, aSize );
       
  5310 
       
  5311     if( KErrNotFound == index )
       
  5312       {
       
  5313       PRINT ( _L("Camera <> Jpeg not supported, trying bitmap format 2..") );
       
  5314       aFormat = KCamJpegAlternativeFormat2;
       
  5315       index   = GetResolutionIndexL( aFormat, aSize );
       
  5316       }
       
  5317 
       
  5318     if( KErrNotFound != index )
       
  5319       {
       
  5320       iAlternateFormatInUse = ETrue;
       
  5321       }
       
  5322     else
       
  5323       {
       
  5324       // Could not find alternative.
       
  5325       aFormat = CCamera::EFormatJpeg;
       
  5326       iAlternateFormatInUse = EFalse;
       
  5327       }
       
  5328    }
       
  5329 
       
  5330   PRINT1( _L("Camera <= CCamCameraController::GetResolutionIndexL, return: %d"), index );
       
  5331   return index;
       
  5332   }
       
  5333 
       
  5334 
       
  5335 #ifdef CAMERAAPP_CAPI_V2_ADV
       
  5336 // ---------------------------------------------------------------------------
       
  5337 // GetAdvancedSettingsInfoL
       
  5338 //
       
  5339 // ---------------------------------------------------------------------------
       
  5340 //
       
  5341 void
       
  5342 CCamCameraController::GetAdvancedSettingsInfoL()
       
  5343   {
       
  5344   PRINT ( _L("Camera => CCamCameraController::GetAdvancedSettingsInfoL") );
       
  5345   PRINT2( _L("Camera <> current camera:%d, latest info for:%d"),
       
  5346           iInfo.iCurrentCamera,
       
  5347           iAdvancedSettingInfo.iForCameraIndex );
       
  5348 
       
  5349 
       
  5350     CheckNonNullL( iAdvancedSettings, KErrNotReady );
       
  5351     iAdvancedSettingInfo.Reset();
       
  5352 
       
  5353     TInt error( KErrNone );
       
  5354     CleanupStack::PushL( TCleanupItem( ResetInfo, &iAdvancedSettingInfo ) );
       
  5355 
       
  5356     // -----------------------------------------------------
       
  5357     // Digital zoom steps support
       
  5358     PRINT( _L("Camera <> Get zoom steps..") );
       
  5359     if( IsFlagOn( iInfo.iState, ECamImageOn ) )
       
  5360       {
       
  5361       TPckgBuf<TCamParamsImage> params;
       
  5362       iSettingProvider.ProvideCameraParamL( ECameraParamImage, &params );
       
  5363 
       
  5364       PRINT( _L("Camera <> Enumerating capture sizes..") );
       
  5365       CCamera::TFormat format( params().iFormat );
       
  5366       TInt             index ( GetResolutionIndexL( format, params().iSize ) );
       
  5367       User::LeaveIfError( index );
       
  5368       TBool isInfluencePossible; // Not used
       
  5369 
       
  5370       PRINT( _L("Camera <> Get zoom steps for image") );
       
  5371       TRAP( error, iAdvancedSettings->GetDigitalZoomStepsForStillL (
       
  5372                       iAdvancedSettingInfo.iDigitalZoomSupport,
       
  5373                       iAdvancedSettingInfo.iDigitalZoomValueInfo,
       
  5374                       index,
       
  5375                       format,
       
  5376                       isInfluencePossible  ) );
       
  5377 
       
  5378       if( KErrNotSupported != error ) User::LeaveIfError( error );
       
  5379       }
       
  5380     else if( IsFlagOn( iInfo.iState, ECamVideoOn ) )
       
  5381       {
       
  5382       PRINT( _L("Camera <> Get zoom steps for video") );
       
  5383       TRAP( error, iAdvancedSettings->GetDigitalZoomStepsL(
       
  5384                       iAdvancedSettingInfo.iDigitalZoomSupport,
       
  5385                       iAdvancedSettingInfo.iDigitalZoomValueInfo ) );
       
  5386       if( KErrNotSupported != error ) User::LeaveIfError( error );
       
  5387       }
       
  5388 
       
  5389     // -----------------------------------------------------
       
  5390     // EV steps multiplied by KECamFineResolutionFactor.
       
  5391     PRINT( _L("Camera <> Get EV support..") );
       
  5392     iAdvancedSettingInfo.iEvModesSupport =
       
  5393         iAdvancedSettings->SupportedExposureModes();
       
  5394 
       
  5395     TRAP( error, iAdvancedSettings->GetExposureCompensationStepsL(
       
  5396                     iAdvancedSettingInfo.iEvStepsSupport,
       
  5397                     iAdvancedSettingInfo.iEvStepsValueInfo ) );
       
  5398     // Ignore error if just not supported.
       
  5399     // We check the support when setting is requested.
       
  5400     if( KErrNotSupported != error ) User::LeaveIfError( error );
       
  5401 
       
  5402     // -----------------------------------------------------
       
  5403     // ISO rates (.. 50, 100, 200, ..)
       
  5404     PRINT( _L("Camera <> Get ISO rates..") );
       
  5405     TRAP( error, iAdvancedSettings->GetSupportedIsoRatesL(
       
  5406                     iAdvancedSettingInfo.iIsoRatesSupport ) );
       
  5407     if( KErrNotSupported != error ) User::LeaveIfError( error );
       
  5408 
       
  5409     // -----------------------------------------------------
       
  5410     // Stabilization
       
  5411     PRINT( _L("Camera <> Get Stabilization info..") );
       
  5412     iAdvancedSettingInfo.iStabilizationModeSupport =
       
  5413         iAdvancedSettings->SupportedStabilizationModes();
       
  5414 
       
  5415     iAdvancedSettingInfo.iStabilizationEffectSupport =
       
  5416         iAdvancedSettings->SupportedStabilizationEffects();
       
  5417 
       
  5418     iAdvancedSettingInfo.iStabilizationComplexitySupport =
       
  5419         iAdvancedSettings->SupportedStabilizationComplexityValues();
       
  5420     // -----------------------------------------------------
       
  5421 
       
  5422 #ifdef CAMERAAPP_CAPI_V2_IP
       
  5423     // Image Processor only for primary camera
       
  5424     if( KPrimaryCameraIndex == iInfo.iCurrentCamera )
       
  5425       {
       
  5426       PRINT( _L("Camera <> Get image processing info..") );
       
  5427 
       
  5428       if( iImageProcessor != NULL )
       
  5429         {
       
  5430         // -----------------------------------------------------
       
  5431         PRINT( _L("Camera <> Get sharpness support..") );
       
  5432         TRAP( error, iImageProcessor->GetTransformationSupportedValuesL(
       
  5433                         KUidECamEventImageProcessingAdjustSharpness,
       
  5434                         iAdvancedSettingInfo.iSharpnessSupport,
       
  5435                         iAdvancedSettingInfo.iSharpnessValueInfo ) );
       
  5436         if( KErrNotSupported != error ) User::LeaveIfError( error );
       
  5437 
       
  5438         // -----------------------------------------------------
       
  5439         PRINT( _L("Camera <> Get colour effect support..") );
       
  5440         TRAP( error, iImageProcessor->GetTransformationSupportedValuesL(
       
  5441                           KUidECamEventImageProcessingEffect,
       
  5442                           iAdvancedSettingInfo.iColourEffectSupport,
       
  5443                           iAdvancedSettingInfo.iColourEffectValueInfo ) );
       
  5444         if( KErrNotSupported != error ) User::LeaveIfError( error );
       
  5445         }
       
  5446       else
       
  5447         {
       
  5448         PRINT( _L("Camera <> [WARNING] Image processing not supported") );
       
  5449         }
       
  5450       }
       
  5451 #endif // CAMERAAPP_CAPI_V2_IP
       
  5452     // -----------------------------------------------------
       
  5453     PRINT( _L("Camera <> ..done") );
       
  5454     CleanupStack::Pop(); // Cleanup item
       
  5455 
       
  5456     // Set only after successfully gathering the data
       
  5457     iAdvancedSettingInfo.iForCameraIndex = iInfo.iCurrentCamera;
       
  5458 
       
  5459 #ifdef _DEBUG
       
  5460     iAdvancedSettingInfo.PrintInfo();
       
  5461 #endif
       
  5462 
       
  5463   PRINT ( _L("Camera <= CCamCameraController::GetAdvancedSettingsInfoL") );
       
  5464   }
       
  5465 
       
  5466 
       
  5467 
       
  5468 // ---------------------------------------------------------------------------
       
  5469 // ResolveEvStep
       
  5470 //
       
  5471 // ---------------------------------------------------------------------------
       
  5472 //
       
  5473 TInt
       
  5474 CCamCameraController::ResolveEvStep( TInt aEvProposedStep ) const
       
  5475   {
       
  5476   PRINT1( _L("Camera => CCamCameraController::ResolveEvStep( %d )"), aEvProposedStep );
       
  5477 
       
  5478   TInt delta ( KMaxTInt );
       
  5479   TInt delta1( 0        );
       
  5480   TInt step  ( 0        );
       
  5481 
       
  5482   for( TInt i = 0; i < iAdvancedSettingInfo.iEvStepsSupport.Count() && delta != 0; i++ )
       
  5483     {
       
  5484     delta1 = Max( iAdvancedSettingInfo.iEvStepsSupport[i], aEvProposedStep )
       
  5485            - Min( iAdvancedSettingInfo.iEvStepsSupport[i], aEvProposedStep );
       
  5486 
       
  5487     if( delta1 < delta )
       
  5488       {
       
  5489       delta = delta1;
       
  5490       step  = iAdvancedSettingInfo.iEvStepsSupport[i];
       
  5491       }
       
  5492     }
       
  5493 
       
  5494   PRINT1( _L("Camera <= CCamCameraController::ResolveEvStep, return %d"), step );
       
  5495   return step;
       
  5496   }
       
  5497 
       
  5498 
       
  5499 // ---------------------------------------------------------------------------
       
  5500 // IsSupportedValue <<static>>
       
  5501 // ---------------------------------------------------------------------------
       
  5502 //
       
  5503 TBool
       
  5504 CCamCameraController::IsSupportedValue( const TInt&         aValue,
       
  5505                                         const RArray<TInt>& aValueList,
       
  5506                                         const TValueInfo&   aValueInfo )
       
  5507   {
       
  5508   TBool support( EFalse );
       
  5509 
       
  5510   switch( aValueInfo )
       
  5511     {
       
  5512     // -----------------------------------------------------
       
  5513     case EBitField:
       
  5514       {
       
  5515       // Supported values are described by a bitfield.
       
  5516       // Compare the support bitfield and the setting value.
       
  5517       // Default value for these settings is zero (0) and
       
  5518       // that is always supported.
       
  5519       // Array: [0] bitfield of supported bits
       
  5520       support = ( 1 <= aValueList.Count()
       
  5521                && ( !aValue
       
  5522                  || (aValue & aValueList[0]) // 0 always supported
       
  5523                   )
       
  5524                 );
       
  5525       break;
       
  5526       }
       
  5527     // -----------------------------------------------------
       
  5528     case EDiscreteSteps:
       
  5529       {
       
  5530       // All supported steps are listed, look for this one.
       
  5531       support = ( KErrNotFound != aValueList.Find( aValue ) );
       
  5532       break;
       
  5533       }
       
  5534     // -----------------------------------------------------
       
  5535     case EDiscreteRangeMinMaxStep:
       
  5536       {
       
  5537       // Support is described with evenly spaced steps between
       
  5538       // min and max value. Step is given.
       
  5539       // Array: [0] min supported value
       
  5540       //        [1] max supported value
       
  5541       //        [2] step between supported values
       
  5542       support =
       
  5543         ( 3      <= aValueList.Count()                 // We need 3 items.
       
  5544        && 1      <=  aValueList[2]                     // 1      <= step
       
  5545        && aValue >=  aValueList[0]                     // aValue >= min
       
  5546        && aValue <=  aValueList[1]                     // aValue <= max
       
  5547        && (aValue - aValueList[0])%aValueList[2] == 0  // aValue  = min + N*step
       
  5548         );
       
  5549       break;
       
  5550       }
       
  5551     // -----------------------------------------------------
       
  5552     case EContinuousRangeMinMax:
       
  5553       {
       
  5554       // Support is described by min and max value,
       
  5555       // continuous range of values within those two is supported.
       
  5556       // Array: [0] min supported value
       
  5557       //        [1] max supported value
       
  5558       support =
       
  5559         ( 2      <= aValueList.Count() // We need 2 items.
       
  5560        && aValue >= aValueList[0]      // aValue >= min
       
  5561        && aValue <= aValueList[1]      // aValue <= max
       
  5562         );
       
  5563       break;
       
  5564       }
       
  5565     // -----------------------------------------------------
       
  5566     case ENotActive:
       
  5567     default:
       
  5568       // Not supported setting
       
  5569       support = EFalse;
       
  5570       break;
       
  5571     // -----------------------------------------------------
       
  5572     }
       
  5573 
       
  5574   return support;
       
  5575   }
       
  5576 #endif // CAMERAAPP_CAPI_V2_ADV
       
  5577 
       
  5578 
       
  5579 // ---------------------------------------------------------------------------
       
  5580 // ResolveSnapshotFormat
       
  5581 //
       
  5582 // ---------------------------------------------------------------------------
       
  5583 //
       
  5584 CCamera::TFormat
       
  5585 CCamCameraController
       
  5586 ::ResolveSnapshotFormatL( CCamera::TFormat aPreferredFormat ) const
       
  5587   {
       
  5588   PRINT ( _L("Camera => CCamCameraController::ResolveSnapshotFormatL") );
       
  5589 
       
  5590   CheckNonNullL( iSnapshotProvider, KErrNotReady );
       
  5591 
       
  5592   const TUint32    support = iSnapshotProvider->SupportedFormats();
       
  5593   CCamera::TFormat final   = aPreferredFormat;
       
  5594 
       
  5595   // Return the preferred format if it is supported.
       
  5596   // Otherwise return the "best" supported format.
       
  5597   if      ( support & aPreferredFormat                   ) final = aPreferredFormat;
       
  5598   else if ( support & CCamera::EFormatFbsBitmapColor16MU ) final = CCamera::EFormatFbsBitmapColor16MU;
       
  5599   else if ( support & CCamera::EFormatFbsBitmapColor16M  ) final = CCamera::EFormatFbsBitmapColor16M;
       
  5600   else if ( support & CCamera::EFormatFbsBitmapColor64K  ) final = CCamera::EFormatFbsBitmapColor64K;
       
  5601   else if ( support & CCamera::EFormatFbsBitmapColor4K   ) final = CCamera::EFormatFbsBitmapColor4K;
       
  5602   else
       
  5603     {
       
  5604     // No known acceptable format supported
       
  5605     PRINT( _L("Camera <> CCamCameraController: No acceptable format available, LEAVE!") );
       
  5606     User::Leave( KErrNotSupported );
       
  5607     }
       
  5608 
       
  5609   PRINT1( _L("Camera <> Preferred format : %032b"), aPreferredFormat  );
       
  5610   PRINT1( _L("Camera <> Supported formats: %032b"), support           );
       
  5611   PRINT1( _L("Camera <> Selected  format : %032b"), final             );
       
  5612   PRINT ( _L("Camera <= CCamCameraController::ResolveSnapshotFormatL") );
       
  5613   return final;
       
  5614   }
       
  5615 
       
  5616 
       
  5617 
       
  5618 // ---------------------------------------------------------------------------
       
  5619 // Request2Event <<static>>
       
  5620 //
       
  5621 // Convert request id to event id
       
  5622 // ---------------------------------------------------------------------------
       
  5623 //
       
  5624 TCamCameraEventId
       
  5625 CCamCameraController::Request2Event( const TCamCameraRequestId& aType )
       
  5626   {
       
  5627   switch( aType )
       
  5628     {
       
  5629     // -----------------------------------------------------
       
  5630     // Camera control
       
  5631     case ECamRequestReserve:       return ECamCameraEventReserveGain;
       
  5632     case ECamRequestRelease:       return ECamCameraEventReserveLose;
       
  5633     case ECamRequestPowerOn:       return ECamCameraEventPowerOn;
       
  5634     case ECamRequestPowerOff:      return ECamCameraEventPowerOff;
       
  5635     // -----------------------------------------------------
       
  5636     // Viewfinder
       
  5637     case ECamRequestVfStart:       return ECamCameraEventVfStart;
       
  5638     case ECamRequestVfStop:        return ECamCameraEventVfStop;
       
  5639     case ECamRequestVfRelease:     return ECamCameraEventVfRelease;
       
  5640     // -----------------------------------------------------
       
  5641     // Snapshot
       
  5642     case ECamRequestSsStart:        return ECamCameraEventSsStart;
       
  5643     case ECamRequestSsStop:         return ECamCameraEventSsStop;
       
  5644     case ECamRequestSsRelease:      return ECamCameraEventSsRelease;
       
  5645     // -----------------------------------------------------
       
  5646     // Still capture
       
  5647     case ECamRequestImageInit:     return ECamCameraEventImageInit;
       
  5648     case ECamRequestImageCapture:  return ECamCameraEventImageStart;
       
  5649     case ECamRequestImageCancel:   return ECamCameraEventImageStop;
       
  5650     case ECamRequestImageRelease:  return ECamCameraEventImageRelease;
       
  5651     // -----------------------------------------------------
       
  5652     // Video recording
       
  5653     case ECamRequestVideoInit:     return ECamCameraEventVideoInit;
       
  5654     case ECamRequestVideoStart:    return ECamCameraEventVideoStart;
       
  5655     case ECamRequestVideoPause:    return ECamCameraEventVideoPause;
       
  5656     case ECamRequestVideoStop:     return ECamCameraEventVideoStop;
       
  5657     case ECamRequestVideoRelease:  return ECamCameraEventVideoRelease;
       
  5658     // -----------------------------------------------------
       
  5659     // Autofocus
       
  5660     case ECamRequestStartAutofocus:   return ECamCameraEventStartAutofocus;
       
  5661     case ECamRequestCancelAutofocus:  return ECamCameraEventCancelAutofocus;
       
  5662     case ECamRequestSetAfRange:       return ECamCameraEventSetAfRange;
       
  5663     // -----------------------------------------------------
       
  5664 
       
  5665     // Unrecognised
       
  5666     default:
       
  5667       {
       
  5668       Panic( ECamCameraControllerUnknownRequest );
       
  5669       return ECamCameraEventNone;
       
  5670       }
       
  5671     // -----------------------------------------------------
       
  5672     }
       
  5673   }
       
  5674 
       
  5675 
       
  5676 // ---------------------------------------------------------------------------
       
  5677 // EventClass <<static>>
       
  5678 //
       
  5679 // Get the event class for an event
       
  5680 // ---------------------------------------------------------------------------
       
  5681 //
       
  5682 TCamCameraEventClassId
       
  5683 CCamCameraController::EventClass( const TCamCameraEventId& aEventId )
       
  5684   {
       
  5685   switch( aEventId )
       
  5686     {
       
  5687     // -------------------------------------------------------
       
  5688     case ECamCameraEventSequenceEnd:
       
  5689     case ECamCameraEventReserveGain:
       
  5690     case ECamCameraEventReserveLose:
       
  5691     case ECamCameraEventPowerOn:
       
  5692     case ECamCameraEventPowerOff:
       
  5693       return ECamCameraEventClassBasicControl;
       
  5694     // -------------------------------------------------------
       
  5695     case ECamCameraEventVfStart:
       
  5696     case ECamCameraEventVfStop:
       
  5697     case ECamCameraEventVfRelease:
       
  5698       return ECamCameraEventClassVfControl;
       
  5699     // -------------------------------------------------------
       
  5700     case ECamCameraEventVfFrameReady:
       
  5701       return ECamCameraEventClassVfData;
       
  5702     // -------------------------------------------------------
       
  5703     case ECamCameraEventSsStart:
       
  5704     case ECamCameraEventSsStop:
       
  5705     case ECamCameraEventSsRelease:
       
  5706       return ECamCameraEventClassSsControl;
       
  5707     // -------------------------------------------------------
       
  5708     case ECamCameraEventSsReady:
       
  5709       return ECamCameraEventClassSsData;
       
  5710     // -------------------------------------------------------
       
  5711     case ECamCameraEventImageInit:
       
  5712     case ECamCameraEventImageStart:
       
  5713     case ECamCameraEventImageStop:
       
  5714     case ECamCameraEventImageRelease:
       
  5715     case ECamCameraEventImageData:
       
  5716     case ECamCameraEventImageCaptureEvent:
       
  5717       return ECamCameraEventClassImage;
       
  5718     // -------------------------------------------------------
       
  5719     case ECamCameraEventVideoInit:
       
  5720     case ECamCameraEventVideoStart:
       
  5721     case ECamCameraEventVideoPause:
       
  5722     case ECamCameraEventVideoStop:
       
  5723     case ECamCameraEventVideoRelease:
       
  5724       return ECamCameraEventClassVideo;
       
  5725     // -------------------------------------------------------
       
  5726     case ECamCameraEventVideoTimes:
       
  5727       return ECamCameraEventClassVideoTimes;
       
  5728     // -------------------------------------------------------
       
  5729     case ECamCameraEventSettingsSingle:
       
  5730     case ECamCameraEventSettingsDone:
       
  5731       return ECamCameraEventClassSettings;
       
  5732     // -------------------------------------------------------
       
  5733     case ECamCameraEventStartAutofocus:
       
  5734     case ECamCameraEventCancelAutofocus:
       
  5735     case ECamCameraEventAutofocusSuccessful:
       
  5736     case ECamCameraEventAutofocusFailed:
       
  5737     case ECamCameraEventSetAfRange:
       
  5738       return ECamCameraEventClassAutofocus;
       
  5739     // -------------------------------------------------------
       
  5740     case ECamCameraEventFlashReady:
       
  5741     case ECamCameraEventFlashNotReady:
       
  5742       return ECamCameraEventClassFlashStatus;
       
  5743     // -------------------------------------------------------
       
  5744     default:
       
  5745       {
       
  5746     #ifdef _DEBUG
       
  5747       Panic( ECamCameraControllerCorrupt );
       
  5748     #endif
       
  5749       return ECamCameraEventClassAll;
       
  5750       }
       
  5751     }
       
  5752   }
       
  5753 
       
  5754 
       
  5755 
       
  5756 // ---------------------------------------------------------------------------
       
  5757 // HasCallback
       
  5758 // ---------------------------------------------------------------------------
       
  5759 //
       
  5760 TBool
       
  5761 CCamCameraController::HasCallback( const TCamCameraRequestId& aType )
       
  5762   {
       
  5763   TBool callback = EFalse;
       
  5764   switch( aType )
       
  5765     {
       
  5766     // -----------------------------------------------------
       
  5767     case ECamRequestReserve:      // ReserveComplete / KUidECamEventReserveComplete
       
  5768     case ECamRequestPowerOn:      // PowerOnComplete / KUidECamEventPowerOnComplete
       
  5769 
       
  5770     case ECamRequestImageCapture: // ImageReady      / ImageBufferReady
       
  5771 
       
  5772 #ifdef CAMERAAPP_CAE_FOR_VIDEO
       
  5773     case ECamRequestVideoInit:    // McaeoVideoPrepareComplete
       
  5774     case ECamRequestVideoStart:   // McaeoVideoRecordingOn
       
  5775     case ECamRequestVideoPause:   // McaeoVideoRecordingPaused
       
  5776     case ECamRequestVideoStop:    // McaeoVideoRecordingComplete
       
  5777 #endif
       
  5778       callback = ETrue;
       
  5779       break;
       
  5780     // -----------------------------------------------------
       
  5781     default:
       
  5782       callback = EFalse;
       
  5783       break;
       
  5784     // -----------------------------------------------------
       
  5785     }
       
  5786   return callback;
       
  5787   }
       
  5788 
       
  5789 // ---------------------------------------------------------------------------
       
  5790 // CurrentSettingHasCallback
       
  5791 // ---------------------------------------------------------------------------
       
  5792 //
       
  5793 TBool
       
  5794 CCamCameraController::CurrentSettingHasCallback()
       
  5795   {
       
  5796   TBool callback( EFalse );
       
  5797 #ifdef CAMERAAPP_CAE_FOR_VIDEO
       
  5798   if( IsFlagOn( iInfo.iState, ECamVideoOn ) )
       
  5799     {
       
  5800     switch( iSettingArray[iSettingIndex] )
       
  5801       {
       
  5802       case ECameraSettingFileName:
       
  5803       case ECameraSettingFileMaxSize:
       
  5804         callback = ETrue;
       
  5805         break;
       
  5806       default:
       
  5807         break;
       
  5808       }
       
  5809     }
       
  5810   else
       
  5811     {
       
  5812     // no callback if not prepared for video yet.
       
  5813     }
       
  5814 #endif
       
  5815   return callback;
       
  5816   }
       
  5817 
       
  5818 #ifdef CAMERAAPP_CAE_FOR_VIDEO
       
  5819 // ---------------------------------------------------------------------------
       
  5820 // NewCaeEngineL
       
  5821 // ---------------------------------------------------------------------------
       
  5822 //
       
  5823 CCaeEngine*
       
  5824 CCamCameraController::NewCaeEngineL( TInt aCameraIndex )
       
  5825   {
       
  5826   PRINT( _L("Camera => CCamCameraController::NewCaeEngineL") );
       
  5827 
       
  5828 #ifndef FORCE_DUMMY_ENGINE
       
  5829   CCaeEngine* engine = CCaeEngine::NewL( aCameraIndex );
       
  5830 #else
       
  5831   (void)aCameraIndex; // remove compiler warning
       
  5832   CCaeEngine* engine = CCameraappDummyEngine::NewL();
       
  5833 #endif
       
  5834 
       
  5835   engine->SetCamAppEngineObserver( *this );
       
  5836 
       
  5837   PRINT( _L("Camera <= CCamCameraController::NewCaeEngineL") );
       
  5838   return engine;
       
  5839   }
       
  5840 #endif
       
  5841 
       
  5842 // ---------------------------------------------------------------------------
       
  5843 // NewCameraL
       
  5844 // ---------------------------------------------------------------------------
       
  5845 //
       
  5846 CAMERA*
       
  5847 CCamCameraController::NewCameraL( TInt aCameraIndex )
       
  5848   {
       
  5849   PRINT( _L("Camera => CCamCameraController::NewCameraL") );
       
  5850   CAMERA* camera( NULL );
       
  5851 #ifdef CAMERAAPP_CAPI_V2
       
  5852   camera = CAMERA::New2L( *this, aCameraIndex, KCameraClientPriority );
       
  5853 #else
       
  5854 
       
  5855   // Both v1 and v2 observer interface implemented
       
  5856   // Need to cast to avoid ambiguous call.
       
  5857   MCameraObserver* self( this );
       
  5858   PRINT1( _L("Camera <> Give observer pointer: %d"), self );
       
  5859 
       
  5860   camera = CAMERA::NewL ( *self, aCameraIndex );
       
  5861 
       
  5862 #endif // CAMERAAPP_CAPI_V2
       
  5863 
       
  5864   PRINT( _L("Camera <= CCamCameraController::NewCameraL") );
       
  5865   return camera;
       
  5866   }
       
  5867 
       
  5868 // ---------------------------------------------------------------------------
       
  5869 // NewDuplicateCameraL
       
  5870 // ---------------------------------------------------------------------------
       
  5871 //
       
  5872 CAMERA*
       
  5873 CCamCameraController::NewDuplicateCameraL( TInt aCameraHandle )
       
  5874   {
       
  5875   PRINT1( _L("Camera => CCamCameraController::NewDuplicateCameraL( %d )"), aCameraHandle );
       
  5876   CAMERA* camera( NULL );
       
  5877 
       
  5878 #ifdef CAMERAAPP_CAPI_V2
       
  5879   PRINT( _L("Camera <> call NewDuplicate2L..") );
       
  5880   camera = CAMERA::NewDuplicate2L( *this, aCameraHandle );
       
  5881 #else
       
  5882   MCameraObserver* self( this );
       
  5883   PRINT( _L("Camera <> call NewDuplicateL..") );
       
  5884   camera = CAMERA::NewDuplicateL ( *self, aCameraHandle );
       
  5885 #endif
       
  5886 
       
  5887   PRINT( _L("Camera <= CCamCameraController::NewCameraL") );
       
  5888   return camera;
       
  5889   }
       
  5890 
       
  5891 
       
  5892 // ===========================================================================
       
  5893 // Constructors
       
  5894 
       
  5895 
       
  5896 // ---------------------------------------------------------------------------
       
  5897 // 2nd phase constructor
       
  5898 // ---------------------------------------------------------------------------
       
  5899 //
       
  5900 void
       
  5901 CCamCameraController::ConstructL( TInt aCameraIndex )
       
  5902   {
       
  5903   iActive = CCamCameraControllerActive::NewL( *this, KCamCallBackPriority );
       
  5904   iIveRecoveryCount = KIveRecoveryCountMax;
       
  5905 
       
  5906 #ifdef CAMERAAPP_PERFORMANCE_CONTROLLER
       
  5907   iPerformanceLogger    = new (ELeave) CCamPerformanceLogger;
       
  5908   iFirstVfFrameReceived = EFalse;
       
  5909 #endif
       
  5910 
       
  5911 #ifdef CAMERAAPP_FLASH_SIMULATOR
       
  5912   iFlashSimulator = CCamFlashSimulator::NewL( *this );
       
  5913 #endif
       
  5914 
       
  5915   SwitchCameraL( aCameraIndex );
       
  5916   iAsyncVideoStopModeSupported = EFalse;
       
  5917 
       
  5918   }
       
  5919 
       
  5920 
       
  5921 
       
  5922 // ---------------------------------------------------------------------------
       
  5923 // 1st phase constructor
       
  5924 // ---------------------------------------------------------------------------
       
  5925 //
       
  5926 CCamCameraController
       
  5927 ::CCamCameraController( MCamSettingProvider& aSettingProvider,
       
  5928                         CCamAppController& aAppController )
       
  5929   : iSequenceArray       ( KCamSequenceGranularity     ),
       
  5930     iReserveTryAgainCount( KCamReserveTryAgainMaxCount ),
       
  5931     iSettingProvider     ( aSettingProvider            ),
       
  5932     iAppController       ( aAppController              )
       
  5933   {
       
  5934   }
       
  5935 
       
  5936 
       
  5937 // ===========================================================================
       
  5938 // Workaround for CCaeEngine with no support for CCamera sharing
       
  5939 
       
  5940 #ifdef CAMERAAPP_CAE_FIX
       
  5941 // ---------------------------------------------------------------------------
       
  5942 // ---------------------------------------------------------------------------
       
  5943 //
       
  5944 TInt
       
  5945 CCamCameraController::ProceedModeSwitch()
       
  5946   {
       
  5947   PRINT1( _L("Camera => CCamCameraController::ProceedModeSwitch, status in:%d"), iModeChangeStatus );
       
  5948   TInt proceed( EFalse );
       
  5949 
       
  5950   // Update only after here, so any events arriving
       
  5951   // in the middle get ignored if wanted.
       
  5952   ++iModeChangePhase;
       
  5953 
       
  5954   if( KErrNone == iModeChangeStatus )
       
  5955     {
       
  5956     TRAP( iModeChangeStatus, proceed = DoProceedModeSwitchL() );
       
  5957     }
       
  5958 
       
  5959   if( KErrNone != iModeChangeStatus )
       
  5960     {
       
  5961     PRINT1( _L("Camera <> Mode switch error: %d"), iModeChangeStatus );
       
  5962     iModeChange       = ECamModeChangeInactive;
       
  5963     iModeChangePhase  = ECamModeChangePhase0;
       
  5964     iModeChangeStatus = KErrNone;
       
  5965 
       
  5966     PRINT( _L("Camera <> Deleting engine..") );
       
  5967     delete iCaeEngine;
       
  5968     iCaeEngine = NULL;
       
  5969 
       
  5970     PRINT( _L("Camera <> Deleting camera..") );
       
  5971     delete iCamera;
       
  5972     iCamera = NULL;
       
  5973 
       
  5974     iInfo.Reset();
       
  5975 
       
  5976     PRINT( _L("Camera <> PANIC!!") );
       
  5977 
       
  5978     Panic( ECamCameraControllerUnrecovableError );
       
  5979     }
       
  5980 
       
  5981   PRINT1( _L("Camera <= CCamCameraController::ProceedModeSwitch, more calls now:%d"), proceed );
       
  5982   return proceed;
       
  5983   }
       
  5984 
       
  5985 // ---------------------------------------------------------------------------
       
  5986 // ---------------------------------------------------------------------------
       
  5987 //
       
  5988 TInt
       
  5989 CCamCameraController::DoProceedModeSwitchL()
       
  5990   {
       
  5991   PRINT( _L("Camera => CCamCameraController::DoProceedModeSwitchL") );
       
  5992   User::LeaveIfError( iModeChangeStatus );
       
  5993 
       
  5994   TBool callback = ETrue;
       
  5995 
       
  5996   // -------------------------------------------------------
       
  5997   if( ECamModeChangeImage2Video == iModeChange )
       
  5998     {
       
  5999     PRINT( _L("Camera <> Changing mode image => video") );
       
  6000     switch( iModeChangePhase )
       
  6001       {
       
  6002       // First two phases only usable if CAE v1 in use.
       
  6003       // Must start from phase2 otherwise.
       
  6004       // -------------------------------
       
  6005       case ECamModeChangePhase0:
       
  6006         {
       
  6007         PRINT( _L("Camera <> Phase0: Release camera..") );
       
  6008         TInt cameraIndex = iInfo.iCurrentCamera;
       
  6009         ReleaseCurrentCamera();
       
  6010         SwitchCameraL( cameraIndex );
       
  6011         CompleteSwitchCameraL();
       
  6012         callback = EFalse;
       
  6013         // iModeChangePhase is incremented when iActive->RunL calls
       
  6014         // ProcessNextRequestL for the next time.
       
  6015         break;
       
  6016         }
       
  6017       // -------------------------------
       
  6018       case ECamModeChangePhase1:
       
  6019         {
       
  6020         PRINT( _L("Camera <> Phase1: calling CCaeEngine::InitL..") );
       
  6021         iCaeEngine->InitL();
       
  6022         iCaeInUse = ETrue;
       
  6023         // Continue mode change in callback
       
  6024         PRINT( _L("Camera <> ..waiting for to complete") );
       
  6025         break;
       
  6026         }
       
  6027       // -------------------------------
       
  6028       case ECamModeChangePhase2:
       
  6029         {
       
  6030         PRINT( _L("Camera <> Phase2: Prepare video..") );
       
  6031         PRINT( _L("Camera <> Call InitVideoRecorderL..") );
       
  6032         iCaeEngine->InitVideoRecorderL();
       
  6033 
       
  6034         PRINT( _L("Camera <> Ask filename..") );
       
  6035 //        HBufC* filename( HBufC::NewLC( KMaxFileName ) );
       
  6036 //        TPtr   ptr     ( filename->Des()              );
       
  6037 //        iSettingProvider.ProvideCameraSettingL( ECameraSettingFileName, &ptr );
       
  6038         _LIT( KTempFilename, "C:\\video.3gp" );
       
  6039         TPtrC ptr;
       
  6040         ptr.Set( KTempFilename() );
       
  6041 #pragma message( "Camera Controller: video filename hardcoded" )
       
  6042         PRINT1( _L("Camera <> Set filename [%S]"), &ptr );
       
  6043         iCaeEngine->SetVideoRecordingFileNameL( ptr );
       
  6044 //        CleanupStack::PopAndDestroy( filename );
       
  6045 
       
  6046 
       
  6047         // Set max video clip size
       
  6048         ProcessSettingL( ECameraSettingFileMaxSize );
       
  6049 
       
  6050 
       
  6051         TPckgBuf<TCamParamsVideoCae> params;
       
  6052         iSettingProvider.ProvideCameraParamL( ECameraParamVideoCae, &params );
       
  6053         // The audioOn value is defined On==0 and Off==1, but the engine expects
       
  6054         // ETrue if audio recording is On
       
  6055         params().iAudioOn = ( ECamSettOn == params().iAudioOn )
       
  6056         											? ETrue
       
  6057         											: EFalse;
       
  6058         PRINT( _L("Camera <> Call prepare..") );
       
  6059         // McaeoVideoPrepareComplete will be called when prepare is ready.
       
  6060         // The callback is allowed to come also *during* this call.
       
  6061         iCaeEngine->PrepareVideoRecordingL( params().iFrameSize,
       
  6062                                             params().iFrameRate,
       
  6063                                             params().iVideoBitRate,
       
  6064                                             params().iAudioOn,
       
  6065                                             params().iAudioBitRate,
       
  6066                                             params().iMimeType,
       
  6067                                             params().iSupplier,
       
  6068                                             params().iVideoType,
       
  6069                                             params().iAudioType );
       
  6070 
       
  6071 //        iCaeEngine->PrepareVideoRecordingL( 0 );
       
  6072 
       
  6073         break;
       
  6074         }
       
  6075       // -------------------------------
       
  6076       case ECamModeChangePhase3:
       
  6077         {
       
  6078         PRINT( _L("Camera <> Phase3: Notifying..") );
       
  6079         iModeChange      = ECamModeChangeInactive;
       
  6080         iModeChangePhase = ECamModeChangePhaseIdle;
       
  6081         callback         = EFalse;
       
  6082 
       
  6083         NotifyObservers( iModeChangeStatus,
       
  6084                          ECamCameraEventVideoInit,
       
  6085                          ECamCameraEventClassVideo );
       
  6086         break;
       
  6087         }
       
  6088       // -------------------------------
       
  6089       default:
       
  6090         {
       
  6091         Panic( ECamCameraControllerCorrupt );
       
  6092         break;
       
  6093         }
       
  6094       // -------------------------------
       
  6095       }
       
  6096     }
       
  6097   // -------------------------------------------------------
       
  6098   else if( ECamModeChangeVideo2Image == iModeChange )
       
  6099     {
       
  6100     PRINT( _L("Camera <> Changing mode video => image") );
       
  6101     switch( iModeChangePhase )
       
  6102       {
       
  6103       // -------------------------------
       
  6104       case ECamModeChangePhase0:
       
  6105         {
       
  6106         PRINT( _L("Camera <> Phase0: Release camera..") );
       
  6107         TInt cameraIndex = iInfo.iCurrentCamera;
       
  6108         ReleaseCurrentCamera();
       
  6109         SwitchCameraL( cameraIndex );
       
  6110         CompleteSwitchCameraL();
       
  6111         callback = EFalse;
       
  6112         break;
       
  6113         }
       
  6114       // -------------------------------
       
  6115       case ECamModeChangePhase1:
       
  6116         {
       
  6117         PRINT( _L("Camera <> Phase1: Reserve camera..") );
       
  6118         iCaeInUse = EFalse;
       
  6119         iCamera->Reserve();
       
  6120         break;
       
  6121         }
       
  6122       // -------------------------------
       
  6123       case ECamModeChangePhase2:
       
  6124         {
       
  6125         PRINT( _L("Camera <> Phase2: Power on..") );
       
  6126         iCamera->PowerOn();
       
  6127         break;
       
  6128         }
       
  6129       // -------------------------------
       
  6130       case ECamModeChangePhase3:
       
  6131         {
       
  6132         PRINT( _L("Camera <> Phase3: Prepare image..") );
       
  6133         TPckgBuf<TCamParamsImage> params;
       
  6134         iSettingProvider.ProvideCameraParamL( ECameraParamImage, &params );
       
  6135 
       
  6136         // Query the supported resolutions for the selected format.
       
  6137         TInt index = GetResolutionIndexL( params().iFormat, params().iSize );
       
  6138         User::LeaveIfError( index );
       
  6139 
       
  6140         PRINT2( _L("Camera <> Image size: (%d, %d)"),
       
  6141                   params().iSize.iWidth,
       
  6142                   params().iSize.iHeight );
       
  6143         iCamera->PrepareImageCaptureL( params().iFormat, index );
       
  6144         iCamera->SetJpegQuality( params().iQualityFactor );
       
  6145 
       
  6146         SetFlags( iInfo.iState, ECamImageOn );
       
  6147 
       
  6148         callback  = EFalse;
       
  6149         break;
       
  6150         }
       
  6151       // -------------------------------
       
  6152       case ECamModeChangePhase4:
       
  6153         {
       
  6154         PRINT( _L("Camera <> Phase4: Notifying..") );
       
  6155         iModeChange      = ECamModeChangeInactive;
       
  6156         iModeChangePhase = ECamModeChangePhaseIdle;
       
  6157         callback         = EFalse;
       
  6158 
       
  6159         NotifyObservers( iModeChangeStatus,
       
  6160                          ECamCameraEventImageInit,
       
  6161                          ECamCameraEventClassImage );
       
  6162 
       
  6163         break;
       
  6164         }
       
  6165       // -------------------------------
       
  6166       default:
       
  6167         {
       
  6168         Panic( ECamCameraControllerCorrupt );
       
  6169         break;
       
  6170         }
       
  6171       // -------------------------------
       
  6172       }
       
  6173     }
       
  6174   // -------------------------------------------------------
       
  6175   else
       
  6176     {
       
  6177     Panic( ECamCameraControllerCorrupt );
       
  6178     }
       
  6179   // -------------------------------------------------------
       
  6180 
       
  6181   PRINT1( _L("Camera <= CCamCameraController::DoProceedModeSwitchL, more calls now:%d"), !callback );
       
  6182   return !callback;
       
  6183   }
       
  6184 #endif // CAMERAAPP_CAE_FIX
       
  6185 
       
  6186 
       
  6187 /**
       
  6188 * CCamCameraController::RemainingVideoRecordingTime()
       
  6189 * Method to retrieve Remaining Recording time from CCaeEngine
       
  6190 * which is used in AppController and AppUi during Video Rec Operation
       
  6191 */
       
  6192 TTimeIntervalMicroSeconds
       
  6193 CCamCameraController::RemainingVideoRecordingTime()
       
  6194 	{
       
  6195 	if( iCaeEngine )
       
  6196   	return iCaeEngine->RemainingVideoRecordingTime();
       
  6197   else
       
  6198     return 0;
       
  6199 	}
       
  6200 
       
  6201 
       
  6202 // ===========================================================================
       
  6203 // Performance measurement related
       
  6204 
       
  6205 #ifdef CAMERAAPP_PERFORMANCE_CONTROLLER
       
  6206 
       
  6207 // ---------------------------------------------------------------------------
       
  6208 // PerformanceLogger()
       
  6209 //
       
  6210 // Return the performance logger instance.
       
  6211 // Used to record performance measurement data.
       
  6212 // ---------------------------------------------------------------------------
       
  6213 //
       
  6214 const CCamPerformanceLogger*
       
  6215 CCamCameraController::PerformanceLogger() const
       
  6216   {
       
  6217   return iPerformanceLogger;
       
  6218   }
       
  6219 
       
  6220 #endif // CAMERAAPP_PERFORMANCE_CONTROLLER
       
  6221 
       
  6222 
       
  6223 
       
  6224 // ===========================================================================
       
  6225 // Debug prints
       
  6226 
       
  6227 #ifdef _DEBUG
       
  6228 // ---------------------------------------------------------------------------
       
  6229 // PrintCameraInfo
       
  6230 // ---------------------------------------------------------------------------
       
  6231 //
       
  6232 void
       
  6233 CCamCameraController::PrintCameraInfo() const
       
  6234   {
       
  6235   PRINT ( _L("Camera <> ==================================================") );
       
  6236   PRINT ( _L("Camera <> Camera info:") );
       
  6237   PRINT3( _L("Camera <> Camera hw version[%d.%d.%d]"),
       
  6238           iCameraInfo.iHardwareVersion.iMajor,
       
  6239           iCameraInfo.iHardwareVersion.iMinor,
       
  6240           iCameraInfo.iHardwareVersion.iBuild );
       
  6241   PRINT3( _L("Camera <> Camera sw version[%d.%d.%d]"),
       
  6242           iCameraInfo.iSoftwareVersion.iMajor,
       
  6243           iCameraInfo.iSoftwareVersion.iMinor,
       
  6244           iCameraInfo.iSoftwareVersion.iBuild );
       
  6245   PRINT1( _L("Camera <> TCameraInfo.iMinZoom             : %d"), iCameraInfo.iMinZoom );
       
  6246   PRINT1( _L("Camera <> TCameraInfo.iMaxZoom             : %d"), iCameraInfo.iMaxZoom );
       
  6247   PRINT1( _L("Camera <> TCameraInfo.iMaxDigitalZoom      : %d"), iCameraInfo.iMaxDigitalZoom );
       
  6248   PRINT1( _L("Camera <> TCameraInfo.iMinZoomFactor       : %f"), iCameraInfo.iMinZoomFactor );
       
  6249   PRINT1( _L("Camera <> TCameraInfo.iMaxZoomFactor       : %f"), iCameraInfo.iMaxZoomFactor );
       
  6250   PRINT1( _L("Camera <> TCameraInfo.iMaxDigitalZoomFactor: %f"), iCameraInfo.iMaxDigitalZoomFactor );
       
  6251   PRINT ( _L("Camera <> ==================================================") );
       
  6252   }
       
  6253 
       
  6254 
       
  6255 // ---------------------------------------------------------------------------
       
  6256 // PrintSnapshotInfo
       
  6257 // ---------------------------------------------------------------------------
       
  6258 //
       
  6259 void
       
  6260 CCamCameraController::PrintSnapshotInfo() const
       
  6261   {
       
  6262   PRINT ( _L("Camera <> ===========================================================") );
       
  6263   PRINT ( _L("Camera <> Snapshot info"  ) );
       
  6264   PRINT1( _L("Camera <> Formats supported (1st)  : %032b"  ), iSnapshotProvider->SupportedFormats() );
       
  6265   PRINT1( _L("Camera <> EFormatFbsBitmapColor4K  : %032b"  ), CCamera::EFormatFbsBitmapColor4K      );
       
  6266   PRINT1( _L("Camera <> EFormatFbsBitmapColor64K : %032b"  ), CCamera::EFormatFbsBitmapColor64K     );
       
  6267   PRINT1( _L("Camera <> EFormatFbsBitmapColor16M : %032b"  ), CCamera::EFormatFbsBitmapColor16M     );
       
  6268   PRINT1( _L("Camera <> EFormatFbsBitmapColor16MU: %032b"  ), CCamera::EFormatFbsBitmapColor16MU    );
       
  6269   PRINT ( _L("Camera <> ===========================================================")               );
       
  6270   }
       
  6271 
       
  6272 // ===========================================================================
       
  6273 #endif // _DEBUG
       
  6274 
       
  6275 // ---------------------------------------------------------------------------
       
  6276 // CCamCameraController::SettingValueUpToDateL
       
  6277 // ---------------------------------------------------------------------------
       
  6278 //
       
  6279 TBool
       
  6280 CCamCameraController::SettingValueUpToDateL( const NCamCameraController::TCamCameraSettingId& aSettingId )
       
  6281   {
       
  6282   PRINT( _L("Camera => CCamCameraController::SettingValueUpToDate") );
       
  6283   TBool upToDate = ETrue;
       
  6284 
       
  6285   switch( aSettingId )
       
  6286     {
       
  6287     case ECameraSettingFlash:
       
  6288     case ECameraUserSceneSettingFlash:
       
  6289       {
       
  6290       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingFlash") );
       
  6291 
       
  6292       // Supposed setting value from settings provider
       
  6293       CCamera::TFlash flashSetting( CCamera::EFlashNone );
       
  6294       iSettingProvider.ProvideCameraSettingL( aSettingId, &flashSetting );
       
  6295 
       
  6296       // Real settings value from camera
       
  6297       CCamera::TFlash flashValue( CCamera::EFlashNone );
       
  6298       GetCameraSettingValueL( aSettingId, &flashValue );
       
  6299 
       
  6300       PRINT2( _L("Camera <> flashValue = %d, flashSetting = %d"), flashValue, flashSetting );
       
  6301       upToDate = ( flashValue == flashSetting );
       
  6302       break;
       
  6303       }
       
  6304     case ECameraSettingExposure:
       
  6305     case ECameraUserSceneSettingExposure:
       
  6306       {
       
  6307       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingExposure") );
       
  6308       TPckgBuf<TCamSettingDataExposure> exposureSetting;
       
  6309       iSettingProvider.ProvideCameraSettingL( aSettingId, &exposureSetting );
       
  6310 
       
  6311       TPckgBuf<TCamSettingDataExposure> exposureValue;
       
  6312       GetCameraSettingValueL( aSettingId, &exposureValue );
       
  6313 
       
  6314       if ( exposureSetting().iExposureMode != exposureValue().iExposureMode ||
       
  6315            exposureSetting().iExposureStep != exposureValue().iExposureStep )
       
  6316         {
       
  6317         upToDate = EFalse;
       
  6318         }
       
  6319 
       
  6320       break;
       
  6321       }
       
  6322     case ECameraSettingLightSensitivity:
       
  6323     case ECameraUserSceneSettingLightSensitivity:
       
  6324       {
       
  6325       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingLightSensitivity") );
       
  6326 
       
  6327       RArray<TInt> ISOarray;
       
  6328       CleanupClosePushL( ISOarray );
       
  6329 #ifdef CAMERAAPP_CAPI_V2
       
  6330       iAdvancedSettings->GetSupportedIsoRatesL( ISOarray );
       
  6331 #endif
       
  6332       iSettingProvider.SetSupportedISORatesL( ISOarray );
       
  6333 
       
  6334       TInt* isoSetting = 0;
       
  6335       iSettingProvider.ProvideCameraSettingL( aSettingId, &isoSetting );
       
  6336       CleanupStack::PopAndDestroy( &ISOarray );
       
  6337 
       
  6338 
       
  6339       TInt* isoValue = 0;
       
  6340       GetCameraSettingValueL( aSettingId, &isoValue );
       
  6341 
       
  6342       upToDate = ( isoSetting == isoValue );
       
  6343       break;
       
  6344       }
       
  6345     case ECameraSettingWhiteBalance:
       
  6346     case ECameraUserSceneSettingWhiteBalance:
       
  6347       {
       
  6348       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingWhiteBalance") );
       
  6349 
       
  6350       TPckgBuf<TCamSettingDataWhiteBalance> wbSetting;
       
  6351       iSettingProvider.ProvideCameraSettingL( aSettingId, &wbSetting );
       
  6352 
       
  6353       TPckgBuf<TCamSettingDataWhiteBalance> wbValue;
       
  6354       GetCameraSettingValueL( aSettingId, &wbValue );
       
  6355 
       
  6356       upToDate = ( wbSetting().iWhiteBalanceMode == wbValue().iWhiteBalanceMode );
       
  6357       break;
       
  6358       }
       
  6359     case ECameraSettingColourEffect:
       
  6360     case ECameraUserSceneSettingColourEffect:
       
  6361       {
       
  6362       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingColourEffect") );
       
  6363 
       
  6364       CIP::TEffect effectSetting( CIP::EEffectNone );
       
  6365       iSettingProvider.ProvideCameraSettingL( aSettingId, &effectSetting );
       
  6366 
       
  6367       CIP::TEffect effectValue( CIP::EEffectNone );
       
  6368       // Can't leave here or other settings won't be restored
       
  6369       TRAP_IGNORE( GetCameraSettingValueL( aSettingId, &effectValue ) );
       
  6370 
       
  6371       upToDate = ( effectSetting == effectValue );
       
  6372       break;
       
  6373       }
       
  6374     case ECameraSettingBrightness:
       
  6375     case ECameraUserSceneSettingBrightness:
       
  6376       {
       
  6377       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingBrightness") );
       
  6378       CCamera::TBrightness brightnessSetting;
       
  6379       iSettingProvider.ProvideCameraSettingL( aSettingId, &brightnessSetting );
       
  6380 
       
  6381       CCamera::TBrightness brightnessValue;
       
  6382       GetCameraSettingValueL( aSettingId, &brightnessValue );
       
  6383 
       
  6384       upToDate = ( brightnessSetting == brightnessValue );
       
  6385       break;
       
  6386       }
       
  6387     case ECameraSettingContrast:
       
  6388     case ECameraUserSceneSettingContrast:
       
  6389       {
       
  6390       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingContrast") );
       
  6391       CCamera::TContrast contrastSetting( CCamera::EContrastAuto );
       
  6392       iSettingProvider.ProvideCameraSettingL( aSettingId, &contrastSetting );
       
  6393 
       
  6394       CCamera::TContrast contrastValue( CCamera::EContrastAuto );
       
  6395       GetCameraSettingValueL( aSettingId, &contrastValue );
       
  6396 
       
  6397       upToDate = ( contrastSetting == contrastValue );
       
  6398       break;
       
  6399       }
       
  6400     case ECameraSettingSharpness:
       
  6401     case ECameraUserSceneSettingSharpness:
       
  6402       {
       
  6403       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingSharpness") );
       
  6404       TInt sharpnessSetting( 0 );
       
  6405       iSettingProvider.ProvideCameraSettingL( aSettingId, &sharpnessSetting );
       
  6406 
       
  6407       TInt sharpnessValue( 0 );
       
  6408       // Can't leave here or other settings won't be restored
       
  6409       TRAP_IGNORE( GetCameraSettingValueL( aSettingId, &sharpnessValue ) );
       
  6410 
       
  6411       upToDate = ( sharpnessSetting == sharpnessValue );
       
  6412       break;
       
  6413       }
       
  6414     case ECameraSettingDigitalZoom:
       
  6415       {
       
  6416       TInt zoomSetting( 0 );
       
  6417       iSettingProvider.ProvideCameraSettingL( aSettingId, &zoomSetting );
       
  6418 
       
  6419       TInt zoomValue( 0 );
       
  6420       GetCameraSettingValueL( aSettingId, &zoomValue );
       
  6421 
       
  6422       upToDate = ( zoomSetting == zoomValue );
       
  6423       break;
       
  6424       }
       
  6425 #ifdef CAMERAAPP_CAPI_V2
       
  6426     case ECameraSettingStabilization:
       
  6427       {
       
  6428       PRINT( _L("Camera <> CCamCameraController::SettingValueUpToDate ECameraSettingStabilization") );
       
  6429 
       
  6430       TPckgBuf<TCamSettingDataStabilization> stabilizationSetting;
       
  6431       iSettingProvider.ProvideCameraSettingL( aSettingId, &stabilizationSetting );
       
  6432 
       
  6433       TPckgBuf<TCamSettingDataStabilization> stabilizationValue;
       
  6434       GetCameraSettingValueL( aSettingId, &stabilizationValue );
       
  6435       if ( stabilizationSetting().iMode != stabilizationValue().iMode ||
       
  6436               stabilizationSetting().iEffect != stabilizationValue().iEffect ||
       
  6437               stabilizationSetting().iComplexity != stabilizationValue().iComplexity )
       
  6438         {
       
  6439         upToDate = EFalse;
       
  6440         }
       
  6441       break;
       
  6442       }
       
  6443     case ECameraSettingContAF:
       
  6444       {
       
  6445       TBool isContAFon( iAdvancedSettings->AutoFocusType() &
       
  6446                         CAS::EAutoFocusTypeContinuous );
       
  6447       if( IsFlagOn( iInfo.iState, ECamVideoOn ) )
       
  6448         {
       
  6449         TBool contAF( ETrue );
       
  6450         iSettingProvider.ProvideCameraSettingL( aSettingId, &contAF );
       
  6451         if( contAF != isContAFon )
       
  6452           {
       
  6453           upToDate = EFalse;
       
  6454           }
       
  6455         }
       
  6456       else
       
  6457         {
       
  6458         //Do nothing
       
  6459 
       
  6460         }
       
  6461       break;
       
  6462       }
       
  6463 #endif
       
  6464     default:
       
  6465       {
       
  6466       PRINT1( _L("CCamCameraController::SettingValueUpToDate - unknown setting id: %d"), aSettingId );
       
  6467       }
       
  6468 
       
  6469     }
       
  6470 
       
  6471   PRINT1( _L("Camera <= CCamCameraController::SettingValueUpToDate returning %d"), upToDate );
       
  6472   return upToDate;
       
  6473   }
       
  6474 
       
  6475 
       
  6476 
       
  6477 // ---------------------------------------------------------------------------
       
  6478 // CCamCameraController::SetViewfinderWindowHandle
       
  6479 // ---------------------------------------------------------------------------
       
  6480 //
       
  6481 void CCamCameraController::SetViewfinderWindowHandle( RWindowBase* aWindow )
       
  6482     {
       
  6483     PRINT( _L("Camera => CCamCameraController::SetViewfinderWindowHandle") );
       
  6484     PRINT2( _L("Camera <> aWindow=0x%08x iViewfinderWindow=0x%08x "), aWindow, iViewfinderWindow );
       
  6485 
       
  6486     if ( aWindow != iViewfinderWindow &&
       
  6487         iCamera &&
       
  6488         iInfo.iVfState == ECamTriActive &&
       
  6489         iInfo.iVfMode == ECamViewfinderDirect )
       
  6490         {
       
  6491         PRINT( _L("Camera <> viewfinder active and window handle changed, restarting viewfinder...") );
       
  6492          iCamera->StopViewFinder();
       
  6493         
       
  6494         if ( iViewfinderWindow != NULL )
       
  6495             {
       
  6496             iViewfinderWindow = aWindow;
       
  6497             // Use the same viewfinder position and size as for bitmap viewfinder
       
  6498             TPckgBuf<TCamParamsVfBitmap> params;
       
  6499             iSettingProvider.ProvideCameraParamL( ECameraParamVfBitmap, &params );
       
  6500             
       
  6501             CEikonEnv* env = CEikonEnv::Static();
       
  6502     
       
  6503             iCamera->StartViewFinderDirectL(
       
  6504                   env->WsSession(),
       
  6505                   *env->ScreenDevice(),
       
  6506                   *iViewfinderWindow,
       
  6507                   params().iRect );
       
  6508               
       
  6509             }
       
  6510         else
       
  6511             {
       
  6512             iCamera->StopViewFinder();
       
  6513             iInfo.iVfState = ECamTriInactive;
       
  6514 
       
  6515             // restart viewfinder
       
  6516        
       
  6517 		    iAppController.EnterViewfinderMode(iAppController.CurrentMode());
       
  6518             }
       
  6519         }
       
  6520     iViewfinderWindow = aWindow;
       
  6521 
       
  6522     PRINT( _L("Camera <= CCamCameraController::SetViewfinderWindowHandle") );
       
  6523     }
       
  6524 
       
  6525 // ---------------------------------------------------------------------------
       
  6526 // CCamCameraController::ViewfinderWindowDeleted
       
  6527 // ---------------------------------------------------------------------------
       
  6528 //
       
  6529 void CCamCameraController::ViewfinderWindowDeleted( RWindowBase* aWindow )
       
  6530     {
       
  6531     PRINT( _L("Camera => CCamCameraController::ViewfinderWindowDeleted") );
       
  6532     PRINT2( _L("Camera <> aWindow=0x%08x iViewfinderWindow=0x%08x "), aWindow, iViewfinderWindow );
       
  6533 
       
  6534     if ( aWindow == iViewfinderWindow )
       
  6535         {
       
  6536         if ( iCamera &&
       
  6537             iInfo.iVfState == ECamTriActive &&
       
  6538             iInfo.iVfMode == ECamViewfinderDirect )
       
  6539             {
       
  6540             PRINT( _L("Camera <> viewfinder active and window deleted, stopping viewfinder...") );
       
  6541             iCamera->StopViewFinder();
       
  6542             iInfo.iVfState = ECamTriInactive;
       
  6543             }
       
  6544         iViewfinderWindow = NULL;
       
  6545         }
       
  6546 
       
  6547     PRINT( _L("Camera <= CCamCameraController::ViewfinderWindowDeleted") );
       
  6548     }
       
  6549 
       
  6550 // ---------------------------------------------------------------------------
       
  6551 // CCamCameraController::SetVfWindowOrdinal
       
  6552 // ---------------------------------------------------------------------------
       
  6553 //
       
  6554 TInt CCamCameraController::SetVfWindowOrdinal( TInt aOrdinalPosition )
       
  6555     {
       
  6556     TInt orgPos( KErrUnknown );
       
  6557     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  6558     if ( iViewfinderWindow )
       
  6559         {
       
  6560         TInt cbaPos(0);
       
  6561         TInt toolbarPos(0);
       
  6562         CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
       
  6563         orgPos = iViewfinderWindow->OrdinalPosition();
       
  6564         if ( aOrdinalPosition != KErrUnknown)
       
  6565             {
       
  6566             // Set wanted ordinal position
       
  6567             iViewfinderWindow->SetOrdinalPosition( aOrdinalPosition );
       
  6568             }
       
  6569         else if ( appUi )
       
  6570             {
       
  6571             // Find out other windows ordinal positions
       
  6572             if ( cba )
       
  6573                 {
       
  6574                 cbaPos =  cba->DrawableWindow()->OrdinalPosition();
       
  6575                 }
       
  6576             CAknToolbar* toolbar = appUi->CurrentFixedToolbar();
       
  6577             if ( toolbar )
       
  6578                 {
       
  6579                 RDrawableWindow* toolbarwindow = toolbar->DrawableWindow();
       
  6580                 if ( toolbarwindow )
       
  6581                     {
       
  6582                     toolbarPos = toolbarwindow->OrdinalPosition();
       
  6583                     }
       
  6584                 }
       
  6585             // Calculate new viewfinder position,
       
  6586             // just under fixed toolbar and CBA buttons
       
  6587             TInt newPos = Max( toolbarPos, cbaPos ) + 1;
       
  6588             // Use new position if viefinder window is not visible already
       
  6589             iViewfinderWindow->SetOrdinalPosition( Min( orgPos, newPos ) );
       
  6590             }
       
  6591         }
       
  6592     return orgPos;
       
  6593     }
       
  6594 
       
  6595 #ifdef CAMERAAPP_CAE_ERR_SIMULATION
       
  6596 
       
  6597 // ---------------------------------------------------------------------------
       
  6598 // CCamCameraController::DelayedCaeCallback
       
  6599 // Static function called when the timer expires
       
  6600 // ---------------------------------------------------------------------------
       
  6601 //
       
  6602 TInt
       
  6603 CCamCameraController::DelayedCaeCallback( TAny* aController )
       
  6604     {
       
  6605     CCamCameraController* self = static_cast<CCamCameraController*>( aController );
       
  6606     self->CallAppropriateCallback();
       
  6607 
       
  6608     return KErrNone;
       
  6609     }
       
  6610 
       
  6611 // ---------------------------------------------------------------------------
       
  6612 // CCamCameraController::CallAppropriateCallback
       
  6613 // Helper function to call the appropriate callback handler.
       
  6614 // ---------------------------------------------------------------------------
       
  6615 //
       
  6616 void
       
  6617 CCamCameraController::CallAppropriateCallback( const TCamCameraEventId aEventId,
       
  6618                                                      TInt              aStatus )
       
  6619     {
       
  6620     PRINT2( _L("Camera => CCamCameraController::CallAppropriateCallback, event:%d, status:%d"), aEventId, aStatus )
       
  6621 
       
  6622     switch ( iSimEventId )
       
  6623         {
       
  6624         case ECamCameraEventVideoInit:
       
  6625         case ECamCameraEventVideoStart:  // fallthrough
       
  6626         case ECamCameraEventVideoPause:  // fallthrough
       
  6627         case ECamCameraEventVideoStop:
       
  6628             if( aEventId == ECamCameraEventNone )
       
  6629                 {
       
  6630                 PRINT( _L("Camera <> CCamCameraController::CallAppropriateCallback - calling handler after delay") )
       
  6631                 HandleVideoEvent( iSimEventId, iSimStatus );
       
  6632                 }
       
  6633             else
       
  6634                 {
       
  6635                 PRINT( _L("Camera <> CCamCameraController::CallAppropriateCallback - calling handler without delay") )
       
  6636                 HandleVideoEvent( aEventId, aStatus );
       
  6637                 }
       
  6638             break;
       
  6639         default:
       
  6640             break;
       
  6641         }
       
  6642 
       
  6643     // In case of being called by timer, stop and destro the timer
       
  6644     if( aEventId == ECamCameraEventNone && iCallbackTimer )
       
  6645         {
       
  6646         iCallbackTimer->Cancel();
       
  6647         delete iCallbackTimer;
       
  6648         iCallbackTimer = NULL;
       
  6649         }
       
  6650 
       
  6651     PRINT( _L("Camera <= CCamCameraController::CallAppropriateCallback") )
       
  6652     }
       
  6653 
       
  6654 #endif // CAMERAAPP_CAE_ERR_SIMULATION
       
  6655 
       
  6656 // ---------------------------------------------------------------------------
       
  6657 // CCamCameraController::AsyncVideoStopModeSupported
       
  6658 // ---------------------------------------------------------------------------
       
  6659 //
       
  6660 TBool
       
  6661 CCamCameraController::AsyncVideoStopModeSupported()
       
  6662   {
       
  6663   PRINT1( _L("Camera <> CCamCameraController::AsyncVideoStopModeSupported = %d "), iAsyncVideoStopModeSupported );
       
  6664   return( iAsyncVideoStopModeSupported );
       
  6665   }
       
  6666 
       
  6667 // ---------------------------------------------------------------------------
       
  6668 // IdleCallback <<static>>
       
  6669 // ---------------------------------------------------------------------------
       
  6670 //
       
  6671 // static
       
  6672 TInt CCamCameraController::IdleCallback( TAny* aSelf )
       
  6673     {
       
  6674     CCamCameraController* self( static_cast<CCamCameraController*>( aSelf ) );
       
  6675     self->DoIveRecovery();
       
  6676 
       
  6677     return EFalse;
       
  6678     }
       
  6679 
       
  6680 // ---------------------------------------------------------------------------
       
  6681 // CCamCameraController::DoIveRecovery
       
  6682 // ---------------------------------------------------------------------------
       
  6683 //
       
  6684 void CCamCameraController::DoIveRecovery()
       
  6685     {
       
  6686     PRINT( _L("Camera => CCamCameraController::DoIveRecovery") )
       
  6687     if( iAppController.IsAppUiAvailable()
       
  6688             && !( iAppController.IsInShutdownMode() || iAppController.CheckExitStatus() ) )
       
  6689         {
       
  6690         CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  6691         __ASSERT_DEBUG(appUi, CamPanic(ECamPanicNullPointer));
       
  6692 		TVwsViewId activeView;
       
  6693         TInt viewErr = appUi->GetActiveViewId( activeView );
       
  6694         CCamViewBase* view = NULL;
       
  6695         if( !viewErr )
       
  6696             {
       
  6697             view = static_cast<CCamViewBase*>( appUi->View( activeView.iViewUid ));
       
  6698             }
       
  6699         else
       
  6700             {
       
  6701             //There was an error when getting active view ID. Propably camera
       
  6702             //application went to background. In that case just return because
       
  6703             //camera resource should be released when going to background.
       
  6704             return;
       
  6705             }
       
  6706 		__ASSERT_DEBUG(view, CamPanic(ECamPanicNullPointer));
       
  6707         if ( appUi->StandbyStatus() && appUi->IsRecoverableStatus() && view->IsInStandbyMode() ) 
       
  6708             {
       
  6709             PRINT( _L("Camera <> CCamCameraController::DoIveRecovery - Standby mode active, try to exit") )
       
  6710             TRAP_IGNORE( appUi->HandleControllerEventL(  ECamEventCameraChanged,
       
  6711                                                          KErrNone ) );
       
  6712             }
       
  6713         else
       
  6714             {
       
  6715             PRINT( _L("Camera <> CCamCameraController::DoIveRecovery - Start recovering from beginning") )
       
  6716             iIveSequenceActive = EFalse;
       
  6717             if( IsFlagOn( iInfo.iBusy, ECamBusySequence|ECamBusySetting ) )
       
  6718                 {
       
  6719                 if( iActive &&
       
  6720                     iActive->IsActive() )
       
  6721                     {
       
  6722                     iActive->Cancel();
       
  6723                     }
       
  6724                 iIveCancel = ETrue;
       
  6725                 EndSequence( KErrNone ); // Clears iIveRecoveryOngoing and iIveSequenceActive
       
  6726                 }
       
  6727             NotifyObservers( KErrNone, ECamCameraEventIveRecover,
       
  6728                              ECamCameraEventClassBasicControl );
       
  6729             }
       
  6730         iIveRecoveryCount--;
       
  6731         iIveRecoveryOngoing = ETrue;
       
  6732         iIveCancel = EFalse;
       
  6733         }
       
  6734     PRINT1( _L("Camera <= CCamCameraController::DoIveRecovery iIveRecoveryCount%d"),iIveRecoveryCount )
       
  6735     }
       
  6736 
       
  6737 // ---------------------------------------------------------------------------
       
  6738 // CCamCameraController::IsWaitingIveResources
       
  6739 // ---------------------------------------------------------------------------
       
  6740 //
       
  6741 TBool CCamCameraController::IsWaitingIveResources()
       
  6742     {
       
  6743     // ETrue if recovery is started, but not completed.
       
  6744     // iIveRecoveryOngoing is set to false when last recovery command is executed
       
  6745     return (iIdle && iIdle->IsActive()) ||
       
  6746             iIveCancel || iIveRecoveryOngoing || iIveSequenceActive;
       
  6747     }
       
  6748 
       
  6749 
       
  6750 // ---------------------------------------------------------------------------
       
  6751 // CCamCameraController::SetFaceTrackingL
       
  6752 // ---------------------------------------------------------------------------
       
  6753 //
       
  6754 void CCamCameraController::SetFaceTrackingL()
       
  6755     {
       
  6756     if( iCustomInterfaceFaceTracking &&
       
  6757         KPrimaryCameraIndex == iInfo.iCurrentCamera )
       
  6758       {
       
  6759       // always enable FaceIndicators regardless of FT setting
       
  6760       // to get reticule visible  
       
  6761       iCustomInterfaceFaceTracking->EnableFaceIndicatorsL( ETrue );
       
  6762       TBool ftOn( EFalse );
       
  6763       iSettingProvider.ProvideCameraSettingL( ECameraSettingFacetracking, &ftOn );
       
  6764       PRINT1( _L("Camera <> Set facetracking: %d"), ftOn )
       
  6765       if( ( ftOn && !iCustomInterfaceFaceTracking->FaceTrackingOn() ) ||
       
  6766           ( !ftOn && iCustomInterfaceFaceTracking->FaceTrackingOn() ) )
       
  6767           {
       
  6768           iCustomInterfaceFaceTracking->SetFaceTrackingL( ftOn );
       
  6769           DirectRequestL( ECamRequestSetAfRange );
       
  6770           }
       
  6771       }
       
  6772     }
       
  6773 
       
  6774 // ---------------------------------------------------------------------------
       
  6775 // CCamCameraController::HintUseCase
       
  6776 // ---------------------------------------------------------------------------
       
  6777 //
       
  6778 void CCamCameraController::HintUseCaseL()
       
  6779     {
       
  6780     PRINT( _L("Camera => CCamCameraController::HintUseCaseL"))
       
  6781     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );    
       
  6782     //videomode    
       
  6783     if ( iCustomInterfaceUseCaseHint && appUi && 
       
  6784        ( ( appUi->IsEmbedded() && appUi->TargetMode() == ECamControllerVideo ) || 
       
  6785        ( !appUi->IsEmbedded() && iAppController.TargetMode() == ECamControllerVideo ) ) )
       
  6786         {
       
  6787         PRINT( _L("Camera <> HintUseCaseL VideoMode") );
       
  6788         MCameraUseCaseHint::TVideoCodec codec = MCameraUseCaseHint::ECodecUnknown;
       
  6789         MCameraUseCaseHint::TVideoProfile profile = MCameraUseCaseHint::EProfileUnknown;
       
  6790         TPckgBuf<TCamParamsVideoCae> params;
       
  6791         iSettingProvider.ProvideCameraParamL( ECameraParamVideoCae, &params );
       
  6792         if( params().iVideoType == KCMRMimeTypeH264AVCBPL31 )
       
  6793             {
       
  6794             PRINT( _L("Camera <> HintUseCaseL VideoMode KCMRMimeTypeH264AVCBPL31") );    
       
  6795             codec = MCameraUseCaseHint::ECodecH264;
       
  6796             profile = MCameraUseCaseHint::EProfileH264BpL3_1;
       
  6797             }
       
  6798         else if( params().iVideoType == KCMRMimeTypeH263 )
       
  6799             {
       
  6800             PRINT( _L("Camera <> HintUseCaseL VideoMode KCMRMimeTypeH263") );    
       
  6801             codec = MCameraUseCaseHint::ECodecH263;
       
  6802             profile = MCameraUseCaseHint::EProfileH263P0L10;
       
  6803             }
       
  6804         else if( params().iVideoType == KCMRMimeTypeH264AVCBPL30 )
       
  6805             {
       
  6806             PRINT( _L("Camera <> HintUseCaseL VideoMode KCMRMimeTypeH264AVCBPL30") );    
       
  6807             codec = MCameraUseCaseHint::ECodecH264;
       
  6808             profile = MCameraUseCaseHint::EProfileH264BpL3;
       
  6809             }            
       
  6810         else if( params().iVideoType == KCMRMimeTypeMPEG4VSPL4A )
       
  6811             {
       
  6812             PRINT( _L("Camera <> HintUseCaseL VideoMode KCMRMimeTypeMPEG4VSPL4A") );    
       
  6813             codec = MCameraUseCaseHint::ECodecMpeg4;
       
  6814             profile = MCameraUseCaseHint::EProfileMPEG4SpL4a;     
       
  6815             }
       
  6816         else if( params().iVideoType == KCMRMimeTypeMPEG4VSPL3 )
       
  6817             {
       
  6818             PRINT( _L("Camera <> HintUseCaseL VideoMode KCMRMimeTypeMPEG4VSPL3") );    
       
  6819             codec = MCameraUseCaseHint::ECodecMpeg4;
       
  6820             profile = MCameraUseCaseHint::EProfileMPEG4SpL3;                        
       
  6821             }
       
  6822         else if( params().iVideoType == KCMRMimeTypeMPEG4VSPL2 )
       
  6823             {
       
  6824             PRINT( _L("Camera <> HintUseCaseL VideoMode KCMRMimeTypeMPEG4VSPL2") );    
       
  6825             codec = MCameraUseCaseHint::ECodecMpeg4;
       
  6826             profile = MCameraUseCaseHint::EProfileMPEG4SpL2;                        
       
  6827             }                        
       
  6828         else
       
  6829             {
       
  6830             PRINT( _L("Camera <> HintUseCaseL VideoMode not supported") );        
       
  6831             //leave if type not supported
       
  6832             User::Leave( KErrNotSupported );
       
  6833             }    
       
  6834         iCustomInterfaceUseCaseHint->HintDirectVideoCaptureL( codec, 
       
  6835                                                               profile, 
       
  6836                                                               params().iFrameSize );
       
  6837             
       
  6838         }
       
  6839     //stillmode    
       
  6840     else if ( iCustomInterfaceUseCaseHint && appUi && 
       
  6841             ( ( appUi->IsEmbedded() && appUi->TargetMode() == ECamControllerImage ) || 
       
  6842               ( !appUi->IsEmbedded() && iAppController.TargetMode() == ECamControllerImage ) ) )
       
  6843         {
       
  6844         PRINT( _L("Camera <> HintUseCaseL ImageMode") );    
       
  6845         TPckgBuf<TCamParamsImage> params;
       
  6846         iSettingProvider.ProvideCameraParamL( ECameraParamImage, &params );
       
  6847         CCamera::TFormat format( params().iFormat );
       
  6848         TInt index ( GetResolutionIndexL( format, params().iSize ) );    
       
  6849         iCustomInterfaceUseCaseHint->HintStillCaptureL( format, index );
       
  6850         }
       
  6851 
       
  6852     PRINT( _L("Camera <= CCamCameraController::HintUseCaseL"))    
       
  6853     }
       
  6854 // End of file