mmlibs/mmfw/src/server/BaseClasses/Mmfformat.cpp
changeset 0 40261b775718
child 11 d5f04de580b7
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <mmf/common/mmfcontrollerpluginresolver.h>
       
    17 #include <mmf/server/mmfdatabuffer.h>
       
    18 #include <mmf/common/mmfutilities.h>
       
    19 #include <mmf/server/Mmfclip.h>
       
    20 #include <mmf/server/MmfFile.h>
       
    21 #include <mmf/server/mmfformat.h>
       
    22 
       
    23 //static const TUid KUidMmfPluginInterfaceFormatDecode = {KMmfUidPluginInterfaceFormatDecode};
       
    24 //static const TUid KUidMmfPluginInterfaceFormatEncode = {KMmfUidPluginInterfaceFormatEncode};
       
    25 
       
    26 const TInt KMmfHeaderBufferSize = 512 ;		//512 bytes read to parse the header
       
    27 
       
    28 CMMFFormatDecode* CMMFFormatDecode::CreateFormatL(TUid aUid, MDataSource* aSource)
       
    29 	{
       
    30 	CMMFFormatDecode* s = REINTERPRET_CAST( CMMFFormatDecode*,
       
    31 				REComSession::CreateImplementationL( aUid, _FOFF( CMMFFormatDecode, iDtor_ID_Key),
       
    32 				STATIC_CAST( TAny*, aSource ) ) ) ;
       
    33 	s->iImplementationUid = aUid;
       
    34 	return s;
       
    35 	}
       
    36 
       
    37 /**
       
    38 Allocates and constructs an ECom format decode object.
       
    39 
       
    40 This is used to explicitly instantiate a format decoder where the UID is known. This method might
       
    41 be used by controllers that only support one type of format such that the UID of the format is
       
    42 already known. For example, if an mp3 controller has been instantiated, there is no need for any
       
    43 further format recognition as this has already been performed in the controller instantiation, thus
       
    44 the controller can instantiate an mp3 format directly from it’s UID.
       
    45 
       
    46 @param  aUid 
       
    47         The implementation UID. This is used by Com to create the plugin.
       
    48 @param  aSource 
       
    49         The controller MDataSource and is the source of the data for the format decode plugin. The 
       
    50         format decode plugin is the sink of data for the MDataSource.
       
    51 
       
    52 @return If successful, returns the address of the format decode plugin object created. If not successful, 
       
    53         leaves with KErrNotFound.
       
    54 */
       
    55 EXPORT_C CMMFFormatDecode* CMMFFormatDecode::NewL( TUid aUid, MDataSource* aSource )
       
    56 	{
       
    57 	return CreateFormatL(aUid, aSource);
       
    58 	}
       
    59 
       
    60 
       
    61 
       
    62 /**
       
    63 Attempt to locate and instantiate a FormatDecode using a filename or an extension.
       
    64 
       
    65 Only the extension is used.  If no extension  is supplied (no dot is present) the whole of the 
       
    66 filename will be treated as the extension.
       
    67 
       
    68 If the file already exists, the file header is scanned to find a match in the opaque_data field of 
       
    69 the resource file.
       
    70 
       
    71 @param  aFileName
       
    72         The file name of target file.  May be extension only or may include full path.
       
    73 @param  aSource
       
    74         The controller's MDataSource. This is the source of the data for the format decode plugin. This must
       
    75         be a CMMFFile source when instantiating a CMMFFormatDecode using a file name.
       
    76 @param  aPreferredSupplier
       
    77         If this is provided the list of matching plugins will be further searched for the latest version of a
       
    78         plugin supplied by supplier named.
       
    79 
       
    80 @return If successful returns an instantiated CMMFFormatDecode from a plugin. If not successful, leaves with KErrNotFound.
       
    81 */
       
    82 EXPORT_C CMMFFormatDecode* CMMFFormatDecode::NewL( const TDesC16& aFileName, MDataSource* aSource, const TDesC& aPreferredSupplier )
       
    83 	{
       
    84 	CMMFFormatDecodePluginSelectionParameters* pluginSelector = CMMFFormatDecodePluginSelectionParameters::NewLC();
       
    85 	CMMFFormatSelectionParameters* formatParams = CMMFFormatSelectionParameters::NewLC();
       
    86 	formatParams->SetMatchToFileNameL(aFileName);
       
    87 	pluginSelector->SetRequiredFormatSupportL(*formatParams);
       
    88 	if (aPreferredSupplier.Length() > 0)
       
    89 		pluginSelector->SetPreferredSupplierL(aPreferredSupplier, CMMFPluginSelectionParameters::EOnlyPreferredSupplierPluginsReturned);
       
    90 
       
    91 	// Instantiate this format
       
    92 	CMMFFormatDecode* theChosenOne = 
       
    93 		MMFFormatEcomUtilities::SelectFormatDecodePluginL(*pluginSelector, aSource);
       
    94 
       
    95 	// Now clean up.
       
    96 	CleanupStack::PopAndDestroy(2);//formatParams, pluginSelector
       
    97 
       
    98 	return theChosenOne;
       
    99 	}
       
   100 
       
   101 /**
       
   102 Attempt to locate and instantiate a FormatDecode using a filename or an extension.
       
   103 
       
   104 Only the extension is used.  If no extension  is supplied (no dot is present) the whole of the 
       
   105 filename will be treated as the extension.
       
   106 
       
   107 If the file already exists, the file header is scanned to find a match in the opaque_data field of 
       
   108 the resource file.
       
   109 
       
   110 @param  aFileName
       
   111         The file name of target file.  May be extension only or may include full path.
       
   112 @param  aSource
       
   113         The controller's MDataSource. This is the source of the data for the format decode plugin. This must
       
   114         be a CMMFFile source when instantiating a CMMFFormatDecode using a file name.
       
   115 @param  aPreferredSupplier
       
   116         If this is provided the list of matching plugins will be further searched for the latest version of a
       
   117         plugin supplied by supplier named.
       
   118 @param  aSupportsCustomInterfaces
       
   119 		Indicates whether the instantiated FormatDecode supports custom interfaces.
       
   120 
       
   121 @return If successful returns an instantiated CMMFFormatDecode from a plugin. If not successful, leaves with KErrNotFound.
       
   122 */
       
   123 EXPORT_C CMMFFormatDecode* CMMFFormatDecode::NewL( const TDesC16& aFileName, MDataSource* aSource, const TDesC& aPreferredSupplier, TBool& aSupportsCustomInterfaces )
       
   124 	{
       
   125 	CMMFFormatDecodePluginSelectionParameters* pluginSelector = CMMFFormatDecodePluginSelectionParameters::NewLC();
       
   126 	CMMFFormatSelectionParameters* formatParams = CMMFFormatSelectionParameters::NewLC();
       
   127 	formatParams->SetMatchToFileNameL(aFileName);
       
   128 	pluginSelector->SetRequiredFormatSupportL(*formatParams);
       
   129 	if (aPreferredSupplier.Length() > 0)
       
   130 		pluginSelector->SetPreferredSupplierL(aPreferredSupplier, CMMFPluginSelectionParameters::EOnlyPreferredSupplierPluginsReturned);
       
   131 
       
   132 	// Instantiate this format
       
   133 	CMMFFormatDecode* theChosenOne = 
       
   134 		MMFFormatEcomUtilities::SelectFormatDecodePluginL(*pluginSelector, aSource, aSupportsCustomInterfaces);
       
   135 
       
   136 	// Now clean up.
       
   137 	CleanupStack::PopAndDestroy(2);//formatParams, pluginSelector
       
   138 
       
   139 	return theChosenOne;
       
   140 	}
       
   141 
       
   142 
       
   143 /**
       
   144 Attempts to locate and instantiate a CMMFFormatDecode using data in a buffer.  The buffer is expected to contain 
       
   145 header data (from a file, stream or descriptor).
       
   146 
       
   147 Signatures (supplied by the plugin registry information) are sought in aSourceHeader.
       
   148 
       
   149 This function uses the match string as a resolver parameter. The format base class uses the match string
       
   150 to find a match to the match string defined in the opaque_data field of the resource file. The
       
   151 match string would typically be a signature for a particular format usually defined in the format header.
       
   152 
       
   153 @param  aSourceHeader
       
   154         The data which is searched for matching signatures.
       
   155 @param  aSource
       
   156         The controller's MDataSource and the source of the data for the format decode plugin.
       
   157 @param  aPreferredSupplier
       
   158         If this is provided the list of matching plugins will be further searched for the latest version of a
       
   159         plugin supplied by the specified supplier.
       
   160 
       
   161 @return If successful returns an instantiated CMMFFormatDecode from a plugin.  If not successful, leaves with KErrNotFound.
       
   162 */
       
   163 EXPORT_C CMMFFormatDecode* CMMFFormatDecode::NewL( const TDesC8& aSourceHeader, MDataSource* aSource, const TDesC& aPreferredSupplier )
       
   164 	{
       
   165 	CMMFFormatDecodePluginSelectionParameters* pluginSelector = CMMFFormatDecodePluginSelectionParameters::NewLC();
       
   166 	CMMFFormatSelectionParameters* formatParams = CMMFFormatSelectionParameters::NewLC();
       
   167 	formatParams->SetMatchToHeaderDataL(aSourceHeader);
       
   168 	pluginSelector->SetRequiredFormatSupportL(*formatParams);
       
   169 	if (aPreferredSupplier.Length() > 0)
       
   170 		pluginSelector->SetPreferredSupplierL(aPreferredSupplier, CMMFPluginSelectionParameters::EOnlyPreferredSupplierPluginsReturned);
       
   171 
       
   172 	// Instantiate this format
       
   173 	CMMFFormatDecode* theChosenOne = 
       
   174 		MMFFormatEcomUtilities::SelectFormatDecodePluginL(*pluginSelector, aSource);
       
   175 
       
   176 	// Now clean up.
       
   177 	CleanupStack::PopAndDestroy(2);//formatParams, pluginSelector
       
   178 
       
   179 	return theChosenOne;
       
   180 	}
       
   181 
       
   182 /**
       
   183 Attempts to locate and instantiate a CMMFFormatDecode using data in a buffer.  The buffer is expected to contain 
       
   184 header data (from a file, stream or descriptor).
       
   185 
       
   186 Signatures (supplied by the plugin registry information) are sought in aSourceHeader.
       
   187 
       
   188 This function uses the match string as a resolver parameter. The format base class uses the match string
       
   189 to find a match to the match string defined in the opaque_data field of the resource file. The
       
   190 match string would typically be a signature for a particular format usually defined in the format header.
       
   191 
       
   192 @param  aSourceHeader
       
   193         The data which is searched for matching signatures.
       
   194 @param  aSource
       
   195         The controller's MDataSource and the source of the data for the format decode plugin.
       
   196 @param  aPreferredSupplier
       
   197         If this is provided the list of matching plugins will be further searched for the latest version of a
       
   198         plugin supplied by the specified supplier.
       
   199 @param  aSupportsCustomInterfaces
       
   200 		Indicates whether the instantiated FormatDecode supports custom interfaces.
       
   201 
       
   202 @return If successful returns an instantiated CMMFFormatDecode from a plugin.  If not successful, leaves with KErrNotFound.
       
   203 */
       
   204 EXPORT_C CMMFFormatDecode* CMMFFormatDecode::NewL( const TDesC8& aSourceHeader, MDataSource* aSource, const TDesC& aPreferredSupplier, TBool& aSupportsCustomInterfaces )
       
   205 	{
       
   206 	CMMFFormatDecodePluginSelectionParameters* pluginSelector = CMMFFormatDecodePluginSelectionParameters::NewLC();
       
   207 	CMMFFormatSelectionParameters* formatParams = CMMFFormatSelectionParameters::NewLC();
       
   208 	formatParams->SetMatchToHeaderDataL(aSourceHeader);
       
   209 	pluginSelector->SetRequiredFormatSupportL(*formatParams);
       
   210 	if (aPreferredSupplier.Length() > 0)
       
   211 		pluginSelector->SetPreferredSupplierL(aPreferredSupplier, CMMFPluginSelectionParameters::EOnlyPreferredSupplierPluginsReturned);
       
   212 
       
   213 	// Instantiate this format
       
   214 	CMMFFormatDecode* theChosenOne = 
       
   215 		MMFFormatEcomUtilities::SelectFormatDecodePluginL(*pluginSelector, aSource, aSupportsCustomInterfaces);
       
   216 
       
   217 	// Now clean up.
       
   218 	CleanupStack::PopAndDestroy(2);//formatParams, pluginSelector
       
   219 
       
   220 	return theChosenOne;
       
   221 	}
       
   222 
       
   223 /**
       
   224 Attempts to locate and instantiate a CMMFFormatDecode using data from MDataSource.  
       
   225 
       
   226 The data is expected to contain header data (from a file, stream or descriptor). Signatures 
       
   227 (supplied by the plugin registry information) are sought in aSource.
       
   228 
       
   229 @param  aSource
       
   230         Header data. Must be derived from CMMFClip.
       
   231 @param  aPreferredSupplier
       
   232         If this is provided, the list of matching plugins will be further searched for the latest version of a
       
   233         plugin supplied by the specified supplier.
       
   234 
       
   235 @return If successful returns an instantiated CMMFFormatDecode from a plugin. If not successful, leaves with KErrNotFound.
       
   236 */
       
   237 EXPORT_C CMMFFormatDecode* CMMFFormatDecode::NewL( MDataSource* aSource, const TDesC& aPreferredSupplier )
       
   238 	{
       
   239 	// Read header data from aSource.  Call source header version
       
   240 
       
   241 	if ( !( (aSource->DataSourceType() == KUidMmfFileSource ) || ( aSource->DataSourceType() == KUidMmfDescriptorSource) ) )
       
   242 		User::Leave( KErrNotSupported ) ;
       
   243 
       
   244 	CMMFDataBuffer* buffer = CMMFDataBuffer::NewL(KMmfHeaderBufferSize) ;
       
   245 	CleanupStack::PushL( buffer ) ;
       
   246 
       
   247 	aSource->SourcePrimeL();
       
   248 	TCleanupItem srcCleanupItem(DoDataSourceStop, aSource);
       
   249 	CleanupStack::PushL(srcCleanupItem);
       
   250 
       
   251 	STATIC_CAST( CMMFClip*, aSource )->ReadBufferL( buffer, 0 ) ;
       
   252 
       
   253 	CleanupStack::Pop();
       
   254 	aSource->SourceStopL();
       
   255 
       
   256 	// attempt to instantiate the format by header data
       
   257 	// if this fails, try using the file extension
       
   258 	CMMFFormatDecode* ret = NULL;
       
   259 	TInt err, errFile;
       
   260 	TRAP(err, ret = NewL( buffer->Data(), aSource, aPreferredSupplier ));
       
   261 	if (err != KErrNone && aSource->DataSourceType() == KUidMmfFileSource)
       
   262 		{
       
   263 		CMMFFile* mmfFile = static_cast<CMMFFile*> (aSource);
       
   264 		TRAP(errFile, ret = NewL( mmfFile->FullName(), aSource, aPreferredSupplier ));
       
   265 		if (errFile == KErrNone)
       
   266 			err = errFile;
       
   267 		}
       
   268 	User::LeaveIfError(err);
       
   269 
       
   270 	CleanupStack::PopAndDestroy() ; // buffer
       
   271 	return ret ;
       
   272 	
       
   273 	}
       
   274 
       
   275 /**
       
   276 Attempts to locate and instantiate a CMMFFormatDecode using data from MDataSource.  
       
   277 
       
   278 The data is expected to contain header data (from a file, stream or descriptor). Signatures 
       
   279 (supplied by the plugin registry information) are sought in aSource.
       
   280 
       
   281 @param  aSource
       
   282         Header data. Must be derived from CMMFClip.
       
   283 @param  aPreferredSupplier
       
   284         If this is provided, the list of matching plugins will be further searched for the latest version of a
       
   285         plugin supplied by the specified supplier.
       
   286 @param  aSupportsCustomInterfaces
       
   287 		Indicates whether the instantiated FormatDecode supports custom interfaces.
       
   288 
       
   289 @return If successful returns an instantiated CMMFFormatDecode from a plugin. If not successful, leaves with KErrNotFound.
       
   290 */
       
   291 EXPORT_C CMMFFormatDecode* CMMFFormatDecode::NewL( MDataSource* aSource, const TDesC& aPreferredSupplier, TBool& aSupportsCustomInterfaces )
       
   292 	{
       
   293 	// Read header data from aSource.  Call source header version
       
   294 
       
   295 	if ( !( (aSource->DataSourceType() == KUidMmfFileSource ) || ( aSource->DataSourceType() == KUidMmfDescriptorSource) ) )
       
   296 		User::Leave( KErrNotSupported ) ;
       
   297 
       
   298 	CMMFDataBuffer* buffer = CMMFDataBuffer::NewL(KMmfHeaderBufferSize) ;
       
   299 	CleanupStack::PushL( buffer ) ;
       
   300 
       
   301 	aSource->SourcePrimeL();
       
   302 	TCleanupItem srcCleanupItem(DoDataSourceStop, aSource);
       
   303 	CleanupStack::PushL(srcCleanupItem);
       
   304 
       
   305 	STATIC_CAST( CMMFClip*, aSource )->ReadBufferL( buffer, 0 ) ;
       
   306 
       
   307 	CleanupStack::Pop();
       
   308 	aSource->SourceStopL();
       
   309 
       
   310 	// attempt to instantiate the format by header data
       
   311 	// if this fails, try using the file extension
       
   312 	CMMFFormatDecode* ret = NULL;
       
   313 	TInt err, errFile;
       
   314 	TRAP(err, ret = NewL( buffer->Data(), aSource, aPreferredSupplier, aSupportsCustomInterfaces ));
       
   315 	if (err != KErrNone && aSource->DataSourceType() == KUidMmfFileSource)
       
   316 		{
       
   317 		CMMFFile* mmfFile = static_cast<CMMFFile*> (aSource);
       
   318 		TRAP(errFile, ret = NewL( mmfFile->FullName(), aSource, aPreferredSupplier, aSupportsCustomInterfaces ));
       
   319 		if (errFile == KErrNone)
       
   320 			err = errFile;
       
   321 		}
       
   322 	User::LeaveIfError(err);
       
   323 
       
   324 	CleanupStack::PopAndDestroy() ; // buffer
       
   325 	return ret ;
       
   326 	
       
   327 	}
       
   328 
       
   329 CMMFFormatEncode* CMMFFormatEncode::CreateFormatL(TUid aUid, MDataSink* aSink)
       
   330 	{
       
   331 	CMMFFormatEncode* s = REINTERPRET_CAST( CMMFFormatEncode*,
       
   332 									REComSession::CreateImplementationL( aUid, _FOFF( CMMFFormatEncode, iDtor_ID_Key ),
       
   333 									STATIC_CAST( TAny*, aSink ) ) ) ;
       
   334 	s->iImplementationUid = aUid;
       
   335 	return s;
       
   336 	}
       
   337 
       
   338 /**
       
   339 Allocates and constructs an ECom format encode object.
       
   340 
       
   341 @param  aUid
       
   342         The implementation UID.
       
   343 @param  aSink
       
   344         The data sink.
       
   345 
       
   346 @return If successful, returns the address of the format decode plugin object created. If not successful,
       
   347         leaves with KErrNotFound.
       
   348 */
       
   349 EXPORT_C CMMFFormatEncode* CMMFFormatEncode::NewL( TUid aUid, MDataSink* aSink )
       
   350 	{
       
   351 	return CreateFormatL(aUid, aSink);
       
   352 	}
       
   353 
       
   354 /**
       
   355 Attempts to locate and instantiate a CMMFFormatEncode using a filename or an extension.
       
   356 
       
   357 Only the extension of the supplied file name is used. If no extension is supplied (ie. no dot is present)
       
   358 the whole of the filename will be treated as the extension.
       
   359 
       
   360 @param  aFileName
       
   361         File name of target file. May be extension only or may include the full path.
       
   362 @param  aSink
       
   363 		The data source.
       
   364 @param  aPreferredSupplier
       
   365         If this is provided, the list of matching plugins will be further searched for the latest version of a
       
   366         plugin supplied by supplier named.
       
   367 
       
   368 @return If successful, returns the address of the format decode plugin object created. If not successful,
       
   369         leaves with KErrNotFound.
       
   370 */
       
   371 EXPORT_C CMMFFormatEncode* CMMFFormatEncode::NewL( const TDesC16& aFileName, MDataSink* aSink, const TDesC& aPreferredSupplier )
       
   372 	{
       
   373 	CMMFFormatEncodePluginSelectionParameters* pluginSelector = CMMFFormatEncodePluginSelectionParameters::NewLC();
       
   374 	CMMFFormatSelectionParameters* formatParams = CMMFFormatSelectionParameters::NewLC();
       
   375 	formatParams->SetMatchToFileNameL(aFileName);
       
   376 	pluginSelector->SetRequiredFormatSupportL(*formatParams);
       
   377 	if (aPreferredSupplier.Length() > 0)
       
   378 		pluginSelector->SetPreferredSupplierL(aPreferredSupplier, CMMFPluginSelectionParameters::EOnlyPreferredSupplierPluginsReturned);
       
   379 
       
   380 	TUid chosenUid = MMFFormatEcomUtilities::SelectFormatPluginL(*pluginSelector);
       
   381 
       
   382 	// Instantiate this format
       
   383 	CMMFFormatEncode* theChosenOne = CreateFormatL(chosenUid, aSink);
       
   384 
       
   385 	// Now clean up.
       
   386 	CleanupStack::PopAndDestroy(2);//formatParams, pluginSelector
       
   387 
       
   388 	return theChosenOne;
       
   389 	}
       
   390 
       
   391 /**
       
   392 Attempts to locate and instantiate a CMMFFormatEncode using data in the specified buffer.
       
   393 
       
   394 The buffer is expected to contain header data (from a file, stream or descriptor).
       
   395 Signatures (supplied by the plugin registry information) are sought in aSourceHeader.
       
   396 
       
   397 @param  aSourceHeader
       
   398         The data which is searched for matching signatures.
       
   399 @param  aSink
       
   400         The data sink.
       
   401 @param  aPreferredSupplier
       
   402         If this is provided the list of matching plugins will be further searched for the latest version of a
       
   403         plugin supplied by supplier named.
       
   404 
       
   405 @return If successful, returns the address of the format decode plugin object created. If not successful,
       
   406         leaves with KErrNotFound.
       
   407 */
       
   408 EXPORT_C CMMFFormatEncode* CMMFFormatEncode::NewL( const TDesC8& aSourceHeader, MDataSink* aSink,  const TDesC& aPreferredSupplier )
       
   409 	{
       
   410 	CMMFFormatEncodePluginSelectionParameters* pluginSelector = CMMFFormatEncodePluginSelectionParameters::NewLC();
       
   411 	CMMFFormatSelectionParameters* formatParams = CMMFFormatSelectionParameters::NewLC();
       
   412 	formatParams->SetMatchToHeaderDataL(aSourceHeader);
       
   413 	pluginSelector->SetRequiredFormatSupportL(*formatParams);
       
   414 	if (aPreferredSupplier.Length() > 0)
       
   415 		pluginSelector->SetPreferredSupplierL(aPreferredSupplier, CMMFPluginSelectionParameters::EOnlyPreferredSupplierPluginsReturned);
       
   416 
       
   417 	TUid chosenUid = MMFFormatEcomUtilities::SelectFormatPluginL(*pluginSelector);
       
   418 
       
   419 	// Instantiate this format
       
   420 	CMMFFormatEncode* theChosenOne = CreateFormatL(chosenUid, aSink);
       
   421 
       
   422 	// Now clean up.
       
   423 	CleanupStack::PopAndDestroy(2);//formatParams, pluginSelector
       
   424 
       
   425 	return theChosenOne;
       
   426 	}
       
   427 
       
   428 /**
       
   429 Attempts to locate and instantiate a CMMFFormatEncode using data from aSink.
       
   430 
       
   431 The data is expected to contain header data (from a file, stream or descriptor).
       
   432 Signatures (supplied by the plugin registry information) are sought in the source header.
       
   433 
       
   434 @param  aSink
       
   435         The header data. Must be derived from CMMFClip.
       
   436 @param  aPreferredSupplier
       
   437         If this is provided, the list of matching plugins will be further searched for the latest version of a
       
   438         plugin supplied by supplier specified.
       
   439 
       
   440 @return If successful, returns the address of the format decode plugin object created. If not successful,
       
   441         leaves with KErrNotFound.
       
   442 */
       
   443 EXPORT_C CMMFFormatEncode* CMMFFormatEncode::NewL( MDataSink* aSink, const TDesC& aPreferredSupplier )
       
   444 	{
       
   445 	// Read header data from aSource.  Call source header version if there is header data, file name version otherwise.
       
   446 
       
   447 	if ( !( (aSink->DataSinkType() == KUidMmfFileSink ) || ( aSink->DataSinkType() == KUidMmfDescriptorSink) ) )
       
   448 		User::Leave( KErrNotSupported ) ;
       
   449 
       
   450 	CMMFDataBuffer* buffer = CMMFDataBuffer::NewL(KMmfHeaderBufferSize) ;
       
   451 	CleanupStack::PushL( buffer ) ;
       
   452 
       
   453 	aSink->SinkPrimeL();
       
   454 	TCleanupItem sinkCleanupItem(DoDataSinkStop, aSink);
       
   455 	CleanupStack::PushL(sinkCleanupItem);
       
   456 
       
   457 	STATIC_CAST( CMMFClip*, aSink )->ReadBufferL( buffer, 0 ) ;
       
   458 
       
   459 	CleanupStack::Pop();
       
   460 	aSink->SinkStopL();
       
   461 
       
   462 	CMMFFormatEncode* ret = NULL ;  // set to null to avoid compiler warning.
       
   463 	// Check for data in the buffer
       
   464 	if (  buffer->BufferSize() != 0 )
       
   465 		ret = NewL( buffer->Data(), aSink, aPreferredSupplier ) ;
       
   466 	else if ( aSink->DataSinkType() == KUidMmfFileSink )
       
   467 		ret = NewL( STATIC_CAST(CMMFFile*, aSink)->Extension(), aSink, aPreferredSupplier ) ;
       
   468 	else
       
   469 		User::Leave( KErrNotSupported ) ;
       
   470 
       
   471 	CleanupStack::PopAndDestroy() ; // buffer
       
   472 	return ret ;
       
   473 	}
       
   474 
       
   475 
       
   476 TUid MMFFormatEcomUtilities::SelectFormatPluginL(const CMMFFormatPluginSelectionParameters& aSelectParams)
       
   477 	{
       
   478 	RMMFFormatImplInfoArray pluginArray;
       
   479 	CleanupResetAndDestroyPushL(pluginArray);
       
   480 	aSelectParams.ListImplementationsL(pluginArray);
       
   481 
       
   482 	// Just leave if no implementations were found
       
   483 	if (pluginArray.Count() == 0)
       
   484 		User::Leave(KErrNotSupported);
       
   485 
       
   486 	// Return the uid of the first plugin in the list
       
   487 	TUid ret = pluginArray[0]->Uid();
       
   488 	CleanupStack::PopAndDestroy();//pluginArray
       
   489 	return ret;
       
   490 	}
       
   491 
       
   492 /*
       
   493  * instantiate each format decode plugin in turn until we find one that works
       
   494  */
       
   495 CMMFFormatDecode* MMFFormatEcomUtilities::SelectFormatDecodePluginL(const CMMFFormatPluginSelectionParameters& aSelectParams, MDataSource* aSource)
       
   496 	{
       
   497 	RMMFFormatImplInfoArray pluginArray;
       
   498 	CleanupResetAndDestroyPushL(pluginArray);
       
   499 	aSelectParams.ListImplementationsL(pluginArray);
       
   500 
       
   501 	TInt pluginCount = pluginArray.Count();
       
   502 	CMMFFormatDecode* theChosenOne = NULL;
       
   503 
       
   504 	TInt err = KErrNotSupported;
       
   505 	for (TInt n=0; n<pluginCount; n++)
       
   506 		{
       
   507 		// Try to instantiate this format
       
   508 		TRAP(err, theChosenOne = CMMFFormatDecode::NewL(pluginArray[n]->Uid(), aSource));
       
   509 		// Ensure OOM or any unexpected error is caught immediately 
       
   510 		// i.e. don't try the next plugin
       
   511 		if (err != KErrNotSupported && err != KErrCorrupt && err != KErrArgument)
       
   512 			break;
       
   513 		}
       
   514 	User::LeaveIfError(err);
       
   515 
       
   516 	CleanupStack::PopAndDestroy(&pluginArray);
       
   517 
       
   518 	return theChosenOne;
       
   519 	}
       
   520 	
       
   521 /*
       
   522  * instantiate each format decode plugin in turn until we find one that works
       
   523  */
       
   524 CMMFFormatDecode* MMFFormatEcomUtilities::SelectFormatDecodePluginL(const CMMFFormatPluginSelectionParameters& aSelectParams, MDataSource* aSource, TBool& aSupportsCustomInterfaces)
       
   525 	{
       
   526 	RMMFFormatImplInfoArray pluginArray;
       
   527 	CleanupResetAndDestroyPushL(pluginArray);
       
   528 	aSelectParams.ListImplementationsL(pluginArray);
       
   529 
       
   530 	TInt pluginCount = pluginArray.Count();
       
   531 	CMMFFormatDecode* theChosenOne = NULL;
       
   532 
       
   533 	TInt err = KErrNotSupported;
       
   534 	CMMFFormatImplementationInformation* implInfo = NULL;
       
   535 	for (TInt n=0; n<pluginCount; n++)
       
   536 		{
       
   537 		implInfo = pluginArray[n];
       
   538 		// Try to instantiate this format
       
   539 		TRAP(err, theChosenOne = CMMFFormatDecode::NewL(implInfo->Uid(), aSource));
       
   540 		// Ensure OOM or any unexpected error is caught immediately 
       
   541 		// i.e. don't try the next plugin
       
   542 		if (err != KErrNotSupported && err != KErrCorrupt && err != KErrArgument)
       
   543 			break;
       
   544 		}
       
   545 	User::LeaveIfError(err);
       
   546 	aSupportsCustomInterfaces = implInfo->SupportsCustomInterfaces();
       
   547 
       
   548 	CleanupStack::PopAndDestroy(&pluginArray);
       
   549 
       
   550 	return theChosenOne;
       
   551 	}
       
   552