videoeditorengine/vedtranscoder/inc/ctrvideoencoderclient.h
branchRCL_3
changeset 3 e0b5df5c0969
parent 0 951a5db380a0
child 7 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 * Video decoder client.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 #ifndef CTRVIDEOENCODERCLIENT_H
       
    23 #define CTRVIDEOENCODERCLIENT_H
       
    24 
       
    25 
       
    26 // INCLUDES
       
    27 #include <e32base.h>
       
    28 #include <devvideobase.h>   // Common data types
       
    29 #include <CCMRMediaSink.h>  // CmmfBuffer
       
    30 #include <e32cmn.h>         // TRequestStatus
       
    31 #include <devvideorecord.h>
       
    32 
       
    33 // When the flag SPP_BUFFER_MGMT_CI_HEADER_SYMBIAN is NOT defined,
       
    34 // Buffer management interface is specified in Symbian header
       
    35 #ifndef SPP_BUFFER_MGMT_CI_HEADER_SYMBIAN
       
    36 #include <devvideostandardcustominterfaces.h>
       
    37 #else
       
    38 #include <devvideostandardcustominterfaces.h>
       
    39 #include "buffermanagementci.h"
       
    40 #endif
       
    41 
       
    42 #include "ctrcommon.h"
       
    43 #include "ctrsettings.h"
       
    44 
       
    45 #ifndef SPP_BUFFER_MGMT_CI_HEADER_SYMBIAN
       
    46 /** Buffer Management Custom Interface UID */
       
    47 const TUid KMmfVideoBuffermanagementUid = { 0x10204bea };
       
    48 #endif
       
    49 
       
    50 // FORWARD DECLARATIONS
       
    51 class MTRDevVideoClientObserver;
       
    52 
       
    53 
       
    54 // CONSTANTS
       
    55 
       
    56 
       
    57 /**
       
    58 *  Video encoder client
       
    59 *  @lib TRANSCODER.LIB
       
    60 *  @since 3.1
       
    61 */
       
    62 class TUidAndRate
       
    63     {
       
    64     public:
       
    65         // Encoder Uid
       
    66         TUid iUid;
       
    67 
       
    68         // Max supported framerate
       
    69         TReal iMaxRate;
       
    70     };
       
    71 
       
    72 /**
       
    73 *  Video encoder client
       
    74 *  @lib TRANSCODER.LIB
       
    75 *  @since 3.1
       
    76 */
       
    77 NONSHARABLE_CLASS(CTRVideoEncoderClient) : public CBase, public MMMFDevVideoRecordObserver, public MMmfVideoBufferManagementObserver,
       
    78                                            public MMmfVideoResourceObserver
       
    79     {
       
    80     public: // Constuctor / destructor
       
    81 
       
    82         /**
       
    83         * Two-phased constructor.
       
    84         */
       
    85         static CTRVideoEncoderClient* NewL(MTRDevVideoClientObserver& aObserver);
       
    86 
       
    87         /**
       
    88         * Destructor.
       
    89         */
       
    90         ~CTRVideoEncoderClient();
       
    91 
       
    92         // Information methods
       
    93         /**
       
    94         * Check codec's support by MIME type
       
    95         * @param aFormat Codec MIME type
       
    96         * @param aShortFormat Codec MIME type (short version)
       
    97         * @param aUid Uid of the codec to check
       
    98         * @param aFallbackUid Fallback Uid incase the first codec is not found
       
    99         * @return TBool: ETrue - supports, EFalse - Does not support
       
   100         */
       
   101         TBool SupportsCodec(const TDesC8& aFormat, const TDesC8& aShortFormat, TInt aUid, TInt aFallbackUid);
       
   102 
       
   103         /**
       
   104         * Sets codec parameters
       
   105         * @param aCodecType Codec type
       
   106         * @param aCodecLevel Codec level
       
   107         * @param aInputFormat Input video format
       
   108         * @param aOutputFormat Output video format
       
   109         * @return none
       
   110         */
       
   111         void SetCodecParametersL(TInt aCodecType, TInt aCodecLevel, const TTRVideoFormat& aInputFormat, 
       
   112                                  const TTRVideoFormat& aOutputFormat);
       
   113 
       
   114         /**
       
   115         * Sets real-time operation
       
   116         * @param aRealTime Real-time operatiopn
       
   117         * @return none
       
   118         */
       
   119         void SetRealTime(TBool aRealTime);
       
   120 
       
   121         /**
       
   122         * From MMMFDevVideoRecordObserver. Returns a used input video picture back to the caller. 
       
   123         * The picture memory can be re-used or freed
       
   124         * @param aPicture Video Picture
       
   125         * @return none
       
   126         */
       
   127         void MdvroReturnPicture(TVideoPicture* aPicture);
       
   128 
       
   129         /**
       
   130         * From MMMFDevVideoRecordObserver. Signals that the supplemental info send request has completed
       
   131         * @param none
       
   132         * @return none
       
   133         */
       
   134         void MdvroSupplementalInfoSent();
       
   135 
       
   136         /**
       
   137         * From MMMFDevVideoRecordObserver. Notifies the client that one or more new output buffers are available
       
   138         * @param none
       
   139         * @return none
       
   140         */
       
   141         void MdvroNewBuffers();
       
   142 
       
   143         /**
       
   144         * From MMMFDevVideoRecordObserver. Reports a fatal encoding or capturing error 
       
   145         * @param aError Run-time error
       
   146         * @return none
       
   147         */
       
   148         void MdvroFatalError(TInt aError);
       
   149 
       
   150         /**
       
   151         * From MMMFDevVideoRecordObserver. Reports that DevVideoRecord initialization has completed
       
   152         * @param aError Init error
       
   153         * @return none
       
   154         */
       
   155         void MdvroInitializeComplete(TInt aError);
       
   156 
       
   157         /**
       
   158         * From MMMFDevVideoRecordObserver. Reports that the input video data end has been reached and all pictures 
       
   159         * have been processed
       
   160         * @param none
       
   161         * @return none
       
   162         */
       
   163         void MdvroStreamEnd();
       
   164 
       
   165         /**
       
   166         * Encode picture
       
   167         * @param aPicture Video picture to encode
       
   168         * @return none
       
   169         */
       
   170         void EncodePictureL(TVideoPicture* aPicture);
       
   171 
       
   172         /**
       
   173         * Starts encoding
       
   174         * @param none
       
   175         * @return none
       
   176         */
       
   177         void StartL();
       
   178 
       
   179         /**
       
   180         * Stops encoding synchronously
       
   181         * @param none
       
   182         * @return none
       
   183         */
       
   184         void StopL();
       
   185 
       
   186         /**
       
   187         * Stops encoding asynchronously
       
   188         * @param none
       
   189         * @return none
       
   190         */
       
   191         void AsyncStopL();
       
   192 
       
   193         /**
       
   194         * Sets target bitrate
       
   195         * @param aBitRate bitrate
       
   196         * @return none
       
   197         */
       
   198         void SetBitRate(TUint aBitRate);
       
   199 
       
   200         /**
       
   201         * Sets target frame rate 
       
   202         * @param aFrameRate Target frame rate 
       
   203         * @return none
       
   204         */
       
   205         void SetFrameRate(TReal& aFrameRate);
       
   206 
       
   207         /**
       
   208         * Sets Channel bit-error rate
       
   209         * @param aErrorRate error rate
       
   210         * @return none
       
   211         */
       
   212         void SetChannelBitErrorRate(TReal aErrorRate);
       
   213 
       
   214         /**
       
   215         * Sets Video coding options
       
   216         * @param aOptions Coding options
       
   217         * @return none
       
   218         */
       
   219         void SetVideoCodingOptionsL(TTRVideoCodingOptions& aOptions);
       
   220 
       
   221         /**
       
   222         * Gets current video bitrate
       
   223         * @param none
       
   224         * @return Video bitrate
       
   225         */
       
   226         TUint GetVideoBitRateL();
       
   227 
       
   228         /**
       
   229         * Gets Current frame rate
       
   230         * @param none
       
   231         * @return Frame rate 
       
   232         */
       
   233         TReal GetFrameRateL();
       
   234 
       
   235         /**
       
   236         * Sets Input / source frame rate 
       
   237         * @param aFrameRate Input / Source frame rate 
       
   238         * @return none
       
   239         */
       
   240         void SetInputFrameRate(TReal aFrameRate);
       
   241 
       
   242         /**
       
   243         * Initialize encoder
       
   244         * @param none 
       
   245         * @return none
       
   246         */
       
   247         void InitializeL();
       
   248 
       
   249         /**
       
   250         * Select encoder
       
   251         * @param none 
       
   252         * @return none 
       
   253         */
       
   254         void SelectEncoderL();
       
   255         
       
   256         /**
       
   257         * Get Coding standard / specific output (VOL / VOS / VO Header)
       
   258         * @param none 
       
   259         * @return Coding standard / specific output (VOL / VOS / VO Header) 
       
   260         */
       
   261         HBufC8* GetCodingStandardSpecificInitOutputLC();
       
   262 
       
   263         /**
       
   264         * Select encoder
       
   265         * @param none 
       
   266         * @return none 
       
   267         */
       
   268         void UseDataTransferOptimizationL();
       
   269 
       
   270         /**
       
   271         * Informs about new buffers available in DevVideoPlay queue
       
   272         * @param none 
       
   273         * @return none 
       
   274         */
       
   275         void MmvbmoNewBuffers();
       
   276 
       
   277         /**
       
   278         * Release buffers request
       
   279         * @param none 
       
   280         * @return none 
       
   281         */
       
   282         void MmvbmoReleaseBuffers();
       
   283         
       
   284         /**
       
   285         * Gets target video picture buffer
       
   286         * @param none 
       
   287         * @return Video picture
       
   288         */
       
   289         TVideoPicture* GetTargetVideoPictureL();
       
   290         
       
   291         /**
       
   292         * Sets Random access point
       
   293         * @param none 
       
   294         * @return none 
       
   295         */
       
   296         void SetRandomAccessPoint();
       
   297         
       
   298         /**
       
   299         * Returns a time estimate on long it takes to encode one frame with the current settings
       
   300         * @param aOutput Output video format
       
   301         * @param aCodecType EH263 or EMpeg4
       
   302         * @return TReal time estimate in seconds
       
   303         */
       
   304         TReal EstimateEncodeFrameTimeL(const TTRVideoFormat& aOutput, TInt aCodecType);
       
   305         
       
   306         /**
       
   307         * Pauses encoding
       
   308         * @param none
       
   309         * @return none
       
   310         */
       
   311         void Pause();
       
   312 
       
   313         /**
       
   314         * Resumes encoding
       
   315         * @param none
       
   316         * @return none
       
   317         */
       
   318         void Resume();
       
   319         
       
   320         /**
       
   321         * Enable / Disable resource observer
       
   322         * @param aEnable ETrue: Observer is enabled, EFalse observer is disabled
       
   323         * @return none
       
   324         */
       
   325         void EnableResourceObserver(TBool aEnable);
       
   326         
       
   327         /**
       
   328         * From MMmfVideoResourceObserver. Indicates that a media device has lost its resources
       
   329         * @param aMediaDevice UID for the media device that lost resources
       
   330         * @return none
       
   331         */
       
   332         void MmvroResourcesLost(TUid aMediaDevice);
       
   333         
       
   334         /**
       
   335         * From MMmfVideoResourceObserver. Indicates that a media device has regained its resources
       
   336         * @param aMediaDevice UID for the media device that regained resources
       
   337         * @return none
       
   338         */
       
   339         void MmvroResourcesRestored(TUid aMediaDevice);
       
   340 
       
   341     private:
       
   342         /**
       
   343         * C++ default constructor.
       
   344         */
       
   345         CTRVideoEncoderClient(MTRDevVideoClientObserver& aObserver);
       
   346 
       
   347         /**
       
   348         * Symbian 2nd phase constructor, can leave
       
   349         */
       
   350         void ConstructL();
       
   351 
       
   352         /**
       
   353         * Checks codec info
       
   354         * @param aUid Decoder Uid
       
   355         * @return TBool ETrue - accelerated codec; EFalse - non-accelerated codec
       
   356         */
       
   357         TBool CheckCodecInfoL(TUid aUid);
       
   358         
       
   359     private:
       
   360         // Observer
       
   361         MTRDevVideoClientObserver& iObserver;
       
   362 
       
   363         // DevVideoRecord
       
   364         CMMFDevVideoRecord* iDevVideoRecord;
       
   365 
       
   366         // Encoder mime type
       
   367         TBuf8<256> iMimeType;
       
   368         
       
   369         // Short version mime type
       
   370         TBuf8<256> iShortMimeType;
       
   371 
       
   372         // Uid of the selected codec
       
   373         TUid iUid;
       
   374         
       
   375         // Fallback codec to use if the first codec doesn't work
       
   376         TUid iFallbackUid;
       
   377 
       
   378         // Max frame rate 
       
   379         TReal iMaxFrameRate;
       
   380 
       
   381         // Uncompressed format
       
   382         TUncompressedVideoFormat iUncompressedFormat;
       
   383 
       
   384         // Compressed format
       
   385         CCompressedVideoFormat* iCompresedFormat;
       
   386 
       
   387         // Picture size
       
   388         TSize iPictureSize;
       
   389 
       
   390         // Rate control options
       
   391         TRateControlOptions iRateControlOptions;
       
   392 
       
   393         // Coding options
       
   394         TTRVideoCodingOptions iCodingOptions;
       
   395 
       
   396         // HwDevice Uid
       
   397         THwDeviceId iHwDeviceId;
       
   398 
       
   399         // MPEG4 VOL header
       
   400         TBufC8<256> iVolHeader;
       
   401 
       
   402         // Output buffer type
       
   403         TInt iBufferType;
       
   404 
       
   405         // Output media buffer
       
   406         CCMRMediaBuffer* iOutputMediaBuffer;
       
   407 
       
   408         // Request status
       
   409         TRequestStatus* iStat;
       
   410 
       
   411         // Real-time processing
       
   412         TBool iRealTime;
       
   413 
       
   414         // State
       
   415         TInt iState;
       
   416 
       
   417         // Src frame rate
       
   418         TReal iSrcRate;
       
   419 
       
   420         // Output data type
       
   421         TInt iOutputDataType;
       
   422 
       
   423         // Codec level
       
   424         TInt iCodecLevel;
       
   425 
       
   426         // Codec type
       
   427         TInt iCodecType;
       
   428 
       
   429         // Error rate 
       
   430         TReal iErrorRate;
       
   431 
       
   432         // Fatal error code
       
   433         TInt iFatalError;
       
   434         
       
   435         // Vol data sending status
       
   436         TBool iVolHeaderSent;
       
   437         
       
   438         // Vol header status 
       
   439         TBool iRemoveHeader;
       
   440         
       
   441         // Vol header length
       
   442         TUint iVolLength;
       
   443         
       
   444         // Rate control options
       
   445         TRateControlOptions iRateOptions;
       
   446         
       
   447         // Rate setting
       
   448         TBool iBitRateSetting;
       
   449         
       
   450         // Buffer Management CI
       
   451         MMmfVideoBufferManagement* iVideoBufferManagementCI;
       
   452         
       
   453         // Last ts
       
   454         TTimeIntervalMicroSeconds iLastTimestamp;
       
   455         
       
   456         // If selected encoder is accelerated or not
       
   457         TBool iAcceleratedCodecSelected;
       
   458         
       
   459         // ETrue if random access point was requested
       
   460         TBool iSetRandomAccessPoint;
       
   461         
       
   462         // Number of H.264 SPS/PPS NAL units from encoder
       
   463         TInt iNumH264SPSPPS;
       
   464         
       
   465         // Video resource handler custom interface
       
   466         MMmfVideoResourceHandler* iVideoResourceHandlerCI;
       
   467     };
       
   468 
       
   469 
       
   470 
       
   471 #endif  // CTRVIDEOENCODERCLIENT_H