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_ContentUtility.cpp
18 * @brief This is the implementation file for the %_ContentUtility class.
20 * This file contains implementation of the %_ContentUtility class.
23 #include <unique_ptr.h>
24 #include <FBaseSysLog.h>
25 #include <FBaseDateTime.h>
26 #include <FBaseInteger.h>
27 #include <FBaseLongLong.h>
28 #include <FBaseFloat.h>
29 #include <FBaseUtilStringTokenizer.h>
30 #include <FCntContentManagerUtil.h>
31 #include <FCntVideoMetadata.h>
32 #include "FCnt_ContentUtility.h"
33 #include "FCnt_ContentInfoImpl.h"
34 #include "FCnt_ImageContentInfoImpl.h"
35 #include "FCnt_AudioContentInfoImpl.h"
36 #include "FCnt_VideoContentInfoImpl.h"
38 using namespace Tizen::Base;
39 using namespace Tizen::Base::Collection;
40 using namespace Tizen::Base::Utility;
41 using namespace Tizen::Locations;
43 namespace Tizen { namespace Content
46 static const double DEFAULT_COORDINATE = -200.0;
48 // Default constructor
49 _ContentUtility::_ContentUtility(void)
56 _ContentUtility::~_ContentUtility(void)
62 _ContentUtility::DoSafeFree(char* pSrc)
70 // Fills ContentInfo information in the content data object.
72 _ContentUtility::FillContentData(media_info_h mediaHandle, _ContentInfoImpl* pInfoImpl)
74 SysTryReturnResult(NID_CNT, mediaHandle != null && pInfoImpl != null, E_INVALID_ARG, "mediaHandle or pInfoImpl is null.");
76 int ret = MEDIA_CONTENT_ERROR_NONE;
79 std::unique_ptr<char, UtilCharDeleter> pMediaId;
80 std::unique_ptr<char, UtilCharDeleter> pContentName;
81 std::unique_ptr<char, UtilCharDeleter> pMediaPath;
82 std::unique_ptr<char, UtilCharDeleter> pThumbnailPath;
83 std::unique_ptr<char, UtilCharDeleter> pAuthor;
84 std::unique_ptr<char, UtilCharDeleter> pCategory;
85 std::unique_ptr<char, UtilCharDeleter> pDescription;
86 std::unique_ptr<char, UtilCharDeleter> pLocationTag;
87 std::unique_ptr<char, UtilCharDeleter> pProvider;
88 std::unique_ptr<char, UtilCharDeleter> pKeyword;
89 std::unique_ptr<char, UtilCharDeleter> pContentRating;
90 std::unique_ptr<char, UtilCharDeleter> pMimeType;
92 media_content_type_e mediaType;
93 media_content_storage_e storageType;
95 unsigned long long contentSize = 0;
97 time_t modifiedTime = 0;
101 Coordinates coordinates;
105 char* pGetMediaValue = null;
106 ret = media_info_get_media_id(mediaHandle, &pGetMediaValue);
107 if (pGetMediaValue != null)
109 pMediaId.reset(pGetMediaValue);
113 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_media_id operation.");
116 ret = media_info_get_content_name(mediaHandle, &pGetMediaValue);
117 if (pGetMediaValue != null)
119 pContentName.reset(pGetMediaValue);
123 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_content_name operation.");
126 ret = media_info_get_file_path(mediaHandle, &pGetMediaValue);
127 if (pGetMediaValue != null)
129 pMediaPath.reset(pGetMediaValue);
133 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_file_path operation.");
136 ret = media_info_get_thumbnail_path(mediaHandle, &pGetMediaValue);
137 if (pGetMediaValue != null)
139 pThumbnailPath.reset(pGetMediaValue);
143 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_thumbnail_path operation.");
146 ret = media_info_get_author(mediaHandle, &pGetMediaValue);
147 if (pGetMediaValue != null)
149 pAuthor.reset(pGetMediaValue);
153 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_author operation.");
156 ret = media_info_get_category(mediaHandle, &pGetMediaValue);
157 if (pGetMediaValue != null)
159 pCategory.reset(pGetMediaValue);
163 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_category operation.");
166 ret = media_info_get_description(mediaHandle, &pGetMediaValue);
167 if (pGetMediaValue != null)
169 pDescription.reset(pGetMediaValue);
173 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_description operation.");
176 ret = media_info_get_location_tag(mediaHandle, &pGetMediaValue);
177 if (pGetMediaValue != null)
179 pLocationTag.reset(pGetMediaValue);
183 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_location_tag operation.");
186 ret = media_info_get_provider(mediaHandle, &pGetMediaValue);
187 if (pGetMediaValue != null)
189 pProvider.reset(pGetMediaValue);
193 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_provider operation.");
196 ret = media_info_get_size(mediaHandle, &contentSize);
197 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_size operation.");
200 ret = media_info_get_latitude(mediaHandle, &latitude);
201 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_latitude operation.");
203 ret = media_info_get_longitude(mediaHandle, &longitude);
204 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_longitude operation.");
206 ret = media_info_get_altitude(mediaHandle, &altitude);
207 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_altitude operation.");
209 ret = media_info_get_age_rating(mediaHandle, &pGetMediaValue);
210 if (pGetMediaValue != null)
212 pContentRating.reset(pGetMediaValue);
216 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_age_rating operation.");
219 ret = media_info_is_drm(mediaHandle, &isDrm);
220 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_is_drm operation.");
222 ret = media_info_get_added_time(mediaHandle, &addedTime);
223 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_added_time operation.");
225 ret = media_info_get_modified_time(mediaHandle, &modifiedTime);
226 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_modified_time operation.");
228 ret = media_info_get_storage_type(mediaHandle, &storageType);
229 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_storage_type operation.");
231 ret = media_info_get_media_type(mediaHandle, &mediaType);
232 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_media_type operation.");
234 ret = media_info_get_mime_type(mediaHandle, &pGetMediaValue);
235 if (pGetMediaValue != null)
237 pMimeType.reset(pGetMediaValue);
241 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_mime_type operation.");
244 ret = media_info_get_keyword(mediaHandle, &pGetMediaValue);
245 if (pGetMediaValue != null)
247 pKeyword.reset(pGetMediaValue);
251 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_keyword operation.");
254 if (pMediaId.get() != null)
258 r = UuId::Parse(String(pMediaId.get()), contentId);
259 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform UuId::Parse operation.");
261 pInfoImpl->SetContentId(contentId);
264 pInfoImpl->SetDrmProtected(isDrm);
265 SysLog(NID_CNT, "pContentInfoImpl->isDrm = %d", pInfoImpl->IsDrmProtected());
267 pInfoImpl->SetContentSize(contentSize);
268 SysLog(NID_CNT, "pContentInfoImpl->contentSize = %lu", pInfoImpl->GetContentSize());
270 if (Double::Compare(latitude, DEFAULT_COORDINATE) != 0)
272 pInfoImpl->SetLatitude(latitude);
273 coordinates.SetLatitude(latitude);
275 if (Double::Compare(longitude, DEFAULT_COORDINATE) != 0)
277 pInfoImpl->SetLongitude(longitude);
278 coordinates.SetLongitude(longitude);
280 if (Double::Compare(altitude, DEFAULT_COORDINATE) != 0)
282 pInfoImpl->SetAltitude(altitude);
283 coordinates.SetAltitude(altitude);
286 pInfoImpl->SetCoordinates(coordinates);
288 if (pMediaPath.get() != NULL)
290 String contentPath(pMediaPath.get());
292 pInfoImpl->SetContentPath(contentPath);
293 SysSecureLog(NID_CNT, "pContentInfoImpl->contentPath = %ls", (pInfoImpl->GetContentPath()).GetPointer());
296 if (pThumbnailPath.get() != NULL)
298 String thumbnailPath(pThumbnailPath.get());
300 pInfoImpl->SetThumbnailPath(thumbnailPath);
301 SysSecureLog(NID_CNT, "pContentInfoImpl->pThumbnailPath = %ls", (pInfoImpl->GetThumbnailPath()).GetPointer());
304 if (pAuthor.get() != NULL)
306 String author(pAuthor.get());
308 pInfoImpl->SetAuthor(author);
309 SysLog(NID_CNT, "pContentInfoImpl->pAuthor = %ls", (pInfoImpl->GetAuthor()).GetPointer());
312 if (pCategory.get() != NULL)
314 String category(pCategory.get());
316 pInfoImpl->SetCategory(category);
317 SysLog(NID_CNT, "pContentInfoImpl->pCategory = %ls", (pInfoImpl->GetCategory()).GetPointer());
320 if (pContentName.get() != NULL)
322 String contentName(pContentName.get());
324 pInfoImpl->SetContentName(contentName);
325 SysLog(NID_CNT, "pContentInfoImpl->pContentName = %ls", (pInfoImpl->GetContentName()).GetPointer());
328 if (pDescription.get() != NULL)
330 String description(pDescription.get());
332 pInfoImpl->SetDescription(description);
333 SysLog(NID_CNT, "pContentInfoImpl->pDescription = %ls", (pInfoImpl->GetDescription()).GetPointer());
336 if (pLocationTag.get() != NULL)
338 String locationTag(pLocationTag.get());
340 pInfoImpl->SetLocationTag(locationTag);
341 SysLog(NID_CNT, "pContentInfoImpl->pLocationTag = %ls", (pInfoImpl->GetLocationTag()).GetPointer());
344 if (pProvider.get() != NULL)
346 String provider(pProvider.get());
348 pInfoImpl->SetProvider(provider);
349 SysLog(NID_CNT, "pContentInfoImpl->pProvider = %ls", (pInfoImpl->GetProvider()).GetPointer());
352 if (pContentRating.get() != NULL)
354 String rating(pContentRating.get());
356 pInfoImpl->SetRating(rating);
357 SysLog(NID_CNT, "pContentInfoImpl->pRating = %ls", (pInfoImpl->GetRating()).GetPointer());
360 if (pKeyword.get() != NULL)
362 String keyword(pKeyword.get());
364 pInfoImpl->SetKeyword(keyword);
365 SysLog(NID_CNT, "pContentInfoImpl->pKeyword = %ls", (pInfoImpl->GetKeyword()).GetPointer());
368 if (pMimeType.get() != NULL)
370 String mimeType(pMimeType.get());
372 pInfoImpl->SetMimeType(mimeType);
373 SysLog(NID_CNT, "pContentInfoImpl->mimeType = %ls", (pInfoImpl->GetMimeType()).GetPointer());
378 case MEDIA_CONTENT_STORAGE_INTERNAL:
379 pInfoImpl->SetStorageType(0);
381 case MEDIA_CONTENT_STORAGE_EXTERNAL:
382 pInfoImpl->SetStorageType(1);
389 case MEDIA_CONTENT_TYPE_OTHERS:
390 pInfoImpl->SetContentType(CONTENT_TYPE_OTHER);
392 case MEDIA_CONTENT_TYPE_IMAGE:
393 pInfoImpl->SetContentType(CONTENT_TYPE_IMAGE);
395 case MEDIA_CONTENT_TYPE_SOUND:
397 case MEDIA_CONTENT_TYPE_MUSIC:
398 pInfoImpl->SetContentType(CONTENT_TYPE_AUDIO);
400 case MEDIA_CONTENT_TYPE_VIDEO:
401 pInfoImpl->SetContentType(CONTENT_TYPE_VIDEO);
410 r = dt.SetValue(1970, 1, 1);
411 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform datetime.SetValue operation.");
413 r = dt.AddSeconds(addedTime);// need to check addedTime is secs/millisec
414 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform datetime.AddSeconds operation.");
416 pInfoImpl->SetDateTime(dt);
418 SysLog(NID_CNT, "addedTime = %ld", addedTime);
419 SysLog(NID_CNT, "pContentInfoImpl->dateTime : %ls", (pInfoImpl->GetDateTime()).ToString().GetPointer());
422 r = dt.SetValue(1970, 1, 1);
423 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform datetime.SetValue operation.");
425 r = dt.AddSeconds(modifiedTime);// need to check addedTime is secs/millisec
426 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform datetime.AddSeconds operation.");
428 pInfoImpl->SetModifiedTime(dt);
430 SysLog(NID_CNT, "modifiedTime = %ld", modifiedTime);
431 SysLog(NID_CNT, "pContentInfoImpl->modifiedTime : %ls", (pInfoImpl->GetModifiedTime()).ToString().GetPointer());
436 // Fills ImageContentInfo information in the image content data object .
438 _ContentUtility::FillImageContentData(media_info_h mediaHandle, _ImageContentInfoImpl* pImageContentInfoImpl)
440 SysTryReturnResult(NID_CNT, mediaHandle != null && pImageContentInfoImpl != null, E_INVALID_ARG, "mediaHandle or pImageContentInfoImpl is null.");
442 int ret = MEDIA_CONTENT_ERROR_NONE;
443 result r = E_SUCCESS;
446 bool isBurst = false;
447 media_content_orientation_e orientation;
448 std::unique_ptr<char, UtilCharDeleter> pStrValue;
450 image_meta_h tempMeta = NULL;
452 ret = media_info_get_image(mediaHandle, &tempMeta);
453 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_image operation.");
455 std::unique_ptr<image_meta_s, ImageMetaHandleDeleter> pImageHandle(tempMeta);
456 SysTryReturnResult(NID_CNT, pImageHandle != null, E_OUT_OF_MEMORY, "pImageHandle is null.");
458 ret = image_meta_get_width(pImageHandle.get(), &width);
459 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform image_meta_get_width operation.");
461 ret = image_meta_get_orientation(pImageHandle.get(), &orientation);
462 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform image_meta_get_orientation operation.");
464 ret = image_meta_get_height(pImageHandle.get(), &height);
465 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform image_meta_get_height operation.");
467 ret = image_meta_is_burst_shot(pImageHandle.get(), &isBurst);
468 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform image_meta_is_burst_shot operation.");
470 pImageContentInfoImpl->SetWidth(width);
471 pImageContentInfoImpl->SetHeight(height);
472 pImageContentInfoImpl->SetOrientation(static_cast< ImageOrientationType >(orientation));
473 pImageContentInfoImpl->SetBurstShot(isBurst);
476 char* pTempValue = null;
477 ret = media_info_get_display_name(mediaHandle, &pTempValue);
478 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_display_name operation.");
480 if (pTempValue != NULL)
482 pStrValue.reset(pTempValue);
485 String fileName = L"";
486 String strTitle(pStrValue.get());
488 r = strTitle.LastIndexOf(L'.', strTitle.GetLength() - 1, pos);
491 r = strTitle.SubString(0, pos, fileName);
492 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform string.SubString operation.");
500 pImageContentInfoImpl->SetTitle(fileName);
501 SysLog(NID_CNT, "pImageContentInfoImpl->title = %ls", (pImageContentInfoImpl->GetTitle()).GetPointer());
505 ret = image_meta_get_date_taken(pImageHandle.get(), &pTempValue);
506 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret),
507 "Failed to perform image_meta_get_date_taken operation.");
511 if (pTempValue != NULL)
513 pStrValue.reset(pTempValue);
514 String dateTaken(pStrValue.get());
515 String newDateTaken(L"");
522 StringTokenizer strTok(dateTaken, delim);
524 r = strTok.GetNextToken(token);
525 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
530 r = strTok.GetNextToken(token);
531 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
533 r = newDateTaken.Append(token);
534 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
536 r = newDateTaken.Append(L"/");
537 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
540 r = strTok.GetNextToken(token);
541 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
543 r = newDateTaken.Append(token);
544 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
546 r = newDateTaken.Append(L"/");
547 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
550 r = newDateTaken.Append(year);
551 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
553 r = newDateTaken.Append(L" ");
554 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
556 String newDelim(L" ");
558 r = strTok.SetDelimiters(newDelim);
559 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform SetDelimiters operation.");
561 r = strTok.GetNextToken(token);
562 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
564 r = newDateTaken.Append(token);
565 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
567 r = DateTime::Parse(newDateTaken, dt);
568 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform Parse operation for DateTime.");
572 dt = DateTime::GetMinValue();
575 pImageContentInfoImpl->SetImageTakenDate(dt);
576 SysLog(NID_CNT, "pImageContentInfoImpl->takenDate = %ls", dt.ToString().GetPointer());
579 ret = image_meta_get_burst_id(pImageHandle.get(), &pTempValue);
580 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret),
581 "Failed to perform image_meta_get_burst_id operation.");
583 if (pTempValue != NULL)
585 pStrValue.reset(pTempValue);
586 String burstShotId(pStrValue.get());
588 pImageContentInfoImpl->SetBurstShotId(burstShotId);
589 SysLog(NID_CNT, "pImageContentInfoImpl->burstShotId = %ls", burstShotId.GetPointer());
595 // Fills AudioContentInfo information in the audio content data object.
597 _ContentUtility::FillAudioContentData(media_info_h mediaHandle, _AudioContentInfoImpl* pAudioContentInfoImpl)
599 SysTryReturnResult(NID_CNT, mediaHandle != null && pAudioContentInfoImpl != null, E_INVALID_ARG, "mediaHandle or pAudioContentInfoImpl is null.");
601 int ret = MEDIA_CONTENT_ERROR_NONE;
602 result r = E_SUCCESS;
606 std::unique_ptr<char, UtilCharDeleter> pTitle;
607 std::unique_ptr<char, UtilCharDeleter> pAlbumName;
608 std::unique_ptr<char, UtilCharDeleter> pArtistName;
609 std::unique_ptr<char, UtilCharDeleter> pGenreName;
610 std::unique_ptr<char, UtilCharDeleter> pComposerName;
611 std::unique_ptr<char, UtilCharDeleter> pYear;
612 std::unique_ptr<char, UtilCharDeleter> pCopyRight;
613 std::unique_ptr<char, UtilCharDeleter> pTrackNum;
615 audio_meta_h tempMeta = NULL;
617 ret = media_info_get_audio(mediaHandle, &tempMeta);
618 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_audio operation.");
620 std::unique_ptr<audio_meta_s, AudioMetaHandleDeleter> pAudioHandle(tempMeta);
621 SysTryReturnResult(NID_CNT, pAudioHandle != null, E_OUT_OF_MEMORY, "pAudioHandle is null.");
623 ret = audio_meta_get_bit_rate(pAudioHandle.get(), &bitrate);
624 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_bit_rate operation.");
626 char* pAudioMetaValue = null;
627 ret = audio_meta_get_title(pAudioHandle.get(), &pAudioMetaValue);
628 if (pAudioMetaValue != null)
630 pTitle.reset(pAudioMetaValue);
634 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_title operation.");
637 ret = audio_meta_get_album(pAudioHandle.get(), &pAudioMetaValue);
638 if (pAudioMetaValue != null)
640 pAlbumName.reset(pAudioMetaValue);
644 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_album operation.");
647 ret = audio_meta_get_artist(pAudioHandle.get(), &pAudioMetaValue);
648 if (pAudioMetaValue != null)
650 pArtistName.reset(pAudioMetaValue);
654 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_artist operation.");
657 ret = audio_meta_get_genre(pAudioHandle.get(), &pAudioMetaValue);
658 if (pAudioMetaValue != null)
660 pGenreName.reset(pAudioMetaValue);
664 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_genre operation.");
667 ret = audio_meta_get_composer(pAudioHandle.get(), &pAudioMetaValue);
668 if (pAudioMetaValue != null)
670 pComposerName.reset(pAudioMetaValue);
674 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_composer operation.");
677 ret = audio_meta_get_year(pAudioHandle.get(), &pAudioMetaValue);
678 if (pAudioMetaValue != null)
680 pYear.reset(pAudioMetaValue);
684 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_year operation.");
687 ret = audio_meta_get_copyright(pAudioHandle.get(), &pAudioMetaValue);
688 if (pAudioMetaValue != null)
690 pCopyRight.reset(pAudioMetaValue);
694 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_copyright operation.");
697 ret = audio_meta_get_track_num(pAudioHandle.get(), &pAudioMetaValue);
698 if (pAudioMetaValue != null)
700 pTrackNum.reset(pAudioMetaValue);
704 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_track_num operation.");
707 ret = audio_meta_get_duration(pAudioHandle.get(), &duration);
708 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_duration operation.");
710 pAudioContentInfoImpl->SetBitrate(bitrate);
712 if (pYear.get() != null)
714 SysLog(NID_CNT, "pAudioContentInfoImpl->pYear = %s", pYear.get());
716 String strYear(pYear.get());
717 if (strYear.CompareTo(L"Unknown") != 0)
721 r = Integer::Parse(strYear, releaseYear);
724 // It is one of the metadata. If error occurs, skip it for other metadata.
725 pAudioContentInfoImpl->SetReleaseYear(0);
727 SysLog(NID_CNT, "pAudioContentInfoImpl->pYear(invalid data) = %ls", strYear.GetPointer());
730 pAudioContentInfoImpl->SetReleaseYear(releaseYear);
734 if (pTitle.get() != NULL)
736 pAudioContentInfoImpl->SetTitle(String(pTitle.get()));
737 SysLog(NID_CNT, "pAudioContentInfoImpl->pTitle = %ls", (pAudioContentInfoImpl->GetTitle()).GetPointer());
740 if (pArtistName.get() != NULL)
742 pAudioContentInfoImpl->SetArtist(String(pArtistName.get()));
743 SysLog(NID_CNT, "pAudioContentInfoImpl->pArtist = %ls", (pAudioContentInfoImpl->GetArtist()).GetPointer());
746 if (pGenreName.get() != NULL)
748 pAudioContentInfoImpl->SetGenre(String(pGenreName.get()));
749 SysLog(NID_CNT, "pAudioContentInfoImpl->pGenre = %ls", (pAudioContentInfoImpl->GetGenre()).GetPointer());
752 if (pComposerName.get() != NULL)
754 pAudioContentInfoImpl->SetComposer(String(pComposerName.get()));
755 SysLog(NID_CNT, "pAudioContentInfoImpl->pComposer = %ls", (pAudioContentInfoImpl->GetComposer()).GetPointer());
758 if (pAlbumName.get() != NULL)
760 pAudioContentInfoImpl->SetAlbumName(String(pAlbumName.get()));
761 SysLog(NID_CNT, "pAudioContentInfoImpl->pAlbumName = %ls", (pAudioContentInfoImpl->GetAlbumName()).GetPointer());
764 if (pCopyRight.get() != NULL)
766 pAudioContentInfoImpl->SetCopyright(String(pCopyRight.get()));
767 SysLog(NID_CNT, "pAudioContentInfoImpl->pCopyright = %ls", (pAudioContentInfoImpl->GetCopyright()).GetPointer());
770 if (pTrackNum.get() != NULL)
772 pAudioContentInfoImpl->SetTrackInfo(String(pTrackNum.get()));
773 SysLog(NID_CNT, "pAudioContentInfoImpl->pTrackInfo = %ls", (pAudioContentInfoImpl->GetTrackInfo()).GetPointer());
776 pAudioContentInfoImpl->SetDuration(duration);
777 SysLog(NID_CNT,"pAudioContentInfoImpl->duration = %d", pAudioContentInfoImpl->GetDuration());
782 // Fills VideoContentInfo information in the video content data object.
784 _ContentUtility::FillVideoContentData(media_info_h mediaHandle, _VideoContentInfoImpl* pVideoContentInfoImpl)
786 SysTryReturnResult(NID_CNT, mediaHandle != null && pVideoContentInfoImpl != null, E_INVALID_ARG, "mediaHandle or pVideoContentInfoImpl is null.");
788 int ret = MEDIA_CONTENT_ERROR_NONE;
789 result r = E_SUCCESS;
792 std::unique_ptr<char, UtilCharDeleter> pArtistName;
793 std::unique_ptr<char, UtilCharDeleter> pGenreName;
794 std::unique_ptr<char, UtilCharDeleter> pTitle;
795 std::unique_ptr<char, UtilCharDeleter> pAlbumName;
798 video_meta_h tempMeta = NULL;
800 ret = media_info_get_video(mediaHandle, &tempMeta);
801 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_video operation.");
803 std::unique_ptr<video_meta_s, VideoMetaHandleDeleter> pVideoHandle(tempMeta);
804 SysTryReturnResult(NID_CNT, pVideoHandle != null, E_OUT_OF_MEMORY, "pVideoHandle is null.");
806 ret = video_meta_get_width(pVideoHandle.get(), &width);
807 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_width operation.");
809 ret = video_meta_get_height(pVideoHandle.get(), &height);
810 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_height operation.");
812 char* pVideoMetaValue = null;
813 ret = video_meta_get_artist(pVideoHandle.get(), &pVideoMetaValue);
814 if (pVideoMetaValue != null)
816 pArtistName.reset(pVideoMetaValue);
820 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_artist operation.");
823 ret = video_meta_get_genre(pVideoHandle.get(), &pVideoMetaValue);
824 if (pVideoMetaValue != null)
826 pGenreName.reset(pVideoMetaValue);
830 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_genre operation.");
833 ret = video_meta_get_title(pVideoHandle.get(), &pVideoMetaValue);
834 if (pVideoMetaValue != null)
836 pTitle.reset(pVideoMetaValue);
840 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_title operation.");
843 ret = video_meta_get_album(pVideoHandle.get(), &pVideoMetaValue);
844 if (pVideoMetaValue != null)
846 pAlbumName.reset(pVideoMetaValue);
850 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_album operation.");
853 ret = video_meta_get_duration(pVideoHandle.get(), &duration);
854 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_duration operation.");
856 pVideoContentInfoImpl->SetWidth(width);
857 pVideoContentInfoImpl->SetHeight(height);
859 if (pTitle.get() != NULL)
861 pVideoContentInfoImpl->SetTitle(String(pTitle.get()));
862 SysLog(NID_CNT, "pVideoContentInfoImpl->pTitle = %ls", (pVideoContentInfoImpl->GetTitle()).GetPointer());
865 if (pArtistName.get() != NULL)
867 pVideoContentInfoImpl->SetArtist(String(pArtistName.get()));
868 SysLog(NID_CNT, "pVideoContentInfoImpl->pArtist = %ls", (pVideoContentInfoImpl->GetArtist()).GetPointer());
871 if (pGenreName.get() != NULL)
873 pVideoContentInfoImpl->SetGenre(String(pGenreName.get()));
874 SysLog(NID_CNT, "pVideoContentInfoImpl->pGenre = %ls", (pVideoContentInfoImpl->GetGenre()).GetPointer());
877 if (pAlbumName.get() != NULL)
879 pVideoContentInfoImpl->SetAlbumName(String(pAlbumName.get()));
880 SysLog(NID_CNT, "pVideoContentInfoImpl->pAlbumName = %ls", (pVideoContentInfoImpl->GetAlbumName()).GetPointer());
883 pVideoContentInfoImpl->SetDuration(duration);
884 SysLog(NID_CNT,"pVideoContentInfoImpl->duration = %d", pVideoContentInfoImpl->GetDuration());
889 // Conversion of system errors to native errors
891 _ContentUtility::MapCoreErrorToNativeResult(int reason)
893 result r = E_SUCCESS;
896 case MEDIA_CONTENT_ERROR_NONE:
899 case MEDIA_CONTENT_ERROR_DB_BUSY:
901 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_DB_BUSY");
903 case MEDIA_CONTENT_ERROR_INVALID_PARAMETER:
905 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_INVALID_PARAMETER");
907 case MEDIA_CONTENT_ERROR_DB_FAILED:
909 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_DB_FAILED");
911 case MEDIA_CONTENT_ERROR_OUT_OF_MEMORY:
913 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_OUT_OF_MEMORY");
916 SysLog(NID_CNT, "default");