epoc32/include/mmf/common/mmfutilities.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
equal deleted inserted replaced
1:666f914201fb 2:2fe1408b6811
     1 mmfutilities.h
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // 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
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // include\mmf\common\mmfutilities.h
       
    15 // 
       
    16 //
       
    17 
       
    18 #ifndef __MMF_COMMON_UTILITIES_H__
       
    19 #define __MMF_COMMON_UTILITIES_H__
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <mmf/server/mmfdatabuffer.h>
       
    23 #include <mmf/common/mmffourcc.h>
       
    24 
       
    25 
       
    26 /** 
       
    27 @publishedAll
       
    28 @released
       
    29 
       
    30 Identifies the particular stream of the given media type.
       
    31 */
       
    32 class TMediaId
       
    33 	{
       
    34 public:
       
    35 
       
    36 	/**
       
    37 	Constructs the class with the supplied arguments.
       
    38 
       
    39 	This constructor is used when there are multiple streams of the same media type on the same
       
    40 	MDataSource.
       
    41 
       
    42 	@param  aMediaType
       
    43 	        The media type (video, audio etc.).
       
    44 	@param  aStreamId
       
    45 	        Identifies a specific stream when there are multiple streams of the same media type on 
       
    46 	        the same MDataSource.
       
    47 	*/
       
    48 	TMediaId(TUid aMediaType, TUint aStreamId);
       
    49 
       
    50 	/**
       
    51     Constructs the class with the supplied argument.
       
    52 
       
    53 	This constructor is used when there is a single stream of the same media type on the same
       
    54 	MDataSource.
       
    55 
       
    56 	@param  aMediaType
       
    57 	        The media type (video, audio etc.).
       
    58 	*/
       
    59 	TMediaId(TUid aMediaType);
       
    60 
       
    61 	/**
       
    62 	Default constructor.
       
    63 	*/
       
    64 	TMediaId();
       
    65 public:
       
    66 	/**
       
    67 	The media type (KUidMediaTypeAudio, KUidMediaTypeVideo, etc).
       
    68 	*/
       
    69 	TUid iMediaType;
       
    70 
       
    71 	/**
       
    72 	Identifies a particular media stream used in case where multiple streams
       
    73 	of the same media type are present on the same MDataSource.
       
    74 	*/
       
    75 	TUint iStreamId;
       
    76 private:
       
    77 	/**
       
    78 	This member is internal and not intended for use.
       
    79 	*/
       
    80 	TInt iReserved1;
       
    81 	TInt iReserved2;
       
    82 	TInt iReserved3;
       
    83 	};
       
    84 
       
    85 /**
       
    86 @publishedAll
       
    87 @released
       
    88 
       
    89 The FourCC code that represents NULL.
       
    90 */
       
    91 const TInt KFourCCNULL = KMMFFourCCCodeNULL;
       
    92 
       
    93 /**
       
    94 @publishedAll
       
    95 @released
       
    96 
       
    97 A class that holds a four character code, representing supported data encodings for the
       
    98 conversion destination. The four character codes are packed into a single TUint32.
       
    99 
       
   100 FourCC codes are a representation of the datatypes used to identify codecs. FourCC codes are used in 
       
   101 codec .rss files as a match string used by ECOM to correctly load the required DLL.
       
   102 */
       
   103 class TFourCC
       
   104 {
       
   105 public:
       
   106 
       
   107 	/**
       
   108 	Default constructor initialises the class to KMMFFourCCCodeNULL.
       
   109 	*/
       
   110 	TFourCC() {iFourCC = KMMFFourCCCodeNULL;} //'NULL'
       
   111 
       
   112 	/**
       
   113 	Packs the four arguments into a single TUint32.
       
   114 
       
   115 	The four arguments are packed in little-endian format.
       
   116 
       
   117 	@param  aChar1
       
   118 	        A character that represents part of the FourCC code. This character will be the least 
       
   119 	        significant byte of the code.
       
   120 	@param  aChar2
       
   121             A character that represents part of the FourCC code.
       
   122 	@param  aChar3
       
   123             A character that represents part of the FourCC code.
       
   124 	@param  aChar4
       
   125 	        A character that represents part of the FourCC code. This character will be the most 
       
   126 	        significant byte of the code.
       
   127 	*/
       
   128 	TFourCC(TUint8 aChar1, TUint8 aChar2, TUint8 aChar3, TUint8 aChar4) {iFourCC =(aChar4<<24)+(aChar3<<16)+(aChar2<<8)+aChar1;}
       
   129 
       
   130 	/**
       
   131 	Constructs a FourCC code with the given 8 bit desciptor where the descriptor contains the
       
   132 	characters that make up the FourCC code.
       
   133 
       
   134 	@param  aDes
       
   135 	        The descriptor containing the characters from which to make the FourCC code.
       
   136 	*/
       
   137 	TFourCC(const TDesC8& aDes) {iFourCC =(aDes[3]<<24)+(aDes[2]<<16)+(aDes[1]<<8)+aDes[0];}
       
   138 
       
   139 	/**
       
   140     Constructor with a TInt32 in little-endian format.
       
   141 
       
   142 	@param  aFourCC
       
   143             The FourCC code.
       
   144 	*/
       
   145 	TFourCC(TInt32 aFourCC) {iFourCC = aFourCC;}
       
   146 
       
   147 	/**
       
   148     Returns the FourCC code in little-endian format.
       
   149 
       
   150 	@return The FourCC code in little-endian format.
       
   151 	*/
       
   152 	TUint32 FourCC() {return iFourCC;}
       
   153 	inline void FourCC( TPtr8* aDes ) const ;
       
   154 
       
   155 	/**
       
   156     Sets the FourCC code equal to the value in the supplied argument.
       
   157 
       
   158 	@param  aFourCC
       
   159 	        The required TFourCC containting the FourCC code.
       
   160 	*/
       
   161 	void Set(TFourCC aFourCC) {iFourCC = aFourCC.iFourCC;}
       
   162 
       
   163 	/**
       
   164     Sets the FourCC code equal to the supplied argument.
       
   165 
       
   166 	@param  aFourCC
       
   167 	        The required FourCC code.
       
   168 	*/
       
   169 	void Set(TUint32 aFourCC) {iFourCC = aFourCC;}
       
   170 
       
   171 	/**
       
   172 	Equality operator.
       
   173 
       
   174 	@param  aA
       
   175 	        The TFourCC code that *this will be tested against.
       
   176 
       
   177 	@return A boolean indicating if the two values are equal. ETrue if the two values are equal, 
       
   178 	        otherwise false.
       
   179 	*/
       
   180 	TBool operator==(const TFourCC& aA) const {return (iFourCC == aA.iFourCC);}
       
   181 
       
   182 	/**
       
   183     Equality operator.
       
   184 
       
   185 	@param  aUint
       
   186 	        The FourCC code that *this will be tested against.
       
   187 
       
   188 	@return A boolean indicating if the two values are equal. ETrue if the two values are equal, 
       
   189 	        otherwise false.
       
   190 	*/
       
   191 	TBool operator==(const TUint32& aUint) const {return (iFourCC == aUint);}
       
   192 
       
   193 	/**
       
   194     Inequality operator.
       
   195 
       
   196 	@param  aA
       
   197 	        The TFourCC code that *this will be tested against.
       
   198 	
       
   199 	@return A boolean indicating if the two values are not equal. ETrue if the two values are 
       
   200 	        unequal, otherwise false.
       
   201 	*/
       
   202 	TBool operator!=(const TFourCC& aA) const {return (iFourCC != aA.iFourCC);}
       
   203 
       
   204 	/**
       
   205     Inequality operator.
       
   206 
       
   207 	@param  aUint
       
   208 	        The FourCC code that *this will be tested against.
       
   209 	*/
       
   210 	TBool operator!=(const TUint32& aUint) const {return (iFourCC != aUint);}
       
   211 
       
   212 private:
       
   213 	TUint32 iFourCC;
       
   214 };
       
   215 
       
   216 /**
       
   217 @internalAll
       
   218 
       
   219 Base utility class to change the sample rate of audio data in a buffer
       
   220 */
       
   221 class CMMFChannelAndSampleRateConverter : public CBase
       
   222 	{
       
   223 public:
       
   224 	/**
       
   225 	Reads the audio data from the source buffer,
       
   226 	converts the number of channels and the sample rate
       
   227 	and copies the result to the destination buffer
       
   228 
       
   229 	@param  aSrcBuffer
       
   230 	        A pointer to a source buffer containing the audio data to convert.
       
   231 	@param  aDstBuffer
       
   232 	        A pointer to a destination buffer.
       
   233 
       
   234 	@return The length of the destination buffer.
       
   235 	*/
       
   236 	virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer) =0;
       
   237 	virtual void Reset() {};
       
   238 
       
   239 	/*
       
   240 	Indicates what buffer size is required to hold the converted data.
       
   241 	*/
       
   242 	virtual TUint MaxConvertBufferSize(TUint aSrcBufferSize) {return aSrcBufferSize;}
       
   243 
       
   244 	void SetRates(TInt aSrcRate,TInt aSrcChannels,TInt aDstRate,TInt aDstChannels);
       
   245 public:
       
   246 	/*
       
   247 	The sample rate of the data in the source buffer
       
   248 	*/
       
   249 	TInt iFromRate;
       
   250 	/*
       
   251 	The sample rate of the data in the destination buffer
       
   252 	*/
       
   253 	TInt iToRate;
       
   254 	/*
       
   255 	The number of channels of data in the source buffer
       
   256 	*/
       
   257 	TInt iFromChannels;
       
   258 	/*
       
   259 	The number of channels of data in the destination buffer
       
   260 	*/
       
   261 	TInt iToChannels;
       
   262 protected:
       
   263 	TReal iRatio;
       
   264 	TInt iFraction;
       
   265 	TInt iIndex;
       
   266 	};
       
   267 
       
   268 /**
       
   269 @internalAll
       
   270 */
       
   271 class CMMFStereoToMonoRateConverter : public CMMFChannelAndSampleRateConverter
       
   272 	{
       
   273 	public:
       
   274 		virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer);
       
   275 		virtual TUint MaxConvertBufferSize(TUint aSrcBufferSize);
       
   276 
       
   277 	};
       
   278 
       
   279 /**
       
   280 @internalAll
       
   281 */
       
   282 class CMMFStereoToMonoConverter : public CMMFChannelAndSampleRateConverter
       
   283 	{
       
   284 	public:
       
   285 		virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer);
       
   286 		virtual TUint MaxConvertBufferSize(TUint aSrcBufferSize);
       
   287 	};
       
   288 
       
   289 /**
       
   290 @internalAll
       
   291 */
       
   292 class CMMFStereoToStereoRateConverter : public CMMFChannelAndSampleRateConverter
       
   293 	{
       
   294 	public:
       
   295 		virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer);
       
   296 	};
       
   297 
       
   298 /**
       
   299 @internalAll
       
   300 */
       
   301 class CMMFMonoToMonoRateConverter : public CMMFChannelAndSampleRateConverter
       
   302 	{
       
   303 	public:
       
   304 		virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer);
       
   305 	};
       
   306 
       
   307 /**
       
   308 @internalAll
       
   309 */
       
   310 class CMMFMonoToStereoConverter : public CMMFChannelAndSampleRateConverter
       
   311 	{
       
   312 	public:
       
   313 		virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer);
       
   314 		virtual TUint MaxConvertBufferSize(TUint aSrcBufferSize);
       
   315 	};
       
   316 
       
   317 /**
       
   318 @internalAll
       
   319 */
       
   320 class CMMFMonoToStereoRateConverter : public CMMFChannelAndSampleRateConverter
       
   321 	{
       
   322 	public:
       
   323 		virtual TInt Convert(const CMMFDataBuffer& aSrcBuffer, CMMFDataBuffer& aDstBuffer);
       
   324 		virtual TUint MaxConvertBufferSize(TUint aSrcBufferSize);
       
   325 	};
       
   326 
       
   327 /**
       
   328 @internalAll
       
   329 
       
   330 Factory class to create the appropriate CMMFChannelAndSampleRateConverter-derived
       
   331 class depending on the supplied number of channels and bit rate
       
   332 */
       
   333 class CMMFChannelAndSampleRateConverterFactory : public CBase
       
   334 	{
       
   335 
       
   336 public:
       
   337 	IMPORT_C CMMFChannelAndSampleRateConverter* CreateConverterL(TInt aFromRate,TInt aFromChannels,
       
   338 												 TInt aToRate,TInt aToChannels);
       
   339 	IMPORT_C CMMFChannelAndSampleRateConverter* CreateConverterL();
       
   340 	CMMFChannelAndSampleRateConverter* Converter() {return iConverter;}
       
   341 	IMPORT_C ~CMMFChannelAndSampleRateConverterFactory();
       
   342 	TInt Rate() {return iToRate;}
       
   343 	TInt Channels() {return iToChannels;}
       
   344 public:
       
   345 	/**
       
   346 	The sample rate of the data in the source buffer
       
   347 	*/
       
   348 	TInt iFromRate;
       
   349 	/**
       
   350 	The sample rate of the data in the destination buffer
       
   351 	*/
       
   352 	TInt iToRate;
       
   353 	/**
       
   354 	The number of channels of data in the source buffer
       
   355 	*/
       
   356 	TInt iFromChannels;
       
   357 	/**
       
   358 	The number of channels of data in the destination buffer
       
   359 	*/
       
   360 	TInt iToChannels;
       
   361 private:
       
   362 	CMMFChannelAndSampleRateConverter* iConverter;
       
   363 	};
       
   364 
       
   365 #include <mmf/common/mmfutilities.inl>
       
   366 
       
   367 #endif