mmfenh/progressivedownload/ProgressiveDownloadUtility/src/mmfclientutility.cpp
branchRCL_3
changeset 46 0ac9a5310753
parent 0 71ca22bcf22a
equal deleted inserted replaced
45:095bea5f582e 46:0ac9a5310753
       
     1 /*
       
     2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Progressive Download Utility  Audio, MIDI and Video client utility functions.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <f32file.h>
       
    21 #include <bautils.h>
       
    22 #include <caf/content.h>
       
    23 #include <caf/data.h>
       
    24 using namespace ContentAccess;
       
    25 
       
    26 #include "mmfclientutility.h"
       
    27 #include <mmf/common/mmfpaniccodes.h>
       
    28 
       
    29 const TInt KMaxMimeLength = 256;
       
    30 const TInt KMaxHeaderSize = 256;
       
    31 #ifdef __WINDOWS_MEDIA
       
    32 _LIT8(KWMAMimeType,"audio/x-ms-wma");
       
    33 #endif
       
    34 
       
    35 void CUPanic(TInt aCUPanicCode)
       
    36 	{
       
    37 	_LIT(KMMFMediaClientUtilityPaanicCategory, "MMFClientUtility");
       
    38 	User::Panic(KMMFMediaClientUtilityPaanicCategory, aCUPanicCode);
       
    39 	}
       
    40 
       
    41 /**
       
    42  * @internalComponent
       
    43  */
       
    44  TUid CMMFClientUtility::ConvertMdaFormatUidToECOMWrite(TUid aMdaFormatUid)
       
    45 	{
       
    46     #if _DEBUG
       
    47       RDebug::Print(_L("CMMFClientUtility::ConvertMdaFormatUidToECOMWrite\n"));
       
    48     #endif
       
    49 	TUid ECOMUid = KNullUid;
       
    50 	if (aMdaFormatUid == KUidMdaClipFormatWav)
       
    51 		ECOMUid = TUid::Uid(KMmfUidFormatWAVWrite);
       
    52 	else if (aMdaFormatUid == KUidMdaClipFormatAu)
       
    53 		ECOMUid = TUid::Uid(KMmfUidFormatAUWrite);
       
    54 	else if (aMdaFormatUid == KUidMdaClipFormatRawAudio)
       
    55 		ECOMUid = TUid::Uid(KMmfUidFormatRAWWrite);
       
    56 	else if (aMdaFormatUid == KUidMdaClipFormatRawAmr)
       
    57 		ECOMUid = TUid::Uid(KAdvancedUidFormatAMRWrite);
       
    58 
       
    59 	return ECOMUid;
       
    60 	}
       
    61 
       
    62 /**
       
    63  * @internalComponent
       
    64  */
       
    65  TUid CMMFClientUtility::ConvertMdaFormatUidToECOMRead(TUid aMdaFormatUid)
       
    66 	{
       
    67     #if _DEBUG
       
    68       RDebug::Print(_L("CMMFClientUtility::ConvertMdaFormatUidToECOMRead\n"));
       
    69     #endif
       
    70 	TUid ECOMUid = KNullUid;
       
    71 	if (aMdaFormatUid == KUidMdaClipFormatWav)
       
    72 		ECOMUid = TUid::Uid(KMmfUidFormatWAVRead);
       
    73 	else if (aMdaFormatUid == KUidMdaClipFormatAu)
       
    74 		ECOMUid = TUid::Uid(KMmfUidFormatAURead);
       
    75 	else if (aMdaFormatUid == KUidMdaClipFormatRawAudio)
       
    76 		ECOMUid = TUid::Uid(KMmfUidFormatRAWRead);
       
    77 	else if (aMdaFormatUid == KUidMdaClipFormatRawAmr)
       
    78 		ECOMUid = TUid::Uid(KAdvancedUidFormatAMRRead);
       
    79 
       
    80 	return ECOMUid;
       
    81 	}
       
    82 
       
    83 /**
       
    84  * @internalComponent
       
    85  */
       
    86  TInt CMMFClientUtility::GetFileHeaderData(const TDesC& aFileName, TDes8& aHeaderData, TInt aMaxLength)
       
    87 	{
       
    88     #if _DEBUG
       
    89       RDebug::Print(_L("CMMFClientUtility::GetFileHeaderData***\n"));
       
    90     #endif
       
    91 	RFs fsSession;
       
    92 	RFile file;
       
    93 	TInt error = KErrNone;
       
    94 	TInt size = 0;
       
    95 	if ((error = fsSession.Connect()) == KErrNone)
       
    96 		{
       
    97 		//rj  if ((error = file.Open(fsSession, aFileName, EFileShareReadersOnly)) == KErrNone)
       
    98         if ((error = file.Open(fsSession, aFileName, EFileShareAny)) == KErrNone)
       
    99 			{
       
   100 
       
   101 
       
   102 			if ((error = file.Size(size)) == KErrNone)
       
   103 				{
       
   104 				if (size > 0)
       
   105 					{
       
   106     #if _DEBUG
       
   107       RDebug::Print(_L("CMMFClientUtility::GetFileHeaderData actual size= %d  \n"),size);
       
   108     #endif
       
   109 					if (size > aMaxLength)
       
   110 						size = aMaxLength;
       
   111 
       
   112 					error = file.Read(aHeaderData, size);
       
   113 					}
       
   114 				}
       
   115 			file.Close();
       
   116 			}
       
   117 		fsSession.Close();
       
   118 
       
   119 
       
   120 		}
       
   121 
       
   122 	#if _DEBUG
       
   123       RDebug::Print(_L("CMMFClientUtility::GetFileHeaderData err %d  header %d\n"),error,size);
       
   124     #endif
       
   125 
       
   126 	return error;
       
   127 	}
       
   128 
       
   129 /**
       
   130  * @internalComponent
       
   131  */
       
   132  TFourCC CMMFClientUtility::ConvertMdaCodecToFourCC(TMdaPackage& aCodec)
       
   133 	{
       
   134     #if _DEBUG
       
   135       RDebug::Print(_L("CMMFClientUtility::ConvertMdaCodecToFourCC\n"));
       
   136     #endif
       
   137 	TFourCC dataType = KMMFFourCCCodeNULL;
       
   138 	switch (aCodec.Uid().iUid)
       
   139 		{
       
   140 		case KUidMdaWavPcmCodecDefine:
       
   141 			{
       
   142 			TMdaPcmWavCodec* pcmWavCodec = (TMdaPcmWavCodec*)&aCodec;
       
   143 			if (pcmWavCodec->iBits == TMdaPcmWavCodec::E8BitPcm)
       
   144 				dataType = KMMFFourCCCodePCMU8; //8 bit PCM
       
   145 			else
       
   146 				dataType = KMMFFourCCCodePCM16; //16 bit PCM
       
   147 			break;
       
   148 			}
       
   149 		case KUidMdaAu8PcmCodecDefine:
       
   150 			dataType = KMMFFourCCCodePCM8;
       
   151 			break;
       
   152 		case KUidMdaAuCodecDefine:
       
   153 		case KUidMdaAu16PcmCodecDefine:
       
   154 			dataType = KMMFFourCCCodePCM16B;
       
   155 			break;
       
   156 
       
   157 		case KUidMdaAuMulawCodecDefine:
       
   158 		case KUidMdaWavMulawCodecDefine:
       
   159 		case KUidMdaRawAudioMulawCodecDefine:  //uLAW
       
   160 			dataType = KMMFFourCCCodeMuLAW;
       
   161 			break;
       
   162 		case KUidMdaAuAlawCodecDefine:
       
   163 		case KUidMdaWavAlawCodecDefine:
       
   164 		case KUidMdaRawAudioAlawCodecDefine:	 //ALAW
       
   165 			dataType = KMMFFourCCCodeALAW;
       
   166 			break;
       
   167 		case KUidMdaRawAudioS8PcmCodecDefine:	 //  P8
       
   168 			dataType = KMMFFourCCCodePCM8;
       
   169 			break;
       
   170 		case KUidMdaRawAudioU8PcmCodecDefine:	  // PU8
       
   171 			dataType = KMMFFourCCCodePCMU8;
       
   172 			break;
       
   173 		case KUidMdaRawAudioSL16PcmCodecDefine: // P16
       
   174 			dataType = KMMFFourCCCodePCM16;
       
   175 			break;
       
   176 		case KUidMdaRawAudioSB16PcmCodecDefine: //P16B
       
   177 			dataType = KMMFFourCCCodePCM16B;
       
   178 			break;
       
   179 		case KUidMdaRawAudioUL16PcmCodecDefine: //PU16
       
   180 			dataType = KMMFFourCCCodePCMU16;
       
   181 			break;
       
   182 		case KUidMdaRawAudioUB16PcmCodecDefine: //PU6B
       
   183 			dataType = KMMFFourCCCodePCMU16B;
       
   184 			break;
       
   185 		case KUidMdaGsmWavCodecDefine: //GSM6
       
   186 			dataType = KMMFFourCCCodeGSM610;
       
   187 			break;
       
   188 		case KUidMdaWavImaAdpcmCodecDefine:
       
   189 			dataType = KMMFFourCCCodeIMAD;
       
   190 			break;
       
   191 		case KUidMdaRawAmrCodecDefine:
       
   192 			dataType = KMMFFourCCCodeAMR;
       
   193 			break;
       
   194 		default:	// Not a Uid we recognise
       
   195 			dataType = KMMFFourCCCodeNULL;
       
   196 			break;
       
   197 		}
       
   198 	return dataType;
       
   199 	}
       
   200 
       
   201 
       
   202 CMMFUtilityFileInfo* CMMFUtilityFileInfo::NewL(TMMSource& aSource)
       
   203 	{
       
   204 	CMMFUtilityFileInfo* self = CMMFUtilityFileInfo::NewLC(aSource);
       
   205 	CleanupStack::Pop(self);
       
   206 	return self;
       
   207 	}
       
   208 
       
   209 
       
   210 CMMFUtilityFileInfo* CMMFUtilityFileInfo::NewLC(TMMSource& aSource)
       
   211 	{
       
   212 	CMMFUtilityFileInfo* self = new (ELeave) CMMFUtilityFileInfo;
       
   213 	CleanupStack::PushL(self);
       
   214 	self->ConstructL(aSource);
       
   215 	return self;
       
   216 	}
       
   217 
       
   218 
       
   219 void CMMFUtilityFileInfo::ConstructL(const TMMSource& aSource)
       
   220 	{
       
   221 	if (aSource.SourceType()==KUidMMFileSource)
       
   222 		{
       
   223 		const TMMFileSource& fileSource = static_cast<const TMMFileSource&>(aSource);
       
   224 		iData = CData::NewL(TVirtualPathPtr(fileSource.Name(), fileSource.UniqueId()),
       
   225 							EContentShareReadWrite/*EContentShareReadOnly*/);
       
   226 		}
       
   227 
       
   228 	if (aSource.SourceType()==KUidMMFileHandleSource)
       
   229 		{
       
   230 		const TMMFileHandleSource& fileHandleSource = static_cast<const TMMFileHandleSource&>(aSource);
       
   231 		iData = CData::NewL(fileHandleSource.Handle(), fileHandleSource.UniqueId());
       
   232 		}
       
   233 
       
   234 	TInt err = iData->SetProperty(EAgentPropertyAgentUI, aSource.IsUIEnabled());
       
   235 
       
   236 	if (err != KErrNone && err != KErrCANotSupported)
       
   237 		{
       
   238 		// KErrCANotSupported isn't a problem for us so eat the error code.
       
   239 		User::Leave(err);
       
   240 		}
       
   241 
       
   242 	err = iData->EvaluateIntent(aSource.Intent());
       
   243 	User::LeaveIfError(err);
       
   244 	}
       
   245 
       
   246 TInt CMMFUtilityFileInfo::EvaluateIntent(TIntent aIntent)
       
   247 	{
       
   248 	return iData->EvaluateIntent(aIntent);
       
   249 	}
       
   250 /**
       
   251  * @internalComponent
       
   252  */
       
   253 TBool CMMFUtilityFileInfo::GetFileMimeTypeL(TDes8& aMimeType)
       
   254 	{
       
   255     #if _DEBUG
       
   256       RDebug::Print(_L("CMMFUtilityFileInfo::GetFileMimeTypeL\n"));
       
   257     #endif
       
   258 	return iData->GetMimeTypeL(aMimeType);
       
   259 	}
       
   260 
       
   261 /**
       
   262  * @internalComponent
       
   263  */
       
   264 void CMMFUtilityFileInfo::GetFileHeaderDataL(TDes8& aHeaderData, TInt aMaxLength)
       
   265 	{
       
   266     #if _DEBUG
       
   267       RDebug::Print(_L("CMMFUtilityFileInfo::GetFileHeaderDataL\n"));
       
   268     #endif
       
   269 	TInt size = 0;
       
   270 	iData->DataSizeL(size);
       
   271 	if (size > 0)
       
   272 		{
       
   273 		if (size > aMaxLength)
       
   274 			size = aMaxLength;
       
   275 		TInt pos = 0;
       
   276 		User::LeaveIfError(iData->Seek(ESeekStart, pos));
       
   277 		User::LeaveIfError(iData->Read(aHeaderData, size));
       
   278 		}
       
   279 	}
       
   280 
       
   281 /**
       
   282  * @internalComponent
       
   283  */
       
   284  HBufC8* CMMFClientUtility::GetFileExtensionL(const TDesC& aFileName)
       
   285 	{
       
   286     #if _DEBUG
       
   287       RDebug::Print(_L("CMMFClientUtility::GetFileExtensionL\n"));
       
   288     #endif
       
   289 	TParse fileName;
       
   290 	fileName.Set(aFileName,NULL,NULL);
       
   291 	HBufC8* fileSuffix = NULL;
       
   292 	if(fileName.ExtPresent())
       
   293 		{
       
   294 		TPtrC fileSuffixPtr(fileName.Ext());
       
   295 		fileSuffix = HBufC8::NewL(fileSuffixPtr.Length());
       
   296 		fileSuffix->Des().Copy(fileSuffixPtr);
       
   297 		}
       
   298 	else
       
   299 		{
       
   300 		fileSuffix = KNullDesC8().AllocL();
       
   301 		}
       
   302 	return fileSuffix;
       
   303 	}
       
   304 
       
   305 
       
   306 /**
       
   307  * @internalComponent
       
   308  */
       
   309 CMMFUtilityFileInfo::~CMMFUtilityFileInfo()
       
   310 	{
       
   311     #if _DEBUG
       
   312       RDebug::Print(_L("CMMFClientUtility::~CMMFUtilityFileInfo\n"));
       
   313     #endif
       
   314 	delete iData;
       
   315 	}
       
   316 
       
   317 /*
       
   318  * @internalComponent
       
   319  *
       
   320  * Returns an integer rating indicating how well the supplied format matches
       
   321  * the header data and file extension supplied.
       
   322  * 3 brownie points awarded for data & suffix match.
       
   323  * 2 brownie points awarded for data match alone.
       
   324  * 1 brownie point awarded for suffix match alone.
       
   325  */
       
   326 TInt CMMFClientUtility::GetBestMatchL(const CMMFFormatImplementationInformation* format, const TDesC8& aHeaderData, const TDesC8& aFileExtension)
       
   327 	{
       
   328     #if _DEBUG
       
   329       RDebug::Print(_L("CMMFClientUtility::GetBestMatchL\n"));
       
   330     #endif
       
   331 	TInt browniePoints = 0;
       
   332 
       
   333 	if (aHeaderData.Length() > 0) // Non empty file
       
   334 		{
       
   335 		if (aFileExtension.Length() > 0) // With a file extension
       
   336 			{
       
   337 			if (format->SupportsHeaderDataL(aHeaderData) &&
       
   338 				format->SupportsFileExtension(aFileExtension))
       
   339 				{
       
   340 				browniePoints = 3;
       
   341 				}
       
   342 			else if (format->SupportsHeaderDataL(aHeaderData))
       
   343 				{
       
   344 				browniePoints = 2;
       
   345 				}
       
   346 			else
       
   347 				{
       
   348 				// See if this format has any 'empty' match data or no match data, indicating
       
   349 				// that this format will match extension alone even if data present.
       
   350 				// (A format may have more than one match data string.)
       
   351 				const CDesC8Array& supportedHeaderData = format->SupportedHeaderData();
       
   352 
       
   353 				if (supportedHeaderData.Count() == 0)
       
   354 					{
       
   355 					// No header data indicated.
       
   356 					if (format->SupportsFileExtension(aFileExtension))
       
   357 						{
       
   358 							browniePoints = 1;
       
   359 						}
       
   360 					}
       
   361 				else
       
   362 					{
       
   363 					for (register TInt i = 0; i < supportedHeaderData.Count(); i++)
       
   364 						{
       
   365 						if ((supportedHeaderData[i].Length() == 0) &&
       
   366 							format->SupportsFileExtension(aFileExtension))
       
   367 							{
       
   368 							browniePoints = 1;
       
   369 							}
       
   370 						}
       
   371 					}
       
   372 				}
       
   373 			}
       
   374 		else
       
   375 			{
       
   376 			// No file suffix, so must match header data alone.
       
   377 			if (format->SupportsHeaderDataL(aHeaderData))
       
   378 				{
       
   379 				browniePoints = 2;
       
   380 				}
       
   381 			}
       
   382 		}
       
   383 	else // Empty File
       
   384 		{
       
   385 		// We have no choice but to match extension, if there is one.
       
   386 		if ((aFileExtension.Length() > 0) && format->SupportsFileExtension(aFileExtension))
       
   387 			{
       
   388 			browniePoints = 1;
       
   389 			}
       
   390 		}
       
   391 
       
   392 	return browniePoints;
       
   393 }
       
   394 
       
   395 /**
       
   396  * @internalComponent
       
   397  *
       
   398  * This function parses all the play & record formats in the given list of controllers,
       
   399  * looking for controllers & formats that best match the requirements.
       
   400  * Play controllers will be returned before record controllers, and
       
   401  * in cases of equal priority between formats, ECom order will be maintained.
       
   402  *
       
   403  * @param	"aControllers"
       
   404  *			A reference to a user supplied list of controllers retrieved from ECom.
       
   405  *			This list may be have been filtered for audio/video/play/record.
       
   406  * @param	"aHeaderDataPlayback"
       
   407  *			A descriptor reference containing the file's header data.
       
   408  *          for matching against a controller's play formats. May be KNullDesC8
       
   409  * @param	"aFileExtensionPlayback"
       
   410  *			A descriptor reference containing the filename's extension.
       
   411  *          for matching against a controller's play formats. May be KNullDesC8
       
   412  * @param	"aHeaderDataRecord"
       
   413  *			A descriptor reference containing the file's header data.
       
   414  *          for matching against a controller's record formats. May be KNullDesC8
       
   415  * @param	"aFileExtensionRecord"
       
   416  *			A descriptor reference containing the filename's extension.
       
   417  *          for matching against a controller's record formats. May be KNullDesC8
       
   418  * @param	"aPrioritisedControllers"
       
   419  *			A reference to a user supplied list through which the list of
       
   420  *			prioritised controllers will be returned.
       
   421  * @since	7.0s
       
   422  * @lib	"MediaClientUtility.lib"
       
   423  */
       
   424 void CMMFClientUtility::PrioritiseControllersL(
       
   425 	const RMMFControllerImplInfoArray& aControllers,
       
   426 	const TDesC8& aHeaderDataPlayback,
       
   427 	const TDesC8& aFileExtensionPlayback,
       
   428 	const TDesC8& aHeaderDataRecord,
       
   429 	const TDesC8& aFileExtensionRecord,
       
   430 	RMMFControllerImplInfoArray& prioritisedControllers)
       
   431 	{
       
   432 	RMMFControllerImplInfoArray fullMatchControllers; // data AND suffix
       
   433 	CleanupClosePushL(fullMatchControllers);
       
   434 	RMMFControllerImplInfoArray partMatchControllers; // data OR suffix
       
   435 	CleanupClosePushL(partMatchControllers);
       
   436 
       
   437 	TBool checkingPlaybackFormats = EFalse;
       
   438 	TBool checkingRecordFormats = EFalse;
       
   439 
       
   440 	if (aHeaderDataPlayback != KNullDesC8 || aFileExtensionPlayback != KNullDesC8)
       
   441 		checkingPlaybackFormats = ETrue;
       
   442 	if (aHeaderDataRecord != KNullDesC8 || aFileExtensionRecord != KNullDesC8)
       
   443 		checkingRecordFormats = ETrue;
       
   444 
       
   445 	// Examine each format for each controller. We only want to know at this stage
       
   446 	// if the controller has suitable formats, so as soon as we know it has, we can
       
   447 	// add it to out list, ranked by how well it matched.
       
   448 	for (register TInt i = 0; i < aControllers.Count(); i++)
       
   449 		{
       
   450 		const CMMFControllerImplementationInformation* controller = aControllers[i];
       
   451 		TInt savedBrowniePointsPlayback = 0;
       
   452 		TInt savedBrowniePointsRecord = 0;
       
   453 
       
   454 		if (checkingPlaybackFormats)
       
   455 			{
       
   456 			for (register TInt p = 0; p < controller->PlayFormats().Count(); p++)
       
   457 				{
       
   458 				const CMMFFormatImplementationInformation* format = controller->PlayFormats()[p];
       
   459 
       
   460 				TInt browniePoints = GetBestMatchL(format, aHeaderDataPlayback, aFileExtensionPlayback);
       
   461 
       
   462 				if (browniePoints >= savedBrowniePointsPlayback)
       
   463 					savedBrowniePointsPlayback = browniePoints;
       
   464 				}
       
   465 			}
       
   466 
       
   467 		if (checkingRecordFormats)
       
   468 			{
       
   469 			for (register TInt r = 0; r < controller->RecordFormats().Count(); r++)
       
   470 				{
       
   471 				const CMMFFormatImplementationInformation* format = controller->RecordFormats()[r];
       
   472 
       
   473 				TInt browniePoints = GetBestMatchL(format, aHeaderDataRecord, aFileExtensionRecord);
       
   474 
       
   475 				if (browniePoints >= savedBrowniePointsRecord)
       
   476 					savedBrowniePointsRecord = browniePoints;
       
   477 				}
       
   478 			}
       
   479 
       
   480 		TInt savedBrowniePoints = 0;
       
   481 		// if we're checking both playback & record formats
       
   482 		// make sure we've found both
       
   483 		if (checkingPlaybackFormats && checkingRecordFormats)
       
   484 			{
       
   485 			savedBrowniePoints = Min(savedBrowniePointsPlayback, savedBrowniePointsRecord);
       
   486 			}
       
   487 		else if (checkingPlaybackFormats)
       
   488 			{
       
   489 			savedBrowniePoints = savedBrowniePointsPlayback;
       
   490 			}
       
   491 		else if (checkingRecordFormats)
       
   492 			{
       
   493 			savedBrowniePoints = savedBrowniePointsRecord;
       
   494 			}
       
   495 
       
   496 		// Checked all formats for this controller, now count our brownie points.
       
   497 		switch (savedBrowniePoints)
       
   498 			{
       
   499 			case 3:
       
   500 				User::LeaveIfError(fullMatchControllers.Append(controller));
       
   501 				break;
       
   502 			case 2:
       
   503 				User::LeaveIfError(partMatchControllers.Insert(controller, 0));
       
   504 				break;
       
   505 			case 1:
       
   506 				User::LeaveIfError(partMatchControllers.Append(controller));
       
   507 				break;
       
   508 			default:
       
   509 				break;
       
   510 			}
       
   511 		}
       
   512 
       
   513 	// The better the controller matches, the earlier it will be in the final list.
       
   514 	for (register TInt x = 0; x < fullMatchControllers.Count(); x++)
       
   515 		{
       
   516 		if (prioritisedControllers.Find(fullMatchControllers[x]) == KErrNotFound)
       
   517 			{
       
   518 			User::LeaveIfError(prioritisedControllers.Append(fullMatchControllers[x]));
       
   519 			}
       
   520 		}
       
   521 
       
   522 	for (register TInt y = 0; y < partMatchControllers.Count(); y++)
       
   523 		{
       
   524 		if (prioritisedControllers.Find(partMatchControllers[y]) == KErrNotFound)
       
   525 			{
       
   526 			User::LeaveIfError(prioritisedControllers.Append(partMatchControllers[y]));
       
   527 			}
       
   528 		}
       
   529 
       
   530 	CleanupStack::PopAndDestroy(2, &fullMatchControllers); // fullMatchControllers, partMatchControllers
       
   531 	}
       
   532 
       
   533 /**
       
   534  * @internalComponent
       
   535  */
       
   536  CMMFMdaObjectStateChangeObserverCallback* CMMFMdaObjectStateChangeObserverCallback::NewL(MMdaObjectStateChangeObserver& aCallback)
       
   537 	{
       
   538 	return new(ELeave) CMMFMdaObjectStateChangeObserverCallback(aCallback);
       
   539 	}
       
   540 
       
   541 /**
       
   542  * @internalComponent
       
   543  */
       
   544 CMMFMdaObjectStateChangeObserverCallback::~CMMFMdaObjectStateChangeObserverCallback()
       
   545 	{
       
   546 	Cancel();
       
   547 	}
       
   548 
       
   549 /**
       
   550  * @internalComponent
       
   551  */
       
   552  void CMMFMdaObjectStateChangeObserverCallback::CallBack(CBase* aObject, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
       
   553 	{
       
   554 	iObject = aObject;
       
   555 	iPreviousState = aPreviousState;
       
   556 	iCurrentState = aCurrentState;
       
   557 	iErrorCode = aErrorCode;
       
   558 	if (!IsActive())
       
   559 		{
       
   560 		TRequestStatus* s = &iStatus;
       
   561 		SetActive();
       
   562 		User::RequestComplete(s, KErrNone);
       
   563 		}
       
   564 	}
       
   565 
       
   566 CMMFMdaObjectStateChangeObserverCallback::CMMFMdaObjectStateChangeObserverCallback(MMdaObjectStateChangeObserver& aCallback) :
       
   567 	CActive(CActive::EPriorityHigh),
       
   568 	iCallback(aCallback)
       
   569 	{
       
   570     #if _DEBUG
       
   571       RDebug::Print(_L("CMMFMdaObjectStateChangeObserverCallback::CMMFMdaObjectStateChangeObserverCallback\n"));
       
   572     #endif
       
   573 	CActiveScheduler::Add(this);
       
   574 	}
       
   575 
       
   576 void CMMFMdaObjectStateChangeObserverCallback::RunL()
       
   577 	{
       
   578     #if _DEBUG
       
   579       RDebug::Print(_L("CMMFMdaObjectStateChangeObserverCallback::RunL\n"));
       
   580     #endif
       
   581 	iCallback.MoscoStateChangeEvent(iObject, iPreviousState, iCurrentState, iErrorCode);
       
   582 	}
       
   583 
       
   584 void CMMFMdaObjectStateChangeObserverCallback::DoCancel()
       
   585 	{
       
   586     #if _DEBUG
       
   587       RDebug::Print(_L("CMMFMdaObjectStateChangeObserverCallback::DoCancel\n"));
       
   588     #endif
       
   589 	//nothing to cancel
       
   590 	}
       
   591 
       
   592 
       
   593 //****************************************
       
   594 // CMMFFindAndOpenController
       
   595 //****************************************
       
   596 
       
   597 /**
       
   598  * Factory function to create a CMMFFindAndOpenController class
       
   599  *
       
   600  * @internalComponent
       
   601  */
       
   602  CMMFFindAndOpenController* CMMFFindAndOpenController::NewL(MMMFFindAndOpenControllerObserver& aObserver)
       
   603 	{
       
   604     #if _DEBUG
       
   605       RDebug::Print(_L("CMMFFindAndOpenController::NewL\n"));
       
   606     #endif
       
   607 	CMMFFindAndOpenController* self = new(ELeave) CMMFFindAndOpenController(aObserver);
       
   608 	CleanupStack::PushL(self);
       
   609 	self->ConstructL();
       
   610 	CleanupStack::Pop(self);
       
   611 	return self;
       
   612 	}
       
   613 
       
   614 CMMFFindAndOpenController::~CMMFFindAndOpenController()
       
   615 	{
       
   616     #if _DEBUG
       
   617       RDebug::Print(_L("CMMFFindAndOpenController::~CMMFFindAndOpenController\n"));
       
   618     #endif
       
   619 	Cancel();
       
   620 
       
   621 	// delete temporary variables
       
   622 	Close();
       
   623 
       
   624 	// this should cancel the AO
       
   625 	delete iAddDataSourceSinkAsync;
       
   626 
       
   627 	delete iPrimaryConfig;
       
   628 	delete iSecondaryConfig;
       
   629 	}
       
   630 
       
   631 /**
       
   632  * Function to free up memory after a successful open has completed
       
   633  * Useful to allow a alloc testing to work.
       
   634  * Must not be called if ReOpen() is to be called
       
   635  *
       
   636  * @internalComponent
       
   637  */
       
   638  void CMMFFindAndOpenController::Close()
       
   639 	{
       
   640 
       
   641 	Cancel();
       
   642 
       
   643 	if(iAddDataSourceSinkAsync)
       
   644 		{
       
   645 		iAddDataSourceSinkAsync->Cancel();
       
   646 		}
       
   647 
       
   648 	if (iPrimaryConfig)
       
   649 		iPrimaryConfig->Close();
       
   650 	if (iSecondaryConfig)
       
   651 		iSecondaryConfig->Close();
       
   652 
       
   653 	iPrioritisedControllers.Close();
       
   654 	iControllers.ResetAndDestroy();
       
   655 	iControllers.Close();
       
   656 
       
   657 	iFileName.SetLength(0);
       
   658 	iFileNameSecondary.SetLength(0);
       
   659 
       
   660 	delete iUrl;
       
   661 	iUrl = NULL;
       
   662 
       
   663 	delete iMimeType;
       
   664 	iMimeType = NULL;
       
   665 
       
   666 	delete iUniqueId;
       
   667 	iUniqueId = NULL;
       
   668 
       
   669 	iFileHandle.Close();
       
   670 	iUseFileHandle = EFalse;
       
   671 	}
       
   672 
       
   673 CMMFFindAndOpenController::CMMFFindAndOpenController(MMMFFindAndOpenControllerObserver& aObserver) :
       
   674 	CActive(EPriorityStandard),
       
   675 	iObserver(aObserver),
       
   676 	iDescriptor(NULL, 0)
       
   677 	{
       
   678     #if _DEBUG
       
   679       RDebug::Print(_L("CMMFFindAndOpenController::CMMFFindAndOpenController\n"));
       
   680     #endif
       
   681 	CActiveScheduler::Add(this);
       
   682 	}
       
   683 
       
   684 void CMMFFindAndOpenController::ConstructL()
       
   685 	{
       
   686     #if _DEBUG
       
   687       RDebug::Print(_L("CMMFFindAndOpenController::ConstructL\n"));
       
   688     #endif
       
   689 	iAddDataSourceSinkAsync = CMMFAddDataSourceSinkAsync::NewL(*this);
       
   690 	iPrimaryConfig = new (ELeave)  CConfig();
       
   691 	iSecondaryConfig =  new (ELeave) CConfig;
       
   692 	iCurrentConfig =  iPrimaryConfig;
       
   693 	}
       
   694 
       
   695 void CMMFFindAndOpenController::RunL()
       
   696 	{
       
   697     #if _DEBUG
       
   698       RDebug::Print(_L("CMMFFindAndOpenController::RunL\n"));
       
   699     #endif
       
   700 	Process();
       
   701 	}
       
   702 
       
   703 void CMMFFindAndOpenController::DoCancel()
       
   704 	{
       
   705     #if _DEBUG
       
   706       RDebug::Print(_L("CMMFFindAndOpenController::DoCancel\n"));
       
   707     #endif
       
   708 	iAddDataSourceSinkAsync->Cancel();
       
   709 	}
       
   710 
       
   711 /**
       
   712  * Defines the media ID & priority to be used when opening a controller
       
   713  * Normally called once only after class has been constructed
       
   714  *
       
   715  * @param	aMediaId
       
   716  *			the media ID to use when searching for a controller
       
   717  *			e.g. KUidMediaTypeAudio
       
   718  * @param	aPrioritySettings
       
   719  *			the priority settings to use when opening a controller
       
   720  * @param	aMediaIdMatchType
       
   721  *			Defines the type of media id match to be performed on the plugins
       
   722  *			returned from the ECOM registry.
       
   723  * @leave	can leave with KErrNoMemory
       
   724 
       
   725  * @internalComponent
       
   726  */
       
   727  void CMMFFindAndOpenController::Configure(
       
   728 	TUid aMediaId,
       
   729 	TMMFPrioritySettings aPrioritySettings,
       
   730 	CMMFPluginSelectionParameters::TMediaIdMatchType aMediaIdMatchType)
       
   731 	{
       
   732     #if _DEBUG
       
   733       RDebug::Print(_L("CMMFFindAndOpenController::Configure\n"));
       
   734     #endif
       
   735 	iPrioritySettings = aPrioritySettings;
       
   736 
       
   737 	iMediaIdMatchType = aMediaIdMatchType;
       
   738 
       
   739 	iMediaId = aMediaId;
       
   740 	}
       
   741 
       
   742 void CMMFFindAndOpenController::ConfigureController(
       
   743 	CConfig& config,
       
   744 	RMMFController& aController,
       
   745 	CMMFControllerEventMonitor& aEventMonitor,
       
   746 	TControllerMode aControllerMode)
       
   747 	{
       
   748     #if _DEBUG
       
   749       RDebug::Print(_L("CMMFFindAndOpenController::ConfigureController\n"));
       
   750     #endif
       
   751 	config.iController = &aController;
       
   752 	config.iEventMonitor = &aEventMonitor;
       
   753 	config.iControllerMode = aControllerMode;
       
   754 	}
       
   755 
       
   756 /**
       
   757  * Configures the primary controller
       
   758  *
       
   759  * @param	aController
       
   760  *			a reference to the client controller object to use
       
   761  * @param	aEventMonitor
       
   762  *			a reference to an event monitor object for receiving
       
   763  *			events from the controller
       
   764  * @param	aControllerMode
       
   765  *			indicates whether this controller is to be used for recording
       
   766  *          or playback
       
   767  *
       
   768  * @internalComponent
       
   769  */
       
   770  void CMMFFindAndOpenController::ConfigureController(
       
   771 	RMMFController& aController,
       
   772 	CMMFControllerEventMonitor& aEventMonitor,
       
   773 	TControllerMode aControllerMode)
       
   774 	{
       
   775     #if _DEBUG
       
   776       RDebug::Print(_L("CMMFFindAndOpenController::ConfigureController2\n"));
       
   777     #endif
       
   778 	ConfigureController(
       
   779 		*iPrimaryConfig,
       
   780 		aController,
       
   781 		aEventMonitor,
       
   782 		aControllerMode);
       
   783 	}
       
   784 
       
   785 /**
       
   786  * Configures the secondary controller
       
   787  *
       
   788  * This is only needed for the audio recorder utility which opens
       
   789  * one controller for playback and another for recording
       
   790  *
       
   791  * @param	aController
       
   792  *			a reference to the client controller object to use
       
   793  * @param	aEventMonitor
       
   794  *			a reference to an event monitor object for receiving
       
   795  *			events from the controller
       
   796  * @param	aControllerMode
       
   797  *			indicates whether this controller is to be used for recording
       
   798  *          or playback or converting
       
   799  *
       
   800  * @internalComponent
       
   801  */
       
   802  void CMMFFindAndOpenController::ConfigureSecondaryController(
       
   803 	RMMFController& aController,
       
   804 	CMMFControllerEventMonitor& aEventMonitor,
       
   805 	TControllerMode aControllerMode)
       
   806 	{
       
   807     #if _DEBUG
       
   808       RDebug::Print(_L("CMMFFindAndOpenController::ConfigureSecondaryController\n"));
       
   809     #endif
       
   810 	ConfigureController(
       
   811 		*iSecondaryConfig,
       
   812 		aController,
       
   813 		aEventMonitor,
       
   814 		aControllerMode);
       
   815 	}
       
   816 
       
   817 void CMMFFindAndOpenController::Init()
       
   818 	{
       
   819     #if _DEBUG
       
   820       RDebug::Print(_L("CMMFFindAndOpenController::Init\n"));
       
   821     #endif
       
   822 	// This should be called prior to opening, so reset the error
       
   823 	iError = KErrNone;
       
   824 	iSourceSinkConfigured = EFalse;
       
   825 	iControllerCount = 0;
       
   826 	}
       
   827 
       
   828 void CMMFFindAndOpenController::ConfigureSourceSink(
       
   829 	CConfig& config,
       
   830 	TSourceSink aSource,
       
   831 	TSourceSink aSink)
       
   832 	{
       
   833 	TInt err;
       
   834 	TRAP(err, config.iSource = CreateSourceSinkL(aSource));
       
   835 	if (err != KErrNone)
       
   836 		{
       
   837 		iError = err;
       
   838 		return;
       
   839 		}
       
   840 
       
   841 	TRAP(err, config.iSink = CreateSourceSinkL(aSink));
       
   842 	if (err != KErrNone)
       
   843 		{
       
   844 		iError = err;
       
   845 		return;
       
   846 		}
       
   847 	}
       
   848 
       
   849 
       
   850 void CMMFFindAndOpenController::ConfigureSourceSink(
       
   851 	CConfig& config,
       
   852 	const TMMSource& aSource,
       
   853 	TSourceSink aSink)
       
   854 	{
       
   855 	TInt err;
       
   856 	TRAP(err, config.iSource = CreateSourceSinkL(aSource));
       
   857 	if (err != KErrNone)
       
   858 		{
       
   859 		iError = err;
       
   860 		return;
       
   861 		}
       
   862 
       
   863 	TRAP(err, config.iSink = CreateSourceSinkL(aSink));
       
   864 	if (err != KErrNone)
       
   865 		{
       
   866 		iError = err;
       
   867 		return;
       
   868 		}
       
   869 	}
       
   870 
       
   871 
       
   872 
       
   873 /**
       
   874  * Configure the primary controller's source and sink
       
   875  * The descriptors passed to this function are copied so they do not need to be persistent.
       
   876  * To simplify the API, any errors that occur are reported back asynchronously following
       
   877  * a subsequent call to OpenByXXX()
       
   878  *
       
   879  * @param	aSourceUid
       
   880  *			the UID of the data source
       
   881  * @param	aSourceData
       
   882  *			a reference to a descriptor used to configure the source
       
   883  * @param	aSinkUid
       
   884  *			the UID of the data sink
       
   885  * @param	aSinkData
       
   886  *			a reference to a descriptor used to configure the sink
       
   887  *
       
   888  * @internalComponent
       
   889  */
       
   890  void CMMFFindAndOpenController::ConfigureSourceSink(
       
   891 	TSourceSink aSource,
       
   892 	TSourceSink aSink)
       
   893 	{
       
   894 
       
   895 	CConfig* config = NULL;
       
   896 
       
   897 	Init();
       
   898 	config = iPrimaryConfig;
       
   899 
       
   900 
       
   901 	// must have already called ConfigureController()
       
   902 	__ASSERT_ALWAYS(config->iController != NULL, CUPanic(EMMFMediaClientUtilityBadState));
       
   903 
       
   904 	ConfigureSourceSink(
       
   905 		*config,
       
   906 		aSource,
       
   907 		aSink);
       
   908 	iCurrentConfig = config;
       
   909 
       
   910 	iSourceSinkConfigured = ETrue;
       
   911 	}
       
   912 
       
   913 
       
   914 /**
       
   915  * Configure the primary controller's source and sink
       
   916  * The descriptors passed to this function are copied so they do not need to be persistent.
       
   917  * To simplify the API, any errors that occur are reported back asynchronously following
       
   918  * a subsequent call to OpenByXXX()
       
   919  *
       
   920  * @param	aSourceUid
       
   921  *			the UID of the data source
       
   922  * @param	aSourceData
       
   923  *			a reference to a descriptor used to configure the source
       
   924  * @param	aSinkUid
       
   925  *			the UID of the data sink
       
   926  * @param	aSinkData
       
   927  *			a reference to a descriptor used to configure the sink
       
   928  *
       
   929  * @internalComponent
       
   930  */
       
   931  void CMMFFindAndOpenController::ConfigureSecondarySourceSink(
       
   932 	TSourceSink aSource,
       
   933 	TSourceSink aSink)
       
   934 	{
       
   935 	if (iError != KErrNone)
       
   936 		{
       
   937 		// if there was an error configuring the primary source/sink, do not try the secondary one
       
   938 		// Don't return the error, since the stored error will be returned by the OpenBy... method
       
   939 		return;
       
   940 		}
       
   941 
       
   942 	CConfig* config = NULL;
       
   943 
       
   944 	config = iSecondaryConfig;
       
   945 
       
   946 	// must have already configured the primary controller
       
   947 	__ASSERT_ALWAYS(iSourceSinkConfigured, CUPanic(EMMFMediaClientUtilityBadState));
       
   948 	config = iSecondaryConfig;
       
   949 
       
   950 	// must have already called ConfigureController()
       
   951 	__ASSERT_ALWAYS(config->iController != NULL, CUPanic(EMMFMediaClientUtilityBadState));
       
   952 
       
   953 	ConfigureSourceSink(
       
   954 		*config,
       
   955 		aSource,
       
   956 		aSink);
       
   957 	iCurrentConfig = config;
       
   958 
       
   959 	iSourceSinkConfigured = ETrue;
       
   960 	}
       
   961 
       
   962 
       
   963 
       
   964 
       
   965  void CMMFFindAndOpenController::ConfigureSourceSink(
       
   966 	const TMMSource& aSource,
       
   967 	TSourceSink aSink)
       
   968 	{
       
   969 	Init();
       
   970 	CConfig* config = iPrimaryConfig;
       
   971 
       
   972 	// must have already called ConfigureController()
       
   973 	__ASSERT_ALWAYS(config->iController != NULL, CUPanic(EMMFMediaClientUtilityBadState));
       
   974 
       
   975 	ConfigureSourceSink(
       
   976 		*config,
       
   977 		aSource,
       
   978 		aSink);
       
   979 	iCurrentConfig = config;
       
   980 
       
   981 	iSourceSinkConfigured = ETrue;
       
   982 	}
       
   983 
       
   984 
       
   985 
       
   986 
       
   987 /**
       
   988  * Opens a controller using the supplied controller UID
       
   989  * and adds the source & sink
       
   990  * Completion is indicated asynchonously by a call to MfaocComplete()
       
   991  *
       
   992  * @param	aControllerUid
       
   993  *			the UID of the primary controller
       
   994  * @param	aControllerUid
       
   995  *			the UID of the secondary controller
       
   996  *
       
   997  * @internalComponent
       
   998  */
       
   999  void CMMFFindAndOpenController::OpenByControllerUid(
       
  1000 		TUid aControllerUid,
       
  1001 		TUid aSecondaryControllerUid)
       
  1002 	{
       
  1003     #if _DEBUG
       
  1004       RDebug::Print(_L("CMMFFindAndOpenController::OpenByControllerUid\n"));
       
  1005     #endif
       
  1006 	// must have already called ConfigureSourceSink()
       
  1007 	__ASSERT_ALWAYS(iSourceSinkConfigured, CUPanic(EMMFMediaClientUtilityBadState));
       
  1008 
       
  1009 	// Have there been any errors so far ?
       
  1010 	if (iError != KErrNone)
       
  1011 		{
       
  1012 	    SchedSendError();
       
  1013 		return;
       
  1014 		}
       
  1015 
       
  1016 	if (iCurrentConfig == iPrimaryConfig)
       
  1017 		{
       
  1018 		// only do this for the playback controller
       
  1019 		TRAP(iError, iCurrentConfig->iSource->EvaluateIntentL())
       
  1020 
       
  1021 		if (iError != KErrNone)
       
  1022 			{
       
  1023 	    	SchedSendError();
       
  1024 			return;
       
  1025 			}
       
  1026 		}
       
  1027 
       
  1028 	iPrimaryConfig->iControllerUid = aControllerUid;
       
  1029 	if (iCurrentConfig == iSecondaryConfig)
       
  1030 		{
       
  1031 		if (aSecondaryControllerUid == KNullUid)
       
  1032 			iSecondaryConfig->iControllerUid = aControllerUid;
       
  1033 		else
       
  1034 			iSecondaryConfig->iControllerUid = aSecondaryControllerUid;
       
  1035 		}
       
  1036 
       
  1037 	iMode = EOpenByControllerUid;
       
  1038 	iControllerImplInfo = NULL;
       
  1039 	iState = EOpenController;
       
  1040 	KickState();
       
  1041 	}
       
  1042 
       
  1043 /**
       
  1044  * Opens a controller using the supplied file name
       
  1045  * and adds the source & sink
       
  1046  * A copy is made of the filename or file handle so that it need not be persistent
       
  1047  * Completion is indicated asynchonously by a call to MfaocComplete()
       
  1048  *
       
  1049  * @param	aSource
       
  1050  *			a reference to a TFileSource object to be used when searching
       
  1051  *          for a controller
       
  1052  * @param	aFileNameSecondary
       
  1053  *			a reference to the seconday filename to be used when searching
       
  1054  *          for a controller. This need only be supplied when converting
       
  1055  *			between two files.
       
  1056  *
       
  1057  * @internalComponent
       
  1058  */
       
  1059  void CMMFFindAndOpenController::OpenByFileSource(const TMMSource& aSource, const TDesC& aFileNameSecondary)
       
  1060 	{
       
  1061 	// must have already called ConfigureSourceSink()
       
  1062 	__ASSERT_ALWAYS(iSourceSinkConfigured, CUPanic(EMMFMediaClientUtilityBadState));
       
  1063 
       
  1064 	TInt err;
       
  1065 	// Have there been any errors so far ?
       
  1066 	if (iError != KErrNone)
       
  1067 		{
       
  1068 		SchedSendError();
       
  1069 		return;
       
  1070 		}
       
  1071 
       
  1072 	if (aSource.SourceType()==KUidMMFileSource)
       
  1073 		{
       
  1074 		const TMMFileSource& fileSource = static_cast<const TMMFileSource&>(aSource);
       
  1075 		iFileName = fileSource.Name();
       
  1076 		}
       
  1077 
       
  1078 	if (aSource.SourceType()==KUidMMFileHandleSource)
       
  1079 		{
       
  1080 		const TMMFileHandleSource& fileHandleSource = static_cast<const TMMFileHandleSource&>(aSource);
       
  1081 		err = iFileHandle.Duplicate(fileHandleSource.Handle());
       
  1082 
       
  1083 
       
  1084 		if (err != KErrNone)
       
  1085 			{
       
  1086 			SchedSendError(err);
       
  1087 			return;
       
  1088 			}
       
  1089 
       
  1090 		iFileHandle.Name(iFileName); //ignore error return since we'll just do without the filename if not available
       
  1091 
       
  1092 
       
  1093 		iUseFileHandle = ETrue;
       
  1094 		}
       
  1095 
       
  1096 	TRAP(err, iUniqueId = aSource.UniqueId().AllocL());
       
  1097 	iIntent = aSource.Intent();
       
  1098 	if (err != KErrNone)
       
  1099 		{
       
  1100 		SchedSendError(err);
       
  1101 		return;
       
  1102 		}
       
  1103 
       
  1104 
       
  1105 	// take a copy of the secondary file name
       
  1106 	iFileNameSecondary = aFileNameSecondary;
       
  1107 
       
  1108 	iMode = EOpenByFileName;
       
  1109 	iState = EBuildControllerList;
       
  1110 	KickState();
       
  1111 	}
       
  1112 
       
  1113 /**
       
  1114  * Opens a controller using the supplied format UID
       
  1115  * and adds the source & sink
       
  1116  * Completion is indicated asynchonously by a call to MfaocComplete()
       
  1117  *
       
  1118  * @param	aFormatUid
       
  1119  *			the UID of a format that must be supported by the controller
       
  1120  * @param	aFormatUidSecondary
       
  1121  *			the UID of a secondary format that must be supported by the controller
       
  1122  *			This need only be supplied when converting between two differnet formats.
       
  1123  *
       
  1124  * @internalComponent
       
  1125  */
       
  1126  void CMMFFindAndOpenController::OpenByFormatUid(TUid aFormatUid, TUid aFormatUidSecondary)
       
  1127 	{
       
  1128     #if _DEBUG
       
  1129       RDebug::Print(_L("CMMFFindAndOpenController::OpenByFormatUid\n"));
       
  1130     #endif
       
  1131 	// must have already called ConfigureSourceSink()
       
  1132 	__ASSERT_ALWAYS(iSourceSinkConfigured, CUPanic(EMMFMediaClientUtilityBadState));
       
  1133 
       
  1134 	// Have there been any errors so far ?
       
  1135 	if (iError != KErrNone)
       
  1136 		{
       
  1137 		SchedSendError();
       
  1138 		return;
       
  1139 		}
       
  1140 
       
  1141 	iFormatUid = aFormatUid;
       
  1142 	iFormatUidSecondary = aFormatUidSecondary;
       
  1143 
       
  1144 	iMode = EOpenByFormatUid;
       
  1145 	iState = EBuildControllerList;
       
  1146 	KickState();
       
  1147 	}
       
  1148 
       
  1149 /**
       
  1150  * Opens a controller using the supplied descriptor
       
  1151  * and adds the source & sink
       
  1152  * Completion is indicated asynchonously by a call to MfaocComplete()
       
  1153  *
       
  1154  * @param	aDescriptor
       
  1155  *			a reference to the descriptor to be used when searching
       
  1156  *          for a controller
       
  1157  *
       
  1158  * @internalComponent
       
  1159  */
       
  1160  void  CMMFFindAndOpenController::OpenByDescriptor(const TDesC8& aDescriptor)
       
  1161 	{
       
  1162     #if _DEBUG
       
  1163       RDebug::Print(_L("CMMFFindAndOpenController::OpenByDescriptor\n"));
       
  1164     #endif
       
  1165 	// must have already called ConfigureSourceSink()
       
  1166 	__ASSERT_ALWAYS(iSourceSinkConfigured, CUPanic(EMMFMediaClientUtilityBadState));
       
  1167 
       
  1168 	// Have there been any errors so far ?
       
  1169 	if (iError != KErrNone)
       
  1170 		{
       
  1171 		SchedSendError();
       
  1172 		return;
       
  1173 		}
       
  1174 
       
  1175 	// take a copy of the descriptor
       
  1176 	TUint8* desBufferPtr = const_cast<TUint8*> (aDescriptor.Ptr());
       
  1177 	iDescriptor.Set( desBufferPtr,aDescriptor.Length(),aDescriptor.Length());
       
  1178 
       
  1179 	iMode = EOpenByDescriptor;
       
  1180 	iState = EBuildControllerList;
       
  1181 	KickState();
       
  1182 	}
       
  1183 
       
  1184 /**
       
  1185  * Opens a controller using the supplied URL
       
  1186  * and adds the source & sink
       
  1187  * Completion is indicated asynchonously by a call to MfaocComplete()
       
  1188  *
       
  1189  * @param	aUrl
       
  1190  *			a reference to the URL to be used when searching for a controller
       
  1191  * @param	aIapId
       
  1192  *          the IAP ID to be used when searching for a controller
       
  1193  * @param	aMimeType
       
  1194  *          the MIME type of the data to be used when searching for a controller
       
  1195  *
       
  1196  * @internalComponent
       
  1197  */
       
  1198  void CMMFFindAndOpenController::OpenByUrl(const TDesC& aUrl, TInt aIapId, const TDesC8& aMimeType)
       
  1199 	{
       
  1200     #if _DEBUG
       
  1201       RDebug::Print(_L("CMMFFindAndOpenController::OpenByUrl\n"));
       
  1202     #endif
       
  1203 	// must have already called ConfigureSourceSink()
       
  1204 	__ASSERT_ALWAYS(iSourceSinkConfigured, CUPanic(EMMFMediaClientUtilityBadState));
       
  1205 
       
  1206 	// Have there been any errors so far ?
       
  1207 	if (iError != KErrNone)
       
  1208 		{
       
  1209 		SchedSendError();
       
  1210 		return;
       
  1211 		}
       
  1212 
       
  1213 	// take a copy of the Url
       
  1214 	delete iUrl;
       
  1215 	iUrl = NULL;
       
  1216 	iUrl = aUrl.Alloc();
       
  1217 	if (iUrl == NULL)
       
  1218 		{
       
  1219 		SchedSendError(KErrNoMemory);
       
  1220 		return;
       
  1221 		}
       
  1222 
       
  1223 	// take a copy of the IapId
       
  1224 	iIapId = aIapId;
       
  1225 
       
  1226 	// take a copy of the mime type
       
  1227 	delete iMimeType;
       
  1228 	iMimeType = NULL;
       
  1229 	iMimeType = aMimeType.Alloc();
       
  1230 	if (iMimeType == NULL)
       
  1231 		{
       
  1232 		SchedSendError(KErrNoMemory);
       
  1233 		return;
       
  1234 		}
       
  1235 
       
  1236 	iMode = EOpenByUrl;
       
  1237 	iState = EBuildControllerList;
       
  1238 	KickState();
       
  1239 	}
       
  1240 
       
  1241 /**
       
  1242  * Static function to return a TMMFFileConfig object
       
  1243  * suitable for passing to ConfigureSourceSink()
       
  1244  *
       
  1245  * @param	aFileName
       
  1246  *          the filename to use
       
  1247  *
       
  1248  * @internalComponent
       
  1249  */
       
  1250  TMMFFileConfig CMMFFindAndOpenController::GetConfigFile(const TDesC& aFileName)
       
  1251 	{
       
  1252     #if _DEBUG
       
  1253       RDebug::Print(_L("CMMFFindAndOpenController::GetConfigFile\n"));
       
  1254     #endif
       
  1255 	TMMFFileConfig sourceSinkData;
       
  1256 	sourceSinkData().iPath = aFileName;
       
  1257 	return sourceSinkData;
       
  1258 	}
       
  1259 
       
  1260 /**
       
  1261  * Static function to return a TMMFDescriptorConfig object
       
  1262  * suitable for passing to ConfigureSourceSink()
       
  1263  *
       
  1264  * @param	aFileName
       
  1265  *          the filename to use
       
  1266  *
       
  1267  * @internalComponent
       
  1268  */
       
  1269  TMMFDescriptorConfig CMMFFindAndOpenController::GetConfigDescriptor(const TDesC8& aDescriptor)
       
  1270 	{
       
  1271     #if _DEBUG
       
  1272       RDebug::Print(_L("CMMFFindAndOpenController::GetConfigDescriptor\n"));
       
  1273     #endif
       
  1274 	TMMFDescriptorConfig sourceSinkData;
       
  1275 	sourceSinkData().iDes = (TAny*)&aDescriptor;
       
  1276 	sourceSinkData().iDesThreadId = RThread().Id();
       
  1277 	return sourceSinkData;
       
  1278 	}
       
  1279 
       
  1280 /**
       
  1281  * Static function to create a CBufFlat object
       
  1282  * suitable for passing to ConfigureSourceSink()
       
  1283  *
       
  1284  * @param	aUrlCfgBuffer
       
  1285  *          the reference to a caller-supplied pointer used to create
       
  1286  *			a CBufFlat object. The caller is responsible for deletion.
       
  1287  * @param	aUrl
       
  1288  *			a reference to the URL to be used
       
  1289  * @param	aIapId
       
  1290  *          the IAP ID to be used
       
  1291  * @return	can return KErrNone or KErrNoMemory
       
  1292  *
       
  1293  * @internalComponent
       
  1294  */
       
  1295  TInt CMMFFindAndOpenController::GetConfigUrl(CBufFlat*& aUrlCfgBuffer, const TDesC& aUrl, TInt aIapId)
       
  1296 	{
       
  1297     #if _DEBUG
       
  1298       RDebug::Print(_L("CMMFFindAndOpenController::GetConfigDescriptor\n"));
       
  1299     #endif
       
  1300 	TInt error;
       
  1301 	delete aUrlCfgBuffer;
       
  1302 	aUrlCfgBuffer = NULL;
       
  1303 
       
  1304 	CMMFUrlParams* urlCfg = NULL;
       
  1305 	TRAP(error, urlCfg = CMMFUrlParams::NewL(aUrl,aIapId));
       
  1306 	if (error != KErrNone)
       
  1307 		return error;
       
  1308 
       
  1309 	TRAP(error,
       
  1310 		aUrlCfgBuffer = urlCfg->ExternalizeToCBufFlatLC();
       
  1311 		CleanupStack::Pop(aUrlCfgBuffer);
       
  1312 		);
       
  1313 
       
  1314 	delete urlCfg;
       
  1315 
       
  1316 	return error;
       
  1317 	}
       
  1318 
       
  1319 /**
       
  1320  * ReOpens the previously opened primary controller
       
  1321  *
       
  1322  * @internalComponent
       
  1323  */
       
  1324  void CMMFFindAndOpenController::ReOpen()
       
  1325 	{
       
  1326     #if _DEBUG
       
  1327       RDebug::Print(_L("CMMFFindAndOpenController::ReOpen\n"));
       
  1328     #endif
       
  1329 	// should already have a valid controller uid so just open it
       
  1330 	iControllerImplInfo = NULL;
       
  1331 	iState = EOpenController;
       
  1332 	KickState();
       
  1333 	}
       
  1334 
       
  1335 void CMMFFindAndOpenController::OpenPrimaryController(void)
       
  1336 	{
       
  1337     #if _DEBUG
       
  1338       RDebug::Print(_L("CMMFFindAndOpenController::OpenPrimaryController\n"));
       
  1339     #endif
       
  1340 	iCurrentConfig = iPrimaryConfig;
       
  1341 	switch(iMode)
       
  1342 		{
       
  1343 		case EOpenByFileName:
       
  1344 		case EOpenByFormatUid:
       
  1345 		case EOpenByDescriptor:
       
  1346 		case EOpenByUrl:
       
  1347 			iState = EBuildControllerList;
       
  1348 			break;
       
  1349 		case EOpenByControllerUid:
       
  1350 			iControllerImplInfo = NULL;
       
  1351 			iState = EOpenController;
       
  1352 			break;
       
  1353 		}
       
  1354 	KickState();
       
  1355 	}
       
  1356 
       
  1357 void CMMFFindAndOpenController::KickState()
       
  1358 	{
       
  1359     #if _DEBUG
       
  1360       RDebug::Print(_L("CMMFFindAndOpenController::KickState\n"));
       
  1361     #endif
       
  1362 	TRequestStatus* status = &iStatus;
       
  1363 	User::RequestComplete(status, KErrNone);
       
  1364 	SetActive();
       
  1365 	}
       
  1366 
       
  1367 void CMMFFindAndOpenController::CloseController()
       
  1368 	{
       
  1369     #if _DEBUG
       
  1370       RDebug::Print(_L("CMMFFindAndOpenController::CloseController\n"));
       
  1371     #endif
       
  1372 	if (iCurrentConfig->iEventMonitor)
       
  1373 		iCurrentConfig->iEventMonitor->Cancel();
       
  1374 	iCurrentConfig->iController->Close();
       
  1375 	}
       
  1376 
       
  1377 void CMMFFindAndOpenController::Process()
       
  1378 	{
       
  1379     #if _DEBUG
       
  1380       RDebug::Print(_L("CMMFFindAndOpenController::Process\n"));
       
  1381     #endif
       
  1382 	switch(iState)
       
  1383 		{
       
  1384 		case EBuildControllerList:
       
  1385 			switch(iMode)
       
  1386 				{
       
  1387 				case EOpenByFileName:
       
  1388 					TRAP(iError, BuildControllerListFileNameL());
       
  1389 					break;
       
  1390 				case EOpenByDescriptor:
       
  1391 					TRAP(iError, BuildControllerListDescriptorL());
       
  1392 					break;
       
  1393 				case EOpenByUrl:
       
  1394 					TRAP(iError, BuildControllerListUrlL());
       
  1395 					break;
       
  1396 				case EOpenByFormatUid:
       
  1397 					TRAP(iError, BuildControllerListFormatL());
       
  1398 					break;
       
  1399 				default:
       
  1400 					CUPanic(EMMFMediaClientUtilityBadState);
       
  1401 				}
       
  1402 
       
  1403 			if (iError != KErrNone)
       
  1404 				{
       
  1405 				iState = EIdle;
       
  1406 				SendError();
       
  1407 				break;
       
  1408 				}
       
  1409 
       
  1410 			// try the first controller
       
  1411 			iControllerIndex = -1;
       
  1412 			TryNextController();
       
  1413 			break;
       
  1414 
       
  1415 		case EOpenController:
       
  1416 			// Make sure any existing controller is closed.
       
  1417 			CloseController();
       
  1418 
       
  1419 			// Open the controller
       
  1420 			if (iControllerImplInfo)
       
  1421 				{
       
  1422 				iError = iCurrentConfig->iController->Open(*iControllerImplInfo, iPrioritySettings);
       
  1423 				}
       
  1424 			else
       
  1425 				{
       
  1426 				iError = iCurrentConfig->iController->Open(iCurrentConfig->iControllerUid, iPrioritySettings);
       
  1427 				}
       
  1428 
       
  1429 			if (iError)
       
  1430 				{
       
  1431 				TryNextController();
       
  1432 				}
       
  1433 			else
       
  1434 				{
       
  1435 
       
  1436 				iCurrentConfig->iEventMonitor->Start();
       
  1437 
       
  1438 				if (iCurrentConfig == iSecondaryConfig)
       
  1439 					{
       
  1440 					iState = EAddSource;
       
  1441 					KickState();
       
  1442 					}
       
  1443 				else
       
  1444 					{
       
  1445 					iState = EAddSink;
       
  1446 					KickState();
       
  1447 					}
       
  1448 				}
       
  1449 			break;
       
  1450 
       
  1451 		case EAddSource:
       
  1452 			{
       
  1453 			iState = EWaitingForSource;
       
  1454 			const CMMSourceSink* source = iCurrentConfig->iSource;
       
  1455 			iAddDataSourceSinkAsync->AddDataSource(*iCurrentConfig->iController,
       
  1456 												   source->SourceSinkUid(),
       
  1457 												   source->SourceSinkData());
       
  1458 			}
       
  1459 			break;
       
  1460 
       
  1461 		case EAddSink:
       
  1462 			{
       
  1463 			iState = EWaitingForSink;
       
  1464 			const CMMSourceSink* sink = iCurrentConfig->iSink;
       
  1465 			iAddDataSourceSinkAsync->AddDataSink(*iCurrentConfig->iController,
       
  1466 												 sink->SourceSinkUid(),
       
  1467 												 sink->SourceSinkData());
       
  1468 			}
       
  1469 			break;
       
  1470 
       
  1471 		case EWaitingForSource:
       
  1472 			break;
       
  1473 
       
  1474 		case EWaitingForSink:
       
  1475 			break;
       
  1476 
       
  1477 		case ESendError:
       
  1478 			SendError();
       
  1479 			iState = EIdle;
       
  1480 			break;
       
  1481 
       
  1482 		case EIdle:
       
  1483 		default:
       
  1484 			break;
       
  1485 		}
       
  1486 	}
       
  1487 
       
  1488 void CMMFFindAndOpenController::TryNextController()
       
  1489 	{
       
  1490 
       
  1491     #if _DEBUG
       
  1492       RDebug::Print(_L("CMMFFindAndOpenController::TryNextController\n"));
       
  1493     #endif
       
  1494 	// If an error occurred close the controller.
       
  1495 	if (iError != KErrNone)
       
  1496 		CloseController();
       
  1497 
       
  1498 	// take the first available exit if we're out of memory
       
  1499 	if (iError == KErrNoMemory)
       
  1500 		{
       
  1501 		SendError();
       
  1502 		return;
       
  1503 		}
       
  1504 
       
  1505 	if (iMode == EOpenByControllerUid || ++iControllerIndex >= iControllerCount)
       
  1506 		{
       
  1507 		SendError(KErrNotSupported);		// KErrNotSupported
       
  1508 		return;
       
  1509 		}
       
  1510 
       
  1511 	if (iMode == EOpenByFileName || iMode == EOpenByFormatUid)
       
  1512 		{
       
  1513 		iControllerImplInfo = iPrioritisedControllers[iControllerIndex];
       
  1514 		}
       
  1515 	else	//if (iMode == EOpenByDescriptor || iMode == EOpenByUrl)
       
  1516 		{
       
  1517 		iControllerImplInfo = iControllers[iControllerIndex];
       
  1518 		}
       
  1519 
       
  1520         // This Flag is defined so that if the Helix Controller Supports
       
  1521         // the playback of Local Media for WMA, then the ProgDL still
       
  1522         // goes through the Old WMA Controller( AdvancedAudioController)
       
  1523         // We are launching the Old WMA Controller using the UID.
       
  1524 
       
  1525 #ifdef __WINDOWS_MEDIA
       
  1526     HBufC8* mimeType = HBufC8::NewLC(KMaxMimeLength);
       
  1527     TPtr8 mimeTypePtr = mimeType->Des();
       
  1528     mimeTypePtr.Copy(KWMAMimeType());
       
  1529 
       
  1530     TBool IsSupported = EFalse;
       
  1531     const RMMFFormatImplInfoArray& playFormatInfo = iControllerImplInfo->PlayFormats();
       
  1532 
       
  1533 	for (TInt p = 0; p < iControllerImplInfo->PlayFormats().Count(); p++)
       
  1534 		{
       
  1535 		const CMMFFormatImplementationInformation* format = iControllerImplInfo->PlayFormats()[p];
       
  1536         IsSupported = format->SupportsMimeType(*mimeType);
       
  1537         if(IsSupported)
       
  1538             break;
       
  1539         }
       
  1540 
       
  1541     if(IsSupported)
       
  1542         {
       
  1543         iControllerImplInfo = NULL;
       
  1544         iCurrentConfig->iControllerUid = TUid::Uid(0x10207A9B);
       
  1545         }
       
  1546     else
       
  1547 #endif
       
  1548         {
       
  1549     	iCurrentConfig->iControllerUid = iControllerImplInfo->Uid();
       
  1550         }
       
  1551 
       
  1552 #ifdef __WINDOWS_MEDIA
       
  1553 	CleanupStack::PopAndDestroy(mimeType);
       
  1554 #endif
       
  1555 	iState = EOpenController;
       
  1556 	KickState();
       
  1557 	}
       
  1558 
       
  1559 void CMMFFindAndOpenController::MadssaoAddDataSourceSinkAsyncComplete(TInt aError, const TMMFMessageDestination& aHandle)
       
  1560 	{
       
  1561     #if _DEBUG
       
  1562       RDebug::Print(_L("CMMFFindAndOpenController::MadssaoAddDataSourceSinkAsyncComplete\n"));
       
  1563     #endif
       
  1564 	iError = aError;
       
  1565 
       
  1566 	// take the first available exit if we're out of memory
       
  1567 	// or we've been cancelled
       
  1568 	if (iError == KErrNoMemory || iError == KErrCancel)
       
  1569 		{
       
  1570 		SendError();
       
  1571 		return;
       
  1572 		}
       
  1573 
       
  1574 	// failed to add source or sink - try the next controller
       
  1575 	if (aError != KErrNone)
       
  1576 		{
       
  1577 		TryNextController();
       
  1578 		return;
       
  1579 		}
       
  1580 
       
  1581 	if (iState == EWaitingForSource)
       
  1582 		{
       
  1583 		iSourceHandle = aHandle;
       
  1584 		if (iCurrentConfig == iSecondaryConfig)
       
  1585 			{
       
  1586 			iState = EAddSink;
       
  1587 			}
       
  1588 		else	// completed ok !
       
  1589 			{
       
  1590 			iState = EIdle;
       
  1591 			iError = KErrNone;
       
  1592 			SendError();
       
  1593 			return;
       
  1594 			}
       
  1595 		}
       
  1596 	else if (iState == EWaitingForSink)
       
  1597 		{
       
  1598 		iSinkHandle = aHandle;
       
  1599 		if (iCurrentConfig == iSecondaryConfig)	// completed ok !
       
  1600 			{
       
  1601 			iState = EIdle;
       
  1602 			iError = KErrNone;
       
  1603 			SendError();
       
  1604 			return;
       
  1605 			}
       
  1606 		else
       
  1607 			{
       
  1608 			iState = EAddSource;
       
  1609 			}
       
  1610 		}
       
  1611 
       
  1612 	KickState();
       
  1613 	}
       
  1614 
       
  1615 void CMMFFindAndOpenController::SendError(TInt aError)
       
  1616 	{
       
  1617     #if _DEBUG
       
  1618       RDebug::Print(_L("CMMFFindAndOpenController::SendError err= %d\n"),aError);
       
  1619     #endif
       
  1620 	if (iError == KErrNone)
       
  1621 		iError = aError;
       
  1622 
       
  1623 	iObserver.MfaocComplete(iError, iCurrentConfig->iController, iCurrentConfig->iControllerUid, &iSourceHandle, &iSinkHandle);
       
  1624 
       
  1625 	// if we've just attempted to open the Secondary controller,
       
  1626 	// try to open the Primary controller
       
  1627 	if (iCurrentConfig == iSecondaryConfig)
       
  1628 		{
       
  1629 		if (iError == KErrNone)
       
  1630 			OpenPrimaryController();
       
  1631 		}
       
  1632 
       
  1633 	// if we failed to open, may as well free up some memory
       
  1634 	// if open succeeded we need to preserve state in case of a re-open
       
  1635 	if (iError != KErrNone)
       
  1636 		Close();
       
  1637 	}
       
  1638 
       
  1639 void CMMFFindAndOpenController::SchedSendError(TInt aError)
       
  1640 	{
       
  1641     #if _DEBUG
       
  1642       RDebug::Print(_L("CMMFFindAndOpenController::SchedSendError\n"));
       
  1643     #endif
       
  1644 	if (aError != KErrNone)
       
  1645 		iError = aError;
       
  1646 	iState = ESendError;
       
  1647 	KickState();
       
  1648 	}
       
  1649 
       
  1650 void CMMFFindAndOpenController::BuildControllerListFileNameL()
       
  1651 	{
       
  1652     #if _DEBUG
       
  1653       RDebug::Print(_L("CMMFFindAndOpenController::BuildControllerListFileNameL\n"));
       
  1654     #endif
       
  1655 	// Retrieve a list of possible controllers from ECOM
       
  1656 	// If we don't have a match, leave with unsupported
       
  1657 
       
  1658 	iControllers.ResetAndDestroy();
       
  1659 	iPrioritisedControllers.Reset();
       
  1660 
       
  1661 	TControllerMode mode = iCurrentConfig->iControllerMode;
       
  1662 
       
  1663 	// if we're playing, try to get the MIME type from the Content Access
       
  1664 	// Framework (CAF) & use that to select a controller - if that fails,
       
  1665 	// try to select a controller based on the header data/file extension
       
  1666 
       
  1667 	CMMFUtilityFileInfo* fileInfo = NULL;
       
  1668 
       
  1669 	TInt error;
       
  1670 
       
  1671 	//If the current CMMSourceSink is a CMMFileSourceSink
       
  1672 	// Using the previous version we'd get KErrCANoPermission when calling EvaluateIntent in the
       
  1673 	// CMMFUtilityFileInfo ConstructL as the intent == EUnknown, so now pass the intent as a parameter
       
  1674 	// to TMMFileHandleSource and....
       
  1675 	if (iUseFileHandle)
       
  1676 		{
       
  1677 		if (iUniqueId != NULL)
       
  1678 			{
       
  1679 			TMMFileHandleSource fileHandleSource(iFileHandle, (*iUniqueId), iIntent);
       
  1680 			TRAP(error, fileInfo = CMMFUtilityFileInfo::NewL(fileHandleSource));
       
  1681 			}
       
  1682 		else
       
  1683 			{
       
  1684 			TMMFileHandleSource fileHandleSource(iFileHandle);
       
  1685 			TRAP(error, fileInfo = CMMFUtilityFileInfo::NewL(fileHandleSource));
       
  1686 			}
       
  1687 		}
       
  1688 	else
       
  1689 		{
       
  1690 		if (iUniqueId != NULL)
       
  1691 			{
       
  1692 			TMMFileSource fileSource(iFileName, (*iUniqueId), iIntent);
       
  1693 			TRAP(error, fileInfo = CMMFUtilityFileInfo::NewL(fileSource));
       
  1694 			}
       
  1695 		else
       
  1696 			{
       
  1697 			TMMFileSource fileSource(iFileName);
       
  1698 			TRAP(error, fileInfo = CMMFUtilityFileInfo::NewL(fileSource));
       
  1699 			}
       
  1700 		}
       
  1701 
       
  1702 	if (fileInfo != NULL)
       
  1703 		{
       
  1704 		CleanupDeletePushL(fileInfo);
       
  1705 		}
       
  1706 
       
  1707 	if (error != KErrNone)
       
  1708 		{
       
  1709 		// if playback mode, leave for any error
       
  1710 		// if record mode, allow KErrNotFound
       
  1711 		if (mode == EPlayback || (mode != EPlayback && error != KErrNotFound))
       
  1712 			{
       
  1713 			User::Leave(error);
       
  1714 			}
       
  1715 		}
       
  1716 
       
  1717 	CMMFControllerPluginSelectionParameters* cSelect = CMMFControllerPluginSelectionParameters::NewLC();
       
  1718 	RArray<TUid> mediaIds;
       
  1719 	CleanupClosePushL(mediaIds);
       
  1720 	User::LeaveIfError(mediaIds.Append(iMediaId));
       
  1721 
       
  1722 	cSelect->SetMediaIdsL(mediaIds, iMediaIdMatchType);
       
  1723 
       
  1724 
       
  1725 	if (mode == EPlayback)
       
  1726 		{
       
  1727 		ASSERT(fileInfo!=NULL);
       
  1728 		TBuf8<KMaxMimeLength> mimeType;
       
  1729 		TBool mimeTypeKnown = fileInfo->GetFileMimeTypeL(mimeType);
       
  1730 		if (mimeTypeKnown)
       
  1731 			{
       
  1732 			CMMFFormatSelectionParameters* fSelect = CMMFFormatSelectionParameters::NewLC();
       
  1733 			fSelect->SetMatchToMimeTypeL(mimeType);
       
  1734 			cSelect->SetRequiredPlayFormatSupportL(*fSelect);
       
  1735 			cSelect->ListImplementationsL(iControllers);
       
  1736 			CleanupStack::PopAndDestroy(fSelect);
       
  1737 			}
       
  1738 
       
  1739 
       
  1740 		// copy to the iPrioritisedControllers array - this is a NOOP if the
       
  1741 		// MIME type is not known since iControllers will be empty
       
  1742 		ASSERT(mimeTypeKnown || iControllers.Count() == 0);
       
  1743 		for (TInt controllerIndex=0; controllerIndex < iControllers.Count(); controllerIndex++)
       
  1744 			User::LeaveIfError(iPrioritisedControllers.Append(iControllers[controllerIndex]));
       
  1745 
       
  1746 		iControllerCount = iPrioritisedControllers.Count();
       
  1747 		if (iControllerCount > 0)
       
  1748 			{
       
  1749 			// Clean up
       
  1750 			// cSelect, mediaIds,
       
  1751 			CleanupStack::PopAndDestroy(2, cSelect);
       
  1752 			if (fileInfo != NULL)
       
  1753 				{
       
  1754 				CleanupStack::PopAndDestroy(fileInfo);
       
  1755 				}
       
  1756 			return;
       
  1757 			}
       
  1758 		}
       
  1759 
       
  1760 	// Retrieve header data first. If file doesn't exist, its ok.
       
  1761 	HBufC8* headerData = HBufC8::NewLC(KMaxHeaderSize);
       
  1762 	TPtr8 headerDataPtr = headerData->Des();
       
  1763 	if (fileInfo)
       
  1764 		{
       
  1765 		fileInfo->GetFileHeaderDataL(headerDataPtr, KMaxHeaderSize);
       
  1766 		}
       
  1767 
       
  1768 	// Get the filename's suffix
       
  1769 	HBufC8* fileSuffix = CMMFClientUtility::GetFileExtensionL(iFileName);
       
  1770 
       
  1771 	CleanupStack::PushL(fileSuffix);
       
  1772 	TPtr8 fileSuffixPtr = fileSuffix->Des();
       
  1773 
       
  1774 	// Get the secondary filename's header data (for convert)
       
  1775 	HBufC8* headerDataSecondary = HBufC8::NewLC(KMaxHeaderSize);
       
  1776 	TPtr8 headerDataPtrSecondary = headerDataSecondary->Des();
       
  1777 	if (iFileNameSecondary.Length() > 0 && fileInfo)
       
  1778 		{
       
  1779 		fileInfo->GetFileHeaderDataL(headerDataPtrSecondary, KMaxHeaderSize);
       
  1780 		}
       
  1781 
       
  1782 	// Get the secondary filename's suffix
       
  1783 	HBufC8* fileSuffixSecondary = CMMFClientUtility::GetFileExtensionL(iFileNameSecondary);
       
  1784 	CleanupStack::PushL(fileSuffixSecondary);
       
  1785 	TPtr8 fileSuffixPtrSecondary = fileSuffixSecondary->Des();
       
  1786 
       
  1787 
       
  1788 	CMMFFormatSelectionParameters* fSelect = CMMFFormatSelectionParameters::NewLC();
       
  1789 
       
  1790 	if (mode == EPlayback || mode == EConvert)
       
  1791 		cSelect->SetRequiredPlayFormatSupportL(*fSelect);
       
  1792 	if (mode == ERecord || mode == EConvert)
       
  1793 		cSelect->SetRequiredRecordFormatSupportL(*fSelect);
       
  1794 
       
  1795 	cSelect->ListImplementationsL(iControllers);
       
  1796 
       
  1797 	if (iControllers.Count()==0)
       
  1798 		User::Leave(KErrNotSupported);
       
  1799 
       
  1800 	if (mode == ERecord)
       
  1801 		{
       
  1802 		CMMFClientUtility::PrioritiseControllersL(
       
  1803 			iControllers,
       
  1804 			headerDataPtrSecondary,
       
  1805 			fileSuffixPtrSecondary,
       
  1806 			headerDataPtr,
       
  1807 			fileSuffixPtr,
       
  1808 			iPrioritisedControllers);
       
  1809 		}
       
  1810 	else
       
  1811 		{
       
  1812 		CMMFClientUtility::PrioritiseControllersL(
       
  1813 			iControllers,
       
  1814 			headerDataPtr,
       
  1815 			fileSuffixPtr,
       
  1816 			headerDataPtrSecondary,
       
  1817 			fileSuffixPtrSecondary,
       
  1818 			iPrioritisedControllers);
       
  1819 		}
       
  1820 
       
  1821 	iControllerCount = iPrioritisedControllers.Count();
       
  1822 	if (iControllerCount == 0)
       
  1823 		User::Leave(KErrNotSupported);
       
  1824 
       
  1825 	// Clean up
       
  1826 	// cSelect, mediaIds,
       
  1827 	// headerData, fileSuffix, headerDataSecondary, fileSuffixSecondary,
       
  1828 	// fSelect
       
  1829 	CleanupStack::PopAndDestroy(7, cSelect);
       
  1830 	if (fileInfo != NULL)
       
  1831 		{
       
  1832 		CleanupStack::PopAndDestroy(fileInfo);
       
  1833 		}
       
  1834 	}
       
  1835 
       
  1836 void CMMFFindAndOpenController::BuildControllerListDescriptorL()
       
  1837 	{
       
  1838 	// Retrieve a list of possible controllers from ECOM
       
  1839 	// If we don't have a match, leave with unsupported
       
  1840 
       
  1841 	iControllers.ResetAndDestroy();
       
  1842 
       
  1843 	CMMFControllerPluginSelectionParameters* cSelect = CMMFControllerPluginSelectionParameters::NewLC();
       
  1844 	CMMFFormatSelectionParameters* fSelect = CMMFFormatSelectionParameters::NewLC();
       
  1845 
       
  1846 
       
  1847 	RArray<TUid> mediaIds;
       
  1848 	CleanupClosePushL(mediaIds);
       
  1849 	User::LeaveIfError(mediaIds.Append(iMediaId));
       
  1850 
       
  1851 	cSelect->SetMediaIdsL(mediaIds, iMediaIdMatchType);
       
  1852 
       
  1853 	TPtrC8 header = iDescriptor.Left(KMaxHeaderSize);
       
  1854 	fSelect->SetMatchToHeaderDataL(header);
       
  1855 
       
  1856 
       
  1857 	TControllerMode mode = iCurrentConfig->iControllerMode;
       
  1858 	if (mode == EPlayback || mode == EConvert)
       
  1859 		cSelect->SetRequiredPlayFormatSupportL(*fSelect);
       
  1860 	if (mode == ERecord || mode == EConvert)
       
  1861 		cSelect->SetRequiredRecordFormatSupportL(*fSelect);
       
  1862 
       
  1863 	cSelect->ListImplementationsL(iControllers);
       
  1864 
       
  1865 	iControllerCount = iControllers.Count();
       
  1866 	if (iControllerCount == 0)
       
  1867 		User::Leave(KErrNotSupported);
       
  1868 
       
  1869 	// Clean up
       
  1870 	// cSelect, fSelect, mediaIds
       
  1871 	CleanupStack::PopAndDestroy(3, cSelect);
       
  1872 	}
       
  1873 
       
  1874 void CMMFFindAndOpenController::BuildControllerListUrlL()
       
  1875 	{
       
  1876     #if _DEBUG
       
  1877       RDebug::Print(_L("CMMFFindAndOpenController::BuildControllerListUrlL"));
       
  1878     #endif
       
  1879 	// Retrieve a list of possible controllers from ECOM
       
  1880 	// If we don't have a match, leave with unsupported
       
  1881 
       
  1882 	iControllers.ResetAndDestroy();
       
  1883 
       
  1884 	CMMFControllerPluginSelectionParameters* cSelect = CMMFControllerPluginSelectionParameters::NewLC();
       
  1885 	CMMFFormatSelectionParameters* fSelect = CMMFFormatSelectionParameters::NewLC();
       
  1886 
       
  1887 	RArray<TUid> mediaIds;
       
  1888 	CleanupClosePushL(mediaIds);
       
  1889 	User::LeaveIfError(mediaIds.Append(iMediaId));
       
  1890 
       
  1891 	cSelect->SetMediaIdsL(mediaIds, iMediaIdMatchType);
       
  1892 
       
  1893 
       
  1894  	if (*iMimeType != KNullDesC8)
       
  1895 		{
       
  1896 		fSelect->SetMatchToMimeTypeL(*iMimeType);//We match to mime type
       
  1897 		}
       
  1898 	else
       
  1899 		fSelect->SetMatchToUriL(*iUrl);
       
  1900 
       
  1901 
       
  1902 	TControllerMode mode = iCurrentConfig->iControllerMode;
       
  1903 	if (mode == EPlayback || mode == EConvert)
       
  1904 		cSelect->SetRequiredPlayFormatSupportL(*fSelect);
       
  1905 	if (mode == ERecord || mode == EConvert)
       
  1906 		cSelect->SetRequiredRecordFormatSupportL(*fSelect);
       
  1907 
       
  1908 	cSelect->ListImplementationsL(iControllers);
       
  1909 
       
  1910 	iControllerCount = iControllers.Count();
       
  1911 	if (iControllerCount == 0)
       
  1912 		User::Leave(KErrNotSupported);
       
  1913 
       
  1914 	// Clean up
       
  1915 	// cSelect, fSelect, mediaIds
       
  1916 	CleanupStack::PopAndDestroy(3, cSelect);
       
  1917 	}
       
  1918 
       
  1919 void CMMFFindAndOpenController::BuildControllerListFormatL()
       
  1920 	{
       
  1921     #if _DEBUG
       
  1922       RDebug::Print(_L("CMMFFindAndOpenController::BuildControllerListFormatL"));
       
  1923     #endif
       
  1924 	// Retrieve a list of possible controllers from ECOM
       
  1925 	// If we don't have a match, leave with unsupported
       
  1926 
       
  1927 	iControllers.ResetAndDestroy();
       
  1928 	iPrioritisedControllers.Reset();
       
  1929 
       
  1930 	CMMFControllerPluginSelectionParameters* cSelect = CMMFControllerPluginSelectionParameters::NewLC();
       
  1931 
       
  1932 	// Select the media IDs to allow
       
  1933 	RArray<TUid> mediaIds;
       
  1934 	CleanupClosePushL(mediaIds);
       
  1935 	User::LeaveIfError(mediaIds.Append(iMediaId));
       
  1936 
       
  1937 	cSelect->SetMediaIdsL(mediaIds, iMediaIdMatchType);
       
  1938 
       
  1939 	CMMFFormatSelectionParameters* fSelect = CMMFFormatSelectionParameters::NewLC();
       
  1940 
       
  1941 	TControllerMode mode = iCurrentConfig->iControllerMode;
       
  1942 	if (mode == EPlayback || mode == EConvert)
       
  1943 		cSelect->SetRequiredPlayFormatSupportL(*fSelect);
       
  1944 	if (mode == ERecord || mode == EConvert)
       
  1945 		cSelect->SetRequiredRecordFormatSupportL(*fSelect);
       
  1946 
       
  1947 	//Obtain a list of the controllers
       
  1948 	cSelect->ListImplementationsL(iControllers);
       
  1949 
       
  1950 	CleanupStack::PopAndDestroy(3, cSelect); // cSelect, mediaIds, fSelect
       
  1951 
       
  1952 	iControllerCount = iControllers.Count();
       
  1953 	if (iControllerCount == 0)
       
  1954 		User::Leave(KErrNotSupported);
       
  1955 
       
  1956 	TUid formatUidPrimary;
       
  1957 	TUid formatUidSecondary;
       
  1958 	if (mode == ERecord)
       
  1959 		{
       
  1960 		formatUidSecondary = iFormatUid;
       
  1961 		formatUidPrimary = iFormatUidSecondary;
       
  1962 		}
       
  1963 	else
       
  1964 		{
       
  1965 		formatUidPrimary = iFormatUid;
       
  1966 		formatUidSecondary = iFormatUidSecondary;
       
  1967 		}
       
  1968 
       
  1969 	for (TInt controllerIndex=0; controllerIndex < iControllers.Count(); controllerIndex++)
       
  1970 		{
       
  1971 		const RMMFFormatImplInfoArray& recFormatInfo = iControllers[controllerIndex]->RecordFormats();
       
  1972 		const RMMFFormatImplInfoArray& playFormatInfo = iControllers[controllerIndex]->PlayFormats();
       
  1973 
       
  1974 		TBool playFormatMatched = EFalse;
       
  1975 		TBool recordFormatMatched = EFalse;
       
  1976 
       
  1977 		if (formatUidPrimary == KNullUid)
       
  1978 			{
       
  1979 			playFormatMatched = ETrue;
       
  1980 			}
       
  1981 		else
       
  1982 			{
       
  1983 			for(TInt playFormatIndex =0; playFormatIndex < playFormatInfo.Count(); playFormatIndex++)
       
  1984 				{
       
  1985 				if(playFormatInfo[playFormatIndex]->Uid() == formatUidPrimary)
       
  1986 					{
       
  1987 					playFormatMatched = ETrue;
       
  1988 					break;
       
  1989 					}
       
  1990 				}
       
  1991 			}
       
  1992 
       
  1993 		if (formatUidSecondary == KNullUid)
       
  1994 			{
       
  1995 			recordFormatMatched = ETrue;
       
  1996 			}
       
  1997 		else
       
  1998 			{
       
  1999 			for (TInt recFormatIndex =0; recFormatIndex < recFormatInfo.Count(); recFormatIndex++)
       
  2000 				{
       
  2001 				if (recFormatInfo[recFormatIndex]->Uid() == formatUidSecondary)
       
  2002 					{
       
  2003 					recordFormatMatched = ETrue;
       
  2004 					break;
       
  2005 					}
       
  2006 				}
       
  2007 			}
       
  2008 
       
  2009 		if (playFormatMatched && recordFormatMatched)
       
  2010 			User::LeaveIfError(iPrioritisedControllers.Append(iControllers[controllerIndex]));
       
  2011 		}
       
  2012 
       
  2013 	iControllerCount = iPrioritisedControllers.Count();
       
  2014 	if (iControllerCount == 0)
       
  2015 		User::Leave(KErrNotSupported);
       
  2016 	}
       
  2017 
       
  2018 CMMSourceSink* CMMFFindAndOpenController::CreateSourceSinkL(const TSourceSink& aParams)
       
  2019 	{
       
  2020 	if (aParams.iUseFileHandle)
       
  2021 		{
       
  2022 		return CMMFileSourceSink::NewL(aParams.iUid, aParams.iFileHandle);
       
  2023 		}
       
  2024 	return CMMSourceSink::NewL(aParams.iUid, aParams.iConfigData);
       
  2025 	}
       
  2026 
       
  2027 
       
  2028 CMMSourceSink* CMMFFindAndOpenController::CreateSourceSinkL(const TMMSource& aSource)
       
  2029 	{
       
  2030 	if (!(aSource.SourceType()==KUidMMFileSource ||
       
  2031 		aSource.SourceType()==KUidMMFileHandleSource))
       
  2032 		User::Leave(KErrNotSupported);
       
  2033 
       
  2034 	return CMMFileSourceSink::NewL(KUidMmfFileSource, aSource);
       
  2035 	}
       
  2036 
       
  2037 
       
  2038 
       
  2039  CMMFFindAndOpenController::TSourceSink::TSourceSink(TUid aUid, const TDesC8& aConfigData)
       
  2040 	: iConfigData(aConfigData)
       
  2041 	{
       
  2042 	iUid = aUid;
       
  2043 
       
  2044 	iUseFileHandle = EFalse;
       
  2045 	}
       
  2046 
       
  2047  CMMFFindAndOpenController::TSourceSink::TSourceSink(TUid aUid, const RFile& aFile)
       
  2048 	: iConfigData(KNullDesC8)
       
  2049 	{
       
  2050 	iUid = aUid;
       
  2051 
       
  2052 	iFileHandle = aFile;
       
  2053 	iUseFileHandle = ETrue;
       
  2054 	}
       
  2055 
       
  2056 CMMFFindAndOpenController::CConfig::CConfig()
       
  2057 	{
       
  2058     #if _DEBUG
       
  2059       RDebug::Print(_L("CMMFFindAndOpenController::CConfig"));
       
  2060     #endif
       
  2061 	}
       
  2062 
       
  2063 void CMMFFindAndOpenController::CConfig::Close()
       
  2064 	{
       
  2065     #if _DEBUG
       
  2066       RDebug::Print(_L("CMMFFindAndOpenController::Close"));
       
  2067     #endif
       
  2068 	delete iSource;
       
  2069 	iSource = NULL;
       
  2070 	delete iSink;
       
  2071 	iSink = NULL;
       
  2072 	}
       
  2073 CMMFFindAndOpenController::CConfig::~CConfig()
       
  2074 	{
       
  2075     #if _DEBUG
       
  2076       RDebug::Print(_L("CMMFFindAndOpenController::~CConfig"));
       
  2077     #endif
       
  2078 	Close();
       
  2079 	}
       
  2080 
       
  2081  CMMSourceSink* CMMSourceSink::NewLC(TUid aUid, const TDesC8& aDescriptor)
       
  2082 	{
       
  2083 	CMMSourceSink* self = new (ELeave) CMMSourceSink(aUid);
       
  2084 	CleanupStack::PushL(self);
       
  2085 	self->ConstructL(aDescriptor);
       
  2086 	return self;
       
  2087 	}
       
  2088 
       
  2089  CMMSourceSink* CMMSourceSink::NewL(TUid aUid, const TDesC8& aDescriptor)
       
  2090 	{
       
  2091 	CMMSourceSink* sourcesink = CMMSourceSink::NewLC(aUid, aDescriptor);
       
  2092 	CleanupStack::Pop(sourcesink);
       
  2093 	return sourcesink;
       
  2094 	}
       
  2095 
       
  2096 CMMSourceSink::CMMSourceSink(TUid aUid)
       
  2097 	: iUid(aUid)
       
  2098 	{
       
  2099 	}
       
  2100 
       
  2101 CMMSourceSink::~CMMSourceSink()
       
  2102 	{
       
  2103 	delete iBuf;
       
  2104 	}
       
  2105 
       
  2106 void CMMSourceSink::ConstructL(const TDesC8& aDescriptor)
       
  2107 	{
       
  2108 	iBuf = aDescriptor.AllocL();
       
  2109 	}
       
  2110 
       
  2111 TUid CMMSourceSink::SourceSinkUid() const
       
  2112 	{
       
  2113 	return iUid;
       
  2114 	}
       
  2115 
       
  2116 const TDesC8& CMMSourceSink::SourceSinkData() const
       
  2117 	{
       
  2118 	return *iBuf;
       
  2119 	}
       
  2120 
       
  2121  CMMFileSourceSink* CMMFileSourceSink::NewLC(TUid aUid, const RFile& aFile)
       
  2122 	{
       
  2123 	CMMFileSourceSink* self = new (ELeave) CMMFileSourceSink(aUid);
       
  2124 	CleanupStack::PushL(self);
       
  2125 	self->ConstructL(aFile);
       
  2126 	return self;
       
  2127 	}
       
  2128 
       
  2129  CMMFileSourceSink* CMMFileSourceSink::NewL(TUid aUid, const RFile& aFile)
       
  2130 	{
       
  2131 	CMMFileSourceSink* sourcesink = CMMFileSourceSink::NewLC(aUid, aFile);
       
  2132 	CleanupStack::Pop(sourcesink);
       
  2133 	return sourcesink;
       
  2134 	}
       
  2135 
       
  2136 CMMFileSourceSink::CMMFileSourceSink(TUid aUid)
       
  2137 	: CMMSourceSink(aUid)
       
  2138 	{
       
  2139 	}
       
  2140 
       
  2141 void CMMFileSourceSink::ConstructL(const RFile& aFile)
       
  2142 	{
       
  2143 	iHandle.Duplicate(aFile);
       
  2144 	iUsingFileHandle = ETrue;
       
  2145 	iFileName = HBufC::NewMaxL(KMaxFileName);
       
  2146 	TPtr fileNamePtr = iFileName->Des();
       
  2147 	iHandle.Name(fileNamePtr);
       
  2148 	DoCreateFileHandleSourceConfigDataL();
       
  2149 	}
       
  2150 const TInt KExpandSize = 100;
       
  2151 
       
  2152 void CMMFileSourceSink::DoCreateFileHandleSourceConfigDataL()
       
  2153 	{
       
  2154 	CBufFlat* buf = CBufFlat::NewL(KExpandSize);
       
  2155 	CleanupStack::PushL(buf);
       
  2156 	RBufWriteStream stream;
       
  2157 	stream.Open(*buf);
       
  2158 	CleanupClosePushL(stream);
       
  2159 
       
  2160 	TPckgBuf<RFile*> fileptr(&iHandle);
       
  2161 	stream.WriteInt32L(KMMFileHandleSourceUid.iUid);
       
  2162 
       
  2163 	stream.WriteL(fileptr);
       
  2164 
       
  2165 	TInt length = 0;
       
  2166 	if (iUniqueId != NULL)
       
  2167 		length = iUniqueId->Length();
       
  2168 	stream.WriteInt32L(length);
       
  2169 	if (length>0)
       
  2170 		stream.WriteL(*iUniqueId);
       
  2171 
       
  2172 	stream.WriteInt32L(iEnableUI);
       
  2173 
       
  2174 	stream.CommitL();
       
  2175 	CleanupStack::PopAndDestroy(&stream);
       
  2176 
       
  2177 	iSourceSinkData = buf->Ptr(0).AllocL();
       
  2178 
       
  2179 	CleanupStack::PopAndDestroy(buf);
       
  2180 	}
       
  2181 
       
  2182 const TDesC8& CMMFileSourceSink::SourceSinkData() const
       
  2183 	{
       
  2184 	ASSERT(iSourceSinkData);
       
  2185 	return *iSourceSinkData;
       
  2186 	}
       
  2187 
       
  2188 CMMFileSourceSink::~CMMFileSourceSink()
       
  2189 	{
       
  2190 	iHandle.Close();
       
  2191 	delete iFileName;
       
  2192 	delete iSourceSinkData;
       
  2193 	delete iUniqueId;
       
  2194 	}
       
  2195 
       
  2196  CMMFileSourceSink* CMMFileSourceSink::NewLC(TUid aUid, const TMMSource& aSource)
       
  2197 	{
       
  2198 	CMMFileSourceSink* self = new (ELeave) CMMFileSourceSink(aUid);
       
  2199 	CleanupStack::PushL(self);
       
  2200 	self->ConstructL(aSource);
       
  2201 	return self;
       
  2202 	}
       
  2203 
       
  2204  CMMFileSourceSink* CMMFileSourceSink::NewL(TUid aUid, const TMMSource& aSource)
       
  2205 	{
       
  2206 	CMMFileSourceSink* sourcesink = CMMFileSourceSink::NewLC(aUid, aSource);
       
  2207 	CleanupStack::Pop(sourcesink);
       
  2208 	return sourcesink;
       
  2209 	}
       
  2210 
       
  2211 void CMMFileSourceSink::ConstructL(const TMMSource& aSource)
       
  2212 	{
       
  2213 	iUniqueId = aSource.UniqueId().AllocL();
       
  2214 	iIntent = aSource.Intent();
       
  2215 	iEnableUI = aSource.IsUIEnabled();
       
  2216 
       
  2217 	if (aSource.SourceType() == KUidMMFileSource)
       
  2218 		{
       
  2219 		const TMMFileSource& fileSource = static_cast<const TMMFileSource&>(aSource);
       
  2220 		iFileName = fileSource.Name().AllocL();
       
  2221 
       
  2222 		DoCreateFileSourceConfigDataL();
       
  2223 		}
       
  2224 	else if (aSource.SourceType() == KUidMMFileHandleSource)
       
  2225 		{
       
  2226 		const TMMFileHandleSource& fileHandleSource = static_cast<const TMMFileHandleSource&>(aSource);
       
  2227 		iHandle.Duplicate(fileHandleSource.Handle());
       
  2228 		iUsingFileHandle = ETrue;
       
  2229 		iFileName = HBufC::NewMaxL(KMaxFileName);
       
  2230 		TPtr fileNamePtr = iFileName->Des();
       
  2231 		iHandle.Name(fileNamePtr);
       
  2232 
       
  2233 		DoCreateFileHandleSourceConfigDataL();
       
  2234 		}
       
  2235 	else
       
  2236 		{
       
  2237 		User::Leave(KErrNotSupported);
       
  2238 		}
       
  2239 	}
       
  2240 
       
  2241 void CMMSourceSink::EvaluateIntentL()
       
  2242 	{
       
  2243 	}
       
  2244 
       
  2245 void CMMFileSourceSink::EvaluateIntentL()
       
  2246 	{
       
  2247 	if (iUsingFileHandle)
       
  2248 		{
       
  2249    		ContentAccess::CContent* Content = ContentAccess::CContent::NewLC(iHandle);
       
  2250    		Content->OpenContentLC(iIntent, *iUniqueId);
       
  2251    		CleanupStack::PopAndDestroy(2, Content);
       
  2252 		}
       
  2253 	else
       
  2254 		{
       
  2255 		ContentAccess::CContent* Content = ContentAccess::CContent::NewLC(*iFileName);
       
  2256    		Content->OpenContentLC(iIntent, *iUniqueId);
       
  2257    		CleanupStack::PopAndDestroy(2, Content);
       
  2258 		}
       
  2259 	}
       
  2260 
       
  2261 
       
  2262 
       
  2263  void CMMFileSourceSink::EvaluateIntentL(ContentAccess::TIntent aIntent)
       
  2264 	{
       
  2265 	if (iUsingFileHandle)
       
  2266 		{
       
  2267    		ContentAccess::CContent* Content = ContentAccess::CContent::NewLC(iHandle);
       
  2268    		Content->OpenContentLC(aIntent, *iUniqueId);
       
  2269    		CleanupStack::PopAndDestroy(2, Content);
       
  2270 		}
       
  2271 	else
       
  2272 		{
       
  2273 		ContentAccess::CContent* Content = ContentAccess::CContent::NewLC(*iFileName);
       
  2274    		Content->OpenContentLC(aIntent, *iUniqueId);
       
  2275    		CleanupStack::PopAndDestroy(2, Content);
       
  2276 		}
       
  2277 	}
       
  2278 
       
  2279 void CMMFileSourceSink::DoCreateFileSourceConfigDataL()
       
  2280 	{
       
  2281 	CBufFlat* buf = CBufFlat::NewL(KExpandSize);
       
  2282 	CleanupStack::PushL(buf);
       
  2283 	RBufWriteStream stream;
       
  2284 	stream.Open(*buf);
       
  2285 	CleanupClosePushL(stream);
       
  2286 
       
  2287 	stream.WriteInt32L(KMMFileSourceUid.iUid);
       
  2288 	stream.WriteInt32L(iFileName->Length());
       
  2289 	stream.WriteL(*iFileName);
       
  2290 	TInt length = 0;
       
  2291 	if (iUniqueId != NULL)
       
  2292 		length = iUniqueId->Length();
       
  2293 	stream.WriteInt32L(length);
       
  2294 	if (length>0)
       
  2295 		stream.WriteL(*iUniqueId);
       
  2296 
       
  2297 	stream.WriteInt32L(iEnableUI);
       
  2298 
       
  2299 	stream.CommitL();
       
  2300 	CleanupStack::PopAndDestroy(&stream);
       
  2301 
       
  2302 	iSourceSinkData = buf->Ptr(0).AllocL();
       
  2303 
       
  2304 	CleanupStack::PopAndDestroy(buf);
       
  2305 	}
       
  2306 
       
  2307 
       
  2308