epoc32/include/mmf/common/mmfutilities.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
     1.1 --- a/epoc32/include/mmf/common/mmfutilities.h	Tue Nov 24 13:55:44 2009 +0000
     1.2 +++ b/epoc32/include/mmf/common/mmfutilities.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -1,1 +1,367 @@
     1.4 -mmfutilities.h
     1.5 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +// All rights reserved.
     1.7 +// This component and the accompanying materials are made available
     1.8 +// 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
     1.9 +// which accompanies this distribution, and is available
    1.10 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
    1.11 +//
    1.12 +// Initial Contributors:
    1.13 +// Nokia Corporation - initial contribution.
    1.14 +//
    1.15 +// Contributors:
    1.16 +//
    1.17 +// Description:
    1.18 +// include\mmf\common\mmfutilities.h
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +#ifndef __MMF_COMMON_UTILITIES_H__
    1.23 +#define __MMF_COMMON_UTILITIES_H__
    1.24 +
    1.25 +#include <e32base.h>
    1.26 +#include <mmf/server/mmfdatabuffer.h>
    1.27 +#include <mmf/common/mmffourcc.h>
    1.28 +
    1.29 +
    1.30 +/** 
    1.31 +@publishedAll
    1.32 +@released
    1.33 +
    1.34 +Identifies the particular stream of the given media type.
    1.35 +*/
    1.36 +class TMediaId
    1.37 +	{
    1.38 +public:
    1.39 +
    1.40 +	/**
    1.41 +	Constructs the class with the supplied arguments.
    1.42 +
    1.43 +	This constructor is used when there are multiple streams of the same media type on the same
    1.44 +	MDataSource.
    1.45 +
    1.46 +	@param  aMediaType
    1.47 +	        The media type (video, audio etc.).
    1.48 +	@param  aStreamId
    1.49 +	        Identifies a specific stream when there are multiple streams of the same media type on 
    1.50 +	        the same MDataSource.
    1.51 +	*/
    1.52 +	TMediaId(TUid aMediaType, TUint aStreamId);
    1.53 +
    1.54 +	/**
    1.55 +    Constructs the class with the supplied argument.
    1.56 +
    1.57 +	This constructor is used when there is a single stream of the same media type on the same
    1.58 +	MDataSource.
    1.59 +
    1.60 +	@param  aMediaType
    1.61 +	        The media type (video, audio etc.).
    1.62 +	*/
    1.63 +	TMediaId(TUid aMediaType);
    1.64 +
    1.65 +	/**
    1.66 +	Default constructor.
    1.67 +	*/
    1.68 +	TMediaId();
    1.69 +public:
    1.70 +	/**
    1.71 +	The media type (KUidMediaTypeAudio, KUidMediaTypeVideo, etc).
    1.72 +	*/
    1.73 +	TUid iMediaType;
    1.74 +
    1.75 +	/**
    1.76 +	Identifies a particular media stream used in case where multiple streams
    1.77 +	of the same media type are present on the same MDataSource.
    1.78 +	*/
    1.79 +	TUint iStreamId;
    1.80 +private:
    1.81 +	/**
    1.82 +	This member is internal and not intended for use.
    1.83 +	*/
    1.84 +	TInt iReserved1;
    1.85 +	TInt iReserved2;
    1.86 +	TInt iReserved3;
    1.87 +	};
    1.88 +
    1.89 +/**
    1.90 +@publishedAll
    1.91 +@released
    1.92 +
    1.93 +The FourCC code that represents NULL.
    1.94 +*/
    1.95 +const TInt KFourCCNULL = KMMFFourCCCodeNULL;
    1.96 +
    1.97 +/**
    1.98 +@publishedAll
    1.99 +@released
   1.100 +
   1.101 +A class that holds a four character code, representing supported data encodings for the
   1.102 +conversion destination. The four character codes are packed into a single TUint32.
   1.103 +
   1.104 +FourCC codes are a representation of the datatypes used to identify codecs. FourCC codes are used in 
   1.105 +codec .rss files as a match string used by ECOM to correctly load the required DLL.
   1.106 +*/
   1.107 +class TFourCC
   1.108 +{
   1.109 +public:
   1.110 +
   1.111 +	/**
   1.112 +	Default constructor initialises the class to KMMFFourCCCodeNULL.
   1.113 +	*/
   1.114 +	TFourCC() {iFourCC = KMMFFourCCCodeNULL;} //'NULL'
   1.115 +
   1.116 +	/**
   1.117 +	Packs the four arguments into a single TUint32.
   1.118 +
   1.119 +	The four arguments are packed in little-endian format.
   1.120 +
   1.121 +	@param  aChar1
   1.122 +	        A character that represents part of the FourCC code. This character will be the least 
   1.123 +	        significant byte of the code.
   1.124 +	@param  aChar2
   1.125 +            A character that represents part of the FourCC code.
   1.126 +	@param  aChar3
   1.127 +            A character that represents part of the FourCC code.
   1.128 +	@param  aChar4
   1.129 +	        A character that represents part of the FourCC code. This character will be the most 
   1.130 +	        significant byte of the code.
   1.131 +	*/
   1.132 +	TFourCC(TUint8 aChar1, TUint8 aChar2, TUint8 aChar3, TUint8 aChar4) {iFourCC =(aChar4<<24)+(aChar3<<16)+(aChar2<<8)+aChar1;}
   1.133 +
   1.134 +	/**
   1.135 +	Constructs a FourCC code with the given 8 bit desciptor where the descriptor contains the
   1.136 +	characters that make up the FourCC code.
   1.137 +
   1.138 +	@param  aDes
   1.139 +	        The descriptor containing the characters from which to make the FourCC code.
   1.140 +	*/
   1.141 +	TFourCC(const TDesC8& aDes) {iFourCC =(aDes[3]<<24)+(aDes[2]<<16)+(aDes[1]<<8)+aDes[0];}
   1.142 +
   1.143 +	/**
   1.144 +    Constructor with a TInt32 in little-endian format.
   1.145 +
   1.146 +	@param  aFourCC
   1.147 +            The FourCC code.
   1.148 +	*/
   1.149 +	TFourCC(TInt32 aFourCC) {iFourCC = aFourCC;}
   1.150 +
   1.151 +	/**
   1.152 +    Returns the FourCC code in little-endian format.
   1.153 +
   1.154 +	@return The FourCC code in little-endian format.
   1.155 +	*/
   1.156 +	TUint32 FourCC() {return iFourCC;}
   1.157 +	inline void FourCC( TPtr8* aDes ) const ;
   1.158 +
   1.159 +	/**
   1.160 +    Sets the FourCC code equal to the value in the supplied argument.
   1.161 +
   1.162 +	@param  aFourCC
   1.163 +	        The required TFourCC containting the FourCC code.
   1.164 +	*/
   1.165 +	void Set(TFourCC aFourCC) {iFourCC = aFourCC.iFourCC;}
   1.166 +
   1.167 +	/**
   1.168 +    Sets the FourCC code equal to the supplied argument.
   1.169 +
   1.170 +	@param  aFourCC
   1.171 +	        The required FourCC code.
   1.172 +	*/
   1.173 +	void Set(TUint32 aFourCC) {iFourCC = aFourCC;}
   1.174 +
   1.175 +	/**
   1.176 +	Equality operator.
   1.177 +
   1.178 +	@param  aA
   1.179 +	        The TFourCC code that *this will be tested against.
   1.180 +
   1.181 +	@return A boolean indicating if the two values are equal. ETrue if the two values are equal, 
   1.182 +	        otherwise false.
   1.183 +	*/
   1.184 +	TBool operator==(const TFourCC& aA) const {return (iFourCC == aA.iFourCC);}
   1.185 +
   1.186 +	/**
   1.187 +    Equality operator.
   1.188 +
   1.189 +	@param  aUint
   1.190 +	        The FourCC code that *this will be tested against.
   1.191 +
   1.192 +	@return A boolean indicating if the two values are equal. ETrue if the two values are equal, 
   1.193 +	        otherwise false.
   1.194 +	*/
   1.195 +	TBool operator==(const TUint32& aUint) const {return (iFourCC == aUint);}
   1.196 +
   1.197 +	/**
   1.198 +    Inequality operator.
   1.199 +
   1.200 +	@param  aA
   1.201 +	        The TFourCC code that *this will be tested against.
   1.202 +	
   1.203 +	@return A boolean indicating if the two values are not equal. ETrue if the two values are 
   1.204 +	        unequal, otherwise false.
   1.205 +	*/
   1.206 +	TBool operator!=(const TFourCC& aA) const {return (iFourCC != aA.iFourCC);}
   1.207 +
   1.208 +	/**
   1.209 +    Inequality operator.
   1.210 +
   1.211 +	@param  aUint
   1.212 +	        The FourCC code that *this will be tested against.
   1.213 +	*/
   1.214 +	TBool operator!=(const TUint32& aUint) const {return (iFourCC != aUint);}
   1.215 +
   1.216 +private:
   1.217 +	TUint32 iFourCC;
   1.218 +};
   1.219 +
   1.220 +/**
   1.221 +@internalAll
   1.222 +
   1.223 +Base utility class to change the sample rate of audio data in a buffer
   1.224 +*/
   1.225 +class CMMFChannelAndSampleRateConverter : public CBase
   1.226 +	{
   1.227 +public:
   1.228 +	/**
   1.229 +	Reads the audio data from the source buffer,
   1.230 +	converts the number of channels and the sample rate
   1.231 +	and copies the result to the destination buffer
   1.232 +
   1.233 +	@param  aSrcBuffer
   1.234 +	        A pointer to a source buffer containing the audio data to convert.
   1.235 +	@param  aDstBuffer
   1.236 +	        A pointer to a destination buffer.
   1.237 +
   1.238 +	@return The length of the destination buffer.
   1.239 +	*/
   1.240 +	virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer) =0;
   1.241 +	virtual void Reset() {};
   1.242 +
   1.243 +	/*
   1.244 +	Indicates what buffer size is required to hold the converted data.
   1.245 +	*/
   1.246 +	virtual TUint MaxConvertBufferSize(TUint aSrcBufferSize) {return aSrcBufferSize;}
   1.247 +
   1.248 +	void SetRates(TInt aSrcRate,TInt aSrcChannels,TInt aDstRate,TInt aDstChannels);
   1.249 +public:
   1.250 +	/*
   1.251 +	The sample rate of the data in the source buffer
   1.252 +	*/
   1.253 +	TInt iFromRate;
   1.254 +	/*
   1.255 +	The sample rate of the data in the destination buffer
   1.256 +	*/
   1.257 +	TInt iToRate;
   1.258 +	/*
   1.259 +	The number of channels of data in the source buffer
   1.260 +	*/
   1.261 +	TInt iFromChannels;
   1.262 +	/*
   1.263 +	The number of channels of data in the destination buffer
   1.264 +	*/
   1.265 +	TInt iToChannels;
   1.266 +protected:
   1.267 +	TReal iRatio;
   1.268 +	TInt iFraction;
   1.269 +	TInt iIndex;
   1.270 +	};
   1.271 +
   1.272 +/**
   1.273 +@internalAll
   1.274 +*/
   1.275 +class CMMFStereoToMonoRateConverter : public CMMFChannelAndSampleRateConverter
   1.276 +	{
   1.277 +	public:
   1.278 +		virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer);
   1.279 +		virtual TUint MaxConvertBufferSize(TUint aSrcBufferSize);
   1.280 +
   1.281 +	};
   1.282 +
   1.283 +/**
   1.284 +@internalAll
   1.285 +*/
   1.286 +class CMMFStereoToMonoConverter : public CMMFChannelAndSampleRateConverter
   1.287 +	{
   1.288 +	public:
   1.289 +		virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer);
   1.290 +		virtual TUint MaxConvertBufferSize(TUint aSrcBufferSize);
   1.291 +	};
   1.292 +
   1.293 +/**
   1.294 +@internalAll
   1.295 +*/
   1.296 +class CMMFStereoToStereoRateConverter : public CMMFChannelAndSampleRateConverter
   1.297 +	{
   1.298 +	public:
   1.299 +		virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer);
   1.300 +	};
   1.301 +
   1.302 +/**
   1.303 +@internalAll
   1.304 +*/
   1.305 +class CMMFMonoToMonoRateConverter : public CMMFChannelAndSampleRateConverter
   1.306 +	{
   1.307 +	public:
   1.308 +		virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer);
   1.309 +	};
   1.310 +
   1.311 +/**
   1.312 +@internalAll
   1.313 +*/
   1.314 +class CMMFMonoToStereoConverter : public CMMFChannelAndSampleRateConverter
   1.315 +	{
   1.316 +	public:
   1.317 +		virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer);
   1.318 +		virtual TUint MaxConvertBufferSize(TUint aSrcBufferSize);
   1.319 +	};
   1.320 +
   1.321 +/**
   1.322 +@internalAll
   1.323 +*/
   1.324 +class CMMFMonoToStereoRateConverter : public CMMFChannelAndSampleRateConverter
   1.325 +	{
   1.326 +	public:
   1.327 +		virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer);
   1.328 +		virtual TUint MaxConvertBufferSize(TUint aSrcBufferSize);
   1.329 +	};
   1.330 +
   1.331 +/**
   1.332 +@internalAll
   1.333 +
   1.334 +Factory class to create the appropriate CMMFChannelAndSampleRateConverter-derived
   1.335 +class depending on the supplied number of channels and bit rate
   1.336 +*/
   1.337 +class CMMFChannelAndSampleRateConverterFactory : public CBase
   1.338 +	{
   1.339 +
   1.340 +public:
   1.341 +	IMPORT_C CMMFChannelAndSampleRateConverter* CreateConverterL(TInt aFromRate,TInt aFromChannels,
   1.342 +												 TInt aToRate,TInt aToChannels);
   1.343 +	IMPORT_C CMMFChannelAndSampleRateConverter* CreateConverterL();
   1.344 +	CMMFChannelAndSampleRateConverter* Converter() {return iConverter;}
   1.345 +	IMPORT_C ~CMMFChannelAndSampleRateConverterFactory();
   1.346 +	TInt Rate() {return iToRate;}
   1.347 +	TInt Channels() {return iToChannels;}
   1.348 +public:
   1.349 +	/**
   1.350 +	The sample rate of the data in the source buffer
   1.351 +	*/
   1.352 +	TInt iFromRate;
   1.353 +	/**
   1.354 +	The sample rate of the data in the destination buffer
   1.355 +	*/
   1.356 +	TInt iToRate;
   1.357 +	/**
   1.358 +	The number of channels of data in the source buffer
   1.359 +	*/
   1.360 +	TInt iFromChannels;
   1.361 +	/**
   1.362 +	The number of channels of data in the destination buffer
   1.363 +	*/
   1.364 +	TInt iToChannels;
   1.365 +private:
   1.366 +	CMMFChannelAndSampleRateConverter* iConverter;
   1.367 +	};
   1.368 +
   1.369 +#include <mmf/common/mmfutilities.inl>
   1.370 +
   1.371 +#endif