os/mm/mmdevicefw/mdfunittest/codecapi/omx/pcmcodec/src/OmxPCMCodec.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) 2005-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 OMXPCMCODEC_H
    17 #define OMXPCMCODEC_H
    18 
    19 #include <e32msgqueue.h>
    20 #include <mdaaudiooutputstream.h>
    21 #include <openmax/il/khronos/v1_x/OMX_Audio.h>
    22 #include "OmxImpl.h"
    23 
    24 #include "MMFAudioU8ToS16PcmCodec.h"
    25 #include "MMFAudioPcm8ToPcm16Codec.h"
    26 #include "MMFAudioPcmS16ToPcmS8Codec.h"
    27 #include "MMFAudioS16ToU8PcmCodec.h"
    28 
    29 class COmxPCMCodec;
    30 
    31 
    32 class CCodecProcessor : public CBase
    33 		{
    34 
    35 	enum TCodecMessageType
    36 		{
    37 		EStopProcessing,
    38 		EPauseProcessing,
    39 		EInputBuffer,
    40 		EOutputBuffer,
    41 		EExit				
    42 		};
    43 
    44 	class TCodecMessage 
    45 		{
    46 	public:
    47 		TCodecMessageType iType;
    48 		OMX_BUFFERHEADERTYPE* iBuffer;
    49 		};
    50 	
    51 	public:		
    52 		static CCodecProcessor* NewL(COmxPCMCodec& aParent);		
    53 
    54 		void RunThreadL();
    55 		void Stop();
    56 		void Exit();
    57 	    
    58         OMX_ERRORTYPE EmptyThisBuffer(
    59             OMX_BUFFERHEADERTYPE* pBuffer);
    60 	    OMX_ERRORTYPE FillThisBuffer(
    61             OMX_BUFFERHEADERTYPE* pBuffer);
    62             
    63 		void SetInputDataType(OMX_NUMERICALDATATYPE aType);
    64 		void SetInputBitsPerSample(TInt aBitsPerSample);
    65 		void SetOutputDataType(OMX_NUMERICALDATATYPE aType);
    66 		void SetOutputBitsPerSample(TInt aBitsPerSample);
    67 
    68 		virtual ~CCodecProcessor();		
    69 	    
    70 	private:
    71 		void ConstructL();
    72 		CCodecProcessor(COmxPCMCodec& aParent);
    73 
    74 		void ProcessAvailableBuffers();
    75 		void ChooseCodec();
    76 	
    77 	private:
    78 		COmxPCMCodec* iParent;
    79 		RPointerArray<OMX_BUFFERHEADERTYPE> iBuffersToEmpty;
    80 		RPointerArray<OMX_BUFFERHEADERTYPE> iBuffersToFill;	
    81 		
    82 		TRequestStatus iQueueStatus;
    83 		RMsgQueue<TCodecMessage> iMessageQueue;
    84 		
    85 		OMX_BUFFERHEADERTYPE* iInputBuffer;
    86 		OMX_BUFFERHEADERTYPE* iOutputBuffer;
    87 		
    88 		TMMFAudioCodecBase* iCodec;
    89 
    90 		// codec configuration settings
    91 		TInt iInputBitsPerSample; 
    92 		TInt iOutputBitsPerSample; 
    93 		OMX_NUMERICALDATATYPE iInputDataType;
    94 		OMX_NUMERICALDATATYPE iOutputDataType;
    95 		
    96 		TInt iInputBufferPos;
    97 		
    98 		TMMFAudioCodecBase* iCurrentCodec;
    99 			
   100 		TMMFAudioU8ToS16PcmCodec iAudioU8ToS16PcmCodec;
   101 		TMMFAudioPcm8ToPcm16Codec iAudioS8ToS16PcmCodec;
   102 		
   103 		TMMFAudioPcmS16ToPcmS8Codec iAudioS16ToS8PcmCodec;
   104 		TMMFAudioS16ToU8PcmCodec iAudioS16ToU8PcmCodec;
   105 
   106 		TBool iStarted;
   107 		TReal iOutputSamplesPerInputSample;
   108 		};
   109 
   110 
   111 
   112 class COmxPCMCodec : public COmxComponentImpl
   113 	{
   114 public:
   115 	friend class CCodecProcessor;
   116 	friend class CCodecCallbacks;
   117 
   118 	static TInt CreateComponent(OMX_HANDLETYPE hComponent);
   119 	~COmxPCMCodec();
   120 	
   121 	OMX_ERRORTYPE GetComponentVersion(
   122 			OMX_STRING pComponentName,
   123 			OMX_VERSIONTYPE* pComponentVersion,
   124 			OMX_VERSIONTYPE* pSpecVersion,
   125 			OMX_UUIDTYPE* pComponentUUID);
   126     OMX_ERRORTYPE SendCommand(
   127 			OMX_COMMANDTYPE Cmd,
   128 			TUint32 nParam1,
   129 			TAny* pCmdData);
   130     OMX_ERRORTYPE GetParameter(
   131 			OMX_INDEXTYPE nParamIndex,  
   132 			TAny* ComponentParameterStructure);
   133     OMX_ERRORTYPE SetParameter(
   134 			OMX_INDEXTYPE nIndex,
   135 			TAny* ComponentParameterStructure);
   136     OMX_ERRORTYPE GetConfig(
   137 			OMX_INDEXTYPE nIndex, 
   138 			TAny* value);
   139     OMX_ERRORTYPE SetConfig(
   140 			OMX_INDEXTYPE nIndex, 
   141 			TAny* value);
   142     OMX_ERRORTYPE GetExtensionIndex(
   143 			OMX_STRING ParameterName,
   144 			OMX_INDEXTYPE* pIndexType);
   145     OMX_ERRORTYPE GetState(
   146 			OMX_STATETYPE* pState);
   147     OMX_ERRORTYPE ComponentTunnelRequest(
   148 			OMX_HANDLETYPE hInput,
   149 			TUint32 nInputPort,
   150 			OMX_HANDLETYPE hOutput,
   151 			TUint32 nOutputPort,
   152 			OMX_TUNNELSETUPTYPE* pTunnelSetup);
   153     virtual OMX_ERRORTYPE UseBuffer(
   154 			OMX_BUFFERHEADERTYPE** pBufferHdr,
   155 			TUint32 nPortIndex,
   156 			TAny* pAppPrivate,
   157 			TUint32 nSizeBytes,
   158 			TUint8* pBuffer);
   159     virtual OMX_ERRORTYPE AllocateBuffer(
   160            OMX_BUFFERHEADERTYPE** pBuffer,
   161            TUint32 nPortIndex,
   162            TAny* pAppData,
   163            TUint32 nSizeBytes);
   164     OMX_ERRORTYPE FreeBuffer(
   165     		  TUint32 nPortIndex,	
   166               OMX_BUFFERHEADERTYPE* pBuffer);
   167     OMX_ERRORTYPE EmptyThisBuffer(
   168               OMX_BUFFERHEADERTYPE* pBuffer);
   169     OMX_ERRORTYPE FillThisBuffer(
   170               OMX_BUFFERHEADERTYPE* pBuffer);
   171     OMX_ERRORTYPE SetCallbacks(
   172               OMX_CALLBACKTYPE* pCallbacks, 
   173               TAny* pAppData);
   174               
   175 	TInt StartExecution();
   176             
   177 	void EventHandlerCallback(
   178         			 OMX_EVENTTYPE eEvent, 
   179         			 TUint32 nData1,
   180         			 TUint32 nData2,
   181         			 OMX_STRING cExtraInfo);
   182 	void FillBufferDoneCallback(OMX_BUFFERHEADERTYPE* pBuffer);
   183 	void EmptyBufferDoneCallback(OMX_BUFFERHEADERTYPE* pBuffer);
   184             
   185 
   186 private:
   187 	COmxPCMCodec(OMX_HANDLETYPE hComponent);
   188 	void ConstructL();
   189 
   190 private:
   191 	OMX_CALLBACKTYPE* iCallback;
   192 	TAny* iAppData;
   193 	OMX_STATETYPE iState;
   194 	
   195 	TRequestStatus iThreadDeath;
   196 	CCodecProcessor* iCodecProcessor;
   197 	TBool iCreatedThread;
   198 	RThread iProcessingThread;
   199 	};
   200 	
   201 #endif // OMXPCMCODEC_H