sl@0
|
1 |
// Copyright (c) 2003-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 |
// This is the body of the MMF recognizer utility class
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <badesca.h>
|
sl@0
|
19 |
|
sl@0
|
20 |
#include <mmf/common/mmfcontrollerpluginresolver.h>
|
sl@0
|
21 |
#include "RecMmfUtilBody.h"
|
sl@0
|
22 |
#include <mmf/server/mmfdatasourcesink.hrh>
|
sl@0
|
23 |
|
sl@0
|
24 |
|
sl@0
|
25 |
// MMF Recognizer Utility class body constructor
|
sl@0
|
26 |
CMmfRecognizerUtil::CBody::CBody():
|
sl@0
|
27 |
CActive(CActive::EPriorityStandard)
|
sl@0
|
28 |
{
|
sl@0
|
29 |
}
|
sl@0
|
30 |
|
sl@0
|
31 |
CMmfRecognizerUtil::CBody::~CBody()
|
sl@0
|
32 |
{
|
sl@0
|
33 |
Cancel();
|
sl@0
|
34 |
iEcomSession.Close();
|
sl@0
|
35 |
iControllers.ResetAndDestroy();
|
sl@0
|
36 |
}
|
sl@0
|
37 |
|
sl@0
|
38 |
// Request ECom to be notified when interface implementation registration
|
sl@0
|
39 |
// data changes so that we can refresh the list of interface implementations.
|
sl@0
|
40 |
void CMmfRecognizerUtil::CBody::StartNotification()
|
sl@0
|
41 |
{
|
sl@0
|
42 |
iEcomSession.NotifyOnChange(iStatus);
|
sl@0
|
43 |
SetActive();
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
// build a list of interface implementation objects
|
sl@0
|
47 |
void CMmfRecognizerUtil::CBody::BuildControllerListL()
|
sl@0
|
48 |
{
|
sl@0
|
49 |
iControllers.ResetAndDestroy();
|
sl@0
|
50 |
CMMFControllerPluginSelectionParameters* cSelect =
|
sl@0
|
51 |
CMMFControllerPluginSelectionParameters::NewLC();
|
sl@0
|
52 |
|
sl@0
|
53 |
CMMFFormatSelectionParameters* fSelect =
|
sl@0
|
54 |
CMMFFormatSelectionParameters::NewLC();
|
sl@0
|
55 |
|
sl@0
|
56 |
cSelect->SetRequiredPlayFormatSupportL(*fSelect);
|
sl@0
|
57 |
|
sl@0
|
58 |
// Set the media ids
|
sl@0
|
59 |
RArray<TUid> mediaIds;
|
sl@0
|
60 |
CleanupClosePushL(mediaIds);
|
sl@0
|
61 |
|
sl@0
|
62 |
User::LeaveIfError(mediaIds.Append(KUidMediaTypeAudio));
|
sl@0
|
63 |
User::LeaveIfError(mediaIds.Append(KUidMediaTypeVideo));
|
sl@0
|
64 |
cSelect->SetMediaIdsL(mediaIds, CMMFPluginSelectionParameters::EAllowOtherMediaIds);
|
sl@0
|
65 |
|
sl@0
|
66 |
cSelect->ListImplementationsL(iControllers);
|
sl@0
|
67 |
|
sl@0
|
68 |
// Clean up
|
sl@0
|
69 |
CleanupStack::PopAndDestroy(3, cSelect);// mediaIds, fSelect, cSelect
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
void CMmfRecognizerUtil::CBody::ConstructL()
|
sl@0
|
73 |
{
|
sl@0
|
74 |
BuildControllerListL();
|
sl@0
|
75 |
|
sl@0
|
76 |
CActiveScheduler::Add(this);
|
sl@0
|
77 |
|
sl@0
|
78 |
iEcomSession = REComSession::OpenL();
|
sl@0
|
79 |
|
sl@0
|
80 |
// request notification from ECOM of any file system changes
|
sl@0
|
81 |
StartNotification();
|
sl@0
|
82 |
}
|
sl@0
|
83 |
|
sl@0
|
84 |
void CMmfRecognizerUtil::CBody::RunL()
|
sl@0
|
85 |
{
|
sl@0
|
86 |
BuildControllerListL();
|
sl@0
|
87 |
StartNotification();
|
sl@0
|
88 |
}
|
sl@0
|
89 |
|
sl@0
|
90 |
void CMmfRecognizerUtil::CBody::DoCancel()
|
sl@0
|
91 |
{
|
sl@0
|
92 |
if (iStatus == KRequestPending)
|
sl@0
|
93 |
iEcomSession.CancelNotifyOnChange(iStatus);
|
sl@0
|
94 |
}
|
sl@0
|
95 |
|
sl@0
|
96 |
/* Determine whether the supplied data header on its own is recognized,
|
sl@0
|
97 |
or the data header plus the file suffix together are recognized,
|
sl@0
|
98 |
and if so return the associated MIME type.
|
sl@0
|
99 |
|
sl@0
|
100 |
@param aFileName
|
sl@0
|
101 |
The name of the file
|
sl@0
|
102 |
@param aImageData
|
sl@0
|
103 |
A descriptor containing the header
|
sl@0
|
104 |
@param aMimeType
|
sl@0
|
105 |
A user-supplied descriptor in which the MIME type is returned
|
sl@0
|
106 |
@leave KErrUnderflow
|
sl@0
|
107 |
Not enough data in descriptor to identify whether it is supported
|
sl@0
|
108 |
by any plugin.
|
sl@0
|
109 |
@leave This method may also leave with one of the system-wide error codes.
|
sl@0
|
110 |
@return EMatchNone if a match was not found.
|
sl@0
|
111 |
EMatchData if a data match was found.
|
sl@0
|
112 |
EMatchName if a data and file suffix match was found.
|
sl@0
|
113 |
@post If recognized, the caller's descriptor is filled with the MIME types
|
sl@0
|
114 |
*/
|
sl@0
|
115 |
CMmfRecognizerUtil::TMatchLevel CMmfRecognizerUtil::CBody::GetMimeTypeL(const TDesC& aFileName, const TDesC8& aImageData, TDes8& aMimeType)
|
sl@0
|
116 |
{
|
sl@0
|
117 |
CMmfRecognizerUtil::TMatchLevel matchLevel = EMatchNone;
|
sl@0
|
118 |
|
sl@0
|
119 |
//Get the suffix
|
sl@0
|
120 |
TParse fileName;
|
sl@0
|
121 |
|
sl@0
|
122 |
// aFileName's length could be greater than KMaxFileName
|
sl@0
|
123 |
// so don't use TFileName here
|
sl@0
|
124 |
TPtrC fName(aFileName);
|
sl@0
|
125 |
if (aFileName.Match(_L("::*")) == 0)
|
sl@0
|
126 |
{
|
sl@0
|
127 |
fName.Set(aFileName.Mid(2));
|
sl@0
|
128 |
}
|
sl@0
|
129 |
User::LeaveIfError(fileName.Set(fName, NULL, NULL));
|
sl@0
|
130 |
|
sl@0
|
131 |
HBufC8* fileSuffix = NULL;
|
sl@0
|
132 |
if(fileName.ExtPresent())
|
sl@0
|
133 |
{
|
sl@0
|
134 |
TPtrC suffixPtr(fileName.Ext());
|
sl@0
|
135 |
fileSuffix = HBufC8::NewLC(suffixPtr.Length());
|
sl@0
|
136 |
fileSuffix->Des().Copy(suffixPtr);
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
// loop through every supported Format of every controller
|
sl@0
|
140 |
// until we find one that matches the data header on its own,
|
sl@0
|
141 |
// or the data header plus the file suffix together
|
sl@0
|
142 |
for (TInt nController = 0, countControllers = iControllers.Count(); nController < countControllers; nController++)
|
sl@0
|
143 |
{
|
sl@0
|
144 |
CMMFControllerImplementationInformation* controllerImpInfo = iControllers[nController];
|
sl@0
|
145 |
|
sl@0
|
146 |
for (TInt nPlayFormat = 0, countFormats = controllerImpInfo->PlayFormats().Count(); nPlayFormat < countFormats; nPlayFormat++)
|
sl@0
|
147 |
{
|
sl@0
|
148 |
const CMMFFormatImplementationInformation* formatImpInfo =
|
sl@0
|
149 |
controllerImpInfo->PlayFormats()[nPlayFormat];
|
sl@0
|
150 |
if (formatImpInfo->SupportsHeaderDataL(aImageData))
|
sl@0
|
151 |
{
|
sl@0
|
152 |
const CDesC8Array& supportedMimeTypes = formatImpInfo->SupportedMimeTypes();
|
sl@0
|
153 |
if (supportedMimeTypes.Count() > 0)
|
sl@0
|
154 |
{
|
sl@0
|
155 |
CMmfRecognizerUtil::TMatchLevel previousMatchLevel = matchLevel;
|
sl@0
|
156 |
if(fileSuffix && formatImpInfo->SupportsFileExtension(*fileSuffix))
|
sl@0
|
157 |
matchLevel = EMatchName;
|
sl@0
|
158 |
else
|
sl@0
|
159 |
matchLevel = EMatchData;
|
sl@0
|
160 |
// Use first data match but update if suffix match is found
|
sl@0
|
161 |
if(matchLevel!=previousMatchLevel)
|
sl@0
|
162 |
aMimeType = supportedMimeTypes[0]; // just return the first mime type in the array
|
sl@0
|
163 |
}
|
sl@0
|
164 |
}
|
sl@0
|
165 |
if(matchLevel==EMatchName || (!fileSuffix && matchLevel==EMatchData))
|
sl@0
|
166 |
break;
|
sl@0
|
167 |
}
|
sl@0
|
168 |
if(matchLevel==EMatchName || (!fileSuffix && matchLevel==EMatchData))
|
sl@0
|
169 |
break;
|
sl@0
|
170 |
}
|
sl@0
|
171 |
|
sl@0
|
172 |
if(fileSuffix)
|
sl@0
|
173 |
CleanupStack::PopAndDestroy(fileSuffix);
|
sl@0
|
174 |
|
sl@0
|
175 |
return matchLevel;
|
sl@0
|
176 |
}
|
sl@0
|
177 |
|
sl@0
|
178 |
// Static factory constructor. Uses two phase
|
sl@0
|
179 |
// construction and leaves nothing on the cleanup stack
|
sl@0
|
180 |
// @leave KErrNoMemory
|
sl@0
|
181 |
// @return A pointer to the newly created CMmfRecognizerUtilBody object
|
sl@0
|
182 |
CMmfRecognizerUtil::CBody* CMmfRecognizerUtil::CBody::NewL()
|
sl@0
|
183 |
{
|
sl@0
|
184 |
CBody* self=new (ELeave) CBody();
|
sl@0
|
185 |
CleanupStack::PushL(self);
|
sl@0
|
186 |
self->ConstructL();
|
sl@0
|
187 |
CleanupStack::Pop(self);
|
sl@0
|
188 |
return self;
|
sl@0
|
189 |
}
|
sl@0
|
190 |
|
sl@0
|
191 |
// Get all the mime types supported by MMF
|
sl@0
|
192 |
// @param aMimeTypes
|
sl@0
|
193 |
// A caller-supplied array of descriptors.
|
sl@0
|
194 |
// @leave This method may leave with one of the system-wide error codes.
|
sl@0
|
195 |
// @post The caller's array is filled with the supported MIME types
|
sl@0
|
196 |
void CMmfRecognizerUtil::CBody::GetMimeTypesL(CDesC8Array* aMimeTypes)
|
sl@0
|
197 |
{
|
sl@0
|
198 |
|
sl@0
|
199 |
CMMFControllerPluginSelectionParameters* cSelect =
|
sl@0
|
200 |
CMMFControllerPluginSelectionParameters::NewLC();
|
sl@0
|
201 |
CMMFFormatSelectionParameters* fSelect = CMMFFormatSelectionParameters::NewLC();
|
sl@0
|
202 |
|
sl@0
|
203 |
// Set the play format selection parameters to be blank
|
sl@0
|
204 |
// - format support Is only retrieved if requested.
|
sl@0
|
205 |
cSelect->SetRequiredPlayFormatSupportL(*fSelect);
|
sl@0
|
206 |
|
sl@0
|
207 |
// Set the media ids
|
sl@0
|
208 |
RArray<TUid> mediaIds;
|
sl@0
|
209 |
CleanupClosePushL(mediaIds);
|
sl@0
|
210 |
User::LeaveIfError(mediaIds.Append(KUidMediaTypeVideo));
|
sl@0
|
211 |
User::LeaveIfError(mediaIds.Append(KUidMediaTypeAudio));
|
sl@0
|
212 |
cSelect->SetMediaIdsL(mediaIds, CMMFPluginSelectionParameters::EAllowOtherMediaIds);
|
sl@0
|
213 |
|
sl@0
|
214 |
// Array to hold all the controller plugins
|
sl@0
|
215 |
RMMFControllerImplInfoArray controllers;
|
sl@0
|
216 |
|
sl@0
|
217 |
CleanupResetAndDestroyPushL(controllers);
|
sl@0
|
218 |
cSelect->ListImplementationsL(controllers);
|
sl@0
|
219 |
|
sl@0
|
220 |
for (TInt nController = 0, controllerCount = controllers.Count(); nController < controllerCount; nController++)
|
sl@0
|
221 |
{
|
sl@0
|
222 |
for (TInt nPlayFormat = 0, formatCount = controllers[nController]->PlayFormats().Count(); nPlayFormat < formatCount; nPlayFormat++)
|
sl@0
|
223 |
{
|
sl@0
|
224 |
const CMMFFormatImplementationInformation* formatImpInfo = controllers[nController]->PlayFormats()[nPlayFormat];
|
sl@0
|
225 |
const CDesC8Array& supportedMimeTypes = formatImpInfo->SupportedMimeTypes();
|
sl@0
|
226 |
for (TInt nMimeType = 0, mimeTypeCount = supportedMimeTypes.Count(); nMimeType < mimeTypeCount; nMimeType++)
|
sl@0
|
227 |
{
|
sl@0
|
228 |
aMimeTypes->AppendL(supportedMimeTypes[nMimeType]);
|
sl@0
|
229 |
}
|
sl@0
|
230 |
}
|
sl@0
|
231 |
}
|
sl@0
|
232 |
|
sl@0
|
233 |
// Clean up
|
sl@0
|
234 |
CleanupStack::PopAndDestroy(4, cSelect);//controllers, mediaIds, fSelect, cSelect
|
sl@0
|
235 |
}
|
sl@0
|
236 |
|
sl@0
|
237 |
|
sl@0
|
238 |
|
sl@0
|
239 |
|
sl@0
|
240 |
|