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