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;
71 _ContentManagerUtilImpl::GetImageMetaN(const String& contentPath, bool internal)
77 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), null, E_INVALID_ARG,
78 "[E_INVALID_ARG] The path is not compatible.");
80 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_INVALID_ARG,
81 "[E_INVALID_ARG] The file corresponding to contentPath could not be found.");
83 // create object here as it needs to be passed to client in any case to make sure Get APIs do not crash
84 unique_ptr<ImageMetadata> pImageMetadata(new (nothrow) ImageMetadata());
85 SysTryReturn(NID_CNT, pImageMetadata != null, null, E_OUT_OF_MEMORY,
86 "[E_OUT_OF_MEMORY] pImageMetadata is null.");
88 _ImageMetadataImpl* pImageMetaImpl = _ImageMetadataImpl::GetInstance(*(pImageMetadata.get()));
89 SysTryReturn(NID_CNT, pImageMetaImpl != null, null, E_OUT_OF_MEMORY,
90 "[E_OUT_OF_MEMORY] pImageMetaImpl is null.");
92 ImageMeta* pMetadata = pImageMetaImpl->GetImageMetadata();
93 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
94 "[E_INVALID_ARG] pMetadata is null.");
96 //assign by default here and overwrite below if width and height presents in EXIF data.
97 ImageFormat imgType = IMG_FORMAT_NONE;
100 result r = _ImageImpl::GetImageInfo(contentPath, imgType, dim);
101 SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_INVALID_ARG,
102 "[E_INVALID_ARG] GetImageInfo failed.");
104 pMetadata->width = dim.width;
105 pMetadata->height = dim.height;
106 pMetadata->contentPath = contentPath;
108 if (imgType == IMG_FORMAT_JPG)
110 unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(contentPath));
111 SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
112 "[E_OUT_OF_MEMORY] The memory is insufficient.");
114 unique_ptr<ExifData, ExifDataDeleter> pExifdata(exif_data_new_from_file(pFileName.get()));
115 if (pExifdata != null)
118 ExifByteOrder byteOrder;
119 ExifEntry** pEntries = null;
120 const char* pData = null;
121 char buf[_IMAGE_BUFF_LENGTH] = {0, };
122 ExifContent* pExifcont[EXIF_IFD_COUNT];
123 char latitudeRef = 0; // to store latitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
124 char longitudeRef = 0; // to store longitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
125 unsigned int entryCount = 0;
127 for (int i = 0; i < EXIF_IFD_COUNT; i++)
129 pExifcont[i] = pExifdata->ifd[i];
130 entryCount = pExifcont[i]->count;
131 pEntries = pExifcont[i]->entries;
132 for (unsigned int j = 0; j < entryCount; j++)
134 tag = pEntries[j]->tag;
135 pData = exif_entry_get_value(pEntries[j], buf, sizeof(buf));
136 SysTryReturn(NID_CNT, pData != null, pImageMetadata.release(), E_INVALID_ARG,
137 "[E_INVALID_ARG] exif_entry_get_value failed.");
139 if (tag == EXIF_TAG_PIXEL_X_DIMENSION)
141 pMetadata->width = atoi(buf);
143 else if (tag == EXIF_TAG_PIXEL_Y_DIMENSION)
145 pMetadata->height = atoi(buf);
147 else if (tag == EXIF_TAG_MAKE)
149 pMetadata->pManufacturer = new (nothrow) String(buf);
150 SysTryReturn(NID_CNT, pMetadata->pManufacturer != null, null, E_OUT_OF_MEMORY,
151 "[E_OUT_OF_MEMORY] The memory is insufficient.");
153 else if (tag == EXIF_TAG_MODEL)
155 pMetadata->pModel = new (nothrow) String(buf);
156 SysTryReturn(NID_CNT, pMetadata->pModel != null, null, E_OUT_OF_MEMORY,
157 "[E_OUT_OF_MEMORY] The memory is insufficient.");
159 else if (tag == EXIF_TAG_DATE_TIME)
161 pMetadata->pDateTime = new (nothrow) String(buf);
162 SysTryReturn(NID_CNT, pMetadata->pDateTime != null, null, E_OUT_OF_MEMORY,
163 "[E_OUT_OF_MEMORY] The memory is insufficient.");
165 else if (tag == EXIF_TAG_ORIENTATION)
167 //get the byte order(little endian or big endian) before extracting orientation type
168 byteOrder = exif_data_get_byte_order(pEntries[j]->parent->parent);
169 pMetadata->orientation = static_cast<ImageOrientationType>(exif_get_short(pEntries[j]->data, byteOrder));
171 else if (tag == EXIF_TAG_SOFTWARE)
173 pMetadata->pSoftware = new (nothrow) String(buf);
174 SysTryReturn(NID_CNT, pMetadata->pSoftware != null, null, E_OUT_OF_MEMORY,
175 "[E_OUT_OF_MEMORY] The memory is insufficient.");
177 else if (tag == EXIF_TAG_GPS_LATITUDE_REF)
179 latitudeRef = buf[0]; // GPS Latitude reference value will be 'N'(NORTH) or 'S'(SOUTH)
181 else if (tag == EXIF_TAG_GPS_LATITUDE)
183 String tempLatitude(buf);
186 StringTokenizer strTok(tempLatitude, delim);
187 String token[3] = {L"", };
190 while (strTok.HasMoreTokens() && count < 3)
192 strTok.GetNextToken(token[count++]);
195 double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value
197 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
199 double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value
201 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
203 double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value
205 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
207 pMetadata->latitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
209 // if latitude designation is Southern (SOUTH) then latitude degree will be negative DD
210 if (latitudeRef == 'S')
212 pMetadata->latitude = (pMetadata->latitude * (double)(-1));
215 else if (tag == EXIF_TAG_GPS_LONGITUDE_REF)
217 longitudeRef = buf[0]; // GPS Longitude reference value will be 'W'(WEST) or 'E'(EAST)
219 else if (tag == EXIF_TAG_GPS_LONGITUDE)
221 String tempLongitude(buf);
224 StringTokenizer strTok(tempLongitude, delim);
225 String token[3] = {L"", };
228 while (strTok.HasMoreTokens() && count < 3)
230 strTok.GetNextToken(token[count++]);
233 double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value
235 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
237 double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value
239 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
241 double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value
243 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
245 pMetadata->longitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
247 // if longitude designation is Western (WEST) then longitude degree will be negative DD
248 if (longitudeRef == 'W')
250 pMetadata->longitude = (pMetadata->longitude * (double)(-1));
253 else if (tag == EXIF_TAG_WHITE_BALANCE)
255 pMetadata->pWhiteBalance = new (nothrow) String(buf);
256 SysTryReturn(NID_CNT, pMetadata->pWhiteBalance != null, null, E_OUT_OF_MEMORY,
257 "[E_OUT_OF_MEMORY] The memory is insufficient.");
264 return pImageMetadata.release();
268 _ContentManagerUtilImpl::GetAudioMetaN(const String& contentPath)
272 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), null, E_INVALID_ARG,
273 "[E_INVALID_ARG] The path is not compatible.");
274 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_INVALID_ARG,
275 "[E_INVALID_ARG] The file corresponding to contentPath could not be found.");
277 // create here to make sure that get apis will not crash though the below API calls fails in case of invalid file.
278 unique_ptr<AudioMetadata> pAudioMetadata(new (nothrow) AudioMetadata());
279 SysTryReturn(NID_CNT, pAudioMetadata != null, null, E_OUT_OF_MEMORY,
280 "[E_OUT_OF_MEMORY] The memory is insufficient.");
282 _AudioMetadataImpl* pAudioMetaImpl = _AudioMetadataImpl::GetInstance(*(pAudioMetadata.get()));
283 SysTryReturn(NID_CNT, pAudioMetaImpl != null, null, E_OUT_OF_MEMORY,
284 "[E_OUT_OF_MEMORY] pAudioMetaImpl is null.");
286 AudioMeta* pMetadata = pAudioMetaImpl->GetAudioMetadata();
287 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
288 "[E_INVALID_ARG] pMetadata is null.");
290 pMetadata->contentPath = contentPath;
292 // Create the metadata extractor handle
293 metadata_extractor_h tempExtractor = NULL;
295 int retVal = metadata_extractor_create(&tempExtractor);
296 result r = ErrorMapToRetVal(retVal);
297 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
298 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
300 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
301 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
302 "[E_OUT_OF_MEMORY] The memory is insufficient.");
304 // Set file path of content to extract the metadata
305 unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(contentPath));
306 SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
307 "[E_OUT_OF_MEMORY] The memory is insufficient.");
309 retVal = metadata_extractor_set_path(pExtractor.get(), pFileName.get());
310 r = ErrorMapToRetVal(retVal);
311 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
312 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
314 // Get all relavent audio metadata by passing relavent attirbutes
315 char* pTempAudioMeta = null;
316 unique_ptr<char, CharDeleter> pAudioMeta(null);
319 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempAudioMeta);
320 if (pTempAudioMeta != null)
322 pAudioMeta.reset(pTempAudioMeta);
323 pMetadata->bitrate = atoi(pAudioMeta.get());
327 r = ErrorMapToRetVal(retVal);
328 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
329 "[%s] metadata_extractor_get_metadata(bitrate) failed.", GetErrorMessage(r));
333 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_CHANNELS, &pTempAudioMeta);
334 if (pTempAudioMeta != null)
336 pAudioMeta.reset(pTempAudioMeta);
337 pMetadata->channelCount = atoi(pAudioMeta.get());
341 r = ErrorMapToRetVal(retVal);
342 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
343 "[%s] metadata_extractor_get_metadata(channels) failed.", GetErrorMessage(r));
347 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempAudioMeta);
348 if (pTempAudioMeta != null)
350 pAudioMeta.reset(pTempAudioMeta);
351 pMetadata->duration = atoi(pAudioMeta.get());
355 r = ErrorMapToRetVal(retVal);
356 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
357 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
361 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_SAMPLERATE, &pTempAudioMeta);
362 if (pTempAudioMeta != null)
364 pAudioMeta.reset(pTempAudioMeta);
365 pMetadata->frequency = atoi(pAudioMeta.get());
369 r = ErrorMapToRetVal(retVal);
370 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
371 "[%s] metadata_extractor_get_metadata(frequency) failed.", GetErrorMessage(r));
375 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ALBUM, &pTempAudioMeta);
376 if (pTempAudioMeta != null)
378 pAudioMeta.reset(pTempAudioMeta);
379 pMetadata->pAlbumName = new (nothrow) String(pAudioMeta.get());
380 SysTryReturn(NID_CNT, pMetadata->pAlbumName != null, null, E_OUT_OF_MEMORY,
381 "[E_OUT_OF_MEMORY] The memory is insufficient.");
385 r = ErrorMapToRetVal(retVal);
386 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
387 "[%s] metadata_extractor_get_metadata(album name) failed.", GetErrorMessage(r));
391 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ARTIST, &pTempAudioMeta);
392 if (pAudioMeta.get() != null)
394 pAudioMeta.reset(pTempAudioMeta);
395 pMetadata->pArtist = new (nothrow) String(pAudioMeta.get());
396 SysTryReturn(NID_CNT, pMetadata->pArtist != null, null, E_OUT_OF_MEMORY,
397 "[E_OUT_OF_MEMORY] The memory is insufficient.");
401 r = ErrorMapToRetVal(retVal);
402 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
403 "[%s] metadata_extractor_get_metadata(artist) failed.", GetErrorMessage(r));
407 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COPYRIGHT, &pTempAudioMeta);
408 if (pTempAudioMeta != null)
410 pAudioMeta.reset(pTempAudioMeta);
411 pMetadata->pCopyright = new (nothrow) String(pAudioMeta.get());
412 SysTryReturn(NID_CNT, pMetadata->pCopyright != null, null, E_OUT_OF_MEMORY,
413 "[E_OUT_OF_MEMORY] The memory is insufficient.");
417 r = ErrorMapToRetVal(retVal);
418 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
419 "[%s] metadata_extractor_get_metadata(copyright) failed.", GetErrorMessage(r));
423 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempAudioMeta);
424 if (pTempAudioMeta != null)
426 pAudioMeta.reset(pTempAudioMeta);
427 pMetadata->pGenre = new (nothrow) String(pAudioMeta.get());
428 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
429 "[E_OUT_OF_MEMORY] The memory is insufficient.");
433 r = ErrorMapToRetVal(retVal);
434 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
435 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
439 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TITLE, &pTempAudioMeta);
440 if (pTempAudioMeta != null)
442 pAudioMeta.reset(pTempAudioMeta);
443 pMetadata->pTitle = new (nothrow) String(pAudioMeta.get());
444 SysTryReturn(NID_CNT, pMetadata->pTitle != null, null, E_OUT_OF_MEMORY,
445 "[E_OUT_OF_MEMORY] The memory is insufficient.");
449 r = ErrorMapToRetVal(retVal);
450 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
451 "[%s] metadata_extractor_get_metadata(title) failed.", GetErrorMessage(r));
455 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempAudioMeta);
456 if (pTempAudioMeta != null)
458 pAudioMeta.reset(pTempAudioMeta);
459 pMetadata->pComment = new (nothrow) String(pAudioMeta.get());
460 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
461 "[E_OUT_OF_MEMORY] The memory is insufficient.");
465 r = ErrorMapToRetVal(retVal);
466 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
467 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
471 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempAudioMeta);
472 if (pTempAudioMeta != null)
474 pAudioMeta.reset(pTempAudioMeta);
475 pMetadata->pDescription = new (nothrow) String(pAudioMeta.get());
476 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
477 "[E_OUT_OF_MEMORY] The memory is insufficient.");
481 r = ErrorMapToRetVal(retVal);
482 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
483 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
487 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_RECDATE, &pTempAudioMeta);
488 if (pTempAudioMeta != null)
490 pAudioMeta.reset(pTempAudioMeta);
491 pMetadata->pRecordingDate = new (nothrow) String(pAudioMeta.get());
492 SysTryReturn(NID_CNT, pMetadata->pRecordingDate != null, null, E_OUT_OF_MEMORY,
493 "[E_OUT_OF_MEMORY] The memory is insufficient.");
497 r = ErrorMapToRetVal(retVal);
498 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
499 "[%s] metadata_extractor_get_metadata(recording date) failed.", GetErrorMessage(r));
503 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUTHOR, &pTempAudioMeta);
504 if (pTempAudioMeta != null)
506 pAudioMeta.reset(pTempAudioMeta);
507 pMetadata->pComposer = new (nothrow) String(pAudioMeta.get());
508 SysTryReturn(NID_CNT, pMetadata->pComposer != null, null, E_OUT_OF_MEMORY,
509 "[E_OUT_OF_MEMORY] The memory is insufficient.");
513 r = ErrorMapToRetVal(retVal);
514 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
515 "[%s] metadata_extractor_get_metadata(author) failed.", GetErrorMessage(r));
519 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TRACK_NUM, &pTempAudioMeta);
520 if (pTempAudioMeta != null)
522 pAudioMeta.reset(pTempAudioMeta);
523 pMetadata->pTrackInfo = new (nothrow) String(pAudioMeta.get());
524 SysTryReturn(NID_CNT, pMetadata->pTrackInfo != null, null, E_OUT_OF_MEMORY,
525 "[E_OUT_OF_MEMORY] The memory is insufficient.");
527 // if the string contains the track info like track num/track position,
528 // then track position will be ignored and only track num is returned
529 // no need to parse this string, since only track number is required
530 pMetadata->trackNum = atoi(pAudioMeta.get());
534 r = ErrorMapToRetVal(retVal);
535 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
536 "[%s] metadata_extractor_get_metadata(track info) failed.", GetErrorMessage(r));
540 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DATE, &pTempAudioMeta);
541 if (pTempAudioMeta != null)
543 pAudioMeta.reset(pTempAudioMeta);
544 pMetadata->year = atoi(pAudioMeta.get());
548 r = ErrorMapToRetVal(retVal);
549 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
550 "[%s] metadata_extractor_get_metadata(date) failed.", GetErrorMessage(r));
555 void* pTempArtwork = null;
556 unique_ptr<void, VoidDeleter> pArtwork(null);
558 // Get the artwork image in media file
559 retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempAudioMeta);
560 pAudioMeta.reset(pTempAudioMeta);
562 //Check if the albumart present and pass it to client if it is successfully processed, otherwise ignore any errors
563 //while processing albumart. This is to pass the other metadata tags to application.
564 if (pTempArtwork != null)
566 pArtwork.reset(pTempArtwork);
569 ImageFormat format = IMG_FORMAT_NONE;
572 r = buffer.Construct(size);
573 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
575 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
581 format = img.GetImageFormat(buffer);
582 pMetadata->pThumbnail = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888,
583 _THUMBNAIL_IMAGE_WIDTH, _THUMBNAIL_IMAGE_HEIGHT);
584 if (pMetadata->pThumbnail == null)
586 // Because Thumbnail is one of the metadata, it is not exception in this function.
587 SysLog(NID_CNT, "DecodeN failed.");
589 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
590 if (pMetadata->pAlbumArt == null)
592 // Because Album Art is one of the metadata, it is not exception in this function.
593 SysLog(NID_CNT, "DecodeN failed.");
601 r = ErrorMapToRetVal(retVal);
602 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
603 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
606 return pAudioMetadata.release();
610 _ContentManagerUtilImpl::GetVideoMetaN(const String& contentPath)
614 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), null, E_INVALID_ARG,
615 "[E_INVALID_ARG] The path is not compatible.");
616 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_INVALID_ARG,
617 "[E_INVALID_ARG] The file corresponding to contentPath could not be found.");
619 // need to create here to make sure that all get APIs will not crash in case of corrupted file
620 unique_ptr<VideoMetadata> pVideoMetadata(new (nothrow) VideoMetadata());
621 SysTryReturn(NID_CNT, pVideoMetadata != null, null, E_OUT_OF_MEMORY,
622 "[E_OUT_OF_MEMORY] The memory insufficient.");
624 _VideoMetadataImpl* pVideoMetaImpl = _VideoMetadataImpl::GetInstance(*(pVideoMetadata.get()));
625 SysTryReturn(NID_CNT, pVideoMetaImpl != null, null, E_OUT_OF_MEMORY,
626 "[E_OUT_OF_MEMORY] pVideoMetaImpl is null.");
628 VideoMeta* pMetadata = pVideoMetaImpl->GetVideoMetadata();
629 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
630 "[E_INVALID_ARG] pMetadata is null.");
632 pMetadata->contentPath = contentPath;
634 // Create the metadata extractor handle
635 metadata_extractor_h tempExtractor = NULL;
637 int retVal = metadata_extractor_create(&tempExtractor);
638 result r = ErrorMapToRetVal(retVal);
639 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
640 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
642 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
643 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
644 "[E_OUT_OF_MEMORY] The memory insufficient.");
646 // Set file path of content to extract the metadata
647 unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(contentPath));
648 SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
649 "[E_OUT_OF_MEMORY] The memory is insufficient.");
651 retVal = metadata_extractor_set_path(pExtractor.get(), pFileName.get());
652 r = ErrorMapToRetVal(retVal);
653 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
654 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
656 // Get all relavent video metadata by passing relavent attirbutes
657 char* pTempVideoMeta = null;
658 unique_ptr<char, CharDeleter> pVideoMeta(null);
661 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_WIDTH, &pTempVideoMeta);
662 if (pTempVideoMeta != null)
664 pVideoMeta.reset(pTempVideoMeta);
665 pMetadata->width = atoi(pVideoMeta.get());
669 r = ErrorMapToRetVal(retVal);
670 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
671 "[%s] metadata_extractor_get_metadata(width) failed.", GetErrorMessage(r));
675 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_HEIGHT, &pTempVideoMeta);
676 if (pTempVideoMeta != null)
678 pVideoMeta.reset(pTempVideoMeta);
679 pMetadata->height = atoi(pVideoMeta.get());
683 r = ErrorMapToRetVal(retVal);
684 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
685 "[%s] metadata_extractor_get_metadata(height) failed.", GetErrorMessage(r));
689 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_BITRATE, &pTempVideoMeta);
690 if (pTempVideoMeta != null)
692 pVideoMeta.reset(pTempVideoMeta);
693 pMetadata->videoBitrate = atoi(pVideoMeta.get());
697 r = ErrorMapToRetVal(retVal);
698 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
699 "[%s] metadata_extractor_get_metadata(video bitrate) failed.", GetErrorMessage(r));
703 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempVideoMeta);
704 if (pTempVideoMeta != null)
706 pVideoMeta.reset(pTempVideoMeta);
707 pMetadata->audioBitrate = atoi(pVideoMeta.get());
711 r = ErrorMapToRetVal(retVal);
712 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
713 "[%s] metadata_extractor_get_metadata(audio bitrate) failed.", GetErrorMessage(r));
717 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_FPS, &pTempVideoMeta);
718 if (pTempVideoMeta != null)
720 pVideoMeta.reset(pTempVideoMeta);
721 pMetadata->framerate = atoi(pVideoMeta.get());
725 r = ErrorMapToRetVal(retVal);
726 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
727 "[%s] metadata_extractor_get_metadata(framerate) failed.", GetErrorMessage(r));
731 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempVideoMeta);
732 if (pTempVideoMeta != null)
734 pVideoMeta.reset(pTempVideoMeta);
735 pMetadata->duration = atoi(pVideoMeta.get());
739 r = ErrorMapToRetVal(retVal);
740 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
741 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
745 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempVideoMeta);
746 if (pTempVideoMeta != null)
748 pVideoMeta.reset(pTempVideoMeta);
749 pMetadata->pGenre = new (nothrow) String(pVideoMeta.get()); //allocate memory
750 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
751 "[E_OUT_OF_MEMORY] The memory is insufficient.");
755 r = ErrorMapToRetVal(retVal);
756 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
757 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
761 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempVideoMeta);
762 if (pTempVideoMeta != null)
764 pVideoMeta.reset(pTempVideoMeta);
765 pMetadata->pComment = new (nothrow) String(pVideoMeta.get());
766 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
767 "[E_OUT_OF_MEMORY] The memory is insufficient.");
771 r = ErrorMapToRetVal(retVal);
772 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
773 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
777 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempVideoMeta);
778 if (pTempVideoMeta != null)
780 pVideoMeta.reset(pTempVideoMeta);
781 pMetadata->pDescription = new (nothrow) String(pVideoMeta.get());
782 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
783 "[E_OUT_OF_MEMORY] The memory is insufficient.");
787 r = ErrorMapToRetVal(retVal);
788 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
789 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
794 void* pTempArtwork = null;
795 unique_ptr<void, VoidDeleter> pArtwork(null);
797 // Get the artwork image in media file
798 retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempVideoMeta);
799 pVideoMeta.reset(pTempVideoMeta);
800 if (pTempArtwork != null)
802 pArtwork.reset(pTempArtwork);
805 ImageFormat format = IMG_FORMAT_NONE;
808 r = buffer.Construct(size);
809 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
811 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
817 format = img.GetImageFormat(buffer);
819 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
820 if (pMetadata->pAlbumArt == null)
822 // Because Album Art is one of the metadata, it is not exception in this function.
823 SysLog(NID_CNT, "DecodeN failed.");
831 r = ErrorMapToRetVal(retVal);
832 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
833 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
836 return pVideoMetadata.release();
840 _ContentManagerUtilImpl::GetImageMetaN(const ByteBuffer& byteBuffer)
844 int bufferLen = byteBuffer.GetRemaining();
845 SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
847 // create object here as it needs to be passed to client in any case to make sure Get APIs do not crash
848 unique_ptr<ImageMetadata> pImageMetadata(new (nothrow) ImageMetadata());
849 SysTryReturn(NID_CNT, pImageMetadata != null, null, E_OUT_OF_MEMORY,
850 "[E_OUT_OF_MEMORY] pImageMetadata is null.");
852 _ImageMetadataImpl* pImageMetaImpl = _ImageMetadataImpl::GetInstance(*(pImageMetadata.get()));
853 SysTryReturn(NID_CNT, pImageMetaImpl != null, null, E_OUT_OF_MEMORY,
854 "[E_OUT_OF_MEMORY] pImageMetaImpl is null.");
856 ImageMeta* pMetadata = pImageMetaImpl->GetImageMetadata();
857 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
858 "[E_INVALID_ARG] pMetadata is null.");
860 //assign by default here and overwrite below if width and height presents in EXIF data.
861 ImageFormat imgType = IMG_FORMAT_NONE;
865 result r = ImageBuffer::GetImageInfo(byteBuffer, imgType, imageWidth, imageHeight);
866 SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_INVALID_ARG,
867 "[E_INVALID_ARG] GetImageInfo failed.");
869 pMetadata->width = imageWidth;
870 pMetadata->height = imageHeight;
872 if (imgType == IMG_FORMAT_JPG)
874 const byte* pByte = byteBuffer.GetPointer();
876 unique_ptr<ExifData, ExifDataDeleter> pExifdata(exif_data_new_from_data(pByte, bufferLen));
877 if (pExifdata != null)
880 ExifByteOrder byteOrder;
881 ExifEntry** pEntries = null;
882 const char* pData = null;
883 char buf[_IMAGE_BUFF_LENGTH] = {0, };
884 ExifContent* pExifcont[EXIF_IFD_COUNT];
885 char latitudeRef = 0; // to store latitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
886 char longitudeRef = 0; // to store longitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
887 unsigned int entryCount = 0;
889 for (int i = 0; i < EXIF_IFD_COUNT; i++)
891 pExifcont[i] = pExifdata->ifd[i];
892 entryCount = pExifcont[i]->count;
893 pEntries = pExifcont[i]->entries;
894 for (unsigned int j = 0; j < entryCount; j++)
896 tag = pEntries[j]->tag;
897 pData = exif_entry_get_value(pEntries[j], buf, sizeof(buf));
898 SysTryReturn(NID_CNT, pData != null, pImageMetadata.release(), E_INVALID_ARG,
899 "[E_INVALID_ARG] exif_entry_get_value failed.");
901 if (tag == EXIF_TAG_PIXEL_X_DIMENSION)
903 pMetadata->width = atoi(buf);
905 else if (tag == EXIF_TAG_PIXEL_Y_DIMENSION)
907 pMetadata->height = atoi(buf);
909 else if (tag == EXIF_TAG_MAKE)
911 pMetadata->pManufacturer = new (nothrow) String(buf);
912 SysTryReturn(NID_CNT, pMetadata->pManufacturer != null, null, E_OUT_OF_MEMORY,
913 "[E_OUT_OF_MEMORY] The memory is insufficient.");
915 else if (tag == EXIF_TAG_MODEL)
917 pMetadata->pModel = new (nothrow) String(buf);
918 SysTryReturn(NID_CNT, pMetadata->pModel != null, null, E_OUT_OF_MEMORY,
919 "[E_OUT_OF_MEMORY] The memory is insufficient.");
921 else if (tag == EXIF_TAG_DATE_TIME)
923 pMetadata->pDateTime = new (nothrow) String(buf);
924 SysTryReturn(NID_CNT, pMetadata->pDateTime != null, null, E_OUT_OF_MEMORY,
925 "[E_OUT_OF_MEMORY] The memory is insufficient.");
927 else if (tag == EXIF_TAG_ORIENTATION)
929 //get the byte order(little endian or big endian) before extracting orientation type
930 byteOrder = exif_data_get_byte_order(pEntries[j]->parent->parent);
931 pMetadata->orientation = static_cast<ImageOrientationType>(exif_get_short(pEntries[j]->data, byteOrder));
933 else if (tag == EXIF_TAG_SOFTWARE)
935 pMetadata->pSoftware = new (nothrow) String(buf);
936 SysTryReturn(NID_CNT, pMetadata->pSoftware != null, null, E_OUT_OF_MEMORY,
937 "[E_OUT_OF_MEMORY] The memory is insufficient.");
939 else if (tag == EXIF_TAG_GPS_LATITUDE_REF)
941 latitudeRef = buf[0]; // GPS Latitude reference value will be 'N'(NORTH) or 'S'(SOUTH)
943 else if (tag == EXIF_TAG_GPS_LATITUDE)
945 String tempLatitude(buf);
948 StringTokenizer strTok(tempLatitude, delim);
949 String token[3] = {L"", };
952 while (strTok.HasMoreTokens() && count < 3)
954 strTok.GetNextToken(token[count++]);
957 double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value
959 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
961 double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value
963 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
965 double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value
967 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
969 pMetadata->latitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
971 // if latitude designation is Southern (SOUTH) then latitude degree will be negative DD
972 if (latitudeRef == 'S')
974 pMetadata->latitude = (pMetadata->latitude * (double)(-1));
977 else if (tag == EXIF_TAG_GPS_LONGITUDE_REF)
979 longitudeRef = buf[0]; // GPS Longitude reference value will be 'W'(WEST) or 'E'(EAST)
981 else if (tag == EXIF_TAG_GPS_LONGITUDE)
983 String tempLongitude(buf);
986 StringTokenizer strTok(tempLongitude, delim);
987 String token[3] = {L"", };
990 while (strTok.HasMoreTokens() && count < 3)
992 strTok.GetNextToken(token[count++]);
995 double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value
997 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
999 double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value
1000 r = GetLastResult();
1001 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
1003 double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value
1004 r = GetLastResult();
1005 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
1007 pMetadata->longitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
1009 // if longitude designation is Western (WEST) then longitude degree will be negative DD
1010 if (longitudeRef == 'W')
1012 pMetadata->longitude = (pMetadata->longitude * (double)(-1));
1015 else if (tag == EXIF_TAG_WHITE_BALANCE)
1017 pMetadata->pWhiteBalance = new (nothrow) String(buf);
1018 SysTryReturn(NID_CNT, pMetadata->pWhiteBalance != null, null, E_OUT_OF_MEMORY,
1019 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1026 return pImageMetadata.release();
1030 _ContentManagerUtilImpl::GetAudioMetaN(const ByteBuffer& byteBuffer)
1034 int bufferLen = byteBuffer.GetRemaining();
1035 SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
1037 // create here to make sure that get apis will not crash though the below API calls fails in case of invalid file.
1038 unique_ptr<AudioMetadata> pAudioMetadata(new (nothrow) AudioMetadata());
1039 SysTryReturn(NID_CNT, pAudioMetadata != null, null, E_OUT_OF_MEMORY,
1040 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1042 _AudioMetadataImpl* pAudioMetaImpl = _AudioMetadataImpl::GetInstance(*(pAudioMetadata.get()));
1043 SysTryReturn(NID_CNT, pAudioMetaImpl != null, null, E_OUT_OF_MEMORY,
1044 "[E_OUT_OF_MEMORY] pAudioMetaImpl is null.");
1046 AudioMeta* pMetadata = pAudioMetaImpl->GetAudioMetadata();
1047 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
1048 "[E_INVALID_ARG] pMetadata is null.");
1050 // Create the metadata extractor handle
1051 metadata_extractor_h tempExtractor = NULL;
1053 int retVal = metadata_extractor_create(&tempExtractor);
1054 result r = ErrorMapToRetVal(retVal);
1055 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1056 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1058 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
1059 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
1060 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1062 const byte* pByte = byteBuffer.GetPointer();
1064 retVal = metadata_extractor_set_buffer(pExtractor.get(), pByte, bufferLen);
1065 r = ErrorMapToRetVal(retVal);
1066 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1067 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1069 // Get all relavent audio metadata by passing relavent attirbutes
1070 char* pTempAudioMeta = null;
1071 unique_ptr<char, CharDeleter> pAudioMeta(null);
1074 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempAudioMeta);
1075 if (pTempAudioMeta != null)
1077 pAudioMeta.reset(pTempAudioMeta);
1078 pMetadata->bitrate = atoi(pAudioMeta.get());
1082 r = ErrorMapToRetVal(retVal);
1083 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1084 "[%s] metadata_extractor_get_metadata(bitrate) failed.", GetErrorMessage(r));
1088 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_CHANNELS, &pTempAudioMeta);
1089 if (pTempAudioMeta != null)
1091 pAudioMeta.reset(pTempAudioMeta);
1092 pMetadata->channelCount = atoi(pAudioMeta.get());
1096 r = ErrorMapToRetVal(retVal);
1097 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1098 "[%s] metadata_extractor_get_metadata(channels) failed.", GetErrorMessage(r));
1102 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempAudioMeta);
1103 if (pTempAudioMeta != null)
1105 pAudioMeta.reset(pTempAudioMeta);
1106 pMetadata->duration = atoi(pAudioMeta.get());
1110 r = ErrorMapToRetVal(retVal);
1111 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1112 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
1116 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_SAMPLERATE, &pTempAudioMeta);
1117 if (pTempAudioMeta != null)
1119 pAudioMeta.reset(pTempAudioMeta);
1120 pMetadata->frequency = atoi(pAudioMeta.get());
1124 r = ErrorMapToRetVal(retVal);
1125 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1126 "[%s] metadata_extractor_get_metadata(frequency) failed.", GetErrorMessage(r));
1130 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ALBUM, &pTempAudioMeta);
1131 if (pTempAudioMeta != null)
1133 pAudioMeta.reset(pTempAudioMeta);
1134 pMetadata->pAlbumName = new (nothrow) String(pAudioMeta.get());
1135 SysTryReturn(NID_CNT, pMetadata->pAlbumName != null, null, E_OUT_OF_MEMORY,
1136 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1140 r = ErrorMapToRetVal(retVal);
1141 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1142 "[%s] metadata_extractor_get_metadata(album name) failed.", GetErrorMessage(r));
1146 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ARTIST, &pTempAudioMeta);
1147 if (pAudioMeta.get() != null)
1149 pAudioMeta.reset(pTempAudioMeta);
1150 pMetadata->pArtist = new (nothrow) String(pAudioMeta.get());
1151 SysTryReturn(NID_CNT, pMetadata->pArtist != null, null, E_OUT_OF_MEMORY,
1152 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1156 r = ErrorMapToRetVal(retVal);
1157 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1158 "[%s] metadata_extractor_get_metadata(artist) failed.", GetErrorMessage(r));
1162 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COPYRIGHT, &pTempAudioMeta);
1163 if (pTempAudioMeta != null)
1165 pAudioMeta.reset(pTempAudioMeta);
1166 pMetadata->pCopyright = new (nothrow) String(pAudioMeta.get());
1167 SysTryReturn(NID_CNT, pMetadata->pCopyright != null, null, E_OUT_OF_MEMORY,
1168 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1172 r = ErrorMapToRetVal(retVal);
1173 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1174 "[%s] metadata_extractor_get_metadata(copyright) failed.", GetErrorMessage(r));
1178 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempAudioMeta);
1179 if (pTempAudioMeta != null)
1181 pAudioMeta.reset(pTempAudioMeta);
1182 pMetadata->pGenre = new (nothrow) String(pAudioMeta.get());
1183 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
1184 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1188 r = ErrorMapToRetVal(retVal);
1189 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1190 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
1194 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TITLE, &pTempAudioMeta);
1195 if (pTempAudioMeta != null)
1197 pAudioMeta.reset(pTempAudioMeta);
1198 pMetadata->pTitle = new (nothrow) String(pAudioMeta.get());
1199 SysTryReturn(NID_CNT, pMetadata->pTitle != null, null, E_OUT_OF_MEMORY,
1200 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1204 r = ErrorMapToRetVal(retVal);
1205 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1206 "[%s] metadata_extractor_get_metadata(title) failed.", GetErrorMessage(r));
1210 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempAudioMeta);
1211 if (pTempAudioMeta != null)
1213 pAudioMeta.reset(pTempAudioMeta);
1214 pMetadata->pComment = new (nothrow) String(pAudioMeta.get());
1215 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
1216 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1220 r = ErrorMapToRetVal(retVal);
1221 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1222 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
1226 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempAudioMeta);
1227 if (pTempAudioMeta != null)
1229 pAudioMeta.reset(pTempAudioMeta);
1230 pMetadata->pDescription = new (nothrow) String(pAudioMeta.get());
1231 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
1232 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1236 r = ErrorMapToRetVal(retVal);
1237 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1238 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
1242 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_RECDATE, &pTempAudioMeta);
1243 if (pTempAudioMeta != null)
1245 pAudioMeta.reset(pTempAudioMeta);
1246 pMetadata->pRecordingDate = new (nothrow) String(pAudioMeta.get());
1247 SysTryReturn(NID_CNT, pMetadata->pRecordingDate != null, null, E_OUT_OF_MEMORY,
1248 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1252 r = ErrorMapToRetVal(retVal);
1253 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1254 "[%s] metadata_extractor_get_metadata(recording date) failed.", GetErrorMessage(r));
1258 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUTHOR, &pTempAudioMeta);
1259 if (pTempAudioMeta != null)
1261 pAudioMeta.reset(pTempAudioMeta);
1262 pMetadata->pComposer = new (nothrow) String(pAudioMeta.get());
1263 SysTryReturn(NID_CNT, pMetadata->pComposer != null, null, E_OUT_OF_MEMORY,
1264 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1268 r = ErrorMapToRetVal(retVal);
1269 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1270 "[%s] metadata_extractor_get_metadata(author) failed.", GetErrorMessage(r));
1274 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TRACK_NUM, &pTempAudioMeta);
1275 if (pTempAudioMeta != null)
1277 pAudioMeta.reset(pTempAudioMeta);
1278 pMetadata->pTrackInfo = new (nothrow) String(pAudioMeta.get());
1279 SysTryReturn(NID_CNT, pMetadata->pTrackInfo != null, null, E_OUT_OF_MEMORY,
1280 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1282 // if the string contains the track info like track num/track position,
1283 // then track position will be ignored and only track num is returned
1284 // no need to parse this string, since only track number is required
1285 pMetadata->trackNum = atoi(pAudioMeta.get());
1289 r = ErrorMapToRetVal(retVal);
1290 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1291 "[%s] metadata_extractor_get_metadata(track info) failed.", GetErrorMessage(r));
1295 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DATE, &pTempAudioMeta);
1296 if (pTempAudioMeta != null)
1298 pAudioMeta.reset(pTempAudioMeta);
1299 pMetadata->year = atoi(pAudioMeta.get());
1303 r = ErrorMapToRetVal(retVal);
1304 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1305 "[%s] metadata_extractor_get_metadata(date) failed.", GetErrorMessage(r));
1310 void* pTempArtwork = null;
1311 unique_ptr<void, VoidDeleter> pArtwork(null);
1313 // Get the artwork image in media file
1314 retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempAudioMeta);
1315 pAudioMeta.reset(pTempAudioMeta);
1317 //Check if the albumart present and pass it to client if it is successfully processed, otherwise ignore any errors
1318 //while processing albumart. This is to pass the other metadata tags to application.
1319 if (pTempArtwork != null)
1321 pArtwork.reset(pTempArtwork);
1324 ImageFormat format = IMG_FORMAT_NONE;
1327 r = buffer.Construct(size);
1328 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
1330 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
1333 r = img.Construct();
1336 format = img.GetImageFormat(buffer);
1337 pMetadata->pThumbnail = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888,
1338 _THUMBNAIL_IMAGE_WIDTH, _THUMBNAIL_IMAGE_HEIGHT);
1339 if (pMetadata->pThumbnail == null)
1341 // Because Thumbnail is one of the metadata, it is not exception in this function.
1342 SysLog(NID_CNT, "DecodeN failed.");
1344 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
1345 if (pMetadata->pAlbumArt == null)
1347 // Because Album Art is one of the metadata, it is not exception in this function.
1348 SysLog(NID_CNT, "DecodeN failed.");
1356 r = ErrorMapToRetVal(retVal);
1357 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1358 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
1361 return pAudioMetadata.release();
1365 _ContentManagerUtilImpl::GetVideoMetaN(const ByteBuffer& byteBuffer)
1369 int bufferLen = byteBuffer.GetRemaining();
1370 SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
1372 // need to create here to make sure that all get APIs will not crash in case of corrupted file
1373 unique_ptr<VideoMetadata> pVideoMetadata(new (nothrow) VideoMetadata());
1374 SysTryReturn(NID_CNT, pVideoMetadata != null, null, E_OUT_OF_MEMORY,
1375 "[E_OUT_OF_MEMORY] The memory insufficient.");
1377 _VideoMetadataImpl* pVideoMetaImpl = _VideoMetadataImpl::GetInstance(*(pVideoMetadata.get()));
1378 SysTryReturn(NID_CNT, pVideoMetaImpl != null, null, E_OUT_OF_MEMORY,
1379 "[E_OUT_OF_MEMORY] pVideoMetaImpl is null.");
1381 VideoMeta* pMetadata = pVideoMetaImpl->GetVideoMetadata();
1382 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
1383 "[E_INVALID_ARG] pMetadata is null.");
1385 // Create the metadata extractor handle
1386 metadata_extractor_h tempExtractor = NULL;
1388 int retVal = metadata_extractor_create(&tempExtractor);
1389 result r = ErrorMapToRetVal(retVal);
1390 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1391 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1393 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
1394 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
1395 "[E_OUT_OF_MEMORY] The memory insufficient.");
1397 const byte* pByte = byteBuffer.GetPointer();
1399 retVal = metadata_extractor_set_buffer(pExtractor.get(), pByte, bufferLen);
1400 r = ErrorMapToRetVal(retVal);
1401 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1402 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1404 // Get all relavent video metadata by passing relavent attirbutes
1405 char* pTempVideoMeta = null;
1406 unique_ptr<char, CharDeleter> pVideoMeta(null);
1409 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_WIDTH, &pTempVideoMeta);
1410 if (pTempVideoMeta != null)
1412 pVideoMeta.reset(pTempVideoMeta);
1413 pMetadata->width = atoi(pVideoMeta.get());
1417 r = ErrorMapToRetVal(retVal);
1418 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1419 "[%s] metadata_extractor_get_metadata(width) failed.", GetErrorMessage(r));
1423 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_HEIGHT, &pTempVideoMeta);
1424 if (pTempVideoMeta != null)
1426 pVideoMeta.reset(pTempVideoMeta);
1427 pMetadata->height = atoi(pVideoMeta.get());
1431 r = ErrorMapToRetVal(retVal);
1432 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1433 "[%s] metadata_extractor_get_metadata(height) failed.", GetErrorMessage(r));
1437 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_BITRATE, &pTempVideoMeta);
1438 if (pTempVideoMeta != null)
1440 pVideoMeta.reset(pTempVideoMeta);
1441 pMetadata->videoBitrate = atoi(pVideoMeta.get());
1445 r = ErrorMapToRetVal(retVal);
1446 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1447 "[%s] metadata_extractor_get_metadata(video bitrate) failed.", GetErrorMessage(r));
1451 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempVideoMeta);
1452 if (pTempVideoMeta != null)
1454 pVideoMeta.reset(pTempVideoMeta);
1455 pMetadata->audioBitrate = atoi(pVideoMeta.get());
1459 r = ErrorMapToRetVal(retVal);
1460 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1461 "[%s] metadata_extractor_get_metadata(audio bitrate) failed.", GetErrorMessage(r));
1465 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_FPS, &pTempVideoMeta);
1466 if (pTempVideoMeta != null)
1468 pVideoMeta.reset(pTempVideoMeta);
1469 pMetadata->framerate = atoi(pVideoMeta.get());
1473 r = ErrorMapToRetVal(retVal);
1474 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1475 "[%s] metadata_extractor_get_metadata(framerate) failed.", GetErrorMessage(r));
1479 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempVideoMeta);
1480 if (pTempVideoMeta != null)
1482 pVideoMeta.reset(pTempVideoMeta);
1483 pMetadata->duration = atoi(pVideoMeta.get());
1487 r = ErrorMapToRetVal(retVal);
1488 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1489 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
1493 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempVideoMeta);
1494 if (pTempVideoMeta != null)
1496 pVideoMeta.reset(pTempVideoMeta);
1497 pMetadata->pGenre = new (nothrow) String(pVideoMeta.get()); //allocate memory
1498 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
1499 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1503 r = ErrorMapToRetVal(retVal);
1504 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1505 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
1509 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempVideoMeta);
1510 if (pTempVideoMeta != null)
1512 pVideoMeta.reset(pTempVideoMeta);
1513 pMetadata->pComment = new (nothrow) String(pVideoMeta.get());
1514 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
1515 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1519 r = ErrorMapToRetVal(retVal);
1520 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1521 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
1525 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempVideoMeta);
1526 if (pTempVideoMeta != null)
1528 pVideoMeta.reset(pTempVideoMeta);
1529 pMetadata->pDescription = new (nothrow) String(pVideoMeta.get());
1530 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
1531 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1535 r = ErrorMapToRetVal(retVal);
1536 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1537 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
1542 void* pTempArtwork = null;
1543 unique_ptr<void, VoidDeleter> pArtwork(null);
1545 // Get the artwork image in media file
1546 retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempVideoMeta);
1547 pVideoMeta.reset(pTempVideoMeta);
1548 if (pTempArtwork != null)
1550 pArtwork.reset(pTempArtwork);
1553 ImageFormat format = IMG_FORMAT_NONE;
1556 r = buffer.Construct(size);
1557 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
1559 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
1562 r = img.Construct();
1565 format = img.GetImageFormat(buffer);
1567 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
1568 if (pMetadata->pAlbumArt == null)
1570 // Because Album Art is one of the metadata, it is not exception in this function.
1571 SysLog(NID_CNT, "DecodeN failed.");
1579 r = ErrorMapToRetVal(retVal);
1580 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1581 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
1584 return pVideoMetadata.release();
1588 _ContentManagerUtilImpl::CheckContentType(const String& contentPath, bool internal)
1592 ContentType contentType = CONTENT_TYPE_UNKNOWN;
1593 String mimeType(L"");
1597 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), contentType, E_INVALID_ARG,
1598 "[E_INVALID_ARG] The path is not compatible.");
1600 SysTryReturn(NID_CNT, contentPath.GetLength() != 0, contentType, E_INVALID_ARG,
1601 "[E_INVALID_ARG] The length of contentPath is 0.");
1602 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), contentType, E_FILE_NOT_FOUND,
1603 "[E_FILE_NOT_FOUND] The file corresponding to contentPath could not be found.");
1605 String fileExt = _FileImpl::GetFileExtension(contentPath);
1606 result r = GetLastResult();
1610 unique_ptr<char[]> pFormat(_StringConverter::CopyToCharArrayN(fileExt));
1611 SysTryReturn(NID_CNT, pFormat != null, contentType, E_OUT_OF_MEMORY,
1612 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1614 char* pTempMimeType = null;
1615 int retVal = mime_type_get_mime_type(pFormat.get(), &pTempMimeType);
1616 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, E_INVALID_ARG,
1617 "[E_INVALID_ARG] mime_type_get_mime_type failed.");
1618 SysTryReturn(NID_CNT, pTempMimeType != null, contentType, E_INVALID_ARG,
1619 "[E_INVALID_ARG] mime_type_get_mime_type failed.");
1621 unique_ptr<char, CharDeleter> pMimeType;
1622 pMimeType.reset(pTempMimeType);
1624 SysLog(NID_CNT, "The MIME type for %ls is %s", fileExt.GetPointer(), pTempMimeType);
1626 r = mimeType.Append(pMimeType.get());
1627 SysTryReturn(NID_CNT, !IsFailed(r), contentType, E_OUT_OF_MEMORY,
1628 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1632 SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
1634 unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(contentPath));
1635 SysTryReturn(NID_CNT, pTempPath != null, contentType, E_OUT_OF_MEMORY,
1636 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1638 char tempType[255] = {0, };
1639 int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
1640 SysTryReturn(NID_CNT, ret == AUL_R_OK, contentType, E_INVALID_ARG,
1641 "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
1643 r = mimeType.Append(tempType);
1644 SysTryReturn(NID_CNT, !IsFailed(r), contentType, E_OUT_OF_MEMORY,
1645 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1648 if (mimeType.Contains(L"image"))
1650 return CONTENT_TYPE_IMAGE;
1652 else if (mimeType.Contains(L"audio"))
1654 if (mimeType.Contains(L"x-mpegurl"))
1656 SysLog(NID_CNT, "The type of x-mpegurl is other.");
1657 return CONTENT_TYPE_OTHER;
1659 return CONTENT_TYPE_AUDIO;
1661 else if (mimeType.Contains(L"video"))
1663 if (mimeType == L"video/3gpp" || mimeType == L"video/mp4")
1665 return CheckStream(contentPath);
1667 return CONTENT_TYPE_VIDEO;
1669 else if (mimeType.Contains(L"application"))
1671 if (mimeType.Contains(L"x-smaf"))
1673 SysLog(NID_CNT, "The type of x-smaf is audio.");
1674 return CONTENT_TYPE_AUDIO;
1676 return CONTENT_TYPE_OTHER;
1679 return CONTENT_TYPE_OTHER;
1683 _ContentManagerUtilImpl::CheckStream(const String& contentPath)
1687 ContentType contentType = CONTENT_TYPE_UNKNOWN;
1688 metadata_extractor_h tempExtractor = NULL;
1690 int retVal = metadata_extractor_create(&tempExtractor);
1691 result r = ErrorMapToRetVal(retVal);
1692 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
1693 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1695 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
1696 SysTryReturn(NID_CNT, pExtractor != null, contentType, E_OUT_OF_MEMORY,
1697 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1699 //Set the file path to extract metadata.
1700 unique_ptr<char[]> pContentPath(_StringConverter::CopyToCharArrayN(contentPath));
1701 SysTryReturn(NID_CNT, pContentPath != null, contentType, E_INVALID_ARG,
1702 "[E_INVALID_ARG] The memory is insufficient.");
1704 retVal = metadata_extractor_set_path(pExtractor.get(), pContentPath.get());
1705 r = ErrorMapToRetVal(retVal);
1706 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE && pExtractor, contentType, r,
1707 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1709 //Check whether it is an audio or video file.
1710 char* pTempAudio = null;
1711 unique_ptr<char, CharDeleter> pAudio(null);
1713 char* pTempVideo = null;
1714 unique_ptr<char, CharDeleter> pVideo(null);
1716 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_HAS_AUDIO, &pTempAudio);
1717 if (pTempAudio != null)
1719 pAudio.reset(pTempAudio);
1723 r = ErrorMapToRetVal(retVal);
1724 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
1725 "[%s] metadata_extractor_get_metadata failed.", GetErrorMessage(r));
1728 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_HAS_VIDEO, &pTempVideo);
1729 if (pTempVideo != null)
1731 pVideo.reset(pTempVideo);
1735 r = ErrorMapToRetVal(retVal);
1736 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
1737 "[%s] metadata_extractor_get_metadata failed.", GetErrorMessage(r));
1740 if (*(pAudio.get()) > '0' && *(pVideo.get()) == '0')
1742 SysLog(NID_CNT, "The result of CheckStream() is audio");
1743 return CONTENT_TYPE_AUDIO;
1745 else if (*(pAudio.get()) == '0' && *(pVideo.get()) > '0')
1747 SysLog(NID_CNT, "The result of CheckStream() is video");
1748 return CONTENT_TYPE_VIDEO;
1750 else if (*(pAudio.get()) > '0' && *(pVideo.get()) > '0')
1752 SysLog(NID_CNT, "The result of CheckStream() is video");
1753 return CONTENT_TYPE_VIDEO;
1757 SysLogException(NID_CNT, E_UNSUPPORTED_FORMAT, "[E_UNSUPPORTED_FORMAT] The stream is empty.");
1764 _ContentManagerUtilImpl::VerifyFilePathCompatibility(const String& contentPath)
1766 if (!_AppInfo::IsOspCompat())
1768 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0)
1769 || contentPath.StartsWith(OSP_HOME, 0))
1771 SysLogException(NID_CNT, E_INVALID_ARG,
1772 "/Home, /Media/, or /Storagecard/Media/ is not supported from Tizen 2.0.");
1779 if (!(contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0)
1780 || contentPath.StartsWith(OSP_HOME, 0)))
1782 SysLogException(NID_CNT, E_INVALID_ARG,
1783 "The contentPath should start with /Home, /Media, or /Storagecard/Media.");
1792 _ContentManagerUtilImpl::ErrorMapToRetVal(int retVal)
1794 result r = E_SUCCESS;
1798 case METADATA_EXTRACTOR_ERROR_NONE:
1801 case METADATA_EXTRACTOR_ERROR_INVALID_PARAMETER:
1804 case METADATA_EXTRACTOR_ERROR_OUT_OF_MEMORY:
1805 r = E_OUT_OF_MEMORY;
1807 case METADATA_EXTRACTOR_ERROR_FILE_EXISTS:
1810 case METADATA_EXTRACTOR_ERROR_OPERATION_FAILED:
1819 _ContentManagerUtilImpl::CopyToMediaDirectory(const String& srcContentPath, const String& destContentPath)
1823 // For srcContentPath
1824 SysTryReturn(NID_CNT, !_FileImpl::IsSystemPath(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1825 "[E_INVALID_ARG] Can not copy the file in the system region.");
1826 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1827 "[E_INVALID_ARG] Can not find the file.");
1829 // For destContentPath
1830 SysTryReturn(NID_CNT, _FileImpl::IsMediaPath(destContentPath), E_INVALID_ARG, E_INVALID_ARG,
1831 "[E_INVALID_ARG] The destination path should start with /Media or /Storagecard/Media.");
1833 // E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_FILE_NOT_FOUND, E_FILE_ALREADY_EXIST, E_MAX_EXCEEDED, E_STORAGE_FULL, E_IO
1834 result r = E_SUCCESS;
1835 r = _FileImpl::Copy(srcContentPath, destContentPath, true);
1836 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] CopyToMediaDirectory failed.", GetErrorMessage(r));
1842 _ContentManagerUtilImpl::MoveToMediaDirectory(const String& srcContentPath, const String& destContentPath)
1846 // For srcContentPath
1847 SysTryReturn(NID_CNT, !_FileImpl::IsSystemPath(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1848 "[E_INVALID_ARG] Can not copy the file in the system region.");
1849 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1850 "[E_INVALID_ARG] Can not find the file.");
1852 // For destContentPath
1853 SysTryReturn(NID_CNT, _FileImpl::IsMediaPath(destContentPath), E_INVALID_ARG, E_INVALID_ARG,
1854 "[E_INVALID_ARG] The destination path should start with /Media or /Storagecard/Media.");
1856 // E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_FILE_NOT_FOUND, E_FILE_ALREADY_EXIST, E_MAX_EXCEEDED, E_STORAGE_FULL, E_IO
1857 result r = E_SUCCESS;
1858 r = _FileImpl::Move(srcContentPath, destContentPath);
1859 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] MoveToMediaDirectory failed.", GetErrorMessage(r));