os/mm/mmdevicefw/mdf/src/video/decoderadapter/mdfvideodecodehwdeviceadapter.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #ifndef MDFVIDEODECODEHWDEVICEADAPTER_H
    17 #define MDFVIDEODECODEHWDEVICEADAPTER_H
    18 
    19 #include <fbs.h>
    20 #include <mmf/devvideo/videoplayhwdevice.h>
    21 #include "mdfvideodecodehwdeviceadapter.hrh"
    22 #include <mmf/server/mmfdatabuffer.h>
    23 
    24 #include <mdf/mdfinputport.h>
    25 #include <mdf/mdfoutputport.h>
    26 #include <mdf/mdfprocessingunit.h>
    27 #include <mdf/mdfpuloader.h>
    28 #include <mdf/codecapivideoresolverutils.h>
    29 #include <mmf/devvideo/devvideopuconfig.h>
    30 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    31 #include <mmf/devvideo/devvideohwdeviceadaptersetup.h>
    32 #endif
    33 
    34 // From hwdevicevideoutils.dll
    35 #include "mdfvideodecoderbuffermanager.h"
    36 #include "mdfplayerengine.h"
    37 
    38 const TUid KUidDevVideoDecodeHwDevice = {KUidDevVideoDecoderHwDeviceDefine};
    39 
    40 // decoder info
    41 _LIT(KVideoDecoderInfoManufacturer, "Symbian Ltd.");
    42 _LIT8(KVideoDecoderInfoCSInfo, "Coded by Symbian");
    43 _LIT8(KVideoDecoderInfoISInfo, "Implemented by Symbian");
    44 const TInt KVideoDecoderInfoVersionMaj = 0;
    45 const TInt KVideoDecoderInfoVersionMin = 1;
    46 const TInt KVideoDecoderInfoVersionBuild = 1;
    47 
    48 /**
    49 Video decoder hardware device. 
    50 This is the DevVideo decoder plugin component
    51 @internalComponent
    52 */
    53 class CMdfVideoDecodeHwDeviceAdapter :	public CMMFVideoDecodeHwDevice,
    54 				       					public MMdfVideoPlayerHwDeviceObserver,
    55 				       					public MMdfInputPortObserver,
    56 				       					public MMdfOutputPortObserver,
    57 				       					public MMdfProcessingUnitObserver,
    58 				       					public MDevVideoHwDeviceAdapterSetup		       					
    59 
    60 {
    61 
    62 public:
    63 		
    64 	/**
    65 	The current state of the Hardware Device Adapter.
    66 	*/
    67 	enum THwDevAdapterState
    68 		{
    69 		/*
    70 		The PULoader has been loaded.
    71 		*/
    72 		EProcessingUnitLoaderLoaded,
    73 		/*
    74 		The Processing Units have been loaded.
    75 		*/
    76 		EProcessingUnitLoaded,
    77 		/*
    78 		The Processing Units are currently being initialised.
    79 		*/
    80 		EProcessingUnitInitializing,
    81 		/*
    82 		The Processing Units are currently in the idle state.
    83 		*/
    84 		EProcessingUnitIdle,
    85 		/*
    86 		The Processing Units are currently in the executing state.
    87 		*/
    88 		EProcessingUnitExecuting,
    89 		/*
    90 		The Processing Units are currently in the paused state.
    91 		*/
    92 		EProcessingUnitPaused		
    93 		};	
    94 
    95 
    96 	static CMdfVideoDecodeHwDeviceAdapter* NewL();
    97 	~CMdfVideoDecodeHwDeviceAdapter();		
    98 	TBool FrameBufferAvailable() const;
    99 
   100 	// from CMMFVideoHwDevice
   101     TAny* CustomInterface(TUid aInterface);
   102 
   103 	// from CMMFVideoPlayHwDevice
   104 	CPostProcessorInfo* PostProcessorInfoLC();
   105 	void GetOutputFormatListL(RArray<TUncompressedVideoFormat>& aFormats);
   106 	void SetOutputFormatL(const TUncompressedVideoFormat &aFormat);
   107 	void SetPostProcessTypesL(TUint32 aPostProcCombination);
   108 	void SetInputCropOptionsL(const TRect& aRect);
   109 	void SetYuvToRgbOptionsL(const TYuvToRgbOptions& aOptions, const TYuvFormat& aYuvFormat, TRgbFormat aRgbFormat);
   110 	void SetYuvToRgbOptionsL(const TYuvToRgbOptions& aOptions);
   111 	void SetRotateOptionsL(TRotationType aRotationType);
   112 	void SetScaleOptionsL(const TSize& aTargetSize, TBool aAntiAliasFiltering);
   113 	void SetOutputCropOptionsL(const TRect& aRect);
   114 	void SetPostProcSpecificOptionsL(const TDesC8& aOptions);
   115 	void SetClockSource(MMMFClockSource* aClock);
   116 	void SetVideoDestScreenL(TBool aScreen);
   117 	void Initialize();
   118 	void StartDirectScreenAccessL(const TRect& aVideoRect, CFbsScreenDevice& aScreenDevice, const TRegion& aClipRegion);
   119 	void SetScreenClipRegion(const TRegion& aRegion);
   120 	void SetPauseOnClipFail(TBool aPause);
   121 	void AbortDirectScreenAccess();
   122 	TBool IsPlaying();
   123 	void Redraw();
   124 	void Start();
   125 	void Stop();
   126 	void Pause();
   127 	void Resume();
   128 	void SetPosition(const TTimeIntervalMicroSeconds& aPlaybackPosition);
   129 	void FreezePicture(const TTimeIntervalMicroSeconds& aTimestamp);
   130 	void ReleaseFreeze(const TTimeIntervalMicroSeconds& aTimestamp);
   131 	TTimeIntervalMicroSeconds PlaybackPosition();
   132 	TUint PictureBufferBytes();
   133 	void GetPictureCounters(CMMFDevVideoPlay::TPictureCounters& aCounters);
   134 	void SetComplexityLevel(TUint aLevel);
   135 	TUint NumComplexityLevels();
   136 	void GetComplexityLevelInfo(TUint aLevel, CMMFDevVideoPlay::TComplexityLevelInfo& aInfo);
   137 	void ReturnPicture(TVideoPicture* aPicture);
   138 	TBool GetSnapshotL(TPictureData& aPictureData, const TUncompressedVideoFormat& aFormat);
   139 	void GetTimedSnapshotL(TPictureData* aPictureData, const TUncompressedVideoFormat& aFormat, const TTimeIntervalMicroSeconds& aPresentationTimestamp);
   140 	void GetTimedSnapshotL(TPictureData* aPictureData, const TUncompressedVideoFormat& aFormat, const TPictureId& aPictureId);
   141 	void CancelTimedSnapshot();
   142 	void GetSupportedSnapshotFormatsL(RArray<TUncompressedVideoFormat>& aFormats);
   143 	void InputEnd();
   144 	void CommitL();
   145 	void Revert();
   146 
   147 	// from CMMFVideoDecodeHwDevice
   148     CVideoDecoderInfo* VideoDecoderInfoLC();
   149 	TVideoPictureHeader* GetHeaderInformationL(TVideoDataUnitType aDataUnitType, TVideoDataUnitEncapsulation aEncapsulation, TVideoInputBuffer* aDataUnit);
   150     void ReturnHeader(TVideoPictureHeader* aHeader);
   151     void SetInputFormatL(const CCompressedVideoFormat& aFormat, TVideoDataUnitType aDataUnitType, TVideoDataUnitEncapsulation aEncapsulation, TBool aDataInOrder);
   152     void SynchronizeDecoding(TBool aSynchronize);
   153     void SetBufferOptionsL(const CMMFDevVideoPlay::TBufferOptions& aOptions);
   154     void GetBufferOptions(CMMFDevVideoPlay::TBufferOptions& aOptions);
   155     void SetHrdVbvSpec(THrdVbvSpecification aHrdVbvSpec, const TDesC8& aHrdVbvParams);
   156     void SetOutputDevice(CMMFVideoPostProcHwDevice* aDevice);
   157     TTimeIntervalMicroSeconds DecodingPosition();
   158     TUint PreDecoderBufferBytes();
   159     void GetBitstreamCounters(CMMFDevVideoPlay::TBitstreamCounters& aCounters);
   160     TUint NumFreeBuffers();
   161     TVideoInputBuffer* GetBufferL(TUint aBufferSize);
   162     void WriteCodedDataL(TVideoInputBuffer* aBuffer);
   163 	void SetProxy(MMMFDevVideoPlayProxy& aProxy);
   164 	void ConfigureDecoderL(const TVideoPictureHeader& aVideoPictureHeader);
   165 	
   166 	// from MMdfVideoPlayerHwDeviceObserver
   167 	TUint Time() const;
   168 	TBool FrameAvailable() const;
   169 	void DisplayFrame();
   170 	void DiscardFrame();
   171 	
   172 	// from MMdfInputPortObserver
   173 	void MipoWriteDataComplete(const MMdfInputPort* aInputPort, CMMFBuffer* aBuffer,
   174 		TInt aErrorCode);
   175 	void MipoDisconnectTunnelComplete(const MMdfInputPort* aInputPort, TInt aErrorCode);
   176 	void MipoRestartTunnelComplete(const MMdfInputPort* aInputPort,	TInt aErrorCode);
   177 	
   178 	// from MMdfOutputPortObserver
   179 	void MopoReadDataComplete(const MMdfOutputPort* aOutputPort, CMMFBuffer* aBuffer,
   180 		TInt aErrorCode);
   181 	void MopoDisconnectTunnelComplete(const MMdfOutputPort* aOutputPort, TInt aErrorCode);
   182 	void MopoRestartTunnelComplete(const MMdfOutputPort* aOutputPort, TInt aErrorCode);
   183 		
   184 	// from MMdfProcessingUnitObserver
   185 	void InitializeComplete(const CMdfProcessingUnit* aPu, TInt aErrorCode);
   186 	void ExecuteComplete(const CMdfProcessingUnit* aPu, TInt aErrorCode);
   187 	// from MDevVideoHwDeviceAdapterSetup
   188 	void LoadProcessingUnitL(const CImplementationInformation& aImplInfo);
   189 
   190 private:
   191 	CMdfVideoDecodeHwDeviceAdapter();
   192 	void ConstructL();
   193 	
   194 	void InitializeL();
   195 	void DoPostPictureNotify();
   196 	void DisplayFrameDirect(TVideoPicture* aPicture); 
   197 	void DisplayLastFrameDirect(); 
   198 	
   199 	void SendLastBuffer();
   200 	
   201 private:
   202 	// minimum decoder buffer useful data size.
   203 	// to work around a problem with the decoder when too 
   204 	// small a buffer passed to it will cause a KERN-EXEC:3;
   205 	// the alternative is putting bounds-checking into the C code
   206 	// throughout reading an encoded header, which would be inefficient
   207 	static const TInt KVideoDecoderMinUsefulDataSize = 256;
   208 
   209 	// minimum decoder data buffer size.
   210 	// the decoder will always return a buffer of at least this size.
   211 	static const TInt KVideoDecoderMinDataBufferSize = 0x2000; // 8k
   212 
   213 	// maximum decoder data buffer size.
   214 	// this is the largest buffer the decoder is able to return.
   215 	static const TInt KVideoDecoderMaxDataBufferSize = 0x40000; // 512k
   216 	
   217 	MMMFDevVideoPlayProxy* iProxy;
   218 
   219 	// the decoder itself
   220 	CMdfProcessingUnit* iDecoderPU;
   221 	
   222 	// the buffer manager
   223 	CMdfVideoDecoderBufferManager* iBufferManager;
   224 	
   225 	// the player engine
   226 	CMdfVideoPlayerEngine* iPlayerEngine;
   227 	
   228 	// the Processing Unit Loader plugin
   229 	CMdfPuLoader* iPuLoader;
   230 	
   231 	// video format arrays (for VideoDecoderInfoLC())
   232 	RPointerArray<CCompressedVideoFormat> iInputVidFormats;
   233 	RArray<TUncompressedVideoFormat> iOutputVidFormats;
   234 	RArray<TPictureRateAndSize> iPictureRates;
   235 	
   236 	// Processing Unit Ports
   237 	MMdfInputPort* iDecoderPUInputPort; 
   238 	MMdfOutputPort* iDecoderPUOutputPort;
   239 
   240 	// decoder settings
   241 	TUncompressedVideoFormat iFormat;
   242 	TReal32 iFrameRate;
   243 	CMMFDevVideoPlay::TPictureCounters iPictureCounters;
   244 	CMMFDevVideoPlay::TBitstreamCounters iBitstreamCounters;
   245 	CMMFDevVideoPlay::TComplexityLevelInfo iComplexityLevelInfo;
   246 	CMMFDevVideoPlay::TBufferOptions iBufferOptions;
   247 	
   248 	// clock settings
   249 	MMMFClockSource* iClockSource;
   250 	TBool iSynchronize;
   251 	TInt64 iSystemClock;	// system clock without HAL
   252 	
   253 	// header info
   254 	TVideoPictureHeader* iPictureHeader;
   255 			
   256 	// input data buffer pointers 
   257 	CVideoDataBuffer* iInputBuffer; // not owned
   258 	CMMFBuffer* iPUInputBuffer; // not owned
   259 	
   260 	// parameters for decoding loop
   261 	TInt iInDataSize;
   262 	TInt iTotalBytesUsed;
   263 	
   264 	// player settings
   265 	TBool iPrimed;
   266 	TBool iInputBufferWaiting;
   267 	TBool iInputEnd;
   268 	TSize iFrameSize;
   269 	
   270 	TBool iDisplayPictureAvailable;
   271 	
   272 	// post-processor output device, if any
   273 	CMMFVideoPostProcHwDevice* iPostProcOutputDevice;
   274 	
   275 	// direct screen access
   276 	TBool iDSAEnabled;
   277 	TBool iDSAStarted;
   278 	CFbsScreenDevice* iScreenDevice; // not owned
   279 	CFbsBitGc* iScreenDeviceGc;
   280 	TRect iScreenDeviceRect;
   281 	
   282 	TUid iPuLoaderDtorKey;	
   283 	THwDevAdapterState iState;	
   284 	TBool iPUInitialized;
   285 	
   286 	CCodecApiVideoOpaqueData* iPuData;	
   287 	HBufC* iManufacturer;
   288 	TUid iPuUid;
   289 	TBool iLastFrameBufferReceived;
   290 	TSize iMaxPictureSize;
   291 	TBool iWriteRequestOutstanding;
   292 	};
   293 
   294 #endif // MDFVIDEODECODEHWDEVICEADAPTER_H