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