videoeditorengine/vedengine/videoprocessor/inc/VideoEncoder.h
changeset 0 951a5db380a0
equal deleted inserted replaced
-1:000000000000 0:951a5db380a0
       
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "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 * Ixonos Plc
       
    14 *
       
    15 * Description:  
       
    16 * Header file for video encoder class.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #ifndef VIDEOENCODER_H
       
    22 #define VIDEOENCODER_H
       
    23 
       
    24 // INCLUDES
       
    25 
       
    26 #include <CCMRMediaSink.h>
       
    27 #include "CTRTranscoderObserver.h"
       
    28 #include "CTRTranscoder.h"
       
    29 #include "CTRCommon.h"
       
    30 #include "CTRVideoPictureSink.h"
       
    31 #include "Vedcommon.h"
       
    32 
       
    33 // FORWARD DECLARATIONS
       
    34 
       
    35 class CStatusMonitor;
       
    36 class CVedVolReader;
       
    37 class CVedAVCEdit;
       
    38 
       
    39 class CVideoEncoder : public CActive, public MTRTranscoderObserver, 
       
    40                       public MCMRMediaSink, public MTRVideoPictureSink
       
    41     {
       
    42 
       
    43     public:  // Constructors and destructor
       
    44         
       
    45         /**
       
    46         * Two-phased constructor.
       
    47         */
       
    48 		static CVideoEncoder* NewL(CStatusMonitor *aMonitor, CVedAVCEdit* aAvcEdit, 
       
    49 		                           const TPtrC8& aVideoMimeType);
       
    50         
       
    51         /**
       
    52         * Destructor.
       
    53         */
       
    54         
       
    55         ~CVideoEncoder();               
       
    56 
       
    57     public:   // Constants        
       
    58         
       
    59         enum TErrorCode
       
    60             {
       
    61             EInternalAssertionFailure = -10030,
       
    62             };
       
    63             
       
    64     public: // Functions from base classes
       
    65 
       
    66         /**
       
    67         * From CActive Active object running method
       
    68         */
       
    69         void RunL();
       
    70         
       
    71         /**
       
    72         * From CActive Active object error method
       
    73         */
       
    74         TInt RunError(TInt aError);
       
    75         
       
    76         /**
       
    77         * From CActive Active object cancelling method
       
    78         */
       
    79         void DoCancel();  
       
    80 
       
    81         /**
       
    82         * From MTRTranscoderObserver
       
    83         */
       
    84         void MtroInitializeComplete(TInt aError);
       
    85         
       
    86         /**
       
    87         * From MTRTranscoderObserver
       
    88         */
       
    89         void MtroFatalError(TInt aError);
       
    90         
       
    91         /**
       
    92         * From MTRTranscoderObserver
       
    93         */
       
    94         void MtroReturnCodedBuffer(CCMRMediaBuffer* aBuffer);
       
    95         
       
    96         /**
       
    97         * From MTRTranscoderObserver
       
    98         */
       
    99         void MtroSetInputFrameRate(TReal& aRate);
       
   100         
       
   101         /**
       
   102         * From MTRTranscoderObserver
       
   103         */
       
   104         void MtroAsyncStopComplete();
       
   105         
       
   106         /**
       
   107         * From MTRTranscoderObserver
       
   108         */
       
   109         inline void MtroSuspend() { };
       
   110         
       
   111         /**
       
   112         * From MTRTranscoderObserver
       
   113         */
       
   114         inline void MtroResume() { };
       
   115         
       
   116         /**	
       
   117         * From MCMRMediaSink
       
   118         */        
       
   119         void WriteBufferL(CCMRMediaBuffer* aBuffer);
       
   120         
       
   121         /**	
       
   122         * From MCMRMediaSink
       
   123         */  
       
   124         TInt SetVideoFrameSize(TSize aSize);
       
   125         
       
   126         /**	
       
   127         * From MCMRMediaSink
       
   128         */  
       
   129         TInt SetAverageVideoBitRate(TInt aBitRate);
       
   130         
       
   131         /**	
       
   132         * From MCMRMediaSink
       
   133         */  
       
   134         TInt SetMaxVideoBitRate(TInt aBitRate);
       
   135         
       
   136         /**	
       
   137         * From MCMRMediaSink
       
   138         */  
       
   139         TInt SetAverageAudioBitRate(TInt aBitRate);
       
   140         
       
   141         /**	
       
   142         * From MTRVideoPictureSink
       
   143         */  
       
   144         void MtroPictureFromTranscoder(TTRVideoPicture* aPicture);
       
   145 
       
   146     public:  // New functions
       
   147 
       
   148         /**
       
   149         * Sets the used frame size
       
   150         * 
       
   151         * @param aSize Frame size 
       
   152         * @return Error codew
       
   153         */
       
   154         void SetFrameSizeL(const TSize& aSize);
       
   155 
       
   156         /**
       
   157         * Gets the current frame size
       
   158         * 
       
   159         * @param aSize Frame size 
       
   160         * @return void
       
   161         */
       
   162         void FrameSize(TSize& aSize) const;
       
   163 
       
   164         /**
       
   165         * Sets the target frame rate
       
   166         * 
       
   167         * @param aFrameRate frame rate
       
   168         * @return Error code
       
   169         */
       
   170         TInt SetFrameRate(const TReal aFrameRate);
       
   171         
       
   172         /**
       
   173         * Sets the frame rate of input sequence
       
   174         * 
       
   175         * @param aFrameRate frame rate
       
   176         * @return Error code
       
   177         */
       
   178         TInt SetInputFrameRate(const TReal aFrameRate);
       
   179         
       
   180         /**
       
   181         * Sets the target random access rate
       
   182         * 
       
   183         * @param aRate random access rate
       
   184         * @return Error code
       
   185         */
       
   186         TInt SetRandomAccessRate(const TReal aRate);
       
   187 
       
   188         /**
       
   189         * Sets the target bitrate
       
   190         * 
       
   191         * @param aBitrate Bitrate 
       
   192         * @return Error code
       
   193         */
       
   194         TInt SetBitrate(const TInt aBitrate);
       
   195         
       
   196         /**
       
   197         * Initializes the encoder
       
   198         * 
       
   199         * @param aStatus Status object for active object
       
   200         * @return void
       
   201         */        
       
   202         void InitializeL(TRequestStatus &aStatus);
       
   203                
       
   204         /**
       
   205         * Encodes a frame
       
   206         * 
       
   207         * @param aYUVFrame Frame to be encoded
       
   208         * @param aStatus Status object for active object
       
   209         * @param Timestamp of the frame
       
   210         * @return void
       
   211         */        
       
   212         void EncodeFrameL(TPtr8 &aYUVFrame, TRequestStatus &aStatus, TTimeIntervalMicroSeconds aTimeStamp);
       
   213         
       
   214         /**
       
   215         * Gets the encoded bitstream
       
   216         *         
       
   217         * @param aKeyFrame Keyframe flag, True if the frame is Intra
       
   218         * @return Descriptor containing the output bitstream
       
   219         */   
       
   220         TPtrC8& GetBufferL(TBool& aKeyFrame);
       
   221 
       
   222         /**
       
   223         * Return used bitstream buffer
       
   224         *         
       
   225         * @return void
       
   226         */         
       
   227         void ReturnBuffer();        
       
   228 
       
   229         /**
       
   230         * Starts the encoder
       
   231         *         
       
   232         * @return void
       
   233         */ 
       
   234         void Start();
       
   235 
       
   236         /**
       
   237         * Stops the encoder
       
   238         *         
       
   239         * @return void
       
   240         */ 
       
   241         void Stop();
       
   242 
       
   243         /**
       
   244         * Resets the encoder
       
   245         *         
       
   246         * @param aStatus Status object for active object
       
   247         * @return void
       
   248         */ 
       
   249         void Reset(TRequestStatus &aStatus);
       
   250         
       
   251         /**
       
   252         * Resets the encoder synchronously
       
   253         *        
       
   254         * @return void
       
   255         */ 
       
   256         void Reset();
       
   257 
       
   258 		/**
       
   259         * Gets status of whether encoding has been started
       
   260         *                 
       
   261         * @return ETrue if encoding has been started
       
   262         */ 
       
   263 		inline TBool BeenStarted() const { return iStarted; }
       
   264 
       
   265 		/**
       
   266         * Gets status of whether encoding request is pending
       
   267         *                 
       
   268         * @return ETrue if encode is pending
       
   269         */ 
       
   270 		inline TBool IsEncodePending() const { return iEncodePending; }
       
   271 
       
   272         /**
       
   273         * Gets time increment resolution used in MPEG-4 
       
   274         *                 
       
   275         * @return Time increment resolution
       
   276         */ 
       
   277         TInt GetTimeIncrementResolution() const;
       
   278         
       
   279         /**
       
   280         * Forces the next encoded frame to be Intra
       
   281         *
       
   282         */ 
       
   283         void SetRandomAccessPoint();
       
   284             
       
   285     private:
       
   286 
       
   287         /**
       
   288         * C++ default constructor.
       
   289         */
       
   290         CVideoEncoder();
       
   291 
       
   292         /**
       
   293         * By default EPOC constructor is private.
       
   294         */
       
   295 		void ConstructL(CStatusMonitor *aMonitor, CVedAVCEdit* aAvcEdit, 
       
   296 		                const TPtrC8& aVideoMimeType);
       
   297 
       
   298         /**
       
   299         * Interpret and store video codec MIME-type, used by ConstructL
       
   300         * @return void
       
   301         */
       
   302         void SetVideoCodecL(const TPtrC8& aMimeType);
       
   303         
       
   304         /**
       
   305         * Set encoding options
       
   306         * @return void
       
   307         */
       
   308         void SetupEncoderL();
       
   309         
       
   310         /**
       
   311         * Parses and writes codec specific information, i.e
       
   312         * MPEG-4 VOL header and AVC decoder configuration record
       
   313         * @return void
       
   314         */
       
   315         void HandleCodingStandardSpecificInfoL();
       
   316 
       
   317     private:    // Data
       
   318     
       
   319         // Transcoder
       
   320         CTRTranscoder* iTranscoder;
       
   321 
       
   322 		// is encode pending ?
       
   323 		TBool iEncodePending;
       
   324 
       
   325 		// has encoding been started ?
       
   326 		TBool iStarted;
       
   327 
       
   328         // used & max frame size, and info if size can be arbitrary
       
   329         TSize iFrameSize;
       
   330         TSize iMaxResolution;
       
   331         TBool iArbitrarySizeAllowed;
       
   332 
       
   333         // target and max allowed frame rate
       
   334         TReal32 iFrameRate;        
       
   335         TReal32 iMaxFrameRate;
       
   336         
       
   337         // input frame rate
       
   338         TReal32 iInputFrameRate;
       
   339         
       
   340         // target random access rate
       
   341         TReal iRandomAccessRate;
       
   342 
       
   343 		// target and max allowed bit rate
       
   344 		TInt iBitRate;
       
   345 		TInt iMaxBitRate;
       
   346 
       
   347         // Mime type for encoded data
       
   348         TBuf8<256> iMimeType;        
       
   349 
       
   350         // input picture         
       
   351         TTRVideoPicture* iInputPicture;     
       
   352         
       
   353         // bitstream buffer
       
   354         HBufC8* iDataBuffer;
       
   355         
       
   356         // keyframe flag for bitstream buffer
       
   357         TBool iKeyFrame;
       
   358         
       
   359         TPtrC8 iReturnDes;
       
   360 
       
   361         // External status info
       
   362         TRequestStatus *iResetRequestStatus;
       
   363 
       
   364 		TRequestStatus *iEncodeRequestStatus;
       
   365 
       
   366         TTimeIntervalMicroSeconds iPreviousTimeStamp;
       
   367 
       
   368         // MPEG-4 time increment resolution
       
   369         TInt iTimeIncrementResolution;        
       
   370 
       
   371         // input YUV data
       
   372         TPtr8 iInputBuffer;
       
   373 
       
   374         // status monitor object
       
   375         CStatusMonitor *iMonitor;
       
   376         
       
   377         // video object layer reader
       
   378         CVedVolReader *iVolReader;
       
   379 
       
   380         RTimer iTimer; // timer object
       
   381         TBool iTimerCreated;
       
   382         TBool iTimerRequestPending;
       
   383         
       
   384         // Timer timeout, depends on codec and resolution
       
   385         TUint iMaxEncodingDelay;
       
   386 
       
   387         // flag to check if devvideorec methods can be called or not; they can't be called after a fatal error 
       
   388         TBool iFatalError;
       
   389 
       
   390 #ifdef _DEBUG
       
   391         TTime iEncodeStartTime;
       
   392 #endif
       
   393         
       
   394         // AVC editing module
       
   395         CVedAVCEdit* iAvcEdit;
       
   396         
       
   397     };
       
   398 
       
   399 
       
   400 
       
   401 #endif