htiui/HtiServicePlugins/HtiCameraServicePlugin/engine/src/EngineVideoRecording.cpp
branchRCL_3
changeset 18 48060abbbeaf
parent 17 d40e813b23c0
child 19 b3cee849fa46
equal deleted inserted replaced
17:d40e813b23c0 18:48060abbbeaf
     1 /*
       
     2 * Copyright (c) 2009 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:  Engine implementation video recording methods.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <HtiLogging.h>
       
    21 #include <AudioPreference.h>                // For MMF audio preference definitions.
       
    22 
       
    23 
       
    24 #include "EngineVideoRecording.h"
       
    25 #include "VideoRecordingQualityLevels.h"
       
    26 // EXTERNAL DATA STRUCTURES
       
    27 
       
    28 // EXTERNAL FUNCTION PROTOTYPES
       
    29 
       
    30 // CONSTANTS
       
    31 
       
    32 // MACROS
       
    33 
       
    34 // LOCAL CONSTANTS AND MACROS
       
    35 
       
    36 // MODULE DATA STRUCTURES
       
    37 
       
    38 // LOCAL FUNCTION PROTOTYPES
       
    39 
       
    40 // FORWARD DECLARATIONS
       
    41 
       
    42 // ============================= LOCAL FUNCTIONS ===============================
       
    43 
       
    44 // ============================ MEMBER FUNCTIONS ===============================
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CEngineVideoRecording::CEngineVideoRecording
       
    48 // C++ default constructor can NOT contain any code, that might leave.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 CEngineVideoRecording::CEngineVideoRecording() :
       
    52     iZoomMode( EZoomModeDigital ), 
       
    53     iExposureMode( CCamera::EExposureAuto ),
       
    54     iWhiteBalanceMode( CCamera::EWBAuto ), 
       
    55     iFlashMode( CCamera::EFlashNone ),
       
    56     iMaxClipSizeInBytes( KMMFNoMaxClipSize ), 
       
    57     iMaxClipSizeInBytesPrep( KMMFNoMaxClipSize )
       
    58     {
       
    59     }
       
    60 
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CEngineVideoRecording::ConstructL
       
    64 // Symbian 2nd phase constructor can leave.
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 void CEngineVideoRecording::ConstructL(MEngineVideoRecordingObserver& aObserver,
       
    68         TInt aCameraIndex)
       
    69     {
       
    70     HTI_LOG_FUNC_IN( "CEngineVideoRecording::ConstructL" );
       
    71     iVideoRecordingObserver = &aObserver;
       
    72     
       
    73     if ( ( aCameraIndex < 0 ) || 
       
    74          ( aCameraIndex >= CCamera::CamerasAvailable() ) )
       
    75         {
       
    76         HTI_LOG_FORMAT("Cae: CEngineVideoRecording::ConstructL leaving KErrHardwareNotAvailable, aCameraIndex=%d", aCameraIndex );
       
    77         User::Leave( KErrHardwareNotAvailable );
       
    78         }
       
    79 
       
    80     // Create a new Camera API implementation object, if supported
       
    81     TRAPD( err, iCamera = CCamera::New2L( static_cast<MCameraObserver2&>(*this), aCameraIndex, KCameraPriority ) );
       
    82     if ( err )
       
    83         {
       
    84         HTI_LOG_FORMAT("CEngineVideoRecording::ConstructL() CCamera::New2L return code=%d", err ); 
       
    85 
       
    86         // Create old Camera API implementation object.
       
    87         iCamera = CCamera::NewL( static_cast<MCameraObserver&>(*this), aCameraIndex );
       
    88         HTI_LOG_TEXT("CEngineVideoRecording::ConstructL() using MCameraObserver"); 
       
    89         }
       
    90     else
       
    91         {
       
    92     HTI_LOG_TEXT("CEngineVideoRecording::ConstructL() using MCameraObserver2"); 
       
    93         }
       
    94 
       
    95 
       
    96     // Get camera handle.
       
    97     iCameraHandle = iCamera->Handle();
       
    98     
       
    99     // Create and initialize info object.
       
   100     iInfo = new( ELeave ) TEngineVideoRecordingInfo;
       
   101     InitializeInfo( *iCamera );
       
   102     
       
   103     HTI_LOG_FUNC_OUT( "CEngineVideoRecording::ConstructL" );
       
   104     }
       
   105 
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CEngineVideoRecording::NewL
       
   109 // Two-phased constructor.
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 CEngineVideoRecording* CEngineVideoRecording::NewL(MEngineVideoRecordingObserver& aObserver,
       
   113         TInt aCameraIndex)
       
   114     {
       
   115     CEngineVideoRecording* self = new (ELeave) CEngineVideoRecording;
       
   116     CleanupStack::PushL( self );
       
   117     self->ConstructL(aObserver, aCameraIndex);
       
   118     CleanupStack::Pop();
       
   119     return self;
       
   120     }
       
   121 
       
   122 
       
   123 // Destructor
       
   124 CEngineVideoRecording::~CEngineVideoRecording()
       
   125     {
       
   126     HTI_LOG_FUNC_IN( "CEngineVideoRecording::~CEngineVideoRecording");
       
   127 
       
   128         delete iVideoType;
       
   129         delete iVideoClipFileName;
       
   130 
       
   131         // Turn camera power off first, then release camera.
       
   132         if ( iCamera ) 
       
   133             {
       
   134             if ( iReserved ) 
       
   135                 {
       
   136                 if ( iPowerOn ) 
       
   137                     {
       
   138                     iCamera->PowerOff();
       
   139                     }
       
   140                 iCamera->Release();
       
   141                 }
       
   142             }
       
   143 
       
   144         delete iVideoFrameSizePrep;
       
   145         delete iVideoFrameSize;
       
   146 
       
   147         delete iVideoRecorder;
       
   148 
       
   149         delete iVideoQualityLevels;
       
   150         
       
   151         delete iCamera;
       
   152 
       
   153         REComSession::FinalClose();
       
   154 
       
   155         HTI_LOG_FUNC_OUT( "CEngineVideoRecording::~CEngineVideoRecording");
       
   156     }
       
   157 
       
   158 void CEngineVideoRecording::InitL( )
       
   159     {
       
   160     HTI_LOG_FUNC_IN( "CEngineVideoRecording::InitL");
       
   161 
       
   162     // To allow re-initialization, release the camera (first cancels possible 
       
   163     // activities and turns camera power off).
       
   164     Release();
       
   165    
       
   166     iCamera->Reserve();
       
   167 
       
   168     HTI_LOG_FUNC_OUT( "CEngineVideoRecording::InitL");
       
   169     }
       
   170 
       
   171 void CEngineVideoRecording::InitializeInfo( 
       
   172     const CCamera& aCamera )
       
   173     {
       
   174 
       
   175     // Initialise Camera (API) info.
       
   176 
       
   177     TCameraInfo cameraInfo;
       
   178     aCamera.CameraInfo( cameraInfo );
       
   179 
       
   180     iInfo->iHardwareVersion = cameraInfo.iHardwareVersion;
       
   181     iInfo->iSoftwareVersion = cameraInfo.iSoftwareVersion;
       
   182 
       
   183     iInfo->iOrientation = cameraInfo.iOrientation;
       
   184 
       
   185     iInfo->iOptionsSupported = cameraInfo.iOptionsSupported;
       
   186     
       
   187     iInfo->iFlashModesSupported = cameraInfo.iFlashModesSupported;
       
   188 
       
   189     iInfo->iExposureModesSupported = cameraInfo.iExposureModesSupported;
       
   190 
       
   191     iInfo->iWhiteBalanceModesSupported = cameraInfo.iWhiteBalanceModesSupported;
       
   192 
       
   193     iInfo->iMinZoom = cameraInfo.iMinZoom;
       
   194     iInfo->iMaxZoom = cameraInfo.iMaxZoom;
       
   195     iInfo->iMaxDigitalZoom = cameraInfo.iMaxDigitalZoom;
       
   196 
       
   197     iInfo->iMinZoomFactor = cameraInfo.iMinZoomFactor;
       
   198     iInfo->iMaxZoomFactor = cameraInfo.iMaxZoomFactor;
       
   199     iInfo->iMaxDigitalZoomFactor = cameraInfo.iMaxDigitalZoomFactor;
       
   200 
       
   201     iInfo->iNumImageSizesSupported = cameraInfo.iNumImageSizesSupported;
       
   202     iInfo->iImageFormatsSupported = cameraInfo.iImageFormatsSupported;
       
   203 
       
   204     // Initialize EV compensation info (no supported in this version)
       
   205     iInfo->iMinEvCompensation = 0;
       
   206     iInfo->iMaxEvCompensation = 0;
       
   207     iInfo->iMinEvCompensationValue = 0;
       
   208     iInfo->iMaxEvCompensationValue = 0;
       
   209 
       
   210     // Initialize engine info.
       
   211 
       
   212     iInfo->iNumStillQualityLevelsSupported = 0; // Quality levels are initialized separately.
       
   213     iInfo->iNumVideoQualityLevelsSupported = 0; // Quality levels are initialized separately.
       
   214 
       
   215     }
       
   216 void CEngineVideoRecording::InitVideoRecorderL()
       
   217     {
       
   218     HTI_LOG_FUNC_IN( "CEngineVideoRecording::InitVideoRecorderL()");
       
   219 
       
   220     iVideoInitialized = EFalse;
       
   221 
       
   222     // Close video recording if previously opened/prepared.
       
   223     CloseVideoRecording();
       
   224     
       
   225     // (Re-)initialize these.
       
   226     iMaxClipSizeInBytes = KMMFNoMaxClipSize; 
       
   227     iMaxClipSizeInBytesPrep = KMMFNoMaxClipSize;
       
   228 
       
   229     // Create video quality levels container object.
       
   230     iVideoQualityLevels = CVideoRecordingQualityLevels::NewL();
       
   231 
       
   232     // Destroy possible video clip file name. (Its allocated elsewhere when file name is set.)
       
   233     delete iVideoClipFileName;
       
   234     iVideoClipFileName = NULL;
       
   235 
       
   236     // Create video recorder.
       
   237     delete iVideoRecorder;
       
   238     iVideoRecorder = NULL;
       
   239     iVideoRecorder = CVideoRecorderUtility::NewL( *this , KAudioPriorityVideoRecording,
       
   240         TMdaPriorityPreference( KAudioPrefVideoRecording ) );
       
   241 
       
   242     delete iVideoFrameSize;
       
   243     iVideoFrameSize = NULL;
       
   244     iVideoFrameSize = new( ELeave ) TSize();
       
   245     
       
   246     delete iVideoFrameSizePrep;
       
   247     iVideoFrameSizePrep = NULL;
       
   248     iVideoFrameSizePrep = new( ELeave ) TSize();
       
   249 
       
   250     iInfo->iNumVideoQualityLevelsSupported = iVideoQualityLevels->InitDefaultsL();
       
   251     iVideoInitialized = ETrue;
       
   252 
       
   253     HTI_LOG_FUNC_OUT( "CEngineVideoRecording::InitVideoRecorderL()");
       
   254     }
       
   255 
       
   256 void CEngineVideoRecording::SetVideoRecordingFileNameL( 
       
   257     const TDesC& aVideoClipFileName )
       
   258     {
       
   259     HTI_LOG_FUNC_IN("CEngineVideoRecording::SetVideoRecordingFileNameL");
       
   260 
       
   261     if ( !iVideoInitialized || iVideoRecordingRunning ) 
       
   262         {
       
   263         HTI_LOG_TEXT("CEngineVideoRecording::SetVideoRecordingFileNameL leaving KErrNotReady" );
       
   264         User::Leave( KErrNotReady );
       
   265         }
       
   266 
       
   267     if ( aVideoClipFileName.Length() > 0 )
       
   268         {
       
   269         // Memorize the video clip file name.
       
   270         delete iVideoClipFileName;
       
   271         iVideoClipFileName = NULL;
       
   272         iVideoClipFileName = aVideoClipFileName.AllocL();
       
   273         }
       
   274     else 
       
   275         {
       
   276         HTI_LOG_TEXT("CEngineVideoRecording::SetVideoRecordingFileNameL leaving KErrArgument");
       
   277         User::Leave( KErrArgument );
       
   278         }
       
   279 
       
   280     if ( iVideoPrepared ) 
       
   281         {
       
   282         // Does the actual change of file name, only if video is prepared.
       
   283         // Note: Variated implementation
       
   284         ChangeVideoFileNameL();
       
   285         }
       
   286 
       
   287     HTI_LOG_FUNC_OUT("CEngineVideoRecording::SetVideoRecordingFileNameL");
       
   288     }
       
   289 
       
   290 void CEngineVideoRecording::ChangeVideoFileNameL()
       
   291     {
       
   292     HTI_LOG_FUNC_IN("CEngineVideoRecording::ChangeVideoFileNameL");
       
   293 
       
   294     // Close if previously prepared.
       
   295     CloseVideoRecording();
       
   296     // Open video recorder.
       
   297     iVideoOpened = ETrue; // This is always set to ETrue when 
       
   298                           // OpenFileL has been called to allow 
       
   299                           // freeing resources by CloseVideoRecording().
       
   300     iVideoRecorder->OpenFileL( iVideoClipFileName->Des(),
       
   301                                iCameraHandle,
       
   302                                iVideoControllerUid,
       
   303                                iVideoFormatUid, 
       
   304                                iVideoType->Des(),  
       
   305                                iVideoAudioType );
       
   306 
       
   307     HTI_LOG_FUNC_OUT("CEngineVideoRecording::ChangeVideoFileNameL");
       
   308     }
       
   309 
       
   310 void CEngineVideoRecording::PrepareVideoRecordingL( 
       
   311     TInt aVideoQualityIndex )
       
   312     {
       
   313     HTI_LOG_TEXT("CEngineVideoRecording::PrepareVideoRecordingL with video quality index");
       
   314 
       
   315     if ( ( aVideoQualityIndex < 0 ) || 
       
   316          ( aVideoQualityIndex >= iVideoQualityLevels->Count() ) ) 
       
   317         {
       
   318         HTI_LOG_TEXT("PrepareVideoRecordingL() leaving KErrArgument");
       
   319         User::Leave( KErrArgument );
       
   320         }
       
   321     
       
   322     PrepareVideoRecordingL( iVideoQualityLevels->At( aVideoQualityIndex ).iFrameSize, 
       
   323                             iVideoQualityLevels->At( aVideoQualityIndex ).iFrameRate, 
       
   324                             iVideoQualityLevels->At( aVideoQualityIndex ).iBitRate, 
       
   325                             iVideoQualityLevels->At( aVideoQualityIndex ).iAudioEnabled,
       
   326                             iVideoQualityLevels->At( aVideoQualityIndex ).iAudioBitRate, 
       
   327                             iVideoQualityLevels->At( aVideoQualityIndex ).iMimeType, 
       
   328                             iVideoQualityLevels->At( aVideoQualityIndex ).iPreferredSupplier, 
       
   329                             iVideoQualityLevels->At( aVideoQualityIndex ).iVideoType,    
       
   330                             iVideoQualityLevels->At( aVideoQualityIndex ).iAudioType );
       
   331     
       
   332     iVideoQualityIndex = aVideoQualityIndex;
       
   333     }
       
   334 
       
   335 void CEngineVideoRecording::PrepareVideoRecordingL( 
       
   336     const TSize&  aFrameSize, 
       
   337     TReal32       aFrameRate, 
       
   338     TInt          aBitRate, 
       
   339     TBool         aAudioEnabled,
       
   340     const TDesC8& aMimeType, 
       
   341     const TDesC&  aPreferredSupplier, 
       
   342     const TDesC8& aVideoType, 
       
   343     const TDesC8& aAudioType )
       
   344     {
       
   345     HTI_LOG_FUNC_IN("CEngineVideoRecording::PrepareVideoRecordingL");
       
   346     // Leave if not initialized properly or busy doing something else.
       
   347     if ( !iVideoInitialized || 
       
   348          !iVideoClipFileName || 
       
   349          iVideoRecordingRunning   ) 
       
   350         {
       
   351         HTI_LOG_TEXT("PrepareVideoRecordingL leaving KErrNotReady");
       
   352         User::Leave( KErrNotReady );
       
   353         }
       
   354 
       
   355     CheckPowerL();
       
   356     
       
   357     // Leave if video clip file name is not set properly.
       
   358     if ( iVideoClipFileName->Length() == 0 )
       
   359         {
       
   360         HTI_LOG_TEXT("PrepareVideoRecordingL() leaving KErrArgument (iVideoClipFileName)");
       
   361         User::Leave( KErrArgument );
       
   362         }
       
   363 
       
   364     // Close if previously opened/prepared.
       
   365     CloseVideoRecording();
       
   366 
       
   367     // Find values for iVideoControllerUid and iVideoFormatUid.
       
   368     // Those are also needed if clip file name is changed when prepared.
       
   369     FindVideoUidsL( aMimeType, aPreferredSupplier );
       
   370 
       
   371     // Memorize video type.
       
   372     delete iVideoType;
       
   373     iVideoType = NULL;
       
   374     iVideoType = aVideoType.AllocL();
       
   375 
       
   376     // Convert audio type from TDesC8 to TFourCC.
       
   377     iVideoAudioType = ConvertAndSetVideoAudioTypeL( aAudioType );
       
   378 
       
   379     // Memorize the parameters to be prepared.
       
   380     *iVideoFrameSizePrep   = aFrameSize;
       
   381     iVideoFrameRatePrep    = aFrameRate;
       
   382     iVideoBitRatePrep      = aBitRate;
       
   383     iVideoAudioEnabledPrep = aAudioEnabled;
       
   384 
       
   385     // Open video recorder.
       
   386     iVideoOpened = ETrue; // This is always set to ETrue when 
       
   387                           // OpenFileL has been called to allow 
       
   388                           // freeing resources by CloseVideoRecording().
       
   389     iVideoRecorder->OpenFileL( iVideoClipFileName->Des(),
       
   390                                iCameraHandle,
       
   391                                iVideoControllerUid,
       
   392                                iVideoFormatUid, 
       
   393                                iVideoType->Des(),  
       
   394                                iVideoAudioType );
       
   395     HTI_LOG_FUNC_OUT("CEngineVideoRecording::PrepareVideoRecordingL");
       
   396     }
       
   397 
       
   398 void CEngineVideoRecording::PrepareVideoRecordingL( 
       
   399     const TSize&  aFrameSize, 
       
   400     TReal32       aFrameRate, 
       
   401     TInt          aBitRate, 
       
   402     TBool         aAudioEnabled,
       
   403     TInt          aAudioBitRate, 
       
   404     const TDesC8& aMimeType, 
       
   405     const TDesC&  aPreferredSupplier, 
       
   406     const TDesC8& aVideoType, 
       
   407     const TDesC8& aAudioType )
       
   408     {
       
   409     HTI_LOG_TEXT("CEngineVideoRecording::PrepareVideoRecordingL with audio bit rate");
       
   410     // Memorize video audio bit rate value to be prepared.
       
   411     iVideoAudioBitRatePrep = aAudioBitRate;
       
   412     // Force audio bit rate preparation.
       
   413     iPrepareVideoAudioBitRate = ETrue;
       
   414 
       
   415     // Call the version without audio bit rate argument.
       
   416     // This is possible because the separate PrepareVideoSettingsL() is doing
       
   417     // settings after succesfull opening of video recording.
       
   418     PrepareVideoRecordingL( aFrameSize, 
       
   419                             aFrameRate, 
       
   420                             aBitRate, 
       
   421                             aAudioEnabled, 
       
   422                             aMimeType, 
       
   423                             aPreferredSupplier, 
       
   424                             aVideoType, 
       
   425                             aAudioType );
       
   426     }
       
   427 
       
   428 void CEngineVideoRecording::CloseVideoRecording()
       
   429     {
       
   430     HTI_LOG_FUNC_IN("CEngineVideoRecording::CloseVideoRecording");
       
   431 
       
   432     if ( iVideoPrepared ) 
       
   433         {
       
   434         CancelVideoRecording();
       
   435         iVideoPrepared = EFalse;
       
   436         }
       
   437 
       
   438     if ( iVideoOpened )
       
   439         {
       
   440         iVideoRecorder->Close();
       
   441         iVideoOpened = EFalse;
       
   442         }
       
   443 
       
   444     HTI_LOG_FUNC_OUT("CEngineVideoRecording::CloseVideoRecording");
       
   445     }
       
   446 
       
   447 TInt CEngineVideoRecording::VideoQualityIndex() const
       
   448     {
       
   449     HTI_LOG_FUNC_IN("CEngineVideoRecording::VideoQualityIndex");
       
   450 
       
   451     TInt qualityIndex( -1 );
       
   452     if ( iVideoPrepared )
       
   453         {
       
   454         qualityIndex = iVideoQualityIndex;
       
   455         }
       
   456     HTI_LOG_FUNC_OUT("CEngineVideoRecording::VideoQualityIndex");
       
   457     return qualityIndex;
       
   458     }
       
   459 
       
   460 TInt CEngineVideoRecording::VideoQualityCount() const
       
   461         {
       
   462         return iVideoQualityLevels->Count();
       
   463         }
       
   464 
       
   465 
       
   466 void CEngineVideoRecording::GetVideoFrameSize( 
       
   467     TInt aVideoQualityIndex, 
       
   468     TSize& aFrameSize ) const
       
   469     {
       
   470     HTI_LOG_FUNC_IN("CEngineVideoRecording::GetVideoFrameSize");
       
   471     
       
   472     if ( aVideoQualityIndex >= 0 &&  
       
   473          aVideoQualityIndex < iVideoQualityLevels->Count() )
       
   474         {
       
   475         aFrameSize = iVideoQualityLevels->At( aVideoQualityIndex ).iFrameSize;
       
   476         }
       
   477     HTI_LOG_FUNC_OUT("CEngineVideoRecording::GetVideoFrameSize");
       
   478     }
       
   479 
       
   480 TReal32 CEngineVideoRecording::VideoFrameRate( 
       
   481     TInt aVideoQualityIndex ) const
       
   482     {
       
   483     HTI_LOG_FUNC_IN("CEngineVideoRecording::VideoFrameRate");
       
   484 
       
   485     TReal32 frameRate( 0.0 );
       
   486     if ( aVideoQualityIndex >= 0 &&  
       
   487          aVideoQualityIndex < iVideoQualityLevels->Count() )
       
   488         {
       
   489         frameRate = iVideoQualityLevels->At( aVideoQualityIndex ).iFrameRate;
       
   490         }
       
   491     HTI_LOG_FUNC_OUT("CEngineVideoRecording::VideoFrameRate");
       
   492     return frameRate;
       
   493     }
       
   494 
       
   495 TInt CEngineVideoRecording::EstimatedVideoRecordingBitRateL( 
       
   496     TInt aVideoQualityIndex ) const
       
   497     {
       
   498     HTI_LOG_FUNC_IN("CEngineVideoRecording::EstimatedVideoRecordingBitRateL");
       
   499 
       
   500     TInt storageRate( 0 );
       
   501     if ( aVideoQualityIndex >= 0 &&  
       
   502          aVideoQualityIndex < iVideoQualityLevels->Count() )
       
   503         {
       
   504         storageRate = iVideoQualityLevels->At( aVideoQualityIndex ).iStorageRate;
       
   505         }
       
   506     HTI_LOG_FUNC_OUT("CEngineVideoRecording::EstimatedVideoRecordingBitRateL");
       
   507     return storageRate;
       
   508     }
       
   509 
       
   510 void CEngineVideoRecording::SetVideoClipMaxSizeL( 
       
   511     TInt aMaxClipSizeInBytes )
       
   512     {
       
   513     HTI_LOG_FUNC_IN("CEngineVideoRecording::SetVideoClipMaxSizeL");
       
   514 
       
   515     if ( !iVideoInitialized || iVideoRecordingRunning ) 
       
   516         {
       
   517         HTI_LOG_TEXT("SetVideoClipMaxSizeL leaving KErrNotReady");
       
   518         User::Leave( KErrNotReady );
       
   519         }
       
   520 
       
   521     if ( aMaxClipSizeInBytes > 0 ) 
       
   522         {
       
   523         iMaxClipSizeInBytesPrep = aMaxClipSizeInBytes;
       
   524         }
       
   525     else 
       
   526         {
       
   527         iMaxClipSizeInBytesPrep = KMMFNoMaxClipSize;
       
   528         }
       
   529 
       
   530     if ( iVideoPrepared )
       
   531         {
       
   532         iPrepPars = ETrue;
       
   533         iVideoRecorder->SetMaxClipSizeL( iMaxClipSizeInBytesPrep );
       
   534         iVideoRecorder->Prepare();
       
   535         }
       
   536 
       
   537     HTI_LOG_FUNC_OUT("CEngineVideoRecording::SetVideoClipMaxSizeL");
       
   538     }
       
   539 
       
   540 TInt CEngineVideoRecording::VideoClipMaxSize() const 
       
   541     {
       
   542     HTI_LOG_FUNC_IN("CEngineVideoRecording::VideoClipMaxSize");
       
   543 
       
   544     TInt maxClipSizeInBytes( 0 );
       
   545     if ( iMaxClipSizeInBytes != KMMFNoMaxClipSize ) 
       
   546         {
       
   547         maxClipSizeInBytes = iMaxClipSizeInBytes;
       
   548         }
       
   549 
       
   550     HTI_LOG_FUNC_OUT("CEngineVideoRecording::VideoClipMaxSize");
       
   551     return maxClipSizeInBytes;
       
   552     }
       
   553 
       
   554 void CEngineVideoRecording::SetVideoAudioL( 
       
   555     TBool aAudioEnabled )
       
   556     {
       
   557     HTI_LOG_FUNC_IN("CEngineVideoRecording::SetVideoAudioL");
       
   558 
       
   559     if ( !iVideoInitialized || iVideoRecordingRunning ) 
       
   560         {
       
   561         HTI_LOG_TEXT("SetVideoAudioL leaving KErrNotReady");
       
   562         User::Leave( KErrNotReady );
       
   563         }
       
   564 
       
   565     iVideoAudioEnabledPrep = aAudioEnabled;
       
   566     iVideoRecorder->SetAudioEnabledL( iVideoAudioEnabledPrep );
       
   567     iPrepPars = ETrue;
       
   568     iVideoRecorder->Prepare();
       
   569 
       
   570     HTI_LOG_FUNC_OUT("CEngineVideoRecording::SetVideoAudioL");
       
   571     }
       
   572 
       
   573 TBool CEngineVideoRecording::VideoAudio() const
       
   574     {
       
   575     HTI_LOG_FUNC_IN("CEngineVideoRecording::VideoAudio");
       
   576 
       
   577     TBool audioEnabled( EFalse );
       
   578     if ( iVideoRecorder )
       
   579         {
       
   580         TRAPD( error, { audioEnabled = iVideoRecorder->AudioEnabledL(); } );
       
   581         if ( error != KErrNone ) 
       
   582             {
       
   583             audioEnabled = EFalse;
       
   584             }
       
   585         }
       
   586     HTI_LOG_FUNC_OUT("CEngineVideoRecording::VideoAudio");
       
   587     return audioEnabled;
       
   588     }
       
   589 
       
   590 void CEngineVideoRecording::StartVideoRecording()
       
   591     {
       
   592     HTI_LOG_FUNC_IN("CEngineVideoRecording::StartVideoRecording");
       
   593 
       
   594     TInt error( KErrNone );
       
   595 
       
   596     if ( iVideoPrepared && !iVideoRecordingRunning ) 
       
   597         {
       
   598         iVideoRecordingRunning = ETrue;
       
   599         iVideoRecordingPaused = EFalse;
       
   600         
       
   601        // Start video recording.
       
   602         iVideoRecorder->Record();
       
   603         }
       
   604     else 
       
   605         {
       
   606         error = KErrNotReady;
       
   607         }
       
   608 
       
   609 
       
   610     iVideoRecordingObserver->MevroVideoRecordingOn( error );
       
   611 
       
   612     HTI_LOG_FUNC_OUT("CEngineVideoRecording::StartVideoRecording");
       
   613     }
       
   614 
       
   615 void CEngineVideoRecording::StopVideoRecording()
       
   616     {
       
   617     HTI_LOG_FUNC_IN("CEngineVideoRecording::StopVideoRecording");
       
   618         
       
   619     TInt stoppingError( KErrNone );
       
   620     
       
   621     if ( iVideoRecordingRunning ) 
       
   622         {
       
   623         iVideoRecordingRunning = EFalse;
       
   624         stoppingError = iVideoRecorder->Stop();
       
   625         
       
   626         // Can't be paused anymore.
       
   627         iVideoRecordingPaused = EFalse;
       
   628         }
       
   629     else 
       
   630         {
       
   631         stoppingError = KErrNotReady;
       
   632         }
       
   633 
       
   634     iVideoRecordingObserver->MevroVideoRecordingComplete( stoppingError );
       
   635 
       
   636     HTI_LOG_FUNC_OUT("CEngineVideoRecording::StopVideoRecording");
       
   637     }
       
   638 
       
   639 void CEngineVideoRecording::PauseVideoRecording()
       
   640     {
       
   641     HTI_LOG_FUNC_IN("CEngineVideoRecording::PauseVideoRecording");
       
   642 
       
   643     TInt error( KErrNone );
       
   644 
       
   645     if ( iVideoRecordingRunning && !iVideoRecordingPaused ) 
       
   646         {
       
   647         // Pause video recording.
       
   648         TRAP( error, iVideoRecorder->PauseL() );
       
   649 
       
   650         if ( error == KErrNone ) 
       
   651             {
       
   652             iVideoRecordingPaused = ETrue;
       
   653             }
       
   654         }
       
   655     else 
       
   656         {
       
   657         error = KErrNotReady;
       
   658         }
       
   659 
       
   660     iVideoRecordingObserver->MevroVideoRecordingPaused( error );
       
   661 
       
   662     HTI_LOG_FUNC_OUT("CEngineVideoRecording::PauseVideoRecording");
       
   663     }
       
   664 
       
   665 void CEngineVideoRecording::ResumeVideoRecording()
       
   666     {
       
   667     HTI_LOG_FUNC_IN("CEngineVideoRecording::ResumeVideoRecording");
       
   668 
       
   669     TInt error( KErrNone );
       
   670 
       
   671     if ( iVideoRecordingRunning && iVideoRecordingPaused ) 
       
   672         {
       
   673         // Start video recording.
       
   674         iVideoRecorder->Record();
       
   675         iVideoRecordingPaused = EFalse;
       
   676         }
       
   677     else 
       
   678         {
       
   679         error = KErrNotReady;
       
   680         }
       
   681 
       
   682     iVideoRecordingObserver->MevroVideoRecordingOn( error );
       
   683 
       
   684     HTI_LOG_FUNC_OUT("CEngineVideoRecording::ResumeVideoRecording");
       
   685     }
       
   686 
       
   687 TTimeIntervalMicroSeconds CEngineVideoRecording::RemainingVideoRecordingTime() const
       
   688     {
       
   689     HTI_LOG_FUNC_IN("CEngineVideoRecording::RemainingVideoRecordingTime");
       
   690     
       
   691     TTimeIntervalMicroSeconds remaining( 0 );
       
   692     if ( iVideoRecorder )
       
   693         {
       
   694         remaining = iVideoRecorder->RecordTimeAvailable();
       
   695         }
       
   696     HTI_LOG_FUNC_OUT("CEngineVideoRecording::RemainingVideoRecordingTime");
       
   697     return remaining;
       
   698     }
       
   699 
       
   700 TBool CEngineVideoRecording::IsVideoRecording() const
       
   701     {
       
   702     return iVideoRecordingRunning;    
       
   703     }
       
   704 
       
   705 
       
   706 void CEngineVideoRecording::CancelVideoRecording()
       
   707     {
       
   708     HTI_LOG_FUNC_IN("CEngineVideoRecording::CancelVideoRecording");
       
   709     
       
   710     if ( iVideoRecordingRunning ) 
       
   711         {
       
   712         iVideoRecordingRunning = EFalse;
       
   713         // Stop video recording. Do not call MevroVideoRecordingComplete()
       
   714         (void) iVideoRecorder->Stop();
       
   715         iVideoRecordingPaused = EFalse;
       
   716         }
       
   717     
       
   718     HTI_LOG_FUNC_OUT("CEngineVideoRecording::CancelVideoRecording");
       
   719     }
       
   720 
       
   721 void CEngineVideoRecording::PrepareVideoSettingsL()
       
   722     {
       
   723     HTI_LOG_FUNC_IN("CEngineVideoRecording::PrepareVideoSettingsL");
       
   724 
       
   725     iVideoRecorder->SetVideoFrameSizeL( *iVideoFrameSizePrep );
       
   726     iVideoRecorder->SetVideoFrameRateL( iVideoFrameRatePrep );
       
   727     iVideoRecorder->SetVideoBitRateL( iVideoBitRatePrep );
       
   728     iVideoRecorder->SetAudioEnabledL( iVideoAudioEnabledPrep );
       
   729     if ( iPrepareVideoAudioBitRate )
       
   730         {
       
   731         iVideoRecorder->SetAudioBitRateL( iVideoAudioBitRatePrep );
       
   732         iPrepareVideoAudioBitRate = EFalse;
       
   733         }
       
   734     iVideoRecorder->SetMaxClipSizeL( iMaxClipSizeInBytesPrep );
       
   735 
       
   736     // Set the recording gain to the maximum
       
   737     TInt gain = iVideoRecorder->GainL();
       
   738     HTI_LOG_FORMAT("CEngineVideoRecording::PrepareVideoSettingsL() GainL was %d", gain );
       
   739     gain = iVideoRecorder->MaxGainL();
       
   740     HTI_LOG_FORMAT("CEngineVideoRecording::PrepareVideoSettingsL() MaxGainL is %d", gain );
       
   741     iVideoRecorder->SetGainL( gain );
       
   742     gain = iVideoRecorder->GainL();
       
   743     HTI_LOG_FORMAT("CEngineVideoRecording::PrepareVideoSettingsL() GainL set to %d", gain );
       
   744 
       
   745     iPrepPars = ETrue;
       
   746     iVideoRecorder->Prepare();
       
   747 
       
   748     HTI_LOG_FUNC_OUT("CEngineVideoRecording::PrepareVideoSettingsL");
       
   749     }
       
   750 
       
   751 void CEngineVideoRecording::FindVideoUidsL(
       
   752     const TDesC8& aMimeType, 
       
   753     const TDesC&  aPreferredSupplier )
       
   754     {
       
   755     HTI_LOG_FUNC_IN("CEngineVideoRecording::FindVideoUidsL");
       
   756 
       
   757     iVideoControllerUid.iUid = 0;
       
   758     iVideoFormatUid.iUid = 0; 
       
   759 
       
   760     // Retrieve a list of possible controllers from ECOM.
       
   761     //
       
   762     // Controller must support recording the requested mime type.
       
   763     // Controller must be provided by preferred supplier.
       
   764 
       
   765     CMMFControllerPluginSelectionParameters* cSelect = 
       
   766         CMMFControllerPluginSelectionParameters::NewLC();
       
   767     CMMFFormatSelectionParameters* fSelect = 
       
   768         CMMFFormatSelectionParameters::NewLC();
       
   769 
       
   770     fSelect->SetMatchToMimeTypeL( aMimeType );
       
   771     cSelect->SetRequiredRecordFormatSupportL( *fSelect );
       
   772     cSelect->SetPreferredSupplierL( aPreferredSupplier,
       
   773        CMMFPluginSelectionParameters::EOnlyPreferredSupplierPluginsReturned );
       
   774 
       
   775     RMMFControllerImplInfoArray controllers;
       
   776     CleanupResetAndDestroyPushL( controllers );
       
   777     cSelect->ListImplementationsL( controllers );
       
   778 
       
   779     if ( controllers.Count() < 1 )
       
   780         {
       
   781         // No appropriate controllers found.
       
   782         HTI_LOG_TEXT("CEngineVideoRecording::FindVideoUidsL() leaving KErrNotSupported (no controllers found)");
       
   783         User::Leave( KErrNotSupported );
       
   784         }
       
   785 
       
   786     TBool found( EFalse );
       
   787     for ( TInt contInd = 0; contInd < controllers.Count() && !found; contInd++ ) // there can be more than one controller, search from all of them
       
   788         {
       
   789         // Get the controller UID.
       
   790         iVideoControllerUid = controllers[contInd]->Uid();
       
   791         HTI_LOG_FORMAT("CEngineVideoRecording::FindVideoUidsL()  iVideoControllerUid=%x", iVideoControllerUid.iUid );
       
   792 
       
   793         // Inquires the controller about supported formats.
       
   794         RMMFFormatImplInfoArray formats = controllers[contInd]->RecordFormats();
       
   795 
       
   796         // Get the first format that supports our mime type.
       
   797         for ( TInt i = 0; i < formats.Count(); i++ )
       
   798             {
       
   799             if ( formats[i]->SupportsMimeType( aMimeType ) )
       
   800                 {
       
   801                 iVideoFormatUid = formats[i]->Uid(); // set the UID
       
   802                 found = ETrue;
       
   803                 HTI_LOG_FORMAT("CEngineVideoRecording::FindVideoUidsL() Found iVideoFormatUid=%x", iVideoFormatUid.iUid);
       
   804                 break;
       
   805                 }
       
   806             }
       
   807         }
       
   808     if ( !found )
       
   809         {
       
   810         // No appropriate video format found.
       
   811         HTI_LOG_TEXT("CEngineVideoRecording::FindVideoUidsL() leaving KErrNotSupported (no video format found)");
       
   812         User::Leave( KErrNotSupported );
       
   813         }
       
   814 
       
   815     CleanupStack::PopAndDestroy( 3, cSelect ); // cselect, fselect, controllers
       
   816 
       
   817     HTI_LOG_FUNC_OUT("CEngineVideoRecording::FindVideoUidsL");
       
   818     }
       
   819 
       
   820 
       
   821 TFourCC CEngineVideoRecording::ConvertAndSetVideoAudioTypeL(
       
   822     const TDesC8& aAudioType )
       
   823     {
       
   824     if ( aAudioType == KNullDesC8 )
       
   825         {
       
   826         return KMMFFourCCCodeNULL;
       
   827         }
       
   828     else
       
   829         {
       
   830         if ( aAudioType.Length() != 4 ) 
       
   831             {
       
   832             User::Leave( KErrArgument );
       
   833             }
       
   834         return TFourCC( aAudioType[0], aAudioType[1], aAudioType[2], aAudioType[3] );
       
   835         }
       
   836     }
       
   837 
       
   838 void CEngineVideoRecording::Reserve()
       
   839     {
       
   840     HTI_LOG_FUNC_IN("CEngineVideoRecording::Reserve");
       
   841 
       
   842     if ( !iReserved ) 
       
   843         {
       
   844         iCamera->Reserve();
       
   845         }
       
   846     else if ( !iPowerOn ) // in case previous reserve ok, but poweron failed
       
   847         {
       
   848         PowerOn();
       
   849         }
       
   850 
       
   851 
       
   852     HTI_LOG_FUNC_OUT("CEngineVideoRecording::Reserve");
       
   853     }
       
   854 
       
   855 
       
   856 void CEngineVideoRecording::Release()
       
   857     {
       
   858     HTI_LOG_FUNC_IN("CEngineVideoRecording::Release");
       
   859 
       
   860     if ( iReserved ) 
       
   861         {
       
   862         PowerOff();         // Cancel all activities (if any) and turn power off.
       
   863         iCamera->Release(); // Release Camera HW.
       
   864         iReserved = EFalse;
       
   865         iVideoPrepared = EFalse;
       
   866         iVideoOpened = EFalse;
       
   867         }
       
   868 
       
   869     HTI_LOG_FUNC_OUT("CEngineVideoRecording::Release");
       
   870     }
       
   871 
       
   872 
       
   873 void CEngineVideoRecording::PowerOn()
       
   874     {
       
   875     HTI_LOG_FUNC_IN("CEngineVideoRecording::PowerOn");
       
   876 
       
   877     if ( iReserved && !iPowerOn ) 
       
   878         {
       
   879         iCamera->PowerOn();
       
   880         }
       
   881 
       
   882     HTI_LOG_FUNC_OUT("CEngineVideoRecording::PowerOn");
       
   883     }
       
   884 
       
   885 
       
   886 void CEngineVideoRecording::PowerOff()
       
   887     {
       
   888     HTI_LOG_FUNC_IN("CEngineVideoRecording::PowerOff");
       
   889 
       
   890     if ( iPowerOn ) 
       
   891         {
       
   892         iCamera->PowerOff();
       
   893         iPowerOn = EFalse;
       
   894         }
       
   895 
       
   896     HTI_LOG_FUNC_OUT("CEngineVideoRecording::PowerOff");
       
   897     }
       
   898 
       
   899 
       
   900 void CEngineVideoRecording::SetZoomModeL( 
       
   901     TZoomMode aZoomMode )
       
   902     {
       
   903     HTI_LOG_FUNC_IN("CEngineVideoRecording::SetZoomModeL");
       
   904 
       
   905     // Currently supporting digital and optical zooms, not EZoomModeOpticalDigital.
       
   906     if ( ( aZoomMode != EZoomModeDigital ) && ( aZoomMode != EZoomModeOptical ) )
       
   907         {
       
   908         HTI_LOG_FORMAT("CEngineVideoRecording::SetZoomModeL leaving KErrNotSupported, aZoomMode=%d", aZoomMode );
       
   909         User::Leave( KErrNotSupported );
       
   910         }
       
   911 
       
   912     iZoomMode = aZoomMode;
       
   913 
       
   914     HTI_LOG_FUNC_OUT("CEngineVideoRecording::SetZoomModeL");
       
   915     }
       
   916 
       
   917 
       
   918 CEngineVideoRecording::TZoomMode CEngineVideoRecording::ZoomMode() const
       
   919     {
       
   920     HTI_LOG_TEXT("CEngineVideoRecording::ZoomMode");
       
   921 
       
   922     return iZoomMode;
       
   923     }
       
   924 
       
   925 
       
   926 void CEngineVideoRecording::SetZoomValueL( 
       
   927     TInt aZoomValue )
       
   928     {
       
   929     HTI_LOG_FUNC_IN("CEngineVideoRecording::SetZoomValueL");
       
   930 
       
   931     CheckPowerL();
       
   932 
       
   933     switch ( iZoomMode )
       
   934         {
       
   935         case EZoomModeDigital:
       
   936             // Leave if zoom factor is out of range.
       
   937             if ( ( aZoomValue < 0 ) || 
       
   938                  ( aZoomValue > iInfo->iMaxDigitalZoom ) )
       
   939                 {
       
   940                 HTI_LOG_FORMAT("CEngineVideoRecording::SetZoomValueL leaving KErrArgument, aZoomValue=%d", aZoomValue );
       
   941                 HTI_LOG_FORMAT("The min digital zool value is 0, the max is %d", iInfo->iMaxDigitalZoom);
       
   942                 User::Leave( KErrArgument );
       
   943                 }
       
   944             // Set DIGITAL zoom value.
       
   945             iCamera->SetDigitalZoomFactorL( aZoomValue );
       
   946             iZoomValue = aZoomValue;
       
   947             break;
       
   948         case EZoomModeOptical:
       
   949             // Leave if zoom factor is out of range.
       
   950             if ( ( aZoomValue < iInfo->iMinZoom ) || 
       
   951                  ( aZoomValue > iInfo->iMaxZoom ) )
       
   952                 {
       
   953                 HTI_LOG_FORMAT("CEngineVideoRecording::SetZoomValueL leaving KErrArgument, aZoomValue=%d", aZoomValue );
       
   954                 HTI_LOG_FORMAT("The max optical zoom value is %d", iInfo->iMaxZoom);
       
   955                 HTI_LOG_FORMAT("The min optical zoom value is %d", iInfo->iMinZoom);
       
   956                 if(iInfo->iMinZoom == iInfo->iMaxZoom)
       
   957                     {
       
   958                     User::Leave(KErrNotSupported);
       
   959                     }
       
   960                 User::Leave( KErrArgument );
       
   961                 }
       
   962             // Set OPTICAL zoom value.
       
   963             iCamera->SetZoomFactorL( aZoomValue );
       
   964             iZoomValue = aZoomValue;
       
   965             break;
       
   966         default:
       
   967             // EZoomModeOpticalDigital not supported
       
   968             HTI_LOG_FORMAT("CEngineVideoRecording::SetZoomValueL leaving KErrNotSupported, iZoomMode=%d", iZoomMode );
       
   969             User::Leave( KErrNotSupported );
       
   970             break;
       
   971         }
       
   972 
       
   973     HTI_LOG_FUNC_OUT("CEngineVideoRecording::SetZoomValueL");
       
   974     }
       
   975 
       
   976 
       
   977 TInt CEngineVideoRecording::ZoomValue() const
       
   978     {
       
   979     HTI_LOG_FUNC_IN("CEngineVideoRecording::ZoomValue");
       
   980     
       
   981     TInt zoomValue( 0 );
       
   982     if ( iPowerOn )
       
   983         {
       
   984         switch ( iZoomMode )
       
   985             {
       
   986             case EZoomModeDigital:
       
   987                 zoomValue = iCamera->DigitalZoomFactor();
       
   988                 break;
       
   989             case EZoomModeOptical:
       
   990                 zoomValue = iCamera->ZoomFactor();
       
   991                 break;
       
   992             default:
       
   993                 // EZoomModeOpticalDigital not supported
       
   994                 break;
       
   995             }
       
   996         }    
       
   997 
       
   998     HTI_LOG_FUNC_OUT("CEngineVideoRecording::ZoomValue");
       
   999     return zoomValue;
       
  1000     }
       
  1001 
       
  1002 TInt CEngineVideoRecording::MaxZoomValue() const
       
  1003     {
       
  1004     HTI_LOG_FUNC_IN("CEngineVideoRecording::MaxZoomValue");
       
  1005     
       
  1006     TInt zoomValue( 0 );
       
  1007     if ( iPowerOn )
       
  1008         {
       
  1009         switch ( iZoomMode )
       
  1010             {
       
  1011             case EZoomModeDigital:
       
  1012                 zoomValue = iInfo->iMaxDigitalZoom;
       
  1013                 break;
       
  1014             case EZoomModeOptical:
       
  1015                 zoomValue = iInfo->iMaxZoom;
       
  1016                 break;
       
  1017             default:
       
  1018                 // EZoomModeOpticalDigital not supported
       
  1019                 break;
       
  1020             }
       
  1021         }
       
  1022         
       
  1023     HTI_LOG_FUNC_OUT("CEngineVideoRecording::MaxZoomValue");
       
  1024     return zoomValue;
       
  1025     }
       
  1026 
       
  1027 TInt CEngineVideoRecording::MinZoomValue() const
       
  1028     {
       
  1029     HTI_LOG_FUNC_IN("CEngineVideoRecording::MinZoomValue");
       
  1030     
       
  1031     TInt zoomValue( 0 );
       
  1032     if ( iPowerOn )
       
  1033         {
       
  1034         switch ( iZoomMode )
       
  1035             {
       
  1036             case EZoomModeDigital:
       
  1037                 zoomValue = 0;
       
  1038                 break;
       
  1039             case EZoomModeOptical:
       
  1040                 zoomValue = iInfo->iMinZoom;
       
  1041                 break;
       
  1042             default:
       
  1043                 // EZoomModeOpticalDigital not supported
       
  1044                 break;
       
  1045             }
       
  1046         }
       
  1047     
       
  1048     HTI_LOG_FUNC_OUT("CEngineVideoRecording::MinZoomValue");
       
  1049     return zoomValue;
       
  1050     }
       
  1051 void CEngineVideoRecording::SetBrightnessL( 
       
  1052     TInt aBrightness )
       
  1053     {
       
  1054     HTI_LOG_FUNC_IN("CEngineVideoRecording::SetBrightnessL");
       
  1055     // Leave if not supported.
       
  1056     if ( !( iInfo->iOptionsSupported & TCameraInfo::EBrightnessSupported ) )
       
  1057         {
       
  1058         HTI_LOG_FORMAT("CEngineVideoRecording::SetBrightnessL leaving KErrNotSupported, aBrightness=%d", aBrightness );
       
  1059         User::Leave( KErrNotSupported );
       
  1060         }
       
  1061 
       
  1062     CheckPowerL();
       
  1063 
       
  1064     iCamera->SetBrightnessL( aBrightness );
       
  1065     iBrightness = aBrightness;
       
  1066 
       
  1067     HTI_LOG_FUNC_OUT("CEngineVideoRecording::SetBrightnessL"); 
       
  1068     }
       
  1069 
       
  1070 
       
  1071 TInt CEngineVideoRecording::Brightness() const
       
  1072     {
       
  1073     HTI_LOG_FUNC_IN("CEngineVideoRecording::Brightness");
       
  1074 
       
  1075     TInt brightness( 0 );
       
  1076     if ( iPowerOn && ( iInfo->iOptionsSupported & TCameraInfo::EBrightnessSupported ) )
       
  1077         {
       
  1078         brightness = iCamera->Brightness();
       
  1079         }
       
  1080     
       
  1081     HTI_LOG_FUNC_OUT("CEngineVideoRecording::Brightness");
       
  1082     return brightness;
       
  1083     }
       
  1084 
       
  1085 
       
  1086 void CEngineVideoRecording::SetContrastL( 
       
  1087     TInt aContrast )
       
  1088     {
       
  1089     HTI_LOG_FUNC_IN("CEngineVideoRecording::SetContrastL");
       
  1090     
       
  1091     // Leave if not supported.
       
  1092     if ( !( iInfo->iOptionsSupported & TCameraInfo::EContrastSupported ) )
       
  1093         {
       
  1094         HTI_LOG_FORMAT("CEngineVideoRecording::SetContrastL leaving KErrNotSupported, aContrast=%d", aContrast );
       
  1095         User::Leave( KErrNotSupported );
       
  1096         }
       
  1097 
       
  1098     CheckPowerL();
       
  1099 
       
  1100     iCamera->SetContrastL( aContrast );
       
  1101     iContrast = aContrast;
       
  1102 
       
  1103     HTI_LOG_FUNC_OUT("CEngineVideoRecording::SetContrastL");
       
  1104     }
       
  1105 
       
  1106 
       
  1107 TInt CEngineVideoRecording::Contrast() const
       
  1108     {
       
  1109     HTI_LOG_FUNC_IN("CEngineVideoRecording::Contrast");
       
  1110     TInt contrast( 0 );
       
  1111     if ( iPowerOn && ( iInfo->iOptionsSupported & TCameraInfo::EContrastSupported ) )
       
  1112         {
       
  1113         contrast = iCamera->Contrast();
       
  1114         }
       
  1115     
       
  1116     HTI_LOG_FUNC_OUT("CEngineVideoRecording::Contrast");
       
  1117     return contrast;
       
  1118     }
       
  1119 
       
  1120 
       
  1121 void CEngineVideoRecording::SetExposureModeL( 
       
  1122     CCamera::TExposure aExposureMode )
       
  1123     {
       
  1124     HTI_LOG_FUNC_IN("CEngineVideoRecording::SetExposureModeL");
       
  1125 
       
  1126     // Leave is requested exposure mode is not supported, 
       
  1127     // EExposureAuto should be always supported.
       
  1128     if ( ( ( aExposureMode != CCamera::EExposureAuto ) && 
       
  1129           !( aExposureMode & iInfo->iExposureModesSupported ) ) ||
       
  1130            ( aExposureMode < 0 ) )
       
  1131         {
       
  1132         HTI_LOG_FORMAT("CEngineVideoRecording::SetExposureModeL leaving KErrNotSupported, aExposureMode=%d", aExposureMode );
       
  1133         User::Leave( KErrNotSupported );
       
  1134         }
       
  1135 
       
  1136     CheckPowerL();
       
  1137 
       
  1138     iCamera->SetExposureL( aExposureMode );
       
  1139     iExposureMode = aExposureMode;
       
  1140     
       
  1141     HTI_LOG_FUNC_OUT("CEngineVideoRecording::SetExposureModeL");
       
  1142     }
       
  1143 
       
  1144 
       
  1145 CCamera::TExposure CEngineVideoRecording::ExposureMode() const
       
  1146     {
       
  1147     HTI_LOG_FUNC_IN("CEngineVideoRecording::ExposureMode");
       
  1148 
       
  1149     CCamera::TExposure exposureMode( CCamera::EExposureAuto );
       
  1150     if ( iPowerOn )
       
  1151         {
       
  1152         exposureMode = iCamera->Exposure();
       
  1153         }
       
  1154     
       
  1155     HTI_LOG_FUNC_OUT("CEngineVideoRecording::ExposureMode");
       
  1156     return exposureMode;
       
  1157     }
       
  1158 
       
  1159 
       
  1160 void CEngineVideoRecording::SetWhiteBalanceModeL( 
       
  1161     CCamera::TWhiteBalance aWhiteBalanceMode )
       
  1162     {
       
  1163     HTI_LOG_FUNC_IN("CEngineVideoRecording::SetWhiteBalanceModeL");
       
  1164 
       
  1165     // Leave is requested WB mode is not supported. 
       
  1166     // EWBAuto is always supported.
       
  1167     if ( ( ( aWhiteBalanceMode != CCamera::EWBAuto ) && 
       
  1168           !( aWhiteBalanceMode & iInfo->iWhiteBalanceModesSupported ) ) ||
       
  1169            ( aWhiteBalanceMode < 0 ) )
       
  1170         {
       
  1171         HTI_LOG_FORMAT("CEngineVideoRecording::SetWhiteBalanceModeL leaving KErrNotSupported, aWhiteBalanceMode=%d", aWhiteBalanceMode );
       
  1172         User::Leave( KErrNotSupported );
       
  1173         }
       
  1174     
       
  1175     CheckPowerL();
       
  1176 
       
  1177     iCamera->SetWhiteBalanceL( aWhiteBalanceMode );
       
  1178     iWhiteBalanceMode = aWhiteBalanceMode;
       
  1179 
       
  1180     HTI_LOG_FUNC_OUT("CEngineVideoRecording::SetWhiteBalanceModeL");
       
  1181     }
       
  1182 
       
  1183 
       
  1184 CCamera::TWhiteBalance CEngineVideoRecording::WhiteBalanceMode() const
       
  1185     {
       
  1186     HTI_LOG_FUNC_IN("CEngineVideoRecording::WhiteBalanceMode");
       
  1187 
       
  1188     CCamera::TWhiteBalance whiteBalanceMode( CCamera::EWBAuto );
       
  1189     if ( iPowerOn )
       
  1190         {
       
  1191         whiteBalanceMode = iCamera->WhiteBalance();
       
  1192         }
       
  1193     
       
  1194     HTI_LOG_FUNC_OUT("CEngineVideoRecording::WhiteBalanceMode");
       
  1195     return whiteBalanceMode;
       
  1196     }
       
  1197 
       
  1198 
       
  1199 void CEngineVideoRecording::SetFlashModeL( 
       
  1200     CCamera::TFlash aFlashMode )
       
  1201     {
       
  1202     HTI_LOG_FUNC_IN("CEngineVideoRecording::SetFlashModeL");
       
  1203     
       
  1204     // Leave is requested flash mode is not supported. 
       
  1205     // EFlashNone is always supported.
       
  1206     if ( ( ( aFlashMode != CCamera::EFlashNone ) && 
       
  1207           !( aFlashMode & iInfo->iFlashModesSupported ) ) || 
       
  1208            ( aFlashMode < 0 ) )
       
  1209         {
       
  1210         HTI_LOG_FORMAT("CEngineVideoRecording::SetFlashModeL leaving KErrNotSupported, aFlashMode=%d", aFlashMode );
       
  1211         User::Leave( KErrNotSupported );
       
  1212         }
       
  1213 
       
  1214     CheckPowerL();
       
  1215 
       
  1216     iCamera->SetFlashL( aFlashMode );
       
  1217     iFlashMode = aFlashMode;
       
  1218 
       
  1219     HTI_LOG_FUNC_OUT("CEngineVideoRecording::SetFlashModeL");
       
  1220     }
       
  1221 
       
  1222 
       
  1223 CCamera::TFlash CEngineVideoRecording::FlashMode() const
       
  1224     {
       
  1225     HTI_LOG_FUNC_IN("CEngineVideoRecording::FlashMode");
       
  1226 
       
  1227     CCamera::TFlash flashMode( CCamera::EFlashNone );
       
  1228     if ( iPowerOn )
       
  1229         {
       
  1230         flashMode = iCamera->Flash();
       
  1231         }
       
  1232     
       
  1233     HTI_LOG_FUNC_OUT("CEngineVideoRecording::FlashMode");
       
  1234     return flashMode;
       
  1235     }
       
  1236 
       
  1237 
       
  1238 void CEngineVideoRecording::ResetToDefaultsL()
       
  1239     {
       
  1240     HTI_LOG_FUNC_IN("CEngineVideoRecording::ResetToDefaultsL");
       
  1241 
       
  1242     SetExposureModeL();
       
  1243     SetWhiteBalanceModeL();
       
  1244     SetZoomModeL();
       
  1245     SetZoomValueL();
       
  1246     SetFlashModeL();
       
  1247 
       
  1248     // Reset this setting only if it is supported by Camera API.
       
  1249     if ( iInfo->iOptionsSupported & TCameraInfo::EBrightnessSupported )
       
  1250         {
       
  1251         SetBrightnessL();
       
  1252         }
       
  1253 
       
  1254     // Reset this setting only if it is supported by Camera API.
       
  1255     if ( iInfo->iOptionsSupported & TCameraInfo::EContrastSupported )
       
  1256         {
       
  1257         SetContrastL();
       
  1258         }
       
  1259 
       
  1260     HTI_LOG_FUNC_OUT("CEngineVideoRecording::ResetToDefaultsL");
       
  1261     }
       
  1262 
       
  1263 void CEngineVideoRecording::CheckPowerL()
       
  1264     {
       
  1265     if ( !iPowerOn ) 
       
  1266         {
       
  1267         HTI_LOG_TEXT("CEngineVideoRecording::CheckPowerL() leaving KErrNotReady (iPowerOn)");
       
  1268         User::Leave( KErrNotReady );
       
  1269         }
       
  1270     }
       
  1271 
       
  1272 void CEngineVideoRecording::MvruoOpenComplete(TInt aError)
       
  1273     {
       
  1274     HTI_LOG_FUNC_IN("CEngineVideoRecording::MvruoOpenComplete");
       
  1275 
       
  1276     HTI_LOG_FORMAT("aError = %d", aError);
       
  1277     if ( aError == KErrNone )
       
  1278         {
       
  1279         // To get default video audio bit rate.
       
  1280         TRAP( aError, { iVideoAudioBitRate = iVideoRecorder->AudioBitRateL(); } );
       
  1281         // (ignore possible error)
       
  1282         // Prepare settings only if no errors in opening.
       
  1283         TRAP( aError, PrepareVideoSettingsL() );
       
  1284         if ( aError != KErrNone ) 
       
  1285             {
       
  1286             iVideoRecordingObserver->MevroVideoPrepareComplete( aError );
       
  1287             }
       
  1288         }
       
  1289     else
       
  1290         {
       
  1291         iVideoRecordingObserver->MevroVideoPrepareComplete( aError );
       
  1292         }
       
  1293 
       
  1294     HTI_LOG_FUNC_OUT("CEngineVideoRecording::MvruoOpenComplete");
       
  1295     }
       
  1296 
       
  1297 void CEngineVideoRecording::MvruoPrepareComplete(TInt aError)
       
  1298     {
       
  1299     HTI_LOG_FUNC_IN("CEngineVideoRecording::MvruoPrepareComplete");
       
  1300 
       
  1301     HTI_LOG_FORMAT("aError = %d", aError);
       
  1302     if ( iVideoOpened && ( aError == KErrNone ) )
       
  1303         {
       
  1304         iVideoPrepared = ETrue; // Later errors with settings after 
       
  1305                                 // do not change the value.
       
  1306         }
       
  1307 
       
  1308     if ( iPrepPars )
       
  1309         {
       
  1310         iPrepPars = EFalse;
       
  1311         // If no error, then fresh parameters are valid.
       
  1312         // Otherwise, old parameters are kept.
       
  1313         if ( aError == KErrNone )
       
  1314             {
       
  1315             *iVideoFrameSize    = *iVideoFrameSizePrep;
       
  1316             iVideoFrameRate     = iVideoFrameRatePrep;
       
  1317             iVideoBitRate       = iVideoBitRatePrep;
       
  1318             iVideoAudioEnabled  = iVideoAudioEnabledPrep;
       
  1319             iVideoAudioBitRate  = iVideoAudioBitRatePrep;
       
  1320             iMaxClipSizeInBytes = iMaxClipSizeInBytesPrep;
       
  1321             }
       
  1322         else 
       
  1323             {
       
  1324             *iVideoFrameSizePrep    = *iVideoFrameSize;
       
  1325             iVideoFrameRatePrep     = iVideoFrameRate;
       
  1326             iVideoBitRatePrep       = iVideoBitRate;
       
  1327             iVideoAudioEnabledPrep  = iVideoAudioEnabled;
       
  1328             iVideoAudioBitRatePrep  = iVideoAudioBitRate;
       
  1329             iMaxClipSizeInBytesPrep = iMaxClipSizeInBytes;
       
  1330             }
       
  1331         }
       
  1332 
       
  1333     iVideoRecordingObserver->MevroVideoPrepareComplete( aError );
       
  1334 
       
  1335     HTI_LOG_FUNC_OUT("CEngineVideoRecording::MvruoPrepareComplete");
       
  1336     }
       
  1337 
       
  1338 void CEngineVideoRecording::MvruoRecordComplete(TInt aError)
       
  1339     {
       
  1340     HTI_LOG_FUNC_IN("CEngineVideoRecording::MvruoRecordComplete");
       
  1341 
       
  1342     HTI_LOG_FORMAT("aError = %d", aError);    
       
  1343 
       
  1344     // Recording stopped: can't be paused anymore.
       
  1345     iVideoRecordingPaused = EFalse; 
       
  1346         
       
  1347     if ( iVideoRecordingRunning) // To ensure that McaeoVideoRecordingComplete 
       
  1348         {                                                   // gets called just once per recording.
       
  1349         iVideoRecordingRunning = EFalse;
       
  1350         
       
  1351         // Close video recording always in error case. Otherwise the camcorder plugin would
       
  1352         // be in indeterminated state. 
       
  1353         // The code KErrCompletion means that video reocording has been completed by timer
       
  1354         if ( aError && aError != KErrCompletion && aError != KErrDiskFull ) 
       
  1355             { 
       
  1356             CloseVideoRecording();
       
  1357             }
       
  1358             
       
  1359         iVideoRecordingObserver->MevroVideoRecordingComplete( aError );
       
  1360         }
       
  1361     
       
  1362     HTI_LOG_FUNC_IN("CEngineVideoRecording::MvruoRecordComplete");
       
  1363     }
       
  1364 
       
  1365 void CEngineVideoRecording::MvruoEvent(const TMMFEvent& /*aEvent*/)
       
  1366     {
       
  1367     HTI_LOG_FUNC_IN("CEngineVideoRecording::MvruoEvent");
       
  1368     HTI_LOG_FUNC_OUT("CEngineVideoRecording::MvruoEvent");
       
  1369     }
       
  1370 
       
  1371 void CEngineVideoRecording::ReserveComplete(                                 
       
  1372     TInt aError )
       
  1373     {
       
  1374     HTI_LOG_FUNC_IN("CEngineVideoRecording::ReserveComplete");
       
  1375 
       
  1376     if ( aError == KErrNone )
       
  1377         {
       
  1378         iReserved = ETrue;
       
  1379         PowerOn();
       
  1380         }
       
  1381     else
       
  1382         {
       
  1383         iVideoRecordingObserver->MevroInitComplete( aError );
       
  1384         }
       
  1385 
       
  1386     HTI_LOG_FUNC_OUT("CEngineVideoRecording::ReserveComplete");
       
  1387     }
       
  1388 
       
  1389 
       
  1390 void CEngineVideoRecording::PowerOnComplete( 
       
  1391     TInt aError )
       
  1392     {
       
  1393     HTI_LOG_FUNC_IN("CEngineVideoRecording::PowerOnComplete");
       
  1394 
       
  1395     if ( aError == KErrNone ) 
       
  1396         {
       
  1397         iPowerOn = ETrue;
       
  1398         }
       
  1399     
       
  1400     iVideoRecordingObserver->MevroInitComplete( aError );
       
  1401 
       
  1402     HTI_LOG_FUNC_OUT("CEngineVideoRecording::PowerOnComplete");
       
  1403     }
       
  1404 
       
  1405 void CEngineVideoRecording::HandleEvent( const TECAMEvent& aEvent)
       
  1406     {
       
  1407     HTI_LOG_FUNC_IN("CEngineVideoRecording::HandleEvent");
       
  1408     if (aEvent.iEventType == KUidECamEventCameraNoLongerReserved)
       
  1409         {
       
  1410         HTI_LOG_TEXT("CEngineVideoRecording::HandleEvent() KUidECamEventCameraNoLongerReserved");
       
  1411         iPowerOn = EFalse;
       
  1412         iReserved = EFalse;
       
  1413         iVideoPrepared = EFalse;
       
  1414         iVideoOpened = EFalse;
       
  1415         iVideoRecordingObserver->MevroInitComplete(KErrInUse); // Tell the client that other application has taken the camera
       
  1416         }
       
  1417     else if (aEvent.iEventType == KUidECamEventPowerOnComplete)
       
  1418         {
       
  1419         HTI_LOG_TEXT("CEngineVideoRecording::HandleEvent() KUidECamEventPowerOnComplete");
       
  1420         PowerOnComplete(aEvent.iErrorCode);
       
  1421         }
       
  1422     else if (aEvent.iEventType == KUidECamEventReserveComplete)
       
  1423         {
       
  1424         HTI_LOG_TEXT("CEngineVideoRecording::HandleEvent() KUidECamEventReserveComplete");
       
  1425         ReserveComplete(aEvent.iErrorCode);
       
  1426         }
       
  1427     
       
  1428     HTI_LOG_FUNC_OUT("CEngineVideoRecording::HandleEvent");
       
  1429     }