25
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Metadata backend engine
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
19
|
18 |
#include <OpenMAXAL.h>
|
|
19 |
#include <string.h>
|
|
20 |
#include <ctype.h>
|
|
21 |
#include <uri8.h>
|
25
|
22 |
#include "cmetadatautilityitf.h"
|
19
|
23 |
#include "profileutilmacro.h"
|
|
24 |
|
25
|
25 |
CMetadataUtilityItf::CMetadataUtilityItf() :
|
|
26 |
m_pS60Util(NULL), m_pHXUtil(NULL)
|
|
27 |
{
|
|
28 |
}
|
19
|
29 |
|
|
30 |
CMetadataUtilityItf::~CMetadataUtilityItf()
|
25
|
31 |
{
|
|
32 |
if (m_pS60Util)
|
|
33 |
{
|
|
34 |
delete m_pS60Util;
|
|
35 |
}
|
19
|
36 |
|
25
|
37 |
if (m_pHXUtil)
|
|
38 |
{
|
|
39 |
delete m_pHXUtil;
|
|
40 |
}
|
|
41 |
}
|
19
|
42 |
|
|
43 |
CMetadataUtilityItf* CMetadataUtilityItf::New(char* uri)
|
25
|
44 |
{
|
|
45 |
CMetadataUtilityItf* p_mdutilitf = new CMetadataUtilityItf;
|
19
|
46 |
|
25
|
47 |
p_mdutilitf->ParseSource(uri); //ignore error
|
|
48 |
|
|
49 |
return p_mdutilitf;
|
|
50 |
}
|
19
|
51 |
|
|
52 |
TInt CMetadataUtilityItf::OpenSource(char* pOrigUri)
|
25
|
53 |
{
|
19
|
54 |
//Make a local copy for uri
|
25
|
55 |
if (!pOrigUri)
|
19
|
56 |
return XA_RESULT_PARAMETER_INVALID;
|
25
|
57 |
|
19
|
58 |
int uriLen = strlen(pOrigUri);
|
25
|
59 |
char* uri = new char[uriLen + 1];
|
|
60 |
if (!uri)
|
19
|
61 |
{
|
|
62 |
return XA_RESULT_MEMORY_FAILURE;
|
|
63 |
}
|
|
64 |
strncpy(uri, pOrigUri, uriLen);
|
|
65 |
uri[uriLen] = '\0';
|
|
66 |
////////////////////////////////////////////
|
|
67 |
_LIT8(KFileSlash,"file:///");
|
|
68 |
TInt fileslashlen = KFileSlash().Length();
|
|
69 |
|
25
|
70 |
TPtr8 fileuri((TUint8*) uri, strlen(uri), strlen(uri));
|
|
71 |
TPtr8 filepath = fileuri.RightTPtr(strlen(uri) - fileslashlen);
|
|
72 |
|
19
|
73 |
TInt pos = filepath.LocateReverse(':');
|
25
|
74 |
if (pos != KErrNotFound)
|
|
75 |
{
|
|
76 |
fileuri.Delete(fileslashlen + pos, 1);
|
|
77 |
}
|
19
|
78 |
|
|
79 |
TUriParser8 localfileUri;
|
|
80 |
TInt ret = localfileUri.Parse(fileuri);
|
25
|
81 |
if (ret == KErrNone)
|
19
|
82 |
{
|
25
|
83 |
HBufC* file = NULL;
|
|
84 |
TRAP(ret,file = localfileUri.GetFileNameL());
|
|
85 |
if (ret == KErrNone)
|
|
86 |
{
|
|
87 |
if (m_pS60Util)
|
|
88 |
{
|
|
89 |
ret = m_pS60Util->ParseSource(*file);
|
|
90 |
}
|
|
91 |
else if (m_pHXUtil)
|
|
92 |
{
|
|
93 |
ret = m_pHXUtil->ParseSource(*file);
|
|
94 |
}
|
|
95 |
else
|
|
96 |
{
|
|
97 |
ret = KErrNotFound;
|
|
98 |
}
|
|
99 |
}
|
|
100 |
|
|
101 |
delete file;
|
19
|
102 |
}
|
25
|
103 |
|
|
104 |
if (uri)
|
|
105 |
{
|
|
106 |
delete[] uri;
|
|
107 |
}
|
|
108 |
|
|
109 |
if (ret != KErrNone)
|
|
110 |
{
|
|
111 |
//delete the utilities
|
|
112 |
if (m_pS60Util)
|
|
113 |
{
|
|
114 |
delete m_pS60Util;
|
|
115 |
m_pS60Util = NULL;
|
|
116 |
}
|
|
117 |
|
|
118 |
if (m_pHXUtil)
|
|
119 |
{
|
|
120 |
delete m_pHXUtil;
|
|
121 |
m_pHXUtil = NULL;
|
|
122 |
}
|
|
123 |
|
|
124 |
}
|
|
125 |
return ret;
|
19
|
126 |
}
|
21
|
127 |
|
25
|
128 |
TInt CMetadataUtilityItf::ExtractUCS2(TDesC& inDes, char* outPtr, TInt maxLen)
|
|
129 |
{
|
|
130 |
TPtrC tempPtr = inDes.Left((maxLen / 2) - 1); //save last one for null terminator
|
|
131 |
TInt outLen = tempPtr.Length() + 1;
|
21
|
132 |
|
25
|
133 |
TPtr16 outDes((unsigned short*) outPtr, outLen);
|
|
134 |
outDes.Copy(tempPtr);
|
|
135 |
outDes.ZeroTerminate();
|
19
|
136 |
|
25
|
137 |
return outLen * 2; //return size
|
|
138 |
}
|
19
|
139 |
|
|
140 |
TInt CMetadataUtilityItf::CalculateNumMetadataItems(TUint*numItems)
|
25
|
141 |
{
|
|
142 |
*numItems = 0;
|
21
|
143 |
|
25
|
144 |
if (m_pS60Util)
|
|
145 |
{
|
|
146 |
return m_pS60Util->CalculateNumMetadataItems(numItems);
|
|
147 |
}
|
|
148 |
else if (m_pHXUtil)
|
|
149 |
{
|
|
150 |
return m_pHXUtil->CalculateNumMetadataItems(numItems);
|
|
151 |
}
|
|
152 |
|
|
153 |
return KErrNone;
|
|
154 |
}
|
19
|
155 |
|
|
156 |
char* CMetadataUtilityItf::GetKey(TInt index)
|
25
|
157 |
{
|
|
158 |
if (m_pS60Util)
|
|
159 |
{
|
|
160 |
return m_pS60Util->GetKey(index);
|
|
161 |
}
|
|
162 |
else if (m_pHXUtil)
|
|
163 |
{
|
|
164 |
return m_pHXUtil->GetKey(index);
|
|
165 |
}
|
21
|
166 |
|
25
|
167 |
return NULL;
|
|
168 |
}
|
19
|
169 |
|
|
170 |
TInt CMetadataUtilityItf::GetValueSize(TInt index)
|
25
|
171 |
{
|
|
172 |
if (m_pS60Util)
|
|
173 |
{
|
|
174 |
return m_pS60Util->GetValueSize(index);
|
|
175 |
}
|
|
176 |
else if (m_pHXUtil)
|
|
177 |
{
|
|
178 |
return m_pHXUtil->GetValueSize(index);
|
|
179 |
}
|
21
|
180 |
|
25
|
181 |
return 0;
|
|
182 |
}
|
19
|
183 |
|
25
|
184 |
TInt CMetadataUtilityItf::GetValue(TInt index, char* data, TInt maxLength,
|
|
185 |
TInt* outSize, TInt* encodingType)
|
|
186 |
{
|
|
187 |
if (m_pS60Util)
|
|
188 |
{
|
|
189 |
return m_pS60Util->GetValue(index, data, maxLength, outSize,
|
|
190 |
encodingType);
|
|
191 |
}
|
|
192 |
else if (m_pHXUtil)
|
|
193 |
{
|
|
194 |
return m_pHXUtil->GetValue(index, data, maxLength, outSize,
|
|
195 |
encodingType);
|
|
196 |
}
|
21
|
197 |
|
25
|
198 |
return 0;
|
|
199 |
}
|
19
|
200 |
|
|
201 |
TInt CMetadataUtilityItf::ParseSource(char* uri)
|
25
|
202 |
{
|
|
203 |
char* tempPtr = NULL;
|
|
204 |
char extension[MAX_EXTENSION_SIZE] =
|
|
205 |
{
|
|
206 |
0
|
|
207 |
};
|
|
208 |
|
|
209 |
tempPtr = strchr(uri, (int) '.');
|
|
210 |
strncpy(extension, tempPtr, sizeof(tempPtr));
|
19
|
211 |
|
25
|
212 |
for (unsigned int i = 0; i < sizeof(extension); i++)
|
|
213 |
{
|
|
214 |
extension[i] = tolower(extension[i]);
|
|
215 |
}
|
|
216 |
|
|
217 |
//if s60 util in use
|
|
218 |
if (m_pS60Util)
|
|
219 |
{
|
|
220 |
//reset existing instace
|
|
221 |
TInt ret = m_pS60Util->Reset();
|
|
222 |
if (!CS60MetadataUtilityItf::IsSupportedExtension(extension))
|
|
223 |
{
|
|
224 |
delete m_pS60Util;
|
|
225 |
m_pS60Util = NULL;
|
|
226 |
}
|
|
227 |
}
|
19
|
228 |
|
25
|
229 |
if (m_pHXUtil)
|
|
230 |
{
|
|
231 |
//reset existing instace
|
|
232 |
TInt ret = m_pHXUtil->Reset();
|
|
233 |
if (CS60MetadataUtilityItf::IsSupportedExtension(extension))
|
|
234 |
{
|
|
235 |
delete m_pHXUtil;
|
|
236 |
m_pHXUtil = NULL;
|
|
237 |
}
|
|
238 |
}
|
19
|
239 |
|
25
|
240 |
if (!m_pS60Util && !m_pHXUtil)
|
|
241 |
{
|
19
|
242 |
|
25
|
243 |
if (CS60MetadataUtilityItf::IsSupportedExtension(extension))
|
|
244 |
{
|
|
245 |
m_pS60Util = CS60MetadataUtilityItf::New();
|
|
246 |
}
|
|
247 |
else
|
|
248 |
{
|
|
249 |
m_pHXUtil = CHXMetadataUtilityItf::New();
|
|
250 |
}
|
|
251 |
}
|
19
|
252 |
|
25
|
253 |
return OpenSource(uri);
|
|
254 |
}
|
19
|
255 |
|
|
256 |
bool CS60MetadataUtilityItf::IsSupportedExtension(char *extn)
|
25
|
257 |
{
|
|
258 |
if ((!strcasecmp(extn, ".mp3")) || (!strcasecmp(extn, ".wma"))
|
|
259 |
|| (!strcasecmp(extn, ".aac")) || (!strcasecmp(extn, ".wav"))
|
|
260 |
|| (!strcasecmp(extn, ".m4a")))
|
|
261 |
{
|
|
262 |
return true;
|
|
263 |
}
|
19
|
264 |
|
25
|
265 |
return false;
|
|
266 |
}
|
19
|
267 |
|
|
268 |
CS60MetadataUtilityItf* CS60MetadataUtilityItf::New()
|
25
|
269 |
{
|
|
270 |
CS60MetadataUtilityItf* self = new CS60MetadataUtilityItf();
|
|
271 |
|
|
272 |
TInt err = KErrGeneral;
|
|
273 |
TRAP(err, self->ConstructL());
|
19
|
274 |
|
25
|
275 |
if (err == KErrNone)
|
|
276 |
{
|
|
277 |
return self;
|
|
278 |
}
|
19
|
279 |
|
25
|
280 |
delete self;
|
|
281 |
return NULL;
|
|
282 |
}
|
19
|
283 |
|
25
|
284 |
CS60MetadataUtilityItf::CS60MetadataUtilityItf() :
|
|
285 |
pMetaDataUtility(NULL)
|
|
286 |
{
|
|
287 |
}
|
19
|
288 |
|
|
289 |
void CS60MetadataUtilityItf::ConstructL()
|
25
|
290 |
{
|
|
291 |
TAG_TIME_PROFILING_BEGIN;
|
|
292 |
pMetaDataUtility = CMetaDataUtility::NewL();
|
|
293 |
TAG_TIME_PROFILING_END; PRINT_TO_CONSOLE_TIME_DIFF;
|
|
294 |
}
|
|
295 |
|
19
|
296 |
CS60MetadataUtilityItf::~CS60MetadataUtilityItf()
|
25
|
297 |
{
|
|
298 |
if (pMetaDataUtility)
|
|
299 |
{
|
|
300 |
TInt err = KErrGeneral;
|
19
|
301 |
|
25
|
302 |
TAG_TIME_PROFILING_BEGIN;
|
|
303 |
TRAP(err, pMetaDataUtility->ResetL());
|
|
304 |
delete pMetaDataUtility;
|
|
305 |
TAG_TIME_PROFILING_END; PRINT_TO_CONSOLE_TIME_DIFF;
|
|
306 |
}
|
|
307 |
|
|
308 |
pMetaDataUtility = NULL;
|
|
309 |
}
|
19
|
310 |
|
|
311 |
TInt CS60MetadataUtilityItf::ParseSource(TDesC& fileName)
|
25
|
312 |
{
|
|
313 |
TInt err = KErrGeneral;
|
|
314 |
|
|
315 |
if (pMetaDataUtility)
|
|
316 |
{
|
19
|
317 |
|
25
|
318 |
TAG_TIME_PROFILING_BEGIN;
|
|
319 |
//open with the file handle
|
|
320 |
TRAP(err, pMetaDataUtility->OpenFileL(fileName));
|
|
321 |
TAG_TIME_PROFILING_END;
|
|
322 |
PRINT_TO_CONSOLE_TIME_DIFF;
|
19
|
323 |
|
25
|
324 |
if (err == KErrNone)
|
|
325 |
{
|
|
326 |
uNumMetadataItems = pMetaDataUtility->MetaDataCount();
|
|
327 |
}
|
|
328 |
}
|
19
|
329 |
|
25
|
330 |
return err;
|
|
331 |
}
|
19
|
332 |
|
|
333 |
TInt CS60MetadataUtilityItf::CalculateNumMetadataItems(TUint* numItems)
|
25
|
334 |
{
|
|
335 |
TInt err = KErrGeneral;
|
19
|
336 |
|
25
|
337 |
if (pMetaDataUtility && numItems)
|
|
338 |
{
|
|
339 |
*numItems = uNumMetadataItems;
|
|
340 |
err = KErrNone;
|
|
341 |
}
|
19
|
342 |
|
25
|
343 |
return err;
|
|
344 |
}
|
19
|
345 |
|
|
346 |
char* CS60MetadataUtilityItf::KeyMapping(TMetaDataFieldId fldID)
|
25
|
347 |
{
|
|
348 |
switch (fldID)
|
|
349 |
{
|
19
|
350 |
|
25
|
351 |
case EMetaDataSongTitle:
|
|
352 |
{
|
|
353 |
return "KhronosTitle";
|
|
354 |
}
|
|
355 |
case EMetaDataArtist:
|
|
356 |
{
|
|
357 |
return "KhronosArtist";
|
|
358 |
}
|
|
359 |
case EMetaDataAlbum:
|
|
360 |
{
|
|
361 |
return "KhronosAlbum";
|
|
362 |
}
|
|
363 |
case EMetaDataYear:
|
|
364 |
{
|
|
365 |
return "KhronosYear";
|
|
366 |
}
|
|
367 |
case EMetaDataComment:
|
|
368 |
{
|
|
369 |
return "KhronosComment";
|
|
370 |
}
|
|
371 |
case EMetaDataAlbumTrack:
|
|
372 |
{
|
|
373 |
return "KhronosTrackNumber";
|
|
374 |
}
|
|
375 |
case EMetaDataGenre:
|
|
376 |
{
|
|
377 |
return "KhronosGenre";
|
|
378 |
}
|
|
379 |
case EMetaDataComposer:
|
|
380 |
{
|
|
381 |
return "Composer"; //Non Standard
|
|
382 |
}
|
|
383 |
case EMetaDataCopyright:
|
|
384 |
{
|
|
385 |
return "KhronosCopyright";
|
|
386 |
}
|
|
387 |
case EMetaDataOriginalArtist:
|
|
388 |
{
|
|
389 |
return "Original Artist"; //Non Standard
|
|
390 |
}
|
|
391 |
case EMetaDataUserUrl:
|
|
392 |
case EMetaDataUrl:
|
|
393 |
{
|
|
394 |
return "KhronosContentURL";
|
|
395 |
}
|
|
396 |
case EMetaDataJpeg:
|
|
397 |
{
|
|
398 |
return "attachedpicture";//"KhronosAlbumArtJPEG";
|
|
399 |
}
|
|
400 |
case EMetaDataVendor:
|
|
401 |
{
|
|
402 |
return "Vendor"; //Non Standard
|
|
403 |
}
|
|
404 |
case EMetaDataRating:
|
|
405 |
{
|
|
406 |
return "KhronosRating";
|
|
407 |
}
|
|
408 |
case EMetaDataDuration:
|
|
409 |
{
|
|
410 |
return "Duration"; //Non Standard
|
|
411 |
}
|
|
412 |
default:
|
|
413 |
{
|
|
414 |
}
|
|
415 |
}
|
|
416 |
|
|
417 |
return "UnSupported";
|
|
418 |
}
|
19
|
419 |
|
|
420 |
TInt CS60MetadataUtilityItf::ValueEncoding(TMetaDataFieldId fldID)
|
25
|
421 |
{
|
|
422 |
switch (fldID)
|
|
423 |
{
|
|
424 |
case EMetaDataJpeg:
|
|
425 |
{
|
|
426 |
return CMetadataUtilityItf::EBinaryEncoding;
|
|
427 |
}
|
|
428 |
|
|
429 |
case EMetaDataSongTitle:
|
|
430 |
case EMetaDataArtist:
|
|
431 |
case EMetaDataAlbum:
|
|
432 |
case EMetaDataYear:
|
|
433 |
case EMetaDataComment:
|
|
434 |
case EMetaDataAlbumTrack:
|
|
435 |
case EMetaDataGenre:
|
|
436 |
case EMetaDataComposer:
|
|
437 |
case EMetaDataCopyright:
|
|
438 |
case EMetaDataOriginalArtist:
|
|
439 |
case EMetaDataUserUrl:
|
|
440 |
case EMetaDataUrl:
|
|
441 |
case EMetaDataVendor:
|
|
442 |
case EMetaDataRating:
|
|
443 |
case EMetaDataDuration:
|
|
444 |
default:
|
|
445 |
{
|
|
446 |
return CMetadataUtilityItf::EUnicodeEncoding;
|
|
447 |
}
|
|
448 |
}
|
|
449 |
|
|
450 |
}
|
19
|
451 |
char* CS60MetadataUtilityItf::GetKey(TInt index)
|
25
|
452 |
{
|
|
453 |
|
|
454 |
if (pMetaDataUtility && index < uNumMetadataItems)
|
|
455 |
{
|
|
456 |
|
|
457 |
TMetaDataFieldId fieldId;
|
19
|
458 |
|
25
|
459 |
TAG_TIME_PROFILING_BEGIN;
|
|
460 |
TInt err = KErrGeneral;
|
|
461 |
TRAP(err, pMetaDataUtility->MetaDataFieldsL().FieldIdAt( index, fieldId ));
|
|
462 |
TAG_TIME_PROFILING_END;
|
|
463 |
PRINT_TO_CONSOLE_TIME_DIFF;
|
|
464 |
|
|
465 |
if ((err == KErrNone) && (fieldId != EUnknownMetaDataField))
|
|
466 |
{
|
|
467 |
return KeyMapping(fieldId);
|
|
468 |
}
|
|
469 |
}
|
|
470 |
return NULL;
|
|
471 |
}
|
19
|
472 |
|
|
473 |
TInt CS60MetadataUtilityItf::GetValueSize(TInt index)
|
25
|
474 |
{
|
|
475 |
if (pMetaDataUtility && index < uNumMetadataItems)
|
|
476 |
{
|
|
477 |
|
|
478 |
TMetaDataFieldId fieldId;
|
|
479 |
TInt err = KErrGeneral;
|
|
480 |
TRAP(err, pMetaDataUtility->MetaDataFieldsL().FieldIdAt( index, fieldId ));
|
19
|
481 |
|
25
|
482 |
if ((err == KErrNone) && (fieldId != EUnknownMetaDataField))
|
|
483 |
{
|
|
484 |
const CMetaDataFieldContainer* iContainer = NULL;
|
|
485 |
TRAP(err, iContainer = &pMetaDataUtility->MetaDataFieldsL());
|
|
486 |
if (err == KErrNone)
|
|
487 |
{
|
|
488 |
if (ValueEncoding(fieldId)
|
|
489 |
== CMetadataUtilityItf::EUnicodeEncoding)
|
|
490 |
{
|
|
491 |
TPtrC field = iContainer->Field(fieldId);
|
|
492 |
if (field != KNullDesC)
|
|
493 |
{
|
|
494 |
return field.Size() + 2; //additional character (two bytes) for null terminator
|
|
495 |
}
|
|
496 |
}
|
|
497 |
else //Binary
|
|
498 |
{
|
|
499 |
TPtrC8 field8 = iContainer->Field8(fieldId);
|
|
500 |
if (field8 != KNullDesC8)
|
|
501 |
{
|
|
502 |
return field8.Size();
|
|
503 |
}
|
|
504 |
}
|
|
505 |
}
|
|
506 |
}
|
|
507 |
}
|
19
|
508 |
|
25
|
509 |
return 0;
|
|
510 |
}
|
19
|
511 |
|
25
|
512 |
TInt CS60MetadataUtilityItf::GetValue(TInt index, char* data, TInt maxLength, //in params
|
|
513 |
TInt* outSize, TInt* encodingType) //out params
|
|
514 |
{
|
|
515 |
|
|
516 |
TInt retValueSize = 0;
|
|
517 |
*encodingType = CMetadataUtilityItf::EUnknownEncoding;
|
|
518 |
|
|
519 |
if (pMetaDataUtility && index < uNumMetadataItems)
|
|
520 |
{
|
19
|
521 |
|
25
|
522 |
TMetaDataFieldId fieldId;
|
|
523 |
TInt err = KErrGeneral;
|
|
524 |
TRAP(err, pMetaDataUtility->MetaDataFieldsL().FieldIdAt( index, fieldId ));
|
|
525 |
|
|
526 |
if ((err == KErrNone) && (fieldId != EUnknownMetaDataField))
|
|
527 |
{
|
|
528 |
|
|
529 |
const CMetaDataFieldContainer* iContainer = NULL;
|
|
530 |
TRAP(err, iContainer = &pMetaDataUtility->MetaDataFieldsL());
|
|
531 |
if (err == KErrNone)
|
|
532 |
{
|
|
533 |
*encodingType = ValueEncoding(fieldId);
|
|
534 |
if (*encodingType == CMetadataUtilityItf::EUnicodeEncoding)
|
|
535 |
{
|
19
|
536 |
|
25
|
537 |
TAG_TIME_PROFILING_BEGIN;
|
|
538 |
TPtrC field = iContainer->Field(fieldId);
|
|
539 |
TAG_TIME_PROFILING_END;
|
|
540 |
PRINT_TO_CONSOLE_TIME_DIFF;
|
|
541 |
if (field != KNullDesC)
|
|
542 |
{
|
|
543 |
*outSize = CMetadataUtilityItf::ExtractUCS2(field,
|
|
544 |
data, maxLength);
|
|
545 |
retValueSize = field.Size() + 2; //actual size
|
|
546 |
}
|
|
547 |
}
|
|
548 |
else //Binary
|
|
549 |
{
|
|
550 |
|
|
551 |
TAG_TIME_PROFILING_BEGIN;
|
|
552 |
TPtrC8 field8 = iContainer->Field8(fieldId);
|
|
553 |
TAG_TIME_PROFILING_END;
|
|
554 |
PRINT_TO_CONSOLE_TIME_DIFF;
|
|
555 |
if (field8 != KNullDesC8)
|
|
556 |
{
|
|
557 |
*outSize
|
|
558 |
= (maxLength > field8.Size())
|
|
559 |
? field8.Size()
|
|
560 |
: maxLength;
|
|
561 |
memcpy(data, field8.Ptr(), *outSize);
|
|
562 |
retValueSize = field8.Size();
|
|
563 |
}
|
|
564 |
}
|
|
565 |
}
|
|
566 |
}
|
|
567 |
}
|
|
568 |
|
|
569 |
return retValueSize;
|
|
570 |
}
|
19
|
571 |
|
|
572 |
TInt CS60MetadataUtilityItf::Reset()
|
25
|
573 |
{
|
|
574 |
TInt err = KErrNone;
|
|
575 |
if (pMetaDataUtility)
|
|
576 |
{
|
|
577 |
TRAP(err, pMetaDataUtility->ResetL());
|
|
578 |
}
|
19
|
579 |
|
25
|
580 |
return err;
|
|
581 |
}
|
19
|
582 |
|
25
|
583 |
CHXMetadataUtilityItf::CHXMetadataUtilityItf() :
|
|
584 |
pHXMetaDataUtility(NULL)
|
|
585 |
{
|
|
586 |
}
|
19
|
587 |
|
|
588 |
void CHXMetadataUtilityItf::ConstructL()
|
25
|
589 |
{
|
|
590 |
TAG_TIME_PROFILING_BEGIN;
|
|
591 |
pHXMetaDataUtility = CHXMetaDataUtility::NewL();
|
|
592 |
TAG_TIME_PROFILING_END;
|
|
593 |
PRINT_TO_CONSOLE_TIME_DIFF;
|
|
594 |
}
|
19
|
595 |
|
|
596 |
CHXMetadataUtilityItf* CHXMetadataUtilityItf::New()
|
25
|
597 |
{
|
|
598 |
CHXMetadataUtilityItf* self = new CHXMetadataUtilityItf();
|
|
599 |
|
|
600 |
if (self)
|
|
601 |
{
|
|
602 |
TInt err = KErrGeneral;
|
|
603 |
TRAP(err, self->ConstructL());
|
19
|
604 |
|
25
|
605 |
if (err != KErrNone)
|
|
606 |
{
|
|
607 |
delete self;
|
|
608 |
self = NULL;
|
|
609 |
}
|
|
610 |
}
|
|
611 |
|
|
612 |
return self;
|
|
613 |
}
|
|
614 |
|
19
|
615 |
CHXMetadataUtilityItf::~CHXMetadataUtilityItf()
|
25
|
616 |
{
|
|
617 |
if (pHXMetaDataUtility)
|
|
618 |
{
|
|
619 |
TInt err = KErrGeneral;
|
19
|
620 |
|
25
|
621 |
TAG_TIME_PROFILING_BEGIN;
|
|
622 |
TRAP(err, pHXMetaDataUtility->ResetL());
|
|
623 |
delete pHXMetaDataUtility;
|
|
624 |
TAG_TIME_PROFILING_END;
|
|
625 |
PRINT_TO_CONSOLE_TIME_DIFF;
|
|
626 |
}
|
|
627 |
|
|
628 |
pHXMetaDataUtility = NULL;
|
|
629 |
}
|
19
|
630 |
|
|
631 |
TInt CHXMetadataUtilityItf::Reset()
|
25
|
632 |
{
|
|
633 |
TInt err = KErrNone;
|
|
634 |
if (pHXMetaDataUtility)
|
|
635 |
{
|
|
636 |
TRAP(err, pHXMetaDataUtility->ResetL());
|
|
637 |
}
|
19
|
638 |
|
25
|
639 |
return err;
|
|
640 |
}
|
19
|
641 |
|
|
642 |
TInt CHXMetadataUtilityItf::ParseSource(TDesC& fileName)
|
25
|
643 |
{
|
|
644 |
TInt err = KErrGeneral;
|
19
|
645 |
|
25
|
646 |
if (pHXMetaDataUtility)
|
|
647 |
{
|
|
648 |
//open with the file handle
|
|
649 |
TAG_TIME_PROFILING_BEGIN;
|
|
650 |
TRAP(err, pHXMetaDataUtility->OpenFileL(fileName));
|
|
651 |
TAG_TIME_PROFILING_END;
|
|
652 |
PRINT_TO_CONSOLE_TIME_DIFF;
|
19
|
653 |
|
25
|
654 |
if (err == KErrNone)
|
|
655 |
{
|
|
656 |
return pHXMetaDataUtility->GetMetaDataCount(uNumMetadataItems);
|
|
657 |
}
|
|
658 |
}
|
19
|
659 |
|
25
|
660 |
return err;
|
|
661 |
}
|
19
|
662 |
|
|
663 |
TInt CHXMetadataUtilityItf::CalculateNumMetadataItems(TUint* numItems)
|
25
|
664 |
{
|
|
665 |
TInt err = KErrGeneral;
|
19
|
666 |
|
25
|
667 |
if (pHXMetaDataUtility && numItems)
|
|
668 |
{
|
|
669 |
*numItems = uNumMetadataItems;
|
|
670 |
err = KErrNone;
|
|
671 |
}
|
19
|
672 |
|
25
|
673 |
return err;
|
|
674 |
}
|
19
|
675 |
|
|
676 |
char* CHXMetadataUtilityItf::KeyMapping(HXMetaDataKeys::EHXMetaDataId fldID)
|
25
|
677 |
{
|
|
678 |
|
|
679 |
switch (fldID)
|
|
680 |
{
|
|
681 |
|
|
682 |
case HXMetaDataKeys::EHXTitle:
|
|
683 |
{
|
|
684 |
return "KhronosTitle";
|
|
685 |
}
|
|
686 |
case HXMetaDataKeys::EHXPerformer:
|
|
687 |
{
|
|
688 |
return "KhronosArtist";
|
|
689 |
}
|
|
690 |
case HXMetaDataKeys::EHXDescription:
|
|
691 |
{
|
|
692 |
return "KhronosComment";
|
|
693 |
}
|
|
694 |
case HXMetaDataKeys::EHXGenre:
|
|
695 |
{
|
|
696 |
return "KhronosGenre";
|
|
697 |
}
|
|
698 |
case HXMetaDataKeys::EHXAuthor:
|
|
699 |
{
|
|
700 |
return "Composer"; //Non Standard
|
|
701 |
}
|
|
702 |
case HXMetaDataKeys::EHXCopyright:
|
|
703 |
{
|
|
704 |
return "KhronosCopyright";
|
|
705 |
}
|
|
706 |
case HXMetaDataKeys::EHXContentURI:
|
|
707 |
{
|
|
708 |
return "KhronosContentURL";
|
|
709 |
}
|
|
710 |
case HXMetaDataKeys::EHXDuration:
|
|
711 |
{
|
|
712 |
return "Duration"; //Non Standard
|
|
713 |
}
|
|
714 |
case HXMetaDataKeys::EHXClipBitRate:
|
|
715 |
{
|
|
716 |
return "ClipBitRate"; //non-standard
|
|
717 |
}
|
|
718 |
case HXMetaDataKeys::EHXVideoBitRate:
|
|
719 |
{
|
|
720 |
return "VideoBitRate"; // non-standard
|
|
721 |
}
|
|
722 |
case HXMetaDataKeys::EHXAudioBitRate:
|
|
723 |
{
|
|
724 |
return "AudioBitRate";
|
|
725 |
}
|
|
726 |
case HXMetaDataKeys::EHXCodec:
|
|
727 |
{
|
|
728 |
return "Codec";
|
|
729 |
}
|
|
730 |
case HXMetaDataKeys::EHXFrameSize:
|
|
731 |
{
|
|
732 |
return "Resolution";
|
|
733 |
}
|
|
734 |
case HXMetaDataKeys::EHXFramesPerSecond:
|
|
735 |
{
|
|
736 |
return "FrameRate";
|
|
737 |
}
|
|
738 |
case HXMetaDataKeys::EHXStreamCount:
|
|
739 |
{
|
|
740 |
return "Stream Count";
|
|
741 |
}
|
|
742 |
case HXMetaDataKeys::EHXLiveStream:
|
|
743 |
{
|
|
744 |
return "Live Stream";
|
|
745 |
}
|
19
|
746 |
case HXMetaDataKeys::EHXSeekable:
|
25
|
747 |
{
|
|
748 |
return "Seekable";
|
|
749 |
}
|
19
|
750 |
case HXMetaDataKeys::EHXContentType:
|
25
|
751 |
{
|
|
752 |
return "Content Type";
|
|
753 |
}
|
|
754 |
case HXMetaDataKeys::EHXFormat:
|
|
755 |
{
|
|
756 |
return "Format";
|
|
757 |
}
|
19
|
758 |
case HXMetaDataKeys::EHXQuality:
|
25
|
759 |
{
|
|
760 |
return "Quality";
|
|
761 |
}
|
19
|
762 |
case HXMetaDataKeys::EHXAbstract:
|
25
|
763 |
{
|
|
764 |
return "Abstract";
|
|
765 |
}
|
|
766 |
case HXMetaDataKeys::EHXMimeType:
|
|
767 |
{
|
|
768 |
return "MimeType";
|
|
769 |
}
|
|
770 |
case HXMetaDataKeys::EHXIconURI:
|
|
771 |
{
|
|
772 |
return "Icon URI";
|
|
773 |
}
|
19
|
774 |
case HXMetaDataKeys::EHXEPreviewURI:
|
25
|
775 |
{
|
|
776 |
return "Preview URI";
|
|
777 |
}
|
19
|
778 |
case HXMetaDataKeys::EHXContentID:
|
25
|
779 |
{
|
|
780 |
return "Content ID";
|
|
781 |
}
|
19
|
782 |
case HXMetaDataKeys::EHXInfoURL:
|
25
|
783 |
{
|
|
784 |
return "Info URL";
|
|
785 |
}
|
|
786 |
default:
|
|
787 |
{
|
|
788 |
}
|
|
789 |
}
|
19
|
790 |
|
25
|
791 |
return "UnSupported";
|
|
792 |
}
|
19
|
793 |
|
|
794 |
TInt CHXMetadataUtilityItf::ValueEncoding(HXMetaDataKeys::EHXMetaDataId fldID)
|
25
|
795 |
{
|
|
796 |
switch (fldID)
|
|
797 |
{
|
|
798 |
default:
|
|
799 |
{
|
|
800 |
return CMetadataUtilityItf::EUnicodeEncoding;
|
|
801 |
}
|
|
802 |
}
|
|
803 |
|
|
804 |
}
|
19
|
805 |
char* CHXMetadataUtilityItf::GetKey(TInt index)
|
25
|
806 |
{
|
19
|
807 |
|
25
|
808 |
if (pHXMetaDataUtility && index < uNumMetadataItems)
|
|
809 |
{
|
|
810 |
HXMetaDataKeys::EHXMetaDataId id;
|
|
811 |
HBufC* pDes;
|
|
812 |
|
|
813 |
TAG_TIME_PROFILING_BEGIN;
|
|
814 |
TInt err = pHXMetaDataUtility->GetMetaDataAt(index, id, pDes);
|
|
815 |
TAG_TIME_PROFILING_END;
|
|
816 |
PRINT_TO_CONSOLE_TIME_DIFF;
|
|
817 |
|
|
818 |
if (err == KErrNone)
|
|
819 |
{
|
|
820 |
return KeyMapping(id);
|
|
821 |
}
|
|
822 |
}
|
|
823 |
return NULL;
|
|
824 |
}
|
19
|
825 |
|
|
826 |
TInt CHXMetadataUtilityItf::GetValueSize(TInt index)
|
25
|
827 |
{
|
|
828 |
if (pHXMetaDataUtility && index < uNumMetadataItems)
|
|
829 |
{
|
|
830 |
HXMetaDataKeys::EHXMetaDataId id;
|
|
831 |
HBufC* pDes;
|
|
832 |
|
|
833 |
TInt err = pHXMetaDataUtility->GetMetaDataAt(index, id, pDes);
|
19
|
834 |
|
25
|
835 |
if (err == KErrNone)
|
|
836 |
{
|
|
837 |
if (ValueEncoding(id) == CMetadataUtilityItf::EUnicodeEncoding)
|
|
838 |
{
|
|
839 |
return pDes->Size() + 2; //additional character (two bytes) for null terminator
|
|
840 |
}
|
|
841 |
else //Binary
|
|
842 |
{
|
|
843 |
//no support
|
|
844 |
}
|
|
845 |
}
|
|
846 |
}
|
19
|
847 |
|
25
|
848 |
return 0;
|
|
849 |
}
|
|
850 |
|
|
851 |
TInt CHXMetadataUtilityItf::GetValue(TInt index, char* data, TInt maxLength, //in params
|
|
852 |
TInt* outSize, TInt* encodingType) //out params
|
|
853 |
{
|
|
854 |
|
|
855 |
TInt retValueSize = 0;
|
|
856 |
*encodingType = CMetadataUtilityItf::EUnknownEncoding;
|
19
|
857 |
|
25
|
858 |
if (pHXMetaDataUtility && index < uNumMetadataItems)
|
|
859 |
{
|
|
860 |
HXMetaDataKeys::EHXMetaDataId id;
|
|
861 |
HBufC* pDes;
|
|
862 |
|
|
863 |
TAG_TIME_PROFILING_BEGIN;
|
|
864 |
TInt err = pHXMetaDataUtility->GetMetaDataAt(index, id, pDes);
|
|
865 |
TAG_TIME_PROFILING_END;
|
|
866 |
PRINT_TO_CONSOLE_TIME_DIFF;
|
|
867 |
|
|
868 |
*encodingType = ValueEncoding(id);
|
19
|
869 |
|
25
|
870 |
if (err == KErrNone)
|
|
871 |
{
|
|
872 |
if (*encodingType == CMetadataUtilityItf::EUnicodeEncoding)
|
|
873 |
{
|
|
874 |
*outSize = CMetadataUtilityItf::ExtractUCS2(*pDes, data,
|
|
875 |
maxLength);
|
|
876 |
retValueSize = pDes->Size() + 2; //actual Size
|
|
877 |
}
|
|
878 |
else //Binary
|
|
879 |
{
|
|
880 |
//no support
|
|
881 |
}
|
|
882 |
}
|
|
883 |
}
|
19
|
884 |
|
25
|
885 |
return retValueSize;
|
|
886 |
}
|
19
|
887 |
|
25
|
888 |
extern "C"
|
|
889 |
{
|
19
|
890 |
|
|
891 |
void* mmf_metadata_utility_init(char* uri)
|
25
|
892 |
{
|
|
893 |
return CMetadataUtilityItf::New(uri);
|
|
894 |
}
|
19
|
895 |
|
|
896 |
void mmf_metadata_utility_destroy(void* context)
|
25
|
897 |
{
|
|
898 |
delete ((CMetadataUtilityItf*) context);
|
|
899 |
}
|
|
900 |
|
|
901 |
XAresult mmf_metadata_utility_parse_source(void* context, char* uri)
|
|
902 |
{
|
|
903 |
TInt err = ((CMetadataUtilityItf*) context)->ParseSource(uri);
|
|
904 |
|
|
905 |
if (err == KErrNone)
|
|
906 |
{
|
|
907 |
return XA_RESULT_SUCCESS;
|
|
908 |
}
|
19
|
909 |
|
25
|
910 |
return XA_RESULT_PARAMETER_INVALID;
|
|
911 |
}
|
19
|
912 |
|
25
|
913 |
XAresult mmf_get_item_count(void* context, XAuint32* itemCount)
|
|
914 |
{
|
|
915 |
if (itemCount)
|
|
916 |
{
|
|
917 |
TInt err =((CMetadataUtilityItf*) (context))->CalculateNumMetadataItems(
|
|
918 |
(TUint *) itemCount);
|
|
919 |
if (err == KErrNone)
|
|
920 |
{
|
|
921 |
return XA_RESULT_SUCCESS;
|
|
922 |
}
|
|
923 |
}
|
|
924 |
|
|
925 |
return XA_RESULT_PARAMETER_INVALID;
|
|
926 |
}
|
19
|
927 |
|
25
|
928 |
XAresult mmf_get_key_size(void* context, XAuint32 keyIndex,
|
|
929 |
XAuint32* keySize)
|
|
930 |
{
|
|
931 |
char* key = ((CMetadataUtilityItf*) (context))->GetKey(keyIndex);
|
|
932 |
if (key && keySize)
|
|
933 |
{
|
|
934 |
*keySize = (strlen(key) + sizeof(XAMetadataInfo));
|
|
935 |
|
|
936 |
return XA_RESULT_SUCCESS;
|
|
937 |
}
|
|
938 |
|
|
939 |
return XA_RESULT_PARAMETER_INVALID;
|
|
940 |
}
|
19
|
941 |
|
25
|
942 |
XAresult mmf_get_key(void* context, XAuint32 index, XAuint32 keySize,
|
|
943 |
XAMetadataInfo *pKey)
|
|
944 |
{
|
|
945 |
XAresult ret = XA_RESULT_PARAMETER_INVALID;
|
|
946 |
|
|
947 |
TInt keyDataSize = keySize - sizeof(XAMetadataInfo) + 1;
|
|
948 |
char* ascKey = ((CMetadataUtilityItf*) (context))->GetKey(index);
|
19
|
949 |
|
25
|
950 |
if (ascKey && keyDataSize)
|
|
951 |
{
|
|
952 |
TInt ascKeySize = strlen(ascKey);
|
|
953 |
TInt outSize = (ascKeySize >= keyDataSize)
|
|
954 |
? (keyDataSize - 1)
|
|
955 |
: ascKeySize;
|
|
956 |
|
|
957 |
pKey->size = outSize + 1;
|
|
958 |
pKey->encoding = XA_CHARACTERENCODING_ASCII;
|
|
959 |
strcpy((char *) (pKey->langCountry), "en-us");
|
|
960 |
strncpy((char *) (pKey->data), ascKey, outSize);
|
|
961 |
pKey->data[outSize] = '\0';
|
19
|
962 |
|
25
|
963 |
if (ascKeySize >= keyDataSize)
|
|
964 |
{
|
|
965 |
ret = XA_RESULT_BUFFER_INSUFFICIENT;
|
|
966 |
}
|
|
967 |
else
|
|
968 |
{
|
|
969 |
ret = XA_RESULT_SUCCESS;
|
|
970 |
}
|
|
971 |
}
|
|
972 |
|
|
973 |
ret = XA_RESULT_SUCCESS;
|
|
974 |
return ret;
|
|
975 |
}
|
19
|
976 |
|
25
|
977 |
XAresult mmf_get_value_size(void* context, XAuint32 index,
|
|
978 |
XAuint32 *pValueSize)
|
|
979 |
{
|
|
980 |
if (pValueSize)
|
|
981 |
{
|
|
982 |
*pValueSize = ((CMetadataUtilityItf*) (context))->GetValueSize(
|
|
983 |
index) + sizeof(XAMetadataInfo) - 1;
|
|
984 |
//XAMetadataInfo already includes one byte for Data
|
19
|
985 |
|
25
|
986 |
return XA_RESULT_SUCCESS;
|
|
987 |
}
|
19
|
988 |
|
25
|
989 |
return XA_RESULT_PARAMETER_INVALID;
|
|
990 |
}
|
19
|
991 |
|
25
|
992 |
XAresult mmf_get_value(void* context, XAuint32 index, XAuint32 valueSize,
|
|
993 |
XAMetadataInfo *pValue)
|
|
994 |
{
|
|
995 |
XAresult ret = XA_RESULT_PARAMETER_INVALID;
|
|
996 |
TInt dataSize = valueSize - sizeof(XAMetadataInfo) + 1;
|
|
997 |
TInt outLen = 0, encodingType = CMetadataUtilityItf::EUnknownEncoding;
|
19
|
998 |
|
25
|
999 |
if (dataSize > 0)
|
|
1000 |
{
|
19
|
1001 |
|
25
|
1002 |
TInt actualDataSize =
|
|
1003 |
((CMetadataUtilityItf*) (context))->GetValue(index,
|
|
1004 |
(char*) pValue->data, dataSize, &outLen,
|
|
1005 |
&encodingType);
|
19
|
1006 |
|
25
|
1007 |
pValue->size = outLen;
|
|
1008 |
pValue->encoding
|
|
1009 |
= (encodingType == CMetadataUtilityItf::EUnicodeEncoding)
|
|
1010 |
? XA_CHARACTERENCODING_UTF16LE : XA_CHARACTERENCODING_BINARY;
|
|
1011 |
strcpy((char *) (pValue->langCountry), "en-us");
|
19
|
1012 |
|
25
|
1013 |
if (!actualDataSize)
|
|
1014 |
{
|
|
1015 |
return XA_RESULT_INTERNAL_ERROR;
|
|
1016 |
}
|
|
1017 |
if (actualDataSize > dataSize)
|
|
1018 |
{
|
|
1019 |
ret = XA_RESULT_BUFFER_INSUFFICIENT;
|
|
1020 |
}
|
|
1021 |
else
|
|
1022 |
{
|
|
1023 |
ret = XA_RESULT_SUCCESS;
|
|
1024 |
}
|
|
1025 |
}
|
|
1026 |
|
|
1027 |
return ret;
|
|
1028 |
}
|
|
1029 |
}
|
|
1030 |
|