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.
24 #include <mime_type.h>
25 #include <FBaseSysLog.h>
26 #include <FBaseByteBuffer.h>
27 #include <FIoDirectory.h>
29 #include <FSysEnvironment.h>
30 #include <FMediaImage.h>
31 #include <FMediaImageBuffer.h>
32 #include <FMediaImageUtil.h>
33 #include <FCntImageMetadata.h>
34 #include <FCntAudioMetadata.h>
35 #include <FCntVideoMetadata.h>
36 #include <FCnt_ContentManagerUtilImpl.h>
37 #include <FCnt_AudioMetadataImpl.h>
38 #include <FCnt_VideoMetadataImpl.h>
39 #include <FCnt_ImageMetadataImpl.h>
40 #include <FBase_StringConverter.h>
41 #include <FIo_FileImpl.h>
42 #include <FGrp_BitmapImpl.h>
43 #include <FMedia_ImageDecoder.h>
44 #include <FMedia_ImageImpl.h>
45 #include <FApp_AppInfo.h>
47 using namespace Tizen::Base;
48 using namespace Tizen::Io;
49 using namespace Tizen::Media;
50 using namespace Tizen::Graphics;
51 using namespace Tizen::App;
52 using namespace Tizen::System;
55 namespace Tizen { namespace Content
57 // Types of content, format supported and default values
58 static const int IMAGE_BUFF_LENGTH = 100;
59 static const int THUMBNAIL_IMAGE_WIDTH = 80;
60 static const int THUMBNAIL_IMAGE_HEIGHT = 60;
61 static const int MINUTES = 60;
62 static const int SECONDS = 3600;
70 _ContentManagerUtilImpl::GetImageMetaN(const String& contentPath, bool internal)
76 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), null, E_INVALID_ARG,
77 "[E_INVALID_ARG] The path is not compatible.");
79 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_INVALID_ARG,
80 "[E_INVALID_ARG] The file corresponding to contentPath could not be found.");
82 // create object here as it needs to be passed to client in any case to make sure Get APIs do not crash
83 unique_ptr<ImageMetadata> pImageMetadata(new (nothrow) ImageMetadata());
84 SysTryReturn(NID_CNT, pImageMetadata != null, null, E_OUT_OF_MEMORY,
85 "[E_OUT_OF_MEMORY] pImageMetadata is null.");
87 _ImageMetadataImpl* pImageMetaImpl = _ImageMetadataImpl::GetInstance(*(pImageMetadata.get()));
88 SysTryReturn(NID_CNT, pImageMetaImpl != null, null, E_OUT_OF_MEMORY,
89 "[E_OUT_OF_MEMORY] pImageMetaImpl is null.");
91 ImageMeta* pMetadata = pImageMetaImpl->GetImageMetadata();
92 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
93 "[E_INVALID_ARG] pMetadata is null.");
95 //assign by default here and overwrite below if width and height presents in EXIF data.
96 ImageFormat imgType = IMG_FORMAT_NONE;
99 result r = _ImageImpl::GetImageInfo(contentPath, imgType, dim);
100 SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_INVALID_ARG,
101 "[E_INVALID_ARG] GetImageInfo failed.");
103 pMetadata->width = dim.width;
104 pMetadata->height = dim.height;
105 pMetadata->contentPath = contentPath;
107 if (imgType == IMG_FORMAT_JPG)
109 unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(contentPath));
110 SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
111 "[E_OUT_OF_MEMORY] The memory is insufficient.");
113 unique_ptr<ExifData, ExifDataDeleter> pExifdata(exif_data_new_from_file(pFileName.get()));
114 if (pExifdata != null)
117 ExifByteOrder byteOrder;
118 ExifEntry** pEntries = null;
119 const char* pData = null;
120 char buf[IMAGE_BUFF_LENGTH] = {0, };
121 char mmBuff[IMAGE_BUFF_LENGTH] = {0, }; // to store minutes value of GPS data
122 char ssBuff[IMAGE_BUFF_LENGTH] = {0, }; // to store seconds value of GPS data
123 ExifContent* pExifcont[EXIF_IFD_COUNT];
125 char latitudeRef = 0; // to store latitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
126 char longitudeRef = 0; // to store longitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
127 unsigned int entryCount = 0;
129 for (int i = 0; i < EXIF_IFD_COUNT; i++)
131 pExifcont[i] = pExifdata->ifd[i];
132 entryCount = pExifcont[i]->count;
133 pEntries = pExifcont[i]->entries;
134 for (unsigned int j = 0; j < entryCount; j++)
136 tag = pEntries[j]->tag;
137 pData = exif_entry_get_value(pEntries[j], buf, sizeof(buf));
138 SysTryReturn(NID_CNT, pData != null, pImageMetadata.release(), E_INVALID_ARG,
139 "[E_INVALID_ARG] exif_entry_get_value failed.");
141 if (tag == EXIF_TAG_PIXEL_X_DIMENSION)
143 pMetadata->width = atoi(buf);
145 else if (tag == EXIF_TAG_PIXEL_Y_DIMENSION)
147 pMetadata->height = atoi(buf);
149 else if (tag == EXIF_TAG_MAKE)
151 pMetadata->pManufacturer = new (nothrow) String(buf);
152 SysTryReturn(NID_CNT, pMetadata->pManufacturer != null, null, E_OUT_OF_MEMORY,
153 "[E_OUT_OF_MEMORY] The memory is insufficient.");
155 else if (tag == EXIF_TAG_MODEL)
157 pMetadata->pModel = new (nothrow) String(buf);
158 SysTryReturn(NID_CNT, pMetadata->pModel != null, null, E_OUT_OF_MEMORY,
159 "[E_OUT_OF_MEMORY] The memory is insufficient.");
161 else if (tag == EXIF_TAG_DATE_TIME)
163 pMetadata->pDateTime = new (nothrow) String(buf);
164 SysTryReturn(NID_CNT, pMetadata->pDateTime != null, null, E_OUT_OF_MEMORY,
165 "[E_OUT_OF_MEMORY] The memory is insufficient.");
167 else if (tag == EXIF_TAG_ORIENTATION)
169 //get the byte order(little endian or big endian) before extracting orientation type
170 byteOrder = exif_data_get_byte_order(pEntries[j]->parent->parent);
171 pMetadata->orientation = static_cast<ImageOrientationType>(exif_get_short(pEntries[j]->data, byteOrder));
173 else if (tag == EXIF_TAG_SOFTWARE)
175 pMetadata->pSoftware = new (nothrow) String(buf);
176 SysTryReturn(NID_CNT, pMetadata->pSoftware != null, null, E_OUT_OF_MEMORY,
177 "[E_OUT_OF_MEMORY] The memory is insufficient.");
179 else if (tag == EXIF_TAG_GPS_LATITUDE_REF)
181 latitudeRef = buf[0]; // GPS Latitude reference value will be 'N'(NORTH) or 'S'(SOUTH)
183 else if (tag == EXIF_TAG_GPS_LATITUDE)
185 ParseBuffer(buf, index); // to extract the minutes value of GPS data, if present
186 for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++)
188 mmBuff[l] = buf[l + index + 1]; //add 1 to skip the ','
190 index = 0; //re-assign index value as this is new buffer
191 ParseBuffer(mmBuff, index); // to extract the seconds value of GPS data, if present
192 for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++)
194 ssBuff[l] = mmBuff[l + index + 1]; //add 1 to skip the ','
198 std::unique_ptr<char> pCurrentLocal(null);
199 pLocal = setlocale (LC_ALL, 0); // Get the name of the current locale.
202 SysLog(NID_CNT, "setlocale failed. (get current locale)");
205 pCurrentLocal.reset(strdup (pLocal));
207 pLocal = setlocale(LC_ALL, "C");
210 SysLog(NID_CNT, "setlocale failed. (set POSIX C locale)");
214 double ddVal = atof(buf); // degree value
215 double mmVal = atof(mmBuff); // minutesvalue
216 double ssVal = atof(ssBuff); // seconds value
218 pLocal = setlocale (LC_ALL, pCurrentLocal.get()); // restore the locale.
221 SysLog(NID_CNT, "setlocale failed. (set current locale)");
225 pMetadata->latitude = ddVal + (mmVal/MINUTES) + (ssVal/SECONDS);
227 // if latitude designation is Southern (SOUTH) then latitude degree will be negative DD
228 if (latitudeRef == 'S')
230 pMetadata->latitude = (pMetadata->latitude * (double)(-1));
233 else if (tag == EXIF_TAG_GPS_LONGITUDE_REF)
235 longitudeRef = buf[0]; // GPS Longitude reference value will be 'W'(WEST) or 'E'(EAST)
237 else if (tag == EXIF_TAG_GPS_LONGITUDE)
239 index = 0; //re-assign index value as this is new buffer
240 ParseBuffer(buf, index); // to extract the minutes value of GPS data, if present
241 for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++)
243 mmBuff[l] = buf[l + index + 1]; //add 1 to skip the ','
245 index = 0; //re-assign index value as this is new buffer
246 ParseBuffer(mmBuff, index); // to extract the seconds value of GPS data, if present
247 for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++)
249 ssBuff[l] = mmBuff[l + index + 1]; //add 1 to skip the ','
253 std::unique_ptr<char> pCurrentLocal(null);
254 pLocal = setlocale (LC_ALL, 0); // Get the name of the current locale.
257 SysLog(NID_CNT, "setlocale failed. (get current locale)");
260 pCurrentLocal.reset(strdup (pLocal));
262 pLocal = setlocale(LC_ALL, "C");
265 SysLog(NID_CNT, "setlocale failed. (set POSIX C locale)");
269 double ddVal = atof(buf); // degree value
270 double mmVal = atof(mmBuff); // minutesvalue
271 double ssVal = atof(ssBuff); // seconds value
273 pLocal = setlocale (LC_ALL, pCurrentLocal.get()); // restore the locale.
276 SysLog(NID_CNT, "setlocale failed. (set current locale)");
280 pMetadata->longitude = ddVal + (mmVal/MINUTES) + (ssVal/SECONDS);
282 // if longitude designation is Western (WEST) then longitude degree will be negative DD
283 if (longitudeRef == 'W')
285 pMetadata->longitude = (pMetadata->longitude * (double)(-1));
288 else if (tag == EXIF_TAG_WHITE_BALANCE)
290 pMetadata->pWhiteBalance = new (nothrow) String(buf);
291 SysTryReturn(NID_CNT, pMetadata->pWhiteBalance != null, null, E_OUT_OF_MEMORY,
292 "[E_OUT_OF_MEMORY] The memory is insufficient.");
299 return pImageMetadata.release();
303 _ContentManagerUtilImpl::ParseBuffer(char* pBuffer, int& count)
305 if ((*pBuffer != ',') && (*pBuffer != '\0')) // parse the buffer till ',' or '\0' and return the index
307 ParseBuffer(++pBuffer, ++count);
317 _ContentManagerUtilImpl::GetAudioMetaN(const String& contentPath)
321 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), null, E_INVALID_ARG,
322 "[E_INVALID_ARG] The path is not compatible.");
323 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_INVALID_ARG,
324 "[E_INVALID_ARG] The file corresponding to contentPath could not be found.");
326 // create here to make sure that get apis will not crash though the below API calls fails in case of invalid file.
327 unique_ptr<AudioMetadata> pAudioMetadata(new (nothrow) AudioMetadata());
328 SysTryReturn(NID_CNT, pAudioMetadata != null, null, E_OUT_OF_MEMORY,
329 "[E_OUT_OF_MEMORY] The memory is insufficient.");
331 _AudioMetadataImpl* pAudioMetaImpl = _AudioMetadataImpl::GetInstance(*(pAudioMetadata.get()));
332 SysTryReturn(NID_CNT, pAudioMetaImpl != null, null, E_OUT_OF_MEMORY,
333 "[E_OUT_OF_MEMORY] pAudioMetaImpl is null.");
335 AudioMeta* pMetadata = pAudioMetaImpl->GetAudioMetadata();
336 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
337 "[E_INVALID_ARG] pMetadata is null.");
339 pMetadata->contentPath = contentPath;
341 // Create the metadata extractor handle
342 unique_ptr<metadata_extractor_h, ExtractorDeleter> pExtractor(new (nothrow) metadata_extractor_h);
343 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
344 "[E_OUT_OF_MEMORY] The memory is insufficient.");
346 int retVal = metadata_extractor_create(pExtractor.get());
347 result r = ErrorMapToRetVal(retVal);
348 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
349 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
351 // Set file path of content to extract the metadata
352 unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(contentPath));
353 SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
354 "[E_OUT_OF_MEMORY] The memory is insufficient.");
356 retVal = metadata_extractor_set_path(*(pExtractor.get()), pFileName.get());
357 r = ErrorMapToRetVal(retVal);
358 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
359 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
361 // Get all relavent audio metadata by passing relavent attirbutes
362 char* __pAudioMeta = null;
363 unique_ptr<char, CharDeleter> pAudioMeta(null);
366 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_AUDIO_BITRATE, &__pAudioMeta);
367 if (__pAudioMeta != null)
369 pAudioMeta.reset(__pAudioMeta);
370 pMetadata->bitrate = atoi(pAudioMeta.get());
374 r = ErrorMapToRetVal(retVal);
375 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
376 "[%s] metadata_extractor_get_metadata(bitrate) failed.", GetErrorMessage(r));
380 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_AUDIO_CHANNELS, &__pAudioMeta);
381 if (__pAudioMeta != null)
383 pAudioMeta.reset(__pAudioMeta);
384 pMetadata->channelCount = atoi(pAudioMeta.get());
388 r = ErrorMapToRetVal(retVal);
389 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
390 "[%s] metadata_extractor_get_metadata(channels) failed.", GetErrorMessage(r));
394 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_DURATION, &__pAudioMeta);
395 if (__pAudioMeta != null)
397 pAudioMeta.reset(__pAudioMeta);
398 pMetadata->duration = atoi(pAudioMeta.get());
402 r = ErrorMapToRetVal(retVal);
403 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
404 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
408 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_AUDIO_SAMPLERATE, &__pAudioMeta);
409 if (__pAudioMeta != null)
411 pAudioMeta.reset(__pAudioMeta);
412 pMetadata->frequency = atoi(pAudioMeta.get());
416 r = ErrorMapToRetVal(retVal);
417 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
418 "[%s] metadata_extractor_get_metadata(frequency) failed.", GetErrorMessage(r));
422 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_ALBUM, &__pAudioMeta);
423 if (__pAudioMeta != null)
425 pAudioMeta.reset(__pAudioMeta);
426 pMetadata->pAlbumName = new (nothrow) String(pAudioMeta.get());
427 SysTryReturn(NID_CNT, pMetadata->pAlbumName != null, null, E_OUT_OF_MEMORY,
428 "[E_OUT_OF_MEMORY] The memory is insufficient.");
432 r = ErrorMapToRetVal(retVal);
433 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
434 "[%s] metadata_extractor_get_metadata(album name) failed.", GetErrorMessage(r));
438 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_ARTIST, &__pAudioMeta);
439 if (pAudioMeta.get() != null)
441 pAudioMeta.reset(__pAudioMeta);
442 pMetadata->pArtist = new (nothrow) String(pAudioMeta.get());
443 SysTryReturn(NID_CNT, pMetadata->pArtist != null, null, E_OUT_OF_MEMORY,
444 "[E_OUT_OF_MEMORY] The memory is insufficient.");
448 r = ErrorMapToRetVal(retVal);
449 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
450 "[%s] metadata_extractor_get_metadata(artist) failed.", GetErrorMessage(r));
454 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_COPYRIGHT, &__pAudioMeta);
455 if (__pAudioMeta != null)
457 pAudioMeta.reset(__pAudioMeta);
458 pMetadata->pCopyright = new (nothrow) String(pAudioMeta.get());
459 SysTryReturn(NID_CNT, pMetadata->pCopyright != null, null, E_OUT_OF_MEMORY,
460 "[E_OUT_OF_MEMORY] The memory is insufficient.");
464 r = ErrorMapToRetVal(retVal);
465 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
466 "[%s] metadata_extractor_get_metadata(copyright) failed.", GetErrorMessage(r));
470 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_GENRE, &__pAudioMeta);
471 if (__pAudioMeta != null)
473 pAudioMeta.reset(__pAudioMeta);
474 pMetadata->pGenre = new (nothrow) String(pAudioMeta.get());
475 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
476 "[E_OUT_OF_MEMORY] The memory is insufficient.");
480 r = ErrorMapToRetVal(retVal);
481 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
482 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
486 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_TITLE, &__pAudioMeta);
487 if (__pAudioMeta != null)
489 pAudioMeta.reset(__pAudioMeta);
490 pMetadata->pTitle = new (nothrow) String(pAudioMeta.get());
491 SysTryReturn(NID_CNT, pMetadata->pTitle != null, null, E_OUT_OF_MEMORY,
492 "[E_OUT_OF_MEMORY] The memory is insufficient.");
496 r = ErrorMapToRetVal(retVal);
497 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
498 "[%s] metadata_extractor_get_metadata(title) failed.", GetErrorMessage(r));
502 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_COMMENT, &__pAudioMeta);
503 if (__pAudioMeta != null)
505 pAudioMeta.reset(__pAudioMeta);
506 pMetadata->pComment = new (nothrow) String(pAudioMeta.get());
507 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
508 "[E_OUT_OF_MEMORY] The memory is insufficient.");
512 r = ErrorMapToRetVal(retVal);
513 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
514 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
518 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_DESCRIPTION, &__pAudioMeta);
519 if (__pAudioMeta != null)
521 pAudioMeta.reset(__pAudioMeta);
522 pMetadata->pDescription = new (nothrow) String(pAudioMeta.get());
523 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
524 "[E_OUT_OF_MEMORY] The memory is insufficient.");
528 r = ErrorMapToRetVal(retVal);
529 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
530 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
534 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_RECDATE, &__pAudioMeta);
535 if (__pAudioMeta != null)
537 pAudioMeta.reset(__pAudioMeta);
538 pMetadata->pRecordingDate = new (nothrow) String(pAudioMeta.get());
539 SysTryReturn(NID_CNT, pMetadata->pRecordingDate != null, null, E_OUT_OF_MEMORY,
540 "[E_OUT_OF_MEMORY] The memory is insufficient.");
544 r = ErrorMapToRetVal(retVal);
545 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
546 "[%s] metadata_extractor_get_metadata(recording date) failed.", GetErrorMessage(r));
550 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_AUTHOR, &__pAudioMeta);
551 if (__pAudioMeta != null)
553 pAudioMeta.reset(__pAudioMeta);
554 pMetadata->pComposer = new (nothrow) String(pAudioMeta.get());
555 SysTryReturn(NID_CNT, pMetadata->pComposer != null, null, E_OUT_OF_MEMORY,
556 "[E_OUT_OF_MEMORY] The memory is insufficient.");
560 r = ErrorMapToRetVal(retVal);
561 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
562 "[%s] metadata_extractor_get_metadata(author) failed.", GetErrorMessage(r));
566 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_TRACK_NUM, &__pAudioMeta);
567 if (__pAudioMeta != null)
569 pAudioMeta.reset(__pAudioMeta);
570 pMetadata->pTrackInfo = new (nothrow) String(pAudioMeta.get());
571 SysTryReturn(NID_CNT, pMetadata->pTrackInfo != null, null, E_OUT_OF_MEMORY,
572 "[E_OUT_OF_MEMORY] The memory is insufficient.");
574 // if the string contains the track info like track num/track position,
575 // then track position will be ignored and only track num is returned
576 // no need to parse this string, since only track number is required
577 pMetadata->trackNum = atoi(pAudioMeta.get());
581 r = ErrorMapToRetVal(retVal);
582 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
583 "[%s] metadata_extractor_get_metadata(track info) failed.", GetErrorMessage(r));
587 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_DATE, &__pAudioMeta);
588 if (__pAudioMeta != null)
590 pAudioMeta.reset(__pAudioMeta);
591 pMetadata->year = atoi(pAudioMeta.get());
595 r = ErrorMapToRetVal(retVal);
596 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
597 "[%s] metadata_extractor_get_metadata(date) failed.", GetErrorMessage(r));
602 void* __pArtwork = null;
603 unique_ptr<void, VoidDeleter> pArtwork(null);
605 // Get the artwork image in media file
606 retVal = metadata_extractor_get_artwork(*(pExtractor.get()), &__pArtwork, &size, &__pAudioMeta);
608 //Check if the albumart present and pass it to client if it is successfully processed, otherwise ignore any errors
609 //while processing albumart. This is to pass the other metadata tags to application.
610 if (__pArtwork != null)
612 pArtwork.reset(__pArtwork);
615 ImageFormat format = IMG_FORMAT_NONE;
618 r = buffer.Construct(size);
619 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
621 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
627 format = img.GetImageFormat(buffer);
628 pMetadata->pThumbnail = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888,
629 THUMBNAIL_IMAGE_WIDTH, THUMBNAIL_IMAGE_HEIGHT);
630 if (pMetadata->pThumbnail == null)
632 // Because Thumbnail is one of the metadata, it is not exception in this function.
633 SysLog(NID_CNT, "DecodeN failed.");
635 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
636 if (pMetadata->pAlbumArt == null)
638 // Because Album Art is one of the metadata, it is not exception in this function.
639 SysLog(NID_CNT, "DecodeN failed.");
647 r = ErrorMapToRetVal(retVal);
648 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
649 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
652 return pAudioMetadata.release();
661 _ContentManagerUtilImpl::GetVideoMetaN(const String& contentPath)
665 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), null, E_INVALID_ARG,
666 "[E_INVALID_ARG] The path is not compatible.");
667 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), null, E_INVALID_ARG,
668 "[E_INVALID_ARG] The file corresponding to contentPath could not be found.");
670 // need to create here to make sure that all get APIs will not crash in case of corrupted file
671 unique_ptr<VideoMetadata> pVideoMetadata(new (nothrow) VideoMetadata());
672 SysTryReturn(NID_CNT, pVideoMetadata != null, null, E_OUT_OF_MEMORY,
673 "[E_OUT_OF_MEMORY] The memory insufficient.");
675 _VideoMetadataImpl* pVideoMetaImpl = _VideoMetadataImpl::GetInstance(*(pVideoMetadata.get()));
676 SysTryReturn(NID_CNT, pVideoMetaImpl != null, null, E_OUT_OF_MEMORY,
677 "[E_OUT_OF_MEMORY] pVideoMetaImpl is null.");
679 VideoMeta* pMetadata = pVideoMetaImpl->GetVideoMetadata();
680 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
681 "[E_INVALID_ARG] pMetadata is null.");
683 pMetadata->contentPath = contentPath;
685 // Create the metadata extractor handle
686 unique_ptr<metadata_extractor_h, ExtractorDeleter> pExtractor(new (nothrow) metadata_extractor_h);
687 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
688 "[E_OUT_OF_MEMORY] The memory insufficient.");
690 int retVal = metadata_extractor_create(pExtractor.get());
691 result r = ErrorMapToRetVal(retVal);
692 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
693 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
695 // Set file path of content to extract the metadata
696 unique_ptr<char[]> pFileName(_StringConverter::CopyToCharArrayN(contentPath));
697 SysTryReturn(NID_CNT, pFileName != null, null, E_OUT_OF_MEMORY,
698 "[E_OUT_OF_MEMORY] The memory is insufficient.");
700 retVal = metadata_extractor_set_path(*(pExtractor.get()), pFileName.get());
701 r = ErrorMapToRetVal(retVal);
702 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
703 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
705 // Get all relavent video metadata by passing relavent attirbutes
706 char* __pVideoMeta = null;
707 unique_ptr<char, CharDeleter> pVideoMeta(null);
710 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_VIDEO_WIDTH, &__pVideoMeta);
711 if (__pVideoMeta != null)
713 pVideoMeta.reset(__pVideoMeta);
714 pMetadata->width = atoi(pVideoMeta.get());
718 r = ErrorMapToRetVal(retVal);
719 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
720 "[%s] metadata_extractor_get_metadata(width) failed.", GetErrorMessage(r));
724 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_VIDEO_HEIGHT, &__pVideoMeta);
725 if (__pVideoMeta != null)
727 pVideoMeta.reset(__pVideoMeta);
728 pMetadata->height = atoi(pVideoMeta.get());
732 r = ErrorMapToRetVal(retVal);
733 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
734 "[%s] metadata_extractor_get_metadata(height) failed.", GetErrorMessage(r));
738 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_VIDEO_BITRATE, &__pVideoMeta);
739 if (__pVideoMeta != null)
741 pVideoMeta.reset(__pVideoMeta);
742 pMetadata->videoBitrate = atoi(pVideoMeta.get());
746 r = ErrorMapToRetVal(retVal);
747 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
748 "[%s] metadata_extractor_get_metadata(video bitrate) failed.", GetErrorMessage(r));
752 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_AUDIO_BITRATE, &__pVideoMeta);
753 if (__pVideoMeta != null)
755 pVideoMeta.reset(__pVideoMeta);
756 pMetadata->audioBitrate = atoi(pVideoMeta.get());
760 r = ErrorMapToRetVal(retVal);
761 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
762 "[%s] metadata_extractor_get_metadata(audio bitrate) failed.", GetErrorMessage(r));
766 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_VIDEO_FPS, &__pVideoMeta);
767 if (__pVideoMeta != null)
769 pVideoMeta.reset(__pVideoMeta);
770 pMetadata->framerate = atoi(pVideoMeta.get());
774 r = ErrorMapToRetVal(retVal);
775 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
776 "[%s] metadata_extractor_get_metadata(framerate) failed.", GetErrorMessage(r));
780 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_DURATION, &__pVideoMeta);
781 if (__pVideoMeta != null)
783 pVideoMeta.reset(__pVideoMeta);
784 pMetadata->duration = atoi(pVideoMeta.get());
788 r = ErrorMapToRetVal(retVal);
789 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
790 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
794 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_GENRE, &__pVideoMeta);
795 if (__pVideoMeta != null)
797 pVideoMeta.reset(__pVideoMeta);
798 pMetadata->pGenre = new (nothrow) String(pVideoMeta.get()); //allocate memory
799 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
800 "[E_OUT_OF_MEMORY] The memory is insufficient.");
804 r = ErrorMapToRetVal(retVal);
805 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
806 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
810 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_COMMENT, &__pVideoMeta);
811 if (__pVideoMeta != null)
813 pVideoMeta.reset(__pVideoMeta);
814 pMetadata->pComment = new (nothrow) String(pVideoMeta.get());
815 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
816 "[E_OUT_OF_MEMORY] The memory is insufficient.");
820 r = ErrorMapToRetVal(retVal);
821 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
822 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
826 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_DESCRIPTION, &__pVideoMeta);
827 if (__pVideoMeta != null)
829 pVideoMeta.reset(__pVideoMeta);
830 pMetadata->pDescription = new (nothrow) String(pVideoMeta.get());
831 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
832 "[E_OUT_OF_MEMORY] The memory is insufficient.");
836 r = ErrorMapToRetVal(retVal);
837 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
838 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
843 void* __pArtwork = null;
844 unique_ptr<void, VoidDeleter> pArtwork(null);
846 // Get the artwork image in media file
847 retVal = metadata_extractor_get_artwork(*(pExtractor.get()), &__pArtwork, &size, &__pVideoMeta);
848 if (__pArtwork != null)
850 pArtwork.reset(__pArtwork);
853 ImageFormat format = IMG_FORMAT_NONE;
856 r = buffer.Construct(size);
857 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
859 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
865 format = img.GetImageFormat(buffer);
867 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
868 if (pMetadata->pAlbumArt == null)
870 // Because Album Art is one of the metadata, it is not exception in this function.
871 SysLog(NID_CNT, "DecodeN failed.");
879 r = ErrorMapToRetVal(retVal);
880 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
881 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
884 return pVideoMetadata.release();
888 _ContentManagerUtilImpl::GetImageMetaN(const ByteBuffer& byteBuffer)
892 int bufferLen = byteBuffer.GetRemaining();
893 SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
895 // create object here as it needs to be passed to client in any case to make sure Get APIs do not crash
896 unique_ptr<ImageMetadata> pImageMetadata(new (nothrow) ImageMetadata());
897 SysTryReturn(NID_CNT, pImageMetadata != null, null, E_OUT_OF_MEMORY,
898 "[E_OUT_OF_MEMORY] pImageMetadata is null.");
900 _ImageMetadataImpl* pImageMetaImpl = _ImageMetadataImpl::GetInstance(*(pImageMetadata.get()));
901 SysTryReturn(NID_CNT, pImageMetaImpl != null, null, E_OUT_OF_MEMORY,
902 "[E_OUT_OF_MEMORY] pImageMetaImpl is null.");
904 ImageMeta* pMetadata = pImageMetaImpl->GetImageMetadata();
905 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
906 "[E_INVALID_ARG] pMetadata is null.");
908 //assign by default here and overwrite below if width and height presents in EXIF data.
909 ImageFormat imgType = IMG_FORMAT_NONE;
913 result r = ImageBuffer::GetImageInfo(byteBuffer, imgType, imageWidth, imageHeight);
914 SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_INVALID_ARG,
915 "[E_INVALID_ARG] GetImageInfo failed.");
917 pMetadata->width = imageWidth;
918 pMetadata->height = imageHeight;
920 if (imgType == IMG_FORMAT_JPG)
922 const byte* pByte = byteBuffer.GetPointer();
924 unique_ptr<ExifData, ExifDataDeleter> pExifdata(exif_data_new_from_data(pByte, bufferLen));
925 if (pExifdata != null)
928 ExifByteOrder byteOrder;
929 ExifEntry** pEntries = null;
930 const char* pData = null;
931 char buf[IMAGE_BUFF_LENGTH] = {0, };
932 char mmBuff[IMAGE_BUFF_LENGTH] = {0, }; // to store minutes value of GPS data
933 char ssBuff[IMAGE_BUFF_LENGTH] = {0, }; // to store seconds value of GPS data
934 ExifContent* pExifcont[EXIF_IFD_COUNT];
936 char latitudeRef = 0; // to store latitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
937 char longitudeRef = 0; // to store longitude reference (quadrasphere designation 'N', 'S', 'W' or 'E')
938 unsigned int entryCount = 0;
940 for (int i = 0; i < EXIF_IFD_COUNT; i++)
942 pExifcont[i] = pExifdata->ifd[i];
943 entryCount = pExifcont[i]->count;
944 pEntries = pExifcont[i]->entries;
945 for (unsigned int j = 0; j < entryCount; j++)
947 tag = pEntries[j]->tag;
948 pData = exif_entry_get_value(pEntries[j], buf, sizeof(buf));
949 SysTryReturn(NID_CNT, pData != null, pImageMetadata.release(), E_INVALID_ARG,
950 "[E_INVALID_ARG] exif_entry_get_value failed.");
952 if (tag == EXIF_TAG_PIXEL_X_DIMENSION)
954 pMetadata->width = atoi(buf);
956 else if (tag == EXIF_TAG_PIXEL_Y_DIMENSION)
958 pMetadata->height = atoi(buf);
960 else if (tag == EXIF_TAG_MAKE)
962 pMetadata->pManufacturer = new (nothrow) String(buf);
963 SysTryReturn(NID_CNT, pMetadata->pManufacturer != null, null, E_OUT_OF_MEMORY,
964 "[E_OUT_OF_MEMORY] The memory is insufficient.");
966 else if (tag == EXIF_TAG_MODEL)
968 pMetadata->pModel = new (nothrow) String(buf);
969 SysTryReturn(NID_CNT, pMetadata->pModel != null, null, E_OUT_OF_MEMORY,
970 "[E_OUT_OF_MEMORY] The memory is insufficient.");
972 else if (tag == EXIF_TAG_DATE_TIME)
974 pMetadata->pDateTime = new (nothrow) String(buf);
975 SysTryReturn(NID_CNT, pMetadata->pDateTime != null, null, E_OUT_OF_MEMORY,
976 "[E_OUT_OF_MEMORY] The memory is insufficient.");
978 else if (tag == EXIF_TAG_ORIENTATION)
980 //get the byte order(little endian or big endian) before extracting orientation type
981 byteOrder = exif_data_get_byte_order(pEntries[j]->parent->parent);
982 pMetadata->orientation = static_cast<ImageOrientationType>(exif_get_short(pEntries[j]->data, byteOrder));
984 else if (tag == EXIF_TAG_SOFTWARE)
986 pMetadata->pSoftware = new (nothrow) String(buf);
987 SysTryReturn(NID_CNT, pMetadata->pSoftware != null, null, E_OUT_OF_MEMORY,
988 "[E_OUT_OF_MEMORY] The memory is insufficient.");
990 else if (tag == EXIF_TAG_GPS_LATITUDE_REF)
992 latitudeRef = buf[0]; // GPS Latitude reference value will be 'N'(NORTH) or 'S'(SOUTH)
994 else if (tag == EXIF_TAG_GPS_LATITUDE)
996 ParseBuffer(buf, index); // to extract the minutes value of GPS data, if present
997 for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++)
999 mmBuff[l] = buf[l + index + 1]; //add 1 to skip the ','
1001 index = 0; //re-assign index value as this is new buffer
1002 ParseBuffer(mmBuff, index); // to extract the seconds value of GPS data, if present
1003 for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++)
1005 ssBuff[l] = mmBuff[l + index + 1]; //add 1 to skip the ','
1007 double ddVal = atof(buf); // degree value
1008 double mmVal = atof(mmBuff); // minutesvalue
1009 double ssVal = atof(ssBuff); // seconds value
1010 pMetadata->latitude = ddVal + (mmVal/MINUTES) + (ssVal/SECONDS);
1012 // if latitude designation is Southern (SOUTH) then latitude degree will be negative DD
1013 if (latitudeRef == 'S')
1015 pMetadata->latitude = (pMetadata->latitude * (double)(-1));
1018 else if (tag == EXIF_TAG_GPS_LONGITUDE_REF)
1020 longitudeRef = buf[0]; // GPS Longitude reference value will be 'W'(WEST) or 'E'(EAST)
1022 else if (tag == EXIF_TAG_GPS_LONGITUDE)
1024 index = 0; //re-assign index value as this is new buffer
1025 ParseBuffer(buf, index); // to extract the minutes value of GPS data, if present
1026 for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++)
1028 mmBuff[l] = buf[l + index + 1]; //add 1 to skip the ','
1030 index = 0; //re-assign index value as this is new buffer
1031 ParseBuffer(mmBuff, index); // to extract the seconds value of GPS data, if present
1032 for (int l = 0; l < IMAGE_BUFF_LENGTH-1; l++)
1034 ssBuff[l] = mmBuff[l + index + 1]; //add 1 to skip the ','
1036 double ddVal = atof(buf); // degree value
1037 double mmVal = atof(mmBuff); // minutesvalue
1038 double ssVal = atof(ssBuff); // seconds value
1039 pMetadata->longitude = ddVal + (mmVal/MINUTES) + (ssVal/SECONDS);
1041 // if longitude designation is Western (WEST) then longitude degree will be negative DD
1042 if (longitudeRef == 'W')
1044 pMetadata->longitude = (pMetadata->longitude * (double)(-1));
1047 else if (tag == EXIF_TAG_WHITE_BALANCE)
1049 pMetadata->pWhiteBalance = new (nothrow) String(buf);
1050 SysTryReturn(NID_CNT, pMetadata->pWhiteBalance != null, null, E_OUT_OF_MEMORY,
1051 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1058 return pImageMetadata.release();
1067 _ContentManagerUtilImpl::GetAudioMetaN(const ByteBuffer& byteBuffer)
1071 int bufferLen = byteBuffer.GetRemaining();
1072 SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
1074 // create here to make sure that get apis will not crash though the below API calls fails in case of invalid file.
1075 unique_ptr<AudioMetadata> pAudioMetadata(new (nothrow) AudioMetadata());
1076 SysTryReturn(NID_CNT, pAudioMetadata != null, null, E_OUT_OF_MEMORY,
1077 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1079 _AudioMetadataImpl* pAudioMetaImpl = _AudioMetadataImpl::GetInstance(*(pAudioMetadata.get()));
1080 SysTryReturn(NID_CNT, pAudioMetaImpl != null, null, E_OUT_OF_MEMORY,
1081 "[E_OUT_OF_MEMORY] pAudioMetaImpl is null.");
1083 AudioMeta* pMetadata = pAudioMetaImpl->GetAudioMetadata();
1084 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
1085 "[E_INVALID_ARG] pMetadata is null.");
1087 // Create the metadata extractor handle
1088 unique_ptr<metadata_extractor_h, ExtractorDeleter> pExtractor(new (nothrow) metadata_extractor_h);
1089 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
1090 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1092 int retVal = metadata_extractor_create(pExtractor.get());
1093 result r = ErrorMapToRetVal(retVal);
1094 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1095 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1097 const byte* pByte = byteBuffer.GetPointer();
1099 retVal = metadata_extractor_set_buffer(*(pExtractor.get()), pByte, bufferLen);
1100 r = ErrorMapToRetVal(retVal);
1101 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1102 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1104 // Get all relavent audio metadata by passing relavent attirbutes
1105 char* __pAudioMeta = null;
1106 unique_ptr<char, CharDeleter> pAudioMeta(null);
1109 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_AUDIO_BITRATE, &__pAudioMeta);
1110 if (__pAudioMeta != null)
1112 pAudioMeta.reset(__pAudioMeta);
1113 pMetadata->bitrate = atoi(pAudioMeta.get());
1117 r = ErrorMapToRetVal(retVal);
1118 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1119 "[%s] metadata_extractor_get_metadata(bitrate) failed.", GetErrorMessage(r));
1123 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_AUDIO_CHANNELS, &__pAudioMeta);
1124 if (__pAudioMeta != null)
1126 pAudioMeta.reset(__pAudioMeta);
1127 pMetadata->channelCount = atoi(pAudioMeta.get());
1131 r = ErrorMapToRetVal(retVal);
1132 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1133 "[%s] metadata_extractor_get_metadata(channels) failed.", GetErrorMessage(r));
1137 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_DURATION, &__pAudioMeta);
1138 if (__pAudioMeta != null)
1140 pAudioMeta.reset(__pAudioMeta);
1141 pMetadata->duration = atoi(pAudioMeta.get());
1145 r = ErrorMapToRetVal(retVal);
1146 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1147 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
1151 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_AUDIO_SAMPLERATE, &__pAudioMeta);
1152 if (__pAudioMeta != null)
1154 pAudioMeta.reset(__pAudioMeta);
1155 pMetadata->frequency = atoi(pAudioMeta.get());
1159 r = ErrorMapToRetVal(retVal);
1160 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1161 "[%s] metadata_extractor_get_metadata(frequency) failed.", GetErrorMessage(r));
1165 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_ALBUM, &__pAudioMeta);
1166 if (__pAudioMeta != null)
1168 pAudioMeta.reset(__pAudioMeta);
1169 pMetadata->pAlbumName = new (nothrow) String(pAudioMeta.get());
1170 SysTryReturn(NID_CNT, pMetadata->pAlbumName != 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(album name) failed.", GetErrorMessage(r));
1181 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_ARTIST, &__pAudioMeta);
1182 if (pAudioMeta.get() != null)
1184 pAudioMeta.reset(__pAudioMeta);
1185 pMetadata->pArtist = new (nothrow) String(pAudioMeta.get());
1186 SysTryReturn(NID_CNT, pMetadata->pArtist != 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(artist) failed.", GetErrorMessage(r));
1197 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_COPYRIGHT, &__pAudioMeta);
1198 if (__pAudioMeta != null)
1200 pAudioMeta.reset(__pAudioMeta);
1201 pMetadata->pCopyright = new (nothrow) String(pAudioMeta.get());
1202 SysTryReturn(NID_CNT, pMetadata->pCopyright != 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(copyright) failed.", GetErrorMessage(r));
1213 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_GENRE, &__pAudioMeta);
1214 if (__pAudioMeta != null)
1216 pAudioMeta.reset(__pAudioMeta);
1217 pMetadata->pGenre = new (nothrow) String(pAudioMeta.get());
1218 SysTryReturn(NID_CNT, pMetadata->pGenre != 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(genre) failed.", GetErrorMessage(r));
1229 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_TITLE, &__pAudioMeta);
1230 if (__pAudioMeta != null)
1232 pAudioMeta.reset(__pAudioMeta);
1233 pMetadata->pTitle = new (nothrow) String(pAudioMeta.get());
1234 SysTryReturn(NID_CNT, pMetadata->pTitle != 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(title) failed.", GetErrorMessage(r));
1245 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_COMMENT, &__pAudioMeta);
1246 if (__pAudioMeta != null)
1248 pAudioMeta.reset(__pAudioMeta);
1249 pMetadata->pComment = new (nothrow) String(pAudioMeta.get());
1250 SysTryReturn(NID_CNT, pMetadata->pComment != 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(comment) failed.", GetErrorMessage(r));
1261 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_DESCRIPTION, &__pAudioMeta);
1262 if (__pAudioMeta != null)
1264 pAudioMeta.reset(__pAudioMeta);
1265 pMetadata->pDescription = new (nothrow) String(pAudioMeta.get());
1266 SysTryReturn(NID_CNT, pMetadata->pDescription != 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(description) failed.", GetErrorMessage(r));
1277 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_RECDATE, &__pAudioMeta);
1278 if (__pAudioMeta != null)
1280 pAudioMeta.reset(__pAudioMeta);
1281 pMetadata->pRecordingDate = new (nothrow) String(pAudioMeta.get());
1282 SysTryReturn(NID_CNT, pMetadata->pRecordingDate != null, null, E_OUT_OF_MEMORY,
1283 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1287 r = ErrorMapToRetVal(retVal);
1288 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1289 "[%s] metadata_extractor_get_metadata(recording date) failed.", GetErrorMessage(r));
1293 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_AUTHOR, &__pAudioMeta);
1294 if (__pAudioMeta != null)
1296 pAudioMeta.reset(__pAudioMeta);
1297 pMetadata->pComposer = new (nothrow) String(pAudioMeta.get());
1298 SysTryReturn(NID_CNT, pMetadata->pComposer != null, null, E_OUT_OF_MEMORY,
1299 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1303 r = ErrorMapToRetVal(retVal);
1304 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1305 "[%s] metadata_extractor_get_metadata(author) failed.", GetErrorMessage(r));
1309 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_TRACK_NUM, &__pAudioMeta);
1310 if (__pAudioMeta != null)
1312 pAudioMeta.reset(__pAudioMeta);
1313 pMetadata->pTrackInfo = new (nothrow) String(pAudioMeta.get());
1314 SysTryReturn(NID_CNT, pMetadata->pTrackInfo != null, null, E_OUT_OF_MEMORY,
1315 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1317 // if the string contains the track info like track num/track position,
1318 // then track position will be ignored and only track num is returned
1319 // no need to parse this string, since only track number is required
1320 pMetadata->trackNum = atoi(pAudioMeta.get());
1324 r = ErrorMapToRetVal(retVal);
1325 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1326 "[%s] metadata_extractor_get_metadata(track info) failed.", GetErrorMessage(r));
1330 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_DATE, &__pAudioMeta);
1331 if (__pAudioMeta != null)
1333 pAudioMeta.reset(__pAudioMeta);
1334 pMetadata->year = atoi(pAudioMeta.get());
1338 r = ErrorMapToRetVal(retVal);
1339 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1340 "[%s] metadata_extractor_get_metadata(date) failed.", GetErrorMessage(r));
1345 void* __pArtwork = null;
1346 unique_ptr<void, VoidDeleter> pArtwork(null);
1348 // Get the artwork image in media file
1349 retVal = metadata_extractor_get_artwork(*(pExtractor.get()), &__pArtwork, &size, &__pAudioMeta);
1351 //Check if the albumart present and pass it to client if it is successfully processed, otherwise ignore any errors
1352 //while processing albumart. This is to pass the other metadata tags to application.
1353 if (__pArtwork != null)
1355 pArtwork.reset(__pArtwork);
1358 ImageFormat format = IMG_FORMAT_NONE;
1361 r = buffer.Construct(size);
1362 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
1364 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
1367 r = img.Construct();
1370 format = img.GetImageFormat(buffer);
1371 pMetadata->pThumbnail = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888,
1372 THUMBNAIL_IMAGE_WIDTH, THUMBNAIL_IMAGE_HEIGHT);
1373 if (pMetadata->pThumbnail == null)
1375 // Because Thumbnail is one of the metadata, it is not exception in this function.
1376 SysLog(NID_CNT, "DecodeN failed.");
1378 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
1379 if (pMetadata->pAlbumArt == null)
1381 // Because Album Art is one of the metadata, it is not exception in this function.
1382 SysLog(NID_CNT, "DecodeN failed.");
1390 r = ErrorMapToRetVal(retVal);
1391 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pAudioMetadata.release(), r,
1392 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
1395 return pAudioMetadata.release();
1404 _ContentManagerUtilImpl::GetVideoMetaN(const ByteBuffer& byteBuffer)
1408 int bufferLen = byteBuffer.GetRemaining();
1409 SysTryReturn(NID_CNT, bufferLen > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The length of buffer is less than zero.");
1411 // need to create here to make sure that all get APIs will not crash in case of corrupted file
1412 unique_ptr<VideoMetadata> pVideoMetadata(new (nothrow) VideoMetadata());
1413 SysTryReturn(NID_CNT, pVideoMetadata != null, null, E_OUT_OF_MEMORY,
1414 "[E_OUT_OF_MEMORY] The memory insufficient.");
1416 _VideoMetadataImpl* pVideoMetaImpl = _VideoMetadataImpl::GetInstance(*(pVideoMetadata.get()));
1417 SysTryReturn(NID_CNT, pVideoMetaImpl != null, null, E_OUT_OF_MEMORY,
1418 "[E_OUT_OF_MEMORY] pVideoMetaImpl is null.");
1420 VideoMeta* pMetadata = pVideoMetaImpl->GetVideoMetadata();
1421 SysTryReturn(NID_CNT, pMetadata != null, null, E_INVALID_ARG,
1422 "[E_INVALID_ARG] pMetadata is null.");
1424 // Create the metadata extractor handle
1425 unique_ptr<metadata_extractor_h, ExtractorDeleter> pExtractor(new (nothrow) metadata_extractor_h);
1426 SysTryReturn(NID_CNT, pExtractor != null, null, E_OUT_OF_MEMORY,
1427 "[E_OUT_OF_MEMORY] The memory insufficient.");
1429 int retVal = metadata_extractor_create(pExtractor.get());
1430 result r = ErrorMapToRetVal(retVal);
1431 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1432 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1434 const byte* pByte = byteBuffer.GetPointer();
1436 retVal = metadata_extractor_set_buffer(*(pExtractor.get()), pByte, bufferLen);
1437 r = ErrorMapToRetVal(retVal);
1438 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, null, r,
1439 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1441 // Get all relavent video metadata by passing relavent attirbutes
1442 char* __pVideoMeta = null;
1443 unique_ptr<char, CharDeleter> pVideoMeta(null);
1446 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_VIDEO_WIDTH, &__pVideoMeta);
1447 if (__pVideoMeta != null)
1449 pVideoMeta.reset(__pVideoMeta);
1450 pMetadata->width = atoi(pVideoMeta.get());
1454 r = ErrorMapToRetVal(retVal);
1455 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1456 "[%s] metadata_extractor_get_metadata(width) failed.", GetErrorMessage(r));
1460 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_VIDEO_HEIGHT, &__pVideoMeta);
1461 if (__pVideoMeta != null)
1463 pVideoMeta.reset(__pVideoMeta);
1464 pMetadata->height = atoi(pVideoMeta.get());
1468 r = ErrorMapToRetVal(retVal);
1469 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1470 "[%s] metadata_extractor_get_metadata(height) failed.", GetErrorMessage(r));
1474 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_VIDEO_BITRATE, &__pVideoMeta);
1475 if (__pVideoMeta != null)
1477 pVideoMeta.reset(__pVideoMeta);
1478 pMetadata->videoBitrate = atoi(pVideoMeta.get());
1482 r = ErrorMapToRetVal(retVal);
1483 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1484 "[%s] metadata_extractor_get_metadata(video bitrate) failed.", GetErrorMessage(r));
1488 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_AUDIO_BITRATE, &__pVideoMeta);
1489 if (__pVideoMeta != null)
1491 pVideoMeta.reset(__pVideoMeta);
1492 pMetadata->audioBitrate = atoi(pVideoMeta.get());
1496 r = ErrorMapToRetVal(retVal);
1497 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1498 "[%s] metadata_extractor_get_metadata(audio bitrate) failed.", GetErrorMessage(r));
1502 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_VIDEO_FPS, &__pVideoMeta);
1503 if (__pVideoMeta != null)
1505 pVideoMeta.reset(__pVideoMeta);
1506 pMetadata->framerate = atoi(pVideoMeta.get());
1510 r = ErrorMapToRetVal(retVal);
1511 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1512 "[%s] metadata_extractor_get_metadata(framerate) failed.", GetErrorMessage(r));
1516 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_DURATION, &__pVideoMeta);
1517 if (__pVideoMeta != null)
1519 pVideoMeta.reset(__pVideoMeta);
1520 pMetadata->duration = atoi(pVideoMeta.get());
1524 r = ErrorMapToRetVal(retVal);
1525 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1526 "[%s] metadata_extractor_get_metadata(duration) failed.", GetErrorMessage(r));
1530 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_GENRE, &__pVideoMeta);
1531 if (__pVideoMeta != null)
1533 pVideoMeta.reset(__pVideoMeta);
1534 pMetadata->pGenre = new (nothrow) String(pVideoMeta.get()); //allocate memory
1535 SysTryReturn(NID_CNT, pMetadata->pGenre != null, null, E_OUT_OF_MEMORY,
1536 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1540 r = ErrorMapToRetVal(retVal);
1541 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1542 "[%s] metadata_extractor_get_metadata(genre) failed.", GetErrorMessage(r));
1546 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_COMMENT, &__pVideoMeta);
1547 if (__pVideoMeta != null)
1549 pVideoMeta.reset(__pVideoMeta);
1550 pMetadata->pComment = new (nothrow) String(pVideoMeta.get());
1551 SysTryReturn(NID_CNT, pMetadata->pComment != null, null, E_OUT_OF_MEMORY,
1552 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1556 r = ErrorMapToRetVal(retVal);
1557 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1558 "[%s] metadata_extractor_get_metadata(comment) failed.", GetErrorMessage(r));
1562 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_DESCRIPTION, &__pVideoMeta);
1563 if (__pVideoMeta != null)
1565 pVideoMeta.reset(__pVideoMeta);
1566 pMetadata->pDescription = new (nothrow) String(pVideoMeta.get());
1567 SysTryReturn(NID_CNT, pMetadata->pDescription != null, null, E_OUT_OF_MEMORY,
1568 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1572 r = ErrorMapToRetVal(retVal);
1573 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1574 "[%s] metadata_extractor_get_metadata(description) failed.", GetErrorMessage(r));
1579 void* __pArtwork = null;
1580 unique_ptr<void, VoidDeleter> pArtwork(null);
1582 // Get the artwork image in media file
1583 retVal = metadata_extractor_get_artwork(*(pExtractor.get()), &__pArtwork, &size, &__pVideoMeta);
1584 if (__pArtwork != null)
1586 pArtwork.reset(__pArtwork);
1589 ImageFormat format = IMG_FORMAT_NONE;
1592 r = buffer.Construct(size);
1593 if (!IsFailed(r)) //Ignore the error codes to send other metadata to app
1595 r = buffer.SetArray((const byte*)(pArtwork.get()), 0, size);
1598 r = img.Construct();
1601 format = img.GetImageFormat(buffer);
1603 pMetadata->pAlbumArt = img.DecodeN(buffer, format, BITMAP_PIXEL_FORMAT_ARGB8888);
1604 if (pMetadata->pAlbumArt == null)
1606 // Because Album Art is one of the metadata, it is not exception in this function.
1607 SysLog(NID_CNT, "DecodeN failed.");
1615 r = ErrorMapToRetVal(retVal);
1616 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, pVideoMetadata.release(), r,
1617 "[%s] metadata_extractor_get_artwork failed.", GetErrorMessage(r));
1620 return pVideoMetadata.release();
1628 // E_UNSUPPORTED_FORMAT
1631 _ContentManagerUtilImpl::CheckContentType(const String& contentPath, bool internal)
1635 ContentType contentType = CONTENT_TYPE_UNKNOWN;
1639 SysTryReturn(NID_CNT, VerifyFilePathCompatibility(contentPath), contentType, E_INVALID_ARG,
1640 "[E_INVALID_ARG] The path is not compatible.");
1642 SysTryReturn(NID_CNT, contentPath.GetLength() != 0, contentType, E_INVALID_ARG,
1643 "[E_INVALID_ARG] The length of contentPath is 0.");
1644 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(contentPath), contentType, E_FILE_NOT_FOUND,
1645 "[E_FILE_NOT_FOUND] The file corresponding to contentPath could not be found.");
1647 String fileExt = _FileImpl::GetFileExtension(contentPath);
1648 result r = GetLastResult();
1649 SysTryReturn(NID_CNT, !IsFailed(r), contentType, r, "[%s] GetFileExtension failed.", GetErrorMessage(r));
1651 unique_ptr<char[]> pFormat(_StringConverter::CopyToCharArrayN(fileExt));
1652 SysTryReturn(NID_CNT, pFormat != null, contentType, E_OUT_OF_MEMORY,
1653 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1655 char* __pMimeType = null;
1656 int retVal = mime_type_get_mime_type(pFormat.get(), &__pMimeType);
1657 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, E_INVALID_ARG,
1658 "[E_INVALID_ARG] mime_type_get_mime_type failed.");
1659 SysTryReturn(NID_CNT, __pMimeType != null, contentType, E_INVALID_ARG,
1660 "[E_INVALID_ARG] mime_type_get_mime_type failed.");
1662 unique_ptr<char, CharDeleter> pMimeType;
1663 pMimeType.reset(__pMimeType);
1665 SysLog(NID_CNT, "The MIME type for %ls is %s", fileExt.GetPointer(), __pMimeType);
1667 String mimeType(pMimeType.get());
1669 if (mimeType.Contains(L"image"))
1671 return CONTENT_TYPE_IMAGE;
1673 else if (mimeType.Contains(L"audio"))
1675 if (mimeType.Contains(L"x-mpegurl"))
1677 SysLog(NID_CNT, "The type of x-mpegurl is other.");
1678 return CONTENT_TYPE_OTHER;
1680 return CONTENT_TYPE_AUDIO;
1682 else if (mimeType.Contains(L"video"))
1685 fileExt.ToLowerCase(format);
1687 if (format == L"3gp" || format == L"mp4")
1689 return CheckStream(contentPath);
1691 return CONTENT_TYPE_VIDEO;
1693 else if (mimeType.Contains(L"application"))
1695 if (mimeType.Contains(L"x-smaf"))
1697 SysLog(NID_CNT, "The type of x-smaf is audio.");
1698 return CONTENT_TYPE_AUDIO;
1700 return CONTENT_TYPE_OTHER;
1703 return CONTENT_TYPE_OTHER;
1707 _ContentManagerUtilImpl::CheckStream(const String& contentPath)
1711 ContentType contentType = CONTENT_TYPE_UNKNOWN;
1713 unique_ptr<metadata_extractor_h, ExtractorDeleter> pExtractor(new (nothrow) metadata_extractor_h);
1714 SysTryReturn(NID_CNT, pExtractor != null, contentType, E_OUT_OF_MEMORY,
1715 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1717 int retVal = metadata_extractor_create(pExtractor.get());
1718 result r = ErrorMapToRetVal(retVal);
1719 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
1720 "[%s] metadata_extractor_create failed.", GetErrorMessage(r));
1722 //Set the file path to extract metadata.
1723 unique_ptr<char[]> pContentPath(_StringConverter::CopyToCharArrayN(contentPath));
1724 SysTryReturn(NID_CNT, pContentPath != null, contentType, E_INVALID_ARG,
1725 "[E_INVALID_ARG] The memory is insufficient.");
1727 retVal = metadata_extractor_set_path(*(pExtractor.get()), pContentPath.get());
1728 r = ErrorMapToRetVal(retVal);
1729 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE && pExtractor, contentType, r,
1730 "[%s] metadata_extractor_set_path failed.", GetErrorMessage(r));
1732 //Check whether it is an audio or video file.
1733 char* __pAudio = null;
1734 unique_ptr<char, CharDeleter> pAudio(null);
1736 char* __pVideo = null;
1737 unique_ptr<char, CharDeleter> pVideo(null);
1739 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_HAS_AUDIO, &__pAudio);
1740 if (__pAudio != null)
1742 pAudio.reset(__pAudio);
1746 r = ErrorMapToRetVal(retVal);
1747 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
1748 "[%s] metadata_extractor_get_metadata failed.", GetErrorMessage(r));
1751 retVal = metadata_extractor_get_metadata(*(pExtractor.get()), METADATA_HAS_VIDEO, &__pVideo);
1752 if (__pVideo != null)
1754 pVideo.reset(__pVideo);
1758 r = ErrorMapToRetVal(retVal);
1759 SysTryReturn(NID_CNT, retVal == METADATA_EXTRACTOR_ERROR_NONE, contentType, r,
1760 "[%s] metadata_extractor_get_metadata failed.", GetErrorMessage(r));
1763 if (*(pAudio.get()) > 0 && *(pVideo.get()) == 0)
1765 SysLog(NID_CNT, "The result of CheckStream() is audio");
1766 return CONTENT_TYPE_AUDIO;
1768 else if (*(pAudio.get()) == 0 && *(pVideo.get()) > 0)
1770 SysLog(NID_CNT, "The result of CheckStream() is video");
1771 return CONTENT_TYPE_VIDEO;
1773 else if (*(pAudio.get()) > 0 && *(pVideo.get()) > 0)
1775 SysLog(NID_CNT, "The result of CheckStream() is video");
1776 return CONTENT_TYPE_VIDEO;
1780 SysLogException(NID_CNT, E_UNSUPPORTED_FORMAT, "[E_UNSUPPORTED_FORMAT] The stream is empty.");
1787 _ContentManagerUtilImpl::VerifyFilePathCompatibility(const String& contentPath)
1789 if (!_AppInfo::IsOspCompat())
1791 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0)
1792 || contentPath.StartsWith(OSP_HOME, 0))
1794 SysLogException(NID_CNT, E_INVALID_ARG,
1795 "/Home, /Media/, or /Storagecard/Media/ is not supported from Tizen 2.0.");
1802 if (!(contentPath.StartsWith(OSP_MEDIA_PHONE, 0) || contentPath.StartsWith(OSP_MEDIA_MMC, 0)
1803 || contentPath.StartsWith(OSP_HOME, 0)))
1805 SysLogException(NID_CNT, E_INVALID_ARG,
1806 "The contentPath should start with /Home, /Media, or /Storagecard/Media.");
1815 _ContentManagerUtilImpl::ErrorMapToRetVal(int retVal)
1817 result r = E_SUCCESS;
1821 case METADATA_EXTRACTOR_ERROR_NONE:
1824 case METADATA_EXTRACTOR_ERROR_INVALID_PARAMETER:
1827 case METADATA_EXTRACTOR_ERROR_OUT_OF_MEMORY:
1828 r = E_OUT_OF_MEMORY;
1830 case METADATA_EXTRACTOR_ERROR_FILE_EXISTS:
1833 case METADATA_EXTRACTOR_ERROR_OPERATION_FAILED:
1845 _ContentManagerUtilImpl::CopyToMediaDirectory(const String& srcContentPath, const String& destContentPath)
1849 // For srcContentPath
1850 SysTryReturn(NID_CNT, !_FileImpl::IsSystemPath(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1851 "[E_INVALID_ARG] Can not copy the file in the system region.");
1852 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1853 "[E_INVALID_ARG] Can not find the file.");
1855 // For destContentPath
1856 SysTryReturn(NID_CNT, _FileImpl::IsMediaPath(destContentPath), E_INVALID_ARG, E_INVALID_ARG,
1857 "[E_INVALID_ARG] The destination path should start with /Media or /Storagecard/Media.");
1859 // E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_FILE_NOT_FOUND, E_FILE_ALREADY_EXIST, E_MAX_EXCEEDED, E_STORAGE_FULL, E_IO
1860 result r = E_SUCCESS;
1861 r = _FileImpl::Copy(srcContentPath, destContentPath, true);
1862 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] CopyToMediaDirectory failed.", GetErrorMessage(r));
1871 _ContentManagerUtilImpl::MoveToMediaDirectory(const String& srcContentPath, const String& destContentPath)
1875 // For srcContentPath
1876 SysTryReturn(NID_CNT, !_FileImpl::IsSystemPath(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1877 "[E_INVALID_ARG] Can not copy the file in the system region.");
1878 SysTryReturn(NID_CNT, _FileImpl::IsFileExist(srcContentPath), E_INVALID_ARG, E_INVALID_ARG,
1879 "[E_INVALID_ARG] Can not find the file.");
1881 // For destContentPath
1882 SysTryReturn(NID_CNT, _FileImpl::IsMediaPath(destContentPath), E_INVALID_ARG, E_INVALID_ARG,
1883 "[E_INVALID_ARG] The destination path should start with /Media or /Storagecard/Media.");
1885 // E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_FILE_NOT_FOUND, E_FILE_ALREADY_EXIST, E_MAX_EXCEEDED, E_STORAGE_FULL, E_IO
1886 result r = E_SUCCESS;
1887 r = _FileImpl::Move(srcContentPath, destContentPath);
1888 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] MoveToMediaDirectory failed.", GetErrorMessage(r));