os/mm/mmhais/refacladapt/src/audiocodec/audiocodec.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200 (2014-06-10)
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2007-2008 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:
    15 *
    16 */
    17 
    18 
    19 #ifndef AUDIOCODEC_H
    20 #define AUDIOCODEC_H
    21 
    22 #include <e32base.h>
    23 #include <mmf/server/mmfhwdevice.h>
    24 #include <mmf/server/mmfhwdevicesetup.h>
    25 #include <mmf/server/sounddevice.h>
    26 #include <a3f/a3f_trace_utils.h>
    27 #include <a3f/a3fbase.h>
    28 
    29 #include "hwdeviceimplementationuids.hrh"
    30 
    31 #include <mmf/plugin/mmfhwdeviceimplementationuids.hrh>
    32 
    33 #include "moutputport.h"
    34 #include "minputport.h"
    35 #include "mgainhelper.h"
    36 #include "mstreampositioncontrol.h"
    37 
    38 #include <a3f/msynccisupport.h>
    39 #include <a3f/maudiocodec.h>
    40 
    41 #define KFOURCCLENGTH 4
    42 
    43 
    44 enum TMode
    45 	{
    46 	// Decoder mode
    47 	EDecode = 0x01,
    48 	// And vice versa
    49 	EEncode = 0x02
    50 	};
    51 
    52 class TSampleRateTableEntry
    53 	{
    54 public:
    55 	TInt		iSampleRateValue;
    56 	TMMFSampleRate iSampleRate;
    57 	};
    58 
    59 class TAudioModeTableEntry
    60 	{
    61 public:
    62 	TMMFMonoStereo	iAudioModeValue;
    63 	TUid 			iAudioMode;
    64 	};
    65 
    66 const TInt KMaxModeIndex = 1;
    67 
    68 
    69 
    70 class MAudioCodecAdaptationObserver;
    71 class CFourCCConvertor;
    72 
    73 	/////
    74 	//This is the reference implementation of Phyisical AudioCodec
    75 	//@lib audiocodec.lib
    76 	///
    77 
    78 // TODO: Check if those interfaces MInputPort, MOutputPort should be replaced by MMMFAudioDataSupplier, MMMFAudioDataConsumer
    79 
    80 
    81 NONSHARABLE_CLASS(CAudioCodec) :public CActive,
    82 								public MMMFHwDeviceObserver,
    83 								public MInputPort,				// Adaptation interface
    84 								public MOutputPort,				// Adaptation interface
    85 								public MGainHelper,				// Adaptation interface
    86 								public MCustomInterfaceSupport,	// A3F interface
    87 								public MStreamPositionControl	// Adaptation interface
    88 	{
    89 friend class CAudioGainControl;
    90 public:
    91 
    92 	/////
    93 	// Create a new instance.
    94 	//
    95 	// @param aTypeId.
    96 	// @return CAudioCodec* a pointer to the created instance.
    97 	///
    98 
    99 	IMPORT_C static CAudioCodec* NewL(TUid aTypeId, const CFourCCConvertor& aFourCCConvertor);
   100 
   101 	// Check if this would be removed
   102 	/////
   103 	//  Structure to hold hw device init parameters
   104 	///
   105 	class THwDeviceInitArgs
   106 		{
   107 	public:
   108 		TUint8 iPolicyId;
   109 		TInt iEapStreamId;
   110 		};
   111 
   112 	/////
   113 	 // Destructor.
   114 	 //
   115 	 // Deletes all objects and releases all resource owned by this instance.
   116 	///
   117 	virtual ~CAudioCodec();
   118 
   119 
   120 	IMPORT_C TInt SetFormat(TUid aFormat);
   121 	IMPORT_C TInt RegisterAudioCodecObserver(MAudioCodecAdaptationObserver& aObserver);
   122 	IMPORT_C void UnregisterAudioCodecObserver(MAudioCodecAdaptationObserver& aObserver);
   123 	IMPORT_C TInt Initialize();
   124 	IMPORT_C TInt Load(TInt aSampleRate, TUid aMode);
   125 	IMPORT_C TInt Start();
   126 	IMPORT_C TInt Pause();
   127 	IMPORT_C TInt Stop();
   128 
   129 
   130 
   131 	// From MOutputPort
   132 	TInt GetOutputPort(MOutputPort*& aOutputPort);
   133 
   134 	// From MInputPort
   135 	TInt GetInputPort(MInputPort*& aInputPort);
   136 
   137 	// From MCustomInterfaceSupport
   138 	virtual TInt RequestCustomInterface(TUid aUid, TAny*& aPtr);
   139 	virtual TInt RegisterObserver(MCustomInterfaceSupportObserver& aObserver);
   140 	virtual void UnRegisterObserver(MCustomInterfaceSupportObserver& aObserver);
   141 
   142 	// from base class MInputPort
   143 	virtual TInt EmptyBuffer(CMMFBuffer* aBuffer, MOutputPort* aSupplier);
   144 	virtual TInt BufferFilled(CMMFBuffer* aBuffer);
   145 	virtual TInt SetOutput(MOutputPort* aOutput);
   146 	virtual TInt RemoveOutput(MOutputPort* aOutput);
   147 
   148 	// from base class MOutputPort
   149 	virtual TInt FillBuffer(CMMFBuffer* aBuffer, MInputPort* aConsumer);
   150 	virtual TInt BufferEmptied(CMMFBuffer* aBuffer);
   151 	virtual TInt SetInput(MInputPort* aInput);
   152 	virtual TInt RemoveInput(MInputPort* aInput);
   153 	virtual TInt FlushBuffer(MFlushHandlerObserver* aFlushObserver);
   154 
   155 	// from base class MMMFHwDeviceObserver
   156 	virtual TInt FillThisHwBuffer(CMMFBuffer& aHwBuffer);
   157 	virtual TInt EmptyThisHwBuffer(CMMFBuffer& aHwBuffer);
   158 	virtual TInt MsgFromHwDevice(TUid aMessageType, const TDesC8& aMsg);
   159 	virtual void Stopped();
   160 	virtual void Error(TInt aError);
   161 
   162 	// from base class MGainHelper
   163 	TInt GetGain(TInt& aGain) const;
   164 	TInt SetGain(RArray<TAudioChannelGain>& aChannels);
   165 	TInt ConfigureRamp(TUid aRampOperation, const TTimeIntervalMicroSeconds& aRampDuration);
   166 
   167 	// from base class MStreamPositionControl
   168 	TInt GetControlPosition(TTimeIntervalMicroSeconds& aPosition);
   169 	void ResetControlPosition();
   170 
   171 
   172 	TInt ResolveMode(TUid aMode);
   173 	TInt GetSupportedSampleRates(RArray<TInt>& aSupportedRates);
   174 	TInt GetSupportedModes(RArray<TUid>& aSupportedModes);
   175 
   176 	//Return the supported values to the client
   177 	IMPORT_C TInt SupportedModes(RArray<TUid>& aSupportedModes);
   178 	IMPORT_C TInt SupportedRates(RArray<TInt>& aSupportedRates);
   179 	
   180 protected:
   181 	// from CActive
   182 	void RunL();
   183 	void DoCancel();
   184 	TInt RunError(TInt aError);
   185 
   186 	TInt LoadHwDevice();
   187 	TInt InitHwDevice();
   188 	TInt SetHwDeviceConfig();
   189 	void FourCCToHwDeviceUidL(TFourCC aFourCC, TMode aMode, TUid &aHWDev);
   190 
   191 	TBool IsDataTypeMatch(CImplementationInformation* aHwDeviceResourceEntry,
   192 		const TDesC8& aHwMatchFourCC, TMode aState);
   193 
   194 	// TODO: This will be replaced, when the new mechanism to get the supported configuration
   195 	// will be defined
   196 	/////
   197 	 // Reads hw device parameters from resource files.
   198 	 // @return error code.
   199 	 ///
   200 	TInt ReadResourceRates(RArray<TInt>& aRates);
   201 	TInt ReadResourceModes(RArray<TUid>& aModes);
   202 
   203 	void UpdateBytesPlayed();
   204 
   205 private:
   206 	void ConstructL();
   207 
   208 	CAudioCodec(TUid aTypeId, const CFourCCConvertor& aFourCCConvertor);
   209 
   210 private:
   211 	TUid						iType;
   212 	// Indicates if this is an encoder or decoder
   213 	TMode						iMode;
   214 
   215 	// The codec format
   216 	TUid						iFormat;
   217 
   218 	// Resolved HwDevice Uid
   219 	TUid						iDeviceUid;
   220 
   221 	//
   222 
   223 	MPlayCustomInterface*		iPlayCustomInterface;
   224 
   225 	MRecordCustomInterface*		iRecordCustomInterface;
   226 
   227 	// HwDevice init parameters
   228 	THwDeviceInitParams			iHwDeviceInitParams;
   229 	THwDeviceInitArgs			iHwDeviceInitArgs;
   230 
   231 	// CI observers
   232 	RPointerArray<MCustomInterfaceSupportObserver>	iCISupportObservers;
   233 
   234 	enum THwDeviceState
   235 		{
   236 		EIdle,
   237 		ERunning,
   238 		EPaused,
   239 		EStopped
   240 		};
   241 
   242 	TBool						iLastBuffer;
   243 	THwDeviceState				iHwDeviceState;
   244 	TBool						iLastBufferAck;
   245 	TInt						iRequest;
   246 	TInt						iErrorRates;
   247 	TInt						iErrorModes;
   248 	TInt						iSampleRateConfig;
   249 	TUid						iModeConfig;
   250 
   251 	CMMFHwDevice*				iHwDevice;
   252 	CMMFDataBuffer*				iAdaptationBuffer;
   253 
   254 	MOutputPort*				iOutputPort;
   255 	MInputPort*					iInputPort;
   256 	TInt64						iPosition;
   257 	TInt64 						iPlayedBytesCount;
   258 
   259 	CFourCCConvertor* 			iFourCCConvertor;
   260 	RPointerArray<MAudioCodecAdaptationObserver> iAudioCodecObservers;
   261 	MIgnoreUnderflowEventsCustomInterface* iIgnoreUnderflowInterface;
   262 	TUid						iRampOperation;
   263 	TTimeIntervalMicroSeconds	iRampDuration;
   264 	};
   265 
   266 /*
   267  *	Updates the total bytes played.
   268  *
   269  */
   270 inline void CAudioCodec::UpdateBytesPlayed()
   271 	{
   272 	if (iPlayCustomInterface)
   273 		{
   274 		iPlayedBytesCount = iPlayCustomInterface->BytesPlayed();
   275 		}
   276 	}
   277 
   278 #endif // AUDIOCODEC_H