videoeditorengine/vedengine/videoprocessor/inc/videoprocessor.h
branchRCL_3
changeset 3 e0b5df5c0969
parent 0 951a5db380a0
child 5 4c409de21d23
equal deleted inserted replaced
0:951a5db380a0 3:e0b5df5c0969
     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 processor.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #ifndef     __VIDEOPROCESSOR_H__
       
    22 #define     __VIDEOPROCESSOR_H__
       
    23 
       
    24 //  INCLUDES
       
    25 #ifndef _H263DAPI_H_
       
    26 #include "h263dapi.h"
       
    27 #endif
       
    28 
       
    29 #include "videodecoder.h"
       
    30 #include "vedVideoclip.h"
       
    31 
       
    32 
       
    33 //  FORWARD DECLARATIONS
       
    34 class CActiveQueue;
       
    35 class CStatusMonitor;
       
    36 class CMovieProcessorImpl;
       
    37 class CVideoEncoder;
       
    38 class CVedH263Dec;
       
    39 class CMPEG4Timer;
       
    40 class CVedAVCEdit;
       
    41 
       
    42 #include "CTRTranscoderObserver.h"
       
    43 #include "CTRTranscoder.h"
       
    44 #include "CTRCommon.h"
       
    45 #include <CCMRMediaSink.h>
       
    46 #include "CTRVideoPictureSink.h"
       
    47 
       
    48 enum TTransitionColor
       
    49 {
       
    50 	EColorNone = 0,
       
    51 	EColorBlack,
       
    52 	EColorWhite,
       
    53 	EColorTransition
       
    54 };
       
    55 
       
    56 enum TTransitionPosition
       
    57 {
       
    58     EPositionNone = 0,
       
    59     EPositionStartOfClip,
       
    60     EPositionEndOfClip
       
    61 };
       
    62 
       
    63 
       
    64 // Threshold for using postfilter. Assumption is that CIF is encoded with high bitrate => no need for postfilter
       
    65 const TInt KThrWidthForPostFilter = 176;
       
    66 
       
    67 //  CLASS DEFINITIONS
       
    68 
       
    69 
       
    70 // Observer class for thumbnail generation
       
    71 class MThumbnailObserver
       
    72 {
       
    73 public:
       
    74     void NotifyThumbnailReady(TInt aError);
       
    75 };
       
    76 
       
    77 class MTimerObserver
       
    78 {
       
    79 public:
       
    80     virtual void MtoTimerElapsed(TInt aError) = 0;
       
    81     
       
    82 };
       
    83 
       
    84 
       
    85 // Timer class to use when waiting for encoding to complete
       
    86 class CCallbackTimer : public CActive
       
    87 {
       
    88  
       
    89 public:
       
    90 
       
    91     /**
       
    92     * Two-phased constructor.
       
    93     */
       
    94     static CCallbackTimer* NewL(MTimerObserver& aObserver);
       
    95     
       
    96     /**
       
    97     * Destructor.
       
    98     */
       
    99     ~CCallbackTimer();
       
   100     
       
   101 public:
       
   102     
       
   103     /**
       
   104     * Set timer
       
   105     *
       
   106     * @param aDuration Duration
       
   107     */
       
   108     void SetTimer(TTimeIntervalMicroSeconds32 aDuration);
       
   109     
       
   110      
       
   111     /**
       
   112     * Query whether timer is active
       
   113     *
       
   114     * @return TRUE if timer is pending
       
   115     */
       
   116     inline TBool IsPending() { return iTimerRequestPending; }
       
   117     
       
   118     /**
       
   119     * Cancel timer    
       
   120     */
       
   121     void CancelTimer();
       
   122     
       
   123 private:
       
   124 
       
   125     /**
       
   126     * C++ default constructor.
       
   127     */
       
   128     CCallbackTimer(MTimerObserver& aObserver);
       
   129 
       
   130     /**
       
   131     * Symbian 2nd phase constructor 
       
   132     */
       
   133     void ConstructL();
       
   134     
       
   135 protected:
       
   136 
       
   137     /**
       
   138     * From CActive. 
       
   139     * @param 
       
   140     * @return void
       
   141     */
       
   142     void RunL();
       
   143 
       
   144     /**
       
   145     * From CActive. 
       
   146     * @param 
       
   147     * @return void
       
   148     */
       
   149     void DoCancel();
       
   150 
       
   151     /**
       
   152     * From CActive. 
       
   153     * @param 
       
   154     * @return void
       
   155     */
       
   156     TInt RunError(TInt aError);
       
   157 
       
   158  
       
   159 private:   // Data
       
   160  
       
   161     MTimerObserver& iObserver;
       
   162     
       
   163     RTimer iTimer;
       
   164     
       
   165     TBool iTimerCreated;    
       
   166     TBool iTimerRequestPending;
       
   167 };
       
   168 
       
   169 
       
   170 
       
   171 class CVideoProcessor : public CVideoDecoder, public MVideoRenderer, 
       
   172                         public MTRTranscoderObserver, public MTRVideoPictureSink,
       
   173                         public MCMRMediaSink, public MTimerObserver
       
   174 
       
   175 {
       
   176 public: // constants
       
   177     enum TErrorCode
       
   178     {
       
   179         EInternalAssertionFailure = -1400,
       
   180         EDecoderFailure = -1401
       
   181     };
       
   182 
       
   183     enum TTimingSource
       
   184     {
       
   185         ETemporalReference = 0,
       
   186         ETimeStamp
       
   187     };
       
   188 
       
   189     enum TDecoderFrameOperation
       
   190     {
       
   191         EDecodeAndWrite = 1,
       
   192         EDecodeNoWrite,
       
   193         EWriteNoDecode,
       
   194         ENoDecodeNoWrite
       
   195     }; 
       
   196     
       
   197     enum TTranscoderMode
       
   198     {
       
   199         EDecodeOnly = 1,
       
   200         EFull,
       
   201         EFullWithIM,
       
   202         EUndefined
       
   203     };
       
   204 	
       
   205 public: // Data structures
       
   206     struct TStreamParameters
       
   207     {
       
   208         TUint iWidth;
       
   209         TUint iHeight;
       
   210         TInt64 iPicturePeriodNsec;
       
   211         TUint iIntraFrequency;
       
   212         TUint iReferencePicturesNeeded; // 0 = disable RPS
       
   213         TUint iNumScalabilityLayers;
       
   214         TUint iLayerFrameRates[8]; // frames per 256 sec
       
   215         TTimingSource iTiming;
       
   216     };
       
   217     
       
   218    
       
   219 private: // Data structures
       
   220 
       
   221     // structure to store information about frames
       
   222     // in decoding/transcoding progress 
       
   223     struct TFrameInformation
       
   224     {
       
   225         TTranscoderMode iTranscoderMode;
       
   226                 
       
   227         TInt iFrameNumber;
       
   228         TInt64 iTimeStamp;  // timestamp in ticks        
       
   229         TBool iEncodeFrame; // ETrue if frame will be encoded        
       
   230         TBool iKeyFrame;  
       
   231         
       
   232         // transition frame info
       
   233         TBool iTransitionFrame;  // is this a transition frame?
       
   234         TBool iFirstTransitionFrame;  // is this the first transition frame in this instance?
       
   235         TTransitionPosition iTransitionPosition;
       
   236         TTransitionColor iTransitionColor;        
       
   237         TInt iTransitionFrameNumber;
       
   238         
       
   239         TBool iModificationApplied; // has intermediate modification been done ?
       
   240         TBool iRepeatFrame; // ETrue for second instance of a color transition frame
       
   241     
       
   242     };
       
   243     
       
   244 public: // New functions
       
   245     
       
   246     /**
       
   247     * Two-phased constructor.
       
   248     *
       
   249     * @param anInputQueue Input active queue
       
   250     * @param aStreamParameters Stream parameters
       
   251     * @param aProcessor Video processor object
       
   252     * @param aStatusMonitor Status monitor object
       
   253     * @param aEncoder Video encoder object
       
   254     * @param aPriority Active object priority
       
   255     */
       
   256 
       
   257     static CVideoProcessor* NewL(CActiveQueue *anInputQueue,
       
   258                                  CVideoProcessor::TStreamParameters *aStreamParameters,
       
   259                                  CMovieProcessorImpl* aProcessor,
       
   260                                  CStatusMonitor *aStatusMonitor,   
       
   261                                  CVedAVCEdit *aAvcEdit,
       
   262                                  TBool aThumbnailMode,
       
   263                                  TInt aPriority=EPriorityStandard);
       
   264 
       
   265 
       
   266     /**
       
   267     * Destructor.
       
   268     */
       
   269     ~CVideoProcessor();
       
   270     
       
   271 public:  // Functions from base classes
       
   272 
       
   273     /**
       
   274     * From CActive Active object running method
       
   275     */
       
   276     void RunL();
       
   277 
       
   278     /**
       
   279     * From CActive Active object cancelling method
       
   280     */
       
   281     void DoCancel();  
       
   282 
       
   283     /**
       
   284     * From CActive Active object error handling method
       
   285     */
       
   286     TInt RunError(TInt aError);
       
   287     
       
   288     /**
       
   289     * From CDecoder Start video decoding
       
   290     */    
       
   291     void Start();
       
   292 
       
   293     /**
       
   294     * From CDecoder Stop video decoding
       
   295     */    
       
   296     void Stop();    
       
   297 
       
   298     /**
       
   299     * From CDataProcessor Notifies that input stream has ended
       
   300     */
       
   301     void StreamEndReached(TAny *aUserPointer);
       
   302 
       
   303     /**
       
   304     * From CDataProcessor Notifies that new input queue blocks are available
       
   305     */
       
   306     void InputDataAvailable(TAny *aUserPointer);
       
   307 
       
   308 	/**
       
   309     * From MVideoRenderer Renders a decoded frame
       
   310     */
       
   311 	TInt RenderFrame(TAny* aFrame);
       
   312 	
       
   313     /**
       
   314     * From MTRTranscoderObserver
       
   315     */
       
   316     void MtroInitializeComplete(TInt aError);
       
   317     
       
   318     /**
       
   319     * From MTRTranscoderObserver
       
   320     */
       
   321     void MtroFatalError(TInt aError);
       
   322     
       
   323     /**
       
   324     * From MTRTranscoderObserver
       
   325     */
       
   326     void MtroReturnCodedBuffer(CCMRMediaBuffer* aBuffer);
       
   327         
       
   328     /**
       
   329     * From MTRTranscoderObserver
       
   330     */
       
   331     void MtroSetInputFrameRate(TReal& aRate);
       
   332         
       
   333     /**
       
   334     * From MTRTranscoderObserver
       
   335     */
       
   336     void MtroAsyncStopComplete();
       
   337     
       
   338     /**
       
   339     * From MTRTranscoderObserver
       
   340     */
       
   341     void MtroSuspend();
       
   342     
       
   343     /**
       
   344     * From MTRTranscoderObserver
       
   345     */
       
   346     void MtroResume();
       
   347     
       
   348     /**	
       
   349     * From MTRVideoPictureSink
       
   350     */  
       
   351     void MtroPictureFromTranscoder(TTRVideoPicture* aPicture);
       
   352     
       
   353      /**	
       
   354      * From MCMRMediaSink
       
   355      */        
       
   356      void WriteBufferL(CCMRMediaBuffer* aBuffer);
       
   357         
       
   358      /**	
       
   359      * From MCMRMediaSink
       
   360      */  
       
   361      TInt SetVideoFrameSize(TSize aSize);
       
   362         
       
   363      /**	
       
   364      * From MCMRMediaSink
       
   365      */  
       
   366      TInt SetAverageVideoBitRate(TInt aBitRate);
       
   367         
       
   368      /**	
       
   369      * From MCMRMediaSink
       
   370      */  
       
   371      TInt SetMaxVideoBitRate(TInt aBitRate);
       
   372         
       
   373      /**	
       
   374      * From MCMRMediaSink
       
   375      */  
       
   376      TInt SetAverageAudioBitRate(TInt aBitRate);
       
   377      
       
   378      /**
       
   379      * From MTimerObserver
       
   380      */
       
   381      void MtoTimerElapsed(TInt aError);
       
   382     
       
   383 public:  // New functions
       
   384     
       
   385     /**
       
   386     * Generates a thumbnail image
       
   387     *
       
   388     * @param aYUVDataPtr For returning the thumbnail
       
   389     * @param aFrameIndex Frame index of the thumbnail image
       
   390     *                   -1 means best thumbnail is generated
       
   391     * @param aStartFrameIndex Frame index of the start frame (last intra before thumbnail)    
       
   392     *
       
   393     * @return Error code
       
   394     */
       
   395     
       
   396     /**
       
   397     * Starts generating a thumbnail image
       
   398     *
       
   399     * @param aThumbObserver Observer class
       
   400     * @param aFrameIndex Frame index of the thumbnail image
       
   401     *                   -1 means best thumbnail is generated
       
   402     * @param aStartFrameIndex Frame index of the start frame (last intra before thumbnail)    
       
   403     * @param aFactor Pointer to transcode factor structure
       
   404     *
       
   405     * @return Error code
       
   406     */
       
   407     TInt ProcessThumb(MThumbnailObserver* aThumbObserver, TInt aFrameIndex, 
       
   408                       TInt aStartFrameIndex, TVedTranscodeFactor* aFactor);       
       
   409 		          
       
   410     TInt FetchThumb(TUint8** aYUVDataPtr);
       
   411 	
       
   412 	/**
       
   413 	*	Gets the frame number of the current frame 
       
   414 	*	
       
   415 	*/
       
   416 	TInt GetFrameNumber() { return iFrameNumber; };
       
   417 
       
   418 	/**
       
   419     * Keeps track whether the clip was resolution transcoded 
       
   420 	*
       
   421 	*/	
       
   422 	inline TInt GetChangeResolution() const { return iFullTranscoding; };
       
   423 
       
   424 	/*	
       
   425 	* Checks whether the resynch bit is set if set then resets to zero
       
   426 	* 
       
   427 	* @return TBool 
       
   428 	*/	
       
   429 	TBool CheckVosHeaderL(TPtrC8& aBuf);
       
   430 	
       
   431 	/**
       
   432 	 * Gets the transcode factor from the current clip
       
   433 	 * @param aFactor For returning the transcode factor
       
   434 	 * @return error code
       
   435 	 */
       
   436 	TInt GetTranscodeFactorL(TVedTranscodeFactor& aFactor);		    
       
   437 	
       
   438     /*	
       
   439 	* Writes a delayed frame, i.e. a frame which has been buffered
       
   440 	* since transcoder has unprocesessed frames that must be written
       
   441 	* before this frame		
       
   442 	*/	
       
   443 	void WriteDelayedFrameL();
       
   444 	
       
   445 	/*	
       
   446 	* Checks if there are any frames waiting to be encoded inside transcoder
       
   447 	* @return TBool 
       
   448 	*/	
       
   449 	TBool IsEncodeQueueEmpty();
       
   450 	
       
   451 	/* 
       
   452 	* Calculates encoding delay based on what kind of frame is 
       
   453 	* next in the encoding queue
       
   454 	*
       
   455 	* @return Delay in microseconds
       
   456 	*/
       
   457 	TInt GetEncodingDelay();	
       
   458 	
       
   459 	/* 
       
   460 	* Checks if the next frame in processing queue
       
   461 	* is being encoded
       
   462 	*
       
   463 	* @return TBool result
       
   464 	*/
       
   465 	TBool IsNextFrameBeingEncoded();
       
   466 	
       
   467     /* 
       
   468 	* Gets MPEG-4 VOS header size in bytes (from encoder)	
       
   469 	*
       
   470 	* @return TInt VOS size
       
   471 	*/
       
   472 	TInt GetVosHeaderSize();
       
   473 
       
   474 private: // internal methods
       
   475 
       
   476     /**
       
   477     * C++ default constructor.
       
   478     *
       
   479     * @param anInputQueue Input active queue
       
   480     * @param aStreamParameters Stream parameters
       
   481     * @param aProcessor Video processor object
       
   482     * @param aStatusMonitor Status monitor object
       
   483     * @param aEncoder Video encoder object
       
   484     * @param aPriority Active object priority
       
   485     */
       
   486     CVideoProcessor(CActiveQueue *anInputQueue,
       
   487                     TStreamParameters *aStreamParameters,
       
   488                     CMovieProcessorImpl* aProcessor,
       
   489                     CStatusMonitor *aStatusMonitor,
       
   490                     CVedAVCEdit *aAvcEdit,
       
   491                     TBool aThumbnailMode,
       
   492                     TInt aPriority);
       
   493     
       
   494 
       
   495     /** 
       
   496     * Symbian 2nd phase constructor 
       
   497     */
       
   498     void ConstructL();
       
   499 
       
   500     /**
       
   501     * Processes one input video frame
       
   502     *
       
   503     * @return ETrue If the current clip has been 
       
   504     *         processed entirely, EFalse if not
       
   505     */
       
   506     TBool ProcessFrameL();
       
   507     
       
   508     /** 
       
   509     * Processes the second frame of a color transition double frame
       
   510     */
       
   511     TBool Process2ndColorTransitionFrameL();
       
   512 
       
   513     /**
       
   514     * Read one frame from input queue to internal buffer
       
   515     *
       
   516     * @return ETrue if a complete frame was read, EFalse otherwise.
       
   517     */
       
   518     TInt ReadFrame();
       
   519 
       
   520     /**
       
   521     * Reads a H.263 frame from input queue to internal buffer
       
   522     *
       
   523     * @return ETrue if a complete frame was read, EFalse otherwise.
       
   524     */    
       
   525     TBool ReadH263Frame();
       
   526     
       
   527     /**
       
   528     * Reads a MPEG-4 frame from input queue to internal buffer
       
   529     *
       
   530     * @return ETrue if a complete frame was read, EFalse otherwise.
       
   531     */
       
   532     TBool ReadMPEG4Frame();
       
   533     
       
   534     /**
       
   535     * Reads an AVC frame from input queue to internal buffer
       
   536     *
       
   537     * @return ETrue if a complete frame was read, EFalse otherwise.
       
   538     */
       
   539     TBool ReadAVCFrame();
       
   540 
       
   541     /**
       
   542     * Checks if a frame has "good" or "legible" quality
       
   543     *
       
   544     * @param aYUVDataPtr Pointer to the frame to be checked
       
   545     *
       
   546     * @return 1 if frame quality is OK, 0 otherwise
       
   547     */
       
   548     TInt CheckFrameQuality(TUint8* aYUVDataPtr);
       
   549 
       
   550     /**
       
   551     * Apply color effect on a frame
       
   552     *
       
   553     * @param aColorEffect Effect to be used
       
   554     * @param aYUVDataPtr Pointer to the frame
       
   555     * @param aColorToneYUV for extracting the UV values
       
   556     * @return void
       
   557     */
       
   558     void ApplySpecialEffect(TInt aColorEffect, TUint8* aYUVDataPtr,
       
   559       TInt aColorToneU, TInt aColorToneV);    
       
   560 
       
   561     /**
       
   562     * Convert frame operation enumeration to TInt
       
   563     *
       
   564     * @param aFrameOperation Frame operation     
       
   565     *
       
   566     * @return Frame operation as TInt
       
   567     */
       
   568     TInt TFrameOperation2TInt(TDecoderFrameOperation aFrameOperation); 
       
   569 
       
   570     /**
       
   571     * Convert color effect enumeration to TInt
       
   572     *
       
   573     * @param aColorEffect Color effect
       
   574     *
       
   575     * @return Color effect as TInt
       
   576     */
       
   577     TInt TColorEffect2TInt(TVedColorEffect aColorEffect);
       
   578 
       
   579     /**
       
   580     * Determines transition effect parameters
       
   581     *
       
   582     * @param aTransitionEffect Output: ETrue if transition effect is to be applied
       
   583     * @param aStartOfClipTransition ETrue if starting transition is to be applied
       
   584     * @param aEndOfClipTransition ETrue if ending transition is to be applied
       
   585     * @param aStartTransitionColor Color for starting transition
       
   586     * @param aEndTransitionColor Color for ending transition
       
   587     *
       
   588     * @return Error code
       
   589     */
       
   590     TInt DetermineClipTransitionParameters(TInt& aTransitionEffect,TInt& aStartOfClipTransition,
       
   591 			TInt& aEndOfClipTransition,TTransitionColor& aStartTransitionColor,TTransitionColor& aEndTransitionColor);
       
   592 
       
   593     
       
   594     /**
       
   595     * Applies fading transition effect to YUV frame
       
   596     *
       
   597     * @param aYUVPtr Pointer to the frame
       
   598     * @param aTransitionPosition 1 = start transition, 2 = end transition
       
   599     * @param aTransitionColor Transition color to be used (EColorWhite/EColorBlack/EColorTransition)
       
   600     * @param aTransitionFrameNumber ordinal number of transition frame (0 - (number of transition frames - 1))
       
   601     *
       
   602     * @return void
       
   603     */
       
   604     void ApplyFadingTransitionEffect(TUint8* aYUVPtr, TTransitionPosition aTransitionPosition,
       
   605                                      TTransitionColor aTransitionColor, TInt aTransitionFrameNumber);
       
   606 
       
   607 	/**
       
   608     * Applies blending transition effect between YUV frames
       
   609     *
       
   610     * @param aYUVPtr1 Pointer to the frame 1
       
   611     * @param aYUVPtr2 Pointer to the frame 2
       
   612     * @param aRepeatFrame True for the second instance of two frames to be blended
       
   613     * @param aTransitionFrameNumber ordinal number of transition frame (0 - (number of transition frames - 1))
       
   614     *
       
   615     * @return void
       
   616     */
       
   617     void ApplyBlendingTransitionEffect(TUint8* aYUVPtr1,TUint8* aYUVPtr2, TInt aRepeatFrame, 
       
   618                                        TInt aTransitionFrameNumber);
       
   619     
       
   620 		
       
   621     /**
       
   622     * Applies sliding transition effect between YUV frames
       
   623     *
       
   624     * @param aYUVPtr1 Pointer to the frame 1
       
   625     * @param aYUVPtr2 Pointer to the frame 2
       
   626     * @param aRepeatFrame True for the second instance of two frames to be blended
       
   627     * @param aTransitionFrameNumber ordinal number of transition frame (0 - (number of transition frames - 1))
       
   628     *
       
   629     * @return void
       
   630     */
       
   631     void ApplySlidingTransitionEffect(TUint8* aYUVPtr1,TUint8* aYUVPtr2, TVedMiddleTransitionEffect aVedMiddleTransitionEffect, 
       
   632                                       TInt aRepeatFrame, TInt aTransitionFrameNumber);
       
   633 		
       
   634     /**
       
   635     * Get the start transition info of the next clip
       
   636     *
       
   637     * @return void
       
   638     */
       
   639     void GetNextClipTransitionInfo();
       
   640 
       
   641 	/*
       
   642 	* Resolution Transcoder
       
   643 	* Determine if the resolution transcoding will apply to the current clip
       
   644 	* 
       
   645 	*/
       
   646 	TBool DetermineResolutionChange();
       
   647 
       
   648     /*
       
   649 	* 
       
   650 	* Determine if frame rate needs to be changed for the current clip
       
   651 	* 
       
   652 	*/
       
   653     TBool DetermineFrameRateChange();
       
   654 
       
   655     /*
       
   656 	* 
       
   657 	* Determine if bitrate needs to be changed for the current clip
       
   658 	* 
       
   659 	*/
       
   660     TBool DetermineBitRateChange();
       
   661     
       
   662     /*	
       
   663 	* Calculate the duration of current frame
       
   664 	*	
       
   665 	* @param aFrameNumber frame number 
       
   666 	*
       
   667 	* @return Frame duration in ticks
       
   668 	*/    
       
   669     TInt GetFrameDuration(TInt aFrameNumber);
       
   670     
       
   671     /*	
       
   672 	* Decode frame using vedh263decoder
       
   673 	* 
       
   674 	* @param aOperation Operation 
       
   675 	* @param aModeChanged ETrue if compressed domain transcoding is neede
       
   676 	* @param aFrameSizeInBytes Return value, coded output frame size in bytes
       
   677 	* @param aVosHeaderSize Return value, size of VOS header in bytes
       
   678 	*/  
       
   679     void DecodeFrameL(TInt aOperation, TBool aModeChanged, TInt& aFrameSizeInBytes);        
       
   680     
       
   681     /*
       
   682     * Create and initialize transcoder
       
   683     *
       
   684     * @param aInputType Input video type 
       
   685     * @param aMode Transcoder operational mode to be used
       
   686     *    
       
   687     */
       
   688     void CreateAndInitializeTranscoderL(TVedVideoType aInputType, CTRTranscoder::TTROperationalMode aMode);
       
   689     
       
   690     /*
       
   691     * Determines if compressed domain transcoding is needed
       
   692     *
       
   693     */
       
   694     TBool GetModeChangeL();
       
   695     
       
   696     /*
       
   697     * Processes a thumbnail frame
       
   698     *
       
   699     * @param aFirstFrame ETrue if the first thumbnail frame is being processed
       
   700     */
       
   701     void ProcessThumb(TBool aFirstFrame);
       
   702     
       
   703     /*
       
   704     * Calculate the number of transition frames
       
   705     *
       
   706     * @param aStartCutTime Start cut time
       
   707     * @param aEndCutTime End cut time
       
   708     */
       
   709     void GetNumberOfTransitionFrames(TTimeIntervalMicroSeconds aStartCutTime, 
       
   710                                      TTimeIntervalMicroSeconds aEndCutTime);
       
   711       
       
   712     /*
       
   713     * Set parameters needed to process a transition frame
       
   714     *
       
   715     * @param aIncludedFrameNumber Ordinal counting from the first included frame number
       
   716     * @param aDecodeFrame ETrue if this frame must be decoded in order to apply end transition
       
   717     */                               
       
   718     void SetTransitionFrameParams(TInt aIncludedFrameNumber, TBool& aDecodeFrame);
       
   719     
       
   720     /*
       
   721     * Sets output codec parameters
       
   722     * 
       
   723     * aMimeType Output mime type
       
   724     */
       
   725     void SetOutputVideoCodecL(const TPtrC8& aMimeType);
       
   726     
       
   727     /*
       
   728     * Generates bitstream for a not coded frame
       
   729     * to be used in color transitions
       
   730     */
       
   731     void GenerateNotCodedFrameL();
       
   732     
       
   733     /*
       
   734     * Reads a frame from input queue and writes it to transcoder
       
   735     *
       
   736     */
       
   737 	void ReadAndWriteThumbFrame();	
       
   738 	
       
   739 	/*
       
   740     * Does thumbnail finalization, stops processing and informs observer
       
   741     *
       
   742     * aError Error code for observer
       
   743     */
       
   744 	void FinalizeThumb(TInt aError);
       
   745 	
       
   746 	/*
       
   747     * Writes a frame to output file
       
   748     *  
       
   749     * @param aBuf Buffer containing the frame
       
   750     * @param aDurationInTicks Frame duration in ticks
       
   751     * @param aFrameNumber Frame number
       
   752     * @return ETrue if clip end was written
       
   753     */
       
   754 	TBool WriteFrameToFileL(TPtr8& aBuf, TInt aDurationInTicks, TInt aFrameNumber);
       
   755 	
       
   756 	/*
       
   757     * Writes a frame to transcoder
       
   758     *      
       
   759     * @param aFrameNumber Frame number
       
   760     * @param aKeyFrame ETrue for a keyframe
       
   761     * @param aVolHeaderInBuffer ETrue if frame buffer contains MPEG-4 VOL header
       
   762     */
       
   763 	void WriteFrameToTranscoderL(TInt aFrameNumber, TBool aKeyFrame, TBool aVolHeaderInBuffer);
       
   764 	
       
   765     /*
       
   766     * Handles a decoded thumbnail frame received from transcoder
       
   767     *      
       
   768     * @param aPicture Pointer to received picture
       
   769     */
       
   770 	void HandleThumbnailFromTranscoder(TTRVideoPicture* aPicture);
       
   771 	
       
   772 	/*
       
   773     * Handles a decoded "decode-only" frame received from transcoder
       
   774     *      
       
   775     * @param aPicture Pointer to received picture
       
   776     * @param aIndex Index of decoded frame to iFrameInfoArray
       
   777     */
       
   778 	void HandleDecodeOnlyFrameFromTranscoder(TTRVideoPicture* aPicture, TInt aIndex);
       
   779 	
       
   780 	/*
       
   781     * Handles a decoded transition frame (intermediate frame) received from transcoder
       
   782     *      
       
   783     * @param aPicture Pointer to received picture
       
   784     * @param aIndex Index of decoded frame to iFrameInfoArray
       
   785     */
       
   786 	void HandleTransitionFrameFromTranscoder(TTRVideoPicture* aPicture, TInt aIndex);
       
   787 	
       
   788     /*
       
   789     * Inserts AVC/MPEG-4 decoder specific info data in front of internal coded frame buffer
       
   790     *
       
   791     */
       
   792 	void InsertDecoderSpecificInfoL();
       
   793 
       
   794 private: // internal constants
       
   795     enum TDataFormat
       
   796     {
       
   797         EDataUnknown = 0,
       
   798         EDataH263,
       
   799         EDataMPEG4,
       
   800         EDataAVC
       
   801     };
       
   802 
       
   803 
       
   804 private: // data
       
   805     CActiveQueue *iQueue; // input data queue
       
   806     TBool iReaderSet; // have we been set as reader?
       
   807     CStatusMonitor *iMonitor; // status monitor object
       
   808     CMovieProcessorImpl *iProcessor;
       
   809 
       
   810     CVedH263Dec *iDecoder;  // H.263/MPEG-4 decoder    
       
   811 
       
   812     TUint iVideoWidth, iVideoHeight; // video picture dimensions
       
   813     TInt64 iPicturePeriodNsec; // one PCF tick period in nanoseconds
       
   814     TDataFormat iDataFormat; // the stream data format
       
   815     TUint iIntraFrequency; // intra picture frequency (intras per 256 sec)
       
   816     TUint iReferencePicturesNeeded; // number of reference pictures needed
       
   817     
       
   818     TBool iFirstFrameFlag; // flag for decoder: is this the first frame?
       
   819 
       
   820     TDecoderFrameOperation iFrameOperation; 
       
   821 
       
   822     TInt iNumberOfIncludedFrames; 
       
   823 
       
   824     TBool iDecoding; // are we decoding?
       
   825     TBool iStreamEnd; // has stream end been reached?    
       
   826     TBool iEncoderResetPending; // is the encoder being reseted
       
   827 
       
   828     TPtr8 *iBlock; // queue block
       
   829     TUint iBlockPos; // current block position
       
   830     TUint8 *iDataBuffer; // data buffer for the current compressed frame
       
   831     TUint iBufferLength; // buffer total length
       
   832     TUint iDataLength; // amount of data in buffer
       
   833     TUint iCurrentFrameLength; // the length of the current frame in the buffer
       
   834 
       
   835     TUint8 *iFrameBuffer;  // Concatenated YUV data for decoded frame
       
   836 
       
   837     TUint8 *iOutVideoFrameBuffer; // data buffer for the output compressed frame    
       
   838     TInt iOutVideoFrameBufferLength; // buffer total length
       
   839     TInt iOutDataLength; // amount of data in buffer
       
   840     TPtr8 iWriteDes;  // writing descriptor for encoding
       
   841     TInt iFrameNumber;  // current frame number
       
   842     TInt iNumberOfFrames;  // no. of frames in current clip
       
   843     TInt iPreviousFrameIncluded;  // ETrue if previous frame was included in output movie
       
   844     TInt  iTrPrevious;
       
   845 
       
   846     // transition effects
       
   847     TInt iTransitionEffect;	    // is transition effect to be applied?
       
   848     TInt iStartOfClipTransition;  // is starting transition effect to be applied ?
       
   849     TInt iEndOfClipTransition; // is ending transition effect to be applied ?
       
   850 
       
   851 	TInt iStartNumberOfTransitionFrames;  // number of frames in transition
       
   852 	TInt iEndNumberOfTransitionFrames;  // number of frames in transition
       
   853 	TInt iTransitionFrameNumber;
       
   854 	TInt iNextTransitionNumber;    
       
   855     
       
   856     TInt iFirstFrameInRange;  // is the current frame the first to be included in output movie
       
   857     TInt iFirstIncludedFrameNumber;  // number of first included frame
       
   858     TTransitionColor iStartTransitionColor;	// color for starting transition
       
   859     TTransitionColor iEndTransitionColor;// color for ending transition
       
   860     
       
   861     // number of preceding I frame (for end-of-clip trans.)this number is relative of start-of-clip
       
   862     TInt iLastIntraFrameBeforeTransition; //The last intra frame before transition effect takes place.       
       
   863 
       
   864     TTimingSource iTiming;  
       
   865 
       
   866 	// for transition effect - blending and sliding
       
   867 	TInt    iFrameDuration;
       
   868 	TBool   iRepeatFrame;
       
   869 	TInt64  iTimeStamp;
       
   870 	TUint8 *iOrigPreviousYUVBuffer;
       
   871 	TUint8 *iColorTransitionBuffer;
       
   872 
       
   873 	CMPEG4Timer *iMPEG4Timer;		// Stores MPEG-4 timing information
       
   874 	
       
   875 	CTRTranscoder *iTransCoder;	
       
   876 	CCMRMediaBuffer* iMediaBuffer;	
       
   877 	
       
   878 	TBool iTranscoderInitPending;  // is transcoder init in progress ?
       
   879 	TBool iDecodePending;  // is decode in progress ?
       
   880 	TBool iTranscoderStarted; // has transcoder been started ?
       
   881 	TBool iFrameToEncode;  // should current frame be encoded ? (: could be changed to local for ProcessFrame)	
       
   882 	
       
   883 	TBool iTransitionFrame;
       
   884 	TBool iFirstTransitionFrame;
       
   885 	TTransitionPosition iTransitionPosition;
       
   886     TTransitionColor iTransitionColor;	
       
   887     
       
   888     // for color toning
       
   889     TInt   iFirstFrameQp;       // QP for first MPEG4 frame, used for color toning 
       
   890 	
       
   891 	TBool iFullTranscoding; // Flag to indicate whether current clip needs to be fully
       
   892 	                        // transcoded (decode & encode)   
       
   893     
       
   894     TBool iThumbnailMode;   // True if we are generating a thumbnail frame
       
   895     
       
   896     TInt iThumbFrameIndex;  // index of thumbnail to be generated, >= 0 means a specific frame,
       
   897                             // < 0 means the first "good" or "legible" frame
       
   898     TInt iThumbFrameNumber;
       
   899     TInt iFramesToSkip;     // for searching a good thumbnail
       
   900     
       
   901     MThumbnailObserver* iThumbObserver;  // observer for thumbnail operation
       
   902     
       
   903     HBufC8* iDecoderSpecificInfo;  // decoder specific info header read from input stream, to be sent to transcoder
       
   904     TBool iDecoderSpecificInfoSent;  // True if decoder specific info has been sent to transcoder
       
   905     
       
   906     HBufC8* iOutputVolHeader;  // VOL header read from encoder, to be inserted in the first
       
   907                                // encoded frame buffer
       
   908                                
       
   909     TBool iOutputVolHeaderWritten;  // True if VOL/AVC header has been written to output bitstream
       
   910     
       
   911     RArray<TFrameInformation> iFrameInfoArray;  // array for storing info about frames in progress
       
   912     
       
   913     TTranscoderMode iTranscoderMode;  // current transcoder operation mode
       
   914 
       
   915     // used & max frame size, and info if size can be arbitrary    
       
   916     TSize iMaxOutputResolution;
       
   917     TBool iArbitrarySizeAllowed;
       
   918 
       
   919     // max allowed frame rate
       
   920     TReal32 iMaxOutputFrameRate;           
       
   921 
       
   922 	// target and max allowed bit rate
       
   923 	TInt iOutputBitRate;
       
   924 	TInt iMaxOutputBitRate;        
       
   925 	
       
   926 	// Mime type for encoded data
       
   927     TBuf8<256> iOutputMimeType;
       
   928     
       
   929     TBool iDelayedWrite;  // True if a frame has to be stored for later writing since
       
   930                           // there are frames inside the transcoder that have to be written
       
   931                           // before this frame
       
   932     HBufC8* iDelayedBuffer;  // buffer for storing the frame  
       
   933     TInt64 iDelayedTimeStamp;  // timestamp
       
   934     TBool iDelayedKeyframe;  // is it a keyframe            
       
   935 
       
   936     TInt iTimeStampIndex;  // index for reading stored timestamps in case of color transition
       
   937     TBool iFirstColorTransitionFrame;  // True if we are processing the first frame of a
       
   938                                        // 'doubled' frame in color transitions
       
   939     
       
   940     TInt iTimeStampOffset;  // offset to be added to timestamps, got from processor
       
   941     
       
   942     CCallbackTimer* iTimer;  // timer for waiting encoding to complete
       
   943     
       
   944     TBool iStreamEndRead;
       
   945     
       
   946     TBool iProcessingComplete;
       
   947     
       
   948     TInt iInputMPEG4ProfileLevelId;  // profile-level id for MPEG-4 input
       
   949     
       
   950     // Timer timeout, depends on codec and resolution
       
   951     TUint iMaxEncodingDelay;
       
   952     
       
   953     TInt iNumThumbFrameSkips;  // number of frame skip cycles done to get a 
       
   954                                // a good thumbnail
       
   955                                
       
   956     TTimeIntervalMicroSeconds iPreviousTimeStamp; // timestamp of previous frame        
       
   957 
       
   958     TInt iSkippedFrameNumber;  // frame number of skipped frame
       
   959     
       
   960     TInt64 iCutInTimeStamp;  // timestamp of cut-in point, needed in color transitions
       
   961     
       
   962     TBool iDecodingSuspended;  // flag for suspended decoding
       
   963     
       
   964     HBufC8* iNotCodedFrame;  // buffer for not coded frame
       
   965     
       
   966     TInt iInputTimeIncrementResolution;  // MPEG-4 time increment resolution from input clip
       
   967     
       
   968     TBool iFirstFrameAfterTransition;  // True for first frame after start transition
       
   969     
       
   970     TBool iFirstRead;  // True for first read frame        
       
   971 
       
   972     TBool iThumbDecoded;  // flag for indicating when a thumb has been decoded,
       
   973                           // needed in AVC thumbnail generation
       
   974     
       
   975     TInt iInputAVCLevel;  // level of input AVC clip
       
   976     
       
   977     TInt iFrameLengthBytes;  // number of bytes used for NAL length in input
       
   978     TInt iThumbFramesToWrite;  // number of thumb frames to write to transcoder
       
   979     
       
   980     CVedAVCEdit* iAvcEdit;  // AVC editing instance
       
   981     
       
   982     TBool iEncodeUntilIDR;  // Flag for encoding until IDR  
       
   983 
       
   984     TBool iIsThumbFrameBeingCopied;  // True if thumbnail frame has been sent for
       
   985                                      // decoding, but MtroReturnCodedBuffer hasn't been called
       
   986                                      
       
   987     TInt iModifiedFrameNumber;  // frame number modification for AVC decoder, 
       
   988                                 // used with color transitions    
       
   989                                 
       
   990     TInt iMaxItemsInProcessingQueue;  // Maximum number of frames kept in transcoder
       
   991                                       // processing queue
       
   992                                       
       
   993     TInt iLastWrittenFrameNumber;  // number of last written frame    
       
   994     
       
   995     TInt iDelayedFrameNumber;  // number of delayed frame
       
   996     
       
   997     TBool iInitializing;  // True when initialisation is ongoing
       
   998     TVedVideoBitstreamMode iInputStreamMode;    //MPEG-4 bitstream mode in input clip
       
   999 };
       
  1000 
       
  1001 #endif      //  __VIDEOPROCESSOR_H__
       
  1002             
       
  1003 // End of File