williamr@2: // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@2: // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members williamr@2: // which accompanies this distribution, and is available williamr@2: // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // williamr@2: williamr@2: #ifndef __MMFSWCODECWRAPPER_H__ williamr@2: #define __MMFSWCODECWRAPPER_H__ williamr@2: williamr@2: #include williamr@2: #include williamr@2: williamr@2: class CMMFSwCodecDataPath; //forward reference williamr@2: williamr@2: /** williamr@2: @publishedAll williamr@2: @released williamr@2: williamr@2: Class for a software codec used by the CMMFSwCodecWrapper class to make the CMMFSwCodec a williamr@2: CMMFHwDevice plugin. The CMMFSwCodec processes source data in a certain fourCC coding type and williamr@2: converts it to a destination buffer of another fourCC coding type. williamr@2: williamr@2: A CMMFSwCodec object would usually not be instantiated directly williamr@2: but instead would be instantiated via the CMMFSwCodecWrapper class's Codec() williamr@2: method. williamr@2: williamr@2: The processing of the data is handled by the codecs ProcessL() member. williamr@2: The intention is that the source buffer for conversion is converted to the appropriate coding type williamr@2: in the destination buffer. The size of the buffers passed in are determined by SourceBufferSize() williamr@2: and SinkBufferSize() methods. The buffer sizes should be chosen such that williamr@2: the ProcessL() method can be guaranteed to have enough destination buffer to williamr@2: completely process one source buffer. williamr@2: williamr@2: The ProcessL should return a TCodecProcessResult returning the number of source bytes processed williamr@2: and the number of destination bytes processed along with a process result code defined thus: williamr@2: - EProcessComplete: the codec processed all the source data into the sink buffer williamr@2: - EProcessIncomplete: the codec filled sink buffer before all the source buffer was processed williamr@2: - EDstNotFilled: the codec processed the source buffer but the sink buffer was not filled williamr@2: - EEndOfData: the codec detected the end data - all source data in processed but sink may not be full williamr@2: - EProcessError: the codec process error condition williamr@2: williamr@2: Unlike the 7.0s CMMFCodec::ProcessL method, the CMMFSwCodec::ProcessL method williamr@2: should not return EProcessIncomplete as this case is not handled by the williamr@2: CMMFSwCodecWrapper. williamr@2: */ williamr@2: class CMMFSwCodec : public CBase williamr@2: { williamr@2: public: williamr@2: /** williamr@2: @publishedAll williamr@2: @released williamr@2: williamr@2: Indicates the result of processing data from the source buffer to a destination buffer williamr@2: and provides functions to compare the result code. williamr@2: The CMMFSwCodec buffer sizes should be set to return EProcessComplete williamr@2: The other return codes are to keep the ProcessL method compatible with williamr@2: the 7.0s CMMFCodec API. williamr@2: */ williamr@2: class TCodecProcessResult williamr@2: { williamr@2: public: williamr@2: /** williamr@2: Flag to track the codec's processing status. williamr@2: */ williamr@2: enum TCodecProcessResultStatus williamr@2: { williamr@2: /** The codec has successfully completed its processing. */ williamr@2: EProcessComplete, williamr@2: /** Could not empty the source buffer because the destination buffer became full. */ williamr@2: EProcessIncomplete, williamr@2: /** Codec came across an end of data. */ williamr@2: EEndOfData, williamr@2: /** Could not fill the destination buffer because the source buffer has been emptied. */ williamr@2: EDstNotFilled, williamr@2: /** An error occured. */ williamr@2: EProcessError williamr@2: }; williamr@2: williamr@2: /** Overloaded operator to test equality. */ williamr@2: TBool operator==(const TCodecProcessResultStatus aStatus) const {return (iCodecProcessStatus == aStatus);} williamr@2: /** Overloaded operator to test inequality. */ williamr@2: TBool operator!=(const TCodecProcessResultStatus aStatus) const {return (iCodecProcessStatus != aStatus);} williamr@2: williamr@2: /** williamr@2: Default constructor. williamr@2: */ williamr@2: TCodecProcessResult() williamr@2: :iCodecProcessStatus(EProcessError), iSrcBytesProcessed(0), iDstBytesAdded(0) {}; williamr@2: williamr@2: public: williamr@2: /** williamr@2: The codec's processing status williamr@2: williamr@2: @see enum TCodecProcessResultStatus williamr@2: */ williamr@2: TCodecProcessResultStatus iCodecProcessStatus; williamr@2: williamr@2: /** The number of source bytes processed */ williamr@2: TUint iSrcBytesProcessed; williamr@2: williamr@2: /** The number of bytes added to the destination buffer */ williamr@2: TUint iDstBytesAdded; williamr@2: }; williamr@2: public: williamr@2: williamr@2: /** williamr@2: Processes the data in the specified source buffer and writes the processed data to williamr@2: the specified destination buffer. williamr@2: williamr@2: This function is synchronous, when the function returns the data has been processed. williamr@2: This is a virtual function that each derived class must implement. williamr@2: williamr@2: @param aSource williamr@2: The source buffer containing data to encode or decode. williamr@2: @param aDest williamr@2: The destination buffer to hold the data after encoding or decoding. williamr@2: williamr@2: @return The result of the processing. williamr@2: williamr@2: @see TCodecProcessResult williamr@2: */ williamr@2: virtual TCodecProcessResult ProcessL(const CMMFBuffer& aSource, CMMFBuffer& aDest) = 0; williamr@2: williamr@2: /** williamr@2: Gets the max size of the source buffer passed into the williamr@2: CMMFSwCodec::ProcessL function. williamr@2: williamr@2: Note that this means that this is the Max size of each buffer passed to the codec. The actual williamr@2: size of the data could be less than the max size. This is a virtual function that each derived williamr@2: class must implement. williamr@2: williamr@2: @return The max size of the source buffer in bytes. williamr@2: */ williamr@2: virtual TUint SourceBufferSize() = 0; williamr@2: williamr@2: /** williamr@2: Gets the max size of the sink (destination) buffer passed into the williamr@2: CMMFSwCodec::ProcessL method. williamr@2: williamr@2: Note that this means that this is the Max size of each buffer passed to the codec. The actual williamr@2: size of the data written to this buffer could be less than the max size. This is a virtual williamr@2: function that each derived class must implement. williamr@2: williamr@2: @return The max size of the sink buffer in bytes. williamr@2: */ williamr@2: virtual TUint SinkBufferSize() = 0; williamr@2: williamr@2: /** williamr@2: @internalAll williamr@2: williamr@2: Function that needs to be overriden if the codec is a 'Null' codec williamr@2: ie. it does not perform any data type transformation. The 'Null' codec williamr@2: should override this to return ETrue and provide a dummy williamr@2: ProcessL. The CMMFSwCodecWrapper will then use the same buffer williamr@2: for both the source and the sink. Null codecs should return the same williamr@2: buffer size for both the Source and SinkBufferSize methods. williamr@2: Since most CMMFSwCodec implementations will not be null codecs williamr@2: this method can be ignored. williamr@2: williamr@2: Would not normally expect 3rd parties to have to implement this. williamr@2: */ williamr@2: virtual TBool IsNullCodec() {return EFalse;}; williamr@2: }; williamr@2: williamr@2: /** williamr@2: @publishedAll williamr@2: @released williamr@2: williamr@2: Class to make a CMMFSwCodec into a CMMFHwDevice ECOM plugin. williamr@2: williamr@2: Most of the code to make a CMMFSwCodec into a CMMFHwDevice ECOM plugin is provided williamr@2: in CMMFSwCodecWrapper. Someone writing a plugin derrived from CMMFSwCodecWrapper williamr@2: only needs to provide the standard ECOM implementation code, constructors williamr@2: and destructors and implement the Codec() function which should return the williamr@2: appropriate CMMFSwCodec. williamr@2: williamr@2: Third parties using CMMFSwCodecWrapper that do not use the RMdaDevSound API williamr@2: to talk to the sound drivers would need to port the datapaths for their own williamr@2: sound drivers. Third parties would also need to change the custom interfaces williamr@2: where necessary. williamr@2: */ williamr@2: class CMMFSwCodecWrapper : public CMMFHwDevice williamr@2: { williamr@2: public: williamr@2: IMPORT_C virtual ~CMMFSwCodecWrapper(); williamr@2: protected: williamr@2: IMPORT_C CMMFSwCodecWrapper(); williamr@2: IMPORT_C virtual TInt Init(THwDeviceInitParams &aDevInfo); williamr@2: IMPORT_C virtual TInt Start(TDeviceFunc aFuncCmd, TDeviceFlow aFlowCmd); williamr@2: IMPORT_C virtual TInt Stop(); williamr@2: IMPORT_C virtual TInt Pause(); williamr@2: IMPORT_C virtual TAny* CustomInterface(TUid aInterfaceId); williamr@2: IMPORT_C virtual TInt ThisHwBufferFilled(CMMFBuffer& aFillBufferPtr); williamr@2: IMPORT_C virtual TInt ThisHwBufferEmptied(CMMFBuffer& aBuffer); williamr@2: IMPORT_C virtual TInt SetConfig(TTaskConfig& aConfig); williamr@2: IMPORT_C virtual TInt StopAndDeleteCodec(); williamr@2: IMPORT_C virtual TInt DeleteCodec(); williamr@2: /** williamr@2: This method must return the CMMFSwCodec used by the derived williamr@2: CMMFSwCodecWrapper class. The method should create the CMMFSwCodec williamr@2: if it hasn't done so already. williamr@2: williamr@2: This is a virtual function that each derived class must implement. williamr@2: williamr@2: @return The CMMFSwCodec used by the derrived CMMFSwCodecWrapper williamr@2: */ williamr@2: virtual CMMFSwCodec& Codec() = 0; williamr@2: IMPORT_C void SetVbrFlag(); williamr@2: private: williamr@2: TInt StartEncode(); williamr@2: TInt StartDecode(); williamr@2: TInt StartConvert(); williamr@2: williamr@2: protected: williamr@2: /** williamr@2: The software codec used williamr@2: */ williamr@2: CMMFSwCodec* iCodec; williamr@2: williamr@2: /** williamr@2: The source buffer for the codec williamr@2: */ williamr@2: CMMFDataBuffer* iSourceBuffer; williamr@2: williamr@2: /** williamr@2: The sink buffer for the codec williamr@2: */ williamr@2: CMMFDataBuffer* iSinkBuffer; williamr@2: williamr@2: /** williamr@2: The datapath used to transfer the data williamr@2: */ williamr@2: CMMFSwCodecDataPath* iDataPath; williamr@2: williamr@2: /** williamr@2: The play custom interface williamr@2: */ williamr@2: MPlayCustomInterface* iPlayCustomInterface; williamr@2: williamr@2: /** williamr@2: The record custom interface williamr@2: */ williamr@2: MRecordCustomInterface* iRecordCustomInterface; williamr@2: williamr@2: /** williamr@2: The buffer size of the sound device williamr@2: */ williamr@2: TUint iDeviceBufferSize; williamr@2: williamr@2: /** williamr@2: The sample rate of the sound device williamr@2: */ williamr@2: TInt iSampleRate; williamr@2: williamr@2: /** williamr@2: The number of channels of the sound device williamr@2: */ williamr@2: TInt iChannels; williamr@2: }; williamr@2: williamr@2: #endif