os/mm/mmlibs/mmfw/src/server/BaseClasses/Mmfformat.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmlibs/mmfw/src/server/BaseClasses/Mmfformat.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,552 @@
     1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <mmf/common/mmfcontrollerpluginresolver.h>
    1.20 +#include <mmf/server/mmfdatabuffer.h>
    1.21 +#include <mmf/common/mmfutilities.h>
    1.22 +#include <mmf/server/mmfclip.h>
    1.23 +#include <mmf/server/mmffile.h>
    1.24 +#include <mmf/server/mmfformat.h>
    1.25 +
    1.26 +//static const TUid KUidMmfPluginInterfaceFormatDecode = {KMmfUidPluginInterfaceFormatDecode};
    1.27 +//static const TUid KUidMmfPluginInterfaceFormatEncode = {KMmfUidPluginInterfaceFormatEncode};
    1.28 +
    1.29 +const TInt KMmfHeaderBufferSize = 512 ;		//512 bytes read to parse the header
    1.30 +
    1.31 +CMMFFormatDecode* CMMFFormatDecode::CreateFormatL(TUid aUid, MDataSource* aSource)
    1.32 +	{
    1.33 +	CMMFFormatDecode* s = REINTERPRET_CAST( CMMFFormatDecode*,
    1.34 +				REComSession::CreateImplementationL( aUid, _FOFF( CMMFFormatDecode, iDtor_ID_Key),
    1.35 +				STATIC_CAST( TAny*, aSource ) ) ) ;
    1.36 +	s->iImplementationUid = aUid;
    1.37 +	return s;
    1.38 +	}
    1.39 +
    1.40 +/**
    1.41 +Allocates and constructs an ECom format decode object.
    1.42 +
    1.43 +This is used to explicitly instantiate a format decoder where the UID is known. This method might
    1.44 +be used by controllers that only support one type of format such that the UID of the format is
    1.45 +already known. For example, if an mp3 controller has been instantiated, there is no need for any
    1.46 +further format recognition as this has already been performed in the controller instantiation, thus
    1.47 +the controller can instantiate an mp3 format directly from it’s UID.
    1.48 +
    1.49 +@param  aUid 
    1.50 +        The implementation UID. This is used by Com to create the plugin.
    1.51 +@param  aSource 
    1.52 +        The controller MDataSource and is the source of the data for the format decode plugin. The 
    1.53 +        format decode plugin is the sink of data for the MDataSource.
    1.54 +
    1.55 +@return If successful, returns the address of the format decode plugin object created. If not successful, 
    1.56 +        leaves with KErrNotFound.
    1.57 +*/
    1.58 +EXPORT_C CMMFFormatDecode* CMMFFormatDecode::NewL( TUid aUid, MDataSource* aSource )
    1.59 +	{
    1.60 +	return CreateFormatL(aUid, aSource);
    1.61 +	}
    1.62 +
    1.63 +
    1.64 +
    1.65 +/**
    1.66 +Attempt to locate and instantiate a FormatDecode using a filename or an extension.
    1.67 +
    1.68 +Only the extension is used.  If no extension  is supplied (no dot is present) the whole of the 
    1.69 +filename will be treated as the extension.
    1.70 +
    1.71 +If the file already exists, the file header is scanned to find a match in the opaque_data field of 
    1.72 +the resource file.
    1.73 +
    1.74 +@param  aFileName
    1.75 +        The file name of target file.  May be extension only or may include full path.
    1.76 +@param  aSource
    1.77 +        The controller's MDataSource. This is the source of the data for the format decode plugin. This must
    1.78 +        be a CMMFFile source when instantiating a CMMFFormatDecode using a file name.
    1.79 +@param  aPreferredSupplier
    1.80 +        If this is provided the list of matching plugins will be further searched for the latest version of a
    1.81 +        plugin supplied by supplier named.
    1.82 +
    1.83 +@return If successful returns an instantiated CMMFFormatDecode from a plugin. If not successful, leaves with KErrNotFound.
    1.84 +*/
    1.85 +EXPORT_C CMMFFormatDecode* CMMFFormatDecode::NewL( const TDesC16& aFileName, MDataSource* aSource, const TDesC& aPreferredSupplier )
    1.86 +	{
    1.87 +	CMMFFormatDecodePluginSelectionParameters* pluginSelector = CMMFFormatDecodePluginSelectionParameters::NewLC();
    1.88 +	CMMFFormatSelectionParameters* formatParams = CMMFFormatSelectionParameters::NewLC();
    1.89 +	formatParams->SetMatchToFileNameL(aFileName);
    1.90 +	pluginSelector->SetRequiredFormatSupportL(*formatParams);
    1.91 +	if (aPreferredSupplier.Length() > 0)
    1.92 +		pluginSelector->SetPreferredSupplierL(aPreferredSupplier, CMMFPluginSelectionParameters::EOnlyPreferredSupplierPluginsReturned);
    1.93 +
    1.94 +	// Instantiate this format
    1.95 +	CMMFFormatDecode* theChosenOne = 
    1.96 +		MMFFormatEcomUtilities::SelectFormatDecodePluginL(*pluginSelector, aSource);
    1.97 +
    1.98 +	// Now clean up.
    1.99 +	CleanupStack::PopAndDestroy(2);//formatParams, pluginSelector
   1.100 +
   1.101 +	return theChosenOne;
   1.102 +	}
   1.103 +
   1.104 +/**
   1.105 +Attempt to locate and instantiate a FormatDecode using a filename or an extension.
   1.106 +
   1.107 +Only the extension is used.  If no extension  is supplied (no dot is present) the whole of the 
   1.108 +filename will be treated as the extension.
   1.109 +
   1.110 +If the file already exists, the file header is scanned to find a match in the opaque_data field of 
   1.111 +the resource file.
   1.112 +
   1.113 +@param  aFileName
   1.114 +        The file name of target file.  May be extension only or may include full path.
   1.115 +@param  aSource
   1.116 +        The controller's MDataSource. This is the source of the data for the format decode plugin. This must
   1.117 +        be a CMMFFile source when instantiating a CMMFFormatDecode using a file name.
   1.118 +@param  aPreferredSupplier
   1.119 +        If this is provided the list of matching plugins will be further searched for the latest version of a
   1.120 +        plugin supplied by supplier named.
   1.121 +@param  aSupportsCustomInterfaces
   1.122 +		Indicates whether the instantiated FormatDecode supports custom interfaces.
   1.123 +
   1.124 +@return If successful returns an instantiated CMMFFormatDecode from a plugin. If not successful, leaves with KErrNotFound.
   1.125 +*/
   1.126 +EXPORT_C CMMFFormatDecode* CMMFFormatDecode::NewL( const TDesC16& aFileName, MDataSource* aSource, const TDesC& aPreferredSupplier, TBool& aSupportsCustomInterfaces )
   1.127 +	{
   1.128 +	CMMFFormatDecodePluginSelectionParameters* pluginSelector = CMMFFormatDecodePluginSelectionParameters::NewLC();
   1.129 +	CMMFFormatSelectionParameters* formatParams = CMMFFormatSelectionParameters::NewLC();
   1.130 +	formatParams->SetMatchToFileNameL(aFileName);
   1.131 +	pluginSelector->SetRequiredFormatSupportL(*formatParams);
   1.132 +	if (aPreferredSupplier.Length() > 0)
   1.133 +		pluginSelector->SetPreferredSupplierL(aPreferredSupplier, CMMFPluginSelectionParameters::EOnlyPreferredSupplierPluginsReturned);
   1.134 +
   1.135 +	// Instantiate this format
   1.136 +	CMMFFormatDecode* theChosenOne = 
   1.137 +		MMFFormatEcomUtilities::SelectFormatDecodePluginL(*pluginSelector, aSource, aSupportsCustomInterfaces);
   1.138 +
   1.139 +	// Now clean up.
   1.140 +	CleanupStack::PopAndDestroy(2);//formatParams, pluginSelector
   1.141 +
   1.142 +	return theChosenOne;
   1.143 +	}
   1.144 +
   1.145 +
   1.146 +/**
   1.147 +Attempts to locate and instantiate a CMMFFormatDecode using data in a buffer.  The buffer is expected to contain 
   1.148 +header data (from a file, stream or descriptor).
   1.149 +
   1.150 +Signatures (supplied by the plugin registry information) are sought in aSourceHeader.
   1.151 +
   1.152 +This function uses the match string as a resolver parameter. The format base class uses the match string
   1.153 +to find a match to the match string defined in the opaque_data field of the resource file. The
   1.154 +match string would typically be a signature for a particular format usually defined in the format header.
   1.155 +
   1.156 +@param  aSourceHeader
   1.157 +        The data which is searched for matching signatures.
   1.158 +@param  aSource
   1.159 +        The controller's MDataSource and the source of the data for the format decode plugin.
   1.160 +@param  aPreferredSupplier
   1.161 +        If this is provided the list of matching plugins will be further searched for the latest version of a
   1.162 +        plugin supplied by the specified supplier.
   1.163 +
   1.164 +@return If successful returns an instantiated CMMFFormatDecode from a plugin.  If not successful, leaves with KErrNotFound.
   1.165 +*/
   1.166 +EXPORT_C CMMFFormatDecode* CMMFFormatDecode::NewL( const TDesC8& aSourceHeader, MDataSource* aSource, const TDesC& aPreferredSupplier )
   1.167 +	{
   1.168 +	CMMFFormatDecodePluginSelectionParameters* pluginSelector = CMMFFormatDecodePluginSelectionParameters::NewLC();
   1.169 +	CMMFFormatSelectionParameters* formatParams = CMMFFormatSelectionParameters::NewLC();
   1.170 +	formatParams->SetMatchToHeaderDataL(aSourceHeader);
   1.171 +	pluginSelector->SetRequiredFormatSupportL(*formatParams);
   1.172 +	if (aPreferredSupplier.Length() > 0)
   1.173 +		pluginSelector->SetPreferredSupplierL(aPreferredSupplier, CMMFPluginSelectionParameters::EOnlyPreferredSupplierPluginsReturned);
   1.174 +
   1.175 +	// Instantiate this format
   1.176 +	CMMFFormatDecode* theChosenOne = 
   1.177 +		MMFFormatEcomUtilities::SelectFormatDecodePluginL(*pluginSelector, aSource);
   1.178 +
   1.179 +	// Now clean up.
   1.180 +	CleanupStack::PopAndDestroy(2);//formatParams, pluginSelector
   1.181 +
   1.182 +	return theChosenOne;
   1.183 +	}
   1.184 +
   1.185 +/**
   1.186 +Attempts to locate and instantiate a CMMFFormatDecode using data in a buffer.  The buffer is expected to contain 
   1.187 +header data (from a file, stream or descriptor).
   1.188 +
   1.189 +Signatures (supplied by the plugin registry information) are sought in aSourceHeader.
   1.190 +
   1.191 +This function uses the match string as a resolver parameter. The format base class uses the match string
   1.192 +to find a match to the match string defined in the opaque_data field of the resource file. The
   1.193 +match string would typically be a signature for a particular format usually defined in the format header.
   1.194 +
   1.195 +@param  aSourceHeader
   1.196 +        The data which is searched for matching signatures.
   1.197 +@param  aSource
   1.198 +        The controller's MDataSource and the source of the data for the format decode plugin.
   1.199 +@param  aPreferredSupplier
   1.200 +        If this is provided the list of matching plugins will be further searched for the latest version of a
   1.201 +        plugin supplied by the specified supplier.
   1.202 +@param  aSupportsCustomInterfaces
   1.203 +		Indicates whether the instantiated FormatDecode supports custom interfaces.
   1.204 +
   1.205 +@return If successful returns an instantiated CMMFFormatDecode from a plugin.  If not successful, leaves with KErrNotFound.
   1.206 +*/
   1.207 +EXPORT_C CMMFFormatDecode* CMMFFormatDecode::NewL( const TDesC8& aSourceHeader, MDataSource* aSource, const TDesC& aPreferredSupplier, TBool& aSupportsCustomInterfaces )
   1.208 +	{
   1.209 +	CMMFFormatDecodePluginSelectionParameters* pluginSelector = CMMFFormatDecodePluginSelectionParameters::NewLC();
   1.210 +	CMMFFormatSelectionParameters* formatParams = CMMFFormatSelectionParameters::NewLC();
   1.211 +	formatParams->SetMatchToHeaderDataL(aSourceHeader);
   1.212 +	pluginSelector->SetRequiredFormatSupportL(*formatParams);
   1.213 +	if (aPreferredSupplier.Length() > 0)
   1.214 +		pluginSelector->SetPreferredSupplierL(aPreferredSupplier, CMMFPluginSelectionParameters::EOnlyPreferredSupplierPluginsReturned);
   1.215 +
   1.216 +	// Instantiate this format
   1.217 +	CMMFFormatDecode* theChosenOne = 
   1.218 +		MMFFormatEcomUtilities::SelectFormatDecodePluginL(*pluginSelector, aSource, aSupportsCustomInterfaces);
   1.219 +
   1.220 +	// Now clean up.
   1.221 +	CleanupStack::PopAndDestroy(2);//formatParams, pluginSelector
   1.222 +
   1.223 +	return theChosenOne;
   1.224 +	}
   1.225 +
   1.226 +/**
   1.227 +Attempts to locate and instantiate a CMMFFormatDecode using data from MDataSource.  
   1.228 +
   1.229 +The data is expected to contain header data (from a file, stream or descriptor). Signatures 
   1.230 +(supplied by the plugin registry information) are sought in aSource.
   1.231 +
   1.232 +@param  aSource
   1.233 +        Header data. Must be derived from CMMFClip.
   1.234 +@param  aPreferredSupplier
   1.235 +        If this is provided, the list of matching plugins will be further searched for the latest version of a
   1.236 +        plugin supplied by the specified supplier.
   1.237 +
   1.238 +@return If successful returns an instantiated CMMFFormatDecode from a plugin. If not successful, leaves with KErrNotFound.
   1.239 +*/
   1.240 +EXPORT_C CMMFFormatDecode* CMMFFormatDecode::NewL( MDataSource* aSource, const TDesC& aPreferredSupplier )
   1.241 +	{
   1.242 +	// Read header data from aSource.  Call source header version
   1.243 +
   1.244 +	if ( !( (aSource->DataSourceType() == KUidMmfFileSource ) || ( aSource->DataSourceType() == KUidMmfDescriptorSource) ) )
   1.245 +		User::Leave( KErrNotSupported ) ;
   1.246 +
   1.247 +	CMMFDataBuffer* buffer = CMMFDataBuffer::NewL(KMmfHeaderBufferSize) ;
   1.248 +	CleanupStack::PushL( buffer ) ;
   1.249 +
   1.250 +	aSource->SourcePrimeL();
   1.251 +	TCleanupItem srcCleanupItem(DoDataSourceStop, aSource);
   1.252 +	CleanupStack::PushL(srcCleanupItem);
   1.253 +
   1.254 +	STATIC_CAST( CMMFClip*, aSource )->ReadBufferL( buffer, 0 ) ;
   1.255 +
   1.256 +	CleanupStack::Pop();
   1.257 +	aSource->SourceStopL();
   1.258 +
   1.259 +	// attempt to instantiate the format by header data
   1.260 +	// if this fails, try using the file extension
   1.261 +	CMMFFormatDecode* ret = NULL;
   1.262 +	TInt err, errFile;
   1.263 +	TRAP(err, ret = NewL( buffer->Data(), aSource, aPreferredSupplier ));
   1.264 +	if (err != KErrNone && aSource->DataSourceType() == KUidMmfFileSource)
   1.265 +		{
   1.266 +		CMMFFile* mmfFile = static_cast<CMMFFile*> (aSource);
   1.267 +		TRAP(errFile, ret = NewL( mmfFile->FullName(), aSource, aPreferredSupplier ));
   1.268 +		if (errFile == KErrNone)
   1.269 +			err = errFile;
   1.270 +		}
   1.271 +	User::LeaveIfError(err);
   1.272 +
   1.273 +	CleanupStack::PopAndDestroy() ; // buffer
   1.274 +	return ret ;
   1.275 +	
   1.276 +	}
   1.277 +
   1.278 +/**
   1.279 +Attempts to locate and instantiate a CMMFFormatDecode using data from MDataSource.  
   1.280 +
   1.281 +The data is expected to contain header data (from a file, stream or descriptor). Signatures 
   1.282 +(supplied by the plugin registry information) are sought in aSource.
   1.283 +
   1.284 +@param  aSource
   1.285 +        Header data. Must be derived from CMMFClip.
   1.286 +@param  aPreferredSupplier
   1.287 +        If this is provided, the list of matching plugins will be further searched for the latest version of a
   1.288 +        plugin supplied by the specified supplier.
   1.289 +@param  aSupportsCustomInterfaces
   1.290 +		Indicates whether the instantiated FormatDecode supports custom interfaces.
   1.291 +
   1.292 +@return If successful returns an instantiated CMMFFormatDecode from a plugin. If not successful, leaves with KErrNotFound.
   1.293 +*/
   1.294 +EXPORT_C CMMFFormatDecode* CMMFFormatDecode::NewL( MDataSource* aSource, const TDesC& aPreferredSupplier, TBool& aSupportsCustomInterfaces )
   1.295 +	{
   1.296 +	// Read header data from aSource.  Call source header version
   1.297 +
   1.298 +	if ( !( (aSource->DataSourceType() == KUidMmfFileSource ) || ( aSource->DataSourceType() == KUidMmfDescriptorSource) ) )
   1.299 +		User::Leave( KErrNotSupported ) ;
   1.300 +
   1.301 +	CMMFDataBuffer* buffer = CMMFDataBuffer::NewL(KMmfHeaderBufferSize) ;
   1.302 +	CleanupStack::PushL( buffer ) ;
   1.303 +
   1.304 +	aSource->SourcePrimeL();
   1.305 +	TCleanupItem srcCleanupItem(DoDataSourceStop, aSource);
   1.306 +	CleanupStack::PushL(srcCleanupItem);
   1.307 +
   1.308 +	STATIC_CAST( CMMFClip*, aSource )->ReadBufferL( buffer, 0 ) ;
   1.309 +
   1.310 +	CleanupStack::Pop();
   1.311 +	aSource->SourceStopL();
   1.312 +
   1.313 +	// attempt to instantiate the format by header data
   1.314 +	// if this fails, try using the file extension
   1.315 +	CMMFFormatDecode* ret = NULL;
   1.316 +	TInt err, errFile;
   1.317 +	TRAP(err, ret = NewL( buffer->Data(), aSource, aPreferredSupplier, aSupportsCustomInterfaces ));
   1.318 +	if (err != KErrNone && aSource->DataSourceType() == KUidMmfFileSource)
   1.319 +		{
   1.320 +		CMMFFile* mmfFile = static_cast<CMMFFile*> (aSource);
   1.321 +		TRAP(errFile, ret = NewL( mmfFile->FullName(), aSource, aPreferredSupplier, aSupportsCustomInterfaces ));
   1.322 +		if (errFile == KErrNone)
   1.323 +			err = errFile;
   1.324 +		}
   1.325 +	User::LeaveIfError(err);
   1.326 +
   1.327 +	CleanupStack::PopAndDestroy() ; // buffer
   1.328 +	return ret ;
   1.329 +	
   1.330 +	}
   1.331 +
   1.332 +CMMFFormatEncode* CMMFFormatEncode::CreateFormatL(TUid aUid, MDataSink* aSink)
   1.333 +	{
   1.334 +	CMMFFormatEncode* s = REINTERPRET_CAST( CMMFFormatEncode*,
   1.335 +									REComSession::CreateImplementationL( aUid, _FOFF( CMMFFormatEncode, iDtor_ID_Key ),
   1.336 +									STATIC_CAST( TAny*, aSink ) ) ) ;
   1.337 +	s->iImplementationUid = aUid;
   1.338 +	return s;
   1.339 +	}
   1.340 +
   1.341 +/**
   1.342 +Allocates and constructs an ECom format encode object.
   1.343 +
   1.344 +@param  aUid
   1.345 +        The implementation UID.
   1.346 +@param  aSink
   1.347 +        The data sink.
   1.348 +
   1.349 +@return If successful, returns the address of the format decode plugin object created. If not successful,
   1.350 +        leaves with KErrNotFound.
   1.351 +*/
   1.352 +EXPORT_C CMMFFormatEncode* CMMFFormatEncode::NewL( TUid aUid, MDataSink* aSink )
   1.353 +	{
   1.354 +	return CreateFormatL(aUid, aSink);
   1.355 +	}
   1.356 +
   1.357 +/**
   1.358 +Attempts to locate and instantiate a CMMFFormatEncode using a filename or an extension.
   1.359 +
   1.360 +Only the extension of the supplied file name is used. If no extension is supplied (ie. no dot is present)
   1.361 +the whole of the filename will be treated as the extension.
   1.362 +
   1.363 +@param  aFileName
   1.364 +        File name of target file. May be extension only or may include the full path.
   1.365 +@param  aSink
   1.366 +		The data source.
   1.367 +@param  aPreferredSupplier
   1.368 +        If this is provided, the list of matching plugins will be further searched for the latest version of a
   1.369 +        plugin supplied by supplier named.
   1.370 +
   1.371 +@return If successful, returns the address of the format decode plugin object created. If not successful,
   1.372 +        leaves with KErrNotFound.
   1.373 +*/
   1.374 +EXPORT_C CMMFFormatEncode* CMMFFormatEncode::NewL( const TDesC16& aFileName, MDataSink* aSink, const TDesC& aPreferredSupplier )
   1.375 +	{
   1.376 +	CMMFFormatEncodePluginSelectionParameters* pluginSelector = CMMFFormatEncodePluginSelectionParameters::NewLC();
   1.377 +	CMMFFormatSelectionParameters* formatParams = CMMFFormatSelectionParameters::NewLC();
   1.378 +	formatParams->SetMatchToFileNameL(aFileName);
   1.379 +	pluginSelector->SetRequiredFormatSupportL(*formatParams);
   1.380 +	if (aPreferredSupplier.Length() > 0)
   1.381 +		pluginSelector->SetPreferredSupplierL(aPreferredSupplier, CMMFPluginSelectionParameters::EOnlyPreferredSupplierPluginsReturned);
   1.382 +
   1.383 +	TUid chosenUid = MMFFormatEcomUtilities::SelectFormatPluginL(*pluginSelector);
   1.384 +
   1.385 +	// Instantiate this format
   1.386 +	CMMFFormatEncode* theChosenOne = CreateFormatL(chosenUid, aSink);
   1.387 +
   1.388 +	// Now clean up.
   1.389 +	CleanupStack::PopAndDestroy(2);//formatParams, pluginSelector
   1.390 +
   1.391 +	return theChosenOne;
   1.392 +	}
   1.393 +
   1.394 +/**
   1.395 +Attempts to locate and instantiate a CMMFFormatEncode using data in the specified buffer.
   1.396 +
   1.397 +The buffer is expected to contain header data (from a file, stream or descriptor).
   1.398 +Signatures (supplied by the plugin registry information) are sought in aSourceHeader.
   1.399 +
   1.400 +@param  aSourceHeader
   1.401 +        The data which is searched for matching signatures.
   1.402 +@param  aSink
   1.403 +        The data sink.
   1.404 +@param  aPreferredSupplier
   1.405 +        If this is provided the list of matching plugins will be further searched for the latest version of a
   1.406 +        plugin supplied by supplier named.
   1.407 +
   1.408 +@return If successful, returns the address of the format decode plugin object created. If not successful,
   1.409 +        leaves with KErrNotFound.
   1.410 +*/
   1.411 +EXPORT_C CMMFFormatEncode* CMMFFormatEncode::NewL( const TDesC8& aSourceHeader, MDataSink* aSink,  const TDesC& aPreferredSupplier )
   1.412 +	{
   1.413 +	CMMFFormatEncodePluginSelectionParameters* pluginSelector = CMMFFormatEncodePluginSelectionParameters::NewLC();
   1.414 +	CMMFFormatSelectionParameters* formatParams = CMMFFormatSelectionParameters::NewLC();
   1.415 +	formatParams->SetMatchToHeaderDataL(aSourceHeader);
   1.416 +	pluginSelector->SetRequiredFormatSupportL(*formatParams);
   1.417 +	if (aPreferredSupplier.Length() > 0)
   1.418 +		pluginSelector->SetPreferredSupplierL(aPreferredSupplier, CMMFPluginSelectionParameters::EOnlyPreferredSupplierPluginsReturned);
   1.419 +
   1.420 +	TUid chosenUid = MMFFormatEcomUtilities::SelectFormatPluginL(*pluginSelector);
   1.421 +
   1.422 +	// Instantiate this format
   1.423 +	CMMFFormatEncode* theChosenOne = CreateFormatL(chosenUid, aSink);
   1.424 +
   1.425 +	// Now clean up.
   1.426 +	CleanupStack::PopAndDestroy(2);//formatParams, pluginSelector
   1.427 +
   1.428 +	return theChosenOne;
   1.429 +	}
   1.430 +
   1.431 +/**
   1.432 +Attempts to locate and instantiate a CMMFFormatEncode using data from aSink.
   1.433 +
   1.434 +The data is expected to contain header data (from a file, stream or descriptor).
   1.435 +Signatures (supplied by the plugin registry information) are sought in the source header.
   1.436 +
   1.437 +@param  aSink
   1.438 +        The header data. Must be derived from CMMFClip.
   1.439 +@param  aPreferredSupplier
   1.440 +        If this is provided, the list of matching plugins will be further searched for the latest version of a
   1.441 +        plugin supplied by supplier specified.
   1.442 +
   1.443 +@return If successful, returns the address of the format decode plugin object created. If not successful,
   1.444 +        leaves with KErrNotFound.
   1.445 +*/
   1.446 +EXPORT_C CMMFFormatEncode* CMMFFormatEncode::NewL( MDataSink* aSink, const TDesC& aPreferredSupplier )
   1.447 +	{
   1.448 +	// Read header data from aSource.  Call source header version if there is header data, file name version otherwise.
   1.449 +
   1.450 +	if ( !( (aSink->DataSinkType() == KUidMmfFileSink ) || ( aSink->DataSinkType() == KUidMmfDescriptorSink) ) )
   1.451 +		User::Leave( KErrNotSupported ) ;
   1.452 +
   1.453 +	CMMFDataBuffer* buffer = CMMFDataBuffer::NewL(KMmfHeaderBufferSize) ;
   1.454 +	CleanupStack::PushL( buffer ) ;
   1.455 +
   1.456 +	aSink->SinkPrimeL();
   1.457 +	TCleanupItem sinkCleanupItem(DoDataSinkStop, aSink);
   1.458 +	CleanupStack::PushL(sinkCleanupItem);
   1.459 +
   1.460 +	STATIC_CAST( CMMFClip*, aSink )->ReadBufferL( buffer, 0 ) ;
   1.461 +
   1.462 +	CleanupStack::Pop();
   1.463 +	aSink->SinkStopL();
   1.464 +
   1.465 +	CMMFFormatEncode* ret = NULL ;  // set to null to avoid compiler warning.
   1.466 +	// Check for data in the buffer
   1.467 +	if (  buffer->BufferSize() != 0 )
   1.468 +		ret = NewL( buffer->Data(), aSink, aPreferredSupplier ) ;
   1.469 +	else if ( aSink->DataSinkType() == KUidMmfFileSink )
   1.470 +		ret = NewL( STATIC_CAST(CMMFFile*, aSink)->Extension(), aSink, aPreferredSupplier ) ;
   1.471 +	else
   1.472 +		User::Leave( KErrNotSupported ) ;
   1.473 +
   1.474 +	CleanupStack::PopAndDestroy() ; // buffer
   1.475 +	return ret ;
   1.476 +	}
   1.477 +
   1.478 +
   1.479 +TUid MMFFormatEcomUtilities::SelectFormatPluginL(const CMMFFormatPluginSelectionParameters& aSelectParams)
   1.480 +	{
   1.481 +	RMMFFormatImplInfoArray pluginArray;
   1.482 +	CleanupResetAndDestroyPushL(pluginArray);
   1.483 +	aSelectParams.ListImplementationsL(pluginArray);
   1.484 +
   1.485 +	// Just leave if no implementations were found
   1.486 +	if (pluginArray.Count() == 0)
   1.487 +		User::Leave(KErrNotSupported);
   1.488 +
   1.489 +	// Return the uid of the first plugin in the list
   1.490 +	TUid ret = pluginArray[0]->Uid();
   1.491 +	CleanupStack::PopAndDestroy();//pluginArray
   1.492 +	return ret;
   1.493 +	}
   1.494 +
   1.495 +/*
   1.496 + * instantiate each format decode plugin in turn until we find one that works
   1.497 + */
   1.498 +CMMFFormatDecode* MMFFormatEcomUtilities::SelectFormatDecodePluginL(const CMMFFormatPluginSelectionParameters& aSelectParams, MDataSource* aSource)
   1.499 +	{
   1.500 +	RMMFFormatImplInfoArray pluginArray;
   1.501 +	CleanupResetAndDestroyPushL(pluginArray);
   1.502 +	aSelectParams.ListImplementationsL(pluginArray);
   1.503 +
   1.504 +	TInt pluginCount = pluginArray.Count();
   1.505 +	CMMFFormatDecode* theChosenOne = NULL;
   1.506 +
   1.507 +	TInt err = KErrNotSupported;
   1.508 +	for (TInt n=0; n<pluginCount; n++)
   1.509 +		{
   1.510 +		// Try to instantiate this format
   1.511 +		TRAP(err, theChosenOne = CMMFFormatDecode::NewL(pluginArray[n]->Uid(), aSource));
   1.512 +		// Ensure OOM or any unexpected error is caught immediately 
   1.513 +		// i.e. don't try the next plugin
   1.514 +		if (err != KErrNotSupported && err != KErrCorrupt && err != KErrArgument)
   1.515 +			break;
   1.516 +		}
   1.517 +	User::LeaveIfError(err);
   1.518 +
   1.519 +	CleanupStack::PopAndDestroy(&pluginArray);
   1.520 +
   1.521 +	return theChosenOne;
   1.522 +	}
   1.523 +	
   1.524 +/*
   1.525 + * instantiate each format decode plugin in turn until we find one that works
   1.526 + */
   1.527 +CMMFFormatDecode* MMFFormatEcomUtilities::SelectFormatDecodePluginL(const CMMFFormatPluginSelectionParameters& aSelectParams, MDataSource* aSource, TBool& aSupportsCustomInterfaces)
   1.528 +	{
   1.529 +	RMMFFormatImplInfoArray pluginArray;
   1.530 +	CleanupResetAndDestroyPushL(pluginArray);
   1.531 +	aSelectParams.ListImplementationsL(pluginArray);
   1.532 +
   1.533 +	TInt pluginCount = pluginArray.Count();
   1.534 +	CMMFFormatDecode* theChosenOne = NULL;
   1.535 +
   1.536 +	TInt err = KErrNotSupported;
   1.537 +	CMMFFormatImplementationInformation* implInfo = NULL;
   1.538 +	for (TInt n=0; n<pluginCount; n++)
   1.539 +		{
   1.540 +		implInfo = pluginArray[n];
   1.541 +		// Try to instantiate this format
   1.542 +		TRAP(err, theChosenOne = CMMFFormatDecode::NewL(implInfo->Uid(), aSource));
   1.543 +		// Ensure OOM or any unexpected error is caught immediately 
   1.544 +		// i.e. don't try the next plugin
   1.545 +		if (err != KErrNotSupported && err != KErrCorrupt && err != KErrArgument)
   1.546 +			break;
   1.547 +		}
   1.548 +	User::LeaveIfError(err);
   1.549 +	aSupportsCustomInterfaces = implInfo->SupportsCustomInterfaces();
   1.550 +
   1.551 +	CleanupStack::PopAndDestroy(&pluginArray);
   1.552 +
   1.553 +	return theChosenOne;
   1.554 +	}
   1.555 +