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 int DATE_TIME_TOKEN_COUNT = 6;
47 static const double DEFAULT_COORDINATE = -200.0;
49 // Default constructor
50 _ContentUtility::_ContentUtility(void)
57 _ContentUtility::~_ContentUtility(void)
63 _ContentUtility::DoSafeFree(char* pSrc)
71 // Fills ContentInfo information in the content data object.
73 _ContentUtility::FillContentData(media_info_h mediaHandle, _ContentInfoImpl* pInfoImpl)
75 SysTryReturnResult(NID_CNT, mediaHandle != null && pInfoImpl != null, E_INVALID_ARG, "mediaHandle or pInfoImpl is null.");
77 int ret = MEDIA_CONTENT_ERROR_NONE;
80 std::unique_ptr<char, UtilCharDeleter> pMediaId;
81 std::unique_ptr<char, UtilCharDeleter> pContentName;
82 std::unique_ptr<char, UtilCharDeleter> pMediaPath;
83 std::unique_ptr<char, UtilCharDeleter> pThumbnailPath;
84 std::unique_ptr<char, UtilCharDeleter> pAuthor;
85 std::unique_ptr<char, UtilCharDeleter> pCategory;
86 std::unique_ptr<char, UtilCharDeleter> pDescription;
87 std::unique_ptr<char, UtilCharDeleter> pLocationTag;
88 std::unique_ptr<char, UtilCharDeleter> pProvider;
89 std::unique_ptr<char, UtilCharDeleter> pKeyword;
90 std::unique_ptr<char, UtilCharDeleter> pContentRating;
91 std::unique_ptr<char, UtilCharDeleter> pMimeType;
93 media_content_type_e mediaType;
94 media_content_storage_e storageType;
96 unsigned long long contentSize = 0;
98 time_t modifiedTime = 0;
100 double longitude = 0;
102 Coordinates coordinates;
106 char* pGetMediaValue = null;
107 ret = media_info_get_media_id(mediaHandle, &pGetMediaValue);
108 if (pGetMediaValue != null)
110 pMediaId.reset(pGetMediaValue);
114 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_media_id operation.");
117 ret = media_info_get_content_name(mediaHandle, &pGetMediaValue);
118 if (pGetMediaValue != null)
120 pContentName.reset(pGetMediaValue);
124 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_content_name operation.");
127 ret = media_info_get_file_path(mediaHandle, &pGetMediaValue);
128 if (pGetMediaValue != null)
130 pMediaPath.reset(pGetMediaValue);
134 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_file_path operation.");
137 ret = media_info_get_thumbnail_path(mediaHandle, &pGetMediaValue);
138 if (pGetMediaValue != null)
140 pThumbnailPath.reset(pGetMediaValue);
144 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_thumbnail_path operation.");
147 ret = media_info_get_author(mediaHandle, &pGetMediaValue);
148 if (pGetMediaValue != null)
150 pAuthor.reset(pGetMediaValue);
154 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_author operation.");
157 ret = media_info_get_category(mediaHandle, &pGetMediaValue);
158 if (pGetMediaValue != null)
160 pCategory.reset(pGetMediaValue);
164 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_category operation.");
167 ret = media_info_get_description(mediaHandle, &pGetMediaValue);
168 if (pGetMediaValue != null)
170 pDescription.reset(pGetMediaValue);
174 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_description operation.");
177 ret = media_info_get_location_tag(mediaHandle, &pGetMediaValue);
178 if (pGetMediaValue != null)
180 pLocationTag.reset(pGetMediaValue);
184 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_location_tag operation.");
187 ret = media_info_get_provider(mediaHandle, &pGetMediaValue);
188 if (pGetMediaValue != null)
190 pProvider.reset(pGetMediaValue);
194 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_provider operation.");
197 ret = media_info_get_size(mediaHandle, &contentSize);
198 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 int tokenCount = strTok.GetTokenCount();
537 if (tokenCount == DATE_TIME_TOKEN_COUNT)
539 r = strTok.GetNextToken(token);
540 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
545 r = strTok.GetNextToken(token);
546 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
548 r = newDateTaken.Append(token);
549 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
551 r = newDateTaken.Append(L"/");
552 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
555 r = strTok.GetNextToken(token);
556 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
558 r = newDateTaken.Append(token);
559 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
561 r = newDateTaken.Append(L"/");
562 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
565 r = newDateTaken.Append(year);
566 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
568 r = newDateTaken.Append(L" ");
569 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
571 String newDelim(L" ");
573 r = strTok.SetDelimiters(newDelim);
574 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform SetDelimiters operation.");
576 r = strTok.GetNextToken(token);
577 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
579 r = newDateTaken.Append(token);
580 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
582 r = DateTime::Parse(newDateTaken, dt);
583 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform Parse operation for DateTime.");
587 dt = DateTime::GetMinValue();
592 dt = DateTime::GetMinValue();
595 pImageContentInfoImpl->SetImageTakenDate(dt);
596 SysLog(NID_CNT, "pImageContentInfoImpl->takenDate = %ls", dt.ToString().GetPointer());
599 ret = image_meta_get_burst_id(pImageHandle.get(), &pTempValue);
600 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret),
601 "Failed to perform image_meta_get_burst_id operation.");
603 if (pTempValue != NULL)
605 pStrValue.reset(pTempValue);
606 String burstShotId(pStrValue.get());
608 pImageContentInfoImpl->SetBurstShotId(burstShotId);
609 SysLog(NID_CNT, "pImageContentInfoImpl->burstShotId = %ls", burstShotId.GetPointer());
615 // Fills AudioContentInfo information in the audio content data object.
617 _ContentUtility::FillAudioContentData(media_info_h mediaHandle, _AudioContentInfoImpl* pAudioContentInfoImpl)
619 SysTryReturnResult(NID_CNT, mediaHandle != null && pAudioContentInfoImpl != null, E_INVALID_ARG, "mediaHandle or pAudioContentInfoImpl is null.");
621 int ret = MEDIA_CONTENT_ERROR_NONE;
622 result r = E_SUCCESS;
626 std::unique_ptr<char, UtilCharDeleter> pTitle;
627 std::unique_ptr<char, UtilCharDeleter> pAlbumName;
628 std::unique_ptr<char, UtilCharDeleter> pArtistName;
629 std::unique_ptr<char, UtilCharDeleter> pAlbumArtistName;
630 std::unique_ptr<char, UtilCharDeleter> pGenreName;
631 std::unique_ptr<char, UtilCharDeleter> pComposerName;
632 std::unique_ptr<char, UtilCharDeleter> pYear;
633 std::unique_ptr<char, UtilCharDeleter> pCopyRight;
634 std::unique_ptr<char, UtilCharDeleter> pTrackNum;
636 audio_meta_h tempMeta = NULL;
638 ret = media_info_get_audio(mediaHandle, &tempMeta);
639 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_audio operation.");
641 std::unique_ptr<audio_meta_s, AudioMetaHandleDeleter> pAudioHandle(tempMeta);
642 SysTryReturnResult(NID_CNT, pAudioHandle != null, E_OUT_OF_MEMORY, "pAudioHandle is null.");
644 ret = audio_meta_get_bit_rate(pAudioHandle.get(), &bitrate);
645 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_bit_rate operation.");
647 char* pAudioMetaValue = null;
648 ret = audio_meta_get_title(pAudioHandle.get(), &pAudioMetaValue);
649 if (pAudioMetaValue != null)
651 pTitle.reset(pAudioMetaValue);
655 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_title operation.");
658 ret = audio_meta_get_album(pAudioHandle.get(), &pAudioMetaValue);
659 if (pAudioMetaValue != null)
661 pAlbumName.reset(pAudioMetaValue);
665 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_album operation.");
668 ret = audio_meta_get_artist(pAudioHandle.get(), &pAudioMetaValue);
669 if (pAudioMetaValue != null)
671 pArtistName.reset(pAudioMetaValue);
675 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_artist operation.");
678 // Add to private for extension api
679 // ret = audio_meta_get_album_artist(pAudioHandle.get(), &pAudioMetaValue);
680 // if (pAudioMetaValue != null)
682 // pAlbumArtistName.reset(pAudioMetaValue);
686 // SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_album_artist operation.");
689 ret = audio_meta_get_genre(pAudioHandle.get(), &pAudioMetaValue);
690 if (pAudioMetaValue != null)
692 pGenreName.reset(pAudioMetaValue);
696 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_genre operation.");
699 ret = audio_meta_get_composer(pAudioHandle.get(), &pAudioMetaValue);
700 if (pAudioMetaValue != null)
702 pComposerName.reset(pAudioMetaValue);
706 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_composer operation.");
709 ret = audio_meta_get_year(pAudioHandle.get(), &pAudioMetaValue);
710 if (pAudioMetaValue != null)
712 pYear.reset(pAudioMetaValue);
716 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_year operation.");
719 ret = audio_meta_get_copyright(pAudioHandle.get(), &pAudioMetaValue);
720 if (pAudioMetaValue != null)
722 pCopyRight.reset(pAudioMetaValue);
726 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_copyright operation.");
729 ret = audio_meta_get_track_num(pAudioHandle.get(), &pAudioMetaValue);
730 if (pAudioMetaValue != null)
732 pTrackNum.reset(pAudioMetaValue);
736 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_track_num operation.");
739 ret = audio_meta_get_duration(pAudioHandle.get(), &duration);
740 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_duration operation.");
742 pAudioContentInfoImpl->SetBitrate(bitrate);
744 if (pYear.get() != null)
746 SysLog(NID_CNT, "pAudioContentInfoImpl->pYear = %s", pYear.get());
748 String strYear(pYear.get());
749 if (strYear.CompareTo(L"Unknown") != 0)
753 r = Integer::Parse(strYear, releaseYear);
756 // It is one of the metadata. If error occurs, skip it for other metadata.
757 pAudioContentInfoImpl->SetReleaseYear(0);
759 SysLog(NID_CNT, "pAudioContentInfoImpl->pYear(invalid data) = %ls", strYear.GetPointer());
762 pAudioContentInfoImpl->SetReleaseYear(releaseYear);
766 if (pTitle.get() != NULL)
768 pAudioContentInfoImpl->SetTitle(String(pTitle.get()));
769 SysLog(NID_CNT, "pAudioContentInfoImpl->pTitle = %ls", (pAudioContentInfoImpl->GetTitle()).GetPointer());
772 if (pArtistName.get() != NULL)
774 pAudioContentInfoImpl->SetArtist(String(pArtistName.get()));
775 SysLog(NID_CNT, "pAudioContentInfoImpl->pArtist = %ls", (pAudioContentInfoImpl->GetArtist()).GetPointer());
778 // Add to private for extension api
779 // if (pAlbumArtistName.get() != NULL)
781 // pAudioContentInfoImpl->SetAlbumArtist(String(pAlbumArtistName.get()));
782 // SysLog(NID_CNT, "pAudioContentInfoImpl->pAlbumArtist = %ls", (pAudioContentInfoImpl->GetAlbumArtist()).GetPointer());
785 if (pGenreName.get() != NULL)
787 pAudioContentInfoImpl->SetGenre(String(pGenreName.get()));
788 SysLog(NID_CNT, "pAudioContentInfoImpl->pGenre = %ls", (pAudioContentInfoImpl->GetGenre()).GetPointer());
791 if (pComposerName.get() != NULL)
793 pAudioContentInfoImpl->SetComposer(String(pComposerName.get()));
794 SysLog(NID_CNT, "pAudioContentInfoImpl->pComposer = %ls", (pAudioContentInfoImpl->GetComposer()).GetPointer());
797 if (pAlbumName.get() != NULL)
799 pAudioContentInfoImpl->SetAlbumName(String(pAlbumName.get()));
800 SysLog(NID_CNT, "pAudioContentInfoImpl->pAlbumName = %ls", (pAudioContentInfoImpl->GetAlbumName()).GetPointer());
803 if (pCopyRight.get() != NULL)
805 pAudioContentInfoImpl->SetCopyright(String(pCopyRight.get()));
806 SysLog(NID_CNT, "pAudioContentInfoImpl->pCopyright = %ls", (pAudioContentInfoImpl->GetCopyright()).GetPointer());
809 if (pTrackNum.get() != NULL)
811 pAudioContentInfoImpl->SetTrackInfo(String(pTrackNum.get()));
812 SysLog(NID_CNT, "pAudioContentInfoImpl->pTrackInfo = %ls", (pAudioContentInfoImpl->GetTrackInfo()).GetPointer());
815 pAudioContentInfoImpl->SetDuration(duration);
816 SysLog(NID_CNT,"pAudioContentInfoImpl->duration = %d", pAudioContentInfoImpl->GetDuration());
821 // Fills VideoContentInfo information in the video content data object.
823 _ContentUtility::FillVideoContentData(media_info_h mediaHandle, _VideoContentInfoImpl* pVideoContentInfoImpl)
825 SysTryReturnResult(NID_CNT, mediaHandle != null && pVideoContentInfoImpl != null, E_INVALID_ARG, "mediaHandle or pVideoContentInfoImpl is null.");
827 int ret = MEDIA_CONTENT_ERROR_NONE;
828 result r = E_SUCCESS;
831 std::unique_ptr<char, UtilCharDeleter> pArtistName;
832 std::unique_ptr<char, UtilCharDeleter> pGenreName;
833 std::unique_ptr<char, UtilCharDeleter> pTitle;
834 std::unique_ptr<char, UtilCharDeleter> pAlbumName;
835 std::unique_ptr<char, UtilCharDeleter> pRecordedDate;
838 video_meta_h tempMeta = NULL;
840 ret = media_info_get_video(mediaHandle, &tempMeta);
841 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_video operation.");
843 std::unique_ptr<video_meta_s, VideoMetaHandleDeleter> pVideoHandle(tempMeta);
844 SysTryReturnResult(NID_CNT, pVideoHandle != null, E_OUT_OF_MEMORY, "pVideoHandle is null.");
846 ret = video_meta_get_width(pVideoHandle.get(), &width);
847 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_width operation.");
849 ret = video_meta_get_height(pVideoHandle.get(), &height);
850 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_height operation.");
852 char* pVideoMetaValue = null;
853 ret = video_meta_get_artist(pVideoHandle.get(), &pVideoMetaValue);
854 if (pVideoMetaValue != null)
856 pArtistName.reset(pVideoMetaValue);
860 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_artist operation.");
863 ret = video_meta_get_genre(pVideoHandle.get(), &pVideoMetaValue);
864 if (pVideoMetaValue != null)
866 pGenreName.reset(pVideoMetaValue);
870 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_genre operation.");
873 ret = video_meta_get_title(pVideoHandle.get(), &pVideoMetaValue);
874 if (pVideoMetaValue != null)
876 pTitle.reset(pVideoMetaValue);
880 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_title operation.");
883 ret = video_meta_get_album(pVideoHandle.get(), &pVideoMetaValue);
884 if (pVideoMetaValue != null)
886 pAlbumName.reset(pVideoMetaValue);
890 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_album operation.");
893 ret = video_meta_get_duration(pVideoHandle.get(), &duration);
894 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_duration operation.");
896 pVideoContentInfoImpl->SetWidth(width);
897 pVideoContentInfoImpl->SetHeight(height);
899 if (pTitle.get() != NULL)
901 pVideoContentInfoImpl->SetTitle(String(pTitle.get()));
902 SysLog(NID_CNT, "pVideoContentInfoImpl->pTitle = %ls", (pVideoContentInfoImpl->GetTitle()).GetPointer());
905 if (pArtistName.get() != NULL)
907 pVideoContentInfoImpl->SetArtist(String(pArtistName.get()));
908 SysLog(NID_CNT, "pVideoContentInfoImpl->pArtist = %ls", (pVideoContentInfoImpl->GetArtist()).GetPointer());
911 if (pGenreName.get() != NULL)
913 pVideoContentInfoImpl->SetGenre(String(pGenreName.get()));
914 SysLog(NID_CNT, "pVideoContentInfoImpl->pGenre = %ls", (pVideoContentInfoImpl->GetGenre()).GetPointer());
917 if (pAlbumName.get() != NULL)
919 pVideoContentInfoImpl->SetAlbumName(String(pAlbumName.get()));
920 SysLog(NID_CNT, "pVideoContentInfoImpl->pAlbumName = %ls", (pVideoContentInfoImpl->GetAlbumName()).GetPointer());
923 pVideoContentInfoImpl->SetDuration(duration);
924 SysLog(NID_CNT,"pVideoContentInfoImpl->duration = %d", pVideoContentInfoImpl->GetDuration());
927 ret = video_meta_get_recorded_date(pVideoHandle.get(), &pVideoMetaValue);
928 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret),
929 "Failed to perform video_meta_get_recorded_date operation.");
933 if (pVideoMetaValue != NULL)
935 pRecordedDate.reset(pVideoMetaValue);
936 String recordedDate(pRecordedDate.get());
937 String newRecordedDate(L"");
939 // detour the unexpected recorded date format
940 String tempDelim(L"+-Z");
943 StringTokenizer tempStrTok(recordedDate, tempDelim);
945 r = tempStrTok.GetNextToken(token);
946 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
948 recordedDate = token;
953 StringTokenizer strTok(recordedDate, delim);
955 r = strTok.SetDelimiters(delim);
956 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform SetDelimiters operation.");
958 int tokenCount = strTok.GetTokenCount();
959 if (tokenCount == DATE_TIME_TOKEN_COUNT)
961 r = strTok.GetNextToken(token);
962 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
967 r = strTok.GetNextToken(token);
968 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
970 r = newRecordedDate.Append(token);
971 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
973 r = newRecordedDate.Append(L"/");
974 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
977 r = strTok.GetNextToken(token);
978 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
980 r = newRecordedDate.Append(token);
981 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
983 r = newRecordedDate.Append(L"/");
984 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
987 r = newRecordedDate.Append(year);
988 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
990 r = newRecordedDate.Append(L" ");
991 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
993 String newDelim(L" ");
995 r = strTok.SetDelimiters(newDelim);
996 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform SetDelimiters operation.");
998 r = strTok.GetNextToken(token);
999 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1001 r = newRecordedDate.Append(token);
1002 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1004 r = DateTime::Parse(newRecordedDate, dt);
1005 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform Parse operation for DateTime.");
1009 dt = DateTime::GetMinValue();
1014 dt = DateTime::GetMinValue();
1017 pVideoContentInfoImpl->SetVideoRecordedDate(dt);
1018 SysLog(NID_CNT, "pVideoContentInfoImpl->recordedDate = %ls", dt.ToString().GetPointer());
1023 // Conversion of system errors to native errors
1025 _ContentUtility::MapCoreErrorToNativeResult(int reason)
1027 result r = E_SUCCESS;
1030 case MEDIA_CONTENT_ERROR_NONE:
1033 case MEDIA_CONTENT_ERROR_DB_BUSY:
1035 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_DB_BUSY");
1037 case MEDIA_CONTENT_ERROR_INVALID_PARAMETER:
1039 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_INVALID_PARAMETER");
1041 case MEDIA_CONTENT_ERROR_DB_FAILED:
1043 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_DB_FAILED");
1045 case MEDIA_CONTENT_ERROR_OUT_OF_MEMORY:
1046 r = E_OUT_OF_MEMORY;
1047 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_OUT_OF_MEMORY");
1050 SysLog(NID_CNT, "default");