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;
126 bool isOrientation = false;
128 for (int i = 0; i < EXIF_IFD_COUNT; i++)
130 pExifcont[i] = pExifdata->ifd[i];
131 entryCount = pExifcont[i]->count;
132 pEntries = pExifcont[i]->entries;
133 for (unsigned int j = 0; j < entryCount; j++)
135 tag = pEntries[j]->tag;
136 pData = exif_entry_get_value(pEntries[j], buf, sizeof(buf));
137 SysTryReturn(NID_CNT, pData != null, pImageMetadata.release(), E_INVALID_ARG,
138 "[E_INVALID_ARG] exif_entry_get_value failed.");
140 if (tag == EXIF_TAG_PIXEL_X_DIMENSION)
142 pMetadata->width = atoi(buf);
144 else if (tag == EXIF_TAG_PIXEL_Y_DIMENSION)
146 pMetadata->height = atoi(buf);
148 else if (tag == EXIF_TAG_MAKE)
150 pMetadata->pManufacturer = new (nothrow) String(buf);
151 SysTryReturn(NID_CNT, pMetadata->pManufacturer != null, null, E_OUT_OF_MEMORY,
152 "[E_OUT_OF_MEMORY] The memory is insufficient.");
154 else if (tag == EXIF_TAG_MODEL)
156 pMetadata->pModel = new (nothrow) String(buf);
157 SysTryReturn(NID_CNT, pMetadata->pModel != null, null, E_OUT_OF_MEMORY,
158 "[E_OUT_OF_MEMORY] The memory is insufficient.");
160 else if (tag == EXIF_TAG_DATE_TIME)
162 pMetadata->pDateTime = new (nothrow) String(buf);
163 SysTryReturn(NID_CNT, pMetadata->pDateTime != null, null, E_OUT_OF_MEMORY,
164 "[E_OUT_OF_MEMORY] The memory is insufficient.");
166 else if (tag == EXIF_TAG_ORIENTATION && !isOrientation)
168 //get the byte order(little endian or big endian) before extracting orientation type
169 byteOrder = exif_data_get_byte_order(pEntries[j]->parent->parent);
170 pMetadata->orientation = static_cast<ImageOrientationType>(exif_get_short(pEntries[j]->data, byteOrder));
172 isOrientation = true;
174 else if (tag == EXIF_TAG_SOFTWARE)
176 pMetadata->pSoftware = new (nothrow) String(buf);
177 SysTryReturn(NID_CNT, pMetadata->pSoftware != null, null, E_OUT_OF_MEMORY,
178 "[E_OUT_OF_MEMORY] The memory is insufficient.");
180 else if (tag == EXIF_TAG_GPS_LATITUDE_REF)
182 latitudeRef = buf[0]; // GPS Latitude reference value will be 'N'(NORTH) or 'S'(SOUTH)
184 else if (tag == EXIF_TAG_GPS_LATITUDE)
186 String tempLatitude(buf);
189 StringTokenizer strTok(tempLatitude, delim);
190 String token[3] = {L"", };
193 while (strTok.HasMoreTokens() && count < 3)
195 strTok.GetNextToken(token[count++]);
198 double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value
200 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
202 double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value
204 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
206 double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value
208 SysTryReturn(NID_CNT, !IsFailed(r), null, E_INVALID_ARG, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
210 pMetadata->latitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
212 // if latitude designation is Southern (SOUTH) then latitude degree will be negative DD
213 if (latitudeRef == 'S')
215 pMetadata->latitude = (pMetadata->latitude * (double)(-1));
218 else if (tag == EXIF_TAG_GPS_LONGITUDE_REF)
220 longitudeRef = buf[0]; // GPS Longitude reference value will be 'W'(WEST) or 'E'(EAST)
222 else if (tag == EXIF_TAG_GPS_LONGITUDE)
224 String tempLongitude(buf);
227 StringTokenizer strTok(tempLongitude, delim);
228 String token[3] = {L"", };
231 while (strTok.HasMoreTokens() && count < 3)
233 strTok.GetNextToken(token[count++]);
236 double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value
238 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
240 double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value
242 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
244 double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value
246 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
248 pMetadata->longitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
250 // if longitude designation is Western (WEST) then longitude degree will be negative DD
251 if (longitudeRef == 'W')
253 pMetadata->longitude = (pMetadata->longitude * (double)(-1));
256 else if (tag == EXIF_TAG_WHITE_BALANCE)
258 pMetadata->pWhiteBalance = new (nothrow) String(buf);
259 SysTryReturn(NID_CNT, pMetadata->pWhiteBalance != null, null, E_OUT_OF_MEMORY,
260 "[E_OUT_OF_MEMORY] The memory is insufficient.");
267 return pImageMetadata.release();
271 _ContentManagerUtilImpl::GetAudioMetaN(const String& contentPath)
275 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), null, E_INVALID_ARG,
276 "[E_INVALID_ARG] The path is not compatible.");
277 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_INVALID_ARG,
278 "[E_INVALID_ARG] The file corresponding to contentPath could not be found.");
280 // create here to make sure that get apis will not crash though the below API calls fails in case of invalid file.
281 unique_ptr<AudioMetadata> pAudioMetadata(new (nothrow) AudioMetadata());
282 SysTryReturn(NID_CNT, pAudioMetadata != null, null, E_OUT_OF_MEMORY,
283 "[E_OUT_OF_MEMORY] The memory is insufficient.");
285 _AudioMetadataImpl* pAudioMetaImpl = _AudioMetadataImpl::GetInstance(*(pAudioMetadata.get()));
286 SysTryReturn(NID_CNT, pAudioMetaImpl != null, null, E_OUT_OF_MEMORY,
287 "[E_OUT_OF_MEMORY] pAudioMetaImpl is null.");
289 AudioMeta* pMetadata = pAudioMetaImpl->GetAudioMetadata();
290 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
291 "[E_INVALID_ARG] pMetadata is null.");
293 pMetadata->contentPath = contentPath;
295 // Create the metadata extractor handle
296 metadata_extractor_h tempExtractor = NULL;
298 int retVal = metadata_extractor_create(&tempExtractor);
299 result r = ErrorMapToRetVal(retVal);
300 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
301 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
303 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
304 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
305 "[E_OUT_OF_MEMORY] The memory is insufficient.");
307 // Set file path of content to extract the metadata
308 unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(contentPath));
309 SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
310 "[E_OUT_OF_MEMORY] The memory is insufficient.");
312 retVal = metadata_extractor_set_path(pExtractor.get(), pFileName.get());
313 r = ErrorMapToRetVal(retVal);
314 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
315 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
317 // Get all relavent audio metadata by passing relavent attirbutes
318 char* pTempAudioMeta = null;
319 unique_ptr<char, CharDeleter> pAudioMeta(null);
322 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempAudioMeta);
323 if (pTempAudioMeta != null)
325 pAudioMeta.reset(pTempAudioMeta);
326 pMetadata->bitrate = atoi(pAudioMeta.get());
330 r = ErrorMapToRetVal(retVal);
331 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
332 "[%s] metadata_extractor_get_metadata(bitrate) failed.", GetErrorMessage(r));
336 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_CHANNELS, &pTempAudioMeta);
337 if (pTempAudioMeta != null)
339 pAudioMeta.reset(pTempAudioMeta);
340 pMetadata->channelCount = 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(channels) failed.", GetErrorMessage(r));
350 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempAudioMeta);
351 if (pTempAudioMeta != null)
353 pAudioMeta.reset(pTempAudioMeta);
354 pMetadata->duration = 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(duration) failed.", GetErrorMessage(r));
364 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_SAMPLERATE, &pTempAudioMeta);
365 if (pTempAudioMeta != null)
367 pAudioMeta.reset(pTempAudioMeta);
368 pMetadata->frequency = 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(frequency) failed.", GetErrorMessage(r));
378 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ALBUM, &pTempAudioMeta);
379 if (pTempAudioMeta != null)
381 pAudioMeta.reset(pTempAudioMeta);
382 pMetadata->pAlbumName = new (nothrow) String(pAudioMeta.get());
383 SysTryReturn(NID_CNT, pMetadata->pAlbumName != null, null, E_OUT_OF_MEMORY,
384 "[E_OUT_OF_MEMORY] The memory is insufficient.");
388 r = ErrorMapToRetVal(retVal);
389 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
390 "[%s] metadata_extractor_get_metadata(album name) failed.", GetErrorMessage(r));
394 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ARTIST, &pTempAudioMeta);
395 if (pAudioMeta.get() != null)
397 pAudioMeta.reset(pTempAudioMeta);
398 pMetadata->pArtist = new (nothrow) String(pAudioMeta.get());
399 SysTryReturn(NID_CNT, pMetadata->pArtist != null, null, E_OUT_OF_MEMORY,
400 "[E_OUT_OF_MEMORY] The memory is insufficient.");
404 r = ErrorMapToRetVal(retVal);
405 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
406 "[%s] metadata_extractor_get_metadata(artist) failed.", GetErrorMessage(r));
410 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COPYRIGHT, &pTempAudioMeta);
411 if (pTempAudioMeta != null)
413 pAudioMeta.reset(pTempAudioMeta);
414 pMetadata->pCopyright = new (nothrow) String(pAudioMeta.get());
415 SysTryReturn(NID_CNT, pMetadata->pCopyright != null, null, E_OUT_OF_MEMORY,
416 "[E_OUT_OF_MEMORY] The memory is insufficient.");
420 r = ErrorMapToRetVal(retVal);
421 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
422 "[%s] metadata_extractor_get_metadata(copyright) failed.", GetErrorMessage(r));
426 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempAudioMeta);
427 if (pTempAudioMeta != null)
429 pAudioMeta.reset(pTempAudioMeta);
430 pMetadata->pGenre = new (nothrow) String(pAudioMeta.get());
431 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
432 "[E_OUT_OF_MEMORY] The memory is insufficient.");
436 r = ErrorMapToRetVal(retVal);
437 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
438 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
442 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TITLE, &pTempAudioMeta);
443 if (pTempAudioMeta != null)
445 pAudioMeta.reset(pTempAudioMeta);
446 pMetadata->pTitle = new (nothrow) String(pAudioMeta.get());
447 SysTryReturn(NID_CNT, pMetadata->pTitle != null, null, E_OUT_OF_MEMORY,
448 "[E_OUT_OF_MEMORY] The memory is insufficient.");
452 r = ErrorMapToRetVal(retVal);
453 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
454 "[%s] metadata_extractor_get_metadata(title) failed.", GetErrorMessage(r));
458 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempAudioMeta);
459 if (pTempAudioMeta != null)
461 pAudioMeta.reset(pTempAudioMeta);
462 pMetadata->pComment = new (nothrow) String(pAudioMeta.get());
463 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
464 "[E_OUT_OF_MEMORY] The memory is insufficient.");
468 r = ErrorMapToRetVal(retVal);
469 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
470 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
474 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempAudioMeta);
475 if (pTempAudioMeta != null)
477 pAudioMeta.reset(pTempAudioMeta);
478 pMetadata->pDescription = new (nothrow) String(pAudioMeta.get());
479 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
480 "[E_OUT_OF_MEMORY] The memory is insufficient.");
484 r = ErrorMapToRetVal(retVal);
485 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
486 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
490 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_RECDATE, &pTempAudioMeta);
491 if (pTempAudioMeta != null)
493 pAudioMeta.reset(pTempAudioMeta);
494 pMetadata->pRecordingDate = new (nothrow) String(pAudioMeta.get());
495 SysTryReturn(NID_CNT, pMetadata->pRecordingDate != null, null, E_OUT_OF_MEMORY,
496 "[E_OUT_OF_MEMORY] The memory is insufficient.");
500 r = ErrorMapToRetVal(retVal);
501 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
502 "[%s] metadata_extractor_get_metadata(recording date) failed.", GetErrorMessage(r));
506 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUTHOR, &pTempAudioMeta);
507 if (pTempAudioMeta != null)
509 pAudioMeta.reset(pTempAudioMeta);
510 pMetadata->pComposer = new (nothrow) String(pAudioMeta.get());
511 SysTryReturn(NID_CNT, pMetadata->pComposer != null, null, E_OUT_OF_MEMORY,
512 "[E_OUT_OF_MEMORY] The memory is insufficient.");
516 r = ErrorMapToRetVal(retVal);
517 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
518 "[%s] metadata_extractor_get_metadata(author) failed.", GetErrorMessage(r));
522 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TRACK_NUM, &pTempAudioMeta);
523 if (pTempAudioMeta != null)
525 pAudioMeta.reset(pTempAudioMeta);
526 pMetadata->pTrackInfo = new (nothrow) String(pAudioMeta.get());
527 SysTryReturn(NID_CNT, pMetadata->pTrackInfo != null, null, E_OUT_OF_MEMORY,
528 "[E_OUT_OF_MEMORY] The memory is insufficient.");
530 // if the string contains the track info like track num/track position,
531 // then track position will be ignored and only track num is returned
532 // no need to parse this string, since only track number is required
533 pMetadata->trackNum = atoi(pAudioMeta.get());
537 r = ErrorMapToRetVal(retVal);
538 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
539 "[%s] metadata_extractor_get_metadata(track info) failed.", GetErrorMessage(r));
543 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DATE, &pTempAudioMeta);
544 if (pTempAudioMeta != null)
546 pAudioMeta.reset(pTempAudioMeta);
547 pMetadata->year = 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(date) failed.", GetErrorMessage(r));
558 void* pTempArtwork = null;
559 unique_ptr<void, VoidDeleter> pArtwork(null);
561 // Get the artwork image in media file
562 retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempAudioMeta);
563 pAudioMeta.reset(pTempAudioMeta);
565 //Check if the albumart present and pass it to client if it is successfully processed, otherwise ignore any errors
566 //while processing albumart. This is to pass the other metadata tags to application.
567 if (pTempArtwork != null)
569 pArtwork.reset(pTempArtwork);
572 ImageFormat format = IMG_FORMAT_NONE;
575 r = buffer.Construct(size);
576 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
578 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
584 format = img.GetImageFormat(buffer);
585 pMetadata->pThumbnail = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888,
586 _THUMBNAIL_IMAGE_WIDTH, _THUMBNAIL_IMAGE_HEIGHT);
587 if (pMetadata->pThumbnail == null)
589 // Because Thumbnail is one of the metadata, it is not exception in this function.
590 SysLog(NID_CNT, "DecodeN failed.");
592 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
593 if (pMetadata->pAlbumArt == null)
595 // Because Album Art is one of the metadata, it is not exception in this function.
596 SysLog(NID_CNT, "DecodeN failed.");
604 r = ErrorMapToRetVal(retVal);
605 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
606 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
609 return pAudioMetadata.release();
613 _ContentManagerUtilImpl::GetVideoMetaN(const String& contentPath)
617 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), null, E_INVALID_ARG,
618 "[E_INVALID_ARG] The path is not compatible.");
619 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_INVALID_ARG,
620 "[E_INVALID_ARG] The file corresponding to contentPath could not be found.");
622 // need to create here to make sure that all get APIs will not crash in case of corrupted file
623 unique_ptr<VideoMetadata> pVideoMetadata(new (nothrow) VideoMetadata());
624 SysTryReturn(NID_CNT, pVideoMetadata != null, null, E_OUT_OF_MEMORY,
625 "[E_OUT_OF_MEMORY] The memory insufficient.");
627 _VideoMetadataImpl* pVideoMetaImpl = _VideoMetadataImpl::GetInstance(*(pVideoMetadata.get()));
628 SysTryReturn(NID_CNT, pVideoMetaImpl != null, null, E_OUT_OF_MEMORY,
629 "[E_OUT_OF_MEMORY] pVideoMetaImpl is null.");
631 VideoMeta* pMetadata = pVideoMetaImpl->GetVideoMetadata();
632 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
633 "[E_INVALID_ARG] pMetadata is null.");
635 pMetadata->contentPath = contentPath;
637 // Create the metadata extractor handle
638 metadata_extractor_h tempExtractor = NULL;
640 int retVal = metadata_extractor_create(&tempExtractor);
641 result r = ErrorMapToRetVal(retVal);
642 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
643 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
645 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
646 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
647 "[E_OUT_OF_MEMORY] The memory insufficient.");
649 // Set file path of content to extract the metadata
650 unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(contentPath));
651 SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
652 "[E_OUT_OF_MEMORY] The memory is insufficient.");
654 retVal = metadata_extractor_set_path(pExtractor.get(), pFileName.get());
655 r = ErrorMapToRetVal(retVal);
656 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
657 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
659 // Get all relavent video metadata by passing relavent attirbutes
660 char* pTempVideoMeta = null;
661 unique_ptr<char, CharDeleter> pVideoMeta(null);
664 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_WIDTH, &pTempVideoMeta);
665 if (pTempVideoMeta != null)
667 pVideoMeta.reset(pTempVideoMeta);
668 pMetadata->width = atoi(pVideoMeta.get());
672 r = ErrorMapToRetVal(retVal);
673 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
674 "[%s] metadata_extractor_get_metadata(width) failed.", GetErrorMessage(r));
678 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_HEIGHT, &pTempVideoMeta);
679 if (pTempVideoMeta != null)
681 pVideoMeta.reset(pTempVideoMeta);
682 pMetadata->height = atoi(pVideoMeta.get());
686 r = ErrorMapToRetVal(retVal);
687 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
688 "[%s] metadata_extractor_get_metadata(height) failed.", GetErrorMessage(r));
692 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_BITRATE, &pTempVideoMeta);
693 if (pTempVideoMeta != null)
695 pVideoMeta.reset(pTempVideoMeta);
696 pMetadata->videoBitrate = atoi(pVideoMeta.get());
700 r = ErrorMapToRetVal(retVal);
701 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
702 "[%s] metadata_extractor_get_metadata(video bitrate) failed.", GetErrorMessage(r));
706 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempVideoMeta);
707 if (pTempVideoMeta != null)
709 pVideoMeta.reset(pTempVideoMeta);
710 pMetadata->audioBitrate = atoi(pVideoMeta.get());
714 r = ErrorMapToRetVal(retVal);
715 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
716 "[%s] metadata_extractor_get_metadata(audio bitrate) failed.", GetErrorMessage(r));
720 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_FPS, &pTempVideoMeta);
721 if (pTempVideoMeta != null)
723 pVideoMeta.reset(pTempVideoMeta);
724 pMetadata->framerate = atoi(pVideoMeta.get());
728 r = ErrorMapToRetVal(retVal);
729 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
730 "[%s] metadata_extractor_get_metadata(framerate) failed.", GetErrorMessage(r));
734 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempVideoMeta);
735 if (pTempVideoMeta != null)
737 pVideoMeta.reset(pTempVideoMeta);
738 pMetadata->duration = atoi(pVideoMeta.get());
742 r = ErrorMapToRetVal(retVal);
743 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
744 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
748 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempVideoMeta);
749 if (pTempVideoMeta != null)
751 pVideoMeta.reset(pTempVideoMeta);
752 pMetadata->pGenre = new (nothrow) String(pVideoMeta.get()); //allocate memory
753 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
754 "[E_OUT_OF_MEMORY] The memory is insufficient.");
758 r = ErrorMapToRetVal(retVal);
759 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
760 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
764 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempVideoMeta);
765 if (pTempVideoMeta != null)
767 pVideoMeta.reset(pTempVideoMeta);
768 pMetadata->pComment = new (nothrow) String(pVideoMeta.get());
769 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
770 "[E_OUT_OF_MEMORY] The memory is insufficient.");
774 r = ErrorMapToRetVal(retVal);
775 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
776 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
780 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempVideoMeta);
781 if (pTempVideoMeta != null)
783 pVideoMeta.reset(pTempVideoMeta);
784 pMetadata->pDescription = new (nothrow) String(pVideoMeta.get());
785 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
786 "[E_OUT_OF_MEMORY] The memory is insufficient.");
790 r = ErrorMapToRetVal(retVal);
791 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
792 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
797 void* pTempArtwork = null;
798 unique_ptr<void, VoidDeleter> pArtwork(null);
800 // Get the artwork image in media file
801 retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempVideoMeta);
802 pVideoMeta.reset(pTempVideoMeta);
803 if (pTempArtwork != null)
805 pArtwork.reset(pTempArtwork);
808 ImageFormat format = IMG_FORMAT_NONE;
811 r = buffer.Construct(size);
812 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
814 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
820 format = img.GetImageFormat(buffer);
822 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
823 if (pMetadata->pAlbumArt == null)
825 // Because Album Art is one of the metadata, it is not exception in this function.
826 SysLog(NID_CNT, "DecodeN failed.");
834 r = ErrorMapToRetVal(retVal);
835 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
836 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
839 return pVideoMetadata.release();
843 _ContentManagerUtilImpl::GetImageMetaN(const ByteBuffer& byteBuffer)
847 int bufferLen = byteBuffer.GetRemaining();
848 SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
850 // create object here as it needs to be passed to client in any case to make sure Get APIs do not crash
851 unique_ptr<ImageMetadata> pImageMetadata(new (nothrow) ImageMetadata());
852 SysTryReturn(NID_CNT, pImageMetadata != null, null, E_OUT_OF_MEMORY,
853 "[E_OUT_OF_MEMORY] pImageMetadata is null.");
855 _ImageMetadataImpl* pImageMetaImpl = _ImageMetadataImpl::GetInstance(*(pImageMetadata.get()));
856 SysTryReturn(NID_CNT, pImageMetaImpl != null, null, E_OUT_OF_MEMORY,
857 "[E_OUT_OF_MEMORY] pImageMetaImpl is null.");
859 ImageMeta* pMetadata = pImageMetaImpl->GetImageMetadata();
860 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
861 "[E_INVALID_ARG] pMetadata is null.");
863 //assign by default here and overwrite below if width and height presents in EXIF data.
864 ImageFormat imgType = IMG_FORMAT_NONE;
868 result r = ImageBuffer::GetImageInfo(byteBuffer, imgType, imageWidth, imageHeight);
869 SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_INVALID_ARG,
870 "[E_INVALID_ARG] GetImageInfo failed.");
872 pMetadata->width = imageWidth;
873 pMetadata->height = imageHeight;
875 if (imgType == IMG_FORMAT_JPG)
877 const byte* pByte = byteBuffer.GetPointer();
879 unique_ptr<ExifData, ExifDataDeleter> pExifdata(exif_data_new_from_data(pByte, bufferLen));
880 if (pExifdata != null)
883 ExifByteOrder byteOrder;
884 ExifEntry** pEntries = null;
885 const char* pData = null;
886 char buf[_IMAGE_BUFF_LENGTH] = {0, };
887 ExifContent* pExifcont[EXIF_IFD_COUNT];
888 char latitudeRef = 0; // to store latitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
889 char longitudeRef = 0; // to store longitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
890 unsigned int entryCount = 0;
892 for (int i = 0; i < EXIF_IFD_COUNT; i++)
894 pExifcont[i] = pExifdata->ifd[i];
895 entryCount = pExifcont[i]->count;
896 pEntries = pExifcont[i]->entries;
897 for (unsigned int j = 0; j < entryCount; j++)
899 tag = pEntries[j]->tag;
900 pData = exif_entry_get_value(pEntries[j], buf, sizeof(buf));
901 SysTryReturn(NID_CNT, pData != null, pImageMetadata.release(), E_INVALID_ARG,
902 "[E_INVALID_ARG] exif_entry_get_value failed.");
904 if (tag == EXIF_TAG_PIXEL_X_DIMENSION)
906 pMetadata->width = atoi(buf);
908 else if (tag == EXIF_TAG_PIXEL_Y_DIMENSION)
910 pMetadata->height = atoi(buf);
912 else if (tag == EXIF_TAG_MAKE)
914 pMetadata->pManufacturer = new (nothrow) String(buf);
915 SysTryReturn(NID_CNT, pMetadata->pManufacturer != null, null, E_OUT_OF_MEMORY,
916 "[E_OUT_OF_MEMORY] The memory is insufficient.");
918 else if (tag == EXIF_TAG_MODEL)
920 pMetadata->pModel = new (nothrow) String(buf);
921 SysTryReturn(NID_CNT, pMetadata->pModel != null, null, E_OUT_OF_MEMORY,
922 "[E_OUT_OF_MEMORY] The memory is insufficient.");
924 else if (tag == EXIF_TAG_DATE_TIME)
926 pMetadata->pDateTime = new (nothrow) String(buf);
927 SysTryReturn(NID_CNT, pMetadata->pDateTime != null, null, E_OUT_OF_MEMORY,
928 "[E_OUT_OF_MEMORY] The memory is insufficient.");
930 else if (tag == EXIF_TAG_ORIENTATION)
932 //get the byte order(little endian or big endian) before extracting orientation type
933 byteOrder = exif_data_get_byte_order(pEntries[j]->parent->parent);
934 pMetadata->orientation = static_cast<ImageOrientationType>(exif_get_short(pEntries[j]->data, byteOrder));
936 else if (tag == EXIF_TAG_SOFTWARE)
938 pMetadata->pSoftware = new (nothrow) String(buf);
939 SysTryReturn(NID_CNT, pMetadata->pSoftware != null, null, E_OUT_OF_MEMORY,
940 "[E_OUT_OF_MEMORY] The memory is insufficient.");
942 else if (tag == EXIF_TAG_GPS_LATITUDE_REF)
944 latitudeRef = buf[0]; // GPS Latitude reference value will be 'N'(NORTH) or 'S'(SOUTH)
946 else if (tag == EXIF_TAG_GPS_LATITUDE)
948 String tempLatitude(buf);
951 StringTokenizer strTok(tempLatitude, delim);
952 String token[3] = {L"", };
955 while (strTok.HasMoreTokens() && count < 3)
957 strTok.GetNextToken(token[count++]);
960 double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value
962 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
964 double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value
966 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
968 double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value
970 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
972 pMetadata->latitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
974 // if latitude designation is Southern (SOUTH) then latitude degree will be negative DD
975 if (latitudeRef == 'S')
977 pMetadata->latitude = (pMetadata->latitude * (double)(-1));
980 else if (tag == EXIF_TAG_GPS_LONGITUDE_REF)
982 longitudeRef = buf[0]; // GPS Longitude reference value will be 'W'(WEST) or 'E'(EAST)
984 else if (tag == EXIF_TAG_GPS_LONGITUDE)
986 String tempLongitude(buf);
989 StringTokenizer strTok(tempLongitude, delim);
990 String token[3] = {L"", };
993 while (strTok.HasMoreTokens() && count < 3)
995 strTok.GetNextToken(token[count++]);
998 double ddVal = _LocalizedNumParser::ToDouble(token[0], "C"); // degree value
1000 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
1002 double mmVal = _LocalizedNumParser::ToDouble(token[1], "C"); // minutes value
1003 r = GetLastResult();
1004 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
1006 double ssVal = _LocalizedNumParser::ToDouble(token[2], "C"); // seconds value
1007 r = GetLastResult();
1008 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[E_INVALID_ARG] Failed to perform ToDouble operation.");
1010 pMetadata->longitude = ddVal + (mmVal/_MINUTES) + (ssVal/_SECONDS);
1012 // if longitude designation is Western (WEST) then longitude degree will be negative DD
1013 if (longitudeRef == 'W')
1015 pMetadata->longitude = (pMetadata->longitude * (double)(-1));
1018 else if (tag == EXIF_TAG_WHITE_BALANCE)
1020 pMetadata->pWhiteBalance = new (nothrow) String(buf);
1021 SysTryReturn(NID_CNT, pMetadata->pWhiteBalance != null, null, E_OUT_OF_MEMORY,
1022 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1029 return pImageMetadata.release();
1033 _ContentManagerUtilImpl::GetAudioMetaN(const ByteBuffer& byteBuffer)
1037 int bufferLen = byteBuffer.GetRemaining();
1038 SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
1040 // create here to make sure that get apis will not crash though the below API calls fails in case of invalid file.
1041 unique_ptr<AudioMetadata> pAudioMetadata(new (nothrow) AudioMetadata());
1042 SysTryReturn(NID_CNT, pAudioMetadata != null, null, E_OUT_OF_MEMORY,
1043 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1045 _AudioMetadataImpl* pAudioMetaImpl = _AudioMetadataImpl::GetInstance(*(pAudioMetadata.get()));
1046 SysTryReturn(NID_CNT, pAudioMetaImpl != null, null, E_OUT_OF_MEMORY,
1047 "[E_OUT_OF_MEMORY] pAudioMetaImpl is null.");
1049 AudioMeta* pMetadata = pAudioMetaImpl->GetAudioMetadata();
1050 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
1051 "[E_INVALID_ARG] pMetadata is null.");
1053 // Create the metadata extractor handle
1054 metadata_extractor_h tempExtractor = NULL;
1056 int retVal = metadata_extractor_create(&tempExtractor);
1057 result r = ErrorMapToRetVal(retVal);
1058 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1059 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1061 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
1062 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
1063 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1065 const byte* pByte = byteBuffer.GetPointer();
1067 retVal = metadata_extractor_set_buffer(pExtractor.get(), pByte, bufferLen);
1068 r = ErrorMapToRetVal(retVal);
1069 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1070 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1072 // Get all relavent audio metadata by passing relavent attirbutes
1073 char* pTempAudioMeta = null;
1074 unique_ptr<char, CharDeleter> pAudioMeta(null);
1077 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempAudioMeta);
1078 if (pTempAudioMeta != null)
1080 pAudioMeta.reset(pTempAudioMeta);
1081 pMetadata->bitrate = atoi(pAudioMeta.get());
1085 r = ErrorMapToRetVal(retVal);
1086 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1087 "[%s] metadata_extractor_get_metadata(bitrate) failed.", GetErrorMessage(r));
1091 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_CHANNELS, &pTempAudioMeta);
1092 if (pTempAudioMeta != null)
1094 pAudioMeta.reset(pTempAudioMeta);
1095 pMetadata->channelCount = atoi(pAudioMeta.get());
1099 r = ErrorMapToRetVal(retVal);
1100 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1101 "[%s] metadata_extractor_get_metadata(channels) failed.", GetErrorMessage(r));
1105 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempAudioMeta);
1106 if (pTempAudioMeta != null)
1108 pAudioMeta.reset(pTempAudioMeta);
1109 pMetadata->duration = atoi(pAudioMeta.get());
1113 r = ErrorMapToRetVal(retVal);
1114 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1115 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
1119 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_SAMPLERATE, &pTempAudioMeta);
1120 if (pTempAudioMeta != null)
1122 pAudioMeta.reset(pTempAudioMeta);
1123 pMetadata->frequency = atoi(pAudioMeta.get());
1127 r = ErrorMapToRetVal(retVal);
1128 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1129 "[%s] metadata_extractor_get_metadata(frequency) failed.", GetErrorMessage(r));
1133 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ALBUM, &pTempAudioMeta);
1134 if (pTempAudioMeta != null)
1136 pAudioMeta.reset(pTempAudioMeta);
1137 pMetadata->pAlbumName = new (nothrow) String(pAudioMeta.get());
1138 SysTryReturn(NID_CNT, pMetadata->pAlbumName != null, null, E_OUT_OF_MEMORY,
1139 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1143 r = ErrorMapToRetVal(retVal);
1144 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1145 "[%s] metadata_extractor_get_metadata(album name) failed.", GetErrorMessage(r));
1149 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_ARTIST, &pTempAudioMeta);
1150 if (pAudioMeta.get() != null)
1152 pAudioMeta.reset(pTempAudioMeta);
1153 pMetadata->pArtist = new (nothrow) String(pAudioMeta.get());
1154 SysTryReturn(NID_CNT, pMetadata->pArtist != null, null, E_OUT_OF_MEMORY,
1155 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1159 r = ErrorMapToRetVal(retVal);
1160 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1161 "[%s] metadata_extractor_get_metadata(artist) failed.", GetErrorMessage(r));
1165 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COPYRIGHT, &pTempAudioMeta);
1166 if (pTempAudioMeta != null)
1168 pAudioMeta.reset(pTempAudioMeta);
1169 pMetadata->pCopyright = new (nothrow) String(pAudioMeta.get());
1170 SysTryReturn(NID_CNT, pMetadata->pCopyright != null, null, E_OUT_OF_MEMORY,
1171 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1175 r = ErrorMapToRetVal(retVal);
1176 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1177 "[%s] metadata_extractor_get_metadata(copyright) failed.", GetErrorMessage(r));
1181 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempAudioMeta);
1182 if (pTempAudioMeta != null)
1184 pAudioMeta.reset(pTempAudioMeta);
1185 pMetadata->pGenre = new (nothrow) String(pAudioMeta.get());
1186 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
1187 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1191 r = ErrorMapToRetVal(retVal);
1192 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1193 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
1197 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TITLE, &pTempAudioMeta);
1198 if (pTempAudioMeta != null)
1200 pAudioMeta.reset(pTempAudioMeta);
1201 pMetadata->pTitle = new (nothrow) String(pAudioMeta.get());
1202 SysTryReturn(NID_CNT, pMetadata->pTitle != null, null, E_OUT_OF_MEMORY,
1203 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1207 r = ErrorMapToRetVal(retVal);
1208 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1209 "[%s] metadata_extractor_get_metadata(title) failed.", GetErrorMessage(r));
1213 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempAudioMeta);
1214 if (pTempAudioMeta != null)
1216 pAudioMeta.reset(pTempAudioMeta);
1217 pMetadata->pComment = new (nothrow) String(pAudioMeta.get());
1218 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
1219 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1223 r = ErrorMapToRetVal(retVal);
1224 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1225 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
1229 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempAudioMeta);
1230 if (pTempAudioMeta != null)
1232 pAudioMeta.reset(pTempAudioMeta);
1233 pMetadata->pDescription = new (nothrow) String(pAudioMeta.get());
1234 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
1235 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1239 r = ErrorMapToRetVal(retVal);
1240 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1241 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
1245 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_RECDATE, &pTempAudioMeta);
1246 if (pTempAudioMeta != null)
1248 pAudioMeta.reset(pTempAudioMeta);
1249 pMetadata->pRecordingDate = new (nothrow) String(pAudioMeta.get());
1250 SysTryReturn(NID_CNT, pMetadata->pRecordingDate != null, null, E_OUT_OF_MEMORY,
1251 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1255 r = ErrorMapToRetVal(retVal);
1256 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1257 "[%s] metadata_extractor_get_metadata(recording date) failed.", GetErrorMessage(r));
1261 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUTHOR, &pTempAudioMeta);
1262 if (pTempAudioMeta != null)
1264 pAudioMeta.reset(pTempAudioMeta);
1265 pMetadata->pComposer = new (nothrow) String(pAudioMeta.get());
1266 SysTryReturn(NID_CNT, pMetadata->pComposer != null, null, E_OUT_OF_MEMORY,
1267 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1271 r = ErrorMapToRetVal(retVal);
1272 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1273 "[%s] metadata_extractor_get_metadata(author) failed.", GetErrorMessage(r));
1277 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_TRACK_NUM, &pTempAudioMeta);
1278 if (pTempAudioMeta != null)
1280 pAudioMeta.reset(pTempAudioMeta);
1281 pMetadata->pTrackInfo = new (nothrow) String(pAudioMeta.get());
1282 SysTryReturn(NID_CNT, pMetadata->pTrackInfo != null, null, E_OUT_OF_MEMORY,
1283 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1285 // if the string contains the track info like track num/track position,
1286 // then track position will be ignored and only track num is returned
1287 // no need to parse this string, since only track number is required
1288 pMetadata->trackNum = atoi(pAudioMeta.get());
1292 r = ErrorMapToRetVal(retVal);
1293 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1294 "[%s] metadata_extractor_get_metadata(track info) failed.", GetErrorMessage(r));
1298 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DATE, &pTempAudioMeta);
1299 if (pTempAudioMeta != null)
1301 pAudioMeta.reset(pTempAudioMeta);
1302 pMetadata->year = atoi(pAudioMeta.get());
1306 r = ErrorMapToRetVal(retVal);
1307 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1308 "[%s] metadata_extractor_get_metadata(date) failed.", GetErrorMessage(r));
1313 void* pTempArtwork = null;
1314 unique_ptr<void, VoidDeleter> pArtwork(null);
1316 // Get the artwork image in media file
1317 retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempAudioMeta);
1318 pAudioMeta.reset(pTempAudioMeta);
1320 //Check if the albumart present and pass it to client if it is successfully processed, otherwise ignore any errors
1321 //while processing albumart. This is to pass the other metadata tags to application.
1322 if (pTempArtwork != null)
1324 pArtwork.reset(pTempArtwork);
1327 ImageFormat format = IMG_FORMAT_NONE;
1330 r = buffer.Construct(size);
1331 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
1333 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
1336 r = img.Construct();
1339 format = img.GetImageFormat(buffer);
1340 pMetadata->pThumbnail = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888,
1341 _THUMBNAIL_IMAGE_WIDTH, _THUMBNAIL_IMAGE_HEIGHT);
1342 if (pMetadata->pThumbnail == null)
1344 // Because Thumbnail is one of the metadata, it is not exception in this function.
1345 SysLog(NID_CNT, "DecodeN failed.");
1347 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
1348 if (pMetadata->pAlbumArt == null)
1350 // Because Album Art is one of the metadata, it is not exception in this function.
1351 SysLog(NID_CNT, "DecodeN failed.");
1359 r = ErrorMapToRetVal(retVal);
1360 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1361 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
1364 return pAudioMetadata.release();
1368 _ContentManagerUtilImpl::GetVideoMetaN(const ByteBuffer& byteBuffer)
1372 int bufferLen = byteBuffer.GetRemaining();
1373 SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
1375 // need to create here to make sure that all get APIs will not crash in case of corrupted file
1376 unique_ptr<VideoMetadata> pVideoMetadata(new (nothrow) VideoMetadata());
1377 SysTryReturn(NID_CNT, pVideoMetadata != null, null, E_OUT_OF_MEMORY,
1378 "[E_OUT_OF_MEMORY] The memory insufficient.");
1380 _VideoMetadataImpl* pVideoMetaImpl = _VideoMetadataImpl::GetInstance(*(pVideoMetadata.get()));
1381 SysTryReturn(NID_CNT, pVideoMetaImpl != null, null, E_OUT_OF_MEMORY,
1382 "[E_OUT_OF_MEMORY] pVideoMetaImpl is null.");
1384 VideoMeta* pMetadata = pVideoMetaImpl->GetVideoMetadata();
1385 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
1386 "[E_INVALID_ARG] pMetadata is null.");
1388 // Create the metadata extractor handle
1389 metadata_extractor_h tempExtractor = NULL;
1391 int retVal = metadata_extractor_create(&tempExtractor);
1392 result r = ErrorMapToRetVal(retVal);
1393 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1394 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1396 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
1397 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
1398 "[E_OUT_OF_MEMORY] The memory insufficient.");
1400 const byte* pByte = byteBuffer.GetPointer();
1402 retVal = metadata_extractor_set_buffer(pExtractor.get(), pByte, bufferLen);
1403 r = ErrorMapToRetVal(retVal);
1404 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1405 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1407 // Get all relavent video metadata by passing relavent attirbutes
1408 char* pTempVideoMeta = null;
1409 unique_ptr<char, CharDeleter> pVideoMeta(null);
1412 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_WIDTH, &pTempVideoMeta);
1413 if (pTempVideoMeta != null)
1415 pVideoMeta.reset(pTempVideoMeta);
1416 pMetadata->width = atoi(pVideoMeta.get());
1420 r = ErrorMapToRetVal(retVal);
1421 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1422 "[%s] metadata_extractor_get_metadata(width) failed.", GetErrorMessage(r));
1426 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_HEIGHT, &pTempVideoMeta);
1427 if (pTempVideoMeta != null)
1429 pVideoMeta.reset(pTempVideoMeta);
1430 pMetadata->height = atoi(pVideoMeta.get());
1434 r = ErrorMapToRetVal(retVal);
1435 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1436 "[%s] metadata_extractor_get_metadata(height) failed.", GetErrorMessage(r));
1440 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_BITRATE, &pTempVideoMeta);
1441 if (pTempVideoMeta != null)
1443 pVideoMeta.reset(pTempVideoMeta);
1444 pMetadata->videoBitrate = atoi(pVideoMeta.get());
1448 r = ErrorMapToRetVal(retVal);
1449 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1450 "[%s] metadata_extractor_get_metadata(video bitrate) failed.", GetErrorMessage(r));
1454 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_AUDIO_BITRATE, &pTempVideoMeta);
1455 if (pTempVideoMeta != null)
1457 pVideoMeta.reset(pTempVideoMeta);
1458 pMetadata->audioBitrate = atoi(pVideoMeta.get());
1462 r = ErrorMapToRetVal(retVal);
1463 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1464 "[%s] metadata_extractor_get_metadata(audio bitrate) failed.", GetErrorMessage(r));
1468 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_VIDEO_FPS, &pTempVideoMeta);
1469 if (pTempVideoMeta != null)
1471 pVideoMeta.reset(pTempVideoMeta);
1472 pMetadata->framerate = atoi(pVideoMeta.get());
1476 r = ErrorMapToRetVal(retVal);
1477 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1478 "[%s] metadata_extractor_get_metadata(framerate) failed.", GetErrorMessage(r));
1482 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DURATION, &pTempVideoMeta);
1483 if (pTempVideoMeta != null)
1485 pVideoMeta.reset(pTempVideoMeta);
1486 pMetadata->duration = atoi(pVideoMeta.get());
1490 r = ErrorMapToRetVal(retVal);
1491 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1492 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
1496 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_GENRE, &pTempVideoMeta);
1497 if (pTempVideoMeta != null)
1499 pVideoMeta.reset(pTempVideoMeta);
1500 pMetadata->pGenre = new (nothrow) String(pVideoMeta.get()); //allocate memory
1501 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
1502 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1506 r = ErrorMapToRetVal(retVal);
1507 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1508 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
1512 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_COMMENT, &pTempVideoMeta);
1513 if (pTempVideoMeta != null)
1515 pVideoMeta.reset(pTempVideoMeta);
1516 pMetadata->pComment = new (nothrow) String(pVideoMeta.get());
1517 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
1518 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1522 r = ErrorMapToRetVal(retVal);
1523 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1524 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
1528 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_DESCRIPTION, &pTempVideoMeta);
1529 if (pTempVideoMeta != null)
1531 pVideoMeta.reset(pTempVideoMeta);
1532 pMetadata->pDescription = new (nothrow) String(pVideoMeta.get());
1533 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
1534 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1538 r = ErrorMapToRetVal(retVal);
1539 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1540 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
1545 void* pTempArtwork = null;
1546 unique_ptr<void, VoidDeleter> pArtwork(null);
1548 // Get the artwork image in media file
1549 retVal = metadata_extractor_get_artwork(pExtractor.get(), &pTempArtwork, &size, &pTempVideoMeta);
1550 pVideoMeta.reset(pTempVideoMeta);
1551 if (pTempArtwork != null)
1553 pArtwork.reset(pTempArtwork);
1556 ImageFormat format = IMG_FORMAT_NONE;
1559 r = buffer.Construct(size);
1560 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
1562 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
1565 r = img.Construct();
1568 format = img.GetImageFormat(buffer);
1570 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
1571 if (pMetadata->pAlbumArt == null)
1573 // Because Album Art is one of the metadata, it is not exception in this function.
1574 SysLog(NID_CNT, "DecodeN failed.");
1582 r = ErrorMapToRetVal(retVal);
1583 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1584 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
1587 return pVideoMetadata.release();
1591 _ContentManagerUtilImpl::CheckContentType(const String& contentPath, bool internal)
1595 ContentType contentType = CONTENT_TYPE_UNKNOWN;
1596 String mimeType(L"");
1600 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), contentType, E_INVALID_ARG,
1601 "[E_INVALID_ARG] The path is not compatible.");
1603 SysTryReturn(NID_CNT, contentPath.GetLength() != 0, contentType, E_INVALID_ARG,
1604 "[E_INVALID_ARG] The length of contentPath is 0.");
1605 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), contentType, E_FILE_NOT_FOUND,
1606 "[E_FILE_NOT_FOUND] The file corresponding to contentPath could not be found.");
1608 String fileExt = _FileImpl::GetFileExtension(contentPath);
1609 result r = GetLastResult();
1613 unique_ptr<char[]> pFormat(_StringConverter::CopyToCharArrayN(fileExt));
1614 SysTryReturn(NID_CNT, pFormat != null, contentType, E_OUT_OF_MEMORY,
1615 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1617 char* pTempMimeType = null;
1618 int retVal = mime_type_get_mime_type(pFormat.get(), &pTempMimeType);
1619 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, E_INVALID_ARG,
1620 "[E_INVALID_ARG] mime_type_get_mime_type failed.");
1621 SysTryReturn(NID_CNT, pTempMimeType != null, contentType, E_INVALID_ARG,
1622 "[E_INVALID_ARG] mime_type_get_mime_type failed.");
1624 unique_ptr<char, CharDeleter> pMimeType;
1625 pMimeType.reset(pTempMimeType);
1627 SysLog(NID_CNT, "The MIME type for %ls is %s", fileExt.GetPointer(), pTempMimeType);
1629 r = mimeType.Append(pMimeType.get());
1630 SysTryReturn(NID_CNT, !IsFailed(r), contentType, E_OUT_OF_MEMORY,
1631 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1637 SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
1639 unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(contentPath));
1640 SysTryReturn(NID_CNT, pTempPath != null, contentType, E_OUT_OF_MEMORY,
1641 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1643 char tempType[255] = {0, };
1644 int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
1645 SysTryReturn(NID_CNT, ret == AUL_R_OK, contentType, E_INVALID_ARG,
1646 "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
1648 r = mimeType.Append(tempType);
1649 SysTryReturn(NID_CNT, !IsFailed(r), contentType, E_OUT_OF_MEMORY,
1650 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1653 if (mimeType.Contains(L"image"))
1655 return CONTENT_TYPE_IMAGE;
1657 else if (mimeType.Contains(L"audio"))
1659 if (mimeType.Contains(L"x-mpegurl"))
1661 SysLog(NID_CNT, "The type of x-mpegurl is other.");
1662 return CONTENT_TYPE_OTHER;
1664 return CONTENT_TYPE_AUDIO;
1666 else if (mimeType.Contains(L"video"))
1668 if (mimeType == L"video/3gpp" || mimeType == L"video/mp4")
1670 return CheckStream(contentPath);
1672 return CONTENT_TYPE_VIDEO;
1674 else if (mimeType.Contains(L"application"))
1676 if (mimeType.Contains(L"x-smaf"))
1678 SysLog(NID_CNT, "The type of x-smaf is audio.");
1679 return CONTENT_TYPE_AUDIO;
1681 return CONTENT_TYPE_OTHER;
1684 return CONTENT_TYPE_OTHER;
1688 _ContentManagerUtilImpl::CheckStream(const String& contentPath)
1692 ContentType contentType = CONTENT_TYPE_UNKNOWN;
1693 metadata_extractor_h tempExtractor = NULL;
1695 int retVal = metadata_extractor_create(&tempExtractor);
1696 result r = ErrorMapToRetVal(retVal);
1697 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
1698 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1700 unique_ptr<metadata_extractor_s, ExtractorDeleter> pExtractor(tempExtractor);
1701 SysTryReturn(NID_CNT, pExtractor != null, contentType, E_OUT_OF_MEMORY,
1702 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1704 //Set the file path to extract metadata.
1705 unique_ptr<char[]> pContentPath(_StringConverter::CopyToCharArrayN(contentPath));
1706 SysTryReturn(NID_CNT, pContentPath != null, contentType, E_INVALID_ARG,
1707 "[E_INVALID_ARG] The memory is insufficient.");
1709 retVal = metadata_extractor_set_path(pExtractor.get(), pContentPath.get());
1710 r = ErrorMapToRetVal(retVal);
1711 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE && pExtractor, contentType, r,
1712 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1714 //Check whether it is an audio or video file.
1715 char* pTempAudio = null;
1716 unique_ptr<char, CharDeleter> pAudio(null);
1718 char* pTempVideo = null;
1719 unique_ptr<char, CharDeleter> pVideo(null);
1721 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_HAS_AUDIO, &pTempAudio);
1722 if (pTempAudio != null)
1724 pAudio.reset(pTempAudio);
1728 r = ErrorMapToRetVal(retVal);
1729 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
1730 "[%s] metadata_extractor_get_metadata failed.", GetErrorMessage(r));
1733 retVal = metadata_extractor_get_metadata(pExtractor.get(), METADATA_HAS_VIDEO, &pTempVideo);
1734 if (pTempVideo != null)
1736 pVideo.reset(pTempVideo);
1740 r = ErrorMapToRetVal(retVal);
1741 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
1742 "[%s] metadata_extractor_get_metadata failed.", GetErrorMessage(r));
1745 if (*(pAudio.get()) > '0' && *(pVideo.get()) == '0')
1747 SysLog(NID_CNT, "The result of CheckStream() is audio");
1748 return CONTENT_TYPE_AUDIO;
1750 else if (*(pAudio.get()) == '0' && *(pVideo.get()) > '0')
1752 SysLog(NID_CNT, "The result of CheckStream() is video");
1753 return CONTENT_TYPE_VIDEO;
1755 else if (*(pAudio.get()) > '0' && *(pVideo.get()) > '0')
1757 SysLog(NID_CNT, "The result of CheckStream() is video");
1758 return CONTENT_TYPE_VIDEO;
1762 SysLogException(NID_CNT, E_UNSUPPORTED_FORMAT, "[E_UNSUPPORTED_FORMAT] The stream is empty.");
1769 _ContentManagerUtilImpl::VerifyFilePathCompatibility(const String& contentPath)
1771 if (!_AppInfo::IsOspCompat())
1773 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0)
1774 || contentPath.StartsWith(OSP_HOME, 0))
1776 SysLogException(NID_CNT, E_INVALID_ARG,
1777 "/Home, /Media/, or /Storagecard/Media/ is not supported from Tizen 2.0.");
1784 if (!(contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0)
1785 || contentPath.StartsWith(OSP_HOME, 0)))
1787 SysLogException(NID_CNT, E_INVALID_ARG,
1788 "The contentPath should start with /Home, /Media, or /Storagecard/Media.");
1797 _ContentManagerUtilImpl::ErrorMapToRetVal(int retVal)
1799 result r = E_SUCCESS;
1803 case METADATA_EXTRACTOR_ERROR_NONE:
1806 case METADATA_EXTRACTOR_ERROR_INVALID_PARAMETER:
1809 case METADATA_EXTRACTOR_ERROR_OUT_OF_MEMORY:
1810 r = E_OUT_OF_MEMORY;
1812 case METADATA_EXTRACTOR_ERROR_FILE_EXISTS:
1815 case METADATA_EXTRACTOR_ERROR_OPERATION_FAILED:
1824 _ContentManagerUtilImpl::CopyToMediaDirectory(const String& srcContentPath, const String& destContentPath)
1828 // For srcContentPath
1829 SysTryReturn(NID_CNT, !_FileImpl::IsSystemPath(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1830 "[E_INVALID_ARG] Can not copy the file in the system region.");
1831 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1832 "[E_INVALID_ARG] Can not find the file.");
1834 // For destContentPath
1835 SysTryReturn(NID_CNT, _FileImpl::IsMediaPath(destContentPath), E_INVALID_ARG, E_INVALID_ARG,
1836 "[E_INVALID_ARG] The destination path should start with /Media or /Storagecard/Media.");
1838 // E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_FILE_NOT_FOUND, E_FILE_ALREADY_EXIST, E_MAX_EXCEEDED, E_STORAGE_FULL, E_IO
1839 result r = E_SUCCESS;
1840 r = _FileImpl::Copy(srcContentPath, destContentPath, true);
1841 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] CopyToMediaDirectory failed.", GetErrorMessage(r));
1847 _ContentManagerUtilImpl::MoveToMediaDirectory(const String& srcContentPath, const String& destContentPath)
1851 // For srcContentPath
1852 SysTryReturn(NID_CNT, !_FileImpl::IsSystemPath(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1853 "[E_INVALID_ARG] Can not copy the file in the system region.");
1854 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1855 "[E_INVALID_ARG] Can not find the file.");
1857 // For destContentPath
1858 SysTryReturn(NID_CNT, _FileImpl::IsMediaPath(destContentPath), E_INVALID_ARG, E_INVALID_ARG,
1859 "[E_INVALID_ARG] The destination path should start with /Media or /Storagecard/Media.");
1861 // E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_FILE_NOT_FOUND, E_FILE_ALREADY_EXIST, E_MAX_EXCEEDED, E_STORAGE_FULL, E_IO
1862 result r = E_SUCCESS;
1863 r = _FileImpl::Move(srcContentPath, destContentPath);
1864 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] MoveToMediaDirectory failed.", GetErrorMessage(r));