os/mm/devsound/devsoundrefplugin/src/sounddevice/DevSoundUtility.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Class that provides API to list ECOM plugin implementation IDs
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32std.h>
sl@0
    19
#include <barsc.h>
sl@0
    20
#include <barsread.h>
sl@0
    21
#include <mmfbase.h>
sl@0
    22
#include <mmfplugininterfaceuids.hrh>
sl@0
    23
#include <fixedsequence.rsg>
sl@0
    24
#include "DevSoundUtility.h"
sl@0
    25
#include <mmf/common/mmfcontroller.h> //needed for CleanupResetAndDestroyPushL()
sl@0
    26
#include <mm/mmpluginutils.h>
sl@0
    27
#ifdef SYMBIAN_MULTIMEDIA_CODEC_API
sl@0
    28
#include <mdf/codecapiresolverutils.h>
sl@0
    29
#include <mdf/codecapiresolverdata.h>
sl@0
    30
#include <mdf/codecapiuids.hrh>
sl@0
    31
#include <mdf/codecapiresolver.hrh>
sl@0
    32
#endif // SYMBIAN_MULTIMEDIA_CODEC_API
sl@0
    33
sl@0
    34
_LIT(KFixedSequenceResourceFile, "Z:\\Resource\\DevSound\\FixedSequence.rsc"); 
sl@0
    35
const TInt KFourCCStringLength = 9;
sl@0
    36
sl@0
    37
inline TMMFRawPackage::TMMFRawPackage(TInt aDerivedSize)
sl@0
    38
#pragma warning( disable : 4355 )	// 'this' : used in base member initializer list
sl@0
    39
: iThis((TUint8*)this,aDerivedSize,aDerivedSize) 
sl@0
    40
#pragma warning( default : 4355 )
sl@0
    41
	{ 
sl@0
    42
	}
sl@0
    43
sl@0
    44
inline TPtr8& TMMFRawPackage::Package()
sl@0
    45
	{ 
sl@0
    46
	((TMMFRawPackage*)this)->iThis.Set((TUint8*)this,iThis.Length(),iThis.MaxLength()); 
sl@0
    47
	return iThis; 
sl@0
    48
	}
sl@0
    49
sl@0
    50
inline const TPtr8& TMMFRawPackage::Package() const
sl@0
    51
	{ 
sl@0
    52
	((TMMFRawPackage*)this)->iThis.Set((TUint8*)this,iThis.Length(),iThis.MaxLength()); 
sl@0
    53
	return iThis; 
sl@0
    54
	}
sl@0
    55
sl@0
    56
inline void TMMFRawPackage::SetSize(TInt aDerivedSize)
sl@0
    57
	{ 
sl@0
    58
	iThis.Set((TUint8*)this,aDerivedSize,aDerivedSize);
sl@0
    59
	}
sl@0
    60
sl@0
    61
inline TMMFToneFixedSequenceNames::TMMFToneFixedSequenceNames() :
sl@0
    62
TMMFRawPackage(sizeof(TMMFToneFixedSequenceNames)) {}
sl@0
    63
sl@0
    64
#ifdef _UNICODE
sl@0
    65
class TNameBuf : public TBufCBase16
sl@0
    66
#else
sl@0
    67
class TNameBuf : public TBufCBase8
sl@0
    68
#endif
sl@0
    69
	{
sl@0
    70
	friend class HMMFToneFixedSequenceNames;
sl@0
    71
	};
sl@0
    72
sl@0
    73
HMMFToneFixedSequenceNames::HMMFToneFixedSequenceNames()
sl@0
    74
	{
sl@0
    75
	iCount = 0;
sl@0
    76
	}
sl@0
    77
sl@0
    78
HMMFToneFixedSequenceNames* HMMFToneFixedSequenceNames::AddNameL(const TDesC& aName)
sl@0
    79
// Append a copy of the supplied descriptor to the end of the 
sl@0
    80
// current heap cell. This will involve a realloc that will normally
sl@0
    81
// result in the object moving
sl@0
    82
	{
sl@0
    83
	TInt size = Package().Length();
sl@0
    84
	TInt desSize = aName.Size() + sizeof(TInt);
sl@0
    85
	if (desSize&3) 
sl@0
    86
		desSize = ((desSize+4)&(~3)); // Must round up to word boundary to keep aligned
sl@0
    87
	HMMFToneFixedSequenceNames* self = REINTERPRET_CAST(HMMFToneFixedSequenceNames*,User::ReAllocL(STATIC_CAST(TAny*,this),size + desSize));
sl@0
    88
	TUint8* newDesPtr = REINTERPRET_CAST(TUint8*,self) + size;
sl@0
    89
	Mem::FillZ(newDesPtr,desSize);
sl@0
    90
	TNameBuf* newDes = REINTERPRET_CAST(TNameBuf*,newDesPtr);
sl@0
    91
	newDes->Copy(aName,aName.Length());
sl@0
    92
	self->SetSize(size+desSize);
sl@0
    93
	self->iCount++;
sl@0
    94
	return self;
sl@0
    95
	}
sl@0
    96
sl@0
    97
sl@0
    98
/******************************************************************
sl@0
    99
 *				CMMFDevSoundUtility
sl@0
   100
 ******************************************************************/
sl@0
   101
CMMFDevSoundUtility::CMMFDevSoundUtility()
sl@0
   102
	{
sl@0
   103
	// No default implementation
sl@0
   104
	}
sl@0
   105
sl@0
   106
sl@0
   107
CMMFDevSoundUtility::~CMMFDevSoundUtility()
sl@0
   108
	{
sl@0
   109
	delete iInfo;
sl@0
   110
	delete iFixedSequenceNames;
sl@0
   111
	}
sl@0
   112
sl@0
   113
CMMFDevSoundUtility* CMMFDevSoundUtility::NewL()
sl@0
   114
	{
sl@0
   115
	CMMFDevSoundUtility* self = NewLC();
sl@0
   116
	CleanupStack::Pop();
sl@0
   117
	return self;
sl@0
   118
	}
sl@0
   119
sl@0
   120
CMMFDevSoundUtility* CMMFDevSoundUtility::NewLC()
sl@0
   121
	{
sl@0
   122
	CMMFDevSoundUtility* self = new(ELeave) CMMFDevSoundUtility();
sl@0
   123
	CleanupStack::PushL(self);
sl@0
   124
	self->ConstructL();
sl@0
   125
	// Leave it on Cleanupstack
sl@0
   126
	return self;
sl@0
   127
	}
sl@0
   128
sl@0
   129
void CMMFDevSoundUtility::ConstructL()
sl@0
   130
	{
sl@0
   131
	iFixedSequenceNames = new (ELeave) HMMFToneFixedSequenceNames;
sl@0
   132
	}
sl@0
   133
sl@0
   134
void CMMFDevSoundUtility::SeekUsingFourCCL(TUid aInterfaceUid, RImplInfoPtrArray& aPlugInArray, const TFourCC& aSrcDataType, const TFourCC& aDstDataType, const TDesC& aPreferredSupplier)
sl@0
   135
	{
sl@0
   136
sl@0
   137
	// Create a match string using the two FourCC codes.
sl@0
   138
	_LIT8(KEmptyFourCCString, "    ,    ");
sl@0
   139
	TBufC8<KFourCCStringLength> fourCCString(KEmptyFourCCString);
sl@0
   140
	TPtr8 fourCCPtr = fourCCString.Des();
sl@0
   141
	TPtr8 fourCCPtr1(&fourCCPtr[0], 4);
sl@0
   142
	TPtr8 fourCCPtr2(&fourCCPtr[5], 4 );
sl@0
   143
	aSrcDataType.FourCC(&fourCCPtr1);
sl@0
   144
	aDstDataType.FourCC(&fourCCPtr2);
sl@0
   145
sl@0
   146
	MmPluginUtils::FindImplementationsL(aInterfaceUid, aPlugInArray, fourCCPtr);
sl@0
   147
sl@0
   148
	// If more than one match.  Narrow the search by preferred supplier
sl@0
   149
	if((aPlugInArray.Count() > 1) && aPreferredSupplier.Length())
sl@0
   150
		{
sl@0
   151
		SelectByPreference( aPlugInArray, aPreferredSupplier );
sl@0
   152
		}		
sl@0
   153
sl@0
   154
	// If there are no plugins, return failure
sl@0
   155
	if(aPlugInArray.Count() == 0)
sl@0
   156
		{
sl@0
   157
		User::Leave( KErrNotFound );
sl@0
   158
		}	
sl@0
   159
	}
sl@0
   160
	
sl@0
   161
	
sl@0
   162
#ifdef SYMBIAN_MULTIMEDIA_CODEC_API
sl@0
   163
void CMMFDevSoundUtility::FindHwDeviceAdapterL(TUid aInterfaceUid, RImplInfoPtrArray& aPlugInArray)
sl@0
   164
	{
sl@0
   165
	// Create a match string using the two FourCC codes.
sl@0
   166
	_LIT8(KAdapterMatch, "*");
sl@0
   167
sl@0
   168
	MmPluginUtils::FindImplementationsL(aInterfaceUid, aPlugInArray, KAdapterMatch);
sl@0
   169
sl@0
   170
	// If there are no plugins, return failure
sl@0
   171
sl@0
   172
	if(aPlugInArray.Count() == 0)
sl@0
   173
		{
sl@0
   174
		User::Leave( KErrNotFound );
sl@0
   175
		}		
sl@0
   176
	}
sl@0
   177
	
sl@0
   178
void CMMFDevSoundUtility::SeekCodecPluginsL(RArray<TFourCC>& aSupportedDataTypes, TMMFState aState, TBool aAppend)	
sl@0
   179
	{
sl@0
   180
	_LIT8(KPCM16FourCCString, " P16");
sl@0
   181
	//check argument precondition for aState
sl@0
   182
	if ((aState != EMMFStatePlaying) && (aState != EMMFStateRecording))
sl@0
   183
		{
sl@0
   184
		User::Leave(KErrArgument);		
sl@0
   185
		}		
sl@0
   186
sl@0
   187
	if (!aAppend)
sl@0
   188
		{
sl@0
   189
		aSupportedDataTypes.Reset(); //clear any existing data in aSupportedDataTypes array if not appending
sl@0
   190
		}
sl@0
   191
	
sl@0
   192
	CCodecApiResolverData* customMatchData = CCodecApiResolverData::NewLC();
sl@0
   193
	if (aState == EMMFStatePlaying)
sl@0
   194
		{
sl@0
   195
		customMatchData->SetMatchType(EMatchOutputDataFormat);
sl@0
   196
		customMatchData->SetOutputDataL(KPCM16FourCCString);
sl@0
   197
		}
sl@0
   198
	else
sl@0
   199
		{
sl@0
   200
		customMatchData->SetMatchType(EMatchInputDataFormat);
sl@0
   201
		customMatchData->SetInputDataL(KPCM16FourCCString);
sl@0
   202
		}
sl@0
   203
sl@0
   204
	customMatchData->SetImplementationType(TUid::Uid(KUidAudioCodec));
sl@0
   205
	
sl@0
   206
	HBufC8* package = customMatchData->NewPackLC();	
sl@0
   207
	
sl@0
   208
	RImplInfoPtrArray ecomArray;
sl@0
   209
	CleanupResetAndDestroyPushL(ecomArray);
sl@0
   210
sl@0
   211
	TInt err = KErrNone;
sl@0
   212
	MmPluginUtils::FindImplementationsL(TUid::Uid(KUidMdfProcessingUnit), ecomArray, *package, TUid::Uid(KUidCodecApiResolverImplementation));
sl@0
   213
sl@0
   214
	for (TInt i=0 ; i < ecomArray.Count() ; i++)
sl@0
   215
		{
sl@0
   216
		CCodecApiOpaqueData* data = NULL;
sl@0
   217
		TRAP(err, data =  CCodecApiOpaqueData::NewL(ecomArray[i]->OpaqueData()));
sl@0
   218
		// simply ignore plugins that we can't parse the opaque data. They should not cause other plugins
sl@0
   219
		// to fall over
sl@0
   220
		if (err == KErrNone)
sl@0
   221
			{
sl@0
   222
			const TDesC8* dataType;
sl@0
   223
			if (aState == EMMFStatePlaying)
sl@0
   224
				{
sl@0
   225
				dataType = &data->InputDataType();	
sl@0
   226
				}
sl@0
   227
			else
sl@0
   228
				{
sl@0
   229
				dataType = &data->OutputDataType();	
sl@0
   230
				}
sl@0
   231
			TFourCC fourCC(*dataType);
sl@0
   232
			delete data;
sl@0
   233
			aSupportedDataTypes.AppendL(fourCC);
sl@0
   234
			}		
sl@0
   235
		}
sl@0
   236
	CleanupStack::PopAndDestroy(3, customMatchData);
sl@0
   237
	}
sl@0
   238
#endif // SYMBIAN_MULTIMEDIA_CODEC_API
sl@0
   239
sl@0
   240
/*
sl@0
   241
 * local function to disable items which do not match the preferred supplier.
sl@0
   242
 * Note that at least one enabled item is returned (if there was an enabled item to begin with) which
sl@0
   243
 * may not match the preferred supplier.
sl@0
   244
 * 
sl@0
   245
 */
sl@0
   246
void CMMFDevSoundUtility::SelectByPreference( RImplInfoPtrArray& aPlugInArray, const TDesC& aPreferredSupplier ) 
sl@0
   247
	{
sl@0
   248
sl@0
   249
	// Use the Disabled flag to eliminated all currently enabled matches that
sl@0
   250
	// do not match the preferred supplier.
sl@0
   251
	TInt firstEnabled = -1 ; // to ensure that we return something valid
sl@0
   252
	TInt matchCount = 0 ;
sl@0
   253
	for ( TInt ii = 0 ; ii < aPlugInArray.Count() ; ii++ )
sl@0
   254
		{
sl@0
   255
		if ( !( aPlugInArray[ii]->Disabled() ) )
sl@0
   256
			{
sl@0
   257
			if ( firstEnabled == -1 )
sl@0
   258
				firstEnabled = ii ;
sl@0
   259
			if ( aPlugInArray[ii]->DisplayName().FindF( aPreferredSupplier ) == KErrNotFound )
sl@0
   260
				aPlugInArray[ii]->SetDisabled( ETrue ) ;
sl@0
   261
			else
sl@0
   262
				matchCount++ ;
sl@0
   263
			}
sl@0
   264
		}
sl@0
   265
sl@0
   266
	// If there are no matches then re-enable the first enabled
sl@0
   267
	if ( matchCount == 0 )
sl@0
   268
		aPlugInArray[firstEnabled]->SetDisabled( EFalse ) ;
sl@0
   269
	else if ( matchCount > 1 )
sl@0
   270
		{
sl@0
   271
		// find the latest version from more than one match
sl@0
   272
		TInt highestVersionIndex = -1 ;
sl@0
   273
		for ( TInt ii = 0 ; ii < aPlugInArray.Count() ; ii++ )
sl@0
   274
			{
sl@0
   275
			if ( !( aPlugInArray[ii]->Disabled() ) )  // only interested in enabled elements
sl@0
   276
				{
sl@0
   277
				if ( highestVersionIndex == -1 )
sl@0
   278
					{ // first match.  Store this.  Keep it enabled
sl@0
   279
					highestVersionIndex = ii ;
sl@0
   280
					}
sl@0
   281
				else if ( aPlugInArray[ii]->Version() > aPlugInArray[highestVersionIndex]->Version() )
sl@0
   282
					{ // a new leader.  Disable the previous leader.  Keep this one.
sl@0
   283
					aPlugInArray[highestVersionIndex]->SetDisabled( ETrue ) ;
sl@0
   284
					highestVersionIndex = ii ;
sl@0
   285
					}
sl@0
   286
				else  // we already have a higher version.
sl@0
   287
					aPlugInArray[ii]->SetDisabled( ETrue ) ;
sl@0
   288
				}
sl@0
   289
			}
sl@0
   290
		}
sl@0
   291
	}
sl@0
   292
sl@0
   293
sl@0
   294
/*
sl@0
   295
 *  SeekHwDevicePluginsL
sl@0
   296
 *  This method looks for hwDevicePlugins that support the state given in aState which
sl@0
   297
 *  must be either EMMFStatePlaying or EMMFStateRecording
sl@0
   298
 *  For each HwDevice plugin found the datatype as indicated by its fourCC code
sl@0
   299
 *  from the default_data field in the resource file is added to the array of aSupportedDataTypes
sl@0
   300
 *
sl@0
   301
 *  @internalComponent
sl@0
   302
 *
sl@0
   303
 *	@param	"RArray<TFourCC>& aSupportedDataTypes"
sl@0
   304
 *  an array of fourCC codes that has a fourCC code added to for each hardware device found
sl@0
   305
 *
sl@0
   306
 *	@param  "TMMFState aState"
sl@0
   307
 *  must be set to EMMFStatePlaying if seeking HwDevice plugins that support play and
sl@0
   308
 *  EMMFStateRecording if seeking HwDevice plugins that support record
sl@0
   309
 *	
sl@0
   310
 *  @leave KErrArgument if aState is not EMMFStatePlaying or EMMFStateRecording else leaves
sl@0
   311
 *  with standard symbian OS error code
sl@0
   312
 */
sl@0
   313
void CMMFDevSoundUtility::SeekHwDevicePluginsL(RArray<TFourCC>& aSupportedDataTypes, TMMFState aState)
sl@0
   314
	{	
sl@0
   315
	//check argument precondition for aState
sl@0
   316
	if ((aState != EMMFStatePlaying) && (aState != EMMFStateRecording))
sl@0
   317
		{
sl@0
   318
		User::Leave(KErrArgument);
sl@0
   319
		}
sl@0
   320
sl@0
   321
	aSupportedDataTypes.Reset(); //clear any existing data in aSupportedDataTypes array
sl@0
   322
sl@0
   323
	RImplInfoPtrArray plugInArray ; // Array to return hw device plugin resource info
sl@0
   324
	CleanupResetAndDestroyPushL(plugInArray);
sl@0
   325
sl@0
   326
	TUid KUidMmfHWPluginInterfaceCodec = {KMmfUidPluginInterfaceHwDevice};
sl@0
   327
sl@0
   328
	MmPluginUtils::FindImplementationsL(KUidMmfHWPluginInterfaceCodec, plugInArray);
sl@0
   329
sl@0
   330
	TUint numberOfHwDevicePlugins = plugInArray.Count();
sl@0
   331
sl@0
   332
	//if have hwdevice plugin resource entries then scan entries
sl@0
   333
	//matching on a datatype of pcm16 as the destination datatype for play and the 
sl@0
   334
	//source datatype for record
sl@0
   335
	//if a match is found and isn't already in list of supported data types
sl@0
   336
	//then add it to the list
sl@0
   337
	if (numberOfHwDevicePlugins)
sl@0
   338
		{					
sl@0
   339
		CImplementationInformation* hwDeviceResourceEntry = NULL;
sl@0
   340
		_LIT8(KPCM16FourCCString, " P16");
sl@0
   341
		TBufC8<KFourCCLength> fourCCStringPCM16(KPCM16FourCCString);
sl@0
   342
		TPtr8 fourCCPtrPCM16 = fourCCStringPCM16.Des();
sl@0
   343
		TUint entryNumber = 0;
sl@0
   344
sl@0
   345
		//check each resource entry for dst 4CC = P16 for play and src 4CC = P16 for record
sl@0
   346
		for (TUint hwDeviceEntry = 0; hwDeviceEntry < numberOfHwDevicePlugins; hwDeviceEntry++)
sl@0
   347
			{
sl@0
   348
			hwDeviceResourceEntry = plugInArray[hwDeviceEntry];
sl@0
   349
			if (IsDataTypeMatch(hwDeviceResourceEntry, fourCCPtrPCM16, aState))
sl@0
   350
				{//resource entry data field has dest/src datatype ' P16' ie pcm16 for play/record
sl@0
   351
				TPtrC8 fourCCPtr(0,0);
sl@0
   352
				if (aState == EMMFStatePlaying)//then datatype supported 4CC is left 4 chars
sl@0
   353
					{
sl@0
   354
					fourCCPtr.Set(hwDeviceResourceEntry->DataType().Left(KFourCCLength));
sl@0
   355
					}
sl@0
   356
				else if (aState == EMMFStateRecording) //then datatype supported 4CC is right 4 chars
sl@0
   357
					{
sl@0
   358
					fourCCPtr.Set(hwDeviceResourceEntry->DataType().Right(KFourCCLength));
sl@0
   359
					}
sl@0
   360
				TFourCC fourCCEntry(fourCCPtr);
sl@0
   361
				//need to check if entry already exists to prevent duplicate entries
sl@0
   362
				entryNumber = aSupportedDataTypes.Count();
sl@0
   363
				TBool alreadyExists = EFalse;
sl@0
   364
				for (TUint fourCCEntryNumber = 0; fourCCEntryNumber < entryNumber; fourCCEntryNumber++)
sl@0
   365
					{
sl@0
   366
					if (aSupportedDataTypes[fourCCEntryNumber]==fourCCEntry)
sl@0
   367
						{
sl@0
   368
						alreadyExists = ETrue;//we already have this 4CC in the supported data types
sl@0
   369
						break;
sl@0
   370
						}
sl@0
   371
					}
sl@0
   372
				if (!alreadyExists)
sl@0
   373
					{
sl@0
   374
					TInt err = aSupportedDataTypes.Append(fourCCEntry);
sl@0
   375
					if (err)
sl@0
   376
						{//note we don't destroy array because we don't own it
sl@0
   377
						//but we do reset it as it is incomplete
sl@0
   378
						aSupportedDataTypes.Reset();
sl@0
   379
						User::Leave(err);
sl@0
   380
						}
sl@0
   381
					}
sl@0
   382
				}//if (IsDataTypeMatch(hwDeviceResourceEntry, fourCCPtrPCM16, aState))
sl@0
   383
			}//for (TUint hwDeviceEntry = 0; hwDeviceEntry < numberOfHwDevicePlugins; hwDeviceEntry++)
sl@0
   384
		}//if (numberOfHwDevicePlugins)
sl@0
   385
sl@0
   386
	CleanupStack::PopAndDestroy(&plugInArray);
sl@0
   387
	}
sl@0
   388
sl@0
   389
sl@0
   390
/*
sl@0
   391
 *	IsDataTypeMatch
sl@0
   392
 *  This method takes a given resource entry from a hardware device and determines 
sl@0
   393
 *  whether the hwdevice plugin is a data type match for playing or recording
sl@0
   394
 *  depending on the setting of aState
sl@0
   395
 *  The method matchs the default_data field from the hw device resource entry matching
sl@0
   396
 *  it with the aHwMatchFourCC code.
sl@0
   397
 *
sl@0
   398
 *  @internalComponent
sl@0
   399
 *
sl@0
   400
 *	@param	"CImplementationInformation aHwDeviceResourceEntry"
sl@0
   401
 *  the hw device resource entry that is to be checked 
sl@0
   402
 *  whether it can be used to play or record
sl@0
   403
 *
sl@0
   404
 *	@param  "TDesC8& aHwMatchFourCC
sl@0
   405
 *	the data type fourCC code to match to that the hardware device that must convert to for
sl@0
   406
 *	playing and convert from for recording - for the reference DevSound this is always ' P16' ie pcm16
sl@0
   407
 *
sl@0
   408
 *  @param "TMMFState aState"
sl@0
   409
 *  this determines whether the match is for playing or recording and should take 
sl@0
   410
 *  either the values EMMFStatePlaying or EMMFStateRecording
sl@0
   411
 *
sl@0
   412
 *  @return ETrue if a match for play or record else EFalse
sl@0
   413
 */
sl@0
   414
TBool CMMFDevSoundUtility::IsDataTypeMatch(CImplementationInformation* aHwDeviceResourceEntry,const TDesC8& aHwMatchFourCC, TMMFState aState)
sl@0
   415
	{
sl@0
   416
	TBool match = EFalse;
sl@0
   417
	// extra length safety check to remove adapter plugins and incorrect ones
sl@0
   418
	if (aHwDeviceResourceEntry->DataType().Length()>=KFourCCStringLength)
sl@0
   419
		{
sl@0
   420
		if (aState == EMMFStatePlaying)
sl@0
   421
			{//play need to match with the right four characters
sl@0
   422
			match =  (!(aHwMatchFourCC.Match(aHwDeviceResourceEntry->DataType().Right(KFourCCLength))==KErrNotFound));
sl@0
   423
			}
sl@0
   424
		else if (aState == EMMFStateRecording)
sl@0
   425
			{//record need to match with the left four characters
sl@0
   426
			match = (!(aHwMatchFourCC.Match(aHwDeviceResourceEntry->DataType().Left(KFourCCLength))==KErrNotFound));
sl@0
   427
			}
sl@0
   428
		}
sl@0
   429
	return match;
sl@0
   430
	}
sl@0
   431
sl@0
   432
sl@0
   433
/**
sl@0
   434
 *	Populate fixed sequences
sl@0
   435
 *
sl@0
   436
 */
sl@0
   437
void CMMFDevSoundUtility::InitializeFixedSequenceL(CPtrC8Array** aFixedSequences)
sl@0
   438
	{
sl@0
   439
sl@0
   440
	RFs fsSession;
sl@0
   441
	User::LeaveIfError(fsSession.Connect());
sl@0
   442
	CleanupClosePushL(fsSession);
sl@0
   443
sl@0
   444
	// Open the resource file
sl@0
   445
	RResourceFile resourceFile;
sl@0
   446
	resourceFile.OpenL(fsSession, KFixedSequenceResourceFile);
sl@0
   447
	CleanupClosePushL(resourceFile);
sl@0
   448
sl@0
   449
	// Allocate buffer to hold resource data in binary format
sl@0
   450
	iInfo = resourceFile.AllocReadL(FIXED_TONE_SEQUENCE);
sl@0
   451
sl@0
   452
	TResourceReader reader;
sl@0
   453
	reader.SetBuffer(iInfo);
sl@0
   454
sl@0
   455
	// Create array to hold fixed sequences data
sl@0
   456
	CPtrC8Array* tempSequences = new(ELeave) CPtrC8Array(8); //  granularity
sl@0
   457
	CleanupStack::PushL(tempSequences);
sl@0
   458
sl@0
   459
	// First word gives number of entries
sl@0
   460
	TInt numberOfEntries = reader.ReadUint16(); 
sl@0
   461
	ASSERT(!(numberOfEntries&1)); // Should have atleast one entry
sl@0
   462
sl@0
   463
	// There must be an even number entries as each sequence structure
sl@0
   464
	// is made of a name string and a data string (SEQUENCE_NAME and SEQUENCE_DATA)
sl@0
   465
sl@0
   466
	HMMFToneFixedSequenceNames* names = new (ELeave) HMMFToneFixedSequenceNames;
sl@0
   467
	CleanupStack::PushL(names);
sl@0
   468
	for (TInt i=0;i<numberOfEntries;i+=2)
sl@0
   469
		{
sl@0
   470
		// Copy name from resource array to returnable array
sl@0
   471
		HMMFToneFixedSequenceNames* newNames = names->AddNameL(reader.ReadTPtrC());
sl@0
   472
		if (names != newNames)
sl@0
   473
			{ // May have moved so fixup cleanupstack reference
sl@0
   474
			CleanupStack::Pop();
sl@0
   475
			names = newNames;
sl@0
   476
			CleanupStack::PushL(names);
sl@0
   477
			}
sl@0
   478
		TInt len = reader.ReadUint16();
sl@0
   479
		TPtrC8 tempTPtrC8(REINTERPRET_CAST(const TUint8*,reader.Ptr()),len<<1);
sl@0
   480
		tempSequences->AppendL(tempTPtrC8);
sl@0
   481
		reader.Advance(len<<1);
sl@0
   482
		}
sl@0
   483
	CleanupStack::Pop(); // names
sl@0
   484
sl@0
   485
	// Delete the old fixed sequence names
sl@0
   486
	delete iFixedSequenceNames;
sl@0
   487
	iFixedSequenceNames = NULL;
sl@0
   488
	iFixedSequenceNames = names;
sl@0
   489
sl@0
   490
	*aFixedSequences = tempSequences;
sl@0
   491
	CleanupStack::Pop(tempSequences);
sl@0
   492
	CleanupStack::PopAndDestroy(2);	// resourceFile, fsSession
sl@0
   493
	}
sl@0
   494
sl@0
   495
TBool CMMFDevSoundUtility::RecognizeSequence(const TDesC8& aData)
sl@0
   496
	{
sl@0
   497
	// Reference plug-in only supports its own sequence format
sl@0
   498
	_LIT8(KSequenceSignature,"SQNC");
sl@0
   499
	if (aData.Length() > 4)
sl@0
   500
		{
sl@0
   501
		if (aData.Left(4) == KSequenceSignature)
sl@0
   502
			return ETrue;
sl@0
   503
		}
sl@0
   504
	// Didn't recognise
sl@0
   505
	return EFalse;
sl@0
   506
	}
sl@0
   507
sl@0
   508
const TDesC& CMMFDevSoundUtility::FixedSequenceName(TInt aSequenceNumber)
sl@0
   509
	{
sl@0
   510
	ASSERT(iFixedSequenceNames); // Defect if this not true when previous was true
sl@0
   511
	ASSERT((aSequenceNumber>=0)&&(aSequenceNumber<iFixedSequenceNames->iCount));
sl@0
   512
sl@0
   513
	// Ptr to first descriptor
sl@0
   514
	TUint8* ptr = REINTERPRET_CAST(TUint8*,&(iFixedSequenceNames->iCount))+sizeof(TInt);
sl@0
   515
	TDesC* desPtr = REINTERPRET_CAST(TDesC*,ptr); // First des
sl@0
   516
	while (aSequenceNumber--)
sl@0
   517
		{
sl@0
   518
		TInt size = desPtr->Size();
sl@0
   519
		if (size&3)
sl@0
   520
			size = ((size+4)&(~3));
sl@0
   521
		ptr += sizeof(TInt) + size;
sl@0
   522
		desPtr = REINTERPRET_CAST(TDesC*,ptr); // Next des
sl@0
   523
		}
sl@0
   524
	return *desPtr;
sl@0
   525
	}