2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 * @file FCnt_ContentManagerUtilImpl.cpp
18 * @brief This is the implementation file for the %_ContentManagerUtilImpl class.
20 * This file contains implementation of the %_ContentManagerUtilImpl class.
26 #include <mime_type.h>
28 #include <FBaseByteBuffer.h>
29 #include <FBaseSysLog.h>
30 #include <FBaseUtilStringTokenizer.h>
31 #include <FCntImageMetadata.h>
32 #include <FCntAudioMetadata.h>
33 #include <FCntVideoMetadata.h>
34 #include <FMediaImage.h>
35 #include <FMediaImageBuffer.h>
36 #include <FMediaImageUtil.h>
37 #include <FIoDirectory.h>
38 #include <FSysEnvironment.h>
39 #include <FApp_AppInfo.h>
40 #include <FBase_LocalizedNumParser.h>
41 #include <FBase_StringConverter.h>
42 #include <FGrp_BitmapImpl.h>
43 #include <FIo_FileImpl.h>
44 #include <FMedia_ImageDecoder.h>
45 #include <FMedia_ImageImpl.h>
46 #include "FCnt_AudioMetadataImpl.h"
47 #include "FCnt_ContentManagerUtilImpl.h"
48 #include "FCnt_ImageMetadataImpl.h"
49 #include "FCnt_VideoMetadataImpl.h"
52 using namespace Tizen::App;
53 using namespace Tizen::Base;
54 using namespace Tizen::Base::Utility;
55 using namespace Tizen::Graphics;
56 using namespace Tizen::Io;
57 using namespace Tizen::Media;
58 using namespace Tizen::System;
60 namespace Tizen { namespace Content
63 // Types of content, format supported and default values
64 static const int _IMAGE_BUFF_LENGTH = 100;
65 static const int _THUMBNAIL_IMAGE_WIDTH = 80;
66 static const int _THUMBNAIL_IMAGE_HEIGHT = 60;
67 static const int _MINUTES = 60;
68 static const int _SECONDS = 3600;
69 static const double DEFAULT_COORDINATE = -200.0;
72 _ContentManagerUtilImpl::GetImageMetaN(const String& contentPath, bool internal)
78 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), null, E_INVALID_ARG,
79 "[E_INVALID_ARG] The path is not compatible.");
81 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_INVALID_ARG,
82 "[E_INVALID_ARG] The file corresponding to contentPath could not be found.");
84 // create object here as it needs to be passed to client in any case to make sure Get APIs do not crash
85 unique_ptr<ImageMetadata> pImageMetadata(new (nothrow) ImageMetadata());
86 SysTryReturn(NID_CNT, pImageMetadata != null, null, E_OUT_OF_MEMORY,
87 "[E_OUT_OF_MEMORY] pImageMetadata is null.");
89 _ImageMetadataImpl* pImageMetaImpl = _ImageMetadataImpl::GetInstance(*(pImageMetadata.get()));
90 SysTryReturn(NID_CNT, pImageMetaImpl != null, null, E_OUT_OF_MEMORY,
91 "[E_OUT_OF_MEMORY] pImageMetaImpl is null.");
93 ImageMeta* pMetadata = pImageMetaImpl->GetImageMetadata();
94 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
95 "[E_INVALID_ARG] pMetadata is null.");
97 //assign by default here and overwrite below if width and height presents in EXIF data.
98 ImageFormat imgType = IMG_FORMAT_NONE;
101 result r = _ImageImpl::GetImageInfo(contentPath, imgType, dim);
102 SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_INVALID_ARG,
103 "[E_INVALID_ARG] GetImageInfo failed.");
105 pMetadata->width = dim.width;
106 pMetadata->height = dim.height;
107 pMetadata->contentPath = contentPath;
109 String tizenPath(L"");
110 String changedPath(L"");
111 r = ChangeMediaFilePath(contentPath, tizenPath, changedPath);
112 SysTryReturn(NID_CNT, r == E_SUCCESS, null, r, "[%s] Failed to perform ChangeMediaFilePath.", GetErrorMessage(r));
114 if (imgType == IMG_FORMAT_JPG)
116 unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(tizenPath));
117 SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
118 "[E_OUT_OF_MEMORY] The memory is insufficient.");
120 unique_ptr<ExifData, ExifDataDeleter> pExifdata(exif_data_new_from_file(pFileName.get()));
121 if (pExifdata != null)
124 ExifByteOrder byteOrder;
125 ExifEntry** pEntries = null;
126 const char* pData = null;
127 char buf[_IMAGE_BUFF_LENGTH] = {0, };
128 ExifContent* pExifcont[EXIF_IFD_COUNT];
129 char latitudeRef = 0; // to store latitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
130 char longitudeRef = 0; // to store longitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
131 unsigned int entryCount = 0;
132 bool isOrientation = false;
133 bool isLatitude = false;
134 bool isLongitude = false;
136 for (int i = 0; i < EXIF_IFD_COUNT; i++)
138 pExifcont[i] = pExifdata->ifd[i];
139 entryCount = pExifcont[i]->count;
140 pEntries = pExifcont[i]->entries;
141 for (unsigned int j = 0; j < entryCount; j++)
143 tag = pEntries[j]->tag;
144 pData = exif_entry_get_value(pEntries[j], buf, sizeof(buf));
145 SysTryReturn(NID_CNT, pData != null, pImageMetadata.release(), E_INVALID_ARG,
146 "[E_INVALID_ARG] exif_entry_get_value failed.");
148 if (tag == EXIF_TAG_PIXEL_X_DIMENSION)
150 pMetadata->width = atoi(buf);
152 else if (tag == EXIF_TAG_PIXEL_Y_DIMENSION)
154 pMetadata->height = atoi(buf);
156 else if (tag == EXIF_TAG_MAKE)
158 pMetadata->pManufacturer = new (nothrow) String(buf);
159 SysTryReturn(NID_CNT, pMetadata->pManufacturer != null, null, E_OUT_OF_MEMORY,
160 "[E_OUT_OF_MEMORY] The memory is insufficient.");
162 else if (tag == EXIF_TAG_MODEL)
164 pMetadata->pModel = new (nothrow) String(buf);
165 SysTryReturn(NID_CNT, pMetadata->pModel != null, null, E_OUT_OF_MEMORY,
166 "[E_OUT_OF_MEMORY] The memory is insufficient.");
168 else if (tag == EXIF_TAG_DATE_TIME)
170 pMetadata->pDateTime = new (nothrow) String(buf);
171 SysTryReturn(NID_CNT, pMetadata->pDateTime != null, null, E_OUT_OF_MEMORY,
172 "[E_OUT_OF_MEMORY] The memory is insufficient.");
174 else if (tag == EXIF_TAG_ORIENTATION && !isOrientation)
176 //get the byte order(little endian or big endian) before extracting orientation type
177 byteOrder = exif_data_get_byte_order(pEntries[j]->parent->parent);
178 pMetadata->orientation = static_cast<ImageOrientationType>(exif_get_short(pEntries[j]->data, byteOrder));
180 isOrientation = true;
182 else if (tag == EXIF_TAG_SOFTWARE)
184 pMetadata->pSoftware = new (nothrow) String(buf);
185 SysTryReturn(NID_CNT, pMetadata->pSoftware != null, null, E_OUT_OF_MEMORY,
186 "[E_OUT_OF_MEMORY] The memory is insufficient.");
188 else if (tag == EXIF_TAG_GPS_LATITUDE_REF)
190 latitudeRef = buf[0]; // GPS Latitude reference value will be 'N'(NORTH) or 'S'(SOUTH)
192 else if (tag == EXIF_TAG_GPS_LATITUDE && !isLatitude)
194 String tempLatitude(buf);
195 if (!tempLatitude.Contains(L","))
197 pMetadata->latitude = DEFAULT_COORDINATE;
205 r = tempLatitude.IndexOf(',', 0, firstComma);
206 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform IndexOf operation.", GetErrorMessage(r));
208 r = tempLatitude.SetCharAt('/', firstComma);
209 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform SetCharAt operation.", GetErrorMessage(r));
211 r = tempLatitude.LastIndexOf(',', tempLatitude.GetLength() - 1, lastComma);
212 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform IndexOf operation.", GetErrorMessage(r));
214 r = tempLatitude.SetCharAt('/', lastComma);
215 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform SetCharAt operation.", GetErrorMessage(r));
218 StringTokenizer strTok(tempLatitude, delim);
219 String token[3] = {L"", };
222 while (strTok.HasMoreTokens() && count < 3)
224 strTok.GetNextToken(token[count++]);
227 double ddVal = _LocalizedNumParser::ToDouble(token[0], ""); // degree value
229 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
231 double mmVal = _LocalizedNumParser::ToDouble(token[1], ""); // minutes value
233 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
235 double ssVal = _LocalizedNumParser::ToDouble(token[2], ""); // seconds value
237 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
239 pMetadata->latitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
241 // if latitude designation is Southern (SOUTH) then latitude degree will be negative DD
242 if (latitudeRef == 'S')
244 pMetadata->latitude = (pMetadata->latitude * (double)(-1));
248 else if (tag == EXIF_TAG_GPS_LONGITUDE_REF)
250 longitudeRef = buf[0]; // GPS Longitude reference value will be 'W'(WEST) or 'E'(EAST)
252 else if (tag == EXIF_TAG_GPS_LONGITUDE && !isLongitude)
254 String tempLongitude(buf);
255 if (!tempLongitude.Contains(L","))
257 pMetadata->longitude = DEFAULT_COORDINATE;
265 r = tempLongitude.IndexOf(',', 0, firstComma);
266 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform IndexOf operation.", GetErrorMessage(r));
268 r = tempLongitude.SetCharAt('/', firstComma);
269 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform SetCharAt operation.", GetErrorMessage(r));
271 r = tempLongitude.LastIndexOf(',', tempLongitude.GetLength() - 1, lastComma);
272 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform IndexOf operation.", GetErrorMessage(r));
274 r = tempLongitude.SetCharAt('/', lastComma);
275 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform SetCharAt operation.", GetErrorMessage(r));
278 StringTokenizer strTok(tempLongitude, delim);
279 String token[3] = {L"", };
282 while (strTok.HasMoreTokens() && count < 3)
284 strTok.GetNextToken(token[count++]);
287 double ddVal = _LocalizedNumParser::ToDouble(token[0], ""); // degree value
289 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
291 double mmVal = _LocalizedNumParser::ToDouble(token[1], ""); // minutes value
293 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
295 double ssVal = _LocalizedNumParser::ToDouble(token[2], ""); // seconds value
297 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
299 pMetadata->longitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
301 // if longitude designation is Western (WEST) then longitude degree will be negative DD
302 if (longitudeRef == 'W')
304 pMetadata->longitude = (pMetadata->longitude * (double)(-1));
308 else if (tag == EXIF_TAG_WHITE_BALANCE)
310 pMetadata->pWhiteBalance = new (nothrow) String(buf);
311 SysTryReturn(NID_CNT, pMetadata->pWhiteBalance != null, null, E_OUT_OF_MEMORY,
312 "[E_OUT_OF_MEMORY] The memory is insufficient.");
319 return pImageMetadata.release();
323 _ContentManagerUtilImpl::GetAudioMetaN(const String& contentPath)
327 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), null, E_INVALID_ARG,
328 "[E_INVALID_ARG] The path is not compatible.");
329 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_INVALID_ARG,
330 "[E_INVALID_ARG] The file corresponding to contentPath could not be found.");
332 // create here to make sure that get apis will not crash though the below API calls fails in case of invalid file.
333 unique_ptr<AudioMetadata> pAudioMetadata(new (nothrow) AudioMetadata());
334 SysTryReturn(NID_CNT, pAudioMetadata != null, null, E_OUT_OF_MEMORY,
335 "[E_OUT_OF_MEMORY] The memory is insufficient.");
337 _AudioMetadataImpl* pAudioMetaImpl = _AudioMetadataImpl::GetInstance(*(pAudioMetadata.get()));
338 SysTryReturn(NID_CNT, pAudioMetaImpl != null, null, E_OUT_OF_MEMORY,
339 "[E_OUT_OF_MEMORY] pAudioMetaImpl is null.");
341 AudioMeta* pMetadata = pAudioMetaImpl->GetAudioMetadata();
342 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
343 "[E_INVALID_ARG] pMetadata is null.");
345 pMetadata->contentPath = contentPath;
347 String tizenPath(L"");
348 String changedPath(L"");
349 result r = ChangeMediaFilePath(contentPath, tizenPath, changedPath);
350 SysTryReturn(NID_CNT, r == E_SUCCESS, null, r, "[%s] Failed to perform ChangeMediaFilePath.", GetErrorMessage(r));
352 // Create the metadata extractor handle
353 metadata_extractor_h tempExtractor = NULL;
355 int retVal = metadata_extractor_create(&tempExtractor);
356 r = ErrorMapToRetVal(retVal);
357 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
358 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
360 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
361 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
362 "[E_OUT_OF_MEMORY] The memory is insufficient.");
364 // Set file path of content to extract the metadata
365 unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(tizenPath));
366 SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
367 "[E_OUT_OF_MEMORY] The memory is insufficient.");
369 retVal = metadata_extractor_set_path(pExtractor.get(), pFileName.get());
370 r = ErrorMapToRetVal(retVal);
371 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
372 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
374 // Get all relavent audio metadata by passing relavent attirbutes
375 char* pTempAudioMeta = null;
376 unique_ptr<char, CharDeleter> pAudioMeta(null);
379 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempAudioMeta);
380 if (pTempAudioMeta != null)
382 pAudioMeta.reset(pTempAudioMeta);
383 pMetadata->bitrate = atoi(pAudioMeta.get());
387 r = ErrorMapToRetVal(retVal);
388 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
389 "[%s] metadata_extractor_get_metadata(bitrate) failed.", GetErrorMessage(r));
393 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_CHANNELS, &pTempAudioMeta);
394 if (pTempAudioMeta != null)
396 pAudioMeta.reset(pTempAudioMeta);
397 pMetadata->channelCount = atoi(pAudioMeta.get());
401 r = ErrorMapToRetVal(retVal);
402 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
403 "[%s] metadata_extractor_get_metadata(channels) failed.", GetErrorMessage(r));
407 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempAudioMeta);
408 if (pTempAudioMeta != null)
410 pAudioMeta.reset(pTempAudioMeta);
411 pMetadata->duration = atoi(pAudioMeta.get());
415 r = ErrorMapToRetVal(retVal);
416 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
417 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
421 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_SAMPLERATE, &pTempAudioMeta);
422 if (pTempAudioMeta != null)
424 pAudioMeta.reset(pTempAudioMeta);
425 pMetadata->frequency = atoi(pAudioMeta.get());
429 r = ErrorMapToRetVal(retVal);
430 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
431 "[%s] metadata_extractor_get_metadata(frequency) failed.", GetErrorMessage(r));
435 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ALBUM, &pTempAudioMeta);
436 if (pTempAudioMeta != null)
438 pAudioMeta.reset(pTempAudioMeta);
439 pMetadata->pAlbumName = new (nothrow) String(pAudioMeta.get());
440 SysTryReturn(NID_CNT, pMetadata->pAlbumName != null, null, E_OUT_OF_MEMORY,
441 "[E_OUT_OF_MEMORY] The memory is insufficient.");
445 r = ErrorMapToRetVal(retVal);
446 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
447 "[%s] metadata_extractor_get_metadata(album name) failed.", GetErrorMessage(r));
451 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ARTIST, &pTempAudioMeta);
452 if (pAudioMeta.get() != null)
454 pAudioMeta.reset(pTempAudioMeta);
455 pMetadata->pArtist = new (nothrow) String(pAudioMeta.get());
456 SysTryReturn(NID_CNT, pMetadata->pArtist != null, null, E_OUT_OF_MEMORY,
457 "[E_OUT_OF_MEMORY] The memory is insufficient.");
461 r = ErrorMapToRetVal(retVal);
462 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
463 "[%s] metadata_extractor_get_metadata(artist) failed.", GetErrorMessage(r));
467 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COPYRIGHT, &pTempAudioMeta);
468 if (pTempAudioMeta != null)
470 pAudioMeta.reset(pTempAudioMeta);
471 pMetadata->pCopyright = new (nothrow) String(pAudioMeta.get());
472 SysTryReturn(NID_CNT, pMetadata->pCopyright != null, null, E_OUT_OF_MEMORY,
473 "[E_OUT_OF_MEMORY] The memory is insufficient.");
477 r = ErrorMapToRetVal(retVal);
478 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
479 "[%s] metadata_extractor_get_metadata(copyright) failed.", GetErrorMessage(r));
483 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempAudioMeta);
484 if (pTempAudioMeta != null)
486 pAudioMeta.reset(pTempAudioMeta);
487 pMetadata->pGenre = new (nothrow) String(pAudioMeta.get());
488 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
489 "[E_OUT_OF_MEMORY] The memory is insufficient.");
493 r = ErrorMapToRetVal(retVal);
494 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
495 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
499 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TITLE, &pTempAudioMeta);
500 if (pTempAudioMeta != null)
502 pAudioMeta.reset(pTempAudioMeta);
503 pMetadata->pTitle = new (nothrow) String(pAudioMeta.get());
504 SysTryReturn(NID_CNT, pMetadata->pTitle != null, null, E_OUT_OF_MEMORY,
505 "[E_OUT_OF_MEMORY] The memory is insufficient.");
509 r = ErrorMapToRetVal(retVal);
510 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
511 "[%s] metadata_extractor_get_metadata(title) failed.", GetErrorMessage(r));
515 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempAudioMeta);
516 if (pTempAudioMeta != null)
518 pAudioMeta.reset(pTempAudioMeta);
519 pMetadata->pComment = new (nothrow) String(pAudioMeta.get());
520 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
521 "[E_OUT_OF_MEMORY] The memory is insufficient.");
525 r = ErrorMapToRetVal(retVal);
526 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
527 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
531 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempAudioMeta);
532 if (pTempAudioMeta != null)
534 pAudioMeta.reset(pTempAudioMeta);
535 pMetadata->pDescription = new (nothrow) String(pAudioMeta.get());
536 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
537 "[E_OUT_OF_MEMORY] The memory is insufficient.");
541 r = ErrorMapToRetVal(retVal);
542 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
543 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
547 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_RECDATE, &pTempAudioMeta);
548 if (pTempAudioMeta != null)
550 pAudioMeta.reset(pTempAudioMeta);
551 pMetadata->pRecordingDate = new (nothrow) String(pAudioMeta.get());
552 SysTryReturn(NID_CNT, pMetadata->pRecordingDate != null, null, E_OUT_OF_MEMORY,
553 "[E_OUT_OF_MEMORY] The memory is insufficient.");
557 r = ErrorMapToRetVal(retVal);
558 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
559 "[%s] metadata_extractor_get_metadata(recording date) failed.", GetErrorMessage(r));
563 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUTHOR, &pTempAudioMeta);
564 if (pTempAudioMeta != null)
566 pAudioMeta.reset(pTempAudioMeta);
567 pMetadata->pComposer = new (nothrow) String(pAudioMeta.get());
568 SysTryReturn(NID_CNT, pMetadata->pComposer != null, null, E_OUT_OF_MEMORY,
569 "[E_OUT_OF_MEMORY] The memory is insufficient.");
573 r = ErrorMapToRetVal(retVal);
574 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
575 "[%s] metadata_extractor_get_metadata(author) failed.", GetErrorMessage(r));
579 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TRACK_NUM, &pTempAudioMeta);
580 if (pTempAudioMeta != null)
582 pAudioMeta.reset(pTempAudioMeta);
583 pMetadata->pTrackInfo = new (nothrow) String(pAudioMeta.get());
584 SysTryReturn(NID_CNT, pMetadata->pTrackInfo != null, null, E_OUT_OF_MEMORY,
585 "[E_OUT_OF_MEMORY] The memory is insufficient.");
587 // if the string contains the track info like track num/track position,
588 // then track position will be ignored and only track num is returned
589 // no need to parse this string, since only track number is required
590 pMetadata->trackNum = atoi(pAudioMeta.get());
594 r = ErrorMapToRetVal(retVal);
595 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
596 "[%s] metadata_extractor_get_metadata(track info) failed.", GetErrorMessage(r));
600 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DATE, &pTempAudioMeta);
601 if (pTempAudioMeta != null)
603 pAudioMeta.reset(pTempAudioMeta);
604 pMetadata->year = atoi(pAudioMeta.get());
608 r = ErrorMapToRetVal(retVal);
609 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
610 "[%s] metadata_extractor_get_metadata(date) failed.", GetErrorMessage(r));
615 void* pTempArtwork = null;
616 unique_ptr<void, VoidDeleter> pArtwork(null);
618 // Get the artwork image in media file
619 retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempAudioMeta);
620 pAudioMeta.reset(pTempAudioMeta);
622 //Check if the albumart present and pass it to client if it is successfully processed, otherwise ignore any errors
623 //while processing albumart. This is to pass the other metadata tags to application.
624 if (pTempArtwork != null)
626 pArtwork.reset(pTempArtwork);
629 ImageFormat format = IMG_FORMAT_NONE;
632 r = buffer.Construct(size);
633 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
635 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
641 format = img.GetImageFormat(buffer);
642 pMetadata->pThumbnail = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888,
643 _THUMBNAIL_IMAGE_WIDTH, _THUMBNAIL_IMAGE_HEIGHT);
644 if (pMetadata->pThumbnail == null)
646 // Because Thumbnail is one of the metadata, it is not exception in this function.
647 SysLog(NID_CNT, "DecodeN failed.");
649 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
650 if (pMetadata->pAlbumArt == null)
652 // Because Album Art is one of the metadata, it is not exception in this function.
653 SysLog(NID_CNT, "DecodeN failed.");
661 r = ErrorMapToRetVal(retVal);
662 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
663 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
666 return pAudioMetadata.release();
670 _ContentManagerUtilImpl::GetVideoMetaN(const String& contentPath)
674 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), null, E_INVALID_ARG,
675 "[E_INVALID_ARG] The path is not compatible.");
676 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_INVALID_ARG,
677 "[E_INVALID_ARG] The file corresponding to contentPath could not be found.");
679 // need to create here to make sure that all get APIs will not crash in case of corrupted file
680 unique_ptr<VideoMetadata> pVideoMetadata(new (nothrow) VideoMetadata());
681 SysTryReturn(NID_CNT, pVideoMetadata != null, null, E_OUT_OF_MEMORY,
682 "[E_OUT_OF_MEMORY] The memory insufficient.");
684 _VideoMetadataImpl* pVideoMetaImpl = _VideoMetadataImpl::GetInstance(*(pVideoMetadata.get()));
685 SysTryReturn(NID_CNT, pVideoMetaImpl != null, null, E_OUT_OF_MEMORY,
686 "[E_OUT_OF_MEMORY] pVideoMetaImpl is null.");
688 VideoMeta* pMetadata = pVideoMetaImpl->GetVideoMetadata();
689 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
690 "[E_INVALID_ARG] pMetadata is null.");
692 pMetadata->contentPath = contentPath;
694 String tizenPath(L"");
695 String changedPath(L"");
696 result r = ChangeMediaFilePath(contentPath, tizenPath, changedPath);
697 SysTryReturn(NID_CNT, r == E_SUCCESS, null, r, "[%s] Failed to perform ChangeMediaFilePath.", GetErrorMessage(r));
699 // Create the metadata extractor handle
700 metadata_extractor_h tempExtractor = NULL;
702 int retVal = metadata_extractor_create(&tempExtractor);
703 r = ErrorMapToRetVal(retVal);
704 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
705 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
707 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
708 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
709 "[E_OUT_OF_MEMORY] The memory insufficient.");
711 // Set file path of content to extract the metadata
712 unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(tizenPath));
713 SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
714 "[E_OUT_OF_MEMORY] The memory is insufficient.");
716 retVal = metadata_extractor_set_path(pExtractor.get(), pFileName.get());
717 r = ErrorMapToRetVal(retVal);
718 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
719 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
721 // Get all relavent video metadata by passing relavent attirbutes
722 char* pTempVideoMeta = null;
723 unique_ptr<char, CharDeleter> pVideoMeta(null);
726 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_WIDTH, &pTempVideoMeta);
727 if (pTempVideoMeta != null)
729 pVideoMeta.reset(pTempVideoMeta);
730 pMetadata->width = atoi(pVideoMeta.get());
734 r = ErrorMapToRetVal(retVal);
735 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
736 "[%s] metadata_extractor_get_metadata(width) failed.", GetErrorMessage(r));
740 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_HEIGHT, &pTempVideoMeta);
741 if (pTempVideoMeta != null)
743 pVideoMeta.reset(pTempVideoMeta);
744 pMetadata->height = atoi(pVideoMeta.get());
748 r = ErrorMapToRetVal(retVal);
749 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
750 "[%s] metadata_extractor_get_metadata(height) failed.", GetErrorMessage(r));
754 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_BITRATE, &pTempVideoMeta);
755 if (pTempVideoMeta != null)
757 pVideoMeta.reset(pTempVideoMeta);
758 pMetadata->videoBitrate = atoi(pVideoMeta.get());
762 r = ErrorMapToRetVal(retVal);
763 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
764 "[%s] metadata_extractor_get_metadata(video bitrate) failed.", GetErrorMessage(r));
768 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempVideoMeta);
769 if (pTempVideoMeta != null)
771 pVideoMeta.reset(pTempVideoMeta);
772 pMetadata->audioBitrate = atoi(pVideoMeta.get());
776 r = ErrorMapToRetVal(retVal);
777 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
778 "[%s] metadata_extractor_get_metadata(audio bitrate) failed.", GetErrorMessage(r));
782 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_FPS, &pTempVideoMeta);
783 if (pTempVideoMeta != null)
785 pVideoMeta.reset(pTempVideoMeta);
786 pMetadata->framerate = atoi(pVideoMeta.get());
790 r = ErrorMapToRetVal(retVal);
791 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
792 "[%s] metadata_extractor_get_metadata(framerate) failed.", GetErrorMessage(r));
796 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempVideoMeta);
797 if (pTempVideoMeta != null)
799 pVideoMeta.reset(pTempVideoMeta);
800 pMetadata->duration = atoi(pVideoMeta.get());
804 r = ErrorMapToRetVal(retVal);
805 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
806 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
810 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempVideoMeta);
811 if (pTempVideoMeta != null)
813 pVideoMeta.reset(pTempVideoMeta);
814 pMetadata->pGenre = new (nothrow) String(pVideoMeta.get()); //allocate memory
815 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
816 "[E_OUT_OF_MEMORY] The memory is insufficient.");
820 r = ErrorMapToRetVal(retVal);
821 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
822 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
826 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempVideoMeta);
827 if (pTempVideoMeta != null)
829 pVideoMeta.reset(pTempVideoMeta);
830 pMetadata->pComment = new (nothrow) String(pVideoMeta.get());
831 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
832 "[E_OUT_OF_MEMORY] The memory is insufficient.");
836 r = ErrorMapToRetVal(retVal);
837 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
838 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
842 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempVideoMeta);
843 if (pTempVideoMeta != null)
845 pVideoMeta.reset(pTempVideoMeta);
846 pMetadata->pDescription = new (nothrow) String(pVideoMeta.get());
847 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
848 "[E_OUT_OF_MEMORY] The memory is insufficient.");
852 r = ErrorMapToRetVal(retVal);
853 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
854 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
859 void* pTempArtwork = null;
860 unique_ptr<void, VoidDeleter> pArtwork(null);
862 // Get the artwork image in media file
863 retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempVideoMeta);
864 pVideoMeta.reset(pTempVideoMeta);
865 if (pTempArtwork != null)
867 pArtwork.reset(pTempArtwork);
870 ImageFormat format = IMG_FORMAT_NONE;
873 r = buffer.Construct(size);
874 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
876 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
882 format = img.GetImageFormat(buffer);
884 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
885 if (pMetadata->pAlbumArt == null)
887 // Because Album Art is one of the metadata, it is not exception in this function.
888 SysLog(NID_CNT, "DecodeN failed.");
896 r = ErrorMapToRetVal(retVal);
897 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
898 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
901 return pVideoMetadata.release();
905 _ContentManagerUtilImpl::GetImageMetaN(const ByteBuffer& byteBuffer)
909 int bufferLen = byteBuffer.GetRemaining();
910 SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
912 // create object here as it needs to be passed to client in any case to make sure Get APIs do not crash
913 unique_ptr<ImageMetadata> pImageMetadata(new (nothrow) ImageMetadata());
914 SysTryReturn(NID_CNT, pImageMetadata != null, null, E_OUT_OF_MEMORY,
915 "[E_OUT_OF_MEMORY] pImageMetadata is null.");
917 _ImageMetadataImpl* pImageMetaImpl = _ImageMetadataImpl::GetInstance(*(pImageMetadata.get()));
918 SysTryReturn(NID_CNT, pImageMetaImpl != null, null, E_OUT_OF_MEMORY,
919 "[E_OUT_OF_MEMORY] pImageMetaImpl is null.");
921 ImageMeta* pMetadata = pImageMetaImpl->GetImageMetadata();
922 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
923 "[E_INVALID_ARG] pMetadata is null.");
925 //assign by default here and overwrite below if width and height presents in EXIF data.
926 ImageFormat imgType = IMG_FORMAT_NONE;
929 bool isOrientation = false;
930 bool isLatitude = false;
931 bool isLongitude = false;
933 result r = ImageBuffer::GetImageInfo(byteBuffer, imgType, imageWidth, imageHeight);
934 SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_INVALID_ARG,
935 "[E_INVALID_ARG] GetImageInfo failed.");
937 pMetadata->width = imageWidth;
938 pMetadata->height = imageHeight;
940 if (imgType == IMG_FORMAT_JPG)
942 const byte* pByte = byteBuffer.GetPointer();
944 unique_ptr<ExifData, ExifDataDeleter> pExifdata(exif_data_new_from_data(pByte, bufferLen));
945 if (pExifdata != null)
948 ExifByteOrder byteOrder;
949 ExifEntry** pEntries = null;
950 const char* pData = null;
951 char buf[_IMAGE_BUFF_LENGTH] = {0, };
952 ExifContent* pExifcont[EXIF_IFD_COUNT];
953 char latitudeRef = 0; // to store latitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
954 char longitudeRef = 0; // to store longitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
955 unsigned int entryCount = 0;
957 for (int i = 0; i < EXIF_IFD_COUNT; i++)
959 pExifcont[i] = pExifdata->ifd[i];
960 entryCount = pExifcont[i]->count;
961 pEntries = pExifcont[i]->entries;
962 for (unsigned int j = 0; j < entryCount; j++)
964 tag = pEntries[j]->tag;
965 pData = exif_entry_get_value(pEntries[j], buf, sizeof(buf));
966 SysTryReturn(NID_CNT, pData != null, pImageMetadata.release(), E_INVALID_ARG,
967 "[E_INVALID_ARG] exif_entry_get_value failed.");
969 if (tag == EXIF_TAG_PIXEL_X_DIMENSION)
971 pMetadata->width = atoi(buf);
973 else if (tag == EXIF_TAG_PIXEL_Y_DIMENSION)
975 pMetadata->height = atoi(buf);
977 else if (tag == EXIF_TAG_MAKE)
979 pMetadata->pManufacturer = new (nothrow) String(buf);
980 SysTryReturn(NID_CNT, pMetadata->pManufacturer != null, null, E_OUT_OF_MEMORY,
981 "[E_OUT_OF_MEMORY] The memory is insufficient.");
983 else if (tag == EXIF_TAG_MODEL)
985 pMetadata->pModel = new (nothrow) String(buf);
986 SysTryReturn(NID_CNT, pMetadata->pModel != null, null, E_OUT_OF_MEMORY,
987 "[E_OUT_OF_MEMORY] The memory is insufficient.");
989 else if (tag == EXIF_TAG_DATE_TIME)
991 pMetadata->pDateTime = new (nothrow) String(buf);
992 SysTryReturn(NID_CNT, pMetadata->pDateTime != null, null, E_OUT_OF_MEMORY,
993 "[E_OUT_OF_MEMORY] The memory is insufficient.");
995 else if (tag == EXIF_TAG_ORIENTATION && !isOrientation)
997 //get the byte order(little endian or big endian) before extracting orientation type
998 byteOrder = exif_data_get_byte_order(pEntries[j]->parent->parent);
999 pMetadata->orientation = static_cast<ImageOrientationType>(exif_get_short(pEntries[j]->data, byteOrder));
1001 isOrientation = true;
1003 else if (tag == EXIF_TAG_SOFTWARE)
1005 pMetadata->pSoftware = new (nothrow) String(buf);
1006 SysTryReturn(NID_CNT, pMetadata->pSoftware != null, null, E_OUT_OF_MEMORY,
1007 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1009 else if (tag == EXIF_TAG_GPS_LATITUDE_REF)
1011 latitudeRef = buf[0]; // GPS Latitude reference value will be 'N'(NORTH) or 'S'(SOUTH)
1013 else if (tag == EXIF_TAG_GPS_LATITUDE && !isLatitude)
1015 String tempLatitude(buf);
1016 if (!tempLatitude.Contains(L","))
1018 pMetadata->latitude = DEFAULT_COORDINATE;
1026 r = tempLatitude.IndexOf(',', 0, firstComma);
1027 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform IndexOf operation.", GetErrorMessage(r));
1029 r = tempLatitude.SetCharAt('/', firstComma);
1030 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform SetCharAt operation.", GetErrorMessage(r));
1032 r = tempLatitude.LastIndexOf(',', tempLatitude.GetLength() - 1, lastComma);
1033 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform IndexOf operation.", GetErrorMessage(r));
1035 r = tempLatitude.SetCharAt('/', lastComma);
1036 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform SetCharAt operation.", GetErrorMessage(r));
1039 StringTokenizer strTok(tempLatitude, delim);
1040 String token[3] = {L"", };
1043 while (strTok.HasMoreTokens() && count < 3)
1045 strTok.GetNextToken(token[count++]);
1048 double ddVal = _LocalizedNumParser::ToDouble(token[0], ""); // degree value
1049 r = GetLastResult();
1050 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
1052 double mmVal = _LocalizedNumParser::ToDouble(token[1], ""); // minutes value
1053 r = GetLastResult();
1054 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
1056 double ssVal = _LocalizedNumParser::ToDouble(token[2], ""); // seconds value
1057 r = GetLastResult();
1058 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
1060 pMetadata->latitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
1062 // if latitude designation is Southern (SOUTH) then latitude degree will be negative DD
1063 if (latitudeRef == 'S')
1065 pMetadata->latitude = (pMetadata->latitude * (double)(-1));
1069 else if (tag == EXIF_TAG_GPS_LONGITUDE_REF)
1071 longitudeRef = buf[0]; // GPS Longitude reference value will be 'W'(WEST) or 'E'(EAST)
1073 else if (tag == EXIF_TAG_GPS_LONGITUDE && !isLongitude)
1075 String tempLongitude(buf);
1076 if (!tempLongitude.Contains(L","))
1078 pMetadata->longitude = DEFAULT_COORDINATE;
1086 r = tempLongitude.IndexOf(',', 0, firstComma);
1087 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform IndexOf operation.", GetErrorMessage(r));
1089 r = tempLongitude.SetCharAt('/', firstComma);
1090 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform SetCharAt operation.", GetErrorMessage(r));
1092 r = tempLongitude.LastIndexOf(',', tempLongitude.GetLength() - 1, lastComma);
1093 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform IndexOf operation.", GetErrorMessage(r));
1095 r = tempLongitude.SetCharAt('/', lastComma);
1096 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[%s] Failed to perform SetCharAt operation.", GetErrorMessage(r));
1099 StringTokenizer strTok(tempLongitude, delim);
1100 String token[3] = {L"", };
1103 while (strTok.HasMoreTokens() && count < 3)
1105 strTok.GetNextToken(token[count++]);
1108 double ddVal = _LocalizedNumParser::ToDouble(token[0], ""); // degree value
1109 r = GetLastResult();
1110 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
1112 double mmVal = _LocalizedNumParser::ToDouble(token[1], ""); // minutes value
1113 r = GetLastResult();
1114 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
1116 double ssVal = _LocalizedNumParser::ToDouble(token[2], ""); // seconds value
1117 r = GetLastResult();
1118 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
1120 pMetadata->longitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
1122 // if longitude designation is Western (WEST) then longitude degree will be negative DD
1123 if (longitudeRef == 'W')
1125 pMetadata->longitude = (pMetadata->longitude * (double)(-1));
1129 else if (tag == EXIF_TAG_WHITE_BALANCE)
1131 pMetadata->pWhiteBalance = new (nothrow) String(buf);
1132 SysTryReturn(NID_CNT, pMetadata->pWhiteBalance != null, null, E_OUT_OF_MEMORY,
1133 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1140 return pImageMetadata.release();
1144 _ContentManagerUtilImpl::GetAudioMetaN(const ByteBuffer& byteBuffer)
1148 int bufferLen = byteBuffer.GetRemaining();
1149 SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
1151 // create here to make sure that get apis will not crash though the below API calls fails in case of invalid file.
1152 unique_ptr<AudioMetadata> pAudioMetadata(new (nothrow) AudioMetadata());
1153 SysTryReturn(NID_CNT, pAudioMetadata != null, null, E_OUT_OF_MEMORY,
1154 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1156 _AudioMetadataImpl* pAudioMetaImpl = _AudioMetadataImpl::GetInstance(*(pAudioMetadata.get()));
1157 SysTryReturn(NID_CNT, pAudioMetaImpl != null, null, E_OUT_OF_MEMORY,
1158 "[E_OUT_OF_MEMORY] pAudioMetaImpl is null.");
1160 AudioMeta* pMetadata = pAudioMetaImpl->GetAudioMetadata();
1161 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
1162 "[E_INVALID_ARG] pMetadata is null.");
1164 // Create the metadata extractor handle
1165 metadata_extractor_h tempExtractor = NULL;
1167 int retVal = metadata_extractor_create(&tempExtractor);
1168 result r = ErrorMapToRetVal(retVal);
1169 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1170 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1172 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
1173 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
1174 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1176 const byte* pByte = byteBuffer.GetPointer();
1178 retVal = metadata_extractor_set_buffer(pExtractor.get(), pByte, bufferLen);
1179 r = ErrorMapToRetVal(retVal);
1180 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1181 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1183 // Get all relavent audio metadata by passing relavent attirbutes
1184 char* pTempAudioMeta = null;
1185 unique_ptr<char, CharDeleter> pAudioMeta(null);
1188 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempAudioMeta);
1189 if (pTempAudioMeta != null)
1191 pAudioMeta.reset(pTempAudioMeta);
1192 pMetadata->bitrate = atoi(pAudioMeta.get());
1196 r = ErrorMapToRetVal(retVal);
1197 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1198 "[%s] metadata_extractor_get_metadata(bitrate) failed.", GetErrorMessage(r));
1202 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_CHANNELS, &pTempAudioMeta);
1203 if (pTempAudioMeta != null)
1205 pAudioMeta.reset(pTempAudioMeta);
1206 pMetadata->channelCount = atoi(pAudioMeta.get());
1210 r = ErrorMapToRetVal(retVal);
1211 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1212 "[%s] metadata_extractor_get_metadata(channels) failed.", GetErrorMessage(r));
1216 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempAudioMeta);
1217 if (pTempAudioMeta != null)
1219 pAudioMeta.reset(pTempAudioMeta);
1220 pMetadata->duration = atoi(pAudioMeta.get());
1224 r = ErrorMapToRetVal(retVal);
1225 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1226 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
1230 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_SAMPLERATE, &pTempAudioMeta);
1231 if (pTempAudioMeta != null)
1233 pAudioMeta.reset(pTempAudioMeta);
1234 pMetadata->frequency = atoi(pAudioMeta.get());
1238 r = ErrorMapToRetVal(retVal);
1239 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1240 "[%s] metadata_extractor_get_metadata(frequency) failed.", GetErrorMessage(r));
1244 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ALBUM, &pTempAudioMeta);
1245 if (pTempAudioMeta != null)
1247 pAudioMeta.reset(pTempAudioMeta);
1248 pMetadata->pAlbumName = new (nothrow) String(pAudioMeta.get());
1249 SysTryReturn(NID_CNT, pMetadata->pAlbumName != null, null, E_OUT_OF_MEMORY,
1250 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1254 r = ErrorMapToRetVal(retVal);
1255 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1256 "[%s] metadata_extractor_get_metadata(album name) failed.", GetErrorMessage(r));
1260 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ARTIST, &pTempAudioMeta);
1261 if (pAudioMeta.get() != null)
1263 pAudioMeta.reset(pTempAudioMeta);
1264 pMetadata->pArtist = new (nothrow) String(pAudioMeta.get());
1265 SysTryReturn(NID_CNT, pMetadata->pArtist != null, null, E_OUT_OF_MEMORY,
1266 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1270 r = ErrorMapToRetVal(retVal);
1271 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1272 "[%s] metadata_extractor_get_metadata(artist) failed.", GetErrorMessage(r));
1276 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COPYRIGHT, &pTempAudioMeta);
1277 if (pTempAudioMeta != null)
1279 pAudioMeta.reset(pTempAudioMeta);
1280 pMetadata->pCopyright = new (nothrow) String(pAudioMeta.get());
1281 SysTryReturn(NID_CNT, pMetadata->pCopyright != null, null, E_OUT_OF_MEMORY,
1282 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1286 r = ErrorMapToRetVal(retVal);
1287 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1288 "[%s] metadata_extractor_get_metadata(copyright) failed.", GetErrorMessage(r));
1292 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempAudioMeta);
1293 if (pTempAudioMeta != null)
1295 pAudioMeta.reset(pTempAudioMeta);
1296 pMetadata->pGenre = new (nothrow) String(pAudioMeta.get());
1297 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
1298 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1302 r = ErrorMapToRetVal(retVal);
1303 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1304 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
1308 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TITLE, &pTempAudioMeta);
1309 if (pTempAudioMeta != null)
1311 pAudioMeta.reset(pTempAudioMeta);
1312 pMetadata->pTitle = new (nothrow) String(pAudioMeta.get());
1313 SysTryReturn(NID_CNT, pMetadata->pTitle != null, null, E_OUT_OF_MEMORY,
1314 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1318 r = ErrorMapToRetVal(retVal);
1319 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1320 "[%s] metadata_extractor_get_metadata(title) failed.", GetErrorMessage(r));
1324 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempAudioMeta);
1325 if (pTempAudioMeta != null)
1327 pAudioMeta.reset(pTempAudioMeta);
1328 pMetadata->pComment = new (nothrow) String(pAudioMeta.get());
1329 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
1330 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1334 r = ErrorMapToRetVal(retVal);
1335 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1336 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
1340 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempAudioMeta);
1341 if (pTempAudioMeta != null)
1343 pAudioMeta.reset(pTempAudioMeta);
1344 pMetadata->pDescription = new (nothrow) String(pAudioMeta.get());
1345 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
1346 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1350 r = ErrorMapToRetVal(retVal);
1351 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1352 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
1356 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_RECDATE, &pTempAudioMeta);
1357 if (pTempAudioMeta != null)
1359 pAudioMeta.reset(pTempAudioMeta);
1360 pMetadata->pRecordingDate = new (nothrow) String(pAudioMeta.get());
1361 SysTryReturn(NID_CNT, pMetadata->pRecordingDate != null, null, E_OUT_OF_MEMORY,
1362 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1366 r = ErrorMapToRetVal(retVal);
1367 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1368 "[%s] metadata_extractor_get_metadata(recording date) failed.", GetErrorMessage(r));
1372 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUTHOR, &pTempAudioMeta);
1373 if (pTempAudioMeta != null)
1375 pAudioMeta.reset(pTempAudioMeta);
1376 pMetadata->pComposer = new (nothrow) String(pAudioMeta.get());
1377 SysTryReturn(NID_CNT, pMetadata->pComposer != null, null, E_OUT_OF_MEMORY,
1378 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1382 r = ErrorMapToRetVal(retVal);
1383 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1384 "[%s] metadata_extractor_get_metadata(author) failed.", GetErrorMessage(r));
1388 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TRACK_NUM, &pTempAudioMeta);
1389 if (pTempAudioMeta != null)
1391 pAudioMeta.reset(pTempAudioMeta);
1392 pMetadata->pTrackInfo = new (nothrow) String(pAudioMeta.get());
1393 SysTryReturn(NID_CNT, pMetadata->pTrackInfo != null, null, E_OUT_OF_MEMORY,
1394 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1396 // if the string contains the track info like track num/track position,
1397 // then track position will be ignored and only track num is returned
1398 // no need to parse this string, since only track number is required
1399 pMetadata->trackNum = atoi(pAudioMeta.get());
1403 r = ErrorMapToRetVal(retVal);
1404 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1405 "[%s] metadata_extractor_get_metadata(track info) failed.", GetErrorMessage(r));
1409 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DATE, &pTempAudioMeta);
1410 if (pTempAudioMeta != null)
1412 pAudioMeta.reset(pTempAudioMeta);
1413 pMetadata->year = atoi(pAudioMeta.get());
1417 r = ErrorMapToRetVal(retVal);
1418 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1419 "[%s] metadata_extractor_get_metadata(date) failed.", GetErrorMessage(r));
1424 void* pTempArtwork = null;
1425 unique_ptr<void, VoidDeleter> pArtwork(null);
1427 // Get the artwork image in media file
1428 retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempAudioMeta);
1429 pAudioMeta.reset(pTempAudioMeta);
1431 //Check if the albumart present and pass it to client if it is successfully processed, otherwise ignore any errors
1432 //while processing albumart. This is to pass the other metadata tags to application.
1433 if (pTempArtwork != null)
1435 pArtwork.reset(pTempArtwork);
1438 ImageFormat format = IMG_FORMAT_NONE;
1441 r = buffer.Construct(size);
1442 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
1444 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
1447 r = img.Construct();
1450 format = img.GetImageFormat(buffer);
1451 pMetadata->pThumbnail = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888,
1452 _THUMBNAIL_IMAGE_WIDTH, _THUMBNAIL_IMAGE_HEIGHT);
1453 if (pMetadata->pThumbnail == null)
1455 // Because Thumbnail is one of the metadata, it is not exception in this function.
1456 SysLog(NID_CNT, "DecodeN failed.");
1458 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
1459 if (pMetadata->pAlbumArt == null)
1461 // Because Album Art is one of the metadata, it is not exception in this function.
1462 SysLog(NID_CNT, "DecodeN failed.");
1470 r = ErrorMapToRetVal(retVal);
1471 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1472 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
1475 return pAudioMetadata.release();
1479 _ContentManagerUtilImpl::GetVideoMetaN(const ByteBuffer& byteBuffer)
1483 int bufferLen = byteBuffer.GetRemaining();
1484 SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
1486 // need to create here to make sure that all get APIs will not crash in case of corrupted file
1487 unique_ptr<VideoMetadata> pVideoMetadata(new (nothrow) VideoMetadata());
1488 SysTryReturn(NID_CNT, pVideoMetadata != null, null, E_OUT_OF_MEMORY,
1489 "[E_OUT_OF_MEMORY] The memory insufficient.");
1491 _VideoMetadataImpl* pVideoMetaImpl = _VideoMetadataImpl::GetInstance(*(pVideoMetadata.get()));
1492 SysTryReturn(NID_CNT, pVideoMetaImpl != null, null, E_OUT_OF_MEMORY,
1493 "[E_OUT_OF_MEMORY] pVideoMetaImpl is null.");
1495 VideoMeta* pMetadata = pVideoMetaImpl->GetVideoMetadata();
1496 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
1497 "[E_INVALID_ARG] pMetadata is null.");
1499 // Create the metadata extractor handle
1500 metadata_extractor_h tempExtractor = NULL;
1502 int retVal = metadata_extractor_create(&tempExtractor);
1503 result r = ErrorMapToRetVal(retVal);
1504 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1505 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1507 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
1508 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
1509 "[E_OUT_OF_MEMORY] The memory insufficient.");
1511 const byte* pByte = byteBuffer.GetPointer();
1513 retVal = metadata_extractor_set_buffer(pExtractor.get(), pByte, bufferLen);
1514 r = ErrorMapToRetVal(retVal);
1515 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1516 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1518 // Get all relavent video metadata by passing relavent attirbutes
1519 char* pTempVideoMeta = null;
1520 unique_ptr<char, CharDeleter> pVideoMeta(null);
1523 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_WIDTH, &pTempVideoMeta);
1524 if (pTempVideoMeta != null)
1526 pVideoMeta.reset(pTempVideoMeta);
1527 pMetadata->width = atoi(pVideoMeta.get());
1531 r = ErrorMapToRetVal(retVal);
1532 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1533 "[%s] metadata_extractor_get_metadata(width) failed.", GetErrorMessage(r));
1537 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_HEIGHT, &pTempVideoMeta);
1538 if (pTempVideoMeta != null)
1540 pVideoMeta.reset(pTempVideoMeta);
1541 pMetadata->height = atoi(pVideoMeta.get());
1545 r = ErrorMapToRetVal(retVal);
1546 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1547 "[%s] metadata_extractor_get_metadata(height) failed.", GetErrorMessage(r));
1551 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_BITRATE, &pTempVideoMeta);
1552 if (pTempVideoMeta != null)
1554 pVideoMeta.reset(pTempVideoMeta);
1555 pMetadata->videoBitrate = atoi(pVideoMeta.get());
1559 r = ErrorMapToRetVal(retVal);
1560 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1561 "[%s] metadata_extractor_get_metadata(video bitrate) failed.", GetErrorMessage(r));
1565 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempVideoMeta);
1566 if (pTempVideoMeta != null)
1568 pVideoMeta.reset(pTempVideoMeta);
1569 pMetadata->audioBitrate = atoi(pVideoMeta.get());
1573 r = ErrorMapToRetVal(retVal);
1574 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1575 "[%s] metadata_extractor_get_metadata(audio bitrate) failed.", GetErrorMessage(r));
1579 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_FPS, &pTempVideoMeta);
1580 if (pTempVideoMeta != null)
1582 pVideoMeta.reset(pTempVideoMeta);
1583 pMetadata->framerate = atoi(pVideoMeta.get());
1587 r = ErrorMapToRetVal(retVal);
1588 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1589 "[%s] metadata_extractor_get_metadata(framerate) failed.", GetErrorMessage(r));
1593 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempVideoMeta);
1594 if (pTempVideoMeta != null)
1596 pVideoMeta.reset(pTempVideoMeta);
1597 pMetadata->duration = atoi(pVideoMeta.get());
1601 r = ErrorMapToRetVal(retVal);
1602 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1603 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
1607 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempVideoMeta);
1608 if (pTempVideoMeta != null)
1610 pVideoMeta.reset(pTempVideoMeta);
1611 pMetadata->pGenre = new (nothrow) String(pVideoMeta.get()); //allocate memory
1612 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
1613 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1617 r = ErrorMapToRetVal(retVal);
1618 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1619 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
1623 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempVideoMeta);
1624 if (pTempVideoMeta != null)
1626 pVideoMeta.reset(pTempVideoMeta);
1627 pMetadata->pComment = new (nothrow) String(pVideoMeta.get());
1628 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
1629 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1633 r = ErrorMapToRetVal(retVal);
1634 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1635 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
1639 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempVideoMeta);
1640 if (pTempVideoMeta != null)
1642 pVideoMeta.reset(pTempVideoMeta);
1643 pMetadata->pDescription = new (nothrow) String(pVideoMeta.get());
1644 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
1645 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1649 r = ErrorMapToRetVal(retVal);
1650 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1651 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
1656 void* pTempArtwork = null;
1657 unique_ptr<void, VoidDeleter> pArtwork(null);
1659 // Get the artwork image in media file
1660 retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempVideoMeta);
1661 pVideoMeta.reset(pTempVideoMeta);
1662 if (pTempArtwork != null)
1664 pArtwork.reset(pTempArtwork);
1667 ImageFormat format = IMG_FORMAT_NONE;
1670 r = buffer.Construct(size);
1671 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
1673 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
1676 r = img.Construct();
1679 format = img.GetImageFormat(buffer);
1681 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
1682 if (pMetadata->pAlbumArt == null)
1684 // Because Album Art is one of the metadata, it is not exception in this function.
1685 SysLog(NID_CNT, "DecodeN failed.");
1693 r = ErrorMapToRetVal(retVal);
1694 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1695 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
1698 return pVideoMetadata.release();
1702 _ContentManagerUtilImpl::CheckContentType(const String& contentPath, bool internal)
1706 ContentType contentType = CONTENT_TYPE_UNKNOWN;
1707 String mimeType(L"");
1711 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), contentType, E_INVALID_ARG,
1712 "[E_INVALID_ARG] The path is not compatible.");
1715 String tizenPath(L"");
1716 String changedPath(L"");
1717 result r = ChangeMediaFilePath(contentPath, tizenPath, changedPath);
1718 SysTryReturn(NID_CNT, !IsFailed(r), contentType, r, "[%s] Failed to perform ChangeMediaFilePathCompat.", GetErrorMessage(r));
1720 SysTryReturn(NID_CNT, changedPath.GetLength() != 0, contentType, E_INVALID_ARG,
1721 "[E_INVALID_ARG] The length of contentPath is 0.");
1722 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(changedPath), contentType, E_FILE_NOT_FOUND,
1723 "[E_FILE_NOT_FOUND] The file corresponding to contentPath could not be found.");
1725 String fileExt = _FileImpl::GetFileExtension(changedPath);
1726 r = GetLastResult();
1730 unique_ptr<char[]> pFormat(_StringConverter::CopyToCharArrayN(fileExt));
1731 SysTryReturn(NID_CNT, pFormat != null, contentType, E_OUT_OF_MEMORY,
1732 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1734 char* pTempMimeType = null;
1735 int retVal = mime_type_get_mime_type(pFormat.get(), &pTempMimeType);
1736 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, E_INVALID_ARG,
1737 "[E_INVALID_ARG] mime_type_get_mime_type failed.");
1738 SysTryReturn(NID_CNT, pTempMimeType != null, contentType, E_INVALID_ARG,
1739 "[E_INVALID_ARG] mime_type_get_mime_type failed.");
1741 unique_ptr<char, CharDeleter> pMimeType;
1742 pMimeType.reset(pTempMimeType);
1744 SysLog(NID_CNT, "The MIME type for %ls is %s", fileExt.GetPointer(), pTempMimeType);
1746 r = mimeType.Append(pMimeType.get());
1747 SysTryReturn(NID_CNT, !IsFailed(r), contentType, E_OUT_OF_MEMORY,
1748 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1754 SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
1756 unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(tizenPath));
1757 SysTryReturn(NID_CNT, pTempPath != null, contentType, E_OUT_OF_MEMORY,
1758 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1760 char tempType[255] = {0, };
1761 int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
1762 SysTryReturn(NID_CNT, ret == AUL_R_OK, contentType, E_INVALID_ARG,
1763 "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
1765 r = mimeType.Append(tempType);
1766 SysTryReturn(NID_CNT, !IsFailed(r), contentType, E_OUT_OF_MEMORY,
1767 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1770 if (mimeType.Contains(L"image"))
1772 return CONTENT_TYPE_IMAGE;
1774 else if (mimeType.Contains(L"audio"))
1776 if (mimeType.Contains(L"x-mpegurl"))
1778 SysLog(NID_CNT, "The type of x-mpegurl is other.");
1779 return CONTENT_TYPE_OTHER;
1781 return CONTENT_TYPE_AUDIO;
1783 else if (mimeType.Contains(L"video"))
1785 if (mimeType == L"video/3gpp" || mimeType == L"video/mp4")
1787 return CheckStream(tizenPath);
1789 return CONTENT_TYPE_VIDEO;
1791 else if (mimeType.Contains(L"application"))
1793 if (mimeType.Contains(L"x-smaf"))
1795 SysLog(NID_CNT, "The type of x-smaf is audio.");
1796 return CONTENT_TYPE_AUDIO;
1798 return CONTENT_TYPE_OTHER;
1801 return CONTENT_TYPE_OTHER;
1805 _ContentManagerUtilImpl::CheckStream(const String& contentPath)
1809 ContentType contentType = CONTENT_TYPE_UNKNOWN;
1810 metadata_extractor_h tempExtractor = NULL;
1812 int retVal = metadata_extractor_create(&tempExtractor);
1813 result r = ErrorMapToRetVal(retVal);
1814 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
1815 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1817 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
1818 SysTryReturn(NID_CNT, pExtractor != null, contentType, E_OUT_OF_MEMORY,
1819 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1821 //Set the file path to extract metadata.
1822 unique_ptr<char[]> pContentPath(_StringConverter::CopyToCharArrayN(contentPath));
1823 SysTryReturn(NID_CNT, pContentPath != null, contentType, E_INVALID_ARG,
1824 "[E_INVALID_ARG] The memory is insufficient.");
1826 retVal = metadata_extractor_set_path(pExtractor.get(), pContentPath.get());
1827 r = ErrorMapToRetVal(retVal);
1828 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE && pExtractor, contentType, r,
1829 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1831 //Check whether it is an audio or video file.
1832 char* pTempAudio = null;
1833 unique_ptr<char, CharDeleter> pAudio(null);
1835 char* pTempVideo = null;
1836 unique_ptr<char, CharDeleter> pVideo(null);
1838 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_HAS_AUDIO, &pTempAudio);
1839 if (pTempAudio != null)
1841 pAudio.reset(pTempAudio);
1845 // The return value is CONTENT_TYPE_VIDEO because CreaetContent have to success, even if the content is invalid.
1846 r = ErrorMapToRetVal(retVal);
1847 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, CONTENT_TYPE_VIDEO, r,
1848 "[%s] metadata_extractor_get_metadata failed.", GetErrorMessage(r));
1851 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_HAS_VIDEO, &pTempVideo);
1852 if (pTempVideo != null)
1854 pVideo.reset(pTempVideo);
1858 // The return value is CONTENT_TYPE_VIDEO because CreaetContent have to success, even if the content is invalid.
1859 r = ErrorMapToRetVal(retVal);
1860 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, CONTENT_TYPE_VIDEO, r,
1861 "[%s] metadata_extractor_get_metadata failed.", GetErrorMessage(r));
1864 if (*(pAudio.get()) > '0' && *(pVideo.get()) == '0')
1866 SysLog(NID_CNT, "The result of CheckStream() is audio");
1867 return CONTENT_TYPE_AUDIO;
1869 else if (*(pAudio.get()) == '0' && *(pVideo.get()) > '0')
1871 SysLog(NID_CNT, "The result of CheckStream() is video");
1872 return CONTENT_TYPE_VIDEO;
1874 else if (*(pAudio.get()) > '0' && *(pVideo.get()) > '0')
1876 SysLog(NID_CNT, "The result of CheckStream() is video");
1877 return CONTENT_TYPE_VIDEO;
1881 SysLogException(NID_CNT, E_UNSUPPORTED_FORMAT, "[E_UNSUPPORTED_FORMAT] The stream is empty.");
1888 _ContentManagerUtilImpl::VerifyFilePathCompatibility(const String& contentPath)
1890 if (!_AppInfo::IsOspCompat())
1892 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0)
1893 || contentPath.StartsWith(OSP_HOME, 0))
1895 SysLogException(NID_CNT, E_INVALID_ARG,
1896 "/Home, /Media/, or /Storagecard/Media/ is not supported from Tizen 2.0.");
1903 if (!(contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0)
1904 || contentPath.StartsWith(OSP_HOME, 0)))
1906 SysLogException(NID_CNT, E_INVALID_ARG,
1907 "The contentPath should start with /Home, /Media, or /Storagecard/Media.");
1916 _ContentManagerUtilImpl::ErrorMapToRetVal(int retVal)
1918 result r = E_SUCCESS;
1922 case METADATA_EXTRACTOR_ERROR_NONE:
1925 case METADATA_EXTRACTOR_ERROR_INVALID_PARAMETER:
1928 case METADATA_EXTRACTOR_ERROR_OUT_OF_MEMORY:
1929 r = E_OUT_OF_MEMORY;
1931 case METADATA_EXTRACTOR_ERROR_FILE_EXISTS:
1934 case METADATA_EXTRACTOR_ERROR_OPERATION_FAILED:
1943 _ContentManagerUtilImpl::CopyToMediaDirectory(const String& srcContentPath, const String& destContentPath)
1947 // For srcContentPath
1948 SysTryReturn(NID_CNT, !_FileImpl::IsSystemPath(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1949 "[E_INVALID_ARG] Can not copy the file in the system region.");
1950 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1951 "[E_INVALID_ARG] Can not find the file.");
1953 // For destContentPath
1954 SysTryReturn(NID_CNT, _FileImpl::IsMediaPath(destContentPath), E_INVALID_ARG, E_INVALID_ARG,
1955 "[E_INVALID_ARG] The destination path should start with /Media or /Storagecard/Media.");
1957 // E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_FILE_NOT_FOUND, E_FILE_ALREADY_EXIST, E_MAX_EXCEEDED, E_STORAGE_FULL, E_IO
1958 result r = E_SUCCESS;
1959 r = _FileImpl::Copy(srcContentPath, destContentPath, true);
1960 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] CopyToMediaDirectory failed.", GetErrorMessage(r));
1966 _ContentManagerUtilImpl::MoveToMediaDirectory(const String& srcContentPath, const String& destContentPath)
1970 // For srcContentPath
1971 SysTryReturn(NID_CNT, !_FileImpl::IsSystemPath(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1972 "[E_INVALID_ARG] Can not copy the file in the system region.");
1973 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1974 "[E_INVALID_ARG] Can not find the file.");
1976 // For destContentPath
1977 SysTryReturn(NID_CNT, _FileImpl::IsMediaPath(destContentPath), E_INVALID_ARG, E_INVALID_ARG,
1978 "[E_INVALID_ARG] The destination path should start with /Media or /Storagecard/Media.");
1980 // E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_FILE_NOT_FOUND, E_FILE_ALREADY_EXIST, E_MAX_EXCEEDED, E_STORAGE_FULL, E_IO
1981 result r = E_SUCCESS;
1982 r = _FileImpl::Move(srcContentPath, destContentPath);
1983 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] MoveToMediaDirectory failed.", GetErrorMessage(r));
1989 _ContentManagerUtilImpl::ChangeMediaFilePath(const String& contentPath, String& tizenPath, String& changedPath)
1991 result r = E_SUCCESS;
1993 tizenPath = contentPath;
1994 changedPath = contentPath;
1996 // If the api version is 2.0, the content path has to be changed.
1997 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1999 if ((contentPath.StartsWith(Environment::GetMediaPath(), 0)) || (contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
2001 tizenPath = contentPath;
2003 r = _FileImpl::ConvertPhysicalToVirtualPath(contentPath, changedPath);
2004 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
2005 "[%s] Failed to convert physical path to virtual path.", GetErrorMessage(E_INVALID_ARG));
2007 else if ((contentPath.StartsWith(OSP_MEDIA_PHONE, 0)) || (contentPath.StartsWith(OSP_MEDIA_MMC, 0)) || (contentPath.StartsWith(OSP_HOME, 0)))
2009 changedPath = contentPath;
2011 r = _FileImpl::ConvertVirtualToPhysicalPath(contentPath, tizenPath);
2012 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
2013 "[%s] Failed to convert virtual path to physical path.", GetErrorMessage(E_INVALID_ARG));
2017 SysLogException(NID_CNT, E_INVALID_ARG, "[%s] The path is not supported.", GetErrorMessage(E_INVALID_ARG));
2018 return E_INVALID_ARG;