os/mm/mmapitest/devvideohaitest/inc/H264DecTestEngine.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2004 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:  
    15 *
    16 */
    17 
    18 
    19 
    20 #ifndef __H264DecTestEngine_H
    21 #define __H264DecTestEngine_H
    22 
    23 #include <e32base.h>
    24 #include <e32std.h>
    25 #include <f32file.h>
    26 
    27 #include "T_DevVideoConstants.h"
    28 #include <Videoplayhwdevice.h>
    29 #include <Devvideoplay.h>
    30 #include <Devvideobase.h> 
    31 
    32 //#define __CI_HEADERS__
    33 //#define __SECUREOUTPUTCI__
    34 
    35 
    36 #ifdef __CI_HEADERS__
    37 #include <buffermanagementci.h>  // Custom interface buffre management
    38 
    39 #endif
    40 
    41 
    42 #ifdef __SECUREOUTPUTCI__
    43 #include <secureoutputci.h>
    44 #endif
    45 
    46 #include <Bitdev.h>   // for display device 
    47 #include <Fbs.h>      // for display device
    48 #include <math.h> //pow
    49 
    50 #ifdef __RESOURCENOTIFICATION__
    51 #include <devvideostandardcustominterfaces.h>
    52 #endif
    53 
    54 
    55 
    56 
    57 
    58 //////////////////
    59 // Utility function
    60 //////////////////
    61 
    62 
    63 // MACROS
    64 
    65 // DATA TYPES
    66 
    67 // FORWARD DECLARATIONS
    68 
    69 // CLASS DECLARATION
    70 
    71 const TUint KMaxNumberOfNals = 100;
    72 //const TUint KDataChunkSize = 500000;
    73 
    74 
    75 //#ifdef _DEBUG
    76 #define DEBUGPRINT
    77 //#endif
    78 
    79 // Debug print macro
    80 #ifdef DEBUGPRINT
    81 #include <e32svr.h>
    82 #define PRINT(x) RDebug::Print x;
    83 #else
    84 #define PRINT(x)
    85 #endif
    86 
    87 // ENumerations
    88 
    89 
    90 enum TEngineState
    91      {
    92      EStateNone,
    93      ECreated,
    94      EInitialized,
    95      ERunning,	
    96      EPaused,	
    97      EStopped,	
    98      };
    99 
   100 enum TYuvDataOptions
   101      {
   102      EYuv420Planner,
   103      EYuv422Interleaved
   104      };
   105 
   106 enum THWDevice 
   107 	{
   108 	EPostProcessor,
   109 	EDecoder
   110 	};
   111 
   112 enum TFLVFileType
   113 	{
   114 	EFLVNotSet,
   115 	EFLVContainer,
   116 	EFLVRaw
   117 	};
   118 
   119 // CLASS DECLARATION
   120 class CVDecTestAO;
   121 class CVDecTestEngine;
   122 class MVDecEngineObserver;
   123 
   124 
   125 /**
   126 *  Video Decoder Test Engine Observer
   127 *  
   128 *  @lib 
   129 *  @since 
   130 */
   131 class MVDecEngineObserver
   132 {
   133 public:
   134 	
   135 	virtual void MvdeStreamEndReached() = 0;
   136 	virtual void MvdeSetError(TInt aError) = 0;
   137 };
   138 
   139 /**
   140 *  Video Decoder Test Engine 
   141 *  implements common test execution block
   142 *  @lib 
   143 *  @since 
   144 */
   145 class CVDecTestEngine : public CBase , public MMMFDevVideoPlayObserver 
   146 #ifdef __CI_HEADERS__
   147 ,public MMmfVideoBufferManagementObserver
   148 #endif
   149 #ifdef __RESOURCENOTIFICATION__
   150 ,public MMmfVideoResourceObserver
   151 #endif
   152     {
   153 public:
   154 
   155      
   156      TEngineState iState;
   157 
   158 public:
   159     CVDecTestEngine () { }
   160     ~CVDecTestEngine ();
   161     static CVDecTestEngine* NewL(MVDecEngineObserver& aTestClass);
   162     
   163     //info test method
   164     void SetCodecType(TVideoCodec aCodec);
   165     //void GetDecoderInfoL(const TDesC8& aMimeType, TBool aExactMatch);
   166     //void GetPostProcessorInfoL(TInt aCombination);
   167     void GetHeaderInformationL();
   168     
   169 	void GetHeaderInformationL(TVideoDataUnitType aDataUnitType, TVideoDataUnitEncapsulation aDataUnitEncapsulation);
   170     //void GetHeaderInfoL(const TUid& aDecUid, TVideoDataUnitType aDataUnitType, TVideoDataUnitEncapsulation aDataUnitEncapsulation);
   171 	void GetBitstreamCountersL();
   172 	void PreDecoderBufferBytes();	
   173     void PictureBufferBytes();
   174     
   175     // Video test control methods
   176     //void SetUpL(TBool aScreenAcces);
   177     void SetUpL(TSize aSize, TBool aScreenAccess, TBool aCIBuffMgmt);
   178     void CreateDecoderL(const TUid& aDecUid, TVideoCodec aCodec, const TDesC8& aMimeType, TYuvDataOptions aOutFormat);
   179     void CreatePostProcessorL(const TUid& aPostprocUid, const TYuvFormat& aInputFormat, const TUncompressedVideoFormat& aOutputFormat, TUint32 aCombination);
   180     void CreateDecPostprocL(const TUid& aDecUid, TVideoCodec aCodec, const TUid& aPostprocUid, TUint32 aCombination);
   181     TInt Initialize();
   182     TInt InitializeAndDelete();
   183     TInt Start(TBool aInputEnd);
   184     TInt Stop();
   185     TInt Resume();
   186     TInt Pause();
   187     void FreezePicture(TTimeIntervalMicroSeconds aTimeStamp);
   188     void ReleaseFreeze(TTimeIntervalMicroSeconds aTimeStamp);
   189     void TearDown();    
   190     void SetFrameMatch(TBool aMatch);
   191     TInt FrameJump(TInt aNumToJump );
   192     void SetFrameDrop(TInt aFrameInterval, TInt aFrameNum, TBool aFrameDropMarker );
   193     void SetFLVPassword(TDesC8& aPassword); 
   194     void EnableInstantFpsL(TFileName& aOutFileName);
   195     
   196     // Select and set Postprocessing  
   197     void SetPostProcessTypesL(TInt aHWDevice, TUint32 aCombination);
   198     void SetInputCropOptionsL(TInt aHWDevice, TRect aCrop);
   199     void SetYuvToRgbOptionsL(TInt aHWDevice, TYuvToRgbOptions aOptions);
   200     void SetRotateOptionsL(TInt aHWDevice, TRotationType aRotation);
   201     void SetScaleOptionsL(TInt aHWDevice, TSize aSize, TBool aAntiAliasFiltering);
   202     void SetScaleOptionsL(TInt aNumFactor,TInt aDenoFactor, TBool aAntiAliasFiltering);
   203     void SetOutputCropOptionsL(TInt aHWDevice, TRect aCrop);
   204     void CommitL();
   205     void Revert();    
   206     
   207     void SetClockSource();
   208     void SetInputBufferSize(TInt aSize);
   209     void SetHrdVbvSpec(THrdVbvSpecification aHrdVbvSpec, const TDesC8& aHrdVbvParams);
   210     void SetPostProcSpecificOptionsL(TInt aHWDevice, const TDesC8& aOptions);
   211     void SetScreenClipRegion(TRegion& aRegion);
   212     void SetPauseOnClipFail(TBool aPause);    
   213     void IsPlaying();
   214     void GetPictureCounters();
   215     void NumFreeBuffers();
   216     void NumComplexityLevels(TInt aHWDevice);
   217     void InputEnd();
   218     void GetNewPictureInfo(TTimeIntervalMicroSeconds& aEarliestTimestamp, 
   219 						   TTimeIntervalMicroSeconds& aLatestTimestamp);
   220     void GetTimedSnapshotL(const TUncompressedVideoFormat& aFormat, 
   221 							const TTimeIntervalMicroSeconds& aPresentationTimestamp); 
   222 	void GetTimedSnapshotL(const TUncompressedVideoFormat& aFormat, const TPictureId& aPictureId);						
   223     void CancelTimedSnapshot();
   224     void GetSupportedSnapshotFormatsL();
   225     
   226     // Complexity level
   227     void SetComplexityLevel(TInt aHWDevice, TInt aLevel);
   228     void GetComplexityLevelInfo(TInt aHWDevice, TInt aLevel);
   229     
   230     //DSA
   231     void StartDirectScreenAccessL();
   232     void StartDirectScreenAccessL(TRect aVideoRect, TRect aClipRegion);
   233     void AbortDirectScreenAccess();    
   234     void Redraw();
   235     
   236     void SetWindowRect(TInt aX, TInt aY, TSize aSize);
   237     void SetSecondScreenAccess(TBool aStatus);
   238     
   239     // snap shot methods
   240     void GetSnapshotL(TUncompressedVideoFormat& aFormat);
   241     
   242     void EnableSynchronization(TInt aFrameRate);
   243     void EnableFrameMeasurementTest(TBool aEnable);
   244     void SetSecureOutputL(TBool aSecure);
   245     void SetPosition(const TTimeIntervalMicroSeconds& aPlaybackPosition);
   246     void ResetPosition();
   247     TTimeIntervalMicroSeconds PlaybackPosition();
   248     void DecodingPosition();
   249     void ListFrameSizeL(RArray<TInt> aFramesizes);
   250     TInt GetFrameSizeCount();
   251     //void GetPictureCounter();
   252     void SetLandscapeMode();
   253     void SelectDecoderL(const TUid& aUid);
   254     void SelectPostProcessorL(const TUid& aUid);
   255     void SetInputFormatL(TInt aHwDev, const TUncompressedVideoFormat& aFormat);
   256     void SetInputFormatL(TInt aHwDev, const CCompressedVideoFormat& aFormat, 
   257 						 TVideoDataUnitType aDataUnitType, TVideoDataUnitEncapsulation aEncapsulation,
   258 						 TBool aDataInOrder);
   259 	void SetOutputFormatL(TInt aHwDev, const TUncompressedVideoFormat& aFormat);						 
   260     void SetBufferOptionsL(const CMMFDevVideoPlay::TBufferOptions& aOptions);
   261     void GetBufferOptions();
   262     void SynchronizeDecoding(TBool aSynch);
   263     void SetVideoDestScreenL(TBool aDest);
   264     void SetYuvToRgbOptionsL(TInt aHWDevice, const TYuvToRgbOptions& aOptions, const TYuvFormat& aYuvFormat, TRgbFormat aRgbFormat);
   265     void FindCommonFormatsL();
   266     TInt FindDecodersL(const TDesC8& aMimeType, TUint32 aPostProcType, TBool aExactMatch, TUid& aUid);
   267     TInt FindPostProcessorsL(TUid& aUid, TUint32 aPostProcType);
   268     void GetDecoderListL();
   269     void ConfigureDecoderL(TVideoPictureHeader& aVideoPictureHeader);
   270     void ConfigureDecoderL();
   271     void GetOutputFormatListL(TInt aHWDevice);
   272     void GetPostProcessorListL();
   273     void VideoDecoderInfoL(TUid aVideoDecoder);
   274     void PostProcessorInfoL(TUid aPostProcessor);
   275     
   276     TReal ConvertToRealL(const TDesC& aPtr);
   277     
   278     //File operations
   279     void OpenFileL(TFileName& aInFileName);
   280     void OpenFileL(TFileName& aOutFileName, TFileName& aInFileName);
   281     void CloseFile();
   282     void CorruptInput(TInt aFilter, TInt aInterval, TInt aFrameNum, TInt aPct);
   283     void CorruptEngineL();
   284     void CorruptEngineL( TVideoInputBuffer* aCodedInBuffer ); 
   285     TInt CreateCorruptedFileL(); 
   286     void OpenFileToWriteL(TFileName& aInFileName);
   287     TInt ReadVC1FrameL(TVideoInputBuffer* aCodedInBuffer);
   288     TInt ReadMPEG4FrameL(TVideoInputBuffer* aCodedInBuffer); 
   289     
   290     TInt SupportsFormatL(const TUid& aUid, const CCompressedVideoFormat& aFormat);
   291 	TInt SupportsFormatInfoL(const TUid& aUid, const CCompressedVideoFormat& aFormat);		
   292 	TInt SupportsAccelerationL(TInt aHwDev, const TUid& aUid);		
   293 	TInt SupportsDirectDisplayL(TInt aHwDev, const TUid& aUid);		
   294 	TInt SupportsMaxBitrateL(const TUid& aUid, TInt aBitrate);		
   295 	TInt SupportsMaxPictureSizeL(const TUid& aUid, TSize aSize);		
   296 	TInt SupportsMaxPictureRateL(const TUid& aUid, TPictureRateAndSize& aRateAndSize);			
   297 	TInt SupportsPictureLossL(const TUid& aUid);		
   298 	TInt SupportsSliceLossL(const TUid& aUid);
   299  	TInt SupportsOutputFormatL(TInt aHwdev, const TUncompressedVideoFormat& aFormat);
   300  	void SetSlowClient(TBool aOption);
   301  	void SetFastClient(TBool aOption);
   302  	TInt SetAUFormat();
   303  	TInt MoveFileL(const TDesC &anOld, const TDesC &aNew);
   304  	TInt CopyFileL(const TDesC &anOld, const TDesC &aNew); 	
   305  	
   306     
   307     // For Active objects
   308     void HandleNewBufferL();
   309         
   310     // From DevVideo Play observer 
   311     void MdvpoNewBuffers();
   312     void MdvpoReturnPicture(TVideoPicture* aPicture);
   313     void MdvpoSupplementalInformation(const TDesC8& aData, const TTimeIntervalMicroSeconds& aTimestamp, const TPictureId& aPictureId);
   314     void MdvpoPictureLoss();
   315     void MdvpoPictureLoss(const TArray<TPictureId>& aPictures);
   316     void MdvpoSliceLoss(TUint aFirstMacroblock, TUint aNumMacroblocks, const TPictureId& aPicture);
   317     void MdvpoReferencePictureSelection(const TDesC8& aSelectionData);
   318     void MdvpoTimedSnapshotComplete(TInt aError, TPictureData* aPictureData, const TTimeIntervalMicroSeconds& aPresentationTimestamp, const TPictureId& aPictureId);
   319     void MdvpoNewPictures();
   320     void MdvpoFatalError(TInt aError);
   321     void MdvpoInitComplete(TInt aError);
   322     void MdvpoStreamEnd();
   323    
   324     // Buffer Management Custom Interface observer 
   325 #ifdef __CI_HEADERS__    
   326     void MmvbmoNewBuffers();
   327     void MmvbmoReleaseBuffers();
   328 #endif
   329 #ifdef __RESOURCENOTIFICATION__
   330 	void MmvroResourcesLost(TUid aMediaDevice);
   331     void MmvroResourcesRestored(TUid aMediaDevice);
   332 #endif
   333  
   334 protected:
   335     // Own test functions
   336     void GetInputBufferL();
   337     void FillAndSendBufferL();
   338     void GetReturnedPictureL();
   339     void SaveAndReturnPicture();
   340     TInt ReadOneCodedPicture(TVideoInputBuffer* aCodedInBuffer);
   341     TInt ReadOneCodedPicture(TVideoInputBuffer* aCodedInBuffer, TInt aSize);
   342     TInt ReadRawPicture();
   343      
   344 private:
   345 	TUint8 ReadByteFromFile();
   346 	void GoBackInFile(TUint aBytes);
   347 	void ReadDataToBuffer(TVideoInputBuffer* aCodedInBuffer, TInt aSize, TBool aDiscard = EFalse);
   348 	TBool CheckAndFillDataChunk();
   349 	TBool ReadItemLE(unsigned char *readBuffer, int Size, unsigned char* pItem);
   350 	TInt LoadNextFrameL(TVideoInputBuffer* aCodedInBuffer);
   351     void ConstructL(MVDecEngineObserver& aTestClass);
   352     void AssertTIntEqualL(TInt aExpected, TInt aActual);
   353     void PrintUncompressedFormat(const TUncompressedVideoFormat& aFormat);
   354     
   355 private:
   356     CMMFDevVideoPlay* iDevvp;			  //points to DevVideo Play
   357     THwDeviceId iDecHWDevId;              //Hwdevise ID of selected Decoder
   358     THwDeviceId iPostProcId;              //Hwdevise ID of selected postprocessor
   359     TUid iPostProcessorUid;
   360     TUid iDecoderUid;
   361     CVDecTestAO* iDecTestAO;              
   362     TBool iRunning;                       //State of scheduler
   363     TYuvFormat iRawFormat;                //Used for Decoder output, postprocessor input 
   364     TRgbFormat iDispFormat;               // Display Options
   365     TRect iDispRect;                        
   366     TInt iError;
   367     TVideoInputBuffer* iCodedInBuffer;     // Pointer to Decoder input buffer
   368     TVideoInputBuffer* iCorruptedInBuffer;   //Pointer to corrupted input for decoder
   369     TInt iInBuffSize;                 // Size of decoder input buffer
   370     TVideoPicture* iOutBuffer;             // Pointer to picuture class for output data in memory buffer output 
   371     TVideoPicture* iOutBufferTemp;             // Pointer to picuture class for output data in memory buffer output 
   372     TVideoPicture* iRawInBuffer;            // Used for postprocessor input
   373     HBufC8* iRawDataArea;                  // Pointer to Heap buffer, filled with input data to postprocessor
   374     TInt64 iTimeStamp; 
   375     TInt64 iFrameTimeInterval;              
   376     TInt iSentBuffCount;                    //Number of frames sent to target HwDevice    
   377     TInt iReturnedBuffCount;                //Number of frames returned from target HwDevice
   378     TInt iPictureLoss;                      // number of picture loss
   379     TBool iInputEnd;
   380     TBool iStreamEnd; 
   381     TVideoCodec iCodecType;                
   382     TSize iPictureSize; 
   383     CSystemClockSource* iClock;            //Clock source, based on System clock
   384     TBool iSynchronized;
   385     TBool iDirectScreenAccess;
   386     TBool iCIBuffMgmtOn;
   387     TBool iDisableInputEnd;
   388     TBool iFrameMatch;              // input frame number should match output frame number
   389     TInt  iFrameJump;
   390     TInt  iFrameJumpCounter;
   391     TInt iFrameWriteLength;
   392     TInt iCurrentFilePos;
   393 #ifdef __CI_HEADERS__     	   
   394     MMmfVideoBufferManagement* iCIBuffMgmt;  
   395 #endif    
   396     MVDecEngineObserver* iTestClass;
   397     TBool iFrameMeasurement;
   398     TBool iDsaStarted;
   399     TBool iLandscapeMode;
   400     TInt iNoBuffAvailable;
   401     RArray<TInt> iFrameSizeList;
   402     TPictureData iPictureDataSnapshot;
   403     TBuf8<128> iInFileName;
   404     TBool iSetSlowClient;
   405     TBool iSetFastClient;
   406     TBool iSetAUFormat;
   407     TBool iOutFileOpen;
   408     TUint8* iAUBuffer;
   409     TUint32* iNalOffsetArray;
   410     TUint32* iNalLengthArray;
   411     TReal32 iFrameTime;
   412     
   413     TUint8* iDataChunk;
   414     TUint8* iReadDataChunk;
   415     TUint8* iWriteDataChunk;
   416     TUint iDataReadFromFile;
   417     TUint iDataThreshold;
   418     TBool iEndOfData;
   419     TBool iLastFrame;
   420     TBool iUseSecondScreen;
   421     
   422     //File IO
   423     RFs   iFs;
   424     RFile iInFile;                         // Input data file
   425     RFile iOutFile;                        // Output data file
   426     RFile iOutCorruptedFile;
   427     RFile iLogFile;
   428 	TBool iDeleteDecoderFromInitComp;
   429 	
   430 	TInt iFlvCounter;
   431 	TBool iCorruptMarker;
   432 	TInt iFilter;
   433 	TInt iInterval;
   434 	TInt iFrameNum;
   435 	TInt iPercentage;
   436 	TInt iFrameCounter;
   437 	TInt iCorruptCounter;
   438 	TInt iFrameDropCounter;
   439 	TInt iFrameDropInterval;
   440 	TInt iFrameDropNum;
   441 	TInt iFrameDropNumCounter;
   442 	TBool iFrameDropMarker;
   443 	TFileName iOutFileName;
   444 	TFileName iOutCorruptedFileName;
   445 	TBool iOutCorruptedFileOpen;
   446 	TBuf8<128> iPasswordForFLV;
   447 	TBool iSetPassword;
   448     TBool iInstantFpsEnabled;
   449     RArray<TTimeIntervalMicroSeconds> iInstantFpsList;
   450     RFile iFpsFile;
   451 
   452 	
   453 	// Memory check
   454 	TInt iMemAlloc;
   455 	TInt iMemDelete;
   456 	
   457     
   458     TInt32 iDataChunkSize;
   459     //Fbs
   460 
   461     CFbsScreenDevice* iScreenDevice;
   462     
   463     CActiveSchedulerWait* iScheduler;      //Nested scheduler
   464     
   465     TTime							iTime;
   466 	TDateTime						iTimeBeforeDecoding;
   467 	TDateTime						iTimeAfterDecoding;	
   468 	//TInt							iNumFramesDecoded;
   469 	//TUint64							iTotalTime;
   470 	//TBool 							iIsBeforeTimeUsed;
   471 	TUint64							iBeforeDecodingTime;
   472 	RArray<TUint64>					iBeforeDecoingTimesQueue;
   473     TUint							iFrame;
   474     //	TInt							iLength;
   475 	//TBool							iFirstTime;
   476 	TBool                           iNumFreeBufsFirstTime;
   477 	TTimeIntervalMicroSeconds		iTimeToPlay;
   478     TTimeIntervalMicroSeconds		iPresentationTimestamp;
   479 	TBool							iNoOfFreeBuffFlag;
   480 	
   481 	
   482 	TInt tempFrame;
   483 
   484 	TFLVFileType                    iFLVFileType;
   485     };
   486 
   487 
   488 
   489 
   490 /**
   491 *  Video Decoder Test Engine AO
   492 *  Provides async services
   493 *  @lib 
   494 *  @since 
   495 */
   496 
   497 class CVDecTestAO : public CActive
   498 {
   499 	public:
   500 		CVDecTestAO(CVDecTestEngine* aTestEngine);
   501   		~CVDecTestAO();
   502   		void RequestData();
   503 	private:
   504 		void RunL();
   505   		void DoCancel();
   506 
   507 	private:
   508   		CVDecTestEngine* iTestEngine;
   509   	    
   510 };
   511 
   512 
   513 
   514 
   515 #endif