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.
25 #include <mime_type.h>
27 #include <FBaseByteBuffer.h>
28 #include <FBaseSysLog.h>
29 #include <FBaseUtilStringTokenizer.h>
30 #include <FCntImageMetadata.h>
31 #include <FCntAudioMetadata.h>
32 #include <FCntVideoMetadata.h>
33 #include <FMediaImage.h>
34 #include <FMediaImageBuffer.h>
35 #include <FMediaImageUtil.h>
36 #include <FIoDirectory.h>
37 #include <FSysEnvironment.h>
38 #include <FApp_AppInfo.h>
39 #include <FBase_LocalizedNumParser.h>
40 #include <FBase_StringConverter.h>
41 #include <FGrp_BitmapImpl.h>
42 #include <FIo_FileImpl.h>
43 #include <FMedia_ImageDecoder.h>
44 #include <FMedia_ImageImpl.h>
45 #include "FCnt_AudioMetadataImpl.h"
46 #include "FCnt_ContentManagerUtilImpl.h"
47 #include "FCnt_ImageMetadataImpl.h"
48 #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
62 // Types of content, format supported and default values
63 static const int _IMAGE_BUFF_LENGTH = 100;
64 static const int _THUMBNAIL_IMAGE_WIDTH = 80;
65 static const int _THUMBNAIL_IMAGE_HEIGHT = 60;
66 static const int _MINUTES = 60;
67 static const int _SECONDS = 3600;
70 _ContentManagerUtilImpl::GetImageMetaN(const String& contentPath, bool internal)
76 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), null, E_INVALID_ARG,
77 "[E_INVALID_ARG] The path is not compatible.");
79 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_INVALID_ARG,
80 "[E_INVALID_ARG] The file corresponding to contentPath could not be found.");
82 // create object here as it needs to be passed to client in any case to make sure Get APIs do not crash
83 unique_ptr<ImageMetadata> pImageMetadata(new (nothrow) ImageMetadata());
84 SysTryReturn(NID_CNT, pImageMetadata != null, null, E_OUT_OF_MEMORY,
85 "[E_OUT_OF_MEMORY] pImageMetadata is null.");
87 _ImageMetadataImpl* pImageMetaImpl = _ImageMetadataImpl::GetInstance(*(pImageMetadata.get()));
88 SysTryReturn(NID_CNT, pImageMetaImpl != null, null, E_OUT_OF_MEMORY,
89 "[E_OUT_OF_MEMORY] pImageMetaImpl is null.");
91 ImageMeta* pMetadata = pImageMetaImpl->GetImageMetadata();
92 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
93 "[E_INVALID_ARG] pMetadata is null.");
95 //assign by default here and overwrite below if width and height presents in EXIF data.
96 ImageFormat imgType = IMG_FORMAT_NONE;
99 result r = _ImageImpl::GetImageInfo(contentPath, imgType, dim);
100 SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_INVALID_ARG,
101 "[E_INVALID_ARG] GetImageInfo failed.");
103 pMetadata->width = dim.width;
104 pMetadata->height = dim.height;
105 pMetadata->contentPath = contentPath;
107 if (imgType == IMG_FORMAT_JPG)
109 unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(contentPath));
110 SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
111 "[E_OUT_OF_MEMORY] The memory is insufficient.");
113 unique_ptr<ExifData, ExifDataDeleter> pExifdata(exif_data_new_from_file(pFileName.get()));
114 if (pExifdata != null)
117 ExifByteOrder byteOrder;
118 ExifEntry** pEntries = null;
119 const char* pData = null;
120 char buf[_IMAGE_BUFF_LENGTH] = {0, };
121 char mmBuff[_IMAGE_BUFF_LENGTH] = {0, }; // to store minutes value of GPS data
122 char ssBuff[_IMAGE_BUFF_LENGTH] = {0, }; // to store seconds value of GPS data
123 ExifContent* pExifcont[EXIF_IFD_COUNT];
125 char latitudeRef = 0; // to store latitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
126 char longitudeRef = 0; // to store longitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
127 unsigned int entryCount = 0;
129 for (int i = 0; i < EXIF_IFD_COUNT; i++)
131 pExifcont[i] = pExifdata->ifd[i];
132 entryCount = pExifcont[i]->count;
133 pEntries = pExifcont[i]->entries;
134 for (unsigned int j = 0; j < entryCount; j++)
136 tag = pEntries[j]->tag;
137 pData = exif_entry_get_value(pEntries[j], buf, sizeof(buf));
138 SysTryReturn(NID_CNT, pData != null, pImageMetadata.release(), E_INVALID_ARG,
139 "[E_INVALID_ARG] exif_entry_get_value failed.");
141 if (tag == EXIF_TAG_PIXEL_X_DIMENSION)
143 pMetadata->width = atoi(buf);
145 else if (tag == EXIF_TAG_PIXEL_Y_DIMENSION)
147 pMetadata->height = atoi(buf);
149 else if (tag == EXIF_TAG_MAKE)
151 pMetadata->pManufacturer = new (nothrow) String(buf);
152 SysTryReturn(NID_CNT, pMetadata->pManufacturer != null, null, E_OUT_OF_MEMORY,
153 "[E_OUT_OF_MEMORY] The memory is insufficient.");
155 else if (tag == EXIF_TAG_MODEL)
157 pMetadata->pModel = new (nothrow) String(buf);
158 SysTryReturn(NID_CNT, pMetadata->pModel != null, null, E_OUT_OF_MEMORY,
159 "[E_OUT_OF_MEMORY] The memory is insufficient.");
161 else if (tag == EXIF_TAG_DATE_TIME)
163 pMetadata->pDateTime = new (nothrow) String(buf);
164 SysTryReturn(NID_CNT, pMetadata->pDateTime != null, null, E_OUT_OF_MEMORY,
165 "[E_OUT_OF_MEMORY] The memory is insufficient.");
167 else if (tag == EXIF_TAG_ORIENTATION)
169 //get the byte order(little endian or big endian) before extracting orientation type
170 byteOrder = exif_data_get_byte_order(pEntries[j]->parent->parent);
171 pMetadata->orientation = static_cast<ImageOrientationType>(exif_get_short(pEntries[j]->data, byteOrder));
173 else if (tag == EXIF_TAG_SOFTWARE)
175 pMetadata->pSoftware = new (nothrow) String(buf);
176 SysTryReturn(NID_CNT, pMetadata->pSoftware != null, null, E_OUT_OF_MEMORY,
177 "[E_OUT_OF_MEMORY] The memory is insufficient.");
179 else if (tag == EXIF_TAG_GPS_LATITUDE_REF)
181 latitudeRef = buf[0]; // GPS Latitude reference value will be 'N'(NORTH) or 'S'(SOUTH)
183 else if (tag == EXIF_TAG_GPS_LATITUDE)
185 String tempLatitude(buf);
188 StringTokenizer strTok(tempLatitude, delim);
189 String token[3] = {L"", };
192 while (strTok.HasMoreTokens())
194 strTok.GetNextToken(token[count++]);
197 double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value
199 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
201 double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value
203 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
205 double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value
207 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
209 pMetadata->latitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
211 // if latitude designation is Southern (SOUTH) then latitude degree will be negative DD
212 if (latitudeRef == 'S')
214 pMetadata->latitude = (pMetadata->latitude * (double)(-1));
217 else if (tag == EXIF_TAG_GPS_LONGITUDE_REF)
219 longitudeRef = buf[0]; // GPS Longitude reference value will be 'W'(WEST) or 'E'(EAST)
221 else if (tag == EXIF_TAG_GPS_LONGITUDE)
223 String tempLongitude(buf);
226 StringTokenizer strTok(tempLongitude, delim);
227 String token[3] = {L"", };
230 while (strTok.HasMoreTokens())
232 strTok.GetNextToken(token[count++]);
235 double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value
237 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
239 double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value
241 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
243 double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value
245 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
247 pMetadata->longitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
249 // if longitude designation is Western (WEST) then longitude degree will be negative DD
250 if (longitudeRef == 'W')
252 pMetadata->longitude = (pMetadata->longitude * (double)(-1));
255 else if (tag == EXIF_TAG_WHITE_BALANCE)
257 pMetadata->pWhiteBalance = new (nothrow) String(buf);
258 SysTryReturn(NID_CNT, pMetadata->pWhiteBalance != null, null, E_OUT_OF_MEMORY,
259 "[E_OUT_OF_MEMORY] The memory is insufficient.");
266 return pImageMetadata.release();
270 _ContentManagerUtilImpl::GetAudioMetaN(const String& contentPath)
274 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), null, E_INVALID_ARG,
275 "[E_INVALID_ARG] The path is not compatible.");
276 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_INVALID_ARG,
277 "[E_INVALID_ARG] The file corresponding to contentPath could not be found.");
279 // create here to make sure that get apis will not crash though the below API calls fails in case of invalid file.
280 unique_ptr<AudioMetadata> pAudioMetadata(new (nothrow) AudioMetadata());
281 SysTryReturn(NID_CNT, pAudioMetadata != null, null, E_OUT_OF_MEMORY,
282 "[E_OUT_OF_MEMORY] The memory is insufficient.");
284 _AudioMetadataImpl* pAudioMetaImpl = _AudioMetadataImpl::GetInstance(*(pAudioMetadata.get()));
285 SysTryReturn(NID_CNT, pAudioMetaImpl != null, null, E_OUT_OF_MEMORY,
286 "[E_OUT_OF_MEMORY] pAudioMetaImpl is null.");
288 AudioMeta* pMetadata = pAudioMetaImpl->GetAudioMetadata();
289 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
290 "[E_INVALID_ARG] pMetadata is null.");
292 pMetadata->contentPath = contentPath;
294 // Create the metadata extractor handle
295 metadata_extractor_h tempExtractor = NULL;
297 int retVal = metadata_extractor_create(&tempExtractor);
298 result r = ErrorMapToRetVal(retVal);
299 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
300 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
302 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
303 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
304 "[E_OUT_OF_MEMORY] The memory is insufficient.");
306 // Set file path of content to extract the metadata
307 unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(contentPath));
308 SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
309 "[E_OUT_OF_MEMORY] The memory is insufficient.");
311 retVal = metadata_extractor_set_path(pExtractor.get(), pFileName.get());
312 r = ErrorMapToRetVal(retVal);
313 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
314 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
316 // Get all relavent audio metadata by passing relavent attirbutes
317 char* pTempAudioMeta = null;
318 unique_ptr<char, CharDeleter> pAudioMeta(null);
321 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempAudioMeta);
322 if (pTempAudioMeta != null)
324 pAudioMeta.reset(pTempAudioMeta);
325 pMetadata->bitrate = atoi(pAudioMeta.get());
329 r = ErrorMapToRetVal(retVal);
330 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
331 "[%s] metadata_extractor_get_metadata(bitrate) failed.", GetErrorMessage(r));
335 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_CHANNELS, &pTempAudioMeta);
336 if (pTempAudioMeta != null)
338 pAudioMeta.reset(pTempAudioMeta);
339 pMetadata->channelCount = atoi(pAudioMeta.get());
343 r = ErrorMapToRetVal(retVal);
344 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
345 "[%s] metadata_extractor_get_metadata(channels) failed.", GetErrorMessage(r));
349 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempAudioMeta);
350 if (pTempAudioMeta != null)
352 pAudioMeta.reset(pTempAudioMeta);
353 pMetadata->duration = atoi(pAudioMeta.get());
357 r = ErrorMapToRetVal(retVal);
358 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
359 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
363 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_SAMPLERATE, &pTempAudioMeta);
364 if (pTempAudioMeta != null)
366 pAudioMeta.reset(pTempAudioMeta);
367 pMetadata->frequency = atoi(pAudioMeta.get());
371 r = ErrorMapToRetVal(retVal);
372 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
373 "[%s] metadata_extractor_get_metadata(frequency) failed.", GetErrorMessage(r));
377 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ALBUM, &pTempAudioMeta);
378 if (pTempAudioMeta != null)
380 pAudioMeta.reset(pTempAudioMeta);
381 pMetadata->pAlbumName = new (nothrow) String(pAudioMeta.get());
382 SysTryReturn(NID_CNT, pMetadata->pAlbumName != null, null, E_OUT_OF_MEMORY,
383 "[E_OUT_OF_MEMORY] The memory is insufficient.");
387 r = ErrorMapToRetVal(retVal);
388 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
389 "[%s] metadata_extractor_get_metadata(album name) failed.", GetErrorMessage(r));
393 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ARTIST, &pTempAudioMeta);
394 if (pAudioMeta.get() != null)
396 pAudioMeta.reset(pTempAudioMeta);
397 pMetadata->pArtist = new (nothrow) String(pAudioMeta.get());
398 SysTryReturn(NID_CNT, pMetadata->pArtist != null, null, E_OUT_OF_MEMORY,
399 "[E_OUT_OF_MEMORY] The memory is insufficient.");
403 r = ErrorMapToRetVal(retVal);
404 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
405 "[%s] metadata_extractor_get_metadata(artist) failed.", GetErrorMessage(r));
409 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COPYRIGHT, &pTempAudioMeta);
410 if (pTempAudioMeta != null)
412 pAudioMeta.reset(pTempAudioMeta);
413 pMetadata->pCopyright = new (nothrow) String(pAudioMeta.get());
414 SysTryReturn(NID_CNT, pMetadata->pCopyright != null, null, E_OUT_OF_MEMORY,
415 "[E_OUT_OF_MEMORY] The memory is insufficient.");
419 r = ErrorMapToRetVal(retVal);
420 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
421 "[%s] metadata_extractor_get_metadata(copyright) failed.", GetErrorMessage(r));
425 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempAudioMeta);
426 if (pTempAudioMeta != null)
428 pAudioMeta.reset(pTempAudioMeta);
429 pMetadata->pGenre = new (nothrow) String(pAudioMeta.get());
430 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
431 "[E_OUT_OF_MEMORY] The memory is insufficient.");
435 r = ErrorMapToRetVal(retVal);
436 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
437 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
441 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TITLE, &pTempAudioMeta);
442 if (pTempAudioMeta != null)
444 pAudioMeta.reset(pTempAudioMeta);
445 pMetadata->pTitle = new (nothrow) String(pAudioMeta.get());
446 SysTryReturn(NID_CNT, pMetadata->pTitle != null, null, E_OUT_OF_MEMORY,
447 "[E_OUT_OF_MEMORY] The memory is insufficient.");
451 r = ErrorMapToRetVal(retVal);
452 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
453 "[%s] metadata_extractor_get_metadata(title) failed.", GetErrorMessage(r));
457 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempAudioMeta);
458 if (pTempAudioMeta != null)
460 pAudioMeta.reset(pTempAudioMeta);
461 pMetadata->pComment = new (nothrow) String(pAudioMeta.get());
462 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
463 "[E_OUT_OF_MEMORY] The memory is insufficient.");
467 r = ErrorMapToRetVal(retVal);
468 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
469 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
473 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempAudioMeta);
474 if (pTempAudioMeta != null)
476 pAudioMeta.reset(pTempAudioMeta);
477 pMetadata->pDescription = new (nothrow) String(pAudioMeta.get());
478 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
479 "[E_OUT_OF_MEMORY] The memory is insufficient.");
483 r = ErrorMapToRetVal(retVal);
484 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
485 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
489 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_RECDATE, &pTempAudioMeta);
490 if (pTempAudioMeta != null)
492 pAudioMeta.reset(pTempAudioMeta);
493 pMetadata->pRecordingDate = new (nothrow) String(pAudioMeta.get());
494 SysTryReturn(NID_CNT, pMetadata->pRecordingDate != null, null, E_OUT_OF_MEMORY,
495 "[E_OUT_OF_MEMORY] The memory is insufficient.");
499 r = ErrorMapToRetVal(retVal);
500 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
501 "[%s] metadata_extractor_get_metadata(recording date) failed.", GetErrorMessage(r));
505 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUTHOR, &pTempAudioMeta);
506 if (pTempAudioMeta != null)
508 pAudioMeta.reset(pTempAudioMeta);
509 pMetadata->pComposer = new (nothrow) String(pAudioMeta.get());
510 SysTryReturn(NID_CNT, pMetadata->pComposer != null, null, E_OUT_OF_MEMORY,
511 "[E_OUT_OF_MEMORY] The memory is insufficient.");
515 r = ErrorMapToRetVal(retVal);
516 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
517 "[%s] metadata_extractor_get_metadata(author) failed.", GetErrorMessage(r));
521 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TRACK_NUM, &pTempAudioMeta);
522 if (pTempAudioMeta != null)
524 pAudioMeta.reset(pTempAudioMeta);
525 pMetadata->pTrackInfo = new (nothrow) String(pAudioMeta.get());
526 SysTryReturn(NID_CNT, pMetadata->pTrackInfo != null, null, E_OUT_OF_MEMORY,
527 "[E_OUT_OF_MEMORY] The memory is insufficient.");
529 // if the string contains the track info like track num/track position,
530 // then track position will be ignored and only track num is returned
531 // no need to parse this string, since only track number is required
532 pMetadata->trackNum = atoi(pAudioMeta.get());
536 r = ErrorMapToRetVal(retVal);
537 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
538 "[%s] metadata_extractor_get_metadata(track info) failed.", GetErrorMessage(r));
542 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DATE, &pTempAudioMeta);
543 if (pTempAudioMeta != null)
545 pAudioMeta.reset(pTempAudioMeta);
546 pMetadata->year = atoi(pAudioMeta.get());
550 r = ErrorMapToRetVal(retVal);
551 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
552 "[%s] metadata_extractor_get_metadata(date) failed.", GetErrorMessage(r));
557 void* pTempArtwork = null;
558 unique_ptr<void, VoidDeleter> pArtwork(null);
560 // Get the artwork image in media file
561 retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempAudioMeta);
562 pAudioMeta.reset(pTempAudioMeta);
564 //Check if the albumart present and pass it to client if it is successfully processed, otherwise ignore any errors
565 //while processing albumart. This is to pass the other metadata tags to application.
566 if (pTempArtwork != null)
568 pArtwork.reset(pTempArtwork);
571 ImageFormat format = IMG_FORMAT_NONE;
574 r = buffer.Construct(size);
575 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
577 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
583 format = img.GetImageFormat(buffer);
584 pMetadata->pThumbnail = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888,
585 _THUMBNAIL_IMAGE_WIDTH, _THUMBNAIL_IMAGE_HEIGHT);
586 if (pMetadata->pThumbnail == null)
588 // Because Thumbnail is one of the metadata, it is not exception in this function.
589 SysLog(NID_CNT, "DecodeN failed.");
591 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
592 if (pMetadata->pAlbumArt == null)
594 // Because Album Art is one of the metadata, it is not exception in this function.
595 SysLog(NID_CNT, "DecodeN failed.");
603 r = ErrorMapToRetVal(retVal);
604 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
605 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
608 return pAudioMetadata.release();
612 _ContentManagerUtilImpl::GetVideoMetaN(const String& contentPath)
616 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), null, E_INVALID_ARG,
617 "[E_INVALID_ARG] The path is not compatible.");
618 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_INVALID_ARG,
619 "[E_INVALID_ARG] The file corresponding to contentPath could not be found.");
621 // need to create here to make sure that all get APIs will not crash in case of corrupted file
622 unique_ptr<VideoMetadata> pVideoMetadata(new (nothrow) VideoMetadata());
623 SysTryReturn(NID_CNT, pVideoMetadata != null, null, E_OUT_OF_MEMORY,
624 "[E_OUT_OF_MEMORY] The memory insufficient.");
626 _VideoMetadataImpl* pVideoMetaImpl = _VideoMetadataImpl::GetInstance(*(pVideoMetadata.get()));
627 SysTryReturn(NID_CNT, pVideoMetaImpl != null, null, E_OUT_OF_MEMORY,
628 "[E_OUT_OF_MEMORY] pVideoMetaImpl is null.");
630 VideoMeta* pMetadata = pVideoMetaImpl->GetVideoMetadata();
631 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
632 "[E_INVALID_ARG] pMetadata is null.");
634 pMetadata->contentPath = contentPath;
636 // Create the metadata extractor handle
637 metadata_extractor_h tempExtractor = NULL;
639 int retVal = metadata_extractor_create(&tempExtractor);
640 result r = ErrorMapToRetVal(retVal);
641 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
642 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
644 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
645 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
646 "[E_OUT_OF_MEMORY] The memory insufficient.");
648 // Set file path of content to extract the metadata
649 unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(contentPath));
650 SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
651 "[E_OUT_OF_MEMORY] The memory is insufficient.");
653 retVal = metadata_extractor_set_path(pExtractor.get(), pFileName.get());
654 r = ErrorMapToRetVal(retVal);
655 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
656 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
658 // Get all relavent video metadata by passing relavent attirbutes
659 char* pTempVideoMeta = null;
660 unique_ptr<char, CharDeleter> pVideoMeta(null);
663 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_WIDTH, &pTempVideoMeta);
664 if (pTempVideoMeta != null)
666 pVideoMeta.reset(pTempVideoMeta);
667 pMetadata->width = atoi(pVideoMeta.get());
671 r = ErrorMapToRetVal(retVal);
672 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
673 "[%s] metadata_extractor_get_metadata(width) failed.", GetErrorMessage(r));
677 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_HEIGHT, &pTempVideoMeta);
678 if (pTempVideoMeta != null)
680 pVideoMeta.reset(pTempVideoMeta);
681 pMetadata->height = atoi(pVideoMeta.get());
685 r = ErrorMapToRetVal(retVal);
686 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
687 "[%s] metadata_extractor_get_metadata(height) failed.", GetErrorMessage(r));
691 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_BITRATE, &pTempVideoMeta);
692 if (pTempVideoMeta != null)
694 pVideoMeta.reset(pTempVideoMeta);
695 pMetadata->videoBitrate = atoi(pVideoMeta.get());
699 r = ErrorMapToRetVal(retVal);
700 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
701 "[%s] metadata_extractor_get_metadata(video bitrate) failed.", GetErrorMessage(r));
705 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempVideoMeta);
706 if (pTempVideoMeta != null)
708 pVideoMeta.reset(pTempVideoMeta);
709 pMetadata->audioBitrate = atoi(pVideoMeta.get());
713 r = ErrorMapToRetVal(retVal);
714 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
715 "[%s] metadata_extractor_get_metadata(audio bitrate) failed.", GetErrorMessage(r));
719 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_FPS, &pTempVideoMeta);
720 if (pTempVideoMeta != null)
722 pVideoMeta.reset(pTempVideoMeta);
723 pMetadata->framerate = atoi(pVideoMeta.get());
727 r = ErrorMapToRetVal(retVal);
728 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
729 "[%s] metadata_extractor_get_metadata(framerate) failed.", GetErrorMessage(r));
733 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempVideoMeta);
734 if (pTempVideoMeta != null)
736 pVideoMeta.reset(pTempVideoMeta);
737 pMetadata->duration = atoi(pVideoMeta.get());
741 r = ErrorMapToRetVal(retVal);
742 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
743 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
747 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempVideoMeta);
748 if (pTempVideoMeta != null)
750 pVideoMeta.reset(pTempVideoMeta);
751 pMetadata->pGenre = new (nothrow) String(pVideoMeta.get()); //allocate memory
752 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
753 "[E_OUT_OF_MEMORY] The memory is insufficient.");
757 r = ErrorMapToRetVal(retVal);
758 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
759 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
763 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempVideoMeta);
764 if (pTempVideoMeta != null)
766 pVideoMeta.reset(pTempVideoMeta);
767 pMetadata->pComment = new (nothrow) String(pVideoMeta.get());
768 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
769 "[E_OUT_OF_MEMORY] The memory is insufficient.");
773 r = ErrorMapToRetVal(retVal);
774 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
775 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
779 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempVideoMeta);
780 if (pTempVideoMeta != null)
782 pVideoMeta.reset(pTempVideoMeta);
783 pMetadata->pDescription = new (nothrow) String(pVideoMeta.get());
784 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
785 "[E_OUT_OF_MEMORY] The memory is insufficient.");
789 r = ErrorMapToRetVal(retVal);
790 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
791 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
796 void* pTempArtwork = null;
797 unique_ptr<void, VoidDeleter> pArtwork(null);
799 // Get the artwork image in media file
800 retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempVideoMeta);
801 pVideoMeta.reset(pTempVideoMeta);
802 if (pTempArtwork != null)
804 pArtwork.reset(pTempArtwork);
807 ImageFormat format = IMG_FORMAT_NONE;
810 r = buffer.Construct(size);
811 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
813 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
819 format = img.GetImageFormat(buffer);
821 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
822 if (pMetadata->pAlbumArt == null)
824 // Because Album Art is one of the metadata, it is not exception in this function.
825 SysLog(NID_CNT, "DecodeN failed.");
833 r = ErrorMapToRetVal(retVal);
834 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
835 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
838 return pVideoMetadata.release();
842 _ContentManagerUtilImpl::GetImageMetaN(const ByteBuffer& byteBuffer)
846 int bufferLen = byteBuffer.GetRemaining();
847 SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
849 // create object here as it needs to be passed to client in any case to make sure Get APIs do not crash
850 unique_ptr<ImageMetadata> pImageMetadata(new (nothrow) ImageMetadata());
851 SysTryReturn(NID_CNT, pImageMetadata != null, null, E_OUT_OF_MEMORY,
852 "[E_OUT_OF_MEMORY] pImageMetadata is null.");
854 _ImageMetadataImpl* pImageMetaImpl = _ImageMetadataImpl::GetInstance(*(pImageMetadata.get()));
855 SysTryReturn(NID_CNT, pImageMetaImpl != null, null, E_OUT_OF_MEMORY,
856 "[E_OUT_OF_MEMORY] pImageMetaImpl is null.");
858 ImageMeta* pMetadata = pImageMetaImpl->GetImageMetadata();
859 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
860 "[E_INVALID_ARG] pMetadata is null.");
862 //assign by default here and overwrite below if width and height presents in EXIF data.
863 ImageFormat imgType = IMG_FORMAT_NONE;
867 result r = ImageBuffer::GetImageInfo(byteBuffer, imgType, imageWidth, imageHeight);
868 SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_INVALID_ARG,
869 "[E_INVALID_ARG] GetImageInfo failed.");
871 pMetadata->width = imageWidth;
872 pMetadata->height = imageHeight;
874 if (imgType == IMG_FORMAT_JPG)
876 const byte* pByte = byteBuffer.GetPointer();
878 unique_ptr<ExifData, ExifDataDeleter> pExifdata(exif_data_new_from_data(pByte, bufferLen));
879 if (pExifdata != null)
882 ExifByteOrder byteOrder;
883 ExifEntry** pEntries = null;
884 const char* pData = null;
885 char buf[_IMAGE_BUFF_LENGTH] = {0, };
886 char mmBuff[_IMAGE_BUFF_LENGTH] = {0, }; // to store minutes value of GPS data
887 char ssBuff[_IMAGE_BUFF_LENGTH] = {0, }; // to store seconds value of GPS data
888 ExifContent* pExifcont[EXIF_IFD_COUNT];
890 char latitudeRef = 0; // to store latitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
891 char longitudeRef = 0; // to store longitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
892 unsigned int entryCount = 0;
894 for (int i = 0; i < EXIF_IFD_COUNT; i++)
896 pExifcont[i] = pExifdata->ifd[i];
897 entryCount = pExifcont[i]->count;
898 pEntries = pExifcont[i]->entries;
899 for (unsigned int j = 0; j < entryCount; j++)
901 tag = pEntries[j]->tag;
902 pData = exif_entry_get_value(pEntries[j], buf, sizeof(buf));
903 SysTryReturn(NID_CNT, pData != null, pImageMetadata.release(), E_INVALID_ARG,
904 "[E_INVALID_ARG] exif_entry_get_value failed.");
906 if (tag == EXIF_TAG_PIXEL_X_DIMENSION)
908 pMetadata->width = atoi(buf);
910 else if (tag == EXIF_TAG_PIXEL_Y_DIMENSION)
912 pMetadata->height = atoi(buf);
914 else if (tag == EXIF_TAG_MAKE)
916 pMetadata->pManufacturer = new (nothrow) String(buf);
917 SysTryReturn(NID_CNT, pMetadata->pManufacturer != null, null, E_OUT_OF_MEMORY,
918 "[E_OUT_OF_MEMORY] The memory is insufficient.");
920 else if (tag == EXIF_TAG_MODEL)
922 pMetadata->pModel = new (nothrow) String(buf);
923 SysTryReturn(NID_CNT, pMetadata->pModel != null, null, E_OUT_OF_MEMORY,
924 "[E_OUT_OF_MEMORY] The memory is insufficient.");
926 else if (tag == EXIF_TAG_DATE_TIME)
928 pMetadata->pDateTime = new (nothrow) String(buf);
929 SysTryReturn(NID_CNT, pMetadata->pDateTime != null, null, E_OUT_OF_MEMORY,
930 "[E_OUT_OF_MEMORY] The memory is insufficient.");
932 else if (tag == EXIF_TAG_ORIENTATION)
934 //get the byte order(little endian or big endian) before extracting orientation type
935 byteOrder = exif_data_get_byte_order(pEntries[j]->parent->parent);
936 pMetadata->orientation = static_cast<ImageOrientationType>(exif_get_short(pEntries[j]->data, byteOrder));
938 else if (tag == EXIF_TAG_SOFTWARE)
940 pMetadata->pSoftware = new (nothrow) String(buf);
941 SysTryReturn(NID_CNT, pMetadata->pSoftware != null, null, E_OUT_OF_MEMORY,
942 "[E_OUT_OF_MEMORY] The memory is insufficient.");
944 else if (tag == EXIF_TAG_GPS_LATITUDE_REF)
946 latitudeRef = buf[0]; // GPS Latitude reference value will be 'N'(NORTH) or 'S'(SOUTH)
948 else if (tag == EXIF_TAG_GPS_LATITUDE)
950 String tempLatitude(buf);
953 StringTokenizer strTok(tempLatitude, delim);
954 String token[3] = {L"", };
957 while (strTok.HasMoreTokens())
959 strTok.GetNextToken(token[count++]);
962 double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value
964 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
966 double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value
968 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
970 double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value
972 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
974 pMetadata->latitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
976 // if latitude designation is Southern (SOUTH) then latitude degree will be negative DD
977 if (latitudeRef == 'S')
979 pMetadata->latitude = (pMetadata->latitude * (double)(-1));
982 else if (tag == EXIF_TAG_GPS_LONGITUDE_REF)
984 longitudeRef = buf[0]; // GPS Longitude reference value will be 'W'(WEST) or 'E'(EAST)
986 else if (tag == EXIF_TAG_GPS_LONGITUDE)
988 String tempLongitude(buf);
991 StringTokenizer strTok(tempLongitude, delim);
992 String token[3] = {L"", };
995 while (strTok.HasMoreTokens())
997 strTok.GetNextToken(token[count++]);
1000 double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value
1001 r = GetLastResult();
1002 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
1004 double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value
1005 r = GetLastResult();
1006 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
1008 double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value
1009 r = GetLastResult();
1010 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
1012 pMetadata->longitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
1014 // if longitude designation is Western (WEST) then longitude degree will be negative DD
1015 if (longitudeRef == 'W')
1017 pMetadata->longitude = (pMetadata->longitude * (double)(-1));
1020 else if (tag == EXIF_TAG_WHITE_BALANCE)
1022 pMetadata->pWhiteBalance = new (nothrow) String(buf);
1023 SysTryReturn(NID_CNT, pMetadata->pWhiteBalance != null, null, E_OUT_OF_MEMORY,
1024 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1031 return pImageMetadata.release();
1035 _ContentManagerUtilImpl::GetAudioMetaN(const ByteBuffer& byteBuffer)
1039 int bufferLen = byteBuffer.GetRemaining();
1040 SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
1042 // create here to make sure that get apis will not crash though the below API calls fails in case of invalid file.
1043 unique_ptr<AudioMetadata> pAudioMetadata(new (nothrow) AudioMetadata());
1044 SysTryReturn(NID_CNT, pAudioMetadata != null, null, E_OUT_OF_MEMORY,
1045 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1047 _AudioMetadataImpl* pAudioMetaImpl = _AudioMetadataImpl::GetInstance(*(pAudioMetadata.get()));
1048 SysTryReturn(NID_CNT, pAudioMetaImpl != null, null, E_OUT_OF_MEMORY,
1049 "[E_OUT_OF_MEMORY] pAudioMetaImpl is null.");
1051 AudioMeta* pMetadata = pAudioMetaImpl->GetAudioMetadata();
1052 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
1053 "[E_INVALID_ARG] pMetadata is null.");
1055 // Create the metadata extractor handle
1056 metadata_extractor_h tempExtractor = NULL;
1058 int retVal = metadata_extractor_create(&tempExtractor);
1059 result r = ErrorMapToRetVal(retVal);
1060 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1061 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1063 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
1064 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
1065 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1067 const byte* pByte = byteBuffer.GetPointer();
1069 retVal = metadata_extractor_set_buffer(pExtractor.get(), pByte, bufferLen);
1070 r = ErrorMapToRetVal(retVal);
1071 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1072 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1074 // Get all relavent audio metadata by passing relavent attirbutes
1075 char* pTempAudioMeta = null;
1076 unique_ptr<char, CharDeleter> pAudioMeta(null);
1079 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempAudioMeta);
1080 if (pTempAudioMeta != null)
1082 pAudioMeta.reset(pTempAudioMeta);
1083 pMetadata->bitrate = atoi(pAudioMeta.get());
1087 r = ErrorMapToRetVal(retVal);
1088 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1089 "[%s] metadata_extractor_get_metadata(bitrate) failed.", GetErrorMessage(r));
1093 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_CHANNELS, &pTempAudioMeta);
1094 if (pTempAudioMeta != null)
1096 pAudioMeta.reset(pTempAudioMeta);
1097 pMetadata->channelCount = atoi(pAudioMeta.get());
1101 r = ErrorMapToRetVal(retVal);
1102 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1103 "[%s] metadata_extractor_get_metadata(channels) failed.", GetErrorMessage(r));
1107 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempAudioMeta);
1108 if (pTempAudioMeta != null)
1110 pAudioMeta.reset(pTempAudioMeta);
1111 pMetadata->duration = atoi(pAudioMeta.get());
1115 r = ErrorMapToRetVal(retVal);
1116 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1117 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
1121 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_SAMPLERATE, &pTempAudioMeta);
1122 if (pTempAudioMeta != null)
1124 pAudioMeta.reset(pTempAudioMeta);
1125 pMetadata->frequency = atoi(pAudioMeta.get());
1129 r = ErrorMapToRetVal(retVal);
1130 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1131 "[%s] metadata_extractor_get_metadata(frequency) failed.", GetErrorMessage(r));
1135 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ALBUM, &pTempAudioMeta);
1136 if (pTempAudioMeta != null)
1138 pAudioMeta.reset(pTempAudioMeta);
1139 pMetadata->pAlbumName = new (nothrow) String(pAudioMeta.get());
1140 SysTryReturn(NID_CNT, pMetadata->pAlbumName != null, null, E_OUT_OF_MEMORY,
1141 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1145 r = ErrorMapToRetVal(retVal);
1146 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1147 "[%s] metadata_extractor_get_metadata(album name) failed.", GetErrorMessage(r));
1151 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ARTIST, &pTempAudioMeta);
1152 if (pAudioMeta.get() != null)
1154 pAudioMeta.reset(pTempAudioMeta);
1155 pMetadata->pArtist = new (nothrow) String(pAudioMeta.get());
1156 SysTryReturn(NID_CNT, pMetadata->pArtist != null, null, E_OUT_OF_MEMORY,
1157 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1161 r = ErrorMapToRetVal(retVal);
1162 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1163 "[%s] metadata_extractor_get_metadata(artist) failed.", GetErrorMessage(r));
1167 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COPYRIGHT, &pTempAudioMeta);
1168 if (pTempAudioMeta != null)
1170 pAudioMeta.reset(pTempAudioMeta);
1171 pMetadata->pCopyright = new (nothrow) String(pAudioMeta.get());
1172 SysTryReturn(NID_CNT, pMetadata->pCopyright != null, null, E_OUT_OF_MEMORY,
1173 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1177 r = ErrorMapToRetVal(retVal);
1178 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1179 "[%s] metadata_extractor_get_metadata(copyright) failed.", GetErrorMessage(r));
1183 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempAudioMeta);
1184 if (pTempAudioMeta != null)
1186 pAudioMeta.reset(pTempAudioMeta);
1187 pMetadata->pGenre = new (nothrow) String(pAudioMeta.get());
1188 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
1189 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1193 r = ErrorMapToRetVal(retVal);
1194 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1195 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
1199 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TITLE, &pTempAudioMeta);
1200 if (pTempAudioMeta != null)
1202 pAudioMeta.reset(pTempAudioMeta);
1203 pMetadata->pTitle = new (nothrow) String(pAudioMeta.get());
1204 SysTryReturn(NID_CNT, pMetadata->pTitle != null, null, E_OUT_OF_MEMORY,
1205 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1209 r = ErrorMapToRetVal(retVal);
1210 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1211 "[%s] metadata_extractor_get_metadata(title) failed.", GetErrorMessage(r));
1215 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempAudioMeta);
1216 if (pTempAudioMeta != null)
1218 pAudioMeta.reset(pTempAudioMeta);
1219 pMetadata->pComment = new (nothrow) String(pAudioMeta.get());
1220 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
1221 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1225 r = ErrorMapToRetVal(retVal);
1226 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1227 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
1231 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempAudioMeta);
1232 if (pTempAudioMeta != null)
1234 pAudioMeta.reset(pTempAudioMeta);
1235 pMetadata->pDescription = new (nothrow) String(pAudioMeta.get());
1236 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
1237 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1241 r = ErrorMapToRetVal(retVal);
1242 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1243 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
1247 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_RECDATE, &pTempAudioMeta);
1248 if (pTempAudioMeta != null)
1250 pAudioMeta.reset(pTempAudioMeta);
1251 pMetadata->pRecordingDate = new (nothrow) String(pAudioMeta.get());
1252 SysTryReturn(NID_CNT, pMetadata->pRecordingDate != null, null, E_OUT_OF_MEMORY,
1253 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1257 r = ErrorMapToRetVal(retVal);
1258 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1259 "[%s] metadata_extractor_get_metadata(recording date) failed.", GetErrorMessage(r));
1263 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUTHOR, &pTempAudioMeta);
1264 if (pTempAudioMeta != null)
1266 pAudioMeta.reset(pTempAudioMeta);
1267 pMetadata->pComposer = new (nothrow) String(pAudioMeta.get());
1268 SysTryReturn(NID_CNT, pMetadata->pComposer != null, null, E_OUT_OF_MEMORY,
1269 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1273 r = ErrorMapToRetVal(retVal);
1274 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1275 "[%s] metadata_extractor_get_metadata(author) failed.", GetErrorMessage(r));
1279 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TRACK_NUM, &pTempAudioMeta);
1280 if (pTempAudioMeta != null)
1282 pAudioMeta.reset(pTempAudioMeta);
1283 pMetadata->pTrackInfo = new (nothrow) String(pAudioMeta.get());
1284 SysTryReturn(NID_CNT, pMetadata->pTrackInfo != null, null, E_OUT_OF_MEMORY,
1285 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1287 // if the string contains the track info like track num/track position,
1288 // then track position will be ignored and only track num is returned
1289 // no need to parse this string, since only track number is required
1290 pMetadata->trackNum = atoi(pAudioMeta.get());
1294 r = ErrorMapToRetVal(retVal);
1295 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1296 "[%s] metadata_extractor_get_metadata(track info) failed.", GetErrorMessage(r));
1300 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DATE, &pTempAudioMeta);
1301 if (pTempAudioMeta != null)
1303 pAudioMeta.reset(pTempAudioMeta);
1304 pMetadata->year = atoi(pAudioMeta.get());
1308 r = ErrorMapToRetVal(retVal);
1309 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1310 "[%s] metadata_extractor_get_metadata(date) failed.", GetErrorMessage(r));
1315 void* pTempArtwork = null;
1316 unique_ptr<void, VoidDeleter> pArtwork(null);
1318 // Get the artwork image in media file
1319 retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempAudioMeta);
1320 pAudioMeta.reset(pTempAudioMeta);
1322 //Check if the albumart present and pass it to client if it is successfully processed, otherwise ignore any errors
1323 //while processing albumart. This is to pass the other metadata tags to application.
1324 if (pTempArtwork != null)
1326 pArtwork.reset(pTempArtwork);
1329 ImageFormat format = IMG_FORMAT_NONE;
1332 r = buffer.Construct(size);
1333 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
1335 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
1338 r = img.Construct();
1341 format = img.GetImageFormat(buffer);
1342 pMetadata->pThumbnail = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888,
1343 _THUMBNAIL_IMAGE_WIDTH, _THUMBNAIL_IMAGE_HEIGHT);
1344 if (pMetadata->pThumbnail == null)
1346 // Because Thumbnail is one of the metadata, it is not exception in this function.
1347 SysLog(NID_CNT, "DecodeN failed.");
1349 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
1350 if (pMetadata->pAlbumArt == null)
1352 // Because Album Art is one of the metadata, it is not exception in this function.
1353 SysLog(NID_CNT, "DecodeN failed.");
1361 r = ErrorMapToRetVal(retVal);
1362 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1363 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
1366 return pAudioMetadata.release();
1370 _ContentManagerUtilImpl::GetVideoMetaN(const ByteBuffer& byteBuffer)
1374 int bufferLen = byteBuffer.GetRemaining();
1375 SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
1377 // need to create here to make sure that all get APIs will not crash in case of corrupted file
1378 unique_ptr<VideoMetadata> pVideoMetadata(new (nothrow) VideoMetadata());
1379 SysTryReturn(NID_CNT, pVideoMetadata != null, null, E_OUT_OF_MEMORY,
1380 "[E_OUT_OF_MEMORY] The memory insufficient.");
1382 _VideoMetadataImpl* pVideoMetaImpl = _VideoMetadataImpl::GetInstance(*(pVideoMetadata.get()));
1383 SysTryReturn(NID_CNT, pVideoMetaImpl != null, null, E_OUT_OF_MEMORY,
1384 "[E_OUT_OF_MEMORY] pVideoMetaImpl is null.");
1386 VideoMeta* pMetadata = pVideoMetaImpl->GetVideoMetadata();
1387 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
1388 "[E_INVALID_ARG] pMetadata is null.");
1390 // Create the metadata extractor handle
1391 metadata_extractor_h tempExtractor = NULL;
1393 int retVal = metadata_extractor_create(&tempExtractor);
1394 result r = ErrorMapToRetVal(retVal);
1395 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1396 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1398 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
1399 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
1400 "[E_OUT_OF_MEMORY] The memory insufficient.");
1402 const byte* pByte = byteBuffer.GetPointer();
1404 retVal = metadata_extractor_set_buffer(pExtractor.get(), pByte, bufferLen);
1405 r = ErrorMapToRetVal(retVal);
1406 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1407 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1409 // Get all relavent video metadata by passing relavent attirbutes
1410 char* pTempVideoMeta = null;
1411 unique_ptr<char, CharDeleter> pVideoMeta(null);
1414 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_WIDTH, &pTempVideoMeta);
1415 if (pTempVideoMeta != null)
1417 pVideoMeta.reset(pTempVideoMeta);
1418 pMetadata->width = atoi(pVideoMeta.get());
1422 r = ErrorMapToRetVal(retVal);
1423 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1424 "[%s] metadata_extractor_get_metadata(width) failed.", GetErrorMessage(r));
1428 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_HEIGHT, &pTempVideoMeta);
1429 if (pTempVideoMeta != null)
1431 pVideoMeta.reset(pTempVideoMeta);
1432 pMetadata->height = atoi(pVideoMeta.get());
1436 r = ErrorMapToRetVal(retVal);
1437 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1438 "[%s] metadata_extractor_get_metadata(height) failed.", GetErrorMessage(r));
1442 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_BITRATE, &pTempVideoMeta);
1443 if (pTempVideoMeta != null)
1445 pVideoMeta.reset(pTempVideoMeta);
1446 pMetadata->videoBitrate = atoi(pVideoMeta.get());
1450 r = ErrorMapToRetVal(retVal);
1451 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1452 "[%s] metadata_extractor_get_metadata(video bitrate) failed.", GetErrorMessage(r));
1456 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempVideoMeta);
1457 if (pTempVideoMeta != null)
1459 pVideoMeta.reset(pTempVideoMeta);
1460 pMetadata->audioBitrate = atoi(pVideoMeta.get());
1464 r = ErrorMapToRetVal(retVal);
1465 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1466 "[%s] metadata_extractor_get_metadata(audio bitrate) failed.", GetErrorMessage(r));
1470 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_FPS, &pTempVideoMeta);
1471 if (pTempVideoMeta != null)
1473 pVideoMeta.reset(pTempVideoMeta);
1474 pMetadata->framerate = atoi(pVideoMeta.get());
1478 r = ErrorMapToRetVal(retVal);
1479 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1480 "[%s] metadata_extractor_get_metadata(framerate) failed.", GetErrorMessage(r));
1484 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempVideoMeta);
1485 if (pTempVideoMeta != null)
1487 pVideoMeta.reset(pTempVideoMeta);
1488 pMetadata->duration = atoi(pVideoMeta.get());
1492 r = ErrorMapToRetVal(retVal);
1493 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1494 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
1498 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempVideoMeta);
1499 if (pTempVideoMeta != null)
1501 pVideoMeta.reset(pTempVideoMeta);
1502 pMetadata->pGenre = new (nothrow) String(pVideoMeta.get()); //allocate memory
1503 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
1504 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1508 r = ErrorMapToRetVal(retVal);
1509 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1510 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
1514 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempVideoMeta);
1515 if (pTempVideoMeta != null)
1517 pVideoMeta.reset(pTempVideoMeta);
1518 pMetadata->pComment = new (nothrow) String(pVideoMeta.get());
1519 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
1520 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1524 r = ErrorMapToRetVal(retVal);
1525 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1526 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
1530 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempVideoMeta);
1531 if (pTempVideoMeta != null)
1533 pVideoMeta.reset(pTempVideoMeta);
1534 pMetadata->pDescription = new (nothrow) String(pVideoMeta.get());
1535 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
1536 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1540 r = ErrorMapToRetVal(retVal);
1541 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1542 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
1547 void* pTempArtwork = null;
1548 unique_ptr<void, VoidDeleter> pArtwork(null);
1550 // Get the artwork image in media file
1551 retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempVideoMeta);
1552 pVideoMeta.reset(pTempVideoMeta);
1553 if (pTempArtwork != null)
1555 pArtwork.reset(pTempArtwork);
1558 ImageFormat format = IMG_FORMAT_NONE;
1561 r = buffer.Construct(size);
1562 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
1564 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
1567 r = img.Construct();
1570 format = img.GetImageFormat(buffer);
1572 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
1573 if (pMetadata->pAlbumArt == null)
1575 // Because Album Art is one of the metadata, it is not exception in this function.
1576 SysLog(NID_CNT, "DecodeN failed.");
1584 r = ErrorMapToRetVal(retVal);
1585 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1586 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
1589 return pVideoMetadata.release();
1593 _ContentManagerUtilImpl::CheckContentType(const String& contentPath, bool internal)
1597 ContentType contentType = CONTENT_TYPE_UNKNOWN;
1601 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), contentType, E_INVALID_ARG,
1602 "[E_INVALID_ARG] The path is not compatible.");
1604 SysTryReturn(NID_CNT, contentPath.GetLength() != 0, contentType, E_INVALID_ARG,
1605 "[E_INVALID_ARG] The length of contentPath is 0.");
1606 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), contentType, E_FILE_NOT_FOUND,
1607 "[E_FILE_NOT_FOUND] The file corresponding to contentPath could not be found.");
1609 String fileExt = _FileImpl::GetFileExtension(contentPath);
1610 result r = GetLastResult();
1611 SysTryReturn(NID_CNT, !IsFailed(r), contentType, r, "[%s] GetFileExtension failed.", GetErrorMessage(r));
1613 unique_ptr<char[]> pFormat(_StringConverter::CopyToCharArrayN(fileExt));
1614 SysTryReturn(NID_CNT, pFormat != null, contentType, E_OUT_OF_MEMORY,
1615 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1617 char* pTempMimeType = null;
1618 int retVal = mime_type_get_mime_type(pFormat.get(), &pTempMimeType);
1619 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, E_INVALID_ARG,
1620 "[E_INVALID_ARG] mime_type_get_mime_type failed.");
1621 SysTryReturn(NID_CNT, pTempMimeType != null, contentType, E_INVALID_ARG,
1622 "[E_INVALID_ARG] mime_type_get_mime_type failed.");
1624 unique_ptr<char, CharDeleter> pMimeType;
1625 pMimeType.reset(pTempMimeType);
1627 SysLog(NID_CNT, "The MIME type for %ls is %s", fileExt.GetPointer(), pTempMimeType);
1629 String mimeType(pMimeType.get());
1631 if (mimeType.Contains(L"image"))
1633 return CONTENT_TYPE_IMAGE;
1635 else if (mimeType.Contains(L"audio"))
1637 if (mimeType.Contains(L"x-mpegurl"))
1639 SysLog(NID_CNT, "The type of x-mpegurl is other.");
1640 return CONTENT_TYPE_OTHER;
1642 return CONTENT_TYPE_AUDIO;
1644 else if (mimeType.Contains(L"video"))
1647 fileExt.ToLowerCase(format);
1649 if (format == L"3gp" || format == L"mp4")
1651 return CheckStream(contentPath);
1653 return CONTENT_TYPE_VIDEO;
1655 else if (mimeType.Contains(L"application"))
1657 if (mimeType.Contains(L"x-smaf"))
1659 SysLog(NID_CNT, "The type of x-smaf is audio.");
1660 return CONTENT_TYPE_AUDIO;
1662 return CONTENT_TYPE_OTHER;
1665 return CONTENT_TYPE_OTHER;
1669 _ContentManagerUtilImpl::CheckStream(const String& contentPath)
1673 ContentType contentType = CONTENT_TYPE_UNKNOWN;
1674 metadata_extractor_h tempExtractor = NULL;
1676 int retVal = metadata_extractor_create(&tempExtractor);
1677 result r = ErrorMapToRetVal(retVal);
1678 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
1679 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1681 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
1682 SysTryReturn(NID_CNT, pExtractor != null, contentType, E_OUT_OF_MEMORY,
1683 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1685 //Set the file path to extract metadata.
1686 unique_ptr<char[]> pContentPath(_StringConverter::CopyToCharArrayN(contentPath));
1687 SysTryReturn(NID_CNT, pContentPath != null, contentType, E_INVALID_ARG,
1688 "[E_INVALID_ARG] The memory is insufficient.");
1690 retVal = metadata_extractor_set_path(pExtractor.get(), pContentPath.get());
1691 r = ErrorMapToRetVal(retVal);
1692 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE && pExtractor, contentType, r,
1693 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1695 //Check whether it is an audio or video file.
1696 char* pTempAudio = null;
1697 unique_ptr<char, CharDeleter> pAudio(null);
1699 char* pTempVideo = null;
1700 unique_ptr<char, CharDeleter> pVideo(null);
1702 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_HAS_AUDIO, &pTempAudio);
1703 if (pTempAudio != null)
1705 pAudio.reset(pTempAudio);
1709 r = ErrorMapToRetVal(retVal);
1710 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
1711 "[%s] metadata_extractor_get_metadata failed.", GetErrorMessage(r));
1714 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_HAS_VIDEO, &pTempVideo);
1715 if (pTempVideo != null)
1717 pVideo.reset(pTempVideo);
1721 r = ErrorMapToRetVal(retVal);
1722 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
1723 "[%s] metadata_extractor_get_metadata failed.", GetErrorMessage(r));
1726 if (*(pAudio.get()) > '0' && *(pVideo.get()) == '0')
1728 SysLog(NID_CNT, "The result of CheckStream() is audio");
1729 return CONTENT_TYPE_AUDIO;
1731 else if (*(pAudio.get()) == '0' && *(pVideo.get()) > '0')
1733 SysLog(NID_CNT, "The result of CheckStream() is video");
1734 return CONTENT_TYPE_VIDEO;
1736 else if (*(pAudio.get()) > '0' && *(pVideo.get()) > '0')
1738 SysLog(NID_CNT, "The result of CheckStream() is video");
1739 return CONTENT_TYPE_VIDEO;
1743 SysLogException(NID_CNT, E_UNSUPPORTED_FORMAT, "[E_UNSUPPORTED_FORMAT] The stream is empty.");
1750 _ContentManagerUtilImpl::VerifyFilePathCompatibility(const String& contentPath)
1752 if (!_AppInfo::IsOspCompat())
1754 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0)
1755 || contentPath.StartsWith(OSP_HOME, 0))
1757 SysLogException(NID_CNT, E_INVALID_ARG,
1758 "/Home, /Media/, or /Storagecard/Media/ is not supported from Tizen 2.0.");
1765 if (!(contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0)
1766 || contentPath.StartsWith(OSP_HOME, 0)))
1768 SysLogException(NID_CNT, E_INVALID_ARG,
1769 "The contentPath should start with /Home, /Media, or /Storagecard/Media.");
1778 _ContentManagerUtilImpl::ErrorMapToRetVal(int retVal)
1780 result r = E_SUCCESS;
1784 case METADATA_EXTRACTOR_ERROR_NONE:
1787 case METADATA_EXTRACTOR_ERROR_INVALID_PARAMETER:
1790 case METADATA_EXTRACTOR_ERROR_OUT_OF_MEMORY:
1791 r = E_OUT_OF_MEMORY;
1793 case METADATA_EXTRACTOR_ERROR_FILE_EXISTS:
1796 case METADATA_EXTRACTOR_ERROR_OPERATION_FAILED:
1805 _ContentManagerUtilImpl::CopyToMediaDirectory(const String& srcContentPath, const String& destContentPath)
1809 // For srcContentPath
1810 SysTryReturn(NID_CNT, !_FileImpl::IsSystemPath(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1811 "[E_INVALID_ARG] Can not copy the file in the system region.");
1812 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1813 "[E_INVALID_ARG] Can not find the file.");
1815 // For destContentPath
1816 SysTryReturn(NID_CNT, _FileImpl::IsMediaPath(destContentPath), E_INVALID_ARG, E_INVALID_ARG,
1817 "[E_INVALID_ARG] The destination path should start with /Media or /Storagecard/Media.");
1819 // E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_FILE_NOT_FOUND, E_FILE_ALREADY_EXIST, E_MAX_EXCEEDED, E_STORAGE_FULL, E_IO
1820 result r = E_SUCCESS;
1821 r = _FileImpl::Copy(srcContentPath, destContentPath, true);
1822 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] CopyToMediaDirectory failed.", GetErrorMessage(r));
1828 _ContentManagerUtilImpl::MoveToMediaDirectory(const String& srcContentPath, const String& destContentPath)
1832 // For srcContentPath
1833 SysTryReturn(NID_CNT, !_FileImpl::IsSystemPath(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1834 "[E_INVALID_ARG] Can not copy the file in the system region.");
1835 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1836 "[E_INVALID_ARG] Can not find the file.");
1838 // For destContentPath
1839 SysTryReturn(NID_CNT, _FileImpl::IsMediaPath(destContentPath), E_INVALID_ARG, E_INVALID_ARG,
1840 "[E_INVALID_ARG] The destination path should start with /Media or /Storagecard/Media.");
1842 // E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_FILE_NOT_FOUND, E_FILE_ALREADY_EXIST, E_MAX_EXCEEDED, E_STORAGE_FULL, E_IO
1843 result r = E_SUCCESS;
1844 r = _FileImpl::Move(srcContentPath, destContentPath);
1845 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] MoveToMediaDirectory failed.", GetErrorMessage(r));