williamr@2: // Copyright (c) 2002-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: // include\mmf\common\mmfutilities.h williamr@2: // williamr@2: // williamr@2: williamr@2: #ifndef __MMF_COMMON_UTILITIES_H__ williamr@2: #define __MMF_COMMON_UTILITIES_H__ williamr@2: williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: williamr@2: /** williamr@2: @publishedAll williamr@2: @released williamr@2: williamr@2: Identifies the particular stream of the given media type. williamr@2: */ williamr@2: class TMediaId williamr@2: { williamr@2: public: williamr@2: williamr@2: /** williamr@2: Constructs the class with the supplied arguments. williamr@2: williamr@2: This constructor is used when there are multiple streams of the same media type on the same williamr@2: MDataSource. williamr@2: williamr@2: @param aMediaType williamr@2: The media type (video, audio etc.). williamr@2: @param aStreamId williamr@2: Identifies a specific stream when there are multiple streams of the same media type on williamr@2: the same MDataSource. williamr@2: */ williamr@2: TMediaId(TUid aMediaType, TUint aStreamId); williamr@2: williamr@2: /** williamr@2: Constructs the class with the supplied argument. williamr@2: williamr@2: This constructor is used when there is a single stream of the same media type on the same williamr@2: MDataSource. williamr@2: williamr@2: @param aMediaType williamr@2: The media type (video, audio etc.). williamr@2: */ williamr@2: TMediaId(TUid aMediaType); williamr@2: williamr@2: /** williamr@2: Default constructor. williamr@2: */ williamr@2: TMediaId(); williamr@2: public: williamr@2: /** williamr@2: The media type (KUidMediaTypeAudio, KUidMediaTypeVideo, etc). williamr@2: */ williamr@2: TUid iMediaType; williamr@2: williamr@2: /** williamr@2: Identifies a particular media stream used in case where multiple streams williamr@2: of the same media type are present on the same MDataSource. williamr@2: */ williamr@2: TUint iStreamId; williamr@2: private: williamr@2: /** williamr@2: This member is internal and not intended for use. williamr@2: */ williamr@2: TInt iReserved1; williamr@2: TInt iReserved2; williamr@2: TInt iReserved3; williamr@2: }; williamr@2: williamr@2: /** williamr@2: @publishedAll williamr@2: @released williamr@2: williamr@2: The FourCC code that represents NULL. williamr@2: */ williamr@2: const TInt KFourCCNULL = KMMFFourCCCodeNULL; williamr@2: williamr@2: /** williamr@2: @publishedAll williamr@2: @released williamr@2: williamr@2: A class that holds a four character code, representing supported data encodings for the williamr@2: conversion destination. The four character codes are packed into a single TUint32. williamr@2: williamr@2: FourCC codes are a representation of the datatypes used to identify codecs. FourCC codes are used in williamr@2: codec .rss files as a match string used by ECOM to correctly load the required DLL. williamr@2: */ williamr@2: class TFourCC williamr@2: { williamr@2: public: williamr@2: williamr@2: /** williamr@2: Default constructor initialises the class to KMMFFourCCCodeNULL. williamr@2: */ williamr@2: TFourCC() {iFourCC = KMMFFourCCCodeNULL;} //'NULL' williamr@2: williamr@2: /** williamr@2: Packs the four arguments into a single TUint32. williamr@2: williamr@2: The four arguments are packed in little-endian format. williamr@2: williamr@2: @param aChar1 williamr@2: A character that represents part of the FourCC code. This character will be the least williamr@2: significant byte of the code. williamr@2: @param aChar2 williamr@2: A character that represents part of the FourCC code. williamr@2: @param aChar3 williamr@2: A character that represents part of the FourCC code. williamr@2: @param aChar4 williamr@2: A character that represents part of the FourCC code. This character will be the most williamr@2: significant byte of the code. williamr@2: */ williamr@2: TFourCC(TUint8 aChar1, TUint8 aChar2, TUint8 aChar3, TUint8 aChar4) {iFourCC =(aChar4<<24)+(aChar3<<16)+(aChar2<<8)+aChar1;} williamr@2: williamr@2: /** williamr@2: Constructs a FourCC code with the given 8 bit desciptor where the descriptor contains the williamr@2: characters that make up the FourCC code. williamr@2: williamr@2: @param aDes williamr@2: The descriptor containing the characters from which to make the FourCC code. williamr@2: */ williamr@2: TFourCC(const TDesC8& aDes) {iFourCC =(aDes[3]<<24)+(aDes[2]<<16)+(aDes[1]<<8)+aDes[0];} williamr@2: williamr@2: /** williamr@2: Constructor with a TInt32 in little-endian format. williamr@2: williamr@2: @param aFourCC williamr@2: The FourCC code. williamr@2: */ williamr@2: TFourCC(TInt32 aFourCC) {iFourCC = aFourCC;} williamr@2: williamr@2: /** williamr@2: Returns the FourCC code in little-endian format. williamr@2: williamr@2: @return The FourCC code in little-endian format. williamr@2: */ williamr@2: TUint32 FourCC() {return iFourCC;} williamr@2: inline void FourCC( TPtr8* aDes ) const ; williamr@2: williamr@2: /** williamr@2: Sets the FourCC code equal to the value in the supplied argument. williamr@2: williamr@2: @param aFourCC williamr@2: The required TFourCC containting the FourCC code. williamr@2: */ williamr@2: void Set(TFourCC aFourCC) {iFourCC = aFourCC.iFourCC;} williamr@2: williamr@2: /** williamr@2: Sets the FourCC code equal to the supplied argument. williamr@2: williamr@2: @param aFourCC williamr@2: The required FourCC code. williamr@2: */ williamr@2: void Set(TUint32 aFourCC) {iFourCC = aFourCC;} williamr@2: williamr@2: /** williamr@2: Equality operator. williamr@2: williamr@2: @param aA williamr@2: The TFourCC code that *this will be tested against. williamr@2: williamr@2: @return A boolean indicating if the two values are equal. ETrue if the two values are equal, williamr@2: otherwise false. williamr@2: */ williamr@2: TBool operator==(const TFourCC& aA) const {return (iFourCC == aA.iFourCC);} williamr@2: williamr@2: /** williamr@2: Equality operator. williamr@2: williamr@2: @param aUint williamr@2: The FourCC code that *this will be tested against. williamr@2: williamr@2: @return A boolean indicating if the two values are equal. ETrue if the two values are equal, williamr@2: otherwise false. williamr@2: */ williamr@2: TBool operator==(const TUint32& aUint) const {return (iFourCC == aUint);} williamr@2: williamr@2: /** williamr@2: Inequality operator. williamr@2: williamr@2: @param aA williamr@2: The TFourCC code that *this will be tested against. williamr@2: williamr@2: @return A boolean indicating if the two values are not equal. ETrue if the two values are williamr@2: unequal, otherwise false. williamr@2: */ williamr@2: TBool operator!=(const TFourCC& aA) const {return (iFourCC != aA.iFourCC);} williamr@2: williamr@2: /** williamr@2: Inequality operator. williamr@2: williamr@2: @param aUint williamr@2: The FourCC code that *this will be tested against. williamr@2: */ williamr@2: TBool operator!=(const TUint32& aUint) const {return (iFourCC != aUint);} williamr@2: williamr@2: private: williamr@2: TUint32 iFourCC; williamr@2: }; williamr@2: williamr@2: /** williamr@2: @internalAll williamr@2: williamr@2: Base utility class to change the sample rate of audio data in a buffer williamr@2: */ williamr@2: class CMMFChannelAndSampleRateConverter : public CBase williamr@2: { williamr@2: public: williamr@2: /** williamr@2: Reads the audio data from the source buffer, williamr@2: converts the number of channels and the sample rate williamr@2: and copies the result to the destination buffer williamr@2: williamr@2: @param aSrcBuffer williamr@2: A pointer to a source buffer containing the audio data to convert. williamr@2: @param aDstBuffer williamr@2: A pointer to a destination buffer. williamr@2: williamr@2: @return The length of the destination buffer. williamr@2: */ williamr@2: virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer) =0; williamr@2: virtual void Reset() {}; williamr@2: williamr@2: /* williamr@2: Indicates what buffer size is required to hold the converted data. williamr@2: */ williamr@2: virtual TUint MaxConvertBufferSize(TUint aSrcBufferSize) {return aSrcBufferSize;} williamr@2: williamr@2: void SetRates(TInt aSrcRate,TInt aSrcChannels,TInt aDstRate,TInt aDstChannels); williamr@2: public: williamr@2: /* williamr@2: The sample rate of the data in the source buffer williamr@2: */ williamr@2: TInt iFromRate; williamr@2: /* williamr@2: The sample rate of the data in the destination buffer williamr@2: */ williamr@2: TInt iToRate; williamr@2: /* williamr@2: The number of channels of data in the source buffer williamr@2: */ williamr@2: TInt iFromChannels; williamr@2: /* williamr@2: The number of channels of data in the destination buffer williamr@2: */ williamr@2: TInt iToChannels; williamr@2: protected: williamr@2: TReal iRatio; williamr@2: TInt iFraction; williamr@2: TInt iIndex; williamr@2: }; williamr@2: williamr@2: /** williamr@2: @internalAll williamr@2: */ williamr@2: class CMMFStereoToMonoRateConverter : public CMMFChannelAndSampleRateConverter williamr@2: { williamr@2: public: williamr@2: virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer); williamr@2: virtual TUint MaxConvertBufferSize(TUint aSrcBufferSize); williamr@2: williamr@2: }; williamr@2: williamr@2: /** williamr@2: @internalAll williamr@2: */ williamr@2: class CMMFStereoToMonoConverter : public CMMFChannelAndSampleRateConverter williamr@2: { williamr@2: public: williamr@2: virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer); williamr@2: virtual TUint MaxConvertBufferSize(TUint aSrcBufferSize); williamr@2: }; williamr@2: williamr@2: /** williamr@2: @internalAll williamr@2: */ williamr@2: class CMMFStereoToStereoRateConverter : public CMMFChannelAndSampleRateConverter williamr@2: { williamr@2: public: williamr@2: virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer); williamr@2: }; williamr@2: williamr@2: /** williamr@2: @internalAll williamr@2: */ williamr@2: class CMMFMonoToMonoRateConverter : public CMMFChannelAndSampleRateConverter williamr@2: { williamr@2: public: williamr@2: virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer); williamr@2: }; williamr@2: williamr@2: /** williamr@2: @internalAll williamr@2: */ williamr@2: class CMMFMonoToStereoConverter : public CMMFChannelAndSampleRateConverter williamr@2: { williamr@2: public: williamr@2: virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer); williamr@2: virtual TUint MaxConvertBufferSize(TUint aSrcBufferSize); williamr@2: }; williamr@2: williamr@2: /** williamr@2: @internalAll williamr@2: */ williamr@2: class CMMFMonoToStereoRateConverter : public CMMFChannelAndSampleRateConverter williamr@2: { williamr@2: public: williamr@2: virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer); williamr@2: virtual TUint MaxConvertBufferSize(TUint aSrcBufferSize); williamr@2: }; williamr@2: williamr@2: /** williamr@2: @internalAll williamr@2: williamr@2: Factory class to create the appropriate CMMFChannelAndSampleRateConverter-derived williamr@2: class depending on the supplied number of channels and bit rate williamr@2: */ williamr@2: class CMMFChannelAndSampleRateConverterFactory : public CBase williamr@2: { williamr@2: williamr@2: public: williamr@2: IMPORT_C CMMFChannelAndSampleRateConverter* CreateConverterL(TInt aFromRate,TInt aFromChannels, williamr@2: TInt aToRate,TInt aToChannels); williamr@2: IMPORT_C CMMFChannelAndSampleRateConverter* CreateConverterL(); williamr@2: CMMFChannelAndSampleRateConverter* Converter() {return iConverter;} williamr@2: IMPORT_C ~CMMFChannelAndSampleRateConverterFactory(); williamr@2: TInt Rate() {return iToRate;} williamr@2: TInt Channels() {return iToChannels;} williamr@2: public: williamr@2: /** williamr@2: The sample rate of the data in the source buffer williamr@2: */ williamr@2: TInt iFromRate; williamr@2: /** williamr@2: The sample rate of the data in the destination buffer williamr@2: */ williamr@2: TInt iToRate; williamr@2: /** williamr@2: The number of channels of data in the source buffer williamr@2: */ williamr@2: TInt iFromChannels; williamr@2: /** williamr@2: The number of channels of data in the destination buffer williamr@2: */ williamr@2: TInt iToChannels; williamr@2: private: williamr@2: CMMFChannelAndSampleRateConverter* iConverter; williamr@2: }; williamr@2: williamr@2: #include williamr@2: williamr@2: #endif