os/mm/mmlibs/mmfw/src/server/BaseClasses/Mmfcodec.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 
    17 #include <mmf/server/mmfcodec.h>
    18 #include "MmfUtilities.h"
    19 #include <mmf/common/mmfcontrollerpluginresolver.h>
    20 #include <ecom/ecom.h>
    21 #include <mm/mmpluginutils.h>
    22 
    23 _LIT8( KEmptyFourCCString, "    ,    " ) ;
    24 _LIT( KNullString, "" ) ;
    25 
    26 static const TUid KUidMmfPluginInterfaceCodec = {KMmfUidPluginInterfaceCodec};
    27 
    28 /**
    29 Creates a CMMFCodec object with match parameter in addition to the source and
    30 destination fourCC codes (for instance a manufacturer's name).
    31 
    32 Will attempt match without extra match string if no match.
    33 
    34 Will Leave if no match on 4CC codes (KErrNotFound).
    35 
    36 Used where there may be multiple codecs that perform the same conversion to ensure the controller
    37 uses the codec specified by aPreferredSupplier.
    38 
    39 @param  aSrcDataType
    40         The source data type.
    41 @param  aDstDataType
    42         The destination data type.
    43 @param  aPreferredSupplier
    44         Additional resolution criteria when searching for plug in codec. If this is provided, the 
    45         list of matching plugins will be further searched for the latest version of a plugin 
    46         supplied by supplier named. Note that the display name field is parsed for a match.
    47 
    48 @return An instantiated CMMFCodec derived obeject from an ECOM plugin DLL.
    49 */
    50 EXPORT_C CMMFCodec* CMMFCodec::NewL(const TFourCC& aSrcDataType, const TFourCC& aDstDataType,  const TDesC& aPreferredSupplier)
    51 	{
    52 
    53 	// Create a match string using the two FourCC codes.
    54 	TBufC8<9> fourCCString( KEmptyFourCCString ) ;
    55 	TPtr8 fourCCPtr = fourCCString.Des() ;
    56 	TPtr8 fourCCPtr1( &fourCCPtr[0], 4 ) ;
    57 	TPtr8 fourCCPtr2( &fourCCPtr[5], 4 ) ;
    58 	aSrcDataType.FourCC( &fourCCPtr1 ) ;
    59 	aDstDataType.FourCC( &fourCCPtr2 ) ;
    60 
    61 	// Do a list implementations here.
    62 
    63 	RImplInfoPtrArray plugInArray; // Array to return matching decoders in
    64 	CleanupResetAndDestroyPushL(plugInArray);
    65 
    66 	MmPluginUtils::FindImplementationsL(KUidMmfPluginInterfaceCodec, plugInArray, fourCCPtr);
    67 
    68 	if (plugInArray.Count() == 0)
    69 		{
    70 		User::Leave(KErrNotSupported);
    71 		}
    72 
    73 	TUid chosenUid = {0};
    74 
    75 	if ( plugInArray.Count() == 1 )
    76 		{
    77 		chosenUid = plugInArray[0]->ImplementationUid() ;
    78 		}
    79 	else
    80 		{
    81 		// Use the preferred supplier to select a codec.
    82 		SelectByPreference( plugInArray, aPreferredSupplier ) ;
    83 		for ( TInt ii = 0 ; ii < plugInArray.Count() ; ii++ )
    84 			{
    85 			if ( !(plugInArray[ii]->Disabled()) )
    86 				{
    87 				// we've found our plugin...
    88 				chosenUid = plugInArray[ii]->ImplementationUid() ;
    89 				break ;
    90 				}
    91 			}
    92 		}
    93 
    94 	//Instantiate the chosen one
    95 	CMMFCodec* theChosenOne = REINTERPRET_CAST( CMMFCodec*,
    96 						REComSession::CreateImplementationL( chosenUid, _FOFF( CMMFCodec, iDtor_ID_Key ) ) ) ;
    97 
    98 	CleanupStack::PopAndDestroy() ;  // pluginArray
    99 
   100 	return theChosenOne ;
   101 	}
   102 
   103 /**
   104 Creates a CMMFCodec object with known fourCC codes for source and destination.
   105 The first matching plug-in will be used.
   106 
   107 The FourCC codes are the same codes as those specified in the resource file and are used to identify
   108 the datatype. ECom scans the registry to find a codec that is registered in its resource file as
   109 being able to convert between the source data type and the destination data type as specified by
   110 their FourCC codes. If a match is found then an instantiation of the appropriate CMMFCodec is made.
   111 If a match is not found this function leaves with KErrNotFound. If more than one codec is present
   112 with the same fourCC match codes then the one that is instantiated is indeterminate. If there is
   113 likely to be any ambiguity due to more than one codec that performs the same conversion being
   114 present, then a preferred supplier should be specified.
   115 
   116 @param  aSrcDataType
   117         The source data type.
   118 @param  aDstDataType
   119         The destination data type.
   120 
   121 @return An instantiated CMMFCodec derived obeject from an ECOM plugin DLL.
   122 */
   123 EXPORT_C CMMFCodec* CMMFCodec::NewL(const TFourCC& aSrcDataType, const TFourCC& aDstDataType )
   124 	{
   125 	// Create a match string using the two FourCC codes.
   126 	return NewL( aSrcDataType, aDstDataType, KNullString ) ;
   127 
   128 	}
   129 
   130 
   131 // local function to disable items which do not match the preferred supplier.
   132 // Note that at least one enabled item is returned (if there was an enabled item to begin with) which
   133 // may not match the preferred supplier.
   134 /**
   135 Selects a codec according to the specified preference.
   136 
   137 @param  aPlugInArray
   138         On return, array of plugins.
   139 @param  aPreferredSupplier
   140         Search criteria, a supplier's name for example.
   141 */
   142 void CMMFCodec::SelectByPreference( RImplInfoPtrArray& aPlugInArray, const TDesC& aPreferredSupplier )
   143 	{	
   144 	// Use the Disabled flag to eliminated all currently enabled matches that
   145 	// do not match the preferred supplier.
   146 	TInt firstEnabled = -1 ; // to ensure that we return something valid
   147 	TInt matchCount = 0 ;
   148 	for ( TInt ii = 0 ; ii < aPlugInArray.Count() ; ii++ )
   149 		{
   150 		if ( !( aPlugInArray[ii]->Disabled() ) )
   151 			{
   152 			if ( firstEnabled == -1 )
   153 				firstEnabled = ii ;
   154 			if ( aPlugInArray[ii]->DisplayName().FindF( aPreferredSupplier ) == KErrNotFound )
   155 				aPlugInArray[ii]->SetDisabled( ETrue ) ;
   156 			else
   157 				matchCount++ ;
   158 			}
   159 		}
   160 
   161 	// If there are no matches then re-enable the first enabled
   162 	if ( matchCount == 0 )
   163 		aPlugInArray[firstEnabled]->SetDisabled( EFalse ) ;
   164 	else if ( matchCount > 1 )
   165 		{
   166 		// find the latest version from more than one match
   167 		TInt highestVersionIndex = -1 ;
   168 		for ( TInt ii = 0 ; ii < aPlugInArray.Count() ; ii++ )
   169 			{
   170 			if ( !( aPlugInArray[ii]->Disabled() ) )  // only interested in enabled elements
   171 				{
   172 				if ( highestVersionIndex == -1 )
   173 					{ // first match.  Store this.  Keep it enabled
   174 					highestVersionIndex = ii ;
   175 					}
   176 				else if ( aPlugInArray[ii]->Version() > aPlugInArray[highestVersionIndex]->Version() )
   177 					{ // a new leader.  Disable the previous leader.  Keep this one.
   178 					aPlugInArray[highestVersionIndex]->SetDisabled( ETrue ) ;
   179 					highestVersionIndex = ii ;
   180 					}
   181 				else  // we already have a higher version.
   182 					aPlugInArray[ii]->SetDisabled( ETrue ) ;
   183 				}
   184 			}
   185 		}	
   186 	}
   187 
   188 
   189 /**
   190 Creates a CMMFCodec object with a known UID.
   191 
   192 Will Leave if the plug in is not found (KErrNotFound).
   193 
   194 @param aUid
   195        The UID of a plugin implementation.
   196 
   197 @return An instantiated CMMFCodec derived obeject from an ECOM plugin DLL.
   198 */
   199 EXPORT_C CMMFCodec* CMMFCodec::NewL(TUid aUid)
   200 	{
   201 	return REINTERPRET_CAST(CMMFCodec*, REComSession::CreateImplementationL(aUid,
   202 												_FOFF(CMMFCodec,iDtor_ID_Key)));
   203 	}
   204 
   205 /**
   206 @internalComponent
   207 
   208 Gets a pointer to the extension specified by an identifier. The extension can be either an
   209 interface or function. If the extension is not supported NULL value is given and returns
   210 KErrExtensionNotSupported.
   211 
   212 @param	aExtensionId
   213 		Extension identifier.
   214 @param	aExtPtr
   215 		Pointer to get the extension.
   216 @return	If successful returns KErrNone otherwise KErrExtensionNotSupported.		
   217 */
   218 TInt CMMFCodec::ExtensionInterface(TUint aExtensionId, TAny*& aExtPtr)
   219 	{
   220 	return Extension_(aExtensionId, aExtPtr, NULL);	
   221 	}
   222