camappengine/Engine/Src/CaeStillStatesActive.cpp
branchRCL_3
changeset 20 e3cdd00b5ae3
parent 19 18fa9327a158
child 21 27fe719c32e6
equal deleted inserted replaced
19:18fa9327a158 20:e3cdd00b5ae3
     1 /*
       
     2 * Copyright (c) 2005 - 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Still capture state machine implementation class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <hal.h>                    // For getting the display mode
       
    21 #include <ExifRead.h>
       
    22 #include "CaeStillStatesActive.h"
       
    23 #include "CaeImageQueueExtPro.h"
       
    24 
       
    25 #ifdef CAE_TEST_VERSION
       
    26 #include "CaeEngineImpTestErrors.h" // For TEST_VERSION compilation only
       
    27 #endif
       
    28 
       
    29 #include "OstTraceDefinitions.h"
       
    30 #ifdef OST_TRACE_COMPILER_IN_USE
       
    31 #include "CaeStillStatesActiveTraces.h"
       
    32 #endif
       
    33 
       
    34 
       
    35 // ================= MEMBER FUNCTIONS =======================
       
    36 
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // CCaeStillStatesActive::CCaeStillStatesActive()
       
    40 // C++ constructor.
       
    41 // Adds the object to the Active Scheduler.
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CCaeStillStatesActive::CCaeStillStatesActive( 
       
    45     CCamera& aCamera,
       
    46     const TCamAppEngineInfo& aInfo,
       
    47     RArray<TCaeExtensionInterfaceImplItem>& aProcessImageImplList )
       
    48     : CActive( EPriorityStandard ), 
       
    49       iCamera( aCamera ),
       
    50       iInfo( aInfo ),
       
    51       iProcessImageImplList( aProcessImageImplList ),
       
    52       iStillInputFormat( CCamera::EFormatFbsBitmapColor16M ), 
       
    53       iStillOutputFormat( CCamera::EFormatFbsBitmapColor16M ), 
       
    54       iStillCompressionQuality( KCaeDefaultCompressionQuality ),
       
    55       iCurrentExtensionIndex( -1 )
       
    56     {
       
    57     CActiveScheduler::Add( this );
       
    58     }
       
    59 
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CCaeStillStatesActive::~CCaeStillStatesActive()
       
    63 // Destructor. 
       
    64 // Cancels operation and closes the timer.
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CCaeStillStatesActive::~CCaeStillStatesActive()
       
    68     {
       
    69     Cancel();
       
    70 
       
    71     iDelayedCallTimer.Close();
       
    72     
       
    73     DeleteStillBurst(); // Using this removes dependency to still burst class
       
    74 
       
    75     CancelAndCleanup();
       
    76 
       
    77     // Check that extensions handle flag registration properly
       
    78     CAE_ASSERT_DEBUG( iRequireFullColorSnapInputImageRefCount == 0 );
       
    79 
       
    80     delete iEmptySnapImage;
       
    81 
       
    82     delete iStillDecoder;
       
    83     delete iStillEncoder;
       
    84 
       
    85 	delete iSnapBitmap;
       
    86 	delete iBitmap;
       
    87 	delete iImageData;
       
    88 	delete iImageHeaderData;
       
    89     delete iImageQueueExtPro;
       
    90     iFs.Close();
       
    91     }
       
    92 
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CCaeStillStatesActive::NewL()
       
    96 // Symbian OS two-phased constructor.
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 CCaeStillStatesActive* CCaeStillStatesActive::NewL( 
       
   100     CCamera& aCamera,
       
   101     const TCamAppEngineInfo& aInfo,
       
   102     RArray<TCaeExtensionInterfaceImplItem>& aProcessImageImplList )
       
   103     {
       
   104     CCaeStillStatesActive* self = new( ELeave ) CCaeStillStatesActive( aCamera, aInfo, 
       
   105         aProcessImageImplList );
       
   106     CleanupStack::PushL( self );
       
   107     self->ConstructL();
       
   108     CleanupStack::Pop( self );
       
   109     return self;
       
   110     }
       
   111 
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // CCaeStillStatesActive::ConstructL()
       
   115 // Symbian OS 2nd phase constructor that can leave.
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 void CCaeStillStatesActive::ConstructL()
       
   119     {
       
   120     // Get native screen mode. This can be used as default mode for the snap bitmap.
       
   121     iSnapImageColorMode = KCaeDefaultDisplayMode;
       
   122     (void)GetSystemDisplayMode( iSnapImageColorMode );
       
   123     LOGTEXT2( _L( "Cae: CCaeStillStatesActive::ConstructL(). Use display mode %d for the snap image" ), iSnapImageColorMode );
       
   124 
       
   125     // Create still image encoder object, e.g. for JPEG encoding.
       
   126     iStillEncoder = CCaeStillEncoder::NewL();
       
   127     iStillEncoder->SetObserver( this );
       
   128 
       
   129     // Create still image decoder object, e.g. for JPEG decoding.
       
   130     iStillDecoder = CCaeStillDecoder::NewL();
       
   131     iStillDecoder->SetObserver( this );
       
   132 
       
   133     // This empty snap image is currently used just for error cases.
       
   134     iEmptySnapImage = new( ELeave ) CFbsBitmap;
       
   135 
       
   136     // Create timer 
       
   137     iDelayedCallTimer.CreateLocal();
       
   138     
       
   139     // Connect to file server.
       
   140     User::LeaveIfError( iFs.Connect() );
       
   141 
       
   142     // Start in normal mode    
       
   143   	iExtModeActive = EFalse;
       
   144     iStillPrepared = EFalse;
       
   145     
       
   146     // Burst mode VF stopping optimization is not used as default
       
   147     iBurstModeVFOptimization = EFalse;
       
   148 
       
   149     }
       
   150 
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // CCaeStillStatesActive::GetSystemDisplayMode()
       
   154 // In some devices Hal:Get(HAL::EDisplayMode) returns directly TDisplayMode, 
       
   155 // in other devices it returns a display mode index.
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 TBool CCaeStillStatesActive::GetSystemDisplayMode( TDisplayMode& aDisplayMode )
       
   159     {
       
   160     TBool found = EFalse;
       
   161     TInt halInOut = 0;
       
   162     TInt err = HAL::Get( HAL::EDisplayMode, halInOut );
       
   163     if (  err == KErrNone )
       
   164         {       
       
   165         if ( halInOut >= EColor256)
       
   166             {
       
   167             // halInOut contains TDisplayMode
       
   168             aDisplayMode = (TDisplayMode) halInOut;
       
   169             found = ETrue;
       
   170             LOGTEXT( _L( "Cae: CCaeStillStatesActive::GetSystemDisplayMode(). HAL returned a display mode." ) );
       
   171             }
       
   172         else
       
   173             {
       
   174              // halInOut contains index
       
   175            LOGTEXT( _L( "Cae: CCaeStillStatesActive::GetSystemDisplayMode(). HAL returned index." ) );
       
   176             err = HAL::Get( HAL::EDisplayBitsPerPixel, halInOut );
       
   177             
       
   178             // Get the color mode. Note: grayscale modes are not supported. 
       
   179             if (  err == KErrNone )
       
   180                 {
       
   181 				switch (halInOut)
       
   182 					{
       
   183 				    case 4:
       
   184 					    aDisplayMode = EColor16;
       
   185                         found = ETrue;
       
   186                         break;
       
   187 			    	case 8:
       
   188 					    aDisplayMode = EColor256;
       
   189                         found = ETrue;
       
   190                         break;
       
   191 				    case 12:
       
   192 				    	aDisplayMode = EColor4K;
       
   193                         found = ETrue;
       
   194                         break;
       
   195 				    case 16:
       
   196 					    aDisplayMode = EColor64K;
       
   197                         found = ETrue;
       
   198                         break;
       
   199 				    case 24:
       
   200 					    aDisplayMode = EColor16M;
       
   201                         found = ETrue;
       
   202                         break;
       
   203 			    	case 32:
       
   204 					    aDisplayMode = EColor16MU;
       
   205                         found = ETrue;
       
   206                         break;
       
   207 				    default:
       
   208 					    break;
       
   209 					}
       
   210                 }
       
   211             }
       
   212         } 
       
   213 
       
   214     #ifdef _DEBUG
       
   215     if ( err || !found )
       
   216         {
       
   217         TBuf<256> text;
       
   218         text.Format(_L( "Cae: CCaeStillStatesActive::GetSystemDisplayMode(). Cannot get the display mode from HW. Err:%d, found:%d" ), err, found );
       
   219         LOGTEXT( text );        
       
   220         }
       
   221     else
       
   222         {   
       
   223         LOGTEXT2( _L( "Cae: CCaeStillStatesActive::GetSystemDisplayMode(). Found the display mode:%d" ), aDisplayMode );
       
   224         }
       
   225     #endif
       
   226 
       
   227     if ( found && !err && aDisplayMode == EColor16MA )
       
   228         {
       
   229         aDisplayMode = EColor16MU;
       
   230         LOGTEXT2( _L( "Cae: CCaeStillStatesActive::GetSystemDisplayMode(). Display mode EColor16MA changed to EColor16MU (%d)" ), aDisplayMode );
       
   231         }
       
   232 
       
   233     return found;   
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // CCaeStillStatesActive::SetCamAppEngineObserver()
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 void CCaeStillStatesActive::SetCamAppEngineObserver( MCamAppEngineObserver& aObserver )
       
   241     {
       
   242     iCaeObserver = &aObserver;    
       
   243     }
       
   244 
       
   245 
       
   246 // -----------------------------------------------------------------------------
       
   247 // CCaeStillStatesActive::SetSnapImageCreation()
       
   248 // -----------------------------------------------------------------------------
       
   249 //
       
   250 void CCaeStillStatesActive::SetSnapImageCreation( 
       
   251     TBool aCreateSnapImage )
       
   252     {
       
   253     iCreateSnapImage = aCreateSnapImage;
       
   254     }
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 // CCaeStillStatesActive::SetSnapImageSourceL()
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 void CCaeStillStatesActive::SetSnapImageSourceL( 
       
   261     CCaeEngine::TSnapImageSource aSnapImageSource )
       
   262     {
       
   263     LOGTEXT2( _L( "Cae: CCaeStillStatesActive::SetSnapImageSourceL(). aSnapImageSource=%d" ), aSnapImageSource );
       
   264     if ( ( aSnapImageSource < 0 ) || 
       
   265          ( aSnapImageSource > CCaeEngine::ESnapImageSourceThumbnail ) )
       
   266         {
       
   267         LOGTEXT( _L( "Cae: CCaeStillStatesActive::SetSnapImageSourceL(). leaving KErrNotSupported" ));
       
   268         User::Leave( KErrNotSupported );
       
   269         }
       
   270 
       
   271     iSnapImageSource = aSnapImageSource;
       
   272     }
       
   273 
       
   274 
       
   275 
       
   276 // -----------------------------------------------------------------------------
       
   277 // CCaeStillStatesActive::SetSnapImageSizeL()
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 void CCaeStillStatesActive::SetSnapImageSizeL( 
       
   281     TSize& aSize )
       
   282     {
       
   283     LOGTEXT3( _L( "Cae: CCaeStillStatesActive::SetSnapImageSizeL(). iWidth=%d, iHeight=%d" ), aSize.iWidth, aSize.iHeight );
       
   284 	// Calc downscaled size.
       
   285     // Use always the default snap size for the snap image. It is the best compromise 
       
   286     // between memory usage and image quality.
       
   287     TSize stepwiseScaledOptimalSize( KCaeDefaultSnapWidth, KCaeDefaultSnapHeight);
       
   288     CalcDownscaledSnapSize( stepwiseScaledOptimalSize ); 
       
   289 
       
   290     // Empty calculated size means that PrepareStillCapture() has not been called.
       
   291     if ( stepwiseScaledOptimalSize == TSize() ) 
       
   292         {
       
   293         LOGTEXT( _L( "Cae: CCaeStillStatesActive::SetSnapImageSizeL(). leaving KErrNotReady (no prepare)" ));
       
   294 		User::Leave( KErrNotReady ); 
       
   295         }
       
   296     else
       
   297         {
       
   298         iOptimalSnapImageSize = stepwiseScaledOptimalSize;
       
   299         // If empty, use the still image size
       
   300         if ( aSize == TSize() )
       
   301             {
       
   302             aSize = iStillFrameSize;
       
   303             }
       
   304         iSnapImageSize = aSize;
       
   305         }
       
   306     }
       
   307 
       
   308 
       
   309 // -----------------------------------------------------------------------------
       
   310 // CCaeStillStatesActive::SnapImageSize
       
   311 // -----------------------------------------------------------------------------
       
   312 TSize CCaeStillStatesActive::SnapImageSize() const
       
   313     {
       
   314     return( iSnapImageSize );
       
   315     }
       
   316 
       
   317 // -----------------------------------------------------------------------------
       
   318 // CCaeStillStatesActive::StillImageSize
       
   319 // -----------------------------------------------------------------------------
       
   320 TSize CCaeStillStatesActive::StillImageSize() const
       
   321     {
       
   322     return( iStillFrameSize );
       
   323     }
       
   324 
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // CCaeStillStatesActive::SetSnapImageColorMode
       
   328 // -----------------------------------------------------------------------------
       
   329 //
       
   330 void CCaeStillStatesActive::SetSnapImageColorMode( 
       
   331     TDisplayMode aMode )
       
   332     {
       
   333     iSnapImageColorMode = aMode;
       
   334     }
       
   335 
       
   336 
       
   337 // -----------------------------------------------------------------------------
       
   338 // CCaeStillStatesActive::SetJpegQuality
       
   339 // -----------------------------------------------------------------------------
       
   340 //
       
   341 void CCaeStillStatesActive::SetJpegQuality(
       
   342     TInt aQuality )
       
   343     {
       
   344     iStillCompressionQuality = aQuality;
       
   345     }
       
   346 
       
   347 
       
   348 // -----------------------------------------------------------------------------
       
   349 // CCaeStillStatesActive::JpegQuality
       
   350 // -----------------------------------------------------------------------------
       
   351 //
       
   352 TInt CCaeStillStatesActive::JpegQuality() const
       
   353     {
       
   354     return( iStillCompressionQuality );
       
   355     }
       
   356 
       
   357 
       
   358 // -----------------------------------------------------------------------------
       
   359 // CCaeStillStatesActive::SetImageCodecsL
       
   360 // Sets the specific image codec implementation to be used in decoding and 
       
   361 // encoding.
       
   362 // -----------------------------------------------------------------------------
       
   363 //
       
   364 void CCaeStillStatesActive::SetImageCodecsL( 
       
   365 	TUid aDecoderUid, TUid aEncoderUid )
       
   366     {
       
   367     iStillEncoder->SetImageCodecL( aEncoderUid );
       
   368     iStillDecoder->SetImageCodecL( aDecoderUid );
       
   369     }
       
   370 
       
   371         
       
   372 // -----------------------------------------------------------------------------
       
   373 // CCaeStillStatesActive::SetViewFinderMode
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 void CCaeStillStatesActive::SetViewFinderMode(
       
   377     TBool aIsEnabled )
       
   378     {
       
   379     iIsViewFinderEnabled = aIsEnabled;
       
   380 
       
   381     // Issue event, if the view finder is stopped, and the state machine is 
       
   382     // waiting for it. Do not issue the same event twice (it will panic).
       
   383     if ( !iIsViewFinderEnabled 
       
   384          && ( iCurrentState == CCaeStillStatesActive::ECaeStateBurstWaitingForViewFinder ) 
       
   385          && !( IsActive() && ( iStatus == CCaeStillStatesActive::ECaeEventViewFinderForBurstReady ) ) )
       
   386         {
       
   387         Event( CCaeStillStatesActive::ECaeEventViewFinderForBurstReady );        
       
   388         }
       
   389     }
       
   390 
       
   391 
       
   392 // -----------------------------------------------------------------------------
       
   393 // CCaeStillStatesActive::IsRunning
       
   394 // Check if the state is other than ECaeStateNone.
       
   395 // -----------------------------------------------------------------------------
       
   396 //
       
   397 TBool CCaeStillStatesActive::IsRunning() const
       
   398     {
       
   399     return( iCurrentState != CCaeStillStatesActive::ECaeStateNone );
       
   400     }
       
   401 
       
   402 
       
   403 // -----------------------------------------------------------------------------
       
   404 // CCaeEngineImp::RegisterFlags
       
   405 // Increment reference counters.
       
   406 // -----------------------------------------------------------------------------
       
   407 //
       
   408 void CCaeStillStatesActive::RegisterFlags( TUint32 aFlags )
       
   409 	{
       
   410     if ( aFlags & ECaeExtFlagRequireFullColorSnapInputImage )
       
   411         { 
       
   412         CAE_ASSERT_DEBUG( iRequireFullColorSnapInputImageRefCount < KMaxTInt32 );
       
   413         if ( iRequireFullColorSnapInputImageRefCount < KMaxTInt32 )
       
   414             {
       
   415             iRequireFullColorSnapInputImageRefCount++;
       
   416             }
       
   417         }
       
   418 	}
       
   419 
       
   420 
       
   421 // -----------------------------------------------------------------------------
       
   422 // CCaeEngineImp::DeregisterFlags
       
   423 // Decrement reference counters.
       
   424 // -----------------------------------------------------------------------------
       
   425 //
       
   426 void CCaeStillStatesActive::DeregisterFlags( TUint32 aFlags )
       
   427     {
       
   428     if ( aFlags & ECaeExtFlagRequireFullColorSnapInputImage )
       
   429         {
       
   430         CAE_ASSERT_DEBUG( iRequireFullColorSnapInputImageRefCount > 0 );
       
   431         if ( iRequireFullColorSnapInputImageRefCount > 0 )
       
   432             {
       
   433             iRequireFullColorSnapInputImageRefCount--;
       
   434             }
       
   435         }
       
   436     }
       
   437 
       
   438 // -----------------------------------------------------------------------------
       
   439 // CCaeStillStatesActive::PrepareStillCaptureL
       
   440 // Using cropping only if supported by Camera API impl.
       
   441 // Calls RetrieveStillSizeIndex() that calls Camera API EnumerateCaptureSizes().
       
   442 // Calls Camera API PrepareImageCaptureL().
       
   443 // -----------------------------------------------------------------------------
       
   444 //
       
   445 void CCaeStillStatesActive::PrepareStillCaptureL( 
       
   446     const TSize&      aFrameSize, 
       
   447     CCamera::TFormat  aFormat, 
       
   448     const TRect&      aCropRect,
       
   449     TSize&            aSnapSize )
       
   450     {
       
   451     LOGTEXT3( _L( "Cae: CCaeStillStatesActive::PrepareStillCaptureL() entering aFrameSize=(w=%d,h=%d)" ), aFrameSize.iWidth, aFrameSize.iHeight );
       
   452 
       
   453     // Handle empty crop rect
       
   454     TRect cropRect( aCropRect );
       
   455     if ( cropRect.IsEmpty() )
       
   456         cropRect = TRect(TPoint(0, 0 ), aFrameSize);
       
   457 
       
   458     CCamera::TFormat stillOutputFormat = aFormat;
       
   459     CCamera::TFormat stillInputFormat = aFormat;
       
   460 
       
   461     // Try if this size and format is supported by the Camera API.
       
   462     TInt sizeIndex = RetrieveStillSizeIndex( aFrameSize, aFormat );
       
   463     if ( sizeIndex != -1 )
       
   464         {
       
   465         stillInputFormat = aFormat;
       
   466         }
       
   467     // If the application requires Jpeg we can encode it from bitmap
       
   468     else if ( aFormat == CCamera::EFormatJpeg )
       
   469         {
       
   470         // Try if this size and format KBaseStillInputFormat1 
       
   471         // is supported by the Camera API.
       
   472         stillInputFormat = KBaseStillInputFormat1;
       
   473         sizeIndex = RetrieveStillSizeIndex( aFrameSize, stillInputFormat );
       
   474         if ( sizeIndex == -1 )
       
   475             {
       
   476             // Try if this size and format KBaseStillInputFormat2 
       
   477             // is supported by the Camera API.
       
   478             stillInputFormat = KBaseStillInputFormat2;
       
   479             sizeIndex = RetrieveStillSizeIndex( aFrameSize, stillInputFormat );
       
   480             if ( sizeIndex == -1 )
       
   481                 {
       
   482                 LOGTEXT2( _L( "Cae: CCaeStillStatesActive::PrepareStillCaptureL() leaving KErrNotSupported, stillInputFormat=%d" ), stillInputFormat );
       
   483                 User::Leave( KErrNotSupported );
       
   484                 }
       
   485             }
       
   486         }
       
   487     else 
       
   488         {
       
   489         LOGTEXT2( _L( "Cae: CCaeStillStatesActive::PrepareStillCaptureL() leaving KErrNotSupported, aFormat=%d" ), aFormat );
       
   490         User::Leave( KErrNotSupported );
       
   491         }
       
   492 
       
   493     // Prepare still image capturing on Camera API.
       
   494     if ( !( iInfo.iOptionsSupported & TCameraInfo::EImageClippingSupported ) ) 
       
   495         {
       
   496         iCamera.PrepareImageCaptureL( stillInputFormat, sizeIndex );
       
   497         }
       
   498     else 
       
   499         {
       
   500         iCamera.PrepareImageCaptureL( stillInputFormat, sizeIndex, cropRect );
       
   501         }
       
   502 
       
   503     // Store values 
       
   504     iStillFrameSize = aFrameSize;
       
   505     iStillInputFormat = stillInputFormat;
       
   506     iStillOutputFormat = stillOutputFormat;
       
   507 
       
   508     // Calc downscaled size if needed
       
   509     SetSnapImageSizeL( aSnapSize );     
       
   510     
       
   511     // Prepare done
       
   512     iStillPrepared = ETrue;
       
   513     
       
   514     LOGTEXT( _L( "Cae: CCaeStillStatesActive::PrepareStillCaptureL() returning" ) );    
       
   515     }
       
   516 
       
   517 
       
   518 // -----------------------------------------------------------------------------
       
   519 // CCaeStillStatesActive::RetrieveStillSizeIndex
       
   520 // Retrieves/fetches still image size index from Camera API.
       
   521 // -----------------------------------------------------------------------------
       
   522 //
       
   523 TInt CCaeStillStatesActive::RetrieveStillSizeIndex( 
       
   524     const TSize& aFrameSize, 
       
   525     CCamera::TFormat aStillDataFormat ) const
       
   526     {
       
   527     LOGTEXT( _L( "Cae: CCaeStillStatesActive::RetrieveStillSizeIndex() entering" ) );
       
   528 
       
   529     TInt index( -1 );
       
   530     TInt i( 0 );
       
   531     TSize size;
       
   532     while ( ( i < iInfo.iNumImageSizesSupported ) && ( index == -1 ) )
       
   533         {
       
   534         iCamera.EnumerateCaptureSizes ( size, i, aStillDataFormat );
       
   535         if ( size == aFrameSize )
       
   536             {
       
   537             index = i;
       
   538             }
       
   539         i++;
       
   540         }
       
   541 
       
   542     LOGTEXT( _L( "Cae: CCaeStillStatesActive::RetrieveStillSizeIndex() returning" ) );
       
   543 
       
   544     return index;
       
   545     }
       
   546 
       
   547 
       
   548 // -----------------------------------------------------------------------------
       
   549 // CCaeStillStatesActive::CalcDownscaledSnapSize
       
   550 // Calc suitable downscaled snap size. Assumed that integer arithmetic is used 
       
   551 // also in CImageDecoder class for calculating image scaling to 1/2, 1/4 or 1/8 
       
   552 // of size (i.e. no rounding). The scaled snap size is not allowed to be smaller
       
   553 // than given snap size in any dimension. Do not do downscaling if aSnapSize is 
       
   554 // empty.
       
   555 // -----------------------------------------------------------------------------
       
   556 //
       
   557 void CCaeStillStatesActive::CalcDownscaledSnapSize(
       
   558     TSize& aSnapSize) const
       
   559     {
       
   560     LOGTEXT( _L( "Cae: CCaeStillStatesActive::CalcDownscaledSnapSize() entering" ) );    
       
   561 
       
   562     // The new snap image size is equal to frame size by default
       
   563     TSize newSnapSize = iStillFrameSize;
       
   564 
       
   565     // Calculate downscaled snap size
       
   566     if ( aSnapSize != TSize( 0, 0 ) 
       
   567         && ( ( iStillInputFormat == CCamera::EFormatExif ) || 
       
   568              ( iStillInputFormat == CCamera::EFormatJpeg )   ) )
       
   569         {
       
   570         // Try scaling to 1/8, 1/4 and 1/2
       
   571         for  ( TInt divider = 8; divider >= 2;  divider /= 2 ) 
       
   572             {
       
   573             TInt scaledWidth = iStillFrameSize.iWidth / divider;
       
   574             TInt scaledHeight = iStillFrameSize.iHeight / divider;
       
   575             if ( scaledHeight >= aSnapSize.iHeight && scaledWidth >= aSnapSize.iWidth ) 
       
   576                 {
       
   577                 newSnapSize = TSize( scaledWidth, scaledHeight );
       
   578                 divider = -1; // exit loop
       
   579                 }
       
   580             }
       
   581         }
       
   582 
       
   583     // Return new size
       
   584     aSnapSize = newSnapSize;
       
   585     LOGTEXT( _L( "Cae: CCaeStillStatesActive::CalcDownscaledSnapSize() returning" ) );    
       
   586     }
       
   587 
       
   588 
       
   589 // ---------------------------------------------------------------------------
       
   590 // CCaeStillStatesActive::GetThumbnailL()
       
   591 // Extracts thumbnail image and its size from Exif image.
       
   592 // Uses Exif reader to extract the thumbnail and 
       
   593 // ICL decoder to extract the size.
       
   594 // ---------------------------------------------------------------------------
       
   595 //
       
   596 void CCaeStillStatesActive::GetThumbnailL( 
       
   597     HBufC8*& aReadThumbnail, 
       
   598     TSize&   aThumbnailSize )
       
   599     {
       
   600     LOGTEXT( _L( "Cae: CCaeStillStatesActive::GetThumbnailL()" ) );    
       
   601 
       
   602     if ( iImageData && ( iStillOutputFormat == CCamera::EFormatExif ) )
       
   603         {
       
   604         // Instantiate exif reader.
       
   605         CExifRead* read = NULL;
       
   606         read = CExifRead::NewL( *iImageData );
       
   607         CleanupStack::PushL( read );
       
   608         
       
   609         // Get thumbnail.
       
   610         aReadThumbnail = read->GetThumbnailL();
       
   611         CleanupStack::PopAndDestroy( read );
       
   612         
       
   613         // Find out thumbnail size by using ICL decoder.
       
   614         // Check first that the size is valid.
       
   615         CImageDecoder* decoder = CImageDecoder::DataNewL( iFs, *aReadThumbnail ); 
       
   616         TFrameInfo frameInfo = decoder->FrameInfo();
       
   617         delete decoder;
       
   618 
       
   619         if ( frameInfo.iOverallSizeInPixels.iWidth > 0 && 
       
   620              frameInfo.iOverallSizeInPixels.iHeight > 0 )
       
   621             {
       
   622             aThumbnailSize = frameInfo.iOverallSizeInPixels;
       
   623             LOGTEXT3( _L( "Cae: CCaeStillStatesActive::GetThumbnailL(): extracted %dx%d thumbnail" ), 
       
   624                 aThumbnailSize.iWidth, aThumbnailSize.iHeight );
       
   625             }
       
   626         else
       
   627             {
       
   628             LOGTEXT3(_L("Cae: CCaeStillStatesActive::GetThumbnailL(): leaving KErrCorrupt due invalid thumbnail size=(w=%d,h=%d)"), 
       
   629                 frameInfo.iOverallSizeInPixels.iWidth, frameInfo.iOverallSizeInPixels.iHeight );
       
   630             delete aReadThumbnail;
       
   631             aReadThumbnail = NULL;
       
   632             aThumbnailSize = TSize( 0, 0 );
       
   633             User::Leave( KErrCorrupt );
       
   634             }
       
   635         }
       
   636     else if ( iImageData && ( iStillOutputFormat != CCamera::EFormatExif ) )
       
   637         {
       
   638         // we can't get the thumbnail from exif header if the exif header doesn't exist
       
   639         LOGTEXT( _L( "Cae: CCaeStillStatesActive::GetThumbnailL() leaving because iStillOutputFormat is not EFormatExif" ) );
       
   640         User::Leave( KErrNotFound );
       
   641         }
       
   642     }
       
   643 
       
   644 // ---------------------------------------------------------------------------
       
   645 // CCaeStillStatesActive::IsBitmapOutput()
       
   646 // ---------------------------------------------------------------------------
       
   647 //
       
   648 TBool CCaeStillStatesActive::IsBitmapOutput()
       
   649     {
       
   650     return ( !( ( iStillOutputFormat == CCamera::EFormatJpeg ) 
       
   651               || ( iStillOutputFormat == CCamera::EFormatExif ) ) );
       
   652     }
       
   653 
       
   654 
       
   655 // ---------------------------------------------------------------------------
       
   656 // CCaeStillStatesActive::Event()
       
   657 // ---------------------------------------------------------------------------
       
   658 //
       
   659 void CCaeStillStatesActive::Event( TCaeEvent aEvent, TTimeIntervalMicroSeconds32 aDelay )
       
   660     {
       
   661     LOGTEXT2( _L( "Cae: CCaeStillStatesActive::Event(). aEvent=%d" ), aEvent );
       
   662     CAE_ASSERT_ALWAYS( !IsActive() );
       
   663 
       
   664     iDelayedEvent = CCaeStillStatesActive::ECaeEventNone;
       
   665 
       
   666     if ( aEvent != CCaeStillStatesActive::ECaeEventEnd )
       
   667         {
       
   668         if ( aDelay == TTimeIntervalMicroSeconds32( 0 ) )
       
   669             {
       
   670             // Issue request
       
   671             TRequestStatus* statusPtr = &iStatus;
       
   672             User::RequestComplete( statusPtr, aEvent );
       
   673             }
       
   674         else
       
   675             {
       
   676             // Use delayed request
       
   677             iDelayedCallTimer.After( iStatus, aDelay );
       
   678             iDelayedEvent = aEvent;
       
   679             }
       
   680     	SetActive();
       
   681         }
       
   682     else
       
   683         {
       
   684         iCurrentState = CCaeStillStatesActive::ECaeStateNone; // The end
       
   685         if ( ExtModeActive() )
       
   686             {
       
   687             // If there are no images in the queue, then extension processing is ended
       
   688             TInt count = iImageQueueExtPro->ImageCount();
       
   689             if ( count > 0 )
       
   690                 {  // Continue and read next image from the queue
       
   691                 Event( CCaeStillStatesActive::ECaeEventImageQueueExtPro );
       
   692                 }
       
   693             }
       
   694         }
       
   695     }
       
   696 
       
   697 
       
   698 // ---------------------------------------------------------------------------
       
   699 // CCaeStillStatesActive::CancelCaptureStill()
       
   700 // ---------------------------------------------------------------------------
       
   701 //
       
   702 void CCaeStillStatesActive::CancelCaptureStill()
       
   703     {
       
   704     LOGTEXT( _L( "Cae: CCaeStillStatesActive::CancelCaptureStill()" ) );
       
   705 
       
   706     if ( !ExtModeActive() ) // in extension mode capture/cancelling is not possible
       
   707         {
       
   708         iStillCancelled = ETrue;
       
   709         Cancel();
       
   710         CancelAndCleanup();
       
   711         }
       
   712 
       
   713     }
       
   714 
       
   715 
       
   716 // ---------------------------------------------------------------------------
       
   717 // CCaeStillStatesActive::Cancel()
       
   718 // Calls the base class Cancel().
       
   719 // As calling this is not allowed outside this class, this is a private method
       
   720 // and it overrides CActive::Cancel(). 
       
   721 // ---------------------------------------------------------------------------
       
   722 //
       
   723 void CCaeStillStatesActive::Cancel()
       
   724     {
       
   725     LOGTEXT( _L( "Cae: CCaeStillStatesActive::Cancel()" ) );
       
   726     CActive::Cancel();
       
   727     }
       
   728 
       
   729 
       
   730 // ---------------------------------------------------------------------------
       
   731 // CCaeStillStatesActive::DoCancel()
       
   732 // Cancel all pending actions. This does not cancel actions that use callback
       
   733 // for signaling for completion, e.g. image encoding and decoding.
       
   734 // ---------------------------------------------------------------------------
       
   735 //
       
   736 void CCaeStillStatesActive::DoCancel()
       
   737     {
       
   738     LOGTEXT( _L( "Cae: CCaeStillStatesActive::DoCancel()" ) );
       
   739     if ( iStatus == KRequestPending )
       
   740         {
       
   741         if ( ( iCurrentState == CCaeStillStatesActive::ECaeStateExtensionsProcessingCapturedImage )
       
   742              || ( iCurrentState == CCaeStillStatesActive::ECaeStateExtensionsProcessingSnapImage ) 
       
   743              || ( iCurrentState == CCaeStillStatesActive::ECaeStateExtensionsProcessingStillImage ) )
       
   744             {
       
   745             // Cancel extension processing            
       
   746             CAE_ASSERT_ALWAYS( iCurrentExtensionIndex != -1 );
       
   747             TAny* interfacePtr = iProcessImageImplList[iCurrentExtensionIndex].iImplPtr;
       
   748 	        STATIC_CAST( MCaeExtProcessImageInterface*, interfacePtr )->CaeExtensionCancel();   
       
   749             }
       
   750         else if ( iDelayedEvent != CCaeStillStatesActive::ECaeEventNone )
       
   751             {
       
   752             // Cancel timer
       
   753             iDelayedCallTimer.Cancel();
       
   754             iDelayedEvent = CCaeStillStatesActive::ECaeEventNone;
       
   755             }
       
   756         else
       
   757             {
       
   758             User::Panic( KCaePanicText, ECaePanicInvalidState );
       
   759             }
       
   760         }
       
   761     }
       
   762 
       
   763 
       
   764 // -----------------------------------------------------------------------------
       
   765 // CCaeStillStatesActive::ErrorRecovery
       
   766 //
       
   767 // For still capture recovery: Delete images, cancel and cleanup. Client 
       
   768 // callbacks should be called also in error cases, except when user has 
       
   769 // cancelled the action. 
       
   770 //
       
   771 // Burst case is handled differently in BurstErrorRecovery().
       
   772 //
       
   773 // Note: If ownership is transferred, the image pointers should be NULLed before
       
   774 // calling the observer method. That is because the observer method can call back
       
   775 // CancelStill() which tries to delete images. That is no allowed if an image 
       
   776 // should be owned by the observer.
       
   777 // -----------------------------------------------------------------------------
       
   778 //
       
   779 void CCaeStillStatesActive::ErrorRecovery( TInt aError )
       
   780     {
       
   781     LOGTEXT2( _L( "Cae: CCaeStillStatesActive::ErrorRecovery(): %d" ), aError );
       
   782 
       
   783     // Check if snap image callback should be called. Do not call it twice.
       
   784 
       
   785     if ( ( iCurrentState <= CCaeStillStatesActive::ECaeStateDeliveringSnapImage ) // Callback not yet called
       
   786          && !iStillCancelled 
       
   787          && iCreateSnapImage ) 
       
   788         {
       
   789         if ( iCurrentState == CCaeStillStatesActive::ECaeStateDecodingCapturedImageToBitmap ) 
       
   790             {
       
   791             // Give decoded image to the client even if there is decoding error
       
   792             iCaeObserver->McaeoSnapImageReady( *iBitmap, aError );
       
   793 
       
   794             // Not needed any more. Delete now to free memory.
       
   795             delete iBitmap;
       
   796             iBitmap = NULL;
       
   797             }
       
   798         else
       
   799             {
       
   800             // Give empty snap image to the client
       
   801             iCaeObserver->McaeoSnapImageReady( *iEmptySnapImage, aError );
       
   802             }
       
   803         }
       
   804 
       
   805     // Check if still image callback should be called. Do not call it twice.
       
   806 
       
   807     if ( ( iCurrentState <= CCaeStillStatesActive::ECaeStateDeliveringStillImage ) // Callback not yet called
       
   808          && !iStillCancelled )
       
   809         {
       
   810         if ( iCurrentState == CCaeStillStatesActive::ECaeStateDecodingCapturedImageToBitmap ) 
       
   811             {
       
   812             // Give original image to the client even if there is decoding error.
       
   813             HBufC8* tmpImageData = iImageData;   
       
   814             iImageData = NULL; 
       
   815             iCaeObserver->McaeoStillImageReady( NULL, tmpImageData, aError );
       
   816             }
       
   817         else if ( iCurrentState == CCaeStillStatesActive::ECaeStateEncodingToJpeg )
       
   818             {
       
   819             // Give original image to the client even if there is encoding error
       
   820             HBufC8* tmpImageData = iImageData;   
       
   821             iImageData = NULL; // Ownership tranferred
       
   822             iCaeObserver->McaeoStillImageReady( NULL, tmpImageData, aError );            
       
   823             }
       
   824         else
       
   825             {
       
   826             // Give error to the client
       
   827             iCaeObserver->McaeoStillImageReady( NULL, NULL, aError );
       
   828             }
       
   829 
       
   830         // In burst case, increment delivery counter. 
       
   831         if ( iStillBurst )
       
   832             {
       
   833             iCountOfDeliveredBurstImages++;
       
   834             }
       
   835         }
       
   836 
       
   837     if ( !iStillCancelled )
       
   838         {
       
   839         // Handle still burst
       
   840         if ( iStillBurst )
       
   841             {
       
   842             BurstErrorRecovery( aError );
       
   843             }
       
   844         else
       
   845             {
       
   846             Cancel();
       
   847             CancelAndCleanup();
       
   848             }  
       
   849         }
       
   850     }
       
   851 
       
   852 
       
   853 // -----------------------------------------------------------------------------
       
   854 // CCaeStillStatesActive::CancelAndCleanup
       
   855 // Cancel all actions and free resources.
       
   856 // -----------------------------------------------------------------------------
       
   857 //
       
   858 void CCaeStillStatesActive::CancelAndCleanup()
       
   859     {
       
   860     iDelayedEvent = CCaeStillStatesActive::ECaeEventNone;
       
   861 
       
   862     CompleteStillBurst();
       
   863 
       
   864     if ( iStillEncoder )
       
   865         {
       
   866         iStillEncoder->Cancel();
       
   867         iStillEncoder->Cleanup(); 
       
   868         }
       
   869 
       
   870     if ( iStillDecoder )
       
   871         {
       
   872         iStillDecoder->Cancel();
       
   873         iStillDecoder->Cleanup();
       
   874         }    
       
   875 
       
   876     // Delete all that is not NULL already. 
       
   877     delete iSnapBitmap;
       
   878     iSnapBitmap = NULL;
       
   879     delete iBitmap;
       
   880     iBitmap = NULL;
       
   881     delete iImageData;
       
   882     iImageData = NULL;
       
   883     delete iImageHeaderData;
       
   884     iImageHeaderData = NULL;
       
   885     if ( iImageQueueExtPro )
       
   886         {
       
   887         iImageQueueExtPro->ResetAndDestroyImages();
       
   888         }    
       
   889 
       
   890     iCurrentState = CCaeStillStatesActive::ECaeStateNone;   
       
   891     }
       
   892 
       
   893 // ---------------------------------------------------------------------------
       
   894 // CCaeStillStatesActive::RunL()
       
   895 // The main function that receives all events. Simple events are also handled 
       
   896 // here. For more complex events, specific handler functions are called.
       
   897 // ---------------------------------------------------------------------------
       
   898 //
       
   899 void CCaeStillStatesActive::RunL()
       
   900     {
       
   901     LOGTEXT3( _L( "Cae: CCaeStillStatesActive::RunL() entering, iStatus=%d, iCurrentState=%d" ), iStatus.Int(), iCurrentState );
       
   902 
       
   903     // Handle external errors 
       
   904 
       
   905     if ( iStatus.Int() < 0 )
       
   906         {
       
   907         HandleExternalError();
       
   908         return;
       
   909         }
       
   910 
       
   911     // Handle all state transitions
       
   912 
       
   913     switch( iStatus.Int() )
       
   914         {
       
   915         case CCaeStillStatesActive::ECaeEventNone:
       
   916             HandleExternalEvent();
       
   917             break;
       
   918 
       
   919         case CCaeStillStatesActive::ECaeEventStartStillCapture:
       
   920             CAE_ASSERT_DEBUG( iCurrentState == CCaeStillStatesActive::ECaeStateNone );
       
   921             HandleStart();
       
   922             break;
       
   923 
       
   924         case CCaeStillStatesActive::ECaeEventImageCaptureReady:
       
   925             CAE_ASSERT_DEBUG( iCurrentState == CCaeStillStatesActive::ECaeStateCapturing );
       
   926             HandleImageCaptureReady();
       
   927             break;
       
   928 
       
   929         case CCaeStillStatesActive::ECaeEventBurstImageCaptureReady:
       
   930             CAE_ASSERT_DEBUG( iCurrentState == CCaeStillStatesActive::ECaeStateCapturingBurst );
       
   931             iCurrentState = CCaeStillStatesActive::ECaeStateAppendingBurstImage;            
       
   932             DoAppendCapturedBurstImageToArray();
       
   933             break;
       
   934 
       
   935         case CCaeStillStatesActive::ECaeEventAppendCapturedBurstImageReady:
       
   936             CAE_ASSERT_DEBUG( iCurrentState == CCaeStillStatesActive::ECaeStateAppendingBurstImage );
       
   937             HandleAppendCapturedBurstImageReady();            
       
   938             break;
       
   939 
       
   940         case CCaeStillStatesActive::ECaeEventViewFinderForBurstReady:
       
   941             CAE_ASSERT_DEBUG( iCurrentState == CCaeStillStatesActive::ECaeStateBurstWaitingForViewFinder );
       
   942             iCurrentState = CCaeStillStatesActive::ECaeStateCapturingBurst;            
       
   943             DoCaptureStillBurstImage();            
       
   944             break;
       
   945 
       
   946         case CCaeStillStatesActive::ECaeEventBurstCaptureReady:
       
   947             CAE_ASSERT_DEBUG( iCurrentState == CCaeStillStatesActive::ECaeStateCapturingBurst );
       
   948             iCurrentState = CCaeStillStatesActive::ECaeStateFetchingNextBurstImage;    
       
   949             iStatus = CCaeStillStatesActive::ECaeEventNone;
       
   950             DoFetchNextBurstImage();
       
   951             break;
       
   952 
       
   953         case CCaeStillStatesActive::ECaeEventBurstImageFetchReady:
       
   954             CAE_ASSERT_DEBUG( iCurrentState == CCaeStillStatesActive::ECaeStateFetchingNextBurstImage );
       
   955             HandleBurstImageFetchReady();
       
   956             break;
       
   957 
       
   958         case CCaeStillStatesActive::ECaeEventDecodeToBitmapReady:
       
   959             CAE_ASSERT_DEBUG( iCurrentState == CCaeStillStatesActive::ECaeStateDecodingCapturedImageToBitmap );
       
   960             HandleDecodeToBitmapReady();
       
   961             break;
       
   962 
       
   963         case CCaeStillStatesActive::ECaeEventExtractExifMetaDataReady:
       
   964             CAE_ASSERT_DEBUG( iCurrentState == CCaeStillStatesActive::ECaeStateExtractingExifMetaData );
       
   965             iCurrentState = CCaeStillStatesActive::ECaeStateExtensionsProcessingCapturedImage;         
       
   966             iStatus = CCaeStillStatesActive::ECaeEventNone;
       
   967             DoExtensionsProcessCapturedImage();    
       
   968             break;
       
   969 
       
   970         case CCaeStillStatesActive::ECaeEventProcessCapturedImageStepReady:
       
   971             CAE_ASSERT_DEBUG( iCurrentState == CCaeStillStatesActive::ECaeStateExtensionsProcessingCapturedImage );
       
   972             iStatus = CCaeStillStatesActive::ECaeEventNone;
       
   973             DoExtensionsProcessCapturedImage();
       
   974             break;
       
   975 
       
   976         case CCaeStillStatesActive::ECaeEventProcessCapturedImageAllReady:
       
   977             CAE_ASSERT_DEBUG( iCurrentState == CCaeStillStatesActive::ECaeStateExtensionsProcessingCapturedImage );
       
   978             HandleProcessCapturedImageAllReady();
       
   979             break;
       
   980 
       
   981         case CCaeStillStatesActive::ECaeEventProcessSnapImageStepReady:
       
   982             CAE_ASSERT_DEBUG( iCurrentState == CCaeStillStatesActive::ECaeStateExtensionsProcessingSnapImage );
       
   983             iStatus = CCaeStillStatesActive::ECaeEventNone;
       
   984             DoExtensionsProcessSnapImage();    
       
   985             break;
       
   986 
       
   987         case CCaeStillStatesActive::ECaeEventProcessSnapImageAllReady:
       
   988             CAE_ASSERT_DEBUG( iCurrentState == CCaeStillStatesActive::ECaeStateExtensionsProcessingSnapImage );
       
   989             iCurrentState = CCaeStillStatesActive::ECaeStateDeliveringSnapImage;         
       
   990             iStatus = CCaeStillStatesActive::ECaeEventNone;
       
   991             DoDeliverSnapImage();    
       
   992             break;
       
   993 
       
   994         case CCaeStillStatesActive::ECaeEventDeliverSnapImageReady:
       
   995             CAE_ASSERT_DEBUG( iCurrentState == CCaeStillStatesActive::ECaeStateDeliveringSnapImage );
       
   996             iCurrentState = CCaeStillStatesActive::ECaeStateExtensionsProcessingStillImage;         
       
   997             iStatus = CCaeStillStatesActive::ECaeEventNone;
       
   998             DoExtensionsProcessStillImage();    
       
   999             break;
       
  1000 
       
  1001         case CCaeStillStatesActive::ECaeEventProcessStillImageStepReady:
       
  1002             CAE_ASSERT_DEBUG( iCurrentState == CCaeStillStatesActive::ECaeStateExtensionsProcessingStillImage );
       
  1003             iStatus = CCaeStillStatesActive::ECaeEventNone;
       
  1004             DoExtensionsProcessStillImage();
       
  1005             break;
       
  1006 
       
  1007         case CCaeStillStatesActive::ECaeEventProcessStillImageAllReady:
       
  1008             CAE_ASSERT_DEBUG( iCurrentState == CCaeStillStatesActive::ECaeStateExtensionsProcessingStillImage );
       
  1009             HandleProcessStillImageAllReady();
       
  1010             break;
       
  1011 
       
  1012         case CCaeStillStatesActive::ECaeEventEncodeToJpegReady:
       
  1013              CAE_ASSERT_DEBUG( iCurrentState == CCaeStillStatesActive::ECaeStateEncodingToJpeg );
       
  1014             HandleEncodeToJpegReady();
       
  1015             break;
       
  1016 
       
  1017         case CCaeStillStatesActive::ECaeEventDeliverStillBurstImageReady:
       
  1018             // We can end up here from any state, if there occurs an error
       
  1019             HandleDeliverStillBurstImageReady();
       
  1020             break;
       
  1021 
       
  1022         case CCaeStillStatesActive::ECaeEventImageQueueExtPro:
       
  1023             CAE_ASSERT_DEBUG( iCurrentState == CCaeStillStatesActive::ECaeStateNone );
       
  1024             HandleImageQueueExtPro();
       
  1025             break;
       
  1026 
       
  1027         default:
       
  1028             CAE_ASSERT_DEBUG( iCurrentState != iCurrentState ); // Always false
       
  1029             break;
       
  1030         }
       
  1031 
       
  1032     LOGTEXT( _L( "Cae: CCaeStillStatesActive::RunL() returning" ) );
       
  1033     }
       
  1034 
       
  1035 
       
  1036 // ---------------------------------------------------------------------------
       
  1037 // EVENT HANDLERS
       
  1038 //
       
  1039 // Event handlers should decide what is the next state and next action after the 
       
  1040 // current event. Modes and flags are checked here leaving the actual action 
       
  1041 // functions as simple as possible. 
       
  1042 // ---------------------------------------------------------------------------
       
  1043 
       
  1044 // -----------------------------------------------------------------------------
       
  1045 // CCaeStillStatesActive::HandleExternalError
       
  1046 // -----------------------------------------------------------------------------
       
  1047 //
       
  1048 void CCaeStillStatesActive::HandleExternalError() 
       
  1049     {
       
  1050     LOGTEXT( _L( "Cae: CCaeStillStatesActive::HandleExternalError()" ));
       
  1051 
       
  1052     CAE_ASSERT_DEBUG( ( ( iDelayedEvent != CCaeStillStatesActive::ECaeEventNone )
       
  1053                        || ( iCurrentState == CCaeStillStatesActive::ECaeStateExtensionsProcessingCapturedImage ) 
       
  1054                        || ( iCurrentState == CCaeStillStatesActive::ECaeStateExtensionsProcessingSnapImage ) 
       
  1055                        || ( iCurrentState == CCaeStillStatesActive::ECaeStateExtensionsProcessingStillImage ) ) ); 
       
  1056          
       
  1057     // Cancelling delayed event timer is not considered as error, but early completion              
       
  1058     if ( (iStatus.Int() == KErrCancel ) && ( iDelayedEvent != CCaeStillStatesActive::ECaeEventNone ) )
       
  1059         {
       
  1060     	LOGTEXT2( _L( "Cae: CCaeStillStatesActive::HandleExternalError(). Delayed event %d completed early." ), iDelayedEvent);
       
  1061     	HandleExternalEvent();
       
  1062         }
       
  1063     else
       
  1064     	{
       
  1065     	ErrorRecovery( iStatus.Int() );                        		
       
  1066     	}    
       
  1067 
       
  1068     }
       
  1069 
       
  1070 
       
  1071 // -----------------------------------------------------------------------------
       
  1072 // CCaeStillStatesActive::HandleExternalEvent
       
  1073 // -----------------------------------------------------------------------------
       
  1074 //
       
  1075 void CCaeStillStatesActive::HandleExternalEvent() 
       
  1076     {
       
  1077     LOGTEXT( _L( "Cae: CCaeStillStatesActive::HandleExternalEvent()" ));
       
  1078     CAE_ASSERT_DEBUG( ( ( iDelayedEvent != CCaeStillStatesActive::ECaeEventNone )
       
  1079                        || ( iCurrentState == CCaeStillStatesActive::ECaeStateExtensionsProcessingCapturedImage ) 
       
  1080                        || ( iCurrentState == CCaeStillStatesActive::ECaeStateExtensionsProcessingSnapImage ) 
       
  1081                        || ( iCurrentState == CCaeStillStatesActive::ECaeStateExtensionsProcessingStillImage ) ) ); 
       
  1082 
       
  1083         
       
  1084     if ( iDelayedEvent != CCaeStillStatesActive::ECaeEventNone )
       
  1085         {
       
  1086         // Timer has finished, issue delayed event now
       
  1087         Event( iDelayedEvent );
       
  1088         }
       
  1089     else          
       
  1090         {
       
  1091         switch ( iCurrentState )
       
  1092             {
       
  1093             case ECaeStateExtensionsProcessingCapturedImage:
       
  1094                 Event( CCaeStillStatesActive::ECaeEventProcessCapturedImageStepReady );
       
  1095                 break;
       
  1096 
       
  1097             case ECaeStateExtensionsProcessingSnapImage:
       
  1098                 Event( CCaeStillStatesActive::ECaeEventProcessSnapImageStepReady );
       
  1099                 break;
       
  1100 
       
  1101             case ECaeStateExtensionsProcessingStillImage:
       
  1102                 Event( CCaeStillStatesActive::ECaeEventProcessStillImageStepReady );
       
  1103                 break;
       
  1104 
       
  1105             default:
       
  1106                 CAE_ASSERT_DEBUG( iCurrentState !=  iCurrentState ); // Always false
       
  1107                 break;
       
  1108 
       
  1109             }
       
  1110         }
       
  1111     }
       
  1112 
       
  1113 
       
  1114 // ---------------------------------------------------------------------------
       
  1115 // CCaeStillStatesActive::HandleStart()
       
  1116 // Start either single or burst image capture.
       
  1117 // ---------------------------------------------------------------------------
       
  1118 //
       
  1119 void CCaeStillStatesActive::HandleStart()
       
  1120     {
       
  1121     LOGTEXT( _L( "Cae: CCaeStillStatesActive::HandleStart()" ));
       
  1122     CAE_ASSERT_ALWAYS( ( iBitmap == NULL ) && ( iSnapBitmap == NULL ) );
       
  1123     CAE_ASSERT_ALWAYS( ( iImageData == NULL ) && ( iImageHeaderData == NULL ) );
       
  1124     
       
  1125     iStatus = CCaeStillStatesActive::ECaeEventNone;
       
  1126     if ( iStillBurst )
       
  1127         {               
       
  1128         iCurrentState = CCaeStillStatesActive::ECaeStateCapturingBurst;            
       
  1129         DoCaptureStillBurst();
       
  1130         }
       
  1131     else
       
  1132         {
       
  1133         iCurrentState = CCaeStillStatesActive::ECaeStateCapturing;            
       
  1134         DoCaptureStill();
       
  1135         }   
       
  1136     }
       
  1137 
       
  1138 
       
  1139 // ---------------------------------------------------------------------------
       
  1140 // CCaeStillStatesActive::HandleImageCaptureReady()
       
  1141 // Decode the captured image, extract Exif metadata, or process the 
       
  1142 // image by the extensions.  
       
  1143 // ---------------------------------------------------------------------------
       
  1144 //
       
  1145 void CCaeStillStatesActive::HandleImageCaptureReady()
       
  1146     {
       
  1147     LOGTEXT( _L( "Cae: CCaeStillStatesActive::HandleImageCaptureReady()" ));
       
  1148 
       
  1149     iStatus = CCaeStillStatesActive::ECaeEventNone;
       
  1150 
       
  1151     if ( !iBitmap                   // Does not already exist
       
  1152          && ( iCreateSnapImage ) )    // Snap bitmap required by UI
       
  1153             /* Not yet implemented
       
  1154             || iRequireStillImageAsBitmapRefCount ) ) // Still bitmap required by any extensions
       
  1155             */
       
  1156         {
       
  1157         iCurrentState = CCaeStillStatesActive::ECaeStateDecodingCapturedImageToBitmap;            
       
  1158         DoDecodeCapturedImageToBitmap();
       
  1159         }
       
  1160     else
       
  1161         {
       
  1162         /* Not yet implemented
       
  1163         if ( iRequireImageFormatHeaderRefCount )
       
  1164             {
       
  1165             iCurrentState = CCaeStillStatesActive::ECaeStateExtractingExifMetaData;            
       
  1166             DoExtractExifMetaData();
       
  1167            }
       
  1168         else
       
  1169         */
       
  1170             {
       
  1171             iCurrentState = CCaeStillStatesActive::ECaeStateExtensionsProcessingCapturedImage;            
       
  1172             DoExtensionsProcessCapturedImage();    
       
  1173             }
       
  1174         }
       
  1175     }
       
  1176 
       
  1177 // ---------------------------------------------------------------------------
       
  1178 // CCaeStillStatesActive::HandleDecodeToBitmapReady()
       
  1179 // Extract Exif metadata, or process the captured image by the 
       
  1180 // extensions.
       
  1181 // ---------------------------------------------------------------------------
       
  1182 //
       
  1183 void CCaeStillStatesActive::HandleDecodeToBitmapReady()
       
  1184     {
       
  1185     LOGTEXT( _L( "Cae: CCaeStillStatesActive::HandleDecodeToBitmapReady()" ));
       
  1186     CAE_ASSERT_ALWAYS( ( iBitmap != NULL ) && ( iSnapBitmap == NULL ) );
       
  1187     CAE_ASSERT_ALWAYS( ( iImageData != NULL ) && ( iImageHeaderData == NULL ) );
       
  1188 
       
  1189     iStatus = CCaeStillStatesActive::ECaeEventNone;
       
  1190 
       
  1191     if ( iCreateSnapImage )    // Snap bitmap required by UI
       
  1192         /* Not yet implemented
       
  1193        && !iRequireStillImageAsBitmapRefCount ) // Still bitmap not required by any extensions
       
  1194        */
       
  1195         {
       
  1196         // Decoded bitmap is used for the snap bitmap only
       
  1197         iSnapBitmap = iBitmap;
       
  1198         iBitmap = NULL;
       
  1199         }    
       
  1200 
       
  1201      /* Not yet implemented
       
  1202     if ( iRequireImageFormatHeaderRefCount )
       
  1203         {
       
  1204         iCurrentState = CCaeStillStatesActive::ECaeStateExtractingExifMetaData;            
       
  1205         DoExtractExifMetaData();
       
  1206         }
       
  1207     else
       
  1208     */
       
  1209         {
       
  1210         iCurrentState = CCaeStillStatesActive::ECaeStateExtensionsProcessingCapturedImage;            
       
  1211         DoExtensionsProcessCapturedImage();    
       
  1212         }
       
  1213     }
       
  1214 
       
  1215 
       
  1216 // ---------------------------------------------------------------------------
       
  1217 // CCaeStillStatesActive::HandleProcessCapturedImageAllReady()
       
  1218 // Process the snap image or the still image by the extensions.
       
  1219 // ---------------------------------------------------------------------------
       
  1220 //
       
  1221 void CCaeStillStatesActive::HandleProcessCapturedImageAllReady()
       
  1222     {
       
  1223     LOGTEXT( _L( "Cae: CCaeStillStatesActive::HandleProcessCapturedImageAllReady()" ));
       
  1224 
       
  1225     iStatus = CCaeStillStatesActive::ECaeEventNone;
       
  1226     if ( iCreateSnapImage )
       
  1227         {
       
  1228         iCurrentState = CCaeStillStatesActive::ECaeStateExtensionsProcessingSnapImage;            
       
  1229         DoExtensionsProcessSnapImage();    
       
  1230         }
       
  1231     else
       
  1232         {
       
  1233         iCurrentState = CCaeStillStatesActive::ECaeStateExtensionsProcessingStillImage;            
       
  1234         DoExtensionsProcessStillImage();
       
  1235         }
       
  1236     }
       
  1237 
       
  1238 
       
  1239 // ---------------------------------------------------------------------------
       
  1240 // CCaeStillStatesActive::HandleProcessStillImageAllReady()
       
  1241 // Encode the still bitmap to Jpeg, or deliver the 
       
  1242 // still image to the client.
       
  1243 // ---------------------------------------------------------------------------
       
  1244 //
       
  1245 void CCaeStillStatesActive::HandleProcessStillImageAllReady()
       
  1246     {
       
  1247     LOGTEXT( _L( "Cae: CCaeStillStatesActive::HandleProcessStillImageAllReady()" ));
       
  1248 
       
  1249     iStatus = CCaeStillStatesActive::ECaeEventNone;
       
  1250 
       
  1251     // Encode to Jpeg if there is a separate (Exif) header or bitmap to 
       
  1252     // Jpeg coversion is needed for client.
       
  1253     if ( iImageHeaderData 
       
  1254          || ( ( iStillOutputFormat == CCamera::EFormatJpeg ) && !iImageData ) )
       
  1255         {
       
  1256         iCurrentState = CCaeStillStatesActive::ECaeStateEncodingToJpeg;            
       
  1257         DoEncodeStillImageToJpeg();
       
  1258         }
       
  1259    else
       
  1260         {
       
  1261         if ( iStillBurst )
       
  1262             {
       
  1263             iCurrentState = CCaeStillStatesActive::ECaeStateDeliveringStillBurstImage;            
       
  1264             DoDeliverStillBurstImage();
       
  1265             }
       
  1266         else
       
  1267             {
       
  1268             iCurrentState = CCaeStillStatesActive::ECaeStateDeliveringStillImage;            
       
  1269             DoDeliverStillImage();
       
  1270             }
       
  1271         }
       
  1272     }
       
  1273     
       
  1274 
       
  1275 // ---------------------------------------------------------------------------
       
  1276 // CCaeStillStatesActive::HandleEncodeToJpegReady()
       
  1277 // Deliver the still image to the client.
       
  1278 // ---------------------------------------------------------------------------
       
  1279 //
       
  1280 void CCaeStillStatesActive::HandleEncodeToJpegReady()
       
  1281     {
       
  1282     LOGTEXT( _L( "Cae: CCaeStillStatesActive::HandleEncodeToJpegReady()" ));
       
  1283 
       
  1284     iStatus = CCaeStillStatesActive::ECaeEventNone;
       
  1285     if ( iStillBurst )
       
  1286         {
       
  1287         iCurrentState = CCaeStillStatesActive::ECaeStateDeliveringStillBurstImage;            
       
  1288         DoDeliverStillBurstImage();
       
  1289         }
       
  1290     else
       
  1291         {
       
  1292         iCurrentState = CCaeStillStatesActive::ECaeStateDeliveringStillImage;            
       
  1293         DoDeliverStillImage();
       
  1294         }
       
  1295     }
       
  1296 
       
  1297 
       
  1298 // ---------------------------------------------------------------------------
       
  1299 // CCaeStillStatesActive::HandleImageQueueExtPro()
       
  1300 // Deliver the still image to the client.
       
  1301 // ---------------------------------------------------------------------------
       
  1302 //
       
  1303 void CCaeStillStatesActive::HandleImageQueueExtPro()
       
  1304     {
       
  1305     LOGTEXT( _L( "Cae: CCaeStillStatesActive::HandleImageQueueExtPro()" ));
       
  1306 
       
  1307     CFbsBitmap* bitmap = NULL;
       
  1308     HBufC8*     imagedata = NULL;
       
  1309     TBool       lastimage = EFalse;
       
  1310     TBool       snapimage = EFalse;
       
  1311 
       
  1312     // Get next snap or main image from image queue
       
  1313     if ( iImageQueueExtPro )
       
  1314         {
       
  1315         TInt result = iImageQueueExtPro->GetNextImage( bitmap, imagedata, lastimage, snapimage );
       
  1316 
       
  1317         // If prepare has not been done then format has default value
       
  1318         if ( !iStillPrepared )
       
  1319             {
       
  1320             iStillOutputFormat = CCamera::EFormatExif; // Only exif/jpeg is supported
       
  1321             }
       
  1322         if ( result == KErrNone )
       
  1323             {
       
  1324             iLastImageExtPro = lastimage;
       
  1325             if ( bitmap && snapimage ) // Snap image
       
  1326                 {
       
  1327                 LOGTEXT( _L( "Cae: CCaeStillStatesActive::HandleImageQueueExtPro() Snap bitmap" ));
       
  1328                 iStatus = CCaeStillStatesActive::ECaeEventNone;
       
  1329                 iCurrentState = CCaeStillStatesActive::ECaeStateExtensionsProcessingSnapImage;            
       
  1330                 iSnapBitmap = bitmap;
       
  1331                 Event( CCaeStillStatesActive::ECaeEventProcessSnapImageStepReady );
       
  1332                 }
       
  1333             else if ( imagedata && !snapimage) // Main captured image (jpeg)
       
  1334                 {
       
  1335                 LOGTEXT( _L( "Cae: CCaeStillStatesActive::HandleImageQueueExtPro() JPG imagedata" ));
       
  1336                 iStatus = CCaeStillStatesActive::ECaeEventNone;
       
  1337                 iCurrentState = CCaeStillStatesActive::ECaeStateExtensionsProcessingStillImage;            
       
  1338                 iImageData = imagedata;
       
  1339                 Event( CCaeStillStatesActive::ECaeEventProcessStillImageStepReady );
       
  1340                 }
       
  1341             else if ( bitmap && !snapimage) // Main captured image (bitmap)
       
  1342                 {
       
  1343                 LOGTEXT( _L( "Cae: CCaeStillStatesActive::HandleImageQueueExtPro() bitmap imagedata" ));
       
  1344                 iStatus = CCaeStillStatesActive::ECaeEventNone;
       
  1345                 iCurrentState = CCaeStillStatesActive::ECaeStateDeliveringSnapImage;            
       
  1346                 iBitmap = bitmap;
       
  1347                 Event( CCaeStillStatesActive::ECaeEventDeliverSnapImageReady );
       
  1348                 }
       
  1349             else 
       
  1350                 {
       
  1351                 LOGTEXT( _L( "Cae: CCaeStillStatesActive::HandleImageQueueExtPro() iImageQueueExtPro return empty image" ));
       
  1352                 }
       
  1353             }
       
  1354         else
       
  1355             {
       
  1356             LOGTEXT2( _L( "Cae: CCaeStillStatesActive::HandleImageQueueExtPro() iImageQueueExtPro error %d" ), result);
       
  1357             }
       
  1358         }
       
  1359     else
       
  1360         {
       
  1361         LOGTEXT( _L( "Cae: CCaeStillStatesActive::HandleImageQueueExtPro() iImageQueueExtPro not found" ));
       
  1362         }
       
  1363 
       
  1364     }
       
  1365 
       
  1366 
       
  1367 // ---------------------------------------------------------------------------
       
  1368 // EXTERNAL CALLBACKS
       
  1369 //
       
  1370 // Callbacks from external objects are mapped to the internal events.
       
  1371 // ---------------------------------------------------------------------------
       
  1372 
       
  1373 
       
  1374 // -----------------------------------------------------------------------------
       
  1375 // CCaeStillStatesActive::ImageReady
       
  1376 // Store the captured image and send event to the state machine.
       
  1377 // -----------------------------------------------------------------------------
       
  1378 //
       
  1379 void CCaeStillStatesActive::ImageReady( 
       
  1380     CFbsBitmap* aBitmap, 
       
  1381     HBufC8*     aImageData, 
       
  1382     TInt        aError )
       
  1383     {
       
  1384     LOGTEXT2( _L( "Cae: CCaeStillStatesActive::ImageReady() entering, aError=%d" ), aError );
       
  1385     CAE_ASSERT_ALWAYS( ( iBitmap == NULL ) && ( iSnapBitmap == NULL ) );
       
  1386     CAE_ASSERT_ALWAYS( ( iImageData == NULL ) && ( iImageHeaderData == NULL ) );
       
  1387     
       
  1388     #ifdef _DEBUG
       
  1389     // Performance debugging
       
  1390     iImageReadyTime.HomeTime();
       
  1391     TTimeIntervalMicroSeconds convertInterval =
       
  1392         iImageReadyTime.MicroSecondsFrom( iCaptureStartTime );
       
  1393     LOGTEXT2( _L( "Cae: CCaeStillStatesActive::ImageReady(): Captured image ready %f seconds after capture" ),
       
  1394                    I64LOW( convertInterval.Int64() ) * 1.0 / KOneSecond );
       
  1395     #endif
       
  1396 
       
  1397     #ifdef CAE_TEST_VERSION
       
  1398     // For simulating errors when compiled as special "test version".
       
  1399     CaeImageReadyError( aError );
       
  1400     #endif    
       
  1401 
       
  1402     // Get ownership and store pointers
       
  1403     iBitmap = aBitmap;
       
  1404     iImageData = aImageData;
       
  1405 
       
  1406     if ( iStillBurst )
       
  1407         {
       
  1408         iFirstStillBurstError =  iFirstStillBurstError ? iFirstStillBurstError : aError;
       
  1409         Event( CCaeStillStatesActive::ECaeEventBurstImageCaptureReady );
       
  1410         }
       
  1411 
       
  1412     // Single image capture
       
  1413     else if ( !aError )
       
  1414         {
       
  1415         Event( CCaeStillStatesActive::ECaeEventImageCaptureReady );
       
  1416         }
       
  1417     else
       
  1418         {
       
  1419         // Handle error
       
  1420         ErrorRecovery( aError );
       
  1421         }
       
  1422 
       
  1423     LOGTEXT( _L( "Cae: CCaeStillStatesActive::ImageReady() returning" ) );
       
  1424     }
       
  1425 
       
  1426 
       
  1427 // -----------------------------------------------------------------------------
       
  1428 // CCaeStillStatesActive::McaesdoCFbsBitmapImageReady
       
  1429 // Store original and decoded images and send event to the state machine.
       
  1430 // -----------------------------------------------------------------------------
       
  1431 //
       
  1432 void CCaeStillStatesActive::McaesdoCFbsBitmapImageReady( 
       
  1433     HBufC8*     aImageData, 
       
  1434     CFbsBitmap* aBitmap, 
       
  1435     TInt        aError,
       
  1436     TInt        /*aImageSize*/ ) // Not yet used
       
  1437     {
       
  1438     LOGTEXT( _L( "Cae: CCaeStillStatesActive::McaesdoCFbsBitmapImageReady() entering" ) );
       
  1439     CAE_ASSERT_ALWAYS( ( iBitmap == NULL ) && ( iSnapBitmap == NULL ) );
       
  1440     CAE_ASSERT_ALWAYS( iImageHeaderData == NULL );
       
  1441     CAE_ASSERT_ALWAYS( !iStillCancelled );
       
  1442 
       
  1443    #ifdef _DEBUG
       
  1444     // Performance debugging
       
  1445     iFinalImageReadyTime.HomeTime();
       
  1446     TTimeIntervalMicroSeconds convertInterval =
       
  1447         iFinalImageReadyTime.MicroSecondsFrom( iCaptureStartTime );
       
  1448     LOGTEXT2( _L( "Cae: CCaeEngineImp::McaesdoCFbsBitmapImageReady(): Final decoded image ready %f seconds after capture" ),
       
  1449                    I64LOW( convertInterval.Int64() ) * 1.0 / KOneSecond );
       
  1450     #endif
       
  1451 
       
  1452     #ifdef CAE_TEST_VERSION
       
  1453     // For simulating errors when compiled as special "test version".
       
  1454     CaeMcaesdoCFbsBitmapImageReadyError( aError );
       
  1455     #endif
       
  1456     
       
  1457     // Get ownership and store pointers
       
  1458     iBitmap = aBitmap;
       
  1459 
       
  1460     // Delete image data if not the original (extracted thumbnail was used as decoder input).
       
  1461     if ( iImageData != NULL )
       
  1462         {
       
  1463         delete ( aImageData ); // Delete (exif) thumbnail source image
       
  1464         }
       
  1465     else
       
  1466         {
       
  1467         iImageData = aImageData; // Store original still image
       
  1468         }
       
  1469 
       
  1470     if ( !aError )
       
  1471         {
       
  1472         Event( CCaeStillStatesActive::ECaeEventDecodeToBitmapReady );
       
  1473         }
       
  1474     else
       
  1475         {
       
  1476         // Handle error
       
  1477         ErrorRecovery( aError );
       
  1478         }
       
  1479 
       
  1480     LOGTEXT( _L( "Cae: CCaeStillStatesActive::McaesdoCFbsBitmapImageReady() returning" ) );
       
  1481     }
       
  1482     
       
  1483 
       
  1484 // -----------------------------------------------------------------------------
       
  1485 // CCaeStillStatesActive::McaeseoHBufC8ImageReady
       
  1486 // Store original and encoded images and send event to the state machine.
       
  1487 // -----------------------------------------------------------------------------
       
  1488 //
       
  1489 void CCaeStillStatesActive::McaeseoHBufC8ImageReady( 
       
  1490     CFbsBitmap* aBitmap, 
       
  1491     HBufC8*     aImageData, 
       
  1492     TInt        aError,
       
  1493     TInt        /*aImageSize*/ )
       
  1494     {
       
  1495     LOGTEXT( _L( "Cae: CCaeStillStatesActive::McaeseoHBufC8ImageReady() entering" ) );
       
  1496     CAE_ASSERT_ALWAYS( ( iBitmap == NULL ) && ( iSnapBitmap == NULL ) );
       
  1497     CAE_ASSERT_ALWAYS( ( iImageData == NULL ) && ( iImageHeaderData == NULL ) );
       
  1498     CAE_ASSERT_ALWAYS( !iStillCancelled );
       
  1499     
       
  1500     #ifdef _DEBUG
       
  1501     // Performance debugging
       
  1502     iFinalImageReadyTime.HomeTime();
       
  1503     TTimeIntervalMicroSeconds convertInterval =
       
  1504         iFinalImageReadyTime.MicroSecondsFrom( iCaptureStartTime );
       
  1505     LOGTEXT2(_L( "Cae: CCaeStillStatesActive::McaeseoHBufC8ImageReady(): Final encoded image ready %f seconds after capture" ), 
       
  1506         I64LOW( convertInterval.Int64() ) * 1.0 / KOneSecond);
       
  1507     #endif
       
  1508 
       
  1509     #ifdef CAE_TEST_VERSION
       
  1510     // For simulating errors when compiled as special "test version".
       
  1511     CaeMcaeseoHBufC8ImageReadyError( aError );
       
  1512     #endif
       
  1513     
       
  1514     // Get ownership and store pointers
       
  1515     iBitmap = aBitmap;
       
  1516     iImageData = aImageData;
       
  1517 
       
  1518     if ( !aError )
       
  1519         {
       
  1520         Event( CCaeStillStatesActive::ECaeEventEncodeToJpegReady );
       
  1521         }
       
  1522     else 
       
  1523         {
       
  1524         // Handle error
       
  1525         ErrorRecovery( aError );
       
  1526         }
       
  1527 
       
  1528     LOGTEXT( _L( "Cae: CCaeStillStatesActive::McaeseoHBufC8ImageReady() returning" ) );
       
  1529     }
       
  1530 
       
  1531 
       
  1532 // -----------------------------------------------------------------------------
       
  1533 // CCaeStillStatesActive::ViewFinderFrameReady
       
  1534 // Send event if the state machine is waiting for the view finder. 
       
  1535 // -----------------------------------------------------------------------------
       
  1536 //
       
  1537 void CCaeStillStatesActive::ViewFinderFrameReady()
       
  1538     {
       
  1539 	iViewFinderFrameReceived = ETrue;
       
  1540 
       
  1541     if ( iCurrentState == CCaeStillStatesActive::ECaeStateBurstWaitingForViewFinder 
       
  1542          && !IsActive() ) // To make sure the previous ECaeEventViewFinderForBurstReady has been handled
       
  1543         {
       
  1544         Event( CCaeStillStatesActive::ECaeEventViewFinderForBurstReady );        
       
  1545         }
       
  1546     }
       
  1547 
       
  1548 
       
  1549 // ---------------------------------------------------------------------------
       
  1550 // ACTION FUNCTIONS FOR STATES
       
  1551 //
       
  1552 // To keep it simple, action functions should do only one task each if 
       
  1553 // possible. If there is a lot of conditions, make several action functions 
       
  1554 // and call them from event handlers. 
       
  1555 // ---------------------------------------------------------------------------
       
  1556 
       
  1557 
       
  1558 // -----------------------------------------------------------------------------
       
  1559 // CCaeStillStatesActive::DoCaptureStill
       
  1560 // Start image capturing in Camera API.
       
  1561 // -----------------------------------------------------------------------------
       
  1562 //
       
  1563 void CCaeStillStatesActive::DoCaptureStill()
       
  1564     {
       
  1565     LOGTEXT( _L( "Cae: CCaeStillStatesActive::DoCaptureStill() entering" ) );
       
  1566 
       
  1567     #ifdef _DEBUG
       
  1568     // Performance debugging
       
  1569     iCaptureStartTime.HomeTime();
       
  1570     #endif
       
  1571 
       
  1572     iViewFinderFrameReceived = EFalse;
       
  1573     iStillCancelled = EFalse;
       
  1574 
       
  1575     iCamera.CaptureImage(); // Start capture
       
  1576 
       
  1577     LOGTEXT( _L( "Cae: CCaeStillStatesActive::DoCaptureStill() returning" ) );
       
  1578     }
       
  1579 
       
  1580 
       
  1581 // -----------------------------------------------------------------------------
       
  1582 // CCaeStillStatesActive::DoDecodeCapturedImageToBitmap
       
  1583 //
       
  1584 // Decode to bitmap. CCaeStillDecoder calls McaesdoCFbsBitmapImageReady 
       
  1585 // callback when decoding is ready.
       
  1586 // Decodes Exif thumbnail to bitmap if requested (by iSnapImageSource).
       
  1587 // Note that the callback can be called synchronously by iStillDecoder, if 
       
  1588 // an error occurs in the still decoder. In that case also  ErrorRecovery() 
       
  1589 // has been called in McaesdoCFbsBitmapImageReady() *before* the method 
       
  1590 // below returns.
       
  1591 // -----------------------------------------------------------------------------
       
  1592 //
       
  1593 void CCaeStillStatesActive::DoDecodeCapturedImageToBitmap()
       
  1594     {
       
  1595     LOGTEXT( _L( "Cae: CCaeStillStatesActive::DoDecodeCapturedImageToBitmap()" ) );
       
  1596     HBufC8* tmpImageData = NULL;
       
  1597     TSize   tmpSnapImageSize( 0, 0 );
       
  1598     TInt    error( KErrNone );
       
  1599     
       
  1600     // Use thumbnail for snap image basis if requested to use it.
       
  1601     if ( iSnapImageSource == CCaeEngine::ESnapImageSourceThumbnail ) 
       
  1602         {
       
  1603         TRAP( error, GetThumbnailL( tmpImageData, tmpSnapImageSize ) );
       
  1604         if ( error )
       
  1605             {
       
  1606             LOGTEXT( _L( "Cae: CCaeStillStatesActive::DoDecodeCapturedImageToBitmap(): Thumbnail extraction failed" ) );
       
  1607             delete( tmpImageData );
       
  1608             tmpImageData = iImageData;
       
  1609             tmpSnapImageSize = iOptimalSnapImageSize;
       
  1610 	        iImageData = NULL; 
       
  1611             }
       
  1612         }
       
  1613     else // Use the captured image for snap image basis.
       
  1614         {
       
  1615         tmpImageData = iImageData;
       
  1616         tmpSnapImageSize = iOptimalSnapImageSize;
       
  1617 	    iImageData = NULL; 
       
  1618         }
       
  1619 
       
  1620     // Ownership will be transferred. Null the pointer already before the method
       
  1621     // call because it can call McaesdoCFbsBitmapImageReady() callback synchronously 
       
  1622     // inside the method.
       
  1623     // Always decode and scale to the correct size if free scaling is supported.
       
  1624     TDisplayMode displayMode = iRequireFullColorSnapInputImageRefCount ? 
       
  1625         EColor16M : iSnapImageColorMode;
       
  1626     TRAP( error, iStillDecoder->ConvertHBufC8ToCFbsBitmapL( 
       
  1627             tmpImageData, displayMode, tmpSnapImageSize, iSnapImageSize) );
       
  1628 
       
  1629     #ifdef CAE_TEST_VERSION
       
  1630     // For simulating errors when compiled as special "test version".
       
  1631     CaeCreateAndDeliverSnapImageError( error );
       
  1632     #endif
       
  1633 
       
  1634     if ( error )
       
  1635         {
       
  1636         // Handle error.
       
  1637         ErrorRecovery( error );
       
  1638         }
       
  1639     }
       
  1640 
       
  1641 
       
  1642 // -----------------------------------------------------------------------------
       
  1643 // CCaeStillStatesActive::DoExtensionsProcessCapturedImage
       
  1644 //
       
  1645 // Call the extensions for processing the captured image. Subsequent synchronous
       
  1646 // methods are called inside a loop. After an asynchronous method, the extension
       
  1647 // signals the state machine which calls this function again for the next 
       
  1648 // extension.  
       
  1649 // -----------------------------------------------------------------------------
       
  1650 //
       
  1651 void CCaeStillStatesActive::DoExtensionsProcessCapturedImage()
       
  1652     {
       
  1653     LOGTEXT( _L( "Cae: CCaeStillStatesActive::DoExtensionsProcessCapturedImage()" ) );
       
  1654     
       
  1655     OstTrace0( CAMERASRV_PERFORMANCE, CCAESTILLSTATESACTIVE_DOEXTENSIONSPROCESSCAPTUREDIMAGE, "e_CAM_CAE_OPERATIONS 1" );   //CAE_ENGINE_OPERATIONS_START
       
  1656         
       
  1657 	TBool isAsyncOperation = EFalse;
       
  1658 
       
  1659 	// Execute synchronous operations in loop. Exit the loop if there is an 
       
  1660 	// asynchronous function or a syncronous function has returned error status.  		
       
  1661 	while ( iStatus == KErrNone  
       
  1662             && !iStillCancelled
       
  1663 		    && !isAsyncOperation 
       
  1664 		    && ( ++iCurrentExtensionIndex <  iProcessImageImplList.Count() ) )
       
  1665 		{
       
  1666 
       
  1667         TAny* interfacePtr = iProcessImageImplList[iCurrentExtensionIndex].iImplPtr;
       
  1668 
       
  1669         // Call extensions. Note that references to image pointers are given as
       
  1670         // parameters. The engine has shared the ownership with the extensions,
       
  1671         // which can also delete and create new images.
       
  1672         if ( iProcessImageImplList[iCurrentExtensionIndex].iIsActive )
       
  1673             {
       
  1674     		isAsyncOperation = STATIC_CAST( MCaeExtProcessImageInterface*, interfacePtr )->ProcessCapturedImage(
       
  1675                 iStatus, iBitmap, iImageData, iImageHeaderData );
       
  1676             }
       
  1677         else
       
  1678             {
       
  1679 	        LOGTEXT2(_L("Cae: CCaeStillStatesActive::DoExtensionsProcessCapturedImage().Skipping extension %x"),
       
  1680 	            iProcessImageImplList[iCurrentExtensionIndex].iImplUid.iUid);
       
  1681             }
       
  1682 	    
       
  1683 	    #ifdef _DEBUG
       
  1684 	    if ( ( iStatus != KErrNone ) && ( iStatus != KRequestPending ) )
       
  1685 	        {
       
  1686 	        LOGTEXT3(_L("Cae: CCaeStillStatesActive::DoExtensionsProcessCapturedImage().Error: %d in ProcessCapturedImage() for Extension %x"),
       
  1687 	            iStatus.Int(), iProcessImageImplList[iCurrentExtensionIndex].iImplUid.iUid);
       
  1688 	        }
       
  1689 	    #endif
       
  1690 		}
       
  1691 
       
  1692     if (!iStillCancelled)
       
  1693         {
       
  1694 	    // Note: For an asynchronous operation the status can be KErrNone 
       
  1695 	    //       if the operation has already finished and this thread has 
       
  1696 	    //       been signaled. 
       
  1697 		if ( ( iStatus == KErrNone || iStatus == KRequestPending ) && isAsyncOperation )
       
  1698 			{
       
  1699 			// Come back after an asynchronous operation has finished
       
  1700 			SetActive();
       
  1701 			}
       
  1702 		else
       
  1703 			{
       
  1704             iCurrentExtensionIndex = -1;
       
  1705             if ( iStatus == KErrNone )
       
  1706                 {
       
  1707                 OstTrace0( CAMERASRV_PERFORMANCE, DUP1_CCAESTILLSTATESACTIVE_DOEXTENSIONSPROCESSCAPTUREDIMAGE, "e_CAM_CAE_OPERATIONS 0" );  //CAE_ENGINE_OPERATIONS_END
       
  1708                 Event( CCaeStillStatesActive::ECaeEventProcessCapturedImageAllReady );            
       
  1709                 }
       
  1710             else
       
  1711                 {
       
  1712                 // Note: negative status values are handled as "external errors"
       
  1713                 // in RunL(). Check that the received iStatus is negative, extension can return any value
       
  1714                 
       
  1715                 if ( iStatus.Int() <= 0 )
       
  1716                     {
       
  1717                     Event( (CCaeStillStatesActive::TCaeEvent)iStatus.Int() );    
       
  1718                     }
       
  1719                 else
       
  1720                     {
       
  1721                     Event( (CCaeStillStatesActive::TCaeEvent) KErrGeneral );    
       
  1722                     }
       
  1723                 }
       
  1724 			}
       
  1725         }
       
  1726     }
       
  1727 
       
  1728 
       
  1729 // -----------------------------------------------------------------------------
       
  1730 // CCaeStillStatesActive::DoExtensionsProcessSnapImage
       
  1731 //
       
  1732 // Call the extensions for processing the snap image. Subsequent synchronous
       
  1733 // methods are called inside a loop. After an asynchronous method, the extension
       
  1734 // signals the state machine which calls this function again for the next 
       
  1735 // extension.  
       
  1736 // -----------------------------------------------------------------------------
       
  1737 //
       
  1738 void CCaeStillStatesActive::DoExtensionsProcessSnapImage()
       
  1739     {
       
  1740     LOGTEXT( _L( "Cae: CCaeStillStatesActive::DoExtensionsProcessSnapImage()" ) );
       
  1741     
       
  1742     OstTrace0( CAMERASRV_PERFORMANCE, CCAESTILLSTATESACTIVE_DOEXTENSIONSPROCESSSNAPIMAGE, "e_CAM_CAE_OPERATIONS 1" );   //CAE_ENGINE_OPERATIONS_START
       
  1743         
       
  1744 	TBool isAsyncOperation = EFalse;
       
  1745 
       
  1746 	// Execute synchronous operations in loop. Exit the loop if there is an 
       
  1747 	// asynchronous function or a syncronous function has returned error status.  
       
  1748 	
       
  1749 	while ( iStatus == KErrNone  
       
  1750             && !iStillCancelled
       
  1751 		    && !isAsyncOperation 
       
  1752 		    && ( ++iCurrentExtensionIndex <  iProcessImageImplList.Count() ) )
       
  1753 		{
       
  1754 
       
  1755         TAny* interfacePtr = iProcessImageImplList[iCurrentExtensionIndex].iImplPtr;
       
  1756 
       
  1757         // Call extensions. Note that references to image pointers are given as
       
  1758         // parameters. The engine has shared the ownership with the extensions,
       
  1759         // which can also delete and create new images.
       
  1760         if ( iProcessImageImplList[iCurrentExtensionIndex].iIsActive )
       
  1761             {
       
  1762     		isAsyncOperation = STATIC_CAST( MCaeExtProcessImageInterface*, interfacePtr )->ProcessSnapImage(
       
  1763                 iStatus, iBitmap, iSnapBitmap );
       
  1764             }
       
  1765         else
       
  1766             {
       
  1767 	        LOGTEXT2(_L("Cae: CCaeStillStatesActive::DoExtensionsProcessSnapImage(). Skipping Extension %x"),
       
  1768 	            iProcessImageImplList[iCurrentExtensionIndex].iImplUid.iUid );
       
  1769             }
       
  1770 	    
       
  1771 	    #ifdef _DEBUG
       
  1772 	    if ( ( iStatus != KErrNone ) && ( iStatus != KRequestPending ) )
       
  1773 	        {
       
  1774 	        LOGTEXT3(_L("Cae: CCaeStillStatesActive::DoExtensionsProcessSnapImage(). Error %d in ProcessSnapImage() for Extension %x"),
       
  1775 	            iStatus.Int(), iProcessImageImplList[iCurrentExtensionIndex].iImplUid.iUid );
       
  1776 	        }
       
  1777 	    #endif
       
  1778 		}
       
  1779 
       
  1780     if (!iStillCancelled)
       
  1781         {
       
  1782 		// Note: For an asynchronous operation the status can be KErrNone 
       
  1783 		//       if the operation has already finished and this thread has 
       
  1784 		//       been signaled. 
       
  1785 		if ( ( iStatus == KErrNone || iStatus == KRequestPending ) && isAsyncOperation )
       
  1786 			{
       
  1787 			// Come back after an asynchronous operation has finished
       
  1788 			SetActive();
       
  1789 			}
       
  1790 		else
       
  1791 			{
       
  1792             iCurrentExtensionIndex = -1;
       
  1793             if ( iStatus == KErrNone )
       
  1794                 {
       
  1795                 OstTrace0( CAMERASRV_PERFORMANCE, DUP1_CCAESTILLSTATESACTIVE_DOEXTENSIONSPROCESSSNAPIMAGE, "CamAppEngine_Perf:e_CAM_CAE_OPERATIONS 0" );    //CAE_ENGINE_OPERATIONS_END
       
  1796                 Event( CCaeStillStatesActive::ECaeEventProcessSnapImageAllReady );            
       
  1797                 }
       
  1798             else
       
  1799                 {
       
  1800                 // Note: negative status values are handled as "external errors"
       
  1801                 // in RunL().
       
  1802                 if ( iStatus.Int() <= 0 )
       
  1803                     {
       
  1804                     Event( (CCaeStillStatesActive::TCaeEvent)iStatus.Int() );    
       
  1805                     }
       
  1806                 else
       
  1807                     {
       
  1808                     Event( (CCaeStillStatesActive::TCaeEvent) KErrGeneral );    
       
  1809                     }
       
  1810                 }
       
  1811 			}
       
  1812         }
       
  1813     }
       
  1814 
       
  1815 
       
  1816 // -----------------------------------------------------------------------------
       
  1817 // CCaeStillStatesActive::DoDeliverSnapImage
       
  1818 // Deliver the snap image to the client.
       
  1819 // -----------------------------------------------------------------------------
       
  1820 //
       
  1821 void CCaeStillStatesActive::DoDeliverSnapImage()
       
  1822     {
       
  1823     LOGTEXT( _L( "Cae: CCaeStillStatesActive::DoDeliverSnapImage()" ) );
       
  1824     CAE_ASSERT_ALWAYS( !iStillCancelled );
       
  1825 
       
  1826     if ( iSnapBitmap )
       
  1827         {
       
  1828         iCaeObserver->McaeoSnapImageReady( *iSnapBitmap, KErrNone );  
       
  1829         delete( iSnapBitmap );
       
  1830         iSnapBitmap = NULL;   
       
  1831         }
       
  1832     else
       
  1833         {
       
  1834         iCaeObserver->McaeoSnapImageReady( *iBitmap, KErrNone );  
       
  1835         }
       
  1836    
       
  1837     if ( !iStillCancelled )
       
  1838         {
       
  1839         if ( ExtModeActive() )
       
  1840             {
       
  1841             Event( CCaeStillStatesActive::ECaeEventEnd ); // extension mode operation is completed
       
  1842             }
       
  1843         else
       
  1844             {
       
  1845             Event( CCaeStillStatesActive::ECaeEventDeliverSnapImageReady );
       
  1846             }
       
  1847         }
       
  1848     }
       
  1849 
       
  1850 
       
  1851 // -----------------------------------------------------------------------------
       
  1852 // CCaeStillStatesActive::DoExtensionsProcessStillImage
       
  1853 //
       
  1854 // Call the extensions for processing the still image. Subsequent synchronous
       
  1855 // methods are called inside a loop. After an asynchronous method, the extension
       
  1856 // signals the state machine which calls this function again for the next 
       
  1857 // extension.  
       
  1858 // -----------------------------------------------------------------------------
       
  1859 //
       
  1860 void CCaeStillStatesActive::DoExtensionsProcessStillImage()
       
  1861     {
       
  1862     LOGTEXT( _L( "Cae: CCaeStillStatesActive::DoExtensionsProcessStillImage()" ) );
       
  1863     
       
  1864     OstTrace0( CAMERASRV_PERFORMANCE, CCAESTILLSTATESACTIVE_DOEXTENSIONSPROCESSSTILLIMAGE, "e_CAM_CAE_OPERATIONS 1" );  //CAE_ENGINE_OPERATIONS_START
       
  1865         
       
  1866 	TBool isAsyncOperation = EFalse;
       
  1867 
       
  1868 	// Execute synchronous operations in loop. Exit the loop if there is an 
       
  1869 	// asynchronous function or a syncronous function has returned error status.  
       
  1870 	
       
  1871 	while ( iStatus == KErrNone  
       
  1872             && !iStillCancelled
       
  1873 		    && !isAsyncOperation 
       
  1874 		    && ( ++iCurrentExtensionIndex <  iProcessImageImplList.Count() ) )
       
  1875 		{
       
  1876 
       
  1877         TAny* interfacePtr = iProcessImageImplList[iCurrentExtensionIndex].iImplPtr;
       
  1878 
       
  1879         // Call extensions. Note that references to image pointers are given as
       
  1880         // parameters. The engine has shared the ownership with the extensions,
       
  1881         // which can also delete and create new images.
       
  1882         if ( iProcessImageImplList[iCurrentExtensionIndex].iIsActive )
       
  1883             {
       
  1884     		isAsyncOperation = STATIC_CAST( MCaeExtProcessImageInterface*, interfacePtr )->ProcessStillImage(
       
  1885                 iStatus, iBitmap, iImageData, iImageHeaderData );
       
  1886             }
       
  1887         else
       
  1888             {
       
  1889 	        LOGTEXT2(_L("Cae: CCaeStillStatesActive::DoExtensionsProcessStillImage(). Skipping extension %x"),
       
  1890 	            iProcessImageImplList[iCurrentExtensionIndex].iImplUid.iUid);
       
  1891             }
       
  1892 	    
       
  1893 	    #ifdef _DEBUG
       
  1894 	    if ( ( iStatus != KErrNone ) && ( iStatus != KRequestPending ) )
       
  1895 	        {
       
  1896 	        LOGTEXT3(_L("Cae: CCaeStillStatesActive::DoExtensionsProcessStillImage(). Error %d in ProcessStillImage() for Extension %x"),
       
  1897 	            iStatus.Int(), iProcessImageImplList[iCurrentExtensionIndex].iImplUid.iUid);
       
  1898 	        }
       
  1899 	    #endif
       
  1900 		}
       
  1901 
       
  1902     if (!iStillCancelled)
       
  1903         {
       
  1904 		// Note: For an asynchronous operation the status can be KErrNone 
       
  1905 		//       if the operation has already finished and this thread has 
       
  1906 		//       been signaled. 
       
  1907 		if ( ( iStatus == KErrNone || iStatus == KRequestPending ) && isAsyncOperation )
       
  1908 			{
       
  1909 			// Come back after an asynchronous operation has finished
       
  1910 			SetActive();
       
  1911 			}
       
  1912 		else
       
  1913 			{
       
  1914             iCurrentExtensionIndex = -1;
       
  1915             if ( iStatus == KErrNone )
       
  1916                 {
       
  1917                 OstTrace0( CAMERASRV_PERFORMANCE, DUP1_CCAESTILLSTATESACTIVE_DOEXTENSIONSPROCESSSTILLIMAGE, "e_CAM_CAE_OPERATIONS 0" ); //CAE_ENGINE_OPERATIONS_END
       
  1918                 Event( CCaeStillStatesActive::ECaeEventProcessStillImageAllReady );            
       
  1919                 }
       
  1920             else
       
  1921                 {
       
  1922                 // Note: negative status values are handled as "external errors"
       
  1923                 // in RunL().
       
  1924                 if ( iStatus.Int() <= 0 )
       
  1925                     {
       
  1926                     Event( (CCaeStillStatesActive::TCaeEvent)iStatus.Int() );    
       
  1927                     }
       
  1928                 else
       
  1929                     {
       
  1930                     Event( (CCaeStillStatesActive::TCaeEvent) KErrGeneral );    
       
  1931                     }
       
  1932                 }
       
  1933 			}
       
  1934         }
       
  1935     }
       
  1936 
       
  1937 
       
  1938 // -----------------------------------------------------------------------------
       
  1939 // CCaeStillStatesActive::DoEncodeStillImageToJpeg
       
  1940 //
       
  1941 // Encode bitmap to the Jpeg image. CCaeStillEncoder calls 
       
  1942 // McaeseoHBufC8ImageReady callback when encoding is ready.
       
  1943 // Note that the callback can be called synchronously by , iStillEncoder
       
  1944 // if an error occurs in the still encoder. In that case also
       
  1945 // ErrorRecovery() has been called in McaeseoHBufC8ImageReady() *before* 
       
  1946 // the method below returns.
       
  1947 //
       
  1948 // -----------------------------------------------------------------------------
       
  1949 //
       
  1950 void CCaeStillStatesActive::DoEncodeStillImageToJpeg()
       
  1951     {
       
  1952     LOGTEXT( _L( "Cae: CCaeStillStatesActive::DoEncodeStillImageToJpeg()" ) );
       
  1953     // Ownership will be transferred. Null the pointer already before the method
       
  1954     // call because it can call McaesdoCFbsBitmapImageReady() callback synchronously 
       
  1955     // inside the method.
       
  1956     CFbsBitmap* tmpBitmap = iBitmap;   
       
  1957 	iBitmap = NULL; 
       
  1958 	iStillEncoder->SetCompressionQuality( iStillCompressionQuality );
       
  1959 	TRAPD( error, iStillEncoder->ConvertCFbsBitmapToHBufC8L( tmpBitmap ) );
       
  1960 
       
  1961     #ifdef CAE_TEST_VERSION
       
  1962     // For simulating errors when compiled as special "test version".
       
  1963     CaeCreateAndDeliverStillImageError( error );
       
  1964     #endif
       
  1965 
       
  1966     if ( error )
       
  1967         {
       
  1968         // Handle error
       
  1969         ErrorRecovery( error );
       
  1970         }
       
  1971    }
       
  1972 
       
  1973 
       
  1974 // -----------------------------------------------------------------------------
       
  1975 // CCaeStillStatesActive::DoDeliverStillImage
       
  1976 // 
       
  1977 // Deliver the still image to the client and delete internal images after that.
       
  1978 // Note: If ownership is transferred, the image pointers should be NULLed before
       
  1979 // calling the observer method. That is because the observer method can call back
       
  1980 // CancelStill() which tries to delete images. That is no allowed as images 
       
  1981 // should be owned by the observer.
       
  1982 // -----------------------------------------------------------------------------
       
  1983 //
       
  1984 void CCaeStillStatesActive::DoDeliverStillImage()
       
  1985     {
       
  1986     LOGTEXT( _L( "Cae: CCaeStillStatesActive::DoDeliverStillImage()" ) );
       
  1987     CAE_ASSERT_ALWAYS( !iStillCancelled && ( iSnapBitmap == NULL ) );
       
  1988 
       
  1989     // Deliver the still image to the client.
       
  1990     if ( IsBitmapOutput() )
       
  1991         {
       
  1992         CFbsBitmap* tmpBitmap = iBitmap;
       
  1993         iBitmap = NULL; // ownership is transferred      
       
  1994         OstTrace0( CAMERASRV_PERFORMANCE, CCAESTILLSTATESACTIVE_DODELIVERSTILLIMAGE, "e_CAM_ENG_SHOT_TO_STILL 0" ); //CAE_ENGINE_SHOT_TO_STILL_END
       
  1995         iCaeObserver->McaeoStillImageReady( tmpBitmap, NULL, KErrNone );
       
  1996         }
       
  1997     else
       
  1998         {
       
  1999         HBufC8* tmpImageData = iImageData;   
       
  2000         iImageData = NULL; // Ownership is tranferred
       
  2001         OstTrace0( CAMERASRV_PERFORMANCE, DUP1_CCAESTILLSTATESACTIVE_DODELIVERSTILLIMAGE, "e_CAM_ENG_SHOT_TO_STILL 0" );    //CAE_ENGINE_SHOT_TO_STILL_END
       
  2002         iCaeObserver->McaeoStillImageReady( NULL, tmpImageData, KErrNone );
       
  2003         }
       
  2004  
       
  2005     // Delete all that is not NULL already. 
       
  2006     delete iImageData;
       
  2007     iImageData = NULL;
       
  2008     delete iImageHeaderData;
       
  2009     iImageHeaderData = NULL;
       
  2010     delete iBitmap;
       
  2011     iBitmap = NULL;
       
  2012 
       
  2013     Event( CCaeStillStatesActive::ECaeEventEnd ); // The end. Actuall does no issue any event. 
       
  2014     }
       
  2015 
       
  2016 
       
  2017 // -----------------------------------------------------------------------------
       
  2018 // CCaeStillStatesActive::StartQuickCapture()
       
  2019 // 
       
  2020 // -----------------------------------------------------------------------------
       
  2021 //
       
  2022 void CCaeStillStatesActive::StartQuickCapture()
       
  2023     {
       
  2024     LOGTEXT( _L( "Cae: CCaeStillStatesActive::StartQuickCapture()" ) );
       
  2025     CAE_ASSERT_DEBUG( iCurrentState == CCaeStillStatesActive::ECaeStateNone );
       
  2026     HandleStart();
       
  2027     }
       
  2028 
       
  2029 // -----------------------------------------------------------------------------
       
  2030 // CCaeStillStatesActive::ExtModeActive()
       
  2031 // 
       
  2032 // -----------------------------------------------------------------------------
       
  2033 //
       
  2034 TBool CCaeStillStatesActive::ExtModeActive()
       
  2035     {
       
  2036     LOGTEXT2( _L( "Cae: CCaeStillStatesActive::ExtModeActive() %d" ), iExtModeActive );
       
  2037     return( iExtModeActive );
       
  2038     }
       
  2039 
       
  2040 // -----------------------------------------------------------------------------
       
  2041 // CCaeStillStatesActive::SetExtModeActiveL()
       
  2042 // 
       
  2043 // -----------------------------------------------------------------------------
       
  2044 //
       
  2045 void CCaeStillStatesActive::SetExtModeActiveL( TBool aExtModeActive )
       
  2046     {
       
  2047     LOGTEXT2( _L( "Cae: CCaeStillStatesActive::SetExtModeActiveL() %d" ), aExtModeActive );
       
  2048     iExtModeActive = aExtModeActive;
       
  2049     iStillCancelled = EFalse;           // clear previous cancel request of still capture
       
  2050 
       
  2051     // Create new instance of still image queue object.
       
  2052     if ( aExtModeActive && !iImageQueueExtPro )
       
  2053         {
       
  2054         iImageQueueExtPro = CCaeImageQueueExtPro::NewL();
       
  2055         }
       
  2056     else if ( !aExtModeActive )
       
  2057         {
       
  2058         delete iImageQueueExtPro;
       
  2059         iImageQueueExtPro = 0;
       
  2060         }
       
  2061 
       
  2062     }
       
  2063 
       
  2064 // -----------------------------------------------------------------------------
       
  2065 // CCaeStillStatesActive::ProcessExtSnapImage
       
  2066 // Process extension for snap image
       
  2067 // -----------------------------------------------------------------------------
       
  2068 //
       
  2069 TInt CCaeStillStatesActive::ProcessExtSnapImage( CFbsBitmap* aSnapImage )
       
  2070     {
       
  2071     LOGTEXT( _L( "Cae: CCaeStillStatesActive::ProcessExtSnapImage()" ));
       
  2072     
       
  2073     TInt result = iImageQueueExtPro->AppendImage( aSnapImage, NULL, EFalse, ETrue );
       
  2074     if ( result == KErrNone &&                                      // image was saved ok
       
  2075         iCurrentState == CCaeStillStatesActive::ECaeStateNone &&    // state machine is idle
       
  2076         iImageQueueExtPro->ImageCount() < 2 )                       // queue was empty
       
  2077         {
       
  2078         // Send event to start processing, state machine will stop when queue is empty
       
  2079         // and return then back to ECaeStateNone state
       
  2080         Event( CCaeStillStatesActive::ECaeEventImageQueueExtPro );
       
  2081         }
       
  2082     return ( result );
       
  2083     }
       
  2084 
       
  2085 // -----------------------------------------------------------------------------
       
  2086 // CCaeStillStatesActive::ProcessExtCapturedImage
       
  2087 // Process extension for captured jpg image
       
  2088 // -----------------------------------------------------------------------------
       
  2089 //
       
  2090 TInt CCaeStillStatesActive::ProcessExtCapturedImage( HBufC8* aImageData, TBool aLastImage  )
       
  2091     {
       
  2092     LOGTEXT( _L( "Cae: CCaeStillStatesActive::ProcessExtCapturedImage() jpg" ));
       
  2093 
       
  2094     TInt result = KErrNone;
       
  2095     result = iImageQueueExtPro->AppendImage( NULL, aImageData, aLastImage, EFalse );
       
  2096 
       
  2097     if ( result == KErrNone &&                                      // image was saved ok
       
  2098         iCurrentState == CCaeStillStatesActive::ECaeStateNone &&    // state machine is idle
       
  2099         iImageQueueExtPro->ImageCount() < 2 )                       // queue was empty
       
  2100         {
       
  2101         // Send event to start processing, state machine will stop when queue is empty
       
  2102         // and return then back to ECaeStateNone state
       
  2103         Event( CCaeStillStatesActive::ECaeEventImageQueueExtPro );
       
  2104         }
       
  2105 
       
  2106     return ( result );
       
  2107     }
       
  2108 
       
  2109 // -----------------------------------------------------------------------------
       
  2110 // CCaeStillStatesActive::ProcessExtCapturedImage
       
  2111 // Process extension for captured bitmap image
       
  2112 // -----------------------------------------------------------------------------
       
  2113 //
       
  2114 TInt CCaeStillStatesActive::ProcessExtCapturedImage( CFbsBitmap* aImageBitmapData, TBool aLastImage  )
       
  2115     {
       
  2116     LOGTEXT( _L( "Cae: CCaeStillStatesActive::ProcessExtCapturedImage() bitmap" ));
       
  2117 
       
  2118     TInt result = KErrNone;
       
  2119     result = iImageQueueExtPro->AppendImage( aImageBitmapData, NULL, aLastImage, EFalse );
       
  2120 
       
  2121     if ( result == KErrNone &&                                      // image was saved ok
       
  2122         iCurrentState == CCaeStillStatesActive::ECaeStateNone &&    // state machine is idle
       
  2123         iImageQueueExtPro->ImageCount() < 2 )                       // queue was empty
       
  2124         {
       
  2125         // Send event to start processing, state machine will stop when queue is empty
       
  2126         // and return then back to ECaeStateNone state
       
  2127         Event( CCaeStillStatesActive::ECaeEventImageQueueExtPro );
       
  2128         }
       
  2129 
       
  2130     return ( result );
       
  2131     }
       
  2132 
       
  2133 // -----------------------------------------------------------------------------
       
  2134 // CCaeStillStatesActive::SetBurstModeVFOptimization()
       
  2135 // -----------------------------------------------------------------------------
       
  2136 //
       
  2137 void CCaeStillStatesActive::SetBurstModeVFOptimization(
       
  2138     TBool aBurstModeVFOptimization )
       
  2139     {
       
  2140     LOGTEXT2( _L( "Cae: CCaeStillStatesActive::SetBurstModeVFOptimization(%d)" ), aBurstModeVFOptimization);
       
  2141     iBurstModeVFOptimization = aBurstModeVFOptimization;
       
  2142     }
       
  2143 
       
  2144 // End of File