mmplugins/imagingplugins/imagedisplay/plugins/mng/MngPlayer.h
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2004-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 __MNGPLAYER_H__
       
    17 
       
    18 #define __MNGPLAYER_H__
       
    19 /** 	@file
       
    20 	@internalTechnology */
       
    21 
       
    22 #include "MngObjects.h"
       
    23 #include "Providers.h"
       
    24 
       
    25 
       
    26 class CMngPlayer;
       
    27 class CMngProcessor;
       
    28 class CPngProcessor;
       
    29 class CMngFileReadStream;
       
    30 class CMngRenderer;
       
    31 class TMhdrChunk;
       
    32 class CMngTermination;
       
    33 class MMngPlayerObserver;
       
    34 class MPixelFilter;
       
    35 class MImageStreamDecoderFactory;
       
    36 class MUniqueChunkDataProvider;
       
    37 
       
    38 class RMngObjectList: public RPointerArray<CMngObject> 
       
    39 	{
       
    40 public:
       
    41 		typedef TInt TObjectIterator;
       
    42 
       
    43 		void Destroy();
       
    44 		void AppendL(CMngObject*& aObject);
       
    45 
       
    46 		TObjectIterator Find(TMngObjLabel aLabel);
       
    47 		TObjectIterator Begin() const;
       
    48 		TObjectIterator End() const;
       
    49 private:
       
    50 		
       
    51 	};
       
    52 
       
    53 class CDelayTimer: public CTimer 
       
    54 	{
       
    55 public:
       
    56 	static CDelayTimer* NewL(CMngPlayer& aPlayer);
       
    57 	void RunNow();
       
    58 protected:
       
    59 	inline CDelayTimer(CMngPlayer& aPlayer);
       
    60 	void RunL();
       
    61 	CMngPlayer& iPlayer;
       
    62 	};
       
    63 
       
    64 class TLoopStackItem 
       
    65 	{
       
    66 public:
       
    67 	TInt			iNestLevel;
       
    68 	TMngObjLabel	iLoopObjectLabel;
       
    69 	TBool			iMoreIterationsNeeded;
       
    70 	};
       
    71 
       
    72 class RLoopStack: protected RArray<TLoopStackItem> 
       
    73 	{
       
    74 	friend class CMngPlayer;
       
    75 public:
       
    76 	inline void PushL(const TLoopStackItem& aItem);
       
    77 	inline TInt Pop(TLoopStackItem& aItem);
       
    78 	inline TBool IsEmpty() const;
       
    79 	};
       
    80 
       
    81 class TProviderEntry 
       
    82 	{
       
    83 public:
       
    84 	inline TProviderEntry();
       
    85 	inline TProviderEntry(const TChunkId& aId, MUniqueChunkDataProvider& aProvider);
       
    86 											
       
    87 	TChunkId					iId;
       
    88 	MUniqueChunkDataProvider*   iProvider;	
       
    89 	};
       
    90 
       
    91 class RChunkProviders: protected RArray<TProviderEntry> 
       
    92 	{
       
    93 	friend class CMngPlayer;
       
    94 	static TInt OrderFunc(const TProviderEntry& aLeft, const TProviderEntry& aRight);
       
    95 	typedef TLinearOrder<TProviderEntry> TMyOrder;
       
    96 public:
       
    97 	TInt Add(const TProviderEntry& aItem);
       
    98 	void RemoveProvider(const TChunkId& aId);
       
    99 	MUniqueChunkDataProvider* Find(const TChunkId& aId);
       
   100 	void Clear();
       
   101 	};
       
   102 
       
   103 class CMngPlayer: protected CActive, public MUniqueChunkDataProvider  
       
   104 	{
       
   105 public:
       
   106 
       
   107 	typedef TUint TObserverNotifyEvent;
       
   108 
       
   109 public:
       
   110 		
       
   111 	static CMngPlayer*	NewL(CMngFileReadStream* aReadStream, MMngPlayerObserver& aObserver, TBool aMngSubframesNoLoops);   //Subframes with No Loops;
       
   112 	~CMngPlayer();
       
   113 
       
   114 // external interface to the MngImageDisplayPlugin //
       
   115 	void StopDecode();
       
   116 	void Pause();
       
   117 	void Decode();
       
   118 	inline void SetInternalDelayOn(TBool aIsOn);
       
   119 	/*
       
   120 	Assumes passing of the ownership
       
   121 	*/
       
   122 	void SetMngHeader(TMhdrChunk*& aHeaderChunk); 
       
   123 	inline TSize FrameSize() const;
       
   124 	inline TInt NumFrames() const;
       
   125 
       
   126 	inline TBool IsAlphaNeeded() const;
       
   127 	
       
   128 	inline void SetRequiredDisplayModes(TDisplayMode aDestDisplayMode, TDisplayMode aMaskDisplayMode);
       
   129 	/**
       
   130 		returns this frame delay, the value is valid only during observer callback
       
   131 	*/
       
   132 	inline TTimeIntervalMicroSeconds32 ThisFrameDelay() const;
       
   133 // internal interface to MNG objects	//
       
   134 	void InitL(TMhdrChunk*& aHeaderChunk);
       
   135 	
       
   136 	void AppendObjectL(CMngObject*& aObject);
       
   137 
       
   138 	inline CMngRenderer* Renderer() const;
       
   139 
       
   140 	void SetTerminationCtrlL(CMngTermination* aTermination);
       
   141 	inline void SetTerminationFrameNum(TInt aFrameNumber);
       
   142 	void SetPixelFilter(MPixelFilter* aPixelFilter);
       
   143 
       
   144 	inline void SetFramingMode(TMngFramingMode	aFramingMode);
       
   145 	void SetInterFrameDelay(TMngFramChangeNextFrameOption aOption, TInt aTicks);
       
   146 	void SetLayerClipping(TMngFramChangeNextFrameOption aOption, const TRect& aClipRect, TBool aIsAdditive);
       
   147 	
       
   148 	void AddUniqueChunkProviderL(const TChunkId& aChunkId,  MUniqueChunkDataProvider& aProvider);
       
   149 
       
   150 	inline RLoopStack& LoopStack();
       
   151 
       
   152 	MImageStreamDecoderFactory& DecoderFactory();
       
   153 
       
   154 // execution timer interface//
       
   155 	void NotifyObserverGate();	
       
   156 
       
   157 	//to set destination bitmap
       
   158 	inline void SetDestinationBitmap(CFbsBitmap* aDestination);
       
   159 	//to get destination bitmap
       
   160 	inline CFbsBitmap* GetDestinationBitmap();
       
   161 protected:
       
   162 	CMngPlayer(MMngPlayerObserver& aObserver, TBool aMngSubframesNoLoops);   //Subframes with No Loops;
       
   163 
       
   164 	void ConstructL(CMngFileReadStream* aReadStream);
       
   165 
       
   166 // from the MUniqueChunkDataProvider //
       
   167 	TInt GetChunkData(const TText8* aChunkId, const TUint8*& aPalettePtr, TInt& aSizeInBites);
       
   168 // 
       
   169 
       
   170 	void OnIteration();
       
   171 	TBool DoIterationL();
       
   172 
       
   173 	void OnEndOfSubFrame();
       
   174 	void OnEndOfFrame(TBool aAlwaysNotify=EFalse, TBool aIsLastFrame=EFalse);
       
   175 	void OnNewLayer();
       
   176 
       
   177 	void DoCancel();
       
   178 	void RunL();
       
   179 	TInt RunError(TInt aError);
       
   180 	void RunAgain();
       
   181 
       
   182 	void StartPlay();
       
   183 
       
   184 	void NotifyObserver(TObserverNotifyEvent aEvent, TInt aArgument, TTimeIntervalMicroSeconds32 aNotifyDelay);
       
   185 	
       
   186 // Utility functions //
       
   187 	inline TTimeIntervalMicroSeconds32 Ticks2TimeInterval(TInt aTicks) const;
       
   188 
       
   189 protected:
       
   190 	TBool 				iMngSubframesNoLoops;   //Subframes with No Loops
       
   191 	MMngPlayerObserver& iObserver;
       
   192 	RMngObjectList		iObjectList;
       
   193 	RLoopStack			iLoopStack;
       
   194 	RChunkProviders		iChunkProviders;
       
   195 	CMngFileReadStream*	iMngStream;
       
   196 	CMngProcessor*		iMngProcessor;
       
   197 	CMngRenderer*		iMngRenderer;
       
   198 	CPngProcessor*		iPngProcessor;
       
   199 	CMngTermination*	iTerminationCtrl;
       
   200 	TMhdrChunk*			iMngHeader;
       
   201 	TInt				iTickLength;
       
   202 	CDelayTimer*		iExecTimer;
       
   203 	TObserverNotifyEvent iNotifyEvent;
       
   204 	TInt				iObserverNotifyArg;
       
   205 	TTimeIntervalMicroSeconds32 iNominalDelayBeforeThisFrame;
       
   206 	TBool				iPerformFrameDelayInternally;
       
   207 	TBool				iIsPaused;
       
   208 	TBool				iOutstandingNotify;
       
   209 	TBool				iGotHeaderFromStream;
       
   210 	TDisplayMode		iDestDisplayMode;
       
   211 	TDisplayMode		iMaskDisplayMode;
       
   212 // Mng operational parameters //
       
   213 	TInt							iPlayerErrorCode;
       
   214 	enum TPlayerState 
       
   215 		{
       
   216 		EStJustBorn=0, 
       
   217 		EStReadingFormat, 
       
   218 		EStReadyToPlay, 
       
   219 		EStPlaying,
       
   220 		EStStopped,
       
   221 		EStNeedsRepeat,
       
   222 		}							iState;
       
   223 	TInt							iInterframeDelay;			// current effective interframe delay
       
   224 	TInt							i1stFrameInterframeDelay;	// interframe delay fro the 1st frame of repeat
       
   225 	TMngFramingMode					iFramingMode;
       
   226 	TMngFramChangeNextFrameOption	iChangeInterFrmDelay;
       
   227 	TInt							iNextInterFrameDelay;	
       
   228 	TInt							iDefaultInterFrmDelay;		// default interframe delay
       
   229 	TMngFramChangeNextFrameOption	iChangeClippingBoundaries;
       
   230 	TRect							iCurrentClippingBnd;
       
   231 	TRect							iDefaultClippingBnd;
       
   232 	TMngFramChangeNextFrameOption	iChangeSyncIdList;
       
   233 	RMngObjectList::TObjectIterator iCurrentObject;
       
   234 	MImageStreamDecoderFactory*		iDecoderFactory;
       
   235 	TInt							iFrameNumberToTerminate;
       
   236 	TBool							iFrameBeingRendered;
       
   237 // play statistics //
       
   238 	TInt							iDrawnLayerNum;			// Layer number within the whole sequence
       
   239 	TInt							iDrawnFrameNum;			// Frame number within the whole sequence
       
   240 	TInt							iSubframeLayerNum;		// Layer number within the current subrame
       
   241 	TTime							iEndOfPreviuosFrame;	// Time point when the previous frame has been completed
       
   242 	TBool							iEndOfFrameNotification;
       
   243 #ifdef _DEBUG
       
   244 	TTime							iNotifyStart;
       
   245 	TTime							iLastNotify;
       
   246 #endif
       
   247 private:
       
   248 	TBool							iNeedsChange;
       
   249 	CFbsBitmap*	iCurrentFrame; //not owned
       
   250 	};
       
   251 
       
   252 #include "MngPlayer.inl"
       
   253 
       
   254 #endif // ndef __MNGPLAYER_H__