htiui/HtiServicePlugins/HtiCameraServicePlugin/engine/inc/EngineVideoRecording.h
branchRCL_3
changeset 13 822c625f7adc
child 19 d40e813b23c0
equal deleted inserted replaced
11:454d022d514b 13:822c625f7adc
       
     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:  Video recording engine implementation class.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef ENGINEVIDEORECORDING_H
       
    19 #define ENGINEVIDEORECORDING_H
       
    20 
       
    21 //  INCLUDES
       
    22 #include <ecam.h>
       
    23 #include <videorecorder.h>
       
    24 #include <e32std.h>
       
    25 
       
    26 // CONSTANTS
       
    27 const TInt KCameraPriority = -1; // Relative priority (-100...100) of camera HW
       
    28 
       
    29 // FORWARD DECLARATIONS
       
    30 class CVideoRecorderUtility;
       
    31 class CVideoRecordingQualityLevels;
       
    32 
       
    33 
       
    34 class TEngineVideoRecordingInfo
       
    35     {
       
    36     public:
       
    37 
       
    38         // Camera hardware version present.
       
    39         TVersion iHardwareVersion;
       
    40         // Camera driver software version present.
       
    41         TVersion iSoftwareVersion;
       
    42         // Actual orientation of the camera.
       
    43         TCameraInfo::TCameraOrientation iOrientation;
       
    44 
       
    45         // Bitfield of CCamera::TOptions available. 
       
    46         TUint32 iOptionsSupported;
       
    47         // Bitfield of CCamera::TFlash modes available.
       
    48         TUint32 iFlashModesSupported;
       
    49         // Bitfield of CCamera::TExposure modes available.
       
    50         TUint32 iExposureModesSupported;
       
    51         // Bitfield of CCamera::TWhiteBalance modes available.
       
    52         TUint32 iWhiteBalanceModesSupported;
       
    53 
       
    54         // Minimum zoom value allowed. Must be negative or 
       
    55         // zero (for not supported).
       
    56         TInt iMinZoom;
       
    57         // Maximum zoom value allowed. Must be positive or 
       
    58         // zero (for not supported).
       
    59         TInt iMaxZoom;
       
    60         // Maximum digital zoom value allowed. Must be positive or 
       
    61         // zero (for not supported).
       
    62         TInt iMaxDigitalZoom;
       
    63 
       
    64         // Image size multiplier corresponding to minimum zoom value. 
       
    65         // Must be between 0 and 1 inclusive.
       
    66         TReal32 iMinZoomFactor;
       
    67         // Image size multiplier corresponding to maximum zoom value. 
       
    68         // Must be greater than or equal to 1.
       
    69         TReal32 iMaxZoomFactor;
       
    70         // Image size multiplier corresponding to maximum digital zoom value. 
       
    71         // Must be greater than or equal to 1.
       
    72         TReal32 iMaxDigitalZoomFactor;
       
    73 
       
    74         // Count of still image capturing sizes allowed.
       
    75         TInt iNumImageSizesSupported;
       
    76         // Bitfield of still image CCamera::TFormat values supported.
       
    77         TUint32 iImageFormatsSupported;
       
    78     
       
    79         // Count of still image capturing quality levels initialized.
       
    80         TInt iNumStillQualityLevelsSupported;
       
    81         // Count of video recording quality levels initialized.
       
    82         TInt iNumVideoQualityLevelsSupported;
       
    83 
       
    84         // Bitfield of CCaeEngine::TOptions available. 
       
    85         TUint32 iCaeOptionsSupported;
       
    86 
       
    87         // Integer (e.g. -9) that corresponds to minimum EV compensation value.
       
    88         TInt iMinEvCompensation;
       
    89         // Integer (e.g. 9) that corresponds to maximum EV compensation value.
       
    90         TInt iMaxEvCompensation;
       
    91         // Minimum camera EV compensation value (e.g. -3.0).
       
    92         TReal32 iMinEvCompensationValue;
       
    93         // Maximum camera EV compensation value (e.g. 3.0).
       
    94         TReal32 iMaxEvCompensationValue;
       
    95     };
       
    96 
       
    97 class MEngineVideoRecordingObserver
       
    98     {
       
    99 
       
   100     public:
       
   101         /**
       
   102         * Called asynchronously when CEngineVideoRecording::Init(), CCaeEngine::CEngineVideoRecording(), 
       
   103         * or CEngineVideoRecording::Reserve() completes.
       
   104         * Indicates if Video Recording Engine is ready for operation, 
       
   105         * the camera is reserved and its power is switched on.
       
   106         * @param aError Error code KErrNone to indicate success or a standard Symbian OS error code.
       
   107         * @return void
       
   108         */
       
   109         virtual void MevroInitComplete( TInt aError ) = 0;
       
   110     
       
   111         /**
       
   112         * Called asynchronously when preparing of video recording completes 
       
   113         * after PrepareVideoRecordingL() has been called.
       
   114         * May be called second time with an error code after a successful preparation 
       
   115         * if video recording loses its prepared state for some reason (e.g. audio HW 
       
   116         * is reserved for some other application).
       
   117         * @param aError Error code KErrNone to indicate success or a standard Symbian OS error code.
       
   118         * @return void
       
   119         */
       
   120         virtual void MevroVideoPrepareComplete( TInt aError ) = 0;
       
   121 
       
   122         /**
       
   123         * Called (possibly asynchronously) when video recording is running 
       
   124         * after CEngineVideoRecording::StartVideoRecording() or 
       
   125         * CEngineVideoRecording::ResumeVideoRecording() has been called.
       
   126         * @param aError Error code KErrNone to indicate success or a standard Symbian OS error code.
       
   127         * @return void
       
   128         */
       
   129         virtual void MevroVideoRecordingOn( TInt aError ) = 0;
       
   130 
       
   131         /**
       
   132         * Called (possibly asynchronously) when video recording is paused after 
       
   133         * CEngineVideoRecording::PauseVideoRecording() has been called.
       
   134         * @param aError Error code KErrNone to indicate success or a standard Symbian OS error code.
       
   135         * @return void
       
   136         */
       
   137         virtual void MevroVideoRecordingPaused( TInt aError ) = 0;
       
   138 
       
   139         /**
       
   140         * Called (possibly asynchronously) when video recording is completed 
       
   141         * after CEngineVideoRecording::StopVideoRecording() has been called or 
       
   142         * recording has been completed for some other reason.
       
   143         * @param aError Error code KErrNone to indicate success or a standard Symbian OS error code.
       
   144         * if aError == KErrDiskFull, then disk storage is full.
       
   145         * if aError == KErrCompletion, then clip max size was reached.
       
   146         * @return void
       
   147         */
       
   148         virtual void MevroVideoRecordingComplete( TInt aError ) = 0;
       
   149     };
       
   150 
       
   151 
       
   152 NONSHARABLE_CLASS( CEngineVideoRecording ) : public CBase,
       
   153         public MVideoRecorderUtilityObserver,
       
   154         public MCameraObserver,
       
   155         public MCameraObserver2
       
   156     {
       
   157     public:
       
   158     // Possible zooming modes.
       
   159     enum TZoomMode
       
   160         {
       
   161         EZoomModeDigital        = 0x00, // Digital zoom (default).
       
   162         EZoomModeOptical        = 0x01, // Optical zoom.
       
   163         EZoomModeOpticalDigital = 0x02  // Optical+digital zoom.
       
   164         };
       
   165     
       
   166     public:
       
   167         /**
       
   168         * Destructor.
       
   169         */
       
   170         virtual ~CEngineVideoRecording();
       
   171         
       
   172         // Construction and destruction
       
   173         static CEngineVideoRecording* NewL(MEngineVideoRecordingObserver& aObserver,
       
   174                 TInt aCameraIndex);
       
   175         
       
   176         void InitL();
       
   177         
       
   178         void InitVideoRecorderL();
       
   179     
       
   180         void SetVideoRecordingFileNameL( 
       
   181             const TDesC& aVideoClipFileName );
       
   182         
       
   183         void ChangeVideoFileNameL();
       
   184         
       
   185         void PrepareVideoRecordingL( 
       
   186             TInt aVideoQualityIndex );
       
   187 
       
   188         void PrepareVideoRecordingL( 
       
   189             const TSize&  aFrameSize, 
       
   190             TReal32       aFrameRate, 
       
   191             TInt          aBitRate, 
       
   192             TBool         aAudioEnabled,
       
   193             const TDesC8& aMimeType, 
       
   194             const TDesC&  aPreferredSupplier, 
       
   195             const TDesC8& aVideoType = KNullDesC8, 
       
   196             const TDesC8& aAudioType = KNullDesC8 );
       
   197 
       
   198         void PrepareVideoRecordingL( 
       
   199             const TSize&  aFrameSize, 
       
   200             TReal32       aFrameRate, 
       
   201             TInt          aBitRate, 
       
   202             TBool         aAudioEnabled,
       
   203             TInt          aAudioBitRate, 
       
   204             const TDesC8& aMimeType, 
       
   205             const TDesC&  aPreferredSupplier, 
       
   206             const TDesC8& aVideoType, 
       
   207             const TDesC8& aAudioType );
       
   208         
       
   209         void CloseVideoRecording();
       
   210 
       
   211         TInt VideoQualityIndex() const;
       
   212         
       
   213         TInt VideoQualityCount() const;
       
   214 
       
   215         void GetVideoFrameSize( 
       
   216             TInt   aVideoQualityIndex, 
       
   217             TSize& aSize ) const;
       
   218 
       
   219         TReal32 VideoFrameRate( 
       
   220             TInt aVideoQualityIndex ) const;
       
   221 
       
   222         TInt EstimatedVideoRecordingBitRateL( 
       
   223             TInt aVideoQualityIndex ) const;
       
   224 
       
   225         void SetVideoClipMaxSizeL( 
       
   226             TInt aMaxClipSizeInBytes = 0 );
       
   227 
       
   228         TInt VideoClipMaxSize() const;
       
   229 
       
   230         void SetVideoAudioL( 
       
   231             TBool aAudioEnabled );
       
   232 
       
   233         TBool VideoAudio() const;
       
   234 
       
   235         void StartVideoRecording();
       
   236 
       
   237         void StopVideoRecording();
       
   238 
       
   239         void PauseVideoRecording();
       
   240 
       
   241         void ResumeVideoRecording();
       
   242 
       
   243         TTimeIntervalMicroSeconds RemainingVideoRecordingTime() const;
       
   244 
       
   245         TBool IsVideoRecording() const;
       
   246         
       
   247         void Reserve();
       
   248 
       
   249         void Release();
       
   250 
       
   251         void PowerOn();
       
   252 
       
   253         void PowerOff();
       
   254     
       
   255         void SetZoomModeL(TZoomMode aZoomMode = EZoomModeDigital);
       
   256     
       
   257         TZoomMode ZoomMode() const;
       
   258     
       
   259         void SetZoomValueL(TInt aZoomValue = 0);
       
   260     
       
   261         TInt ZoomValue() const;
       
   262         
       
   263         TInt MaxZoomValue() const;
       
   264         TInt MinZoomValue() const;
       
   265     
       
   266         void SetBrightnessL(TInt aBrightness = 0);
       
   267     
       
   268         TInt Brightness() const;
       
   269     
       
   270         void SetContrastL(TInt aContrast = 0);
       
   271     
       
   272         TInt Contrast() const;
       
   273     
       
   274         void SetExposureModeL(CCamera::TExposure aExposureMode =
       
   275                 CCamera::EExposureAuto);
       
   276     
       
   277         CCamera::TExposure ExposureMode() const;
       
   278     
       
   279         void SetWhiteBalanceModeL(CCamera::TWhiteBalance aWhiteBalanceMode =
       
   280                 CCamera::EWBAuto);
       
   281     
       
   282         CCamera::TWhiteBalance WhiteBalanceMode() const;
       
   283     
       
   284         void SetFlashModeL(CCamera::TFlash aFlashMode = CCamera::EFlashNone);
       
   285     
       
   286         CCamera::TFlash FlashMode() const;
       
   287     
       
   288         void ResetToDefaultsL();
       
   289     private:
       
   290         void InitializeInfo(const CCamera& aCamera);
       
   291     
       
   292         /**
       
   293          * Checks that power is on. If not, then leaves.
       
   294          * @since 2.1
       
   295          * @return void
       
   296          */
       
   297         void CheckPowerL();
       
   298     
       
   299         void CancelVideoRecording();
       
   300     
       
   301         void PrepareVideoSettingsL();
       
   302     
       
   303         void FindVideoUidsL(const TDesC8& aMimeType,
       
   304                 const TDesC& aPreferredSupplier);
       
   305     
       
   306         TFourCC ConvertAndSetVideoAudioTypeL(const TDesC8& aAudioType);
       
   307     
       
   308     private:    
       
   309         
       
   310         /**
       
   311          * From MVideoRecorderUtilityObserver
       
   312          * Notification to the client that the opening of the video clip has completed,
       
   313          * successfully, or otherwise.
       
   314          * @param  aError
       
   315          *          The status of the video recorder after initialisation.
       
   316          *          This is either KErrNone if the open has completed successfully,
       
   317          *          or one of the system wide error codes.
       
   318          */
       
   319         virtual void MvruoOpenComplete(TInt aError);  
       
   320 
       
   321         /**
       
   322          * From MVideoRecorderUtilityObserver
       
   323          * Notification that video recorder is ready to begin recording. This callback
       
   324          * is generated in response to a call to Prepare.
       
   325          * @param  aError
       
   326          *          This is either KErrNone if the video recorder has been prepared for
       
   327          *          recording successfully, or one of the system wide error codes
       
   328          */
       
   329         virtual void MvruoPrepareComplete(TInt aError);
       
   330 
       
   331         /**
       
   332          * From MVideoRecorderUtilityObserver
       
   333          * Notification that video recording has completed. This is not called if
       
   334          * recording is explicitly stopped by calling Stop.
       
   335          * @param  aError
       
   336          *          This is either KErrNone if recording was completed successfully,
       
   337          *          or one of the system wide error codes.
       
   338          */
       
   339         virtual void MvruoRecordComplete(TInt aError);
       
   340 
       
   341         /**
       
   342          * From MVideoRecorderUtilityObserver
       
   343          * General event notification from controller. These events are specified by
       
   344          * the supplier of the controller.
       
   345          * @param  aEvent
       
   346          * The event sent by the controller.
       
   347          */
       
   348         virtual void MvruoEvent(const TMMFEvent& aEvent);
       
   349         
       
   350     private: // From Camera Observer / ECam.h
       
   351 
       
   352         void ReserveComplete( 
       
   353             TInt aError );
       
   354 
       
   355         void PowerOnComplete( 
       
   356             TInt aError );
       
   357 
       
   358         void ViewFinderFrameReady( 
       
   359             CFbsBitmap& aFrame ){};
       
   360 
       
   361         void ImageReady( 
       
   362             CFbsBitmap* aBitmap, 
       
   363             HBufC8*     aData, 
       
   364             TInt        aError ){};
       
   365 
       
   366         void FrameBufferReady( 
       
   367             MFrameBuffer* /*aFrameBuffer*/, 
       
   368             TInt          /*aError*/ ) {}; // Empty default because not in use.
       
   369         
       
   370     private: // From Camera Observer2 / ECam.h
       
   371         
       
   372         void HandleEvent(const TECAMEvent& aEvent);
       
   373 
       
   374         void ViewFinderReady(MCameraBuffer& aCameraBuffer,TInt aError){};
       
   375 
       
   376         void ImageBufferReady(MCameraBuffer& aCameraBuffer,TInt aError){};
       
   377     
       
   378         void VideoBufferReady(MCameraBuffer& aCameraBuffer,TInt aError){};
       
   379     protected:  
       
   380 
       
   381         /**
       
   382         * C++ default constructor.
       
   383         */
       
   384         CEngineVideoRecording();
       
   385 
       
   386         /**
       
   387         * 2nd phase constructor.
       
   388         */
       
   389         void ConstructL(MEngineVideoRecordingObserver& aObserver,
       
   390                 TInt aCameraIndex);
       
   391 
       
   392     private:
       
   393         // Camera API implementation object.
       
   394         CCamera* iCamera;
       
   395         
       
   396         // Video Recorder API implementation object.
       
   397         CVideoRecorderUtility* iVideoRecorder;
       
   398         
       
   399         // Video Recording observer
       
   400         MEngineVideoRecordingObserver* iVideoRecordingObserver;
       
   401     
       
   402         // Video Recording Engine info object.
       
   403         TEngineVideoRecordingInfo* iInfo;
       
   404         
       
   405         // Video recording quality levels container.
       
   406         CVideoRecordingQualityLevels* iVideoQualityLevels;
       
   407         
       
   408         // Video recording frame size.
       
   409         // This is ptr because video recorder is not necessarily initialized.
       
   410         TSize* iVideoFrameSize;
       
   411 
       
   412         // Video recording frame size (to be prepared).
       
   413         // This is ptr because video recorder is not necessarily initialized.
       
   414         TSize* iVideoFrameSizePrep;
       
   415 
       
   416         // Video clip file name.
       
   417         HBufC* iVideoClipFileName;
       
   418         
       
   419         // Video Recorder video type.
       
   420         HBufC8* iVideoType;
       
   421         
       
   422         // Boolean indicating if camera module is reserved for the engine.
       
   423         TBool iReserved;
       
   424 
       
   425         // Boolean indicating if camera module power is on.
       
   426         TBool iPowerOn;
       
   427         
       
   428         // Boolean indicating if video recording is initialized.
       
   429         TBool iVideoInitialized;
       
   430     
       
   431         // Boolean indicating if video recording is opened.
       
   432         TBool iVideoOpened;
       
   433     
       
   434         // Boolean indicating if video recording is prepared.
       
   435         TBool iVideoPrepared;
       
   436         
       
   437         // Boolean indicating if video recording is currently running.
       
   438         TBool iVideoRecordingRunning;
       
   439 
       
   440         // Boolean indicating if video recording is currently paused.
       
   441         TBool iVideoRecordingPaused;
       
   442         
       
   443         // Video recording quality level index currently prepared.
       
   444         TInt iVideoQualityIndex;
       
   445 
       
   446         // Handle to the camera used.
       
   447         TInt iCameraHandle;
       
   448 
       
   449         // Video Recorder controller UID.
       
   450         TUid iVideoControllerUid;
       
   451 
       
   452         // Video Recorder format UID.
       
   453         TUid iVideoFormatUid;
       
   454 
       
   455         // Video Recorder audio type.
       
   456         TFourCC iVideoAudioType;
       
   457 
       
   458         //// Camera module settings related variables. ////
       
   459 
       
   460             // Current zoom mode.
       
   461             TZoomMode iZoomMode;
       
   462 
       
   463             // Current zoom value.
       
   464             TInt iZoomValue;
       
   465 
       
   466             // Current brightness value.
       
   467             TInt iBrightness;
       
   468 
       
   469             // Current contrast value.
       
   470             TInt iContrast;
       
   471 
       
   472             // Camera exposure mode.
       
   473             CCamera::TExposure iExposureMode;
       
   474 
       
   475             // Camera white balance mode.
       
   476             CCamera::TWhiteBalance iWhiteBalanceMode;
       
   477 
       
   478             // Camera flash mode.
       
   479             CCamera::TFlash iFlashMode;
       
   480     //// Video recording parameters prepared. ////
       
   481         
       
   482         // Video recording frame rate.
       
   483         TReal32 iVideoFrameRate;
       
   484 
       
   485         // Video recording bit rate.
       
   486         TInt iVideoBitRate;
       
   487 
       
   488         // Boolean indicating if audio is enabled with video recording.
       
   489         TBool iVideoAudioEnabled;
       
   490 
       
   491         // Video recording audio bit rate.
       
   492         TInt iVideoAudioBitRate;
       
   493 
       
   494         // Video recording maximum clip size in bytes.
       
   495         TInt iMaxClipSizeInBytes;
       
   496 
       
   497     //// Video recording parameters to be prepared. ////
       
   498 
       
   499         // Video recording frame rate (to be prepared).
       
   500         TReal32 iVideoFrameRatePrep;
       
   501 
       
   502         // Video recording bit rate (to be prepared).
       
   503         TInt iVideoBitRatePrep;
       
   504 
       
   505         // Boolean indicating if audio is enabled with video recording (to be prepared).
       
   506         TBool iVideoAudioEnabledPrep;
       
   507 
       
   508         // Video recording audio bit rate (to be prepared).
       
   509         TInt iVideoAudioBitRatePrep;
       
   510 
       
   511         // Video recording maximum clip size in bytes (to be prepared).
       
   512         TInt iMaxClipSizeInBytesPrep;
       
   513 
       
   514         // Boolean indicating if parameters are/were prepared in video recording preparation..
       
   515         TBool iPrepPars;
       
   516 
       
   517         // Boolean indicating if video audio bit rate should be prepared.
       
   518         TBool iPrepareVideoAudioBitRate;
       
   519     };
       
   520 
       
   521 
       
   522 
       
   523 
       
   524 #endif //ENGINEVIDEORECORDING_H