camappengine/Engine/Src/CaeEngineImpVideoRecording.cpp
changeset 15 50d5061ee01e
parent 14 34024902876b
child 17 880d946921e4
equal deleted inserted replaced
14:34024902876b 15:50d5061ee01e
     1 /*
       
     2 * Copyright (c) 2002 - 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Camera Application Engine implementation video recording methods
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <mmf/server/mmffile.h>                        // For MMF definitions (as TMMFFileConfig)
       
    22 #include <AudioPreference.h>                // For MMF audio preference definitions.
       
    23 
       
    24 
       
    25 #include "CaeEngineImp.h"                   // Engine implementation header.
       
    26 #include "CaeVideoQualityLevels.h"          // For video recording quality levels.
       
    27 #include "CaeVideoTimes.h"                  // For generating video recording time estimates.
       
    28 #include "CaeStillStatesActive.h"                
       
    29 
       
    30 #ifdef CAE_TEST_VERSION
       
    31 #include "CaeEngineImpTestErrors.h"         // For TEST_VERSION compilation only
       
    32 #endif
       
    33 
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CCaeEngineImp::InitVideoRecorderL
       
    40 // Initialise the engine for video recording using default parameters.
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 void CCaeEngineImp::InitVideoRecorderL()
       
    44     {
       
    45     LOGTEXT( _L( "Cae: CCaeEngineImp::InitVideoRecorderL() entering" ) );
       
    46 
       
    47     iVideoInitialized = EFalse;
       
    48 
       
    49     // Close video recording if previously opened/prepared.
       
    50     CloseVideoRecording();
       
    51 
       
    52     // (Re-)initialize these.
       
    53     iVideoTimesInterval = KVideoTimesIntervalDefault; 
       
    54     iMaxClipSizeInBytes = KMMFNoMaxClipSize; 
       
    55     iMaxClipSizeInBytesPrep = KMMFNoMaxClipSize;
       
    56 
       
    57     // Create video quality levels container object.
       
    58     delete iVideoQualityLevelsCont;
       
    59     iVideoQualityLevelsCont = NULL;
       
    60     iVideoQualityLevelsCont = CCaeVideoQualityLevelsCont::NewL();
       
    61 
       
    62     // Destroy possible video clip file name. (Its allocated elsewhere when file name is set.)
       
    63     delete iVideoClipFileName;
       
    64     iVideoClipFileName = NULL;
       
    65 
       
    66     // Create video recorder.
       
    67     delete iVideoRecorder;
       
    68     iVideoRecorder = NULL;
       
    69     iVideoRecorder = CVideoRecorderUtility::NewL( *this , KAudioPriorityVideoRecording,
       
    70     	TMdaPriorityPreference( KAudioPrefVideoRecording ) );
       
    71 
       
    72     delete iVideoFrameSize;
       
    73     iVideoFrameSize = NULL;
       
    74     iVideoFrameSize = new( ELeave ) TSize();
       
    75     
       
    76     delete iVideoFrameSizePrep;
       
    77     iVideoFrameSizePrep = NULL;
       
    78     iVideoFrameSizePrep = new( ELeave ) TSize();
       
    79 
       
    80     // Create video times generator object.
       
    81     delete iVideoTimes;
       
    82     iVideoTimes = NULL;
       
    83     iVideoTimes = CCaeVideoTimes::NewL();
       
    84 
       
    85     // Create call-back function for video times generation.
       
    86     delete iVideoTimesCallback;
       
    87     iVideoTimesCallback = NULL;
       
    88     iVideoTimesCallback = new( ELeave ) TCallBack( VideoRecordingTimesCallback, this );
       
    89 
       
    90     // Initialize default video recording quality levels.
       
    91     iInfo->iNumVideoQualityLevelsSupported = 
       
    92         iVideoQualityLevelsCont->InitDefaultsL();
       
    93 
       
    94     iVideoInitialized = ETrue;
       
    95 
       
    96     LOGTEXT( _L( "Cae: CCaeEngineImp::InitVideoRecorderL() returning" ) );
       
    97     }
       
    98 
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CCaeEngineImp::InitVideoRecorderL
       
   102 // Initialise the engine for video recording using either using default 
       
   103 // parameters or parameters from ini-file.
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 void CCaeEngineImp::InitVideoRecorderL( 
       
   107     TUid aSdUidVideoQltyLevels )
       
   108     {
       
   109     if( aSdUidVideoQltyLevels == KNullUid )
       
   110         {
       
   111         InitVideoRecorderL();
       
   112         }
       
   113     else
       
   114         {
       
   115         LOGTEXT( _L( "Cae: CCaeEngineImp::InitVideoRecorderL(aSdUidVideoQltyLevels): NOT SUPPORTED, leaving" ) );
       
   116         User::Leave( KErrNotSupported );
       
   117         }
       
   118     }
       
   119 
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CCaeEngineImp::SetVideoRecordingFileNameL
       
   123 // If video recording is not prepared then just memorizes the file name.
       
   124 // If video recording is prepared, then calls variated ChangeVideoFileNameL().
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CCaeEngineImp::SetVideoRecordingFileNameL( 
       
   128     const TDesC& aVideoClipFileName )
       
   129     {
       
   130     LOGTEXT( _L( "Cae: CCaeEngineImp::SetVideoRecordingFileNameL() entering" ) );
       
   131 
       
   132     if ( !iVideoInitialized || iVideoRecordingRunning ) 
       
   133         {
       
   134         LOGTEXT( _L( "Cae: CCaeEngineImp::SetVideoRecordingFileNameL leaving KErrNotReady" ));
       
   135         User::Leave( KErrNotReady );
       
   136         }
       
   137 
       
   138     if ( aVideoClipFileName.Length() > 0 )
       
   139         {
       
   140         // Memorize the video clip file name.
       
   141         delete iVideoClipFileName;
       
   142         iVideoClipFileName = NULL;
       
   143         iVideoClipFileName = aVideoClipFileName.AllocL();
       
   144         }
       
   145     else 
       
   146         {
       
   147         LOGTEXT( _L( "Cae: CCaeEngineImp::SetVideoRecordingFileNameL leaving KErrArgument (aVideoClipFileName)" ));
       
   148         User::Leave( KErrArgument );
       
   149         }
       
   150 
       
   151     if ( iVideoPrepared ) 
       
   152         {
       
   153         // Does the actual change of file name, only if video is prepared.
       
   154         // Note: Variated implementation
       
   155         ChangeVideoFileNameL();
       
   156         }
       
   157 
       
   158     LOGTEXT( _L( "Cae: CCaeEngineImp::SetVideoRecordingFileNameL() returning" ) );
       
   159     }
       
   160 
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CCaeEngineImp::PrepareVideoRecordingL
       
   164 // Retrieves video recording parameters from the specified quality level and
       
   165 // calls overloading PrepareVideoRecordingL().
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 void CCaeEngineImp::PrepareVideoRecordingL( 
       
   169     TInt aVideoQualityIndex )
       
   170     {
       
   171     LOGTEXT( _L( "Cae: CCaeEngineImp::PrepareVideoRecordingL() entering" ) );
       
   172 
       
   173     if ( ( aVideoQualityIndex < 0 ) || 
       
   174          ( aVideoQualityIndex >= iVideoQualityLevelsCont->Count() ) ) 
       
   175         {
       
   176         LOGTEXT( _L( "Cae: CCaeEngineImp::PrepareVideoRecordingL() leaving KErrArgument" ) );
       
   177         User::Leave( KErrArgument );
       
   178         }
       
   179     
       
   180     PrepareVideoRecordingL( iVideoQualityLevelsCont->At( aVideoQualityIndex ).iFrameSize, 
       
   181                             iVideoQualityLevelsCont->At( aVideoQualityIndex ).iFrameRate, 
       
   182                             iVideoQualityLevelsCont->At( aVideoQualityIndex ).iBitRate, 
       
   183                             iVideoQualityLevelsCont->At( aVideoQualityIndex ).iAudioEnabled,
       
   184                             iVideoQualityLevelsCont->At( aVideoQualityIndex ).iAudioBitRate, 
       
   185                             iVideoQualityLevelsCont->At( aVideoQualityIndex ).iMimeType, 
       
   186                             iVideoQualityLevelsCont->At( aVideoQualityIndex ).iPreferredSupplier, 
       
   187                             iVideoQualityLevelsCont->At( aVideoQualityIndex ).iVideoType,    
       
   188                             iVideoQualityLevelsCont->At( aVideoQualityIndex ).iAudioType );
       
   189     
       
   190     iVideoQualityIndex = aVideoQualityIndex;
       
   191 
       
   192     LOGTEXT( _L( "Cae: CCaeEngineImp::PrepareVideoRecordingL() returning" ) );
       
   193     }
       
   194 
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CCaeEngineImp::PrepareVideoRecordingL
       
   198 // Finds first the UIDs needed for opening a video recording, uses ECOM.
       
   199 // Then gets camera handle from Camera API.
       
   200 // Finally calls Video Recorder API OpenFileL().
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 void CCaeEngineImp::PrepareVideoRecordingL( 
       
   204     const TSize&  aFrameSize, 
       
   205     TReal32       aFrameRate, 
       
   206     TInt          aBitRate, 
       
   207     TBool         aAudioEnabled,
       
   208     const TDesC8& aMimeType, 
       
   209     const TDesC&  aPreferredSupplier, 
       
   210     const TDesC8& aVideoType, 
       
   211     const TDesC8& aAudioType )
       
   212     {
       
   213     LOGTEXT3( _L( "Cae: CCaeEngineImp::PrepareVideoRecordingL() entering aFrameSize wxh=%dx%d" ),
       
   214             aFrameSize.iWidth, aFrameSize.iHeight );
       
   215 
       
   216     // Leave if not initialized properly or busy doing something else.
       
   217     if ( !iVideoInitialized || 
       
   218          !iVideoClipFileName || 
       
   219          iStillStatesActive->IsRunning() || 
       
   220          iVideoRecordingRunning   ) 
       
   221         {
       
   222         LOGTEXT2( _L( "Cae: CCaeEngineImp::PrepareVideoRecordingL leaving KErrNotReady, iVideoInitialized=%d" ), iVideoInitialized );
       
   223         User::Leave( KErrNotReady );
       
   224         }
       
   225 
       
   226     CheckPowerL();
       
   227 
       
   228     // Leave if video clip file name is not set properly.
       
   229     if ( iVideoClipFileName->Length() == 0 )
       
   230         {
       
   231         LOGTEXT( _L( "Cae: CCaeEngineImp::PrepareVideoRecordingL() leaving KErrArgument (iVideoClipFileName)" ) );
       
   232         User::Leave( KErrArgument );
       
   233         }
       
   234 
       
   235     // Close if previously opened/prepared.
       
   236     CloseVideoRecording();
       
   237 
       
   238     // Find values for iVideoControllerUid and iVideoFormatUid.
       
   239     // Those are also needed if clip file name is changed when prepared.
       
   240     FindVideoUidsL( aMimeType, aPreferredSupplier );
       
   241 
       
   242     // Memorize video type.
       
   243     delete iVideoType;
       
   244     iVideoType = NULL;
       
   245     iVideoType = aVideoType.AllocL();
       
   246 
       
   247     // Convert audio type from TDesC8 to TFourCC.
       
   248     iVideoAudioType = ConvertAndSetVideoAudioTypeL( aAudioType );
       
   249 
       
   250     // Memorize the parameters to be prepared.
       
   251     *iVideoFrameSizePrep   = aFrameSize;
       
   252     iVideoFrameRatePrep    = aFrameRate;
       
   253     iVideoBitRatePrep      = aBitRate;
       
   254     iVideoAudioEnabledPrep = aAudioEnabled;
       
   255 
       
   256     // Open video recorder.
       
   257     iVideoOpened = ETrue; // This is always set to ETrue when 
       
   258                           // OpenFileL has been called to allow 
       
   259                           // freeing resources by CloseVideoRecording().
       
   260     iVideoRecorder->OpenFileL( iVideoClipFileName->Des(),
       
   261                                iCameraHandle,
       
   262                                iVideoControllerUid,
       
   263                                iVideoFormatUid, 
       
   264                                iVideoType->Des(),  
       
   265                                iVideoAudioType );
       
   266     
       
   267     LOGTEXT( _L( "Cae: CCaeEngineImp::PrepareVideoRecordingL() returning" ) );
       
   268     }
       
   269 
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // CCaeEngineImp::CloseVideoRecording
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 void CCaeEngineImp::CloseVideoRecording()
       
   276     {
       
   277     LOGTEXT( _L( "Cae: CCaeEngineImp::CloseVideoRecording() entering" ) );
       
   278 
       
   279     if ( iVideoPrepared ) 
       
   280         {
       
   281         CancelVideoRecording();
       
   282         iVideoPrepared = EFalse;
       
   283         }
       
   284 
       
   285     if ( iVideoOpened )
       
   286         {
       
   287         iVideoRecorder->Close();
       
   288         iVideoOpened = EFalse;
       
   289         }
       
   290 
       
   291     LOGTEXT( _L( "Cae: CCaeEngineImp::CloseVideoRecording() returning" ) );
       
   292     }
       
   293 
       
   294 
       
   295 // -----------------------------------------------------------------------------
       
   296 // CCaeEngineImp::VideoQualityIndex
       
   297 // -----------------------------------------------------------------------------
       
   298 //
       
   299 TInt CCaeEngineImp::VideoQualityIndex() const
       
   300     {
       
   301     LOGTEXT( _L( "Cae: CCaeEngineImp::VideoQualityIndex()" ) );
       
   302 
       
   303     TInt qualityIndex( -1 );
       
   304     if ( iVideoPrepared )
       
   305         {
       
   306         qualityIndex = iVideoQualityIndex;
       
   307         }
       
   308     return qualityIndex;
       
   309     }
       
   310 
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // CCaeEngineImp::GetVideoFrameSize
       
   314 // -----------------------------------------------------------------------------
       
   315 //
       
   316 void CCaeEngineImp::GetVideoFrameSize( 
       
   317     TInt aVideoQualityIndex, 
       
   318     TSize& aFrameSize ) const
       
   319     {
       
   320     LOGTEXT( _L( "Cae: CCaeEngineImp::GetVideoFrameSize()" ) );
       
   321     
       
   322     if ( aVideoQualityIndex >= 0 &&  
       
   323          aVideoQualityIndex < iVideoQualityLevelsCont->Count() )
       
   324         {
       
   325         aFrameSize = iVideoQualityLevelsCont->At( aVideoQualityIndex ).iFrameSize;
       
   326         }
       
   327     }
       
   328 
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 // CCaeEngineImp::VideoFrameRate
       
   332 // -----------------------------------------------------------------------------
       
   333 //
       
   334 TReal32 CCaeEngineImp::VideoFrameRate( 
       
   335     TInt aVideoQualityIndex ) const
       
   336     {
       
   337     LOGTEXT( _L( "Cae: CCaeEngineImp::VideoFrameRate()" ) );
       
   338 
       
   339     TReal32 frameRate( 0.0 );
       
   340     if ( aVideoQualityIndex >= 0 &&  
       
   341          aVideoQualityIndex < iVideoQualityLevelsCont->Count() )
       
   342         {
       
   343         frameRate = iVideoQualityLevelsCont->At( aVideoQualityIndex ).iFrameRate;
       
   344         }
       
   345     return frameRate;
       
   346     }
       
   347 
       
   348 
       
   349 // -----------------------------------------------------------------------------
       
   350 // CCaeEngineImp::EstimatedVideoRecordingBitRateL
       
   351 // -----------------------------------------------------------------------------
       
   352 //
       
   353 TInt CCaeEngineImp::EstimatedVideoRecordingBitRateL( 
       
   354     TInt aVideoQualityIndex ) const
       
   355     {
       
   356     LOGTEXT( _L( "Cae: CCaeEngineImp::EstimatedVideoRecordingBitRateL()" ) );
       
   357 
       
   358     TInt storageRate( 0 );
       
   359     if ( aVideoQualityIndex >= 0 &&  
       
   360          aVideoQualityIndex < iVideoQualityLevelsCont->Count() )
       
   361         {
       
   362         storageRate = iVideoQualityLevelsCont->At( aVideoQualityIndex ).iStorageRate;
       
   363         }
       
   364     return storageRate;
       
   365     }
       
   366 
       
   367 
       
   368 // -----------------------------------------------------------------------------
       
   369 // CCaeEngineImp::SetVideoClipMaxSizeL
       
   370 // If video recording is not prepared then just memorizes the clip max size.
       
   371 // If video recording is prepared, then calls Video Recorder API 
       
   372 // SetMaxClipSizeL() and Prepare().
       
   373 // -----------------------------------------------------------------------------
       
   374 //
       
   375 void CCaeEngineImp::SetVideoClipMaxSizeL( 
       
   376     TInt aMaxClipSizeInBytes )
       
   377     {
       
   378     LOGTEXT( _L( "Cae: CCaeEngineImp::SetVideoClipMaxSizeL() entering" ) );
       
   379 
       
   380     if ( !iVideoInitialized || iVideoRecordingRunning ) 
       
   381         {
       
   382         LOGTEXT2( _L( "Cae: CCaeEngineImp::SetVideoClipMaxSizeL leaving KErrNotReady, iVideoInitialized=%d" ), iVideoInitialized );
       
   383         User::Leave( KErrNotReady );
       
   384         }
       
   385 
       
   386     if ( aMaxClipSizeInBytes > 0 ) 
       
   387         {
       
   388         iMaxClipSizeInBytesPrep = aMaxClipSizeInBytes;
       
   389         }
       
   390     else 
       
   391         {
       
   392         iMaxClipSizeInBytesPrep = KMMFNoMaxClipSize;
       
   393         }
       
   394 
       
   395     if ( iVideoPrepared )
       
   396         {
       
   397         iPrepPars = ETrue;
       
   398         iVideoRecorder->SetMaxClipSizeL( iMaxClipSizeInBytesPrep );
       
   399         iVideoRecorder->Prepare();
       
   400         }
       
   401 
       
   402     LOGTEXT( _L( "Cae: CCaeEngineImp::SetVideoClipMaxSizeL() returning" ) );
       
   403     }
       
   404 
       
   405 
       
   406 // -----------------------------------------------------------------------------
       
   407 // CCaeEngineImp::VideoClipMaxSize
       
   408 // -----------------------------------------------------------------------------
       
   409 //
       
   410 TInt CCaeEngineImp::VideoClipMaxSize() const 
       
   411     {
       
   412     LOGTEXT( _L( "Cae: CCaeEngineImp::VideoClipMaxSize()" ) );
       
   413 
       
   414     TInt maxClipSizeInBytes( 0 );
       
   415     if ( iMaxClipSizeInBytes != KMMFNoMaxClipSize ) 
       
   416         {
       
   417         maxClipSizeInBytes = iMaxClipSizeInBytes;
       
   418         }
       
   419 
       
   420     return maxClipSizeInBytes;
       
   421     }
       
   422 
       
   423 
       
   424 // -----------------------------------------------------------------------------
       
   425 // CCaeEngineImp::SetVideoAudioL
       
   426 // Calls Video Recorder API SetAudioEnabledL() and Prepare().
       
   427 // -----------------------------------------------------------------------------
       
   428 //
       
   429 void CCaeEngineImp::SetVideoAudioL( 
       
   430     TBool aAudioEnabled )
       
   431     {
       
   432     LOGTEXT( _L( "Cae: CCaeEngineImp::SetVideoAudioL() entering" ) );
       
   433 
       
   434     if ( !iVideoInitialized || iVideoRecordingRunning ) 
       
   435         {
       
   436         LOGTEXT2( _L( "Cae: CCaeEngineImp::SetVideoAudioL leaving KErrNotReady, iVideoInitialized=%d" ), iVideoInitialized );
       
   437         User::Leave( KErrNotReady );
       
   438         }
       
   439 
       
   440     iVideoAudioEnabledPrep = aAudioEnabled;
       
   441     iVideoRecorder->SetAudioEnabledL( iVideoAudioEnabledPrep );
       
   442     iPrepPars = ETrue;
       
   443     iVideoRecorder->Prepare();
       
   444 
       
   445     LOGTEXT( _L( "Cae: CCaeEngineImp::SetVideoAudioL() returning" ) );
       
   446     }
       
   447 
       
   448 
       
   449 // -----------------------------------------------------------------------------
       
   450 // CCaeEngineImp::VideoAudio
       
   451 // Calls Video Recorder API AudioEnabledL().
       
   452 // -----------------------------------------------------------------------------
       
   453 //
       
   454 TBool CCaeEngineImp::VideoAudio() const
       
   455     {
       
   456     LOGTEXT( _L( "Cae: CCaeEngineImp::VideoAudio()" ) );
       
   457 
       
   458     TBool audioEnabled( EFalse );
       
   459     if ( iVideoRecorder )
       
   460         {
       
   461         TRAPD( error, { audioEnabled = iVideoRecorder->AudioEnabledL(); } );
       
   462         if ( error != KErrNone ) 
       
   463             {
       
   464             audioEnabled = EFalse;
       
   465             }
       
   466         }
       
   467     return audioEnabled;
       
   468     }
       
   469 
       
   470 
       
   471 // -----------------------------------------------------------------------------
       
   472 // CCaeEngineImp::SetVideoTimesIntervalL
       
   473 // Converts from TTimeIntervalMicroSeconds used in the interface to 
       
   474 // TTimeIntervalMicroSeconds32 used internally.
       
   475 // -----------------------------------------------------------------------------
       
   476 //
       
   477 void CCaeEngineImp::SetVideoTimesIntervalL( 
       
   478     TTimeIntervalMicroSeconds aInterval )
       
   479     {
       
   480     LOGTEXT( _L( "Cae: CCaeEngineImp::SetVideoTimesIntervalL()" ) );
       
   481 
       
   482     if ( iVideoRecordingRunning ) 
       
   483         {
       
   484         LOGTEXT2( _L( "Cae: CCaeEngineImp::SetVideoTimesIntervalL leaving KErrNotReady, iVideoRecordingRunning=%d" ), iVideoRecordingRunning );
       
   485         User::Leave( KErrNotReady );
       
   486         }
       
   487 
       
   488     // Note: KMaxTInt32 in microseconds is about 35 minutes
       
   489     if ( aInterval < TTimeIntervalMicroSeconds( 0 ) || 
       
   490          aInterval > TTimeIntervalMicroSeconds( KMaxTInt32 ) )
       
   491         {
       
   492         LOGTEXT( _L( "Cae: CCaeEngineImp::SetVideoTimesIntervalL leaving KErrArgument" ));
       
   493         User::Leave( KErrArgument );
       
   494         }
       
   495 
       
   496     iVideoTimesInterval = I64INT( aInterval.Int64() );
       
   497     }
       
   498         
       
   499 
       
   500 // -----------------------------------------------------------------------------
       
   501 // CCaeEngineImp::VideoTimesInterval
       
   502 // Converts to TTimeIntervalMicroSeconds used in the interface from  
       
   503 // TTimeIntervalMicroSeconds32 used internally.
       
   504 // -----------------------------------------------------------------------------
       
   505 //
       
   506 TTimeIntervalMicroSeconds CCaeEngineImp::VideoTimesInterval() const 
       
   507     {
       
   508     LOGTEXT( _L( "Cae: CCaeEngineImp::VideoTimesInterval()" ) );
       
   509     
       
   510     TInt64 intInterval = iVideoTimesInterval.Int();
       
   511 
       
   512     TTimeIntervalMicroSeconds interval( intInterval );
       
   513 
       
   514     return interval;
       
   515     }
       
   516 
       
   517 
       
   518 // -----------------------------------------------------------------------------
       
   519 // CCaeEngineImp::StartVideoRecording
       
   520 // Calls Video Recorder API Record().
       
   521 // Starts generating video recording time information for the client.
       
   522 // Finally calls McaeoVideoRecordingOn().
       
   523 // -----------------------------------------------------------------------------
       
   524 //
       
   525 void CCaeEngineImp::StartVideoRecording()
       
   526     {
       
   527     LOGTEXT( _L( "Cae: CCaeEngineImp::StartVideoRecording() entering" ) );
       
   528 
       
   529     TInt error( KErrNone );
       
   530 
       
   531     if ( iVideoPrepared && !iVideoRecordingRunning ) 
       
   532         {
       
   533         iVideoRecordingRunning = ETrue;
       
   534         iVideoRecordingPaused = EFalse;
       
   535         
       
   536  		// Reset previous time information
       
   537     	iPrevTimeElapsed = 0;
       
   538     	iPrevTimeRemaining = 0;
       
   539     	
       
   540        // Start video recording.
       
   541         iVideoRecorder->Record();
       
   542         if ( iVideoTimesInterval > TTimeIntervalMicroSeconds32( 0 ) ) 
       
   543             {
       
   544             // Start generating video recording time information for the client.
       
   545             iVideoTimes->Start( KVideoTimesDelay,       // delay
       
   546                                 iVideoTimesInterval,    // interval
       
   547                                 *iVideoTimesCallback ); // callback
       
   548             }
       
   549         }
       
   550     else 
       
   551         {
       
   552         error = KErrNotReady;
       
   553         }
       
   554 
       
   555 
       
   556     iCaeObserver->McaeoVideoRecordingOn( error );
       
   557 
       
   558     LOGTEXT( _L( "Cae: CCaeEngineImp::StartVideoRecording() returning" ) );
       
   559     }
       
   560 
       
   561 
       
   562 // -----------------------------------------------------------------------------
       
   563 // CCaeEngineImp::StopVideoRecording
       
   564 // Calls Video Recorder API Record(), DurationL(), and RecordTimeAvailable().
       
   565 // Stops generating video recording time information for the client.
       
   566 // Delivers video recording time info to the client once right after stopping, 
       
   567 // by calling McaeoVideoRecordingTimes().
       
   568 // Finally calls McaeoVideoRecordingComplete().
       
   569 // -----------------------------------------------------------------------------
       
   570 //
       
   571 void CCaeEngineImp::StopVideoRecording()
       
   572     {
       
   573     LOGTEXT( _L( "Cae: CCaeEngineImp::StopVideoRecording() entering" ) );
       
   574         
       
   575     TInt stoppingError( KErrNone );
       
   576     TInt asyncStopErr( KErrNone );
       
   577     
       
   578     if ( iVideoRecordingRunning ) 
       
   579         {
       
   580         TInt timesError( KErrNone );
       
   581         TTimeIntervalMicroSeconds timeElapsed( 0 );
       
   582                 
       
   583         iVideoRecordingRunning = EFalse;
       
   584         
       
   585         // Stop generating video recording time information for the client. 
       
   586         iVideoTimes->Cancel();
       
   587         
       
   588         if ( iVideoTimesInterval > TTimeIntervalMicroSeconds32( 0 ) ) 
       
   589             {
       
   590             // Query elapsed time before stop (it is set to zero after stop).
       
   591             TRAP( timesError, { timeElapsed = iVideoRecorder->DurationL(); } );
       
   592             // Possible error is ignored locally because not so crucial. Error code is delivered by call-back.
       
   593             }
       
   594                     
       
   595         // Stop video recording.
       
   596         if ( iAsyncVideoStopEnabled )
       
   597             {
       
   598        		LOGTEXT( _L( "Cae: CCaeEngineImp::StopVideoRecording(). using custom command ECamCControllerCCVideoStopAsync" )); 
       
   599             asyncStopErr = iVideoRecorder->CustomCommandSync( TMMFMessageDestination( iVideoControllerUid, KMMFObjectHandleController ), 
       
   600                                                         ECamCControllerCCVideoStopAsync, 
       
   601                                                         KNullDesC8, 
       
   602                                                         KNullDesC8 );
       
   603        		if ( asyncStopErr ) // async stop was not supported, use sync stop
       
   604        		    {
       
   605            		LOGTEXT2( _L( "Cae: CCaeEngineImp::StopVideoRecording(). async stop err=%d, using sync stop" ), asyncStopErr); 
       
   606                 stoppingError = iVideoRecorder->Stop();
       
   607                 iCaeObserver->McaeoVideoRecordingStopped();
       
   608        		    }
       
   609             }
       
   610         else
       
   611             {
       
   612             // Synchronous, quaranteed that video recording is stopped when returning.
       
   613             stoppingError = iVideoRecorder->Stop();
       
   614             }
       
   615         
       
   616         // Can't be paused anymore.
       
   617         iVideoRecordingPaused = EFalse;
       
   618 
       
   619         /*
       
   620         #ifdef CAE_TEST_VERSION
       
   621         // For simulating errors when compiled as special "test version".
       
   622         CaeStopVideoRecordingError( stoppingError );
       
   623         #endif
       
   624         */
       
   625         
       
   626         if ( iVideoTimesInterval > TTimeIntervalMicroSeconds32( 0 ) ) 
       
   627             {    
       
   628             // Query remaining time after stop.
       
   629             TTimeIntervalMicroSeconds timeRemaining = iVideoRecorder->RecordTimeAvailable();
       
   630             
       
   631         	// The elapsed time could have been reseted to zero by the video recorder 
       
   632         	// if there is stopping ongoing in video recorder, even if we do 
       
   633         	// not have had the notification yet. In that case McaeoVideoRecordingTimes
       
   634         	// should be called with previous valid values.
       
   635         	if ( ( timeElapsed == 0 ) && ( iPrevTimeElapsed != 0 ) )
       
   636         		{
       
   637         		// Invalid time. Use previous time information
       
   638        			LOGTEXT2( _L( "Cae: CCaeEngineImp::StopVideoRecording(). Got invalid elapsed time from the video recorder: %f s." ), 
       
   639        				I64LOW( timeElapsed.Int64() ) * 1.0 / KOneSecond);
       
   640        			LOGTEXT3( _L( "Cae: CCaeEngineImp::StopVideoRecording(). Use previous valid elapsed time %f s. and remaining time %f s." ), 
       
   641        				I64LOW( iPrevTimeElapsed.Int64() ) * 1.0 / KOneSecond,  
       
   642        				I64LOW( iPrevTimeRemaining.Int64() ) * 1.0 / KOneSecond );
       
   643         		timeElapsed = iPrevTimeElapsed;
       
   644         		timeRemaining =iPrevTimeRemaining;
       
   645         		}
       
   646        
       
   647             // Deliver video times (elapsed, remaining) information.
       
   648             iCaeObserver->McaeoVideoRecordingTimes( timeElapsed, timeRemaining, timesError );
       
   649             }
       
   650         }
       
   651     else 
       
   652         {
       
   653         stoppingError = KErrNotReady;
       
   654         }
       
   655 
       
   656 	// Reset previous time information
       
   657     iPrevTimeElapsed = 0;
       
   658     iPrevTimeRemaining = 0;
       
   659 
       
   660     if ( !iAsyncVideoStopEnabled || asyncStopErr )
       
   661         {
       
   662         iCaeObserver->McaeoVideoRecordingComplete( stoppingError );
       
   663         }
       
   664 
       
   665 
       
   666     LOGTEXT( _L( "Cae: CCaeEngineImp::StopVideoRecording() returning" ) );
       
   667     }
       
   668 
       
   669 
       
   670 // -----------------------------------------------------------------------------
       
   671 // CCaeEngineImp::PauseVideoRecording
       
   672 // Stops generating video recording time info for the client.
       
   673 // Calls Video Recorder API PauseL().
       
   674 // Delivers video recording time info to the client once right after pausing
       
   675 // by calling VideoRecordingTimesCallback() that calls Video Recorder API 
       
   676 // DurationL() and RecordTimeAvailable(), and then McaeoVideoRecordingTimes().
       
   677 // Finally calls McaeoVideoRecordingPaused().
       
   678 // -----------------------------------------------------------------------------
       
   679 //
       
   680 void CCaeEngineImp::PauseVideoRecording()
       
   681     {
       
   682     LOGTEXT( _L( "Cae: CCaeEngineImp::PauseVideoRecording() entering" ) );
       
   683 
       
   684     TInt error( KErrNone );
       
   685 
       
   686     if ( iVideoRecordingRunning && !iVideoRecordingPaused ) 
       
   687         {
       
   688         // Stop generating video recording time info for the client.
       
   689         iVideoTimes->Cancel();
       
   690         // Pause video recording.
       
   691         TRAP( error, iVideoRecorder->PauseL() );
       
   692         if ( iVideoTimesInterval > TTimeIntervalMicroSeconds32( 0 ) ) 
       
   693             {
       
   694             // Deliver video recording times (elapsed, remaining) info once.
       
   695             VideoRecordingTimesCallback( this );
       
   696             }
       
   697         // Intentionally setting iVideoRecordingPaused after (possibly) calling VideoRecordingTimesCallback().
       
   698         if ( error == KErrNone ) 
       
   699             {
       
   700             iVideoRecordingPaused = ETrue;
       
   701             }
       
   702         }
       
   703     else 
       
   704         {
       
   705         error = KErrNotReady;
       
   706         }
       
   707 
       
   708     iCaeObserver->McaeoVideoRecordingPaused( error );
       
   709 
       
   710     LOGTEXT( _L( "Cae: CCaeEngineImp::PauseVideoRecording() returning" ) );
       
   711     }
       
   712 
       
   713 
       
   714 // -----------------------------------------------------------------------------
       
   715 // CCaeEngineImp::ResumeVideoRecording
       
   716 // Calls Video Recorder API Record().
       
   717 // Starts generating video recording time information for the client.
       
   718 // Finally calls McaeoVideoRecordingOn().
       
   719 // -----------------------------------------------------------------------------
       
   720 //
       
   721 void CCaeEngineImp::ResumeVideoRecording()
       
   722     {
       
   723     LOGTEXT( _L( "Cae: CCaeEngineImp::ResumeVideoRecording() entering" ) );
       
   724 
       
   725     TInt error( KErrNone );
       
   726 
       
   727     if ( iVideoRecordingRunning && iVideoRecordingPaused ) 
       
   728         {
       
   729         // Start video recording.
       
   730         iVideoRecorder->Record();
       
   731         iVideoRecordingPaused = EFalse;
       
   732         if ( iVideoTimesInterval > TTimeIntervalMicroSeconds32( 0 ) ) 
       
   733             {
       
   734             // Start generating video recording time information for the client.
       
   735             iVideoTimes->Start( KVideoTimesDelay,       // delay
       
   736                                 iVideoTimesInterval,    // interval
       
   737                                 *iVideoTimesCallback ); // callback
       
   738             }
       
   739         }
       
   740     else 
       
   741         {
       
   742         error = KErrNotReady;
       
   743         }
       
   744 
       
   745     iCaeObserver->McaeoVideoRecordingOn( error );
       
   746 
       
   747     LOGTEXT( _L( "Cae: CCaeEngineImp::ResumeVideoRecording() returning" ) );
       
   748     }
       
   749 
       
   750 
       
   751 // -----------------------------------------------------------------------------
       
   752 // CCaeEngineImp::RemainingVideoRecordingTime
       
   753 // Calls Video Recorder API RecordTimeAvailable().
       
   754 // -----------------------------------------------------------------------------
       
   755 //
       
   756 TTimeIntervalMicroSeconds CCaeEngineImp::RemainingVideoRecordingTime() const
       
   757     {
       
   758     LOGTEXT( _L( "Cae: CCaeEngineImp::RemainingVideoRecordingTime()" ) );
       
   759     
       
   760     TTimeIntervalMicroSeconds remaining( 0 );
       
   761     if ( iVideoRecorder )
       
   762         {
       
   763         remaining = iVideoRecorder->RecordTimeAvailable();
       
   764         }
       
   765     return remaining;
       
   766     }
       
   767 
       
   768 
       
   769 // -----------------------------------------------------------------------------
       
   770 // CCaeEngineImp::IsVideoRecording
       
   771 // -----------------------------------------------------------------------------
       
   772 //
       
   773 TBool CCaeEngineImp::IsVideoRecording() const
       
   774     {
       
   775     return iVideoRecordingRunning;    
       
   776     }
       
   777 
       
   778 
       
   779 // -----------------------------------------------------------------------------
       
   780 // CCaeEngineImp::PrepareVideoRecordingL
       
   781 // Overloading version with audio bit rate argument.
       
   782 // -----------------------------------------------------------------------------
       
   783 //
       
   784 void CCaeEngineImp::PrepareVideoRecordingL( 
       
   785     const TSize&  aFrameSize, 
       
   786     TReal32       aFrameRate, 
       
   787     TInt          aBitRate, 
       
   788     TBool         aAudioEnabled,
       
   789     TInt          aAudioBitRate, 
       
   790     const TDesC8& aMimeType, 
       
   791     const TDesC&  aPreferredSupplier, 
       
   792     const TDesC8& aVideoType, 
       
   793     const TDesC8& aAudioType )
       
   794     {
       
   795     // Memorize video audio bit rate value to be prepared.
       
   796     iVideoAudioBitRatePrep = aAudioBitRate;
       
   797     // Force audio bit rate preparation.
       
   798     iPrepareVideoAudioBitRate = ETrue;
       
   799 
       
   800     // Call the version without audio bit rate argument.
       
   801     // This is possible because the separate PrepareVideoSettingsL() is doing
       
   802     // settings after succesfull opening of video recording.
       
   803     PrepareVideoRecordingL( aFrameSize, 
       
   804                             aFrameRate, 
       
   805                             aBitRate, 
       
   806                             aAudioEnabled, 
       
   807                             aMimeType, 
       
   808                             aPreferredSupplier, 
       
   809                             aVideoType, 
       
   810                             aAudioType );
       
   811     }
       
   812 
       
   813 
       
   814 // -----------------------------------------------------------------------------
       
   815 // CCaeEngineImp::MvruoOpenComplete
       
   816 // The status of the video recorder after initialisation.
       
   817 // This is either KErrNone if the open has completed successfully,
       
   818 // or one of the system wide error codes
       
   819 // -----------------------------------------------------------------------------
       
   820 //
       
   821 void CCaeEngineImp::MvruoOpenComplete( 
       
   822     TInt aError )
       
   823     {
       
   824     LOGTEXT2( _L( "Cae: CCaeEngineImp::MvruoOpenComplete() entering, aError=%d" ), aError );
       
   825 
       
   826     #ifdef CAE_TEST_VERSION
       
   827     // For simulating errors when compiled as special "test version".
       
   828     CaeMvruoOpenCompleteError( aError );
       
   829     #endif    
       
   830 
       
   831     if ( aError == KErrNone )
       
   832         {
       
   833         // To get default video audio bit rate.
       
   834         TRAP( aError, { iVideoAudioBitRate = iVideoRecorder->AudioBitRateL(); } );
       
   835         // (ignore possible error)
       
   836         // Prepare settings only if no errors in opening.
       
   837         TRAP( aError, PrepareVideoSettingsL() );
       
   838         if ( aError != KErrNone ) 
       
   839             {
       
   840             iCaeObserver->McaeoVideoPrepareComplete( aError );
       
   841             }
       
   842         }
       
   843     else
       
   844         {
       
   845         iCaeObserver->McaeoVideoPrepareComplete( aError );
       
   846         }
       
   847 
       
   848     LOGTEXT( _L( "Cae: CCaeEngineImp::MvruoOpenComplete() returning" ) );
       
   849     }
       
   850 
       
   851 
       
   852 // -----------------------------------------------------------------------------
       
   853 // CCaeEngineImp::MvruoPrepareComplete
       
   854 // Notification that video recorder is ready to begin recording. This callback
       
   855 // is generated in response to a call to VR's Prepare.
       
   856 // -----------------------------------------------------------------------------
       
   857 //
       
   858 void CCaeEngineImp::MvruoPrepareComplete( 
       
   859     TInt aError )
       
   860     {
       
   861     LOGTEXT2( _L( "Cae: CCaeEngineImp::MvruoPrepareComplete() entering, aError=%d" ), aError );
       
   862 
       
   863     #ifdef CAE_TEST_VERSION
       
   864     // For simulating errors when compiled as special "test version".
       
   865     CaeMvruoPrepareCompleteError( aError );
       
   866     #endif    
       
   867 
       
   868     if ( iVideoOpened && ( aError == KErrNone ) )
       
   869         {
       
   870         iVideoPrepared = ETrue; // Later errors with settings after 
       
   871                                 // do not change the value.
       
   872         }
       
   873 
       
   874     if ( iPrepPars )
       
   875         {
       
   876         iPrepPars = EFalse;
       
   877         // If no error, then fresh parameters are valid.
       
   878         // Otherwise, old parameters are kept.
       
   879         if ( aError == KErrNone )
       
   880             {
       
   881             *iVideoFrameSize    = *iVideoFrameSizePrep;
       
   882             iVideoFrameRate     = iVideoFrameRatePrep;
       
   883             iVideoBitRate       = iVideoBitRatePrep;
       
   884             iVideoAudioEnabled  = iVideoAudioEnabledPrep;
       
   885             iVideoAudioBitRate  = iVideoAudioBitRatePrep;
       
   886             iMaxClipSizeInBytes = iMaxClipSizeInBytesPrep;
       
   887             }
       
   888         else 
       
   889             {
       
   890             *iVideoFrameSizePrep    = *iVideoFrameSize;
       
   891             iVideoFrameRatePrep     = iVideoFrameRate;
       
   892             iVideoBitRatePrep       = iVideoBitRate;
       
   893             iVideoAudioEnabledPrep  = iVideoAudioEnabled;
       
   894             iVideoAudioBitRatePrep  = iVideoAudioBitRate;
       
   895             iMaxClipSizeInBytesPrep = iMaxClipSizeInBytes;
       
   896             }
       
   897         }
       
   898 
       
   899     iCaeObserver->McaeoVideoPrepareComplete( aError );
       
   900 
       
   901     LOGTEXT( _L( "Cae: CCaeEngineImp::MvruoPrepareComplete() returning" ) );
       
   902     }
       
   903 
       
   904 
       
   905 // -----------------------------------------------------------------------------
       
   906 // CCaeEngineImp::MvruoRecordComplete
       
   907 // Notification that video recording has completed. This is not called if 
       
   908 // recording is explicitly stopped by calling Stop.
       
   909 // -----------------------------------------------------------------------------
       
   910 //
       
   911 void CCaeEngineImp::MvruoRecordComplete( 
       
   912     TInt aError )
       
   913     {
       
   914     LOGTEXT3( _L( "Cae: CCaeEngineImp::MvruoRecordComplete() entering, aError=%d, iVideoRecordingRunning=%d" ), aError, iVideoRecordingRunning );
       
   915     
       
   916     // Stop generating video recording time information for the client. 
       
   917     iVideoTimes->Cancel();
       
   918     // Recording stopped: can't be paused anymore.
       
   919     iVideoRecordingPaused = EFalse; 
       
   920         
       
   921  	// Reset previous time information
       
   922     iPrevTimeElapsed = 0;
       
   923     iPrevTimeRemaining = 0;
       
   924     	
       
   925     if ( iVideoRecordingRunning || iAsyncVideoStopEnabled ) // To ensure that McaeoVideoRecordingComplete 
       
   926         {                                                   // gets called just once per recording.
       
   927         iVideoRecordingRunning = EFalse;
       
   928         
       
   929         #ifdef CAE_TEST_VERSION
       
   930         // For simulating errors when compiled as special "test version".
       
   931         CaeMvruoRecordCompleteError( aError );
       
   932         #endif
       
   933         
       
   934         // Close video recording always in error case. Otherwise the camcorder plugin would
       
   935         // be in indeterminated state. 
       
   936         // The code KErrCompletion means that video reocording has been completed by timer
       
   937         if ( aError && aError != KErrCompletion && aError != KErrDiskFull ) 
       
   938         	{ 
       
   939         	CloseVideoRecording();
       
   940         	}
       
   941         	
       
   942         // In async stop mode call also the other call-back to play stop sound
       
   943         if ( iAsyncVideoStopEnabled )
       
   944             {
       
   945             iCaeObserver->McaeoVideoRecordingStopped();
       
   946             }
       
   947         iCaeObserver->McaeoVideoRecordingComplete( aError );
       
   948         }
       
   949     
       
   950     LOGTEXT( _L( "Cae: CCaeEngineImp::MvruoRecordComplete() returning" ) );
       
   951     }
       
   952 
       
   953 
       
   954 // -----------------------------------------------------------------------------
       
   955 // CCaeEngineImp::MvruoEvent
       
   956 // Event Notification from controller 
       
   957 // -----------------------------------------------------------------------------
       
   958 //
       
   959 
       
   960 void CCaeEngineImp::MvruoEvent( 
       
   961     const TMMFEvent& aEvent )
       
   962     {
       
   963     LOGTEXT3( _L( "Cae: CCaeEngineImp::MvruoEvent() entering, uid=%x, err=%d" ), aEvent.iEventType.iUid, aEvent.iErrorCode );
       
   964     
       
   965     if ( aEvent.iEventType.iUid == KCamCControllerCCVideoRecordStopped.iUid )
       
   966         {
       
   967         iCaeObserver->McaeoVideoRecordingStopped();
       
   968         }
       
   969     else if ( aEvent.iEventType.iUid == KCamCControllerCCVideoFileComposed.iUid )
       
   970         {
       
   971         iCaeObserver->McaeoVideoRecordingComplete( aEvent.iErrorCode );
       
   972         }
       
   973     else
       
   974         {
       
   975         // Send others events as error to UI 
       
   976         iVideoPrepared = EFalse;    // mark that re-preparation is needed 
       
   977         iCaeObserver->McaeoVideoPrepareComplete( aEvent.iErrorCode );
       
   978         }
       
   979     
       
   980     LOGTEXT( _L( "Cae: CCaeEngineImp::MvruoEvent() returning" ) );
       
   981     }
       
   982 
       
   983 
       
   984 
       
   985 // -----------------------------------------------------------------------------
       
   986 // CCaeEngineImp::CancelVideoRecording
       
   987 // Calls Video Recorder API Stop().
       
   988 // -----------------------------------------------------------------------------
       
   989 //
       
   990 void CCaeEngineImp::CancelVideoRecording()
       
   991     {
       
   992     LOGTEXT( _L( "Cae: CCaeEngineImp::CancelVideoRecording() entering" ) );
       
   993     
       
   994     if ( iVideoRecordingRunning ) 
       
   995         {
       
   996         // This also prevents McaeoVideoRecordingComplete() call from MvruoRecordComplete()  
       
   997         // and McaeoVideoRecordingTimes() call from VideoRecordingTimesCallback().
       
   998         iVideoRecordingRunning = EFalse;
       
   999         // Stop generating video recording time information for the client. 
       
  1000         iVideoTimes->Cancel();
       
  1001         
       
  1002  		// Reset previous time information
       
  1003     	iPrevTimeElapsed = 0;
       
  1004     	iPrevTimeRemaining = 0;
       
  1005     	
       
  1006         // Stop video recording. Do not call McaeoVideoRecordingComplete()
       
  1007         (void) iVideoRecorder->Stop();
       
  1008         iVideoRecordingPaused = EFalse;
       
  1009         }
       
  1010     
       
  1011     LOGTEXT( _L( "Cae: CCaeEngineImp::CancelVideoRecording() returning" ) );
       
  1012     }
       
  1013 
       
  1014 
       
  1015 // -----------------------------------------------------------------------------
       
  1016 // CCaeEngineImp::PrepareVideoSettingsL
       
  1017 // Calls Video Recorder API setting methods to set video recording paramaters.
       
  1018 // -----------------------------------------------------------------------------
       
  1019 //
       
  1020 void CCaeEngineImp::PrepareVideoSettingsL()
       
  1021     {
       
  1022     LOGTEXT( _L( "Cae: CCaeEngineImp::PrepareVideoSettingsL() entering" ) );
       
  1023 
       
  1024     #ifdef CAE_TEST_VERSION
       
  1025     // For simulating errors when compiled as special "test version".
       
  1026     CaePrepareVideoSettingsErrorL();
       
  1027     #endif    
       
  1028 
       
  1029     iVideoRecorder->SetVideoFrameSizeL( *iVideoFrameSizePrep );
       
  1030     iVideoRecorder->SetVideoFrameRateL( iVideoFrameRatePrep );
       
  1031     iVideoRecorder->SetVideoBitRateL( iVideoBitRatePrep );
       
  1032     iVideoRecorder->SetAudioEnabledL( iVideoAudioEnabledPrep );
       
  1033     if ( iPrepareVideoAudioBitRate )
       
  1034         {
       
  1035         iVideoRecorder->SetAudioBitRateL( iVideoAudioBitRatePrep );
       
  1036         iPrepareVideoAudioBitRate = EFalse;
       
  1037         }
       
  1038     iVideoRecorder->SetMaxClipSizeL( iMaxClipSizeInBytesPrep );
       
  1039 
       
  1040     // Set the recording gain to the maximum
       
  1041     TInt gain = iVideoRecorder->GainL();
       
  1042     LOGTEXT2( _L( "Cae: CCaeEngineImp::PrepareVideoSettingsL() GainL was %d" ), gain );
       
  1043     gain = iVideoRecorder->MaxGainL();
       
  1044     LOGTEXT2( _L( "Cae: CCaeEngineImp::PrepareVideoSettingsL() MaxGainL is %d" ), gain );
       
  1045     iVideoRecorder->SetGainL( gain );
       
  1046     gain = iVideoRecorder->GainL();
       
  1047     LOGTEXT2( _L( "Cae: CCaeEngineImp::PrepareVideoSettingsL() GainL set to %d" ), gain );
       
  1048 
       
  1049     iPrepPars = ETrue;
       
  1050     iVideoRecorder->Prepare();
       
  1051 
       
  1052     LOGTEXT( _L( "Cae: CCaeEngineImp::PrepareVideoSettingsL() returning" ) );
       
  1053     }
       
  1054 
       
  1055 
       
  1056 // -----------------------------------------------------------------------------
       
  1057 // CCaeEngineImp::FindVideoUidsL
       
  1058 // Finds UIDs for opening video recording. Uses ECOM.
       
  1059 // -----------------------------------------------------------------------------
       
  1060 //
       
  1061 void CCaeEngineImp::FindVideoUidsL(
       
  1062     const TDesC8& aMimeType, 
       
  1063     const TDesC&  aPreferredSupplier )
       
  1064     {
       
  1065     LOGTEXT( _L( "Cae: CCaeEngineImp::FindVideoUidsL() entering" ) );
       
  1066 
       
  1067     iVideoControllerUid.iUid = 0;
       
  1068     iVideoFormatUid.iUid = 0; 
       
  1069 
       
  1070     // Retrieve a list of possible controllers from ECOM.
       
  1071     //
       
  1072     // Controller must support recording the requested mime type.
       
  1073     // Controller must be provided by preferred supplier.
       
  1074 
       
  1075     CMMFControllerPluginSelectionParameters* cSelect = 
       
  1076         CMMFControllerPluginSelectionParameters::NewLC();
       
  1077     CMMFFormatSelectionParameters* fSelect = 
       
  1078         CMMFFormatSelectionParameters::NewLC();
       
  1079 
       
  1080     fSelect->SetMatchToMimeTypeL( aMimeType );
       
  1081     cSelect->SetRequiredRecordFormatSupportL( *fSelect );
       
  1082     cSelect->SetPreferredSupplierL( aPreferredSupplier,
       
  1083        CMMFPluginSelectionParameters::EOnlyPreferredSupplierPluginsReturned );
       
  1084 
       
  1085     RMMFControllerImplInfoArray controllers;
       
  1086     CleanupResetAndDestroyPushL( controllers );
       
  1087     cSelect->ListImplementationsL( controllers );
       
  1088 
       
  1089     if ( controllers.Count() < 1 )
       
  1090         {
       
  1091         // No appropriate controllers found.
       
  1092         LOGTEXT( _L( "Cae: CCaeEngineImp::FindVideoUidsL() leaving KErrNotSupported (no controllers found)" ) );
       
  1093         User::Leave( KErrNotSupported );
       
  1094         }
       
  1095 
       
  1096     // Get the controller UID.
       
  1097     iVideoControllerUid = controllers[0]->Uid();
       
  1098 
       
  1099     // Inquires the controller about supported formats.
       
  1100     // We use the first controller found having index 0.
       
  1101     RMMFFormatImplInfoArray formats;
       
  1102     formats = controllers[0]->RecordFormats();
       
  1103 
       
  1104     // Get the first format that supports our mime type.
       
  1105     
       
  1106     TBool found( EFalse );
       
  1107 
       
  1108     for ( TInt i = 0; i < formats.Count(); i++ )
       
  1109         {
       
  1110         if ( formats[i]->SupportsMimeType( aMimeType ) )
       
  1111             {
       
  1112             iVideoFormatUid = formats[i]->Uid(); // set the UID
       
  1113             found = ETrue;
       
  1114             break;
       
  1115             }
       
  1116         }
       
  1117     if ( !found )
       
  1118         {
       
  1119         // No appropriate video format found.
       
  1120         LOGTEXT( _L( "Cae: CCaeEngineImp::FindVideoUidsL() leaving KErrNotSupported (no video format found)" ) );
       
  1121         User::Leave( KErrNotSupported );
       
  1122         }
       
  1123 
       
  1124     CleanupStack::PopAndDestroy( 3, cSelect ); // cselect, fselect, controllers
       
  1125 
       
  1126     LOGTEXT( _L( "Cae: CCaeEngineImp::FindVideoUidsL() returning" ) );
       
  1127     }
       
  1128 
       
  1129 
       
  1130 // -----------------------------------------------------------------------------
       
  1131 // CCaeEngineImp::ConvertAndSetVideoAudioTypeL
       
  1132 // Convert audio type from TDesC8 to TFourCC, set to iVideoAudioType.
       
  1133 // -----------------------------------------------------------------------------
       
  1134 //
       
  1135 TFourCC CCaeEngineImp::ConvertAndSetVideoAudioTypeL(
       
  1136     const TDesC8& aAudioType )
       
  1137     {
       
  1138     if ( aAudioType == KNullDesC8 )
       
  1139         {
       
  1140         return KMMFFourCCCodeNULL;
       
  1141         }
       
  1142     else
       
  1143         {
       
  1144         if ( aAudioType.Length() != 4 ) 
       
  1145             {
       
  1146             User::Leave( KErrArgument );
       
  1147             }
       
  1148         return TFourCC( aAudioType[0], aAudioType[1], aAudioType[2], aAudioType[3] );
       
  1149         }
       
  1150     }
       
  1151 
       
  1152 
       
  1153 // -----------------------------------------------------------------------------
       
  1154 // CCaeEngineImp::VideoRecordingTimesCallback
       
  1155 // Calls Video Recorder API DurationL() and RecordTimeAvailable().
       
  1156 // Finally calls McaeoVideoRecordingTimes().
       
  1157 // -----------------------------------------------------------------------------
       
  1158 //
       
  1159 TInt CCaeEngineImp::VideoRecordingTimesCallback( 
       
  1160     TAny* aEngineImp )
       
  1161     {
       
  1162     LOGTEXT( _L( "Cae: CCaeEngineImp::VideoRecordingTimesCallback() entering" ) );
       
  1163 
       
  1164     CCaeEngineImp* thisEngineImp = static_cast<CCaeEngineImp*>( aEngineImp );
       
  1165 
       
  1166     if ( thisEngineImp->iVideoRecordingRunning && !thisEngineImp->iVideoRecordingPaused )
       
  1167         {
       
  1168         // Query elapsed recording time.
       
  1169         TTimeIntervalMicroSeconds timeElapsed( 0 );
       
  1170         TRAPD( error, { timeElapsed = thisEngineImp->iVideoRecorder->DurationL(); } );
       
  1171         
       
  1172         // Query remaining recording time.
       
  1173         TTimeIntervalMicroSeconds timeRemaining = thisEngineImp->iVideoRecorder->RecordTimeAvailable();
       
  1174         	
       
  1175         // The elapsed time could have been reseted to zero by the video recorder 
       
  1176         // if there is stopping ongoing in video recorder, even if we do 
       
  1177         // not have had the notification yet. In that case McaeoVideoRecordingTimes
       
  1178         // should be called with previous valid values.
       
  1179         if ( ( timeElapsed == 0 ) && ( thisEngineImp->iPrevTimeElapsed != 0 ) )
       
  1180         	{
       
  1181         	// Invalid time. Use previous time information
       
  1182    			LOGTEXT2( _L( "Cae: CCaeEngineImp::VideoRecordingTimesCallback(). Got invalid elapsed time from the video recorder: %f s." ), 
       
  1183    				I64LOW( timeElapsed.Int64() ) * 1.0 / KOneSecond);
       
  1184    			LOGTEXT3( _L( "Cae: CCaeEngineImp::VideoRecordingTimesCallback(). Use previous valid elapsed time %f s. and remaining time %f s." ), 
       
  1185    				I64LOW( thisEngineImp->iPrevTimeElapsed.Int64() ) * 1.0 / KOneSecond,  
       
  1186    				I64LOW( thisEngineImp->iPrevTimeRemaining.Int64() ) * 1.0 / KOneSecond );
       
  1187         	timeElapsed = thisEngineImp->iPrevTimeElapsed;
       
  1188         	timeRemaining = thisEngineImp->iPrevTimeRemaining;
       
  1189         	}
       
  1190         else
       
  1191          	{
       
  1192          	// Store current time information
       
  1193         	thisEngineImp->iPrevTimeElapsed = timeElapsed;
       
  1194         	thisEngineImp->iPrevTimeRemaining = timeRemaining;
       
  1195         	}
       
  1196        
       
  1197        	// Deliver video recording times information.
       
  1198        	thisEngineImp->iCaeObserver->McaeoVideoRecordingTimes( timeElapsed, timeRemaining, error );
       
  1199         }
       
  1200 
       
  1201     LOGTEXT( _L( "Cae: CCaeEngineImp::VideoRecordingTimesCallback() returning" ) );
       
  1202 
       
  1203     return ETrue;
       
  1204     }
       
  1205 
       
  1206 // ---------------------------------------------------------
       
  1207 // CCaeEngineImp::EnumerateVideoFrameSizeL
       
  1208 // Checks that camera HW supports given framesize
       
  1209 // ---------------------------------------------------------
       
  1210 //
       
  1211 TInt CCaeEngineImp::EnumerateVideoFrameSizeL(const TSize& aSize)
       
  1212     {
       
  1213 
       
  1214     LOGTEXT3( _L("Cae: CCaeEngineImp::EnumerateVideoFrameSizeL(), In, size: %dx%d"), aSize.iWidth, aSize.iHeight );
       
  1215 
       
  1216     TCameraInfo cameraInfo;
       
  1217     iCamera->CameraInfo( cameraInfo );
       
  1218     
       
  1219     TSize size;
       
  1220     TInt i = 0;
       
  1221     TInt j = 0;
       
  1222     TInt sizeIndex = -1;
       
  1223 
       
  1224     if ( cameraInfo.iVideoFrameFormatsSupported & CCamera::EFormatYUV420Planar )
       
  1225         {
       
  1226         // check YUV420 planar
       
  1227         for ( i = 0; i < cameraInfo.iNumVideoFrameSizesSupported; i++ )
       
  1228             {
       
  1229             iCamera->EnumerateVideoFrameSizes(size, i, CCamera::EFormatYUV420Planar);
       
  1230 			LOGTEXT3(_L("Cae: CCaeEngineImp::EnumerateVideoFrameSizeL() Camera EFormatYUV420Planar %d x %d found from camera"), size.iWidth, size.iHeight ); 
       
  1231         
       
  1232             if ( size == aSize )
       
  1233                 {
       
  1234 				LOGTEXT3(_L("Cae: CCaeEngineImp::EnumerateVideoFrameSizeL() Camera EFormatYUV420Planar %d x %d Matched."), size.iWidth, size.iHeight ); 
       
  1235                 sizeIndex = i;
       
  1236                 break;
       
  1237                 }
       
  1238             }
       
  1239         }
       
  1240     else
       
  1241     	{
       
  1242 		LOGTEXT(_L("Cae: CCaeEngineImp::EnumerateVideoFrameSizeL() Camera doesn't support EFormatYUV420Planar"));
       
  1243     	}
       
  1244 
       
  1245     if ( cameraInfo.iVideoFrameFormatsSupported & CCamera::EFormatYUV422 )
       
  1246         {
       
  1247         // check YUV422 interleaved
       
  1248         for ( j = 0; j < cameraInfo.iNumVideoFrameSizesSupported; j++ )
       
  1249             {
       
  1250             iCamera->EnumerateVideoFrameSizes(size, j, CCamera::EFormatYUV422 );
       
  1251 			LOGTEXT3(_L("Cae: CCaeEngineImp::EnumerateVideoFrameSizeL() Camera EFormatYUV422 %d x %d found from camera"), size.iWidth, size.iHeight );
       
  1252         
       
  1253             if ( size == aSize )
       
  1254                 {
       
  1255                 LOGTEXT3(_L("Cae: CCaeEngineImp::EnumerateVideoFrameSizeL() Camera EFormatYUV422 %d x %d Matched."), size.iWidth, size.iHeight );
       
  1256                 sizeIndex = j;
       
  1257                 break;
       
  1258                 }
       
  1259             }
       
  1260         }
       
  1261     else
       
  1262     	{
       
  1263 		LOGTEXT(_L("Cae: CCaeEngineImp::EnumerateVideoFrameSizeL() Camera doesn't support EFormatYUV422"));	
       
  1264     	}
       
  1265 
       
  1266     if ( sizeIndex == -1 )
       
  1267         {
       
  1268         LOGTEXT(_L("Cae: CCaeEngineImp::EnumerateVideoFrameSizeL(), Camera does not support this resolution"));
       
  1269         }
       
  1270 
       
  1271 
       
  1272     LOGTEXT(_L("Cae: CCaeEngineImp::EnumerateVideoFrameSizeL(), Out"));
       
  1273     return ( sizeIndex );
       
  1274     }
       
  1275 
       
  1276 // ---------------------------------------------------------
       
  1277 // CCaeEngineImp::SetAsyncVideoStopMode
       
  1278 // Enables/disables async stopping
       
  1279 // ---------------------------------------------------------
       
  1280 //
       
  1281 TInt CCaeEngineImp::SetAsyncVideoStopMode( TBool aAsyncVideoStopEnabled )
       
  1282     {
       
  1283     LOGTEXT2( _L("Cae: CCaeEngineImp::SetAsyncVideoStop(%d) entering"), aAsyncVideoStopEnabled );
       
  1284     TInt err;
       
  1285 
       
  1286     // Check if async stopping is supported
       
  1287     if ( iVideoControllerUid == KCamCControllerImplementationUid ) 
       
  1288         {
       
  1289         iAsyncVideoStopEnabled = aAsyncVideoStopEnabled; 
       
  1290         err = KErrNone;
       
  1291         }
       
  1292     else
       
  1293         {
       
  1294         err = KErrNotSupported;
       
  1295         }
       
  1296 
       
  1297     LOGTEXT2(_L("Cae: CCaeEngineImp::SetAsyncVideoStop() err=%d, returning"), err);
       
  1298     return ( err );
       
  1299     }
       
  1300 
       
  1301 
       
  1302 //  End of File