sl@0: /* sl@0: * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #ifndef AUDIOCODEC_H sl@0: #define AUDIOCODEC_H sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "hwdeviceimplementationuids.hrh" sl@0: sl@0: #include sl@0: sl@0: #include "moutputport.h" sl@0: #include "minputport.h" sl@0: #include "mgainhelper.h" sl@0: #include "mstreampositioncontrol.h" sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #define KFOURCCLENGTH 4 sl@0: sl@0: sl@0: enum TMode sl@0: { sl@0: // Decoder mode sl@0: EDecode = 0x01, sl@0: // And vice versa sl@0: EEncode = 0x02 sl@0: }; sl@0: sl@0: class TSampleRateTableEntry sl@0: { sl@0: public: sl@0: TInt iSampleRateValue; sl@0: TMMFSampleRate iSampleRate; sl@0: }; sl@0: sl@0: class TAudioModeTableEntry sl@0: { sl@0: public: sl@0: TMMFMonoStereo iAudioModeValue; sl@0: TUid iAudioMode; sl@0: }; sl@0: sl@0: const TInt KMaxModeIndex = 1; sl@0: sl@0: sl@0: sl@0: class MAudioCodecAdaptationObserver; sl@0: class CFourCCConvertor; sl@0: sl@0: ///// sl@0: //This is the reference implementation of Phyisical AudioCodec sl@0: //@lib audiocodec.lib sl@0: /// sl@0: sl@0: // TODO: Check if those interfaces MInputPort, MOutputPort should be replaced by MMMFAudioDataSupplier, MMMFAudioDataConsumer sl@0: sl@0: sl@0: NONSHARABLE_CLASS(CAudioCodec) :public CActive, sl@0: public MMMFHwDeviceObserver, sl@0: public MInputPort, // Adaptation interface sl@0: public MOutputPort, // Adaptation interface sl@0: public MGainHelper, // Adaptation interface sl@0: public MCustomInterfaceSupport, // A3F interface sl@0: public MStreamPositionControl // Adaptation interface sl@0: { sl@0: friend class CAudioGainControl; sl@0: public: sl@0: sl@0: ///// sl@0: // Create a new instance. sl@0: // sl@0: // @param aTypeId. sl@0: // @return CAudioCodec* a pointer to the created instance. sl@0: /// sl@0: sl@0: IMPORT_C static CAudioCodec* NewL(TUid aTypeId, const CFourCCConvertor& aFourCCConvertor); sl@0: sl@0: // Check if this would be removed sl@0: ///// sl@0: // Structure to hold hw device init parameters sl@0: /// sl@0: class THwDeviceInitArgs sl@0: { sl@0: public: sl@0: TUint8 iPolicyId; sl@0: TInt iEapStreamId; sl@0: }; sl@0: sl@0: ///// sl@0: // Destructor. sl@0: // sl@0: // Deletes all objects and releases all resource owned by this instance. sl@0: /// sl@0: virtual ~CAudioCodec(); sl@0: sl@0: sl@0: IMPORT_C TInt SetFormat(TUid aFormat); sl@0: IMPORT_C TInt RegisterAudioCodecObserver(MAudioCodecAdaptationObserver& aObserver); sl@0: IMPORT_C void UnregisterAudioCodecObserver(MAudioCodecAdaptationObserver& aObserver); sl@0: IMPORT_C TInt Initialize(); sl@0: IMPORT_C TInt Load(TInt aSampleRate, TUid aMode); sl@0: IMPORT_C TInt Start(); sl@0: IMPORT_C TInt Pause(); sl@0: IMPORT_C TInt Stop(); sl@0: sl@0: sl@0: sl@0: // From MOutputPort sl@0: TInt GetOutputPort(MOutputPort*& aOutputPort); sl@0: sl@0: // From MInputPort sl@0: TInt GetInputPort(MInputPort*& aInputPort); sl@0: sl@0: // From MCustomInterfaceSupport sl@0: virtual TInt RequestCustomInterface(TUid aUid, TAny*& aPtr); sl@0: virtual TInt RegisterObserver(MCustomInterfaceSupportObserver& aObserver); sl@0: virtual void UnRegisterObserver(MCustomInterfaceSupportObserver& aObserver); sl@0: sl@0: // from base class MInputPort sl@0: virtual TInt EmptyBuffer(CMMFBuffer* aBuffer, MOutputPort* aSupplier); sl@0: virtual TInt BufferFilled(CMMFBuffer* aBuffer); sl@0: virtual TInt SetOutput(MOutputPort* aOutput); sl@0: virtual TInt RemoveOutput(MOutputPort* aOutput); sl@0: sl@0: // from base class MOutputPort sl@0: virtual TInt FillBuffer(CMMFBuffer* aBuffer, MInputPort* aConsumer); sl@0: virtual TInt BufferEmptied(CMMFBuffer* aBuffer); sl@0: virtual TInt SetInput(MInputPort* aInput); sl@0: virtual TInt RemoveInput(MInputPort* aInput); sl@0: virtual TInt FlushBuffer(MFlushHandlerObserver* aFlushObserver); sl@0: sl@0: // from base class MMMFHwDeviceObserver sl@0: virtual TInt FillThisHwBuffer(CMMFBuffer& aHwBuffer); sl@0: virtual TInt EmptyThisHwBuffer(CMMFBuffer& aHwBuffer); sl@0: virtual TInt MsgFromHwDevice(TUid aMessageType, const TDesC8& aMsg); sl@0: virtual void Stopped(); sl@0: virtual void Error(TInt aError); sl@0: sl@0: // from base class MGainHelper sl@0: TInt GetGain(TInt& aGain) const; sl@0: TInt SetGain(RArray& aChannels); sl@0: TInt ConfigureRamp(TUid aRampOperation, const TTimeIntervalMicroSeconds& aRampDuration); sl@0: sl@0: // from base class MStreamPositionControl sl@0: TInt GetControlPosition(TTimeIntervalMicroSeconds& aPosition); sl@0: void ResetControlPosition(); sl@0: sl@0: sl@0: TInt ResolveMode(TUid aMode); sl@0: TInt GetSupportedSampleRates(RArray& aSupportedRates); sl@0: TInt GetSupportedModes(RArray& aSupportedModes); sl@0: sl@0: //Return the supported values to the client sl@0: IMPORT_C TInt SupportedModes(RArray& aSupportedModes); sl@0: IMPORT_C TInt SupportedRates(RArray& aSupportedRates); sl@0: sl@0: protected: sl@0: // from CActive sl@0: void RunL(); sl@0: void DoCancel(); sl@0: TInt RunError(TInt aError); sl@0: sl@0: TInt LoadHwDevice(); sl@0: TInt InitHwDevice(); sl@0: TInt SetHwDeviceConfig(); sl@0: void FourCCToHwDeviceUidL(TFourCC aFourCC, TMode aMode, TUid &aHWDev); sl@0: sl@0: TBool IsDataTypeMatch(CImplementationInformation* aHwDeviceResourceEntry, sl@0: const TDesC8& aHwMatchFourCC, TMode aState); sl@0: sl@0: // TODO: This will be replaced, when the new mechanism to get the supported configuration sl@0: // will be defined sl@0: ///// sl@0: // Reads hw device parameters from resource files. sl@0: // @return error code. sl@0: /// sl@0: TInt ReadResourceRates(RArray& aRates); sl@0: TInt ReadResourceModes(RArray& aModes); sl@0: sl@0: void UpdateBytesPlayed(); sl@0: sl@0: private: sl@0: void ConstructL(); sl@0: sl@0: CAudioCodec(TUid aTypeId, const CFourCCConvertor& aFourCCConvertor); sl@0: sl@0: private: sl@0: TUid iType; sl@0: // Indicates if this is an encoder or decoder sl@0: TMode iMode; sl@0: sl@0: // The codec format sl@0: TUid iFormat; sl@0: sl@0: // Resolved HwDevice Uid sl@0: TUid iDeviceUid; sl@0: sl@0: // sl@0: sl@0: MPlayCustomInterface* iPlayCustomInterface; sl@0: sl@0: MRecordCustomInterface* iRecordCustomInterface; sl@0: sl@0: // HwDevice init parameters sl@0: THwDeviceInitParams iHwDeviceInitParams; sl@0: THwDeviceInitArgs iHwDeviceInitArgs; sl@0: sl@0: // CI observers sl@0: RPointerArray iCISupportObservers; sl@0: sl@0: enum THwDeviceState sl@0: { sl@0: EIdle, sl@0: ERunning, sl@0: EPaused, sl@0: EStopped sl@0: }; sl@0: sl@0: TBool iLastBuffer; sl@0: THwDeviceState iHwDeviceState; sl@0: TBool iLastBufferAck; sl@0: TInt iRequest; sl@0: TInt iErrorRates; sl@0: TInt iErrorModes; sl@0: TInt iSampleRateConfig; sl@0: TUid iModeConfig; sl@0: sl@0: CMMFHwDevice* iHwDevice; sl@0: CMMFDataBuffer* iAdaptationBuffer; sl@0: sl@0: MOutputPort* iOutputPort; sl@0: MInputPort* iInputPort; sl@0: TInt64 iPosition; sl@0: TInt64 iPlayedBytesCount; sl@0: sl@0: CFourCCConvertor* iFourCCConvertor; sl@0: RPointerArray iAudioCodecObservers; sl@0: MIgnoreUnderflowEventsCustomInterface* iIgnoreUnderflowInterface; sl@0: TUid iRampOperation; sl@0: TTimeIntervalMicroSeconds iRampDuration; sl@0: }; sl@0: sl@0: /* sl@0: * Updates the total bytes played. sl@0: * sl@0: */ sl@0: inline void CAudioCodec::UpdateBytesPlayed() sl@0: { sl@0: if (iPlayCustomInterface) sl@0: { sl@0: iPlayedBytesCount = iPlayCustomInterface->BytesPlayed(); sl@0: } sl@0: } sl@0: sl@0: #endif // AUDIOCODEC_H