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"");
517 // detour the unexpected datetaken format
518 String tempDelim(L"+-Z");
521 StringTokenizer tempStrTok(dateTaken, tempDelim);
523 r = tempStrTok.GetNextToken(token);
524 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
531 StringTokenizer strTok(dateTaken, delim);
533 r = strTok.SetDelimiters(delim);
534 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform SetDelimiters operation.");
536 r = strTok.GetNextToken(token);
537 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
542 r = strTok.GetNextToken(token);
543 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
545 r = newDateTaken.Append(token);
546 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
548 r = newDateTaken.Append(L"/");
549 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
552 r = strTok.GetNextToken(token);
553 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
555 r = newDateTaken.Append(token);
556 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
558 r = newDateTaken.Append(L"/");
559 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
562 r = newDateTaken.Append(year);
563 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
565 r = newDateTaken.Append(L" ");
566 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
568 String newDelim(L" ");
570 r = strTok.SetDelimiters(newDelim);
571 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform SetDelimiters operation.");
573 r = strTok.GetNextToken(token);
574 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
576 r = newDateTaken.Append(token);
577 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
579 r = DateTime::Parse(newDateTaken, dt);
580 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform Parse operation for DateTime.");
584 dt = DateTime::GetMinValue();
587 pImageContentInfoImpl->SetImageTakenDate(dt);
588 SysLog(NID_CNT, "pImageContentInfoImpl->takenDate = %ls", dt.ToString().GetPointer());
591 ret = image_meta_get_burst_id(pImageHandle.get(), &pTempValue);
592 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret),
593 "Failed to perform image_meta_get_burst_id operation.");
595 if (pTempValue != NULL)
597 pStrValue.reset(pTempValue);
598 String burstShotId(pStrValue.get());
600 pImageContentInfoImpl->SetBurstShotId(burstShotId);
601 SysLog(NID_CNT, "pImageContentInfoImpl->burstShotId = %ls", burstShotId.GetPointer());
607 // Fills AudioContentInfo information in the audio content data object.
609 _ContentUtility::FillAudioContentData(media_info_h mediaHandle, _AudioContentInfoImpl* pAudioContentInfoImpl)
611 SysTryReturnResult(NID_CNT, mediaHandle != null && pAudioContentInfoImpl != null, E_INVALID_ARG, "mediaHandle or pAudioContentInfoImpl is null.");
613 int ret = MEDIA_CONTENT_ERROR_NONE;
614 result r = E_SUCCESS;
618 std::unique_ptr<char, UtilCharDeleter> pTitle;
619 std::unique_ptr<char, UtilCharDeleter> pAlbumName;
620 std::unique_ptr<char, UtilCharDeleter> pArtistName;
621 std::unique_ptr<char, UtilCharDeleter> pGenreName;
622 std::unique_ptr<char, UtilCharDeleter> pComposerName;
623 std::unique_ptr<char, UtilCharDeleter> pYear;
624 std::unique_ptr<char, UtilCharDeleter> pCopyRight;
625 std::unique_ptr<char, UtilCharDeleter> pTrackNum;
627 audio_meta_h tempMeta = NULL;
629 ret = media_info_get_audio(mediaHandle, &tempMeta);
630 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_audio operation.");
632 std::unique_ptr<audio_meta_s, AudioMetaHandleDeleter> pAudioHandle(tempMeta);
633 SysTryReturnResult(NID_CNT, pAudioHandle != null, E_OUT_OF_MEMORY, "pAudioHandle is null.");
635 ret = audio_meta_get_bit_rate(pAudioHandle.get(), &bitrate);
636 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_bit_rate operation.");
638 char* pAudioMetaValue = null;
639 ret = audio_meta_get_title(pAudioHandle.get(), &pAudioMetaValue);
640 if (pAudioMetaValue != null)
642 pTitle.reset(pAudioMetaValue);
646 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_title operation.");
649 ret = audio_meta_get_album(pAudioHandle.get(), &pAudioMetaValue);
650 if (pAudioMetaValue != null)
652 pAlbumName.reset(pAudioMetaValue);
656 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_album operation.");
659 ret = audio_meta_get_artist(pAudioHandle.get(), &pAudioMetaValue);
660 if (pAudioMetaValue != null)
662 pArtistName.reset(pAudioMetaValue);
666 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_artist operation.");
669 ret = audio_meta_get_genre(pAudioHandle.get(), &pAudioMetaValue);
670 if (pAudioMetaValue != null)
672 pGenreName.reset(pAudioMetaValue);
676 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_genre operation.");
679 ret = audio_meta_get_composer(pAudioHandle.get(), &pAudioMetaValue);
680 if (pAudioMetaValue != null)
682 pComposerName.reset(pAudioMetaValue);
686 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_composer operation.");
689 ret = audio_meta_get_year(pAudioHandle.get(), &pAudioMetaValue);
690 if (pAudioMetaValue != null)
692 pYear.reset(pAudioMetaValue);
696 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_year operation.");
699 ret = audio_meta_get_copyright(pAudioHandle.get(), &pAudioMetaValue);
700 if (pAudioMetaValue != null)
702 pCopyRight.reset(pAudioMetaValue);
706 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_copyright operation.");
709 ret = audio_meta_get_track_num(pAudioHandle.get(), &pAudioMetaValue);
710 if (pAudioMetaValue != null)
712 pTrackNum.reset(pAudioMetaValue);
716 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_track_num operation.");
719 ret = audio_meta_get_duration(pAudioHandle.get(), &duration);
720 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_duration operation.");
722 pAudioContentInfoImpl->SetBitrate(bitrate);
724 if (pYear.get() != null)
726 SysLog(NID_CNT, "pAudioContentInfoImpl->pYear = %s", pYear.get());
728 String strYear(pYear.get());
729 if (strYear.CompareTo(L"Unknown") != 0)
733 r = Integer::Parse(strYear, releaseYear);
736 // It is one of the metadata. If error occurs, skip it for other metadata.
737 pAudioContentInfoImpl->SetReleaseYear(0);
739 SysLog(NID_CNT, "pAudioContentInfoImpl->pYear(invalid data) = %ls", strYear.GetPointer());
742 pAudioContentInfoImpl->SetReleaseYear(releaseYear);
746 if (pTitle.get() != NULL)
748 pAudioContentInfoImpl->SetTitle(String(pTitle.get()));
749 SysLog(NID_CNT, "pAudioContentInfoImpl->pTitle = %ls", (pAudioContentInfoImpl->GetTitle()).GetPointer());
752 if (pArtistName.get() != NULL)
754 pAudioContentInfoImpl->SetArtist(String(pArtistName.get()));
755 SysLog(NID_CNT, "pAudioContentInfoImpl->pArtist = %ls", (pAudioContentInfoImpl->GetArtist()).GetPointer());
758 if (pGenreName.get() != NULL)
760 pAudioContentInfoImpl->SetGenre(String(pGenreName.get()));
761 SysLog(NID_CNT, "pAudioContentInfoImpl->pGenre = %ls", (pAudioContentInfoImpl->GetGenre()).GetPointer());
764 if (pComposerName.get() != NULL)
766 pAudioContentInfoImpl->SetComposer(String(pComposerName.get()));
767 SysLog(NID_CNT, "pAudioContentInfoImpl->pComposer = %ls", (pAudioContentInfoImpl->GetComposer()).GetPointer());
770 if (pAlbumName.get() != NULL)
772 pAudioContentInfoImpl->SetAlbumName(String(pAlbumName.get()));
773 SysLog(NID_CNT, "pAudioContentInfoImpl->pAlbumName = %ls", (pAudioContentInfoImpl->GetAlbumName()).GetPointer());
776 if (pCopyRight.get() != NULL)
778 pAudioContentInfoImpl->SetCopyright(String(pCopyRight.get()));
779 SysLog(NID_CNT, "pAudioContentInfoImpl->pCopyright = %ls", (pAudioContentInfoImpl->GetCopyright()).GetPointer());
782 if (pTrackNum.get() != NULL)
784 pAudioContentInfoImpl->SetTrackInfo(String(pTrackNum.get()));
785 SysLog(NID_CNT, "pAudioContentInfoImpl->pTrackInfo = %ls", (pAudioContentInfoImpl->GetTrackInfo()).GetPointer());
788 pAudioContentInfoImpl->SetDuration(duration);
789 SysLog(NID_CNT,"pAudioContentInfoImpl->duration = %d", pAudioContentInfoImpl->GetDuration());
794 // Fills VideoContentInfo information in the video content data object.
796 _ContentUtility::FillVideoContentData(media_info_h mediaHandle, _VideoContentInfoImpl* pVideoContentInfoImpl)
798 SysTryReturnResult(NID_CNT, mediaHandle != null && pVideoContentInfoImpl != null, E_INVALID_ARG, "mediaHandle or pVideoContentInfoImpl is null.");
800 int ret = MEDIA_CONTENT_ERROR_NONE;
801 result r = E_SUCCESS;
804 std::unique_ptr<char, UtilCharDeleter> pArtistName;
805 std::unique_ptr<char, UtilCharDeleter> pGenreName;
806 std::unique_ptr<char, UtilCharDeleter> pTitle;
807 std::unique_ptr<char, UtilCharDeleter> pAlbumName;
810 video_meta_h tempMeta = NULL;
812 ret = media_info_get_video(mediaHandle, &tempMeta);
813 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_video operation.");
815 std::unique_ptr<video_meta_s, VideoMetaHandleDeleter> pVideoHandle(tempMeta);
816 SysTryReturnResult(NID_CNT, pVideoHandle != null, E_OUT_OF_MEMORY, "pVideoHandle is null.");
818 ret = video_meta_get_width(pVideoHandle.get(), &width);
819 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_width operation.");
821 ret = video_meta_get_height(pVideoHandle.get(), &height);
822 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_height operation.");
824 char* pVideoMetaValue = null;
825 ret = video_meta_get_artist(pVideoHandle.get(), &pVideoMetaValue);
826 if (pVideoMetaValue != null)
828 pArtistName.reset(pVideoMetaValue);
832 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_artist operation.");
835 ret = video_meta_get_genre(pVideoHandle.get(), &pVideoMetaValue);
836 if (pVideoMetaValue != null)
838 pGenreName.reset(pVideoMetaValue);
842 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_genre operation.");
845 ret = video_meta_get_title(pVideoHandle.get(), &pVideoMetaValue);
846 if (pVideoMetaValue != null)
848 pTitle.reset(pVideoMetaValue);
852 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_title operation.");
855 ret = video_meta_get_album(pVideoHandle.get(), &pVideoMetaValue);
856 if (pVideoMetaValue != null)
858 pAlbumName.reset(pVideoMetaValue);
862 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_album operation.");
865 ret = video_meta_get_duration(pVideoHandle.get(), &duration);
866 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_duration operation.");
868 pVideoContentInfoImpl->SetWidth(width);
869 pVideoContentInfoImpl->SetHeight(height);
871 if (pTitle.get() != NULL)
873 pVideoContentInfoImpl->SetTitle(String(pTitle.get()));
874 SysLog(NID_CNT, "pVideoContentInfoImpl->pTitle = %ls", (pVideoContentInfoImpl->GetTitle()).GetPointer());
877 if (pArtistName.get() != NULL)
879 pVideoContentInfoImpl->SetArtist(String(pArtistName.get()));
880 SysLog(NID_CNT, "pVideoContentInfoImpl->pArtist = %ls", (pVideoContentInfoImpl->GetArtist()).GetPointer());
883 if (pGenreName.get() != NULL)
885 pVideoContentInfoImpl->SetGenre(String(pGenreName.get()));
886 SysLog(NID_CNT, "pVideoContentInfoImpl->pGenre = %ls", (pVideoContentInfoImpl->GetGenre()).GetPointer());
889 if (pAlbumName.get() != NULL)
891 pVideoContentInfoImpl->SetAlbumName(String(pAlbumName.get()));
892 SysLog(NID_CNT, "pVideoContentInfoImpl->pAlbumName = %ls", (pVideoContentInfoImpl->GetAlbumName()).GetPointer());
895 pVideoContentInfoImpl->SetDuration(duration);
896 SysLog(NID_CNT,"pVideoContentInfoImpl->duration = %d", pVideoContentInfoImpl->GetDuration());
901 // Conversion of system errors to native errors
903 _ContentUtility::MapCoreErrorToNativeResult(int reason)
905 result r = E_SUCCESS;
908 case MEDIA_CONTENT_ERROR_NONE:
911 case MEDIA_CONTENT_ERROR_DB_BUSY:
913 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_DB_BUSY");
915 case MEDIA_CONTENT_ERROR_INVALID_PARAMETER:
917 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_INVALID_PARAMETER");
919 case MEDIA_CONTENT_ERROR_DB_FAILED:
921 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_DB_FAILED");
923 case MEDIA_CONTENT_ERROR_OUT_OF_MEMORY:
925 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_OUT_OF_MEMORY");
928 SysLog(NID_CNT, "default");