mmfenh/advancedaudiocontroller/audiocontrollerpluginsvariant/AdvancedAudioController/Inc/AdvancedAudioDecoder.h
changeset 0 71ca22bcf22a
child 41 a36789189b53
equal deleted inserted replaced
-1:000000000000 0:71ca22bcf22a
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Definition of Advance Audio Decoder base class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CADVANCEDAUDIODECODER_H
       
    20 #define CADVANCEDAUDIODECODER_H
       
    21 
       
    22 // INCLUDES
       
    23 #include "AdvancedAudioHelper.h"        // for MAdvancedAudioDecoderUtilityObserver
       
    24 #include <FrameTable.h>                 // for CFrameTable
       
    25 #include <e32base.h>
       
    26 #include <sounddevice.h>
       
    27 #include <mmfcodecimplementationuids.hrh>
       
    28 #include <mmfcodec.h>
       
    29 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    30 #include <mmf/common/mmfhelper.h>
       
    31 #endif
       
    32 // CONSTANTS
       
    33 const TUid KUidConfig = {KUidMmfCodecAudioSettings};
       
    34 const TInt KErrBufferNotReady = -1000;  // standard error on NextSharedBufferL called and the desire buffer is not EFull
       
    35 
       
    36 // FORWARD DECLARATIONS
       
    37 class CMMFBuffer;
       
    38 class CMMFDataBuffer;
       
    39 class CMMFCodec;
       
    40 
       
    41 // CLASS DECLARATION
       
    42 class TMMFPtr8 : public TPtr8
       
    43 	{
       
    44 public:
       
    45 	TMMFPtr8()
       
    46 		: TPtr8(0,0,0) {};
       
    47 	inline void Set(const TDes8& aDes)
       
    48 		{ TPtr8::Set((TUint8*)(aDes.Ptr()),aDes.Length(),aDes.MaxLength()); };
       
    49 	inline void SetLengthOnly(const TDes8& aDes)
       
    50 		{ TPtr8::Set((TUint8*)(aDes.Ptr()),aDes.Length(),aDes.Length()); };
       
    51 	inline void Set(const TPtrC8& aDes)
       
    52 		{ TPtr8::Set((TUint8*)(aDes.Ptr()),aDes.Length(),aDes.Length()); };
       
    53 	inline void Shift(TInt aOffset)
       
    54 		{ SetLength(Length()-aOffset); iMaxLength-=aOffset; iPtr+=aOffset; };
       
    55 	};
       
    56 
       
    57 
       
    58 
       
    59 /**
       
    60 * Mixin observer class to define an object capable of handling a callback from
       
    61 * CAdvancedAudioDecoder objects
       
    62 *
       
    63 * @lib AdvancedAudioController.lib
       
    64 * @since 3.0
       
    65 */
       
    66 class MAdvancedAudioDecoderObserver
       
    67     {
       
    68     public:
       
    69 
       
    70         /**
       
    71         * Callback function from CAdvancedAudioDecoder when the specified buffer
       
    72         * has been filled.
       
    73         * @param   aFilledBuffer  data buffer filled with converted data
       
    74         * @return  -
       
    75         */
       
    76         virtual void BufferFilled(CMMFBuffer* aFilledBuffer) = 0;
       
    77 
       
    78         /**
       
    79         * Callback function from CAdvancedAudioDecoder when the specified buffer
       
    80         * needs to be refilled. This indicates a shared buffer is to be refilled.
       
    81         * @param   aEmptyBuffer an empty buffer to be refilled
       
    82         * @return  -
       
    83         */
       
    84         virtual void RefillBuffer(CMMFBuffer* aEmptyBuffer) = 0;
       
    85         
       
    86         /**
       
    87         * Callback function from CAdvancedAudioDecoder when the specified buffer
       
    88         * needs to be refilled. This indicates a shared buffer is to be refilled.
       
    89         * @param   aEmptyBuffer an empty buffer to be refilled
       
    90         * @param   aDoSynchronousRead if the operation should be perform Synchronuously
       
    91         * @return  -
       
    92         */
       
    93         //virtual void RefillBuffer(CMMFBuffer* aEmptyBuffer, TBool aDoSynchronousRead) = 0;
       
    94 
       
    95         /**
       
    96         * Callback function from CAdvancedAudioDecoder to handle specified event
       
    97         * @param   aEvent  the event to be handled
       
    98         * @return  void
       
    99         */
       
   100         virtual void SendEvent(const TMMFEvent& aEvent) = 0;
       
   101     };
       
   102     
       
   103 /**
       
   104 *  This is the base class for all audio converter classes.
       
   105 *  It contains common behaviour for all audio decoders. The audio decoder class
       
   106 *  provides the interface to audio decoders.
       
   107 *
       
   108 *  @lib AdvancedAudioController.lib
       
   109 *  @since 3.0
       
   110 */
       
   111 class CAdvancedAudioDecoder : public CActive, public MFrameTableEventObserver
       
   112     {
       
   113 	protected:
       
   114 		enum TCodecCmd
       
   115 			{
       
   116 			ERenderDisable,
       
   117 			ERenderEnable,
       
   118 			EDisable,
       
   119 			EEnable,
       
   120 			EMarkPlayEnd,
       
   121 			EUnMarkPlayEnd
       
   122 			};
       
   123 			
       
   124     public:
       
   125         /**
       
   126         * Destructor.
       
   127         */
       
   128         IMPORT_C virtual ~CAdvancedAudioDecoder();
       
   129 
       
   130     protected:
       
   131 
       
   132         /**
       
   133         * C++ default constructor.
       
   134         */
       
   135     	IMPORT_C CAdvancedAudioDecoder(TInt aPriority);
       
   136 
       
   137     public: // New functions
       
   138 
       
   139         /**
       
   140         * Sets the DevSound instance to be used by the audio decoder.
       
   141         * @since 3.0
       
   142         * @param aDevSound Devsound instance
       
   143         * @return void
       
   144         */
       
   145         IMPORT_C virtual void SetDevSound(CMMFDevSound& aDevSound);
       
   146 
       
   147         /**
       
   148         * Sets the observer object that will handle callbacks
       
   149         * @since 3.0
       
   150         * @param aObserver Observer object that will handle callbacks
       
   151         * @return void
       
   152         */
       
   153 		IMPORT_C virtual void SetObserver(MAdvancedAudioDecoderObserver& aObserver);
       
   154 		
       
   155 		/**
       
   156         * Sets the DecoderUtilityObserver object that will handle callbacks
       
   157         * @since 3.0
       
   158         * @param aDecoderUtilityObserver DecoderUtilityObserver object that will handle callbacks
       
   159         * @return void
       
   160         */
       
   161 		IMPORT_C virtual void SetDecoderUtilityObserver(MAdvancedAudioDecoderUtilityObserver& aDecoderUtilityObserver);
       
   162 		
       
   163         /**
       
   164         * Sets the source buffer for decoding operations.
       
   165         * @since 3.0
       
   166         * @param aBuffers Pointer to shared buffers.
       
   167         * @return void
       
   168         */
       
   169         IMPORT_C virtual void SetSourceBuffers(RPointerArray<CMMFDataBuffer>* aBuffers);
       
   170         
       
   171         /**
       
   172 		* Sets audio decoder settings and attributes.
       
   173 		* @since 3.0
       
   174         * @param   aSampleRate 			a source sampling rate
       
   175         * @param   aNumChannel 			required number of channels (mono/stereo indication)
       
   176         * @param   aSWConvertSampleRate a sampling rate after conversion
       
   177         * @param   aSWConvertChannels   number of channels after conversion
       
   178         * @param   aCodecConfigData  	specific codec configuration data
       
   179         * @param   aIndex               specify the index in iSharedBuffers
       
   180         *
       
   181         * @return  void
       
   182         */
       
   183         IMPORT_C virtual void SetConfigL(TUint aSampleRate, TUint aChannels,
       
   184         						 TUint aSWConvertSampleRate, TUint aSWConvertChannels,
       
   185         						 const RArray<TInt>& aCodecConfigData, TInt aIndex);
       
   186 
       
   187 
       
   188         /**
       
   189         * Provides the audio converter a buffer to fill with decoded data.
       
   190         * @since 3.0
       
   191         * @param   aBuffer a data buffer to be filled with decoded data
       
   192         * @return  -
       
   193         */
       
   194         IMPORT_C virtual void FillBufferL(CMMFBuffer* aBuffer);
       
   195 
       
   196         /**
       
   197 		* Resets audio decoder settings and attributes.
       
   198 		* @since 3.0
       
   199         * @return void
       
   200         */
       
   201 		IMPORT_C virtual void ResetL();
       
   202 
       
   203         /**
       
   204 	    * Check if the audio converter is hardware accelerated.
       
   205 	    * @since 3.0
       
   206 	    * @return ETrue if hardare accelerated, otherwise, EFalse.
       
   207 	    */
       
   208         IMPORT_C virtual TBool IsHwAccelerated();
       
   209 
       
   210         /**
       
   211         * Stops decoding process.
       
   212         * @since 3.0
       
   213         * @param none
       
   214         * @return void
       
   215         */
       
   216         IMPORT_C virtual void Stop();
       
   217         
       
   218         /**
       
   219         * Set source reference offset in frametable
       
   220         * added to support AAC optimization
       
   221         * @since 3.2
       
   222         * @param aOffset    offset of the source position
       
   223         * return TInt       standard system error
       
   224         */
       
   225 		IMPORT_C virtual TInt SetSourceReference(TUint aTimeMs, TUint aPos);
       
   226         
       
   227         /**
       
   228         * Find the closest Frame's position from a given time (millisec) in frametable
       
   229         * added to support AAC optimization
       
   230         * @since 3.2
       
   231         * @param aTimeMs    Time to search from in millisec
       
   232         * @param aPos       Bytes Position found in frametable if return is KErrNone
       
   233         * return TInt       standard system error
       
   234         */
       
   235 		IMPORT_C virtual TInt FindFramePosFromTime(TUint& aTimeMs, TUint& aPos);
       
   236 		
       
   237 		IMPORT_C virtual TInt FindFrameTimeFromPos(TUint& aTimeMs, TUint& aPos);
       
   238 
       
   239 		/**
       
   240         * Find the last record Frame's position in frametable
       
   241         * added to support AAC optimization
       
   242         * @since 3.2
       
   243         * @param aPos       Bytes Position found in frametable if return is KErrNone
       
   244         * return TInt       standard system error
       
   245         */
       
   246 		IMPORT_C virtual TInt LastFramePos(TUint& aPos);
       
   247 		
       
   248 		/*
       
   249         * Find the last Frame's position relative time (millisec) in frametable
       
   250         * added to support AAC optimization
       
   251         * @since 3.2
       
   252         * @param aTimeMs    Time of the last Frame in millisec if return is KErrNone
       
   253         * return TInt       standard system error
       
   254         */
       
   255 		IMPORT_C virtual TInt LastFrameTime(TUint& aTimeMs);
       
   256 		
       
   257 		/*
       
   258         * Reset the frame table
       
   259         * added to support AAC optimization
       
   260         * @since 3.2
       
   261         * return TInt       standard system error
       
   262         */
       
   263 		IMPORT_C virtual TInt ResetTable();
       
   264 		
       
   265 		/**
       
   266         * Cause FrameTable to generate an event when the desire Position is recorded in FrameTable
       
   267         * added to support AAC optimization
       
   268         * @since 3.2
       
   269         * @param aTimeMs    Time to be Seek to when callback occurs in millisec
       
   270         * return TInt       standard system error
       
   271         */
       
   272 		IMPORT_C virtual TInt SeekToTimeMs(TUint aTimeMs);
       
   273 		IMPORT_C virtual TInt SetPlayWindowEndTimeMs(TUint aTimeMs);
       
   274 		/**
       
   275         * Get the average bitrate inside the FrameTable
       
   276         * added to support AAC optimization
       
   277         * @since 3.2
       
   278         * return TInt       averate bitrate at the moment
       
   279         */
       
   280 		IMPORT_C virtual TInt BitRate();
       
   281 		
       
   282         /**
       
   283         * Cause FrameTable to generate an event when desire interval of data has been decoded
       
   284         * added to support AAC optimization
       
   285         * @since 3.2
       
   286         * @param aEnable    Enable/Disable the event
       
   287         * @param aTimeMs    Time of the desire interval in millisec
       
   288         * return TInt       standard system error
       
   289         */
       
   290         IMPORT_C virtual TInt EnableDecodeIntervalEvent(TBool aEnable, TUint aTimeMs = 0);
       
   291         
       
   292         IMPORT_C virtual void RenderDisable();
       
   293     
       
   294         IMPORT_C virtual void RenderEnable();
       
   295 
       
   296         IMPORT_C virtual void QueueThisBuffer(TUint aBufferIndex);
       
   297 
       
   298     public: // from MFrameTableEventObserver
       
   299         /**
       
   300         * Callback from FrameTable when event occur
       
   301         * added to support AAC optimization
       
   302         * @since 3.2
       
   303         * @param CFrameTable::TFrameTableEvent
       
   304         *                   event from FrameTable
       
   305         * return TInt       standard system error
       
   306         */
       
   307         IMPORT_C virtual TInt HandleFrameTableEvent(CFrameTable::TFrameTableEvent aEvent);
       
   308 //		IMPORT_C virtual TInt IsSeeking(TBool& aIsSeeking);
       
   309 
       
   310     protected: // New functions
       
   311 
       
   312       	/**
       
   313         * Handle filling the requested buffer received in FillBufferL()
       
   314         * @param   none
       
   315         * @return  void
       
   316         */
       
   317 		IMPORT_C virtual void HandleFillBufferL();
       
   318 		IMPORT_C virtual TCodecProcessResult ProcessL(CMMFBuffer& aSrc, CMMFBuffer& aDst);
       
   319 		IMPORT_C virtual TInt CodecCmd(TCodecCmd aCmd);
       
   320 		IMPORT_C virtual TInt CodecConfig(RArray<TInt>& aCodecConfigData);
       
   321 //		IMPORT_C void RenderDisable();
       
   322 //		IMPORT_C void RenderEnable();
       
   323 		IMPORT_C void MarkPlayEnd();
       
   324 		IMPORT_C void UnMarkPlayEnd();
       
   325 		IMPORT_C void Disable();
       
   326 		IMPORT_C void Enable();
       
   327 
       
   328 		IMPORT_C virtual TCodecProcessResult ProcessHwL(CMMFBuffer& aSrc, CMMFBuffer& aDst);
       
   329 		IMPORT_C virtual void ProcessParseL(TMMFPtr8* aSrc, TMMFPtr8* aDst);
       
   330 		IMPORT_C virtual TUint8* PrepareInFrame(TUint8* aSrc, TInt aSrcLen, TInt& aSrcUsed);
       
   331 		IMPORT_C virtual void ParseL(TUint8* aSrc, TInt& aSrcUsed, TUint8* aDst, TInt& aDstLen);
       
   332 		virtual TInt SeekSync(TUint8* aBuf, TInt aBufLen);
       
   333 		virtual TInt FrameLength(const TUint8* aBuf, TInt aBufLen, TInt& aFrameLength);
       
   334 
       
   335 	private:	
       
   336         /**
       
   337         * Completes own request.
       
   338         */
       
   339         void Ready(TInt aRequest);
       
   340         void NextSharedBufferL();
       
   341 
       
   342     protected:	// Functions from base classes
       
   343     
       
   344         /**
       
   345         * From CActive
       
   346         */
       
   347         IMPORT_C virtual void RunL();
       
   348 
       
   349         /**
       
   350         * From CActive
       
   351         */
       
   352         IMPORT_C virtual void DoCancel();
       
   353 
       
   354     protected: // Data
       
   355 
       
   356 		enum TAudioDecoderState
       
   357 			{
       
   358 			EIdle,
       
   359 			EDecoding
       
   360 			};
       
   361 
       
   362         enum TNextEvent
       
   363             {
       
   364             EDoNothing,
       
   365             ERefillBuffer,
       
   366             EPlayEnd
       
   367             };
       
   368 
       
   369 		// Decoder state
       
   370 		TAudioDecoderState iState;
       
   371 
       
   372 		// array of shared buffers
       
   373 		RPointerArray<CMMFDataBuffer>* iSharedBuffers;
       
   374        	// next available buffer index
       
   375 	    TInt iSharedBufferIndex;
       
   376 
       
   377 		// audio buffer to fill pointer
       
   378 		CMMFBuffer* iBufferToFill;
       
   379         // audio buffer to empty pointer
       
   380         CMMFBuffer* iBufferToEmpty;
       
   381         // next available buffer pointer
       
   382         CMMFBuffer* iNextBuffer;
       
   383 
       
   384         // DevSound pointer
       
   385         CMMFDevSound* iMMFDevSound;
       
   386 
       
   387         // Audio Converter observer
       
   388         MAdvancedAudioDecoderObserver* iObserver;
       
   389         MAdvancedAudioDecoderUtilityObserver* iDecoderUtilityObserver;  // the Utility object as Observer to Decoder event
       
   390 
       
   391         CFrameTable* iFrameTable;   // FrameTable that record decoded frame position, added for AAC optimization
       
   392         
       
   393         TBool iRenderEnabled; // indicate whether audio buffer should be given to DevSound, added for AAC optimization
       
   394         TBool iEnabled;       // indicates if decoding in codec is enabled
       
   395         TBool iMarkPlayEnd;
       
   396         TUint iSeekToTimeMs;
       
   397 
       
   398         // soft codec pointer if soft codec is used
       
   399 		CMMFCodec* iSoftCodec;
       
   400 
       
   401         // True if sampling rate conversion is required
       
   402         TBool iNeedsSWConversion;
       
   403         // Sample rate to convert to
       
   404         TUint iSWConvertSampleRate;
       
   405         // Number of channels to convert to
       
   406         TUint iSWConvertChannels;
       
   407 
       
   408         // sample rate converter factory pointer
       
   409         CMMFChannelAndSampleRateConverterFactory* iChannelAndSampleRateConverterFactory;
       
   410         // sample rate converter pointer
       
   411         CMMFChannelAndSampleRateConverter* iChannelAndSampleRateConverter;
       
   412 
       
   413         // converter buffer pointer
       
   414         CMMFDataBuffer* iConvertBuffer;
       
   415         TUint iEventPos;
       
   416         
       
   417         
       
   418        	RArray<TInt> iRenderEnableConfig;
       
   419        	RArray<TInt> iRenderDisableConfig;
       
   420        	RArray<TInt> iMarkPlayEndConfig;
       
   421        	RArray<TInt> iUnMarkPlayEndConfig;
       
   422        	RArray<TInt> iEnableConfig;
       
   423        	RArray<TInt> iDisableConfig;
       
   424 
       
   425 		// below are for the hw decoding and could be moved to another header file
       
   426         	// local input buffer
       
   427         TUint8* iInBuffer;
       
   428         TInt iInBufferCount;
       
   429         TInt iInBufferIndx;
       
   430 		TInt iSavedBytesCopiedFromSrc;
       
   431 		TBool iInBufferFilled;
       
   432 		TUint iAccLen;
       
   433 		TInt iUsedInBuffer;
       
   434         
       
   435         // local output buffer
       
   436         TUint8* iOutBuffer;
       
   437         TInt iOutBufferCount;
       
   438         TInt iOutBufferLength;
       
   439         
       
   440         TUint8* iOutBufferPtr;
       
   441         TInt iOutFrameLength;
       
   442 
       
   443 		const CMMFDataBuffer*	iSrc;
       
   444 		CMMFDataBuffer*			iDst;
       
   445 
       
   446         TInt iMaxFrameSize;
       
   447         TInt iSizeOfInBuffer;
       
   448 
       
   449 	};
       
   450 	
       
   451 #endif 		// CADVANCEDAUDIODECODER_H