os/mm/mmplugins/mmfwplugins/src/Plugin/Controller/Video/AviPlayController/aviplaycontroller.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 AVIPLAYCONTROLLER_H
    17 #define AVIPLAYCONTROLLER_H
    18 
    19 //standard epoc32 includes
    20 #include <ecom/implementationproxy.h>
    21 #include <ecom/ecom.h>
    22 #include <e32std.h>
    23 #include <e32base.h>
    24 #include <fbs.h>
    25 #include <bitstd.h>
    26 #include <bitdev.h>
    27 
    28 #include <mmf/common/mmfcontroller.h>
    29 #include <mmf/server/mmfdatasource.h>
    30 #include <mmf/server/mmfdatasink.h>
    31 #include <mmf/server/mmffile.h>
    32 #include <mmf/common/mmfdrmcustomcommands.h>
    33 #include <mmf/common/mmfstandardcustomcommands.h>
    34 #include <mmf/devvideo/devvideoplay.h>
    35 #include <mmf/devvideo/videoplayhwdevice.h>
    36 #include <mmf/server/sounddevice.h>
    37 #include <mmf/server/mmfaudiooutput.h>
    38 #include <mmf/server/mmfcodec.h>
    39 
    40 #ifdef SYMBIAN_BUILD_GCE
    41 #include <mmf/common/mmfvideosurfacecustomcommands.h>
    42 #include <mmf/devvideo/devvideovideosurfacecustominterface.h>
    43 #endif // SYMBIAN_BUILD_GCE
    44 
    45 #include "avireader.h"
    46 #include "aviplaycontrolleruids.hrh"
    47 
    48 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
    49 #include <mmf/common/mmfvideosubtitlecustomcommands.h>
    50 
    51 class CSrtReader;
    52 class CMMFDevSubtitle;
    53 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
    54 	
    55 class CAviReader;
    56 class MAviReaderObserver;
    57 
    58 const TInt KNumSampleRates = 9;
    59 
    60 struct TSampleRateTable
    61   	{
    62 	TInt iRate;
    63 	TMMFSampleRate iRateEnum;
    64 	};
    65 
    66 //TAviPlayControllerPanics is an enumeration with the following entries:
    67 //EBadState indicates a state violation.
    68 //EBadCall indicates a bad call
    69 enum TAviPlayControllerPanics
    70 	{
    71 	EBadCall,
    72 	EBadState
    73 	};
    74 
    75 
    76 //The public API of CAviPlayController.It mainly implements the public APIs in CMMFController. It also implements PlayCustomInterfaces 
    77 //to support extended functionality during playing.This class is reponsible for controlling the audio and video data transfer from file to
    78 //devvideoplay and devsound.
    79 class CAviPlayController: public CMMFController, 
    80                           public MMMFVideoPlayControllerCustomCommandImplementor,
    81 						  public MMMFVideoControllerCustomCommandImplementor,
    82 						  public MMMFAudioPlayDeviceCustomCommandImplementor,
    83 						  public MMMFDevVideoPlayObserver,
    84 						  public MDevSoundObserver,
    85 						  public MAviReaderObserver,
    86 						  public MMMFResourceNotificationCustomCommandImplementor,
    87  					  	  public MMMFVideoSetInitScreenCustomCommandImplementor,
    88  					  	  public MMMFVideoPlayControllerExtCustomCommandImplementor
    89 #ifdef SYMBIAN_BUILD_GCE 					  	  
    90  					  	  ,public MMMFVideoPlaySurfaceSupportCustomCommandImplementor,
    91  					  	  public MMMFVideoSurfaceObserver
    92 #endif // SYMBIAN_BUILD_GCE  
    93 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
    94 						  ,public MMMFVideoPlaySubtitleSupportCustomCommandImplementor
    95 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
    96 	{
    97 public:
    98 
    99 	static CAviPlayController* NewL();
   100 	~CAviPlayController();
   101 	// from CMMFController Implementation
   102     virtual void AddDataSourceL(MDataSource& aDataSource);
   103 	virtual void AddDataSinkL(MDataSink& aDataSink);
   104 	virtual void RemoveDataSourceL(MDataSource& aDataSource);
   105 	virtual void RemoveDataSinkL(MDataSink& aDataSink);
   106 	virtual void ResetL();
   107 	virtual void PrimeL();
   108     virtual void PrimeL(TMMFMessage& aMessage);
   109 	virtual void PlayL();
   110 	virtual void PauseL();
   111 	virtual void StopL();
   112 	virtual TTimeIntervalMicroSeconds PositionL() const;
   113 	virtual void SetPositionL(const TTimeIntervalMicroSeconds& aPosition);
   114 	virtual TTimeIntervalMicroSeconds DurationL() const;
   115 	virtual void CustomCommand(TMMFMessage& aMessage);
   116 	virtual void SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings);
   117 	virtual void GetNumberOfMetaDataEntriesL(TInt& aNumberOfEntries);
   118 	virtual CMMFMetaDataEntry* GetMetaDataEntryL(TInt aIndex);
   119 	//MMMFVideoPlayControllerCustomCommandImplementor
   120     void MvpcPrepare();
   121 	void MvpcGetFrameL(MMMFVideoFrameMessage& aMessage);
   122 	void MvpcGetAudioEnabledL(TBool& aEnabled);
   123 	void MvpcSetDisplayWindowL(const TRect& aWindowRect, const TRect& aClipRect);
   124 	void MvpcUpdateDisplayRegionL(const TRegion& aRegion);
   125 	void MvpcDirectScreenAccessEventL(const TMMFDSAEvent aDSAEvent);
   126 	void MvpcRefreshFrameL();
   127 	void MvpcPlayL(const TTimeIntervalMicroSeconds& aBegin, const TTimeIntervalMicroSeconds& aEnd);
   128 	void MvpcGetLoadingProgressL(TInt& aPercentage);
   129 	void MvpcSetRotationL(TVideoRotation aRotation);
   130 	void MvpcGetRotationL(TVideoRotation& aRotation);
   131 	void MvpcSetScaleFactorL(TReal32 aWidthPercentage, TReal32 aHeightPercentage, TBool aAntiAliasFiltering);
   132 	void MvpcGetScaleFactorL(TReal32& aWidthPercentage, TReal32& aHeightPercentage, TBool& aAntiAliasFiltering);
   133 	void MvpcSetCropRegionL(const TRect& aCropRegion);
   134 	void MvpcGetCropRegionL(TRect& aCropRegion);
   135 	// MMMFVideoControllerCustomCommandImplementor 
   136 	void MvcGetAudioCodecL(TFourCC& aCodec);
   137 	void MvcGetVideoBitRateL(TInt& aBitRate);
   138 	void MvcGetAudioBitRateL(TInt& aBitRate);
   139 	void MvcSetFrameRateL(TReal32 aFramesPerSecond);
   140 	void MvcGetFrameRateL(TReal32& aFramesPerSecond);
   141 	void MvcGetVideoFrameSizeL(class TSize &aVideoFrameSize);
   142 	void MvcGetVideoMimeTypeL(TDes8& aMimeType);
   143 	// from MMMFAudioPlayDeviceCustomCommandImplemetor 
   144 	void MapdSetVolumeL(TInt aVolume);
   145 	void MapdGetMaxVolumeL(TInt& aMaxVolume);
   146 	void MapdGetVolumeL(TInt& aVolume);
   147 	void MapdSetVolumeRampL(const TTimeIntervalMicroSeconds& aRampDuration);
   148 	void MapdSetBalanceL(TInt aBalance);
   149 	void MapdGetBalanceL(TInt& aBalance);
   150 
   151 	//from MMMFDevVideoPlayObserver
   152     void MdvpoNewBuffers();
   153     void MdvpoReturnPicture(TVideoPicture *aPicture);
   154     void MdvpoSupplementalInformation(const TDesC8 &aData, const TTimeIntervalMicroSeconds &aTimestamp, const TPictureId &aPictureId);
   155     void MdvpoPictureLoss();
   156     void MdvpoPictureLoss(const TArray< TPictureId > &aPictures);
   157     void MdvpoSliceLoss(TUint aFirstMacroblock, TUint aNumMacroblocks, const TPictureId &aPicture);
   158     void MdvpoReferencePictureSelection(const TDesC8 &aSelectionData);
   159     void MdvpoTimedSnapshotComplete(TInt aError, TPictureData *aPictureData, const TTimeIntervalMicroSeconds &aPresentationTimestamp, const TPictureId &aPictureId);
   160     void MdvpoFatalError(TInt aError);
   161     void MdvpoNewPictures();
   162     void MdvpoInitComplete(TInt aError);
   163     void MdvpoStreamEnd();
   164     // from MDevSoundObserver
   165     void InitializeComplete(TInt aError);
   166 	void ToneFinished(TInt aError);
   167 	void BufferToBeFilled(CMMFBuffer* aBuffer);
   168 	void PlayError(TInt aError);
   169 	void BufferToBeEmptied(CMMFBuffer* aBuffer); 
   170 	void RecordError(TInt aError);
   171 	void ConvertError(TInt aError);
   172 	void DeviceMessage(TUid aMessageType, const TDesC8& aMsg);
   173 	void SendEventToClient(const TMMFEvent& aEvent);
   174 	//from  MMMFResourceNotificationCustomCommandImplementor,for audio resource notification 
   175 	virtual void MarnRegisterAsClientL(TUid aEventType, const TDesC8& aNotificationRegistrationData);
   176 	virtual void MarnCancelRegisterAsClientL(TUid aEventType);
   177 	virtual void MarnGetResourceNotificationDataL(TUid aEventType, TDes8& aNotificationData);
   178 	virtual void MarnWillResumePlayL();		
   179 	// MMMFVideoSetInitScreenCustomCommandImplementor
   180 	void MvsdSetInitScreenNumber(TInt aScreenNumber);
   181 
   182 	// from MMMFVideoPlayControllerExtCustomCommandImplementor
   183 	virtual void MvpecSetPlayVelocityL(TInt aVelocity);
   184 	virtual TInt MvpecPlayVelocityL();
   185 	virtual void MvpecStepFrameL(TInt aStep);
   186 	virtual void MvpecGetPlayRateCapabilitiesL(TVideoPlayRateCapabilities& aCapabilities);
   187 	virtual void MvpecSetVideoEnabledL(TBool aVideoEnabled);
   188 	virtual TBool MvpecVideoEnabledL();
   189 	virtual void MvpecSetAudioEnabledL(TBool aAudioEnabled);
   190 	virtual void MvpecSetAutoScaleL(TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos);
   191 
   192 #ifdef SYMBIAN_BUILD_GCE
   193 	// MMMFVideoPlaySurfaceSupportCustomCommandImplementor
   194 	void MvpssUseSurfacesL();
   195 	void MvpssGetSurfaceParametersL(TSurfaceId& aSurfaceId,	TRect& aCropRect,
   196 											TVideoAspectRatio& aPixelAspectRatio);
   197 	void MvpssSurfaceRemovedL(const TSurfaceId& aSurfaceId);
   198 	
   199 	// MMMFVideoSurfaceObserver
   200 	void MmvsoSurfaceCreated();
   201     void MmvsoSurfaceParametersChanged();
   202     void MmvsoRemoveSurface();
   203 #endif // SYMBIAN_BUILD_GCE
   204 
   205 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
   206 	// MMMFVideoPlaySubtitleSupportCustomCommandImplementor
   207 	void MvpsusGetCrpParametersL(TInt aWindowId, TWsGraphicId& aId, TRect& aCrpRect);
   208 	void MvpsusAddSubtitleConfigL(const TMMFSubtitleWindowConfig& aConfig);
   209 	void MvpsusRemoveSubtitleConfigL(TInt aWindowId);
   210 	void MvpsusUpdateSubtitleConfigL(const TMMFSubtitleWindowConfig& aConfig);
   211 	void MvpsusGetSubtitlesAvailableL(TBool& aAvailable);
   212 	void MvpsusDisableSubtitlesL();
   213 	void MvpsusEnableSubtitlesL();
   214 	void MvpsusGetSubtitleLanguageL(TLanguage& aLanguage);
   215 	void MvpsusGetSupportedSubtitleLanguagesL(RArray<TLanguage>& aLanguages);
   216 	void MvpsusSetSubtitleLanguageL(TLanguage aLanguage);
   217 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
   218 	
   219 public:
   220    //TControllerState is an enumeration within the namespace  CAviVideoPlayController
   221    //The enumeration provides a set of control states:
   222    //EStopped is the initial state the controller resides in after it has been loaded
   223    //EPrimed is the state the controller is in when it has been associated with datapaths but is not streaming data
   224    //EPlaying is the state the controller is in when it is streaming data
   225    enum TControllerState
   226 		{
   227 		EStopped,
   228 		EPrimed,
   229 		EAudioReadyToPlay,
   230 		EPlaying
   231 		};
   232 protected:
   233     CAviPlayController();
   234    	void StartPrimeL();
   235 	TBool SelectFirstSuitableDecoderL(
   236 		const RArray<TUid>& aDecodersArray,
   237 		const TUncompressedVideoFormat& aRequiredOutputFormat,
   238 		TBool aUseSurfaces);
   239 	void ConstructL();
   240 	void SendErrorToClient(TInt aError);
   241 	void CopyFrameL(CFbsBitmap& aBitmap);
   242 	void CheckDevSoundPresentL();
   243 	void CheckDevVideoPresentL()const;
   244 	void CheckAviReaderPresentL()const;
   245 	void CheckForInitComplete();
   246 	void Panic(TInt aPanicCode);
   247 	void StopVideoL();
   248 	void StopAudioL();
   249 	void StopAviReaderL();
   250 	void RecreateDevVideoAfterFatalErrorL();
   251 	TBool LocateDecoderL(TBool aUseSurfaces);
   252 	void UpdateClipRegion();
   253 
   254 	//from MAviReaderObserver
   255 	void AudioBufferFilled();
   256 	void VideoBufferFilled(TVideoInputBuffer* aBuffer);
   257 	
   258 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
   259 	CSrtReader* CreateSubtitleSourceL();
   260 	void StopSubtitles();
   261 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
   262 
   263 
   264 private:
   265 	class CMMFMessageHolder : public CBase
   266 		{
   267 		public:
   268 			static CMMFMessageHolder* NewL(TMMFMessage& aMessage);
   269 			void Complete(TInt aError);
   270 		private:
   271 			CMMFMessageHolder(TMMFMessage& aMessage);
   272 			TMMFMessage iMessage;
   273 		};
   274 	
   275 	class CSourceSinkEventHandler : public MAsyncEventHandler
   276 		{
   277 		public:
   278 			CSourceSinkEventHandler(CAviPlayController& aParent);
   279 			virtual ~CSourceSinkEventHandler();
   280 		public:
   281 			virtual TInt SendEventToClient(const TMMFEvent& aEvent);
   282 		private:
   283 			CAviPlayController& iParent;
   284 		};
   285 	
   286 private:
   287 	CMMFDevVideoPlay *iDevVideoPlay;
   288 	CMMFDevSound* iDevSound;
   289 	TControllerState iState;
   290 	CAviReader* iAviReader;
   291 	CMMFFile* iClip;
   292 	CSourceSinkEventHandler *iEventHandler;
   293 	TMMFPrioritySettings iPrioritySettings;
   294 	THwDeviceId iDecoderDeviceId;
   295 	CMMFMessageHolder* iMessage;
   296     CFbsScreenDevice* iScreenDev;
   297 	CFbsBitGc* iScreenGc;
   298 	CFbsBitmap* iBitmap;
   299 	TRect iScreenRect;
   300 	TRect iClipRect;
   301 	RRegion iDisplayRegion;
   302 	RRegion iDerivedClipRegion;
   303 	TRect iCropRect;
   304 	TVideoRotation iRotation;
   305 	TReal32 iWidthPercentage;
   306 	TReal32 iHeightPercentage;
   307 	TBool iAntiAliasFiltering;
   308 	TBool iDevVideoInitialized;
   309 	TBool iDevSoundInitialized;
   310 	TSize iFrameSize;
   311 	TBool iAudioEnabled;
   312 	TUid iDecoder;
   313 	TBool iVideoDecoderInitialized;
   314 	TInt iScreenNumber;
   315 	TBool iVideoFatalError;
   316 #ifdef SYMBIAN_BUILD_GCE
   317 	MMMFVideoSurfaceSupport* iVideoSurfaceSupport;
   318 #else
   319 	const TAny* const iVideoSurfaceSupport;	
   320 #endif // SYMBIAN_BUILD_GCE
   321 
   322 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
   323 	CMMFDevSubtitle* iDevSubtitle;
   324 	CSrtReader* iSrtReader;
   325 	TBool iDevSubtitleStarted;
   326 	TInt iSubtitleConfigCount;
   327 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
   328  	};
   329 
   330 #endif