Update contrib.
1 // Copyright (c) 2003-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.
14 // This is the body of the MMF recognizer utility class
20 #include <mmf/common/mmfcontrollerpluginresolver.h>
21 #include "RecMmfUtilBody.h"
22 #include <mmf/server/mmfdatasourcesink.hrh>
25 // MMF Recognizer Utility class body constructor
26 CMmfRecognizerUtil::CBody::CBody():
27 CActive(CActive::EPriorityStandard)
31 CMmfRecognizerUtil::CBody::~CBody()
35 iControllers.ResetAndDestroy();
38 // Request ECom to be notified when interface implementation registration
39 // data changes so that we can refresh the list of interface implementations.
40 void CMmfRecognizerUtil::CBody::StartNotification()
42 iEcomSession.NotifyOnChange(iStatus);
46 // build a list of interface implementation objects
47 void CMmfRecognizerUtil::CBody::BuildControllerListL()
49 iControllers.ResetAndDestroy();
50 CMMFControllerPluginSelectionParameters* cSelect =
51 CMMFControllerPluginSelectionParameters::NewLC();
53 CMMFFormatSelectionParameters* fSelect =
54 CMMFFormatSelectionParameters::NewLC();
56 cSelect->SetRequiredPlayFormatSupportL(*fSelect);
59 RArray<TUid> mediaIds;
60 CleanupClosePushL(mediaIds);
62 User::LeaveIfError(mediaIds.Append(KUidMediaTypeAudio));
63 User::LeaveIfError(mediaIds.Append(KUidMediaTypeVideo));
64 cSelect->SetMediaIdsL(mediaIds, CMMFPluginSelectionParameters::EAllowOtherMediaIds);
66 cSelect->ListImplementationsL(iControllers);
69 CleanupStack::PopAndDestroy(3, cSelect);// mediaIds, fSelect, cSelect
72 void CMmfRecognizerUtil::CBody::ConstructL()
74 BuildControllerListL();
76 CActiveScheduler::Add(this);
78 iEcomSession = REComSession::OpenL();
80 // request notification from ECOM of any file system changes
84 void CMmfRecognizerUtil::CBody::RunL()
86 BuildControllerListL();
90 void CMmfRecognizerUtil::CBody::DoCancel()
92 if (iStatus == KRequestPending)
93 iEcomSession.CancelNotifyOnChange(iStatus);
96 /* Determine whether the supplied data header on its own is recognized,
97 or the data header plus the file suffix together are recognized,
98 and if so return the associated MIME type.
103 A descriptor containing the header
105 A user-supplied descriptor in which the MIME type is returned
107 Not enough data in descriptor to identify whether it is supported
109 @leave This method may also leave with one of the system-wide error codes.
110 @return EMatchNone if a match was not found.
111 EMatchData if a data match was found.
112 EMatchName if a data and file suffix match was found.
113 @post If recognized, the caller's descriptor is filled with the MIME types
115 CMmfRecognizerUtil::TMatchLevel CMmfRecognizerUtil::CBody::GetMimeTypeL(const TDesC& aFileName, const TDesC8& aImageData, TDes8& aMimeType)
117 CMmfRecognizerUtil::TMatchLevel matchLevel = EMatchNone;
122 // aFileName's length could be greater than KMaxFileName
123 // so don't use TFileName here
124 TPtrC fName(aFileName);
125 if (aFileName.Match(_L("::*")) == 0)
127 fName.Set(aFileName.Mid(2));
129 User::LeaveIfError(fileName.Set(fName, NULL, NULL));
131 HBufC8* fileSuffix = NULL;
132 if(fileName.ExtPresent())
134 TPtrC suffixPtr(fileName.Ext());
135 fileSuffix = HBufC8::NewLC(suffixPtr.Length());
136 fileSuffix->Des().Copy(suffixPtr);
139 // loop through every supported Format of every controller
140 // until we find one that matches the data header on its own,
141 // or the data header plus the file suffix together
142 for (TInt nController = 0, countControllers = iControllers.Count(); nController < countControllers; nController++)
144 CMMFControllerImplementationInformation* controllerImpInfo = iControllers[nController];
146 for (TInt nPlayFormat = 0, countFormats = controllerImpInfo->PlayFormats().Count(); nPlayFormat < countFormats; nPlayFormat++)
148 const CMMFFormatImplementationInformation* formatImpInfo =
149 controllerImpInfo->PlayFormats()[nPlayFormat];
150 if (formatImpInfo->SupportsHeaderDataL(aImageData))
152 const CDesC8Array& supportedMimeTypes = formatImpInfo->SupportedMimeTypes();
153 if (supportedMimeTypes.Count() > 0)
155 CMmfRecognizerUtil::TMatchLevel previousMatchLevel = matchLevel;
156 if(fileSuffix && formatImpInfo->SupportsFileExtension(*fileSuffix))
157 matchLevel = EMatchName;
159 matchLevel = EMatchData;
160 // Use first data match but update if suffix match is found
161 if(matchLevel!=previousMatchLevel)
162 aMimeType = supportedMimeTypes[0]; // just return the first mime type in the array
165 if(matchLevel==EMatchName || (!fileSuffix && matchLevel==EMatchData))
168 if(matchLevel==EMatchName || (!fileSuffix && matchLevel==EMatchData))
173 CleanupStack::PopAndDestroy(fileSuffix);
178 // Static factory constructor. Uses two phase
179 // construction and leaves nothing on the cleanup stack
180 // @leave KErrNoMemory
181 // @return A pointer to the newly created CMmfRecognizerUtilBody object
182 CMmfRecognizerUtil::CBody* CMmfRecognizerUtil::CBody::NewL()
184 CBody* self=new (ELeave) CBody();
185 CleanupStack::PushL(self);
187 CleanupStack::Pop(self);
191 // Get all the mime types supported by MMF
193 // A caller-supplied array of descriptors.
194 // @leave This method may leave with one of the system-wide error codes.
195 // @post The caller's array is filled with the supported MIME types
196 void CMmfRecognizerUtil::CBody::GetMimeTypesL(CDesC8Array* aMimeTypes)
199 CMMFControllerPluginSelectionParameters* cSelect =
200 CMMFControllerPluginSelectionParameters::NewLC();
201 CMMFFormatSelectionParameters* fSelect = CMMFFormatSelectionParameters::NewLC();
203 // Set the play format selection parameters to be blank
204 // - format support Is only retrieved if requested.
205 cSelect->SetRequiredPlayFormatSupportL(*fSelect);
208 RArray<TUid> mediaIds;
209 CleanupClosePushL(mediaIds);
210 User::LeaveIfError(mediaIds.Append(KUidMediaTypeVideo));
211 User::LeaveIfError(mediaIds.Append(KUidMediaTypeAudio));
212 cSelect->SetMediaIdsL(mediaIds, CMMFPluginSelectionParameters::EAllowOtherMediaIds);
214 // Array to hold all the controller plugins
215 RMMFControllerImplInfoArray controllers;
217 CleanupResetAndDestroyPushL(controllers);
218 cSelect->ListImplementationsL(controllers);
220 for (TInt nController = 0, controllerCount = controllers.Count(); nController < controllerCount; nController++)
222 for (TInt nPlayFormat = 0, formatCount = controllers[nController]->PlayFormats().Count(); nPlayFormat < formatCount; nPlayFormat++)
224 const CMMFFormatImplementationInformation* formatImpInfo = controllers[nController]->PlayFormats()[nPlayFormat];
225 const CDesC8Array& supportedMimeTypes = formatImpInfo->SupportedMimeTypes();
226 for (TInt nMimeType = 0, mimeTypeCount = supportedMimeTypes.Count(); nMimeType < mimeTypeCount; nMimeType++)
228 aMimeTypes->AppendL(supportedMimeTypes[nMimeType]);
234 CleanupStack::PopAndDestroy(4, cSelect);//controllers, mediaIds, fSelect, cSelect