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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
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>
23 _LIT8( KEmptyFourCCString, " , " ) ;
24 _LIT( KNullString, "" ) ;
26 static const TUid KUidMmfPluginInterfaceCodec = {KMmfUidPluginInterfaceCodec};
29 Creates a CMMFCodec object with match parameter in addition to the source and
30 destination fourCC codes (for instance a manufacturer's name).
32 Will attempt match without extra match string if no match.
34 Will Leave if no match on 4CC codes (KErrNotFound).
36 Used where there may be multiple codecs that perform the same conversion to ensure the controller
37 uses the codec specified by aPreferredSupplier.
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.
48 @return An instantiated CMMFCodec derived obeject from an ECOM plugin DLL.
50 EXPORT_C CMMFCodec* CMMFCodec::NewL(const TFourCC& aSrcDataType, const TFourCC& aDstDataType, const TDesC& aPreferredSupplier)
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 ) ;
61 // Do a list implementations here.
63 RImplInfoPtrArray plugInArray; // Array to return matching decoders in
64 CleanupResetAndDestroyPushL(plugInArray);
66 MmPluginUtils::FindImplementationsL(KUidMmfPluginInterfaceCodec, plugInArray, fourCCPtr);
68 if (plugInArray.Count() == 0)
70 User::Leave(KErrNotSupported);
75 if ( plugInArray.Count() == 1 )
77 chosenUid = plugInArray[0]->ImplementationUid() ;
81 // Use the preferred supplier to select a codec.
82 SelectByPreference( plugInArray, aPreferredSupplier ) ;
83 for ( TInt ii = 0 ; ii < plugInArray.Count() ; ii++ )
85 if ( !(plugInArray[ii]->Disabled()) )
87 // we've found our plugin...
88 chosenUid = plugInArray[ii]->ImplementationUid() ;
94 //Instantiate the chosen one
95 CMMFCodec* theChosenOne = REINTERPRET_CAST( CMMFCodec*,
96 REComSession::CreateImplementationL( chosenUid, _FOFF( CMMFCodec, iDtor_ID_Key ) ) ) ;
98 CleanupStack::PopAndDestroy() ; // pluginArray
100 return theChosenOne ;
104 Creates a CMMFCodec object with known fourCC codes for source and destination.
105 The first matching plug-in will be used.
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.
117 The source data type.
119 The destination data type.
121 @return An instantiated CMMFCodec derived obeject from an ECOM plugin DLL.
123 EXPORT_C CMMFCodec* CMMFCodec::NewL(const TFourCC& aSrcDataType, const TFourCC& aDstDataType )
125 // Create a match string using the two FourCC codes.
126 return NewL( aSrcDataType, aDstDataType, KNullString ) ;
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.
135 Selects a codec according to the specified preference.
138 On return, array of plugins.
139 @param aPreferredSupplier
140 Search criteria, a supplier's name for example.
142 void CMMFCodec::SelectByPreference( RImplInfoPtrArray& aPlugInArray, const TDesC& aPreferredSupplier )
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++ )
150 if ( !( aPlugInArray[ii]->Disabled() ) )
152 if ( firstEnabled == -1 )
154 if ( aPlugInArray[ii]->DisplayName().FindF( aPreferredSupplier ) == KErrNotFound )
155 aPlugInArray[ii]->SetDisabled( ETrue ) ;
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 )
166 // find the latest version from more than one match
167 TInt highestVersionIndex = -1 ;
168 for ( TInt ii = 0 ; ii < aPlugInArray.Count() ; ii++ )
170 if ( !( aPlugInArray[ii]->Disabled() ) ) // only interested in enabled elements
172 if ( highestVersionIndex == -1 )
173 { // first match. Store this. Keep it enabled
174 highestVersionIndex = ii ;
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 ;
181 else // we already have a higher version.
182 aPlugInArray[ii]->SetDisabled( ETrue ) ;
190 Creates a CMMFCodec object with a known UID.
192 Will Leave if the plug in is not found (KErrNotFound).
195 The UID of a plugin implementation.
197 @return An instantiated CMMFCodec derived obeject from an ECOM plugin DLL.
199 EXPORT_C CMMFCodec* CMMFCodec::NewL(TUid aUid)
201 return REINTERPRET_CAST(CMMFCodec*, REComSession::CreateImplementationL(aUid,
202 _FOFF(CMMFCodec,iDtor_ID_Key)));
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.
213 Extension identifier.
215 Pointer to get the extension.
216 @return If successful returns KErrNone otherwise KErrExtensionNotSupported.
218 TInt CMMFCodec::ExtensionInterface(TUint aExtensionId, TAny*& aExtPtr)
220 return Extension_(aExtensionId, aExtPtr, NULL);