os/mm/mmlibs/mmfw/src/server/BaseClasses/Mmfcodec.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/Mmfcodec.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,222 @@
     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 +
    1.20 +#include <mmf/server/mmfcodec.h>
    1.21 +#include "MmfUtilities.h"
    1.22 +#include <mmf/common/mmfcontrollerpluginresolver.h>
    1.23 +#include <ecom/ecom.h>
    1.24 +#include <mm/mmpluginutils.h>
    1.25 +
    1.26 +_LIT8( KEmptyFourCCString, "    ,    " ) ;
    1.27 +_LIT( KNullString, "" ) ;
    1.28 +
    1.29 +static const TUid KUidMmfPluginInterfaceCodec = {KMmfUidPluginInterfaceCodec};
    1.30 +
    1.31 +/**
    1.32 +Creates a CMMFCodec object with match parameter in addition to the source and
    1.33 +destination fourCC codes (for instance a manufacturer's name).
    1.34 +
    1.35 +Will attempt match without extra match string if no match.
    1.36 +
    1.37 +Will Leave if no match on 4CC codes (KErrNotFound).
    1.38 +
    1.39 +Used where there may be multiple codecs that perform the same conversion to ensure the controller
    1.40 +uses the codec specified by aPreferredSupplier.
    1.41 +
    1.42 +@param  aSrcDataType
    1.43 +        The source data type.
    1.44 +@param  aDstDataType
    1.45 +        The destination data type.
    1.46 +@param  aPreferredSupplier
    1.47 +        Additional resolution criteria when searching for plug in codec. If this is provided, the 
    1.48 +        list of matching plugins will be further searched for the latest version of a plugin 
    1.49 +        supplied by supplier named. Note that the display name field is parsed for a match.
    1.50 +
    1.51 +@return An instantiated CMMFCodec derived obeject from an ECOM plugin DLL.
    1.52 +*/
    1.53 +EXPORT_C CMMFCodec* CMMFCodec::NewL(const TFourCC& aSrcDataType, const TFourCC& aDstDataType,  const TDesC& aPreferredSupplier)
    1.54 +	{
    1.55 +
    1.56 +	// Create a match string using the two FourCC codes.
    1.57 +	TBufC8<9> fourCCString( KEmptyFourCCString ) ;
    1.58 +	TPtr8 fourCCPtr = fourCCString.Des() ;
    1.59 +	TPtr8 fourCCPtr1( &fourCCPtr[0], 4 ) ;
    1.60 +	TPtr8 fourCCPtr2( &fourCCPtr[5], 4 ) ;
    1.61 +	aSrcDataType.FourCC( &fourCCPtr1 ) ;
    1.62 +	aDstDataType.FourCC( &fourCCPtr2 ) ;
    1.63 +
    1.64 +	// Do a list implementations here.
    1.65 +
    1.66 +	RImplInfoPtrArray plugInArray; // Array to return matching decoders in
    1.67 +	CleanupResetAndDestroyPushL(plugInArray);
    1.68 +
    1.69 +	MmPluginUtils::FindImplementationsL(KUidMmfPluginInterfaceCodec, plugInArray, fourCCPtr);
    1.70 +
    1.71 +	if (plugInArray.Count() == 0)
    1.72 +		{
    1.73 +		User::Leave(KErrNotSupported);
    1.74 +		}
    1.75 +
    1.76 +	TUid chosenUid = {0};
    1.77 +
    1.78 +	if ( plugInArray.Count() == 1 )
    1.79 +		{
    1.80 +		chosenUid = plugInArray[0]->ImplementationUid() ;
    1.81 +		}
    1.82 +	else
    1.83 +		{
    1.84 +		// Use the preferred supplier to select a codec.
    1.85 +		SelectByPreference( plugInArray, aPreferredSupplier ) ;
    1.86 +		for ( TInt ii = 0 ; ii < plugInArray.Count() ; ii++ )
    1.87 +			{
    1.88 +			if ( !(plugInArray[ii]->Disabled()) )
    1.89 +				{
    1.90 +				// we've found our plugin...
    1.91 +				chosenUid = plugInArray[ii]->ImplementationUid() ;
    1.92 +				break ;
    1.93 +				}
    1.94 +			}
    1.95 +		}
    1.96 +
    1.97 +	//Instantiate the chosen one
    1.98 +	CMMFCodec* theChosenOne = REINTERPRET_CAST( CMMFCodec*,
    1.99 +						REComSession::CreateImplementationL( chosenUid, _FOFF( CMMFCodec, iDtor_ID_Key ) ) ) ;
   1.100 +
   1.101 +	CleanupStack::PopAndDestroy() ;  // pluginArray
   1.102 +
   1.103 +	return theChosenOne ;
   1.104 +	}
   1.105 +
   1.106 +/**
   1.107 +Creates a CMMFCodec object with known fourCC codes for source and destination.
   1.108 +The first matching plug-in will be used.
   1.109 +
   1.110 +The FourCC codes are the same codes as those specified in the resource file and are used to identify
   1.111 +the datatype. ECom scans the registry to find a codec that is registered in its resource file as
   1.112 +being able to convert between the source data type and the destination data type as specified by
   1.113 +their FourCC codes. If a match is found then an instantiation of the appropriate CMMFCodec is made.
   1.114 +If a match is not found this function leaves with KErrNotFound. If more than one codec is present
   1.115 +with the same fourCC match codes then the one that is instantiated is indeterminate. If there is
   1.116 +likely to be any ambiguity due to more than one codec that performs the same conversion being
   1.117 +present, then a preferred supplier should be specified.
   1.118 +
   1.119 +@param  aSrcDataType
   1.120 +        The source data type.
   1.121 +@param  aDstDataType
   1.122 +        The destination data type.
   1.123 +
   1.124 +@return An instantiated CMMFCodec derived obeject from an ECOM plugin DLL.
   1.125 +*/
   1.126 +EXPORT_C CMMFCodec* CMMFCodec::NewL(const TFourCC& aSrcDataType, const TFourCC& aDstDataType )
   1.127 +	{
   1.128 +	// Create a match string using the two FourCC codes.
   1.129 +	return NewL( aSrcDataType, aDstDataType, KNullString ) ;
   1.130 +
   1.131 +	}
   1.132 +
   1.133 +
   1.134 +// local function to disable items which do not match the preferred supplier.
   1.135 +// Note that at least one enabled item is returned (if there was an enabled item to begin with) which
   1.136 +// may not match the preferred supplier.
   1.137 +/**
   1.138 +Selects a codec according to the specified preference.
   1.139 +
   1.140 +@param  aPlugInArray
   1.141 +        On return, array of plugins.
   1.142 +@param  aPreferredSupplier
   1.143 +        Search criteria, a supplier's name for example.
   1.144 +*/
   1.145 +void CMMFCodec::SelectByPreference( RImplInfoPtrArray& aPlugInArray, const TDesC& aPreferredSupplier )
   1.146 +	{	
   1.147 +	// Use the Disabled flag to eliminated all currently enabled matches that
   1.148 +	// do not match the preferred supplier.
   1.149 +	TInt firstEnabled = -1 ; // to ensure that we return something valid
   1.150 +	TInt matchCount = 0 ;
   1.151 +	for ( TInt ii = 0 ; ii < aPlugInArray.Count() ; ii++ )
   1.152 +		{
   1.153 +		if ( !( aPlugInArray[ii]->Disabled() ) )
   1.154 +			{
   1.155 +			if ( firstEnabled == -1 )
   1.156 +				firstEnabled = ii ;
   1.157 +			if ( aPlugInArray[ii]->DisplayName().FindF( aPreferredSupplier ) == KErrNotFound )
   1.158 +				aPlugInArray[ii]->SetDisabled( ETrue ) ;
   1.159 +			else
   1.160 +				matchCount++ ;
   1.161 +			}
   1.162 +		}
   1.163 +
   1.164 +	// If there are no matches then re-enable the first enabled
   1.165 +	if ( matchCount == 0 )
   1.166 +		aPlugInArray[firstEnabled]->SetDisabled( EFalse ) ;
   1.167 +	else if ( matchCount > 1 )
   1.168 +		{
   1.169 +		// find the latest version from more than one match
   1.170 +		TInt highestVersionIndex = -1 ;
   1.171 +		for ( TInt ii = 0 ; ii < aPlugInArray.Count() ; ii++ )
   1.172 +			{
   1.173 +			if ( !( aPlugInArray[ii]->Disabled() ) )  // only interested in enabled elements
   1.174 +				{
   1.175 +				if ( highestVersionIndex == -1 )
   1.176 +					{ // first match.  Store this.  Keep it enabled
   1.177 +					highestVersionIndex = ii ;
   1.178 +					}
   1.179 +				else if ( aPlugInArray[ii]->Version() > aPlugInArray[highestVersionIndex]->Version() )
   1.180 +					{ // a new leader.  Disable the previous leader.  Keep this one.
   1.181 +					aPlugInArray[highestVersionIndex]->SetDisabled( ETrue ) ;
   1.182 +					highestVersionIndex = ii ;
   1.183 +					}
   1.184 +				else  // we already have a higher version.
   1.185 +					aPlugInArray[ii]->SetDisabled( ETrue ) ;
   1.186 +				}
   1.187 +			}
   1.188 +		}	
   1.189 +	}
   1.190 +
   1.191 +
   1.192 +/**
   1.193 +Creates a CMMFCodec object with a known UID.
   1.194 +
   1.195 +Will Leave if the plug in is not found (KErrNotFound).
   1.196 +
   1.197 +@param aUid
   1.198 +       The UID of a plugin implementation.
   1.199 +
   1.200 +@return An instantiated CMMFCodec derived obeject from an ECOM plugin DLL.
   1.201 +*/
   1.202 +EXPORT_C CMMFCodec* CMMFCodec::NewL(TUid aUid)
   1.203 +	{
   1.204 +	return REINTERPRET_CAST(CMMFCodec*, REComSession::CreateImplementationL(aUid,
   1.205 +												_FOFF(CMMFCodec,iDtor_ID_Key)));
   1.206 +	}
   1.207 +
   1.208 +/**
   1.209 +@internalComponent
   1.210 +
   1.211 +Gets a pointer to the extension specified by an identifier. The extension can be either an
   1.212 +interface or function. If the extension is not supported NULL value is given and returns
   1.213 +KErrExtensionNotSupported.
   1.214 +
   1.215 +@param	aExtensionId
   1.216 +		Extension identifier.
   1.217 +@param	aExtPtr
   1.218 +		Pointer to get the extension.
   1.219 +@return	If successful returns KErrNone otherwise KErrExtensionNotSupported.		
   1.220 +*/
   1.221 +TInt CMMFCodec::ExtensionInterface(TUint aExtensionId, TAny*& aExtPtr)
   1.222 +	{
   1.223 +	return Extension_(aExtensionId, aExtPtr, NULL);	
   1.224 +	}
   1.225 +