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 String tizenPath(L"");
109 String changedPath(L"");
110 r = ChangeMediaFilePath(contentPath, tizenPath, changedPath);
111 SysTryReturn(NID_CNT, r == E_SUCCESS, null, r, "[%s] Failed to perform ChangeMediaFilePath.", GetErrorMessage(r));
113 if (imgType == IMG_FORMAT_JPG)
115 unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(tizenPath));
116 SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
117 "[E_OUT_OF_MEMORY] The memory is insufficient.");
119 unique_ptr<ExifData, ExifDataDeleter> pExifdata(exif_data_new_from_file(pFileName.get()));
120 if (pExifdata != null)
123 ExifByteOrder byteOrder;
124 ExifEntry** pEntries = null;
125 const char* pData = null;
126 char buf[_IMAGE_BUFF_LENGTH] = {0, };
127 ExifContent* pExifcont[EXIF_IFD_COUNT];
128 char latitudeRef = 0; // to store latitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
129 char longitudeRef = 0; // to store longitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
130 unsigned int entryCount = 0;
131 bool isOrientation = false;
132 bool isLatitude = false;
133 bool isLongitude = false;
135 for (int i = 0; i < EXIF_IFD_COUNT; i++)
137 pExifcont[i] = pExifdata->ifd[i];
138 entryCount = pExifcont[i]->count;
139 pEntries = pExifcont[i]->entries;
140 for (unsigned int j = 0; j < entryCount; j++)
142 tag = pEntries[j]->tag;
143 pData = exif_entry_get_value(pEntries[j], buf, sizeof(buf));
144 SysTryReturn(NID_CNT, pData != null, pImageMetadata.release(), E_INVALID_ARG,
145 "[E_INVALID_ARG] exif_entry_get_value failed.");
147 if (tag == EXIF_TAG_PIXEL_X_DIMENSION)
149 pMetadata->width = atoi(buf);
151 else if (tag == EXIF_TAG_PIXEL_Y_DIMENSION)
153 pMetadata->height = atoi(buf);
155 else if (tag == EXIF_TAG_MAKE)
157 pMetadata->pManufacturer = new (nothrow) String(buf);
158 SysTryReturn(NID_CNT, pMetadata->pManufacturer != null, null, E_OUT_OF_MEMORY,
159 "[E_OUT_OF_MEMORY] The memory is insufficient.");
161 else if (tag == EXIF_TAG_MODEL)
163 pMetadata->pModel = new (nothrow) String(buf);
164 SysTryReturn(NID_CNT, pMetadata->pModel != null, null, E_OUT_OF_MEMORY,
165 "[E_OUT_OF_MEMORY] The memory is insufficient.");
167 else if (tag == EXIF_TAG_DATE_TIME)
169 pMetadata->pDateTime = new (nothrow) String(buf);
170 SysTryReturn(NID_CNT, pMetadata->pDateTime != null, null, E_OUT_OF_MEMORY,
171 "[E_OUT_OF_MEMORY] The memory is insufficient.");
173 else if (tag == EXIF_TAG_ORIENTATION && !isOrientation)
175 //get the byte order(little endian or big endian) before extracting orientation type
176 byteOrder = exif_data_get_byte_order(pEntries[j]->parent->parent);
177 pMetadata->orientation = static_cast<ImageOrientationType>(exif_get_short(pEntries[j]->data, byteOrder));
179 isOrientation = true;
181 else if (tag == EXIF_TAG_SOFTWARE)
183 pMetadata->pSoftware = new (nothrow) String(buf);
184 SysTryReturn(NID_CNT, pMetadata->pSoftware != null, null, E_OUT_OF_MEMORY,
185 "[E_OUT_OF_MEMORY] The memory is insufficient.");
187 else if (tag == EXIF_TAG_GPS_LATITUDE_REF)
189 latitudeRef = buf[0]; // GPS Latitude reference value will be 'N'(NORTH) or 'S'(SOUTH)
191 else if (tag == EXIF_TAG_GPS_LATITUDE && !isLatitude)
193 String tempLatitude(buf);
196 StringTokenizer strTok(tempLatitude, delim);
197 String token[3] = {L"", };
200 while (strTok.HasMoreTokens() && count < 3)
202 strTok.GetNextToken(token[count++]);
205 double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value
207 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
209 double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value
211 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
213 double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value
215 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
217 pMetadata->latitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
219 // if latitude designation is Southern (SOUTH) then latitude degree will be negative DD
220 if (latitudeRef == 'S')
222 pMetadata->latitude = (pMetadata->latitude * (double)(-1));
226 else if (tag == EXIF_TAG_GPS_LONGITUDE_REF)
228 longitudeRef = buf[0]; // GPS Longitude reference value will be 'W'(WEST) or 'E'(EAST)
230 else if (tag == EXIF_TAG_GPS_LONGITUDE && !isLongitude)
232 String tempLongitude(buf);
235 StringTokenizer strTok(tempLongitude, delim);
236 String token[3] = {L"", };
239 while (strTok.HasMoreTokens() && count < 3)
241 strTok.GetNextToken(token[count++]);
244 double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value
246 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
248 double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value
250 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
252 double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value
254 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
256 pMetadata->longitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
258 // if longitude designation is Western (WEST) then longitude degree will be negative DD
259 if (longitudeRef == 'W')
261 pMetadata->longitude = (pMetadata->longitude * (double)(-1));
265 else if (tag == EXIF_TAG_WHITE_BALANCE)
267 pMetadata->pWhiteBalance = new (nothrow) String(buf);
268 SysTryReturn(NID_CNT, pMetadata->pWhiteBalance != null, null, E_OUT_OF_MEMORY,
269 "[E_OUT_OF_MEMORY] The memory is insufficient.");
276 return pImageMetadata.release();
280 _ContentManagerUtilImpl::GetAudioMetaN(const String& contentPath)
284 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), null, E_INVALID_ARG,
285 "[E_INVALID_ARG] The path is not compatible.");
286 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_INVALID_ARG,
287 "[E_INVALID_ARG] The file corresponding to contentPath could not be found.");
289 // create here to make sure that get apis will not crash though the below API calls fails in case of invalid file.
290 unique_ptr<AudioMetadata> pAudioMetadata(new (nothrow) AudioMetadata());
291 SysTryReturn(NID_CNT, pAudioMetadata != null, null, E_OUT_OF_MEMORY,
292 "[E_OUT_OF_MEMORY] The memory is insufficient.");
294 _AudioMetadataImpl* pAudioMetaImpl = _AudioMetadataImpl::GetInstance(*(pAudioMetadata.get()));
295 SysTryReturn(NID_CNT, pAudioMetaImpl != null, null, E_OUT_OF_MEMORY,
296 "[E_OUT_OF_MEMORY] pAudioMetaImpl is null.");
298 AudioMeta* pMetadata = pAudioMetaImpl->GetAudioMetadata();
299 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
300 "[E_INVALID_ARG] pMetadata is null.");
302 pMetadata->contentPath = contentPath;
304 String tizenPath(L"");
305 String changedPath(L"");
306 result r = ChangeMediaFilePath(contentPath, tizenPath, changedPath);
307 SysTryReturn(NID_CNT, r == E_SUCCESS, null, r, "[%s] Failed to perform ChangeMediaFilePath.", GetErrorMessage(r));
309 // Create the metadata extractor handle
310 metadata_extractor_h tempExtractor = NULL;
312 int retVal = metadata_extractor_create(&tempExtractor);
313 r = ErrorMapToRetVal(retVal);
314 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
315 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
317 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
318 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
319 "[E_OUT_OF_MEMORY] The memory is insufficient.");
321 // Set file path of content to extract the metadata
322 unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(tizenPath));
323 SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
324 "[E_OUT_OF_MEMORY] The memory is insufficient.");
326 retVal = metadata_extractor_set_path(pExtractor.get(), pFileName.get());
327 r = ErrorMapToRetVal(retVal);
328 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
329 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
331 // Get all relavent audio metadata by passing relavent attirbutes
332 char* pTempAudioMeta = null;
333 unique_ptr<char, CharDeleter> pAudioMeta(null);
336 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempAudioMeta);
337 if (pTempAudioMeta != null)
339 pAudioMeta.reset(pTempAudioMeta);
340 pMetadata->bitrate = atoi(pAudioMeta.get());
344 r = ErrorMapToRetVal(retVal);
345 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
346 "[%s] metadata_extractor_get_metadata(bitrate) failed.", GetErrorMessage(r));
350 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_CHANNELS, &pTempAudioMeta);
351 if (pTempAudioMeta != null)
353 pAudioMeta.reset(pTempAudioMeta);
354 pMetadata->channelCount = atoi(pAudioMeta.get());
358 r = ErrorMapToRetVal(retVal);
359 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
360 "[%s] metadata_extractor_get_metadata(channels) failed.", GetErrorMessage(r));
364 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempAudioMeta);
365 if (pTempAudioMeta != null)
367 pAudioMeta.reset(pTempAudioMeta);
368 pMetadata->duration = atoi(pAudioMeta.get());
372 r = ErrorMapToRetVal(retVal);
373 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
374 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
378 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_SAMPLERATE, &pTempAudioMeta);
379 if (pTempAudioMeta != null)
381 pAudioMeta.reset(pTempAudioMeta);
382 pMetadata->frequency = atoi(pAudioMeta.get());
386 r = ErrorMapToRetVal(retVal);
387 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
388 "[%s] metadata_extractor_get_metadata(frequency) failed.", GetErrorMessage(r));
392 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ALBUM, &pTempAudioMeta);
393 if (pTempAudioMeta != null)
395 pAudioMeta.reset(pTempAudioMeta);
396 pMetadata->pAlbumName = new (nothrow) String(pAudioMeta.get());
397 SysTryReturn(NID_CNT, pMetadata->pAlbumName != null, null, E_OUT_OF_MEMORY,
398 "[E_OUT_OF_MEMORY] The memory is insufficient.");
402 r = ErrorMapToRetVal(retVal);
403 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
404 "[%s] metadata_extractor_get_metadata(album name) failed.", GetErrorMessage(r));
408 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ARTIST, &pTempAudioMeta);
409 if (pAudioMeta.get() != null)
411 pAudioMeta.reset(pTempAudioMeta);
412 pMetadata->pArtist = new (nothrow) String(pAudioMeta.get());
413 SysTryReturn(NID_CNT, pMetadata->pArtist != null, null, E_OUT_OF_MEMORY,
414 "[E_OUT_OF_MEMORY] The memory is insufficient.");
418 r = ErrorMapToRetVal(retVal);
419 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
420 "[%s] metadata_extractor_get_metadata(artist) failed.", GetErrorMessage(r));
424 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COPYRIGHT, &pTempAudioMeta);
425 if (pTempAudioMeta != null)
427 pAudioMeta.reset(pTempAudioMeta);
428 pMetadata->pCopyright = new (nothrow) String(pAudioMeta.get());
429 SysTryReturn(NID_CNT, pMetadata->pCopyright != null, null, E_OUT_OF_MEMORY,
430 "[E_OUT_OF_MEMORY] The memory is insufficient.");
434 r = ErrorMapToRetVal(retVal);
435 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
436 "[%s] metadata_extractor_get_metadata(copyright) failed.", GetErrorMessage(r));
440 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempAudioMeta);
441 if (pTempAudioMeta != null)
443 pAudioMeta.reset(pTempAudioMeta);
444 pMetadata->pGenre = new (nothrow) String(pAudioMeta.get());
445 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
446 "[E_OUT_OF_MEMORY] The memory is insufficient.");
450 r = ErrorMapToRetVal(retVal);
451 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
452 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
456 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TITLE, &pTempAudioMeta);
457 if (pTempAudioMeta != null)
459 pAudioMeta.reset(pTempAudioMeta);
460 pMetadata->pTitle = new (nothrow) String(pAudioMeta.get());
461 SysTryReturn(NID_CNT, pMetadata->pTitle != null, null, E_OUT_OF_MEMORY,
462 "[E_OUT_OF_MEMORY] The memory is insufficient.");
466 r = ErrorMapToRetVal(retVal);
467 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
468 "[%s] metadata_extractor_get_metadata(title) failed.", GetErrorMessage(r));
472 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempAudioMeta);
473 if (pTempAudioMeta != null)
475 pAudioMeta.reset(pTempAudioMeta);
476 pMetadata->pComment = new (nothrow) String(pAudioMeta.get());
477 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
478 "[E_OUT_OF_MEMORY] The memory is insufficient.");
482 r = ErrorMapToRetVal(retVal);
483 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
484 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
488 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempAudioMeta);
489 if (pTempAudioMeta != null)
491 pAudioMeta.reset(pTempAudioMeta);
492 pMetadata->pDescription = new (nothrow) String(pAudioMeta.get());
493 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
494 "[E_OUT_OF_MEMORY] The memory is insufficient.");
498 r = ErrorMapToRetVal(retVal);
499 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
500 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
504 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_RECDATE, &pTempAudioMeta);
505 if (pTempAudioMeta != null)
507 pAudioMeta.reset(pTempAudioMeta);
508 pMetadata->pRecordingDate = new (nothrow) String(pAudioMeta.get());
509 SysTryReturn(NID_CNT, pMetadata->pRecordingDate != null, null, E_OUT_OF_MEMORY,
510 "[E_OUT_OF_MEMORY] The memory is insufficient.");
514 r = ErrorMapToRetVal(retVal);
515 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
516 "[%s] metadata_extractor_get_metadata(recording date) failed.", GetErrorMessage(r));
520 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUTHOR, &pTempAudioMeta);
521 if (pTempAudioMeta != null)
523 pAudioMeta.reset(pTempAudioMeta);
524 pMetadata->pComposer = new (nothrow) String(pAudioMeta.get());
525 SysTryReturn(NID_CNT, pMetadata->pComposer != null, null, E_OUT_OF_MEMORY,
526 "[E_OUT_OF_MEMORY] The memory is insufficient.");
530 r = ErrorMapToRetVal(retVal);
531 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
532 "[%s] metadata_extractor_get_metadata(author) failed.", GetErrorMessage(r));
536 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TRACK_NUM, &pTempAudioMeta);
537 if (pTempAudioMeta != null)
539 pAudioMeta.reset(pTempAudioMeta);
540 pMetadata->pTrackInfo = new (nothrow) String(pAudioMeta.get());
541 SysTryReturn(NID_CNT, pMetadata->pTrackInfo != null, null, E_OUT_OF_MEMORY,
542 "[E_OUT_OF_MEMORY] The memory is insufficient.");
544 // if the string contains the track info like track num/track position,
545 // then track position will be ignored and only track num is returned
546 // no need to parse this string, since only track number is required
547 pMetadata->trackNum = atoi(pAudioMeta.get());
551 r = ErrorMapToRetVal(retVal);
552 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
553 "[%s] metadata_extractor_get_metadata(track info) failed.", GetErrorMessage(r));
557 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DATE, &pTempAudioMeta);
558 if (pTempAudioMeta != null)
560 pAudioMeta.reset(pTempAudioMeta);
561 pMetadata->year = atoi(pAudioMeta.get());
565 r = ErrorMapToRetVal(retVal);
566 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
567 "[%s] metadata_extractor_get_metadata(date) failed.", GetErrorMessage(r));
572 void* pTempArtwork = null;
573 unique_ptr<void, VoidDeleter> pArtwork(null);
575 // Get the artwork image in media file
576 retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempAudioMeta);
577 pAudioMeta.reset(pTempAudioMeta);
579 //Check if the albumart present and pass it to client if it is successfully processed, otherwise ignore any errors
580 //while processing albumart. This is to pass the other metadata tags to application.
581 if (pTempArtwork != null)
583 pArtwork.reset(pTempArtwork);
586 ImageFormat format = IMG_FORMAT_NONE;
589 r = buffer.Construct(size);
590 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
592 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
598 format = img.GetImageFormat(buffer);
599 pMetadata->pThumbnail = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888,
600 _THUMBNAIL_IMAGE_WIDTH, _THUMBNAIL_IMAGE_HEIGHT);
601 if (pMetadata->pThumbnail == null)
603 // Because Thumbnail is one of the metadata, it is not exception in this function.
604 SysLog(NID_CNT, "DecodeN failed.");
606 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
607 if (pMetadata->pAlbumArt == null)
609 // Because Album Art is one of the metadata, it is not exception in this function.
610 SysLog(NID_CNT, "DecodeN failed.");
618 r = ErrorMapToRetVal(retVal);
619 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
620 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
623 return pAudioMetadata.release();
627 _ContentManagerUtilImpl::GetVideoMetaN(const String& contentPath)
631 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), null, E_INVALID_ARG,
632 "[E_INVALID_ARG] The path is not compatible.");
633 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_INVALID_ARG,
634 "[E_INVALID_ARG] The file corresponding to contentPath could not be found.");
636 // need to create here to make sure that all get APIs will not crash in case of corrupted file
637 unique_ptr<VideoMetadata> pVideoMetadata(new (nothrow) VideoMetadata());
638 SysTryReturn(NID_CNT, pVideoMetadata != null, null, E_OUT_OF_MEMORY,
639 "[E_OUT_OF_MEMORY] The memory insufficient.");
641 _VideoMetadataImpl* pVideoMetaImpl = _VideoMetadataImpl::GetInstance(*(pVideoMetadata.get()));
642 SysTryReturn(NID_CNT, pVideoMetaImpl != null, null, E_OUT_OF_MEMORY,
643 "[E_OUT_OF_MEMORY] pVideoMetaImpl is null.");
645 VideoMeta* pMetadata = pVideoMetaImpl->GetVideoMetadata();
646 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
647 "[E_INVALID_ARG] pMetadata is null.");
649 pMetadata->contentPath = contentPath;
651 String tizenPath(L"");
652 String changedPath(L"");
653 result r = ChangeMediaFilePath(contentPath, tizenPath, changedPath);
654 SysTryReturn(NID_CNT, r == E_SUCCESS, null, r, "[%s] Failed to perform ChangeMediaFilePath.", GetErrorMessage(r));
656 // Create the metadata extractor handle
657 metadata_extractor_h tempExtractor = NULL;
659 int retVal = metadata_extractor_create(&tempExtractor);
660 r = ErrorMapToRetVal(retVal);
661 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
662 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
664 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
665 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
666 "[E_OUT_OF_MEMORY] The memory insufficient.");
668 // Set file path of content to extract the metadata
669 unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(tizenPath));
670 SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
671 "[E_OUT_OF_MEMORY] The memory is insufficient.");
673 retVal = metadata_extractor_set_path(pExtractor.get(), pFileName.get());
674 r = ErrorMapToRetVal(retVal);
675 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
676 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
678 // Get all relavent video metadata by passing relavent attirbutes
679 char* pTempVideoMeta = null;
680 unique_ptr<char, CharDeleter> pVideoMeta(null);
683 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_WIDTH, &pTempVideoMeta);
684 if (pTempVideoMeta != null)
686 pVideoMeta.reset(pTempVideoMeta);
687 pMetadata->width = atoi(pVideoMeta.get());
691 r = ErrorMapToRetVal(retVal);
692 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
693 "[%s] metadata_extractor_get_metadata(width) failed.", GetErrorMessage(r));
697 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_HEIGHT, &pTempVideoMeta);
698 if (pTempVideoMeta != null)
700 pVideoMeta.reset(pTempVideoMeta);
701 pMetadata->height = atoi(pVideoMeta.get());
705 r = ErrorMapToRetVal(retVal);
706 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
707 "[%s] metadata_extractor_get_metadata(height) failed.", GetErrorMessage(r));
711 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_BITRATE, &pTempVideoMeta);
712 if (pTempVideoMeta != null)
714 pVideoMeta.reset(pTempVideoMeta);
715 pMetadata->videoBitrate = atoi(pVideoMeta.get());
719 r = ErrorMapToRetVal(retVal);
720 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
721 "[%s] metadata_extractor_get_metadata(video bitrate) failed.", GetErrorMessage(r));
725 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempVideoMeta);
726 if (pTempVideoMeta != null)
728 pVideoMeta.reset(pTempVideoMeta);
729 pMetadata->audioBitrate = atoi(pVideoMeta.get());
733 r = ErrorMapToRetVal(retVal);
734 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
735 "[%s] metadata_extractor_get_metadata(audio bitrate) failed.", GetErrorMessage(r));
739 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_FPS, &pTempVideoMeta);
740 if (pTempVideoMeta != null)
742 pVideoMeta.reset(pTempVideoMeta);
743 pMetadata->framerate = atoi(pVideoMeta.get());
747 r = ErrorMapToRetVal(retVal);
748 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
749 "[%s] metadata_extractor_get_metadata(framerate) failed.", GetErrorMessage(r));
753 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempVideoMeta);
754 if (pTempVideoMeta != null)
756 pVideoMeta.reset(pTempVideoMeta);
757 pMetadata->duration = atoi(pVideoMeta.get());
761 r = ErrorMapToRetVal(retVal);
762 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
763 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
767 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempVideoMeta);
768 if (pTempVideoMeta != null)
770 pVideoMeta.reset(pTempVideoMeta);
771 pMetadata->pGenre = new (nothrow) String(pVideoMeta.get()); //allocate memory
772 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
773 "[E_OUT_OF_MEMORY] The memory is insufficient.");
777 r = ErrorMapToRetVal(retVal);
778 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
779 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
783 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempVideoMeta);
784 if (pTempVideoMeta != null)
786 pVideoMeta.reset(pTempVideoMeta);
787 pMetadata->pComment = new (nothrow) String(pVideoMeta.get());
788 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
789 "[E_OUT_OF_MEMORY] The memory is insufficient.");
793 r = ErrorMapToRetVal(retVal);
794 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
795 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
799 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempVideoMeta);
800 if (pTempVideoMeta != null)
802 pVideoMeta.reset(pTempVideoMeta);
803 pMetadata->pDescription = new (nothrow) String(pVideoMeta.get());
804 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
805 "[E_OUT_OF_MEMORY] The memory is insufficient.");
809 r = ErrorMapToRetVal(retVal);
810 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
811 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
816 void* pTempArtwork = null;
817 unique_ptr<void, VoidDeleter> pArtwork(null);
819 // Get the artwork image in media file
820 retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempVideoMeta);
821 pVideoMeta.reset(pTempVideoMeta);
822 if (pTempArtwork != null)
824 pArtwork.reset(pTempArtwork);
827 ImageFormat format = IMG_FORMAT_NONE;
830 r = buffer.Construct(size);
831 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
833 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
839 format = img.GetImageFormat(buffer);
841 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
842 if (pMetadata->pAlbumArt == null)
844 // Because Album Art is one of the metadata, it is not exception in this function.
845 SysLog(NID_CNT, "DecodeN failed.");
853 r = ErrorMapToRetVal(retVal);
854 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
855 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
858 return pVideoMetadata.release();
862 _ContentManagerUtilImpl::GetImageMetaN(const ByteBuffer& byteBuffer)
866 int bufferLen = byteBuffer.GetRemaining();
867 SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
869 // create object here as it needs to be passed to client in any case to make sure Get APIs do not crash
870 unique_ptr<ImageMetadata> pImageMetadata(new (nothrow) ImageMetadata());
871 SysTryReturn(NID_CNT, pImageMetadata != null, null, E_OUT_OF_MEMORY,
872 "[E_OUT_OF_MEMORY] pImageMetadata is null.");
874 _ImageMetadataImpl* pImageMetaImpl = _ImageMetadataImpl::GetInstance(*(pImageMetadata.get()));
875 SysTryReturn(NID_CNT, pImageMetaImpl != null, null, E_OUT_OF_MEMORY,
876 "[E_OUT_OF_MEMORY] pImageMetaImpl is null.");
878 ImageMeta* pMetadata = pImageMetaImpl->GetImageMetadata();
879 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
880 "[E_INVALID_ARG] pMetadata is null.");
882 //assign by default here and overwrite below if width and height presents in EXIF data.
883 ImageFormat imgType = IMG_FORMAT_NONE;
886 bool isOrientation = false;
887 bool isLatitude = false;
888 bool isLongitude = false;
890 result r = ImageBuffer::GetImageInfo(byteBuffer, imgType, imageWidth, imageHeight);
891 SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_INVALID_ARG,
892 "[E_INVALID_ARG] GetImageInfo failed.");
894 pMetadata->width = imageWidth;
895 pMetadata->height = imageHeight;
897 if (imgType == IMG_FORMAT_JPG)
899 const byte* pByte = byteBuffer.GetPointer();
901 unique_ptr<ExifData, ExifDataDeleter> pExifdata(exif_data_new_from_data(pByte, bufferLen));
902 if (pExifdata != null)
905 ExifByteOrder byteOrder;
906 ExifEntry** pEntries = null;
907 const char* pData = null;
908 char buf[_IMAGE_BUFF_LENGTH] = {0, };
909 ExifContent* pExifcont[EXIF_IFD_COUNT];
910 char latitudeRef = 0; // to store latitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
911 char longitudeRef = 0; // to store longitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
912 unsigned int entryCount = 0;
914 for (int i = 0; i < EXIF_IFD_COUNT; i++)
916 pExifcont[i] = pExifdata->ifd[i];
917 entryCount = pExifcont[i]->count;
918 pEntries = pExifcont[i]->entries;
919 for (unsigned int j = 0; j < entryCount; j++)
921 tag = pEntries[j]->tag;
922 pData = exif_entry_get_value(pEntries[j], buf, sizeof(buf));
923 SysTryReturn(NID_CNT, pData != null, pImageMetadata.release(), E_INVALID_ARG,
924 "[E_INVALID_ARG] exif_entry_get_value failed.");
926 if (tag == EXIF_TAG_PIXEL_X_DIMENSION)
928 pMetadata->width = atoi(buf);
930 else if (tag == EXIF_TAG_PIXEL_Y_DIMENSION)
932 pMetadata->height = atoi(buf);
934 else if (tag == EXIF_TAG_MAKE)
936 pMetadata->pManufacturer = new (nothrow) String(buf);
937 SysTryReturn(NID_CNT, pMetadata->pManufacturer != null, null, E_OUT_OF_MEMORY,
938 "[E_OUT_OF_MEMORY] The memory is insufficient.");
940 else if (tag == EXIF_TAG_MODEL)
942 pMetadata->pModel = new (nothrow) String(buf);
943 SysTryReturn(NID_CNT, pMetadata->pModel != null, null, E_OUT_OF_MEMORY,
944 "[E_OUT_OF_MEMORY] The memory is insufficient.");
946 else if (tag == EXIF_TAG_DATE_TIME)
948 pMetadata->pDateTime = new (nothrow) String(buf);
949 SysTryReturn(NID_CNT, pMetadata->pDateTime != null, null, E_OUT_OF_MEMORY,
950 "[E_OUT_OF_MEMORY] The memory is insufficient.");
952 else if (tag == EXIF_TAG_ORIENTATION && !isOrientation)
954 //get the byte order(little endian or big endian) before extracting orientation type
955 byteOrder = exif_data_get_byte_order(pEntries[j]->parent->parent);
956 pMetadata->orientation = static_cast<ImageOrientationType>(exif_get_short(pEntries[j]->data, byteOrder));
958 isOrientation = true;
960 else if (tag == EXIF_TAG_SOFTWARE)
962 pMetadata->pSoftware = new (nothrow) String(buf);
963 SysTryReturn(NID_CNT, pMetadata->pSoftware != null, null, E_OUT_OF_MEMORY,
964 "[E_OUT_OF_MEMORY] The memory is insufficient.");
966 else if (tag == EXIF_TAG_GPS_LATITUDE_REF)
968 latitudeRef = buf[0]; // GPS Latitude reference value will be 'N'(NORTH) or 'S'(SOUTH)
970 else if (tag == EXIF_TAG_GPS_LATITUDE && !isLatitude)
972 String tempLatitude(buf);
975 StringTokenizer strTok(tempLatitude, delim);
976 String token[3] = {L"", };
979 while (strTok.HasMoreTokens() && count < 3)
981 strTok.GetNextToken(token[count++]);
984 double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value
986 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
988 double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value
990 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
992 double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value
994 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
996 pMetadata->latitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
998 // if latitude designation is Southern (SOUTH) then latitude degree will be negative DD
999 if (latitudeRef == 'S')
1001 pMetadata->latitude = (pMetadata->latitude * (double)(-1));
1005 else if (tag == EXIF_TAG_GPS_LONGITUDE_REF)
1007 longitudeRef = buf[0]; // GPS Longitude reference value will be 'W'(WEST) or 'E'(EAST)
1009 else if (tag == EXIF_TAG_GPS_LONGITUDE && !isLongitude)
1011 String tempLongitude(buf);
1014 StringTokenizer strTok(tempLongitude, delim);
1015 String token[3] = {L"", };
1018 while (strTok.HasMoreTokens() && count < 3)
1020 strTok.GetNextToken(token[count++]);
1023 double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value
1024 r = GetLastResult();
1025 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
1027 double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value
1028 r = GetLastResult();
1029 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
1031 double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value
1032 r = GetLastResult();
1033 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
1035 pMetadata->longitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
1037 // if longitude designation is Western (WEST) then longitude degree will be negative DD
1038 if (longitudeRef == 'W')
1040 pMetadata->longitude = (pMetadata->longitude * (double)(-1));
1044 else if (tag == EXIF_TAG_WHITE_BALANCE)
1046 pMetadata->pWhiteBalance = new (nothrow) String(buf);
1047 SysTryReturn(NID_CNT, pMetadata->pWhiteBalance != null, null, E_OUT_OF_MEMORY,
1048 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1055 return pImageMetadata.release();
1059 _ContentManagerUtilImpl::GetAudioMetaN(const ByteBuffer& byteBuffer)
1063 int bufferLen = byteBuffer.GetRemaining();
1064 SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
1066 // create here to make sure that get apis will not crash though the below API calls fails in case of invalid file.
1067 unique_ptr<AudioMetadata> pAudioMetadata(new (nothrow) AudioMetadata());
1068 SysTryReturn(NID_CNT, pAudioMetadata != null, null, E_OUT_OF_MEMORY,
1069 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1071 _AudioMetadataImpl* pAudioMetaImpl = _AudioMetadataImpl::GetInstance(*(pAudioMetadata.get()));
1072 SysTryReturn(NID_CNT, pAudioMetaImpl != null, null, E_OUT_OF_MEMORY,
1073 "[E_OUT_OF_MEMORY] pAudioMetaImpl is null.");
1075 AudioMeta* pMetadata = pAudioMetaImpl->GetAudioMetadata();
1076 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
1077 "[E_INVALID_ARG] pMetadata is null.");
1079 // Create the metadata extractor handle
1080 metadata_extractor_h tempExtractor = NULL;
1082 int retVal = metadata_extractor_create(&tempExtractor);
1083 result r = ErrorMapToRetVal(retVal);
1084 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1085 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1087 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
1088 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
1089 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1091 const byte* pByte = byteBuffer.GetPointer();
1093 retVal = metadata_extractor_set_buffer(pExtractor.get(), pByte, bufferLen);
1094 r = ErrorMapToRetVal(retVal);
1095 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1096 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1098 // Get all relavent audio metadata by passing relavent attirbutes
1099 char* pTempAudioMeta = null;
1100 unique_ptr<char, CharDeleter> pAudioMeta(null);
1103 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempAudioMeta);
1104 if (pTempAudioMeta != null)
1106 pAudioMeta.reset(pTempAudioMeta);
1107 pMetadata->bitrate = atoi(pAudioMeta.get());
1111 r = ErrorMapToRetVal(retVal);
1112 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1113 "[%s] metadata_extractor_get_metadata(bitrate) failed.", GetErrorMessage(r));
1117 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_CHANNELS, &pTempAudioMeta);
1118 if (pTempAudioMeta != null)
1120 pAudioMeta.reset(pTempAudioMeta);
1121 pMetadata->channelCount = atoi(pAudioMeta.get());
1125 r = ErrorMapToRetVal(retVal);
1126 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1127 "[%s] metadata_extractor_get_metadata(channels) failed.", GetErrorMessage(r));
1131 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempAudioMeta);
1132 if (pTempAudioMeta != null)
1134 pAudioMeta.reset(pTempAudioMeta);
1135 pMetadata->duration = atoi(pAudioMeta.get());
1139 r = ErrorMapToRetVal(retVal);
1140 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1141 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
1145 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_SAMPLERATE, &pTempAudioMeta);
1146 if (pTempAudioMeta != null)
1148 pAudioMeta.reset(pTempAudioMeta);
1149 pMetadata->frequency = atoi(pAudioMeta.get());
1153 r = ErrorMapToRetVal(retVal);
1154 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1155 "[%s] metadata_extractor_get_metadata(frequency) failed.", GetErrorMessage(r));
1159 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ALBUM, &pTempAudioMeta);
1160 if (pTempAudioMeta != null)
1162 pAudioMeta.reset(pTempAudioMeta);
1163 pMetadata->pAlbumName = new (nothrow) String(pAudioMeta.get());
1164 SysTryReturn(NID_CNT, pMetadata->pAlbumName != null, null, E_OUT_OF_MEMORY,
1165 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1169 r = ErrorMapToRetVal(retVal);
1170 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1171 "[%s] metadata_extractor_get_metadata(album name) failed.", GetErrorMessage(r));
1175 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ARTIST, &pTempAudioMeta);
1176 if (pAudioMeta.get() != null)
1178 pAudioMeta.reset(pTempAudioMeta);
1179 pMetadata->pArtist = new (nothrow) String(pAudioMeta.get());
1180 SysTryReturn(NID_CNT, pMetadata->pArtist != null, null, E_OUT_OF_MEMORY,
1181 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1185 r = ErrorMapToRetVal(retVal);
1186 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1187 "[%s] metadata_extractor_get_metadata(artist) failed.", GetErrorMessage(r));
1191 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COPYRIGHT, &pTempAudioMeta);
1192 if (pTempAudioMeta != null)
1194 pAudioMeta.reset(pTempAudioMeta);
1195 pMetadata->pCopyright = new (nothrow) String(pAudioMeta.get());
1196 SysTryReturn(NID_CNT, pMetadata->pCopyright != null, null, E_OUT_OF_MEMORY,
1197 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1201 r = ErrorMapToRetVal(retVal);
1202 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1203 "[%s] metadata_extractor_get_metadata(copyright) failed.", GetErrorMessage(r));
1207 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempAudioMeta);
1208 if (pTempAudioMeta != null)
1210 pAudioMeta.reset(pTempAudioMeta);
1211 pMetadata->pGenre = new (nothrow) String(pAudioMeta.get());
1212 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
1213 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1217 r = ErrorMapToRetVal(retVal);
1218 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1219 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
1223 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TITLE, &pTempAudioMeta);
1224 if (pTempAudioMeta != null)
1226 pAudioMeta.reset(pTempAudioMeta);
1227 pMetadata->pTitle = new (nothrow) String(pAudioMeta.get());
1228 SysTryReturn(NID_CNT, pMetadata->pTitle != null, null, E_OUT_OF_MEMORY,
1229 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1233 r = ErrorMapToRetVal(retVal);
1234 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1235 "[%s] metadata_extractor_get_metadata(title) failed.", GetErrorMessage(r));
1239 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempAudioMeta);
1240 if (pTempAudioMeta != null)
1242 pAudioMeta.reset(pTempAudioMeta);
1243 pMetadata->pComment = new (nothrow) String(pAudioMeta.get());
1244 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
1245 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1249 r = ErrorMapToRetVal(retVal);
1250 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1251 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
1255 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempAudioMeta);
1256 if (pTempAudioMeta != null)
1258 pAudioMeta.reset(pTempAudioMeta);
1259 pMetadata->pDescription = new (nothrow) String(pAudioMeta.get());
1260 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
1261 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1265 r = ErrorMapToRetVal(retVal);
1266 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1267 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
1271 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_RECDATE, &pTempAudioMeta);
1272 if (pTempAudioMeta != null)
1274 pAudioMeta.reset(pTempAudioMeta);
1275 pMetadata->pRecordingDate = new (nothrow) String(pAudioMeta.get());
1276 SysTryReturn(NID_CNT, pMetadata->pRecordingDate != null, null, E_OUT_OF_MEMORY,
1277 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1281 r = ErrorMapToRetVal(retVal);
1282 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1283 "[%s] metadata_extractor_get_metadata(recording date) failed.", GetErrorMessage(r));
1287 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUTHOR, &pTempAudioMeta);
1288 if (pTempAudioMeta != null)
1290 pAudioMeta.reset(pTempAudioMeta);
1291 pMetadata->pComposer = new (nothrow) String(pAudioMeta.get());
1292 SysTryReturn(NID_CNT, pMetadata->pComposer != null, null, E_OUT_OF_MEMORY,
1293 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1297 r = ErrorMapToRetVal(retVal);
1298 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1299 "[%s] metadata_extractor_get_metadata(author) failed.", GetErrorMessage(r));
1303 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TRACK_NUM, &pTempAudioMeta);
1304 if (pTempAudioMeta != null)
1306 pAudioMeta.reset(pTempAudioMeta);
1307 pMetadata->pTrackInfo = new (nothrow) String(pAudioMeta.get());
1308 SysTryReturn(NID_CNT, pMetadata->pTrackInfo != null, null, E_OUT_OF_MEMORY,
1309 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1311 // if the string contains the track info like track num/track position,
1312 // then track position will be ignored and only track num is returned
1313 // no need to parse this string, since only track number is required
1314 pMetadata->trackNum = atoi(pAudioMeta.get());
1318 r = ErrorMapToRetVal(retVal);
1319 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1320 "[%s] metadata_extractor_get_metadata(track info) failed.", GetErrorMessage(r));
1324 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DATE, &pTempAudioMeta);
1325 if (pTempAudioMeta != null)
1327 pAudioMeta.reset(pTempAudioMeta);
1328 pMetadata->year = atoi(pAudioMeta.get());
1332 r = ErrorMapToRetVal(retVal);
1333 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1334 "[%s] metadata_extractor_get_metadata(date) failed.", GetErrorMessage(r));
1339 void* pTempArtwork = null;
1340 unique_ptr<void, VoidDeleter> pArtwork(null);
1342 // Get the artwork image in media file
1343 retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempAudioMeta);
1344 pAudioMeta.reset(pTempAudioMeta);
1346 //Check if the albumart present and pass it to client if it is successfully processed, otherwise ignore any errors
1347 //while processing albumart. This is to pass the other metadata tags to application.
1348 if (pTempArtwork != null)
1350 pArtwork.reset(pTempArtwork);
1353 ImageFormat format = IMG_FORMAT_NONE;
1356 r = buffer.Construct(size);
1357 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
1359 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
1362 r = img.Construct();
1365 format = img.GetImageFormat(buffer);
1366 pMetadata->pThumbnail = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888,
1367 _THUMBNAIL_IMAGE_WIDTH, _THUMBNAIL_IMAGE_HEIGHT);
1368 if (pMetadata->pThumbnail == null)
1370 // Because Thumbnail is one of the metadata, it is not exception in this function.
1371 SysLog(NID_CNT, "DecodeN failed.");
1373 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
1374 if (pMetadata->pAlbumArt == null)
1376 // Because Album Art is one of the metadata, it is not exception in this function.
1377 SysLog(NID_CNT, "DecodeN failed.");
1385 r = ErrorMapToRetVal(retVal);
1386 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1387 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
1390 return pAudioMetadata.release();
1394 _ContentManagerUtilImpl::GetVideoMetaN(const ByteBuffer& byteBuffer)
1398 int bufferLen = byteBuffer.GetRemaining();
1399 SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
1401 // need to create here to make sure that all get APIs will not crash in case of corrupted file
1402 unique_ptr<VideoMetadata> pVideoMetadata(new (nothrow) VideoMetadata());
1403 SysTryReturn(NID_CNT, pVideoMetadata != null, null, E_OUT_OF_MEMORY,
1404 "[E_OUT_OF_MEMORY] The memory insufficient.");
1406 _VideoMetadataImpl* pVideoMetaImpl = _VideoMetadataImpl::GetInstance(*(pVideoMetadata.get()));
1407 SysTryReturn(NID_CNT, pVideoMetaImpl != null, null, E_OUT_OF_MEMORY,
1408 "[E_OUT_OF_MEMORY] pVideoMetaImpl is null.");
1410 VideoMeta* pMetadata = pVideoMetaImpl->GetVideoMetadata();
1411 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
1412 "[E_INVALID_ARG] pMetadata is null.");
1414 // Create the metadata extractor handle
1415 metadata_extractor_h tempExtractor = NULL;
1417 int retVal = metadata_extractor_create(&tempExtractor);
1418 result r = ErrorMapToRetVal(retVal);
1419 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1420 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1422 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
1423 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
1424 "[E_OUT_OF_MEMORY] The memory insufficient.");
1426 const byte* pByte = byteBuffer.GetPointer();
1428 retVal = metadata_extractor_set_buffer(pExtractor.get(), pByte, bufferLen);
1429 r = ErrorMapToRetVal(retVal);
1430 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1431 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1433 // Get all relavent video metadata by passing relavent attirbutes
1434 char* pTempVideoMeta = null;
1435 unique_ptr<char, CharDeleter> pVideoMeta(null);
1438 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_WIDTH, &pTempVideoMeta);
1439 if (pTempVideoMeta != null)
1441 pVideoMeta.reset(pTempVideoMeta);
1442 pMetadata->width = atoi(pVideoMeta.get());
1446 r = ErrorMapToRetVal(retVal);
1447 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1448 "[%s] metadata_extractor_get_metadata(width) failed.", GetErrorMessage(r));
1452 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_HEIGHT, &pTempVideoMeta);
1453 if (pTempVideoMeta != null)
1455 pVideoMeta.reset(pTempVideoMeta);
1456 pMetadata->height = atoi(pVideoMeta.get());
1460 r = ErrorMapToRetVal(retVal);
1461 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1462 "[%s] metadata_extractor_get_metadata(height) failed.", GetErrorMessage(r));
1466 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_BITRATE, &pTempVideoMeta);
1467 if (pTempVideoMeta != null)
1469 pVideoMeta.reset(pTempVideoMeta);
1470 pMetadata->videoBitrate = atoi(pVideoMeta.get());
1474 r = ErrorMapToRetVal(retVal);
1475 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1476 "[%s] metadata_extractor_get_metadata(video bitrate) failed.", GetErrorMessage(r));
1480 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempVideoMeta);
1481 if (pTempVideoMeta != null)
1483 pVideoMeta.reset(pTempVideoMeta);
1484 pMetadata->audioBitrate = atoi(pVideoMeta.get());
1488 r = ErrorMapToRetVal(retVal);
1489 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1490 "[%s] metadata_extractor_get_metadata(audio bitrate) failed.", GetErrorMessage(r));
1494 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_FPS, &pTempVideoMeta);
1495 if (pTempVideoMeta != null)
1497 pVideoMeta.reset(pTempVideoMeta);
1498 pMetadata->framerate = atoi(pVideoMeta.get());
1502 r = ErrorMapToRetVal(retVal);
1503 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1504 "[%s] metadata_extractor_get_metadata(framerate) failed.", GetErrorMessage(r));
1508 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempVideoMeta);
1509 if (pTempVideoMeta != null)
1511 pVideoMeta.reset(pTempVideoMeta);
1512 pMetadata->duration = atoi(pVideoMeta.get());
1516 r = ErrorMapToRetVal(retVal);
1517 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1518 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
1522 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempVideoMeta);
1523 if (pTempVideoMeta != null)
1525 pVideoMeta.reset(pTempVideoMeta);
1526 pMetadata->pGenre = new (nothrow) String(pVideoMeta.get()); //allocate memory
1527 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
1528 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1532 r = ErrorMapToRetVal(retVal);
1533 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1534 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
1538 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempVideoMeta);
1539 if (pTempVideoMeta != null)
1541 pVideoMeta.reset(pTempVideoMeta);
1542 pMetadata->pComment = new (nothrow) String(pVideoMeta.get());
1543 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
1544 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1548 r = ErrorMapToRetVal(retVal);
1549 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1550 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
1554 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempVideoMeta);
1555 if (pTempVideoMeta != null)
1557 pVideoMeta.reset(pTempVideoMeta);
1558 pMetadata->pDescription = new (nothrow) String(pVideoMeta.get());
1559 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
1560 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1564 r = ErrorMapToRetVal(retVal);
1565 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1566 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
1571 void* pTempArtwork = null;
1572 unique_ptr<void, VoidDeleter> pArtwork(null);
1574 // Get the artwork image in media file
1575 retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempVideoMeta);
1576 pVideoMeta.reset(pTempVideoMeta);
1577 if (pTempArtwork != null)
1579 pArtwork.reset(pTempArtwork);
1582 ImageFormat format = IMG_FORMAT_NONE;
1585 r = buffer.Construct(size);
1586 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
1588 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
1591 r = img.Construct();
1594 format = img.GetImageFormat(buffer);
1596 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
1597 if (pMetadata->pAlbumArt == null)
1599 // Because Album Art is one of the metadata, it is not exception in this function.
1600 SysLog(NID_CNT, "DecodeN failed.");
1608 r = ErrorMapToRetVal(retVal);
1609 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1610 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
1613 return pVideoMetadata.release();
1617 _ContentManagerUtilImpl::CheckContentType(const String& contentPath, bool internal)
1621 ContentType contentType = CONTENT_TYPE_UNKNOWN;
1622 String mimeType(L"");
1626 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), contentType, E_INVALID_ARG,
1627 "[E_INVALID_ARG] The path is not compatible.");
1630 String tizenPath(L"");
1631 String changedPath(L"");
1632 result r = ChangeMediaFilePath(contentPath, tizenPath, changedPath);
1633 SysTryReturn(NID_CNT, !IsFailed(r), contentType, r, "[%s] Failed to perform ChangeMediaFilePathCompat.", GetErrorMessage(r));
1635 SysTryReturn(NID_CNT, changedPath.GetLength() != 0, contentType, E_INVALID_ARG,
1636 "[E_INVALID_ARG] The length of contentPath is 0.");
1637 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(changedPath), contentType, E_FILE_NOT_FOUND,
1638 "[E_FILE_NOT_FOUND] The file corresponding to contentPath could not be found.");
1640 String fileExt = _FileImpl::GetFileExtension(changedPath);
1641 r = GetLastResult();
1645 unique_ptr<char[]> pFormat(_StringConverter::CopyToCharArrayN(fileExt));
1646 SysTryReturn(NID_CNT, pFormat != null, contentType, E_OUT_OF_MEMORY,
1647 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1649 char* pTempMimeType = null;
1650 int retVal = mime_type_get_mime_type(pFormat.get(), &pTempMimeType);
1651 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, E_INVALID_ARG,
1652 "[E_INVALID_ARG] mime_type_get_mime_type failed.");
1653 SysTryReturn(NID_CNT, pTempMimeType != null, contentType, E_INVALID_ARG,
1654 "[E_INVALID_ARG] mime_type_get_mime_type failed.");
1656 unique_ptr<char, CharDeleter> pMimeType;
1657 pMimeType.reset(pTempMimeType);
1659 SysLog(NID_CNT, "The MIME type for %ls is %s", fileExt.GetPointer(), pTempMimeType);
1661 r = mimeType.Append(pMimeType.get());
1662 SysTryReturn(NID_CNT, !IsFailed(r), contentType, E_OUT_OF_MEMORY,
1663 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1669 SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
1671 unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(tizenPath));
1672 SysTryReturn(NID_CNT, pTempPath != null, contentType, E_OUT_OF_MEMORY,
1673 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1675 char tempType[255] = {0, };
1676 int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
1677 SysTryReturn(NID_CNT, ret == AUL_R_OK, contentType, E_INVALID_ARG,
1678 "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
1680 r = mimeType.Append(tempType);
1681 SysTryReturn(NID_CNT, !IsFailed(r), contentType, E_OUT_OF_MEMORY,
1682 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1685 if (mimeType.Contains(L"image"))
1687 return CONTENT_TYPE_IMAGE;
1689 else if (mimeType.Contains(L"audio"))
1691 if (mimeType.Contains(L"x-mpegurl"))
1693 SysLog(NID_CNT, "The type of x-mpegurl is other.");
1694 return CONTENT_TYPE_OTHER;
1696 return CONTENT_TYPE_AUDIO;
1698 else if (mimeType.Contains(L"video"))
1700 if (mimeType == L"video/3gpp" || mimeType == L"video/mp4")
1702 return CheckStream(tizenPath);
1704 return CONTENT_TYPE_VIDEO;
1706 else if (mimeType.Contains(L"application"))
1708 if (mimeType.Contains(L"x-smaf"))
1710 SysLog(NID_CNT, "The type of x-smaf is audio.");
1711 return CONTENT_TYPE_AUDIO;
1713 return CONTENT_TYPE_OTHER;
1716 return CONTENT_TYPE_OTHER;
1720 _ContentManagerUtilImpl::CheckStream(const String& contentPath)
1724 ContentType contentType = CONTENT_TYPE_UNKNOWN;
1725 metadata_extractor_h tempExtractor = NULL;
1727 int retVal = metadata_extractor_create(&tempExtractor);
1728 result r = ErrorMapToRetVal(retVal);
1729 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
1730 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1732 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
1733 SysTryReturn(NID_CNT, pExtractor != null, contentType, E_OUT_OF_MEMORY,
1734 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1736 //Set the file path to extract metadata.
1737 unique_ptr<char[]> pContentPath(_StringConverter::CopyToCharArrayN(contentPath));
1738 SysTryReturn(NID_CNT, pContentPath != null, contentType, E_INVALID_ARG,
1739 "[E_INVALID_ARG] The memory is insufficient.");
1741 retVal = metadata_extractor_set_path(pExtractor.get(), pContentPath.get());
1742 r = ErrorMapToRetVal(retVal);
1743 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE && pExtractor, contentType, r,
1744 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1746 //Check whether it is an audio or video file.
1747 char* pTempAudio = null;
1748 unique_ptr<char, CharDeleter> pAudio(null);
1750 char* pTempVideo = null;
1751 unique_ptr<char, CharDeleter> pVideo(null);
1753 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_HAS_AUDIO, &pTempAudio);
1754 if (pTempAudio != null)
1756 pAudio.reset(pTempAudio);
1760 r = ErrorMapToRetVal(retVal);
1761 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
1762 "[%s] metadata_extractor_get_metadata failed.", GetErrorMessage(r));
1765 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_HAS_VIDEO, &pTempVideo);
1766 if (pTempVideo != null)
1768 pVideo.reset(pTempVideo);
1772 r = ErrorMapToRetVal(retVal);
1773 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
1774 "[%s] metadata_extractor_get_metadata failed.", GetErrorMessage(r));
1777 if (*(pAudio.get()) > '0' && *(pVideo.get()) == '0')
1779 SysLog(NID_CNT, "The result of CheckStream() is audio");
1780 return CONTENT_TYPE_AUDIO;
1782 else if (*(pAudio.get()) == '0' && *(pVideo.get()) > '0')
1784 SysLog(NID_CNT, "The result of CheckStream() is video");
1785 return CONTENT_TYPE_VIDEO;
1787 else if (*(pAudio.get()) > '0' && *(pVideo.get()) > '0')
1789 SysLog(NID_CNT, "The result of CheckStream() is video");
1790 return CONTENT_TYPE_VIDEO;
1794 SysLogException(NID_CNT, E_UNSUPPORTED_FORMAT, "[E_UNSUPPORTED_FORMAT] The stream is empty.");
1801 _ContentManagerUtilImpl::VerifyFilePathCompatibility(const String& contentPath)
1803 if (!_AppInfo::IsOspCompat())
1805 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0)
1806 || contentPath.StartsWith(OSP_HOME, 0))
1808 SysLogException(NID_CNT, E_INVALID_ARG,
1809 "/Home, /Media/, or /Storagecard/Media/ is not supported from Tizen 2.0.");
1816 if (!(contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0)
1817 || contentPath.StartsWith(OSP_HOME, 0)))
1819 SysLogException(NID_CNT, E_INVALID_ARG,
1820 "The contentPath should start with /Home, /Media, or /Storagecard/Media.");
1829 _ContentManagerUtilImpl::ErrorMapToRetVal(int retVal)
1831 result r = E_SUCCESS;
1835 case METADATA_EXTRACTOR_ERROR_NONE:
1838 case METADATA_EXTRACTOR_ERROR_INVALID_PARAMETER:
1841 case METADATA_EXTRACTOR_ERROR_OUT_OF_MEMORY:
1842 r = E_OUT_OF_MEMORY;
1844 case METADATA_EXTRACTOR_ERROR_FILE_EXISTS:
1847 case METADATA_EXTRACTOR_ERROR_OPERATION_FAILED:
1856 _ContentManagerUtilImpl::CopyToMediaDirectory(const String& srcContentPath, const String& destContentPath)
1860 // For srcContentPath
1861 SysTryReturn(NID_CNT, !_FileImpl::IsSystemPath(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1862 "[E_INVALID_ARG] Can not copy the file in the system region.");
1863 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1864 "[E_INVALID_ARG] Can not find the file.");
1866 // For destContentPath
1867 SysTryReturn(NID_CNT, _FileImpl::IsMediaPath(destContentPath), E_INVALID_ARG, E_INVALID_ARG,
1868 "[E_INVALID_ARG] The destination path should start with /Media or /Storagecard/Media.");
1870 // E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_FILE_NOT_FOUND, E_FILE_ALREADY_EXIST, E_MAX_EXCEEDED, E_STORAGE_FULL, E_IO
1871 result r = E_SUCCESS;
1872 r = _FileImpl::Copy(srcContentPath, destContentPath, true);
1873 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] CopyToMediaDirectory failed.", GetErrorMessage(r));
1879 _ContentManagerUtilImpl::MoveToMediaDirectory(const String& srcContentPath, const String& destContentPath)
1883 // For srcContentPath
1884 SysTryReturn(NID_CNT, !_FileImpl::IsSystemPath(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1885 "[E_INVALID_ARG] Can not copy the file in the system region.");
1886 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1887 "[E_INVALID_ARG] Can not find the file.");
1889 // For destContentPath
1890 SysTryReturn(NID_CNT, _FileImpl::IsMediaPath(destContentPath), E_INVALID_ARG, E_INVALID_ARG,
1891 "[E_INVALID_ARG] The destination path should start with /Media or /Storagecard/Media.");
1893 // E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_FILE_NOT_FOUND, E_FILE_ALREADY_EXIST, E_MAX_EXCEEDED, E_STORAGE_FULL, E_IO
1894 result r = E_SUCCESS;
1895 r = _FileImpl::Move(srcContentPath, destContentPath);
1896 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] MoveToMediaDirectory failed.", GetErrorMessage(r));
1902 _ContentManagerUtilImpl::ChangeMediaFilePath(const String& contentPath, String& tizenPath, String& changedPath)
1904 result r = E_SUCCESS;
1906 tizenPath = contentPath;
1907 changedPath = contentPath;
1909 // If the api version is 2.0, the content path has to be changed.
1910 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1912 if ((contentPath.StartsWith(Environment::GetMediaPath(), 0)) || (contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
1914 tizenPath = contentPath;
1916 r = _FileImpl::ConvertPhysicalToVirtualPath(contentPath, changedPath);
1917 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
1918 "[%s] Failed to convert physical path to virtual path.", GetErrorMessage(E_INVALID_ARG));
1920 else if ((contentPath.StartsWith(OSP_MEDIA_PHONE, 0)) || (contentPath.StartsWith(OSP_MEDIA_MMC, 0)) || (contentPath.StartsWith(OSP_HOME, 0)))
1922 changedPath = contentPath;
1924 r = _FileImpl::ConvertVirtualToPhysicalPath(contentPath, tizenPath);
1925 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
1926 "[%s] Failed to convert virtual path to physical path.", GetErrorMessage(E_INVALID_ARG));
1930 SysLogException(NID_CNT, E_INVALID_ARG, "[%s] The path is not supported.", GetErrorMessage(E_INVALID_ARG));
1931 return E_INVALID_ARG;