[content] Remove Open Service Platform words
[platform/framework/native/content.git] / src / FCnt_ContentUtility.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16 /**
17  * @file                FCnt_ContentUtility.cpp
18  * @brief               This is the implementation file for the %_ContentUtility class.
19  *
20  * This file contains implementation of the %_ContentUtility class.
21  */
22
23 #include <unique_ptr.h>
24 #include <FBaseSysLog.h>
25 #include <FBaseInteger.h>
26 #include <FBaseLongLong.h>
27 #include <FBaseFloat.h>
28 #include <FCnt_ContentUtility.h>
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32
33 namespace Tizen { namespace Content
34 {
35
36 static const double DEFAULT_COORDINATE = -200.0;
37
38 // Default constructor
39 _ContentUtility::_ContentUtility(void)
40         : Object()
41 {
42         SysLog(NID_CNT, "Enter\n");
43 }
44
45
46 // Default destructor
47 _ContentUtility::~_ContentUtility(void)
48 {
49         SysLog(NID_CNT, "Enter\n");
50 }
51
52 void
53 _ContentUtility::DoSafeFree(char* pSrc)
54 {
55         if (pSrc != NULL)
56         {
57                 free(pSrc);
58                 pSrc = NULL;
59         }
60 }
61
62 void
63 _ContentUtility::DoSafeDelete(String* pSrc)
64 {
65         if (pSrc != NULL)
66         {
67                 delete pSrc;
68                 pSrc = NULL;
69         }
70 }
71
72 // fills contentinfo information in the content data object.
73 result
74 _ContentUtility::FillContentData(media_info_h mediaHandle, ContentInfo::_ContentData* pContentData)
75 {
76
77         SysTryReturnResult(NID_CNT, mediaHandle != null && pContentData != null, E_INVALID_ARG, "mediaHandle or pContentData is null.");
78
79         int ret  = MEDIA_CONTENT_ERROR_NONE;
80         result r = E_SUCCESS;
81
82         std::unique_ptr<char, UtilCharDeleter> pMediaId;
83         std::unique_ptr<char, UtilCharDeleter> pContentName;
84         std::unique_ptr<char, UtilCharDeleter> pMediaPath;
85         std::unique_ptr<char, UtilCharDeleter> pThumbnailPath;
86         std::unique_ptr<char, UtilCharDeleter> pAuthor;
87         std::unique_ptr<char, UtilCharDeleter> pCategory;
88         std::unique_ptr<char, UtilCharDeleter> pDescription;
89         std::unique_ptr<char, UtilCharDeleter> pLocationTag;
90         std::unique_ptr<char, UtilCharDeleter> pProvider;
91         std::unique_ptr<char, UtilCharDeleter> pKeyword;
92         std::unique_ptr<char, UtilCharDeleter> pContentRating;
93         std::unique_ptr<char, UtilCharDeleter> pMimeType;
94
95         media_content_type_e mediaType;
96         media_content_storage_e storageType;
97
98         unsigned long long contentSize = 0;
99         time_t addedTime        = 0;
100         double latitude         = 0;
101         double longitude        = 0;
102         double altitude         = 0;
103
104         bool isDrm = 0;
105
106         char* pGetMediaValue = null;
107         ret = media_info_get_media_id(mediaHandle, &pGetMediaValue);
108         if (pGetMediaValue != null)
109         {
110                 pMediaId.reset(pGetMediaValue);
111         }
112         else
113         {
114                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_media_id operation.");
115         }
116
117         ret = media_info_get_content_name(mediaHandle, &pGetMediaValue);
118         if (pGetMediaValue != null)
119         {
120                 pContentName.reset(pGetMediaValue);
121         }
122         else
123         {
124                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_content_name operation.");
125         }
126
127         ret = media_info_get_file_path(mediaHandle, &pGetMediaValue);
128         if (pGetMediaValue != null)
129         {
130                 pMediaPath.reset(pGetMediaValue);
131         }
132         else
133         {
134                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_file_path operation.");
135         }
136
137         ret = media_info_get_thumbnail_path(mediaHandle, &pGetMediaValue);
138         if (pGetMediaValue != null)
139         {
140                 pThumbnailPath.reset(pGetMediaValue);
141         }
142         else
143         {
144                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_thumbnail_path operation.");
145         }
146
147         ret = media_info_get_author(mediaHandle, &pGetMediaValue);
148         if (pGetMediaValue != null)
149         {
150                 pAuthor.reset(pGetMediaValue);
151         }
152         else
153         {
154                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_author operation.");
155         }
156
157         ret = media_info_get_category(mediaHandle, &pGetMediaValue);
158         if (pGetMediaValue != null)
159         {
160                 pCategory.reset(pGetMediaValue);
161         }
162         else
163         {
164                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_category operation.");
165         }
166
167         ret = media_info_get_description(mediaHandle, &pGetMediaValue);
168         if (pGetMediaValue != null)
169         {
170                 pDescription.reset(pGetMediaValue);
171         }
172         else
173         {
174                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_description operation.");
175         }
176
177         ret = media_info_get_location_tag(mediaHandle, &pGetMediaValue);
178         if (pGetMediaValue != null)
179         {
180                 pLocationTag.reset(pGetMediaValue);
181         }
182         else
183         {
184                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_location_tag operation.");
185         }
186
187         ret = media_info_get_provider(mediaHandle, &pGetMediaValue);
188         if (pGetMediaValue != null)
189         {
190                 pProvider.reset(pGetMediaValue);
191         }
192         else
193         {
194                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_provider operation.");
195         }
196
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.");
199
200
201         ret = media_info_get_latitude(mediaHandle, &latitude);
202         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_latitude operation.");
203
204         ret = media_info_get_longitude(mediaHandle, &longitude);
205         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_longitude operation.");
206
207         ret = media_info_get_altitude(mediaHandle, &altitude);
208         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_altitude operation.");
209
210         ret = media_info_get_age_rating(mediaHandle, &pGetMediaValue);
211         if (pGetMediaValue != null)
212         {
213                 pContentRating.reset(pGetMediaValue);
214         }
215         else
216         {
217                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_age_rating operation.");
218         }
219
220         ret = media_info_is_drm(mediaHandle, &isDrm);
221         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_is_drm operation.");
222
223         ret = media_info_get_added_time(mediaHandle, &addedTime);
224         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_added_time operation.");
225
226         ret = media_info_get_storage_type(mediaHandle, &storageType);
227         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_storage_type operation.");
228
229         ret = media_info_get_media_type(mediaHandle, &mediaType);
230         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_media_type operation.");
231
232         ret = media_info_get_mime_type(mediaHandle, &pGetMediaValue);
233         if (pGetMediaValue != null)
234         {
235                 pMimeType.reset(pGetMediaValue);
236         }
237         else
238         {
239                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_mime_type operation.");
240         }
241
242         ret = media_info_get_keyword(mediaHandle, &pGetMediaValue);
243         if (pGetMediaValue != null)
244         {
245                 pKeyword.reset(pGetMediaValue);
246         }
247         else
248         {
249                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_keyword operation.");
250         }
251
252         if (pMediaId.get() != null)
253         {
254                 r = UuId::Parse(String(pMediaId.get()), pContentData->contentId);
255                 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform UuId::Parse operation.");
256         }
257
258         pContentData->isDrm = isDrm;
259         SysLog(NID_CNT, "pContentData->isDrm = %d", pContentData->isDrm);
260
261         pContentData->contentSize       = contentSize;
262         SysLog(NID_CNT, "pContentData->contentSize = %lu", pContentData->contentSize);
263
264         if (Double::Compare(latitude, DEFAULT_COORDINATE) != 0)
265         {
266                 pContentData->latitude          = latitude;
267         }
268         if (Double::Compare(longitude, DEFAULT_COORDINATE) != 0)
269         {
270                 pContentData->longitude         = longitude;
271         }
272         if (Double::Compare(altitude, DEFAULT_COORDINATE) != 0)
273         {
274                 pContentData->altitude          = altitude;
275         }
276
277         if (pMediaPath.get() != NULL)
278         {
279                 pContentData->contentPath       = String(pMediaPath.get());
280                 SysSecureLog(NID_CNT, "pContentData->contentPath = %ls", pContentData->contentPath.GetPointer());
281         }
282
283         if (pThumbnailPath.get() != NULL)
284         {
285                 pContentData->pThumbnailPath    = new (std::nothrow) String(pThumbnailPath.get());
286                 SysTryReturnResult(NID_CNT, pContentData->pThumbnailPath != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
287                 SysSecureLog(NID_CNT, "pContentData->pThumbnailPath = %ls", pContentData->pThumbnailPath->GetPointer());
288         }
289
290         if (pAuthor.get() != NULL)
291         {
292                 pContentData->pAuthor           = new (std::nothrow) String(pAuthor.get());
293                 SysTryReturnResult(NID_CNT, pContentData->pAuthor != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
294                 SysLog(NID_CNT, "pContentData->pAuthor = %ls", pContentData->pAuthor->GetPointer());
295         }
296
297         if (pCategory.get() != NULL)
298         {
299                 pContentData->pCategory         = new (std::nothrow) String(pCategory.get());
300                 SysTryReturnResult(NID_CNT, pContentData->pCategory != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
301                 SysLog(NID_CNT, "pContentData->pCategory = %ls", pContentData->pCategory->GetPointer());
302         }
303
304         if (pContentName.get() != NULL)
305         {
306                 pContentData->pContentName      = new (std::nothrow) String(pContentName.get());
307                 SysTryReturnResult(NID_CNT, pContentData->pContentName != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
308                 SysLog(NID_CNT, "pContentData->pContentName = %ls", pContentData->pContentName->GetPointer());
309         }
310
311         if (pDescription.get() != NULL)
312         {
313                 pContentData->pDescription      = new (std::nothrow) String(pDescription.get());
314                 SysTryReturnResult(NID_CNT, pContentData->pDescription != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
315                 SysLog(NID_CNT, "pContentData->pDescription = %ls", pContentData->pDescription->GetPointer());
316         }
317
318         if (pLocationTag.get() != NULL)
319         {
320                 pContentData->pLocationTag      = new (std::nothrow) String(pLocationTag.get());
321                 SysTryReturnResult(NID_CNT, pContentData->pLocationTag != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
322                 SysLog(NID_CNT, "pContentData->pLocationTag = %ls", pContentData->pLocationTag->GetPointer());
323         }
324
325         if (pProvider.get() != NULL)
326         {
327                 pContentData->pProvider         = new (std::nothrow) String(pProvider.get());
328                 SysTryReturnResult(NID_CNT, pContentData->pProvider != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
329                 SysLog(NID_CNT, "pContentData->pProvider = %ls", pContentData->pProvider->GetPointer());
330         }
331
332         if (pContentRating.get() != NULL)
333         {
334                 pContentData->pRating           = new (std::nothrow) String(pContentRating.get());
335                 SysTryReturnResult(NID_CNT, pContentData->pRating != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
336                 SysLog(NID_CNT, "pContentData->pRating = %ls", pContentData->pRating->GetPointer());
337         }
338
339         if (pKeyword.get() != NULL)
340         {
341                 pContentData->pKeyword  = new (std::nothrow) String(pKeyword.get());
342                 SysTryReturnResult(NID_CNT, pContentData->pKeyword != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
343                 SysLog(NID_CNT, "pContentData->pKeyword = %ls", pContentData->pKeyword->GetPointer());
344         }
345
346         if (pMimeType.get() != NULL)
347         {
348                 pContentData->mimeType  = String(pMimeType.get());
349                 SysLog(NID_CNT, "pContentData->mimeType = %ls", (pContentData->mimeType).GetPointer());
350         }
351
352         switch (storageType)
353         {
354         case MEDIA_CONTENT_STORAGE_INTERNAL:
355                 pContentData->storageType = 0;
356                 break;
357         case MEDIA_CONTENT_STORAGE_EXTERNAL:
358                 pContentData->storageType = 1;
359                 break;
360         default:
361                 break;
362         }
363         switch (mediaType)
364         {
365         case MEDIA_CONTENT_TYPE_OTHERS:
366                 pContentData->contentType       = CONTENT_TYPE_OTHER;
367                 break;
368         case MEDIA_CONTENT_TYPE_IMAGE:
369                 pContentData->contentType       = CONTENT_TYPE_IMAGE;
370                 break;
371         case MEDIA_CONTENT_TYPE_SOUND:
372                 //fall through
373         case MEDIA_CONTENT_TYPE_MUSIC:
374                 pContentData->contentType       = CONTENT_TYPE_AUDIO;
375                 break;
376         case MEDIA_CONTENT_TYPE_VIDEO:
377                 pContentData->contentType       = CONTENT_TYPE_VIDEO;
378                 break;
379         default:
380                 break;
381         }
382
383         r = (pContentData->dateTime).SetValue(1970, 1, 1);
384         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform datetime.SetValue operation.");
385
386         r = (pContentData->dateTime).AddSeconds(addedTime);// need to check addedTime is secs/millisec
387         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform datetime.AddSeconds operation.");
388
389         SysLog(NID_CNT, "addedTime = %ld", addedTime);
390         SysLog(NID_CNT, "pContentData->dateTime : %ls", pContentData->dateTime.ToString().GetPointer());
391
392         return r;
393 }
394
395 // fills Imagecontentinfo information in the image content data object .
396 result
397 _ContentUtility::FillImageContentData(media_info_h mediaHandle, ImageContentInfo::_ImageContentData* pImageContentData)
398 {
399         SysTryReturnResult(NID_CNT, mediaHandle != null && pImageContentData != null, E_INVALID_ARG, "mediaHandle or pImageContentData is null.");
400
401         int ret  = MEDIA_CONTENT_ERROR_NONE;
402         result r = E_SUCCESS;
403         int width  = 0;
404         int height = 0;
405         media_content_orientation_e orientation;
406         std::unique_ptr<char, UtilCharDeleter> pDisplayName;
407
408         char* pDisplayValue = null;
409         ret = media_info_get_display_name(mediaHandle, &pDisplayValue);
410         if (pDisplayValue != null)
411         {
412                 pDisplayName.reset(pDisplayValue);
413         }
414         else
415         {
416                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_display_name operation.");
417         }
418         
419         std::unique_ptr<image_meta_h, ImageMetaHandleDeleter> pImageHandle(new (std::nothrow) image_meta_h);
420         ret = media_info_get_image(mediaHandle, pImageHandle.get());
421
422         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_image operation.");
423
424         
425         ret = image_meta_get_width(*(pImageHandle.get()), &width);
426         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform image_meta_get_width operation.");
427
428         ret = image_meta_get_orientation(*(pImageHandle.get()), &orientation);
429         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform image_meta_get_orientation operation.");
430
431         ret = image_meta_get_height(*(pImageHandle.get()), &height);
432         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform image_meta_get_height operation.");
433
434         pImageContentData->width        = width;
435         pImageContentData->height       = height;
436         pImageContentData->orientationType      = static_cast<ImageOrientationType>(orientation);
437
438         if (pDisplayName != NULL)
439         {
440                 int pos = 0;
441                 String fileName = L"";
442                 String strTitle(pDisplayName.get());
443
444                 r = strTitle.LastIndexOf(L'.', strTitle.GetLength() - 1, pos);
445                 if (r == E_SUCCESS)
446                 {
447                         r = strTitle.SubString(0, pos, fileName);
448                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform string.SubString operation.");
449                 }
450                 else
451                 {
452                         // Without extension
453                         r = E_SUCCESS;
454                         fileName = strTitle;
455                 }
456                 pImageContentData->title = fileName;
457                 SysLog(NID_CNT, "pImageContentData->title = %ls", pImageContentData->title.GetPointer());
458         }
459
460         return r;
461 }
462
463 // fills audio contentinfo information in the audio content data object.
464 result
465 _ContentUtility::FillAudioContentData(media_info_h mediaHandle, AudioContentInfo::_AudioContentData* pAudioContentData)
466 {
467         SysTryReturnResult(NID_CNT, mediaHandle != null && pAudioContentData != null, E_INVALID_ARG, "mediaHandle or pAudioContentData is null.");
468
469         int ret  = MEDIA_CONTENT_ERROR_NONE;
470         result r = E_SUCCESS;
471         int bitrate = 0;
472         int duration = 0;
473
474         std::unique_ptr<char, UtilCharDeleter> pTitle;
475         std::unique_ptr<char, UtilCharDeleter> pAlbumName;
476         std::unique_ptr<char, UtilCharDeleter> pArtistName;
477         std::unique_ptr<char, UtilCharDeleter> pGenreName;
478         std::unique_ptr<char, UtilCharDeleter> pComposerName;
479         std::unique_ptr<char, UtilCharDeleter> pYear;
480         std::unique_ptr<char, UtilCharDeleter> pCopyRight;
481         std::unique_ptr<char, UtilCharDeleter> pTrackNum;
482
483
484         std::unique_ptr<audio_meta_h, AudioMetaHandleDeleter> pAudioHandle(new (std::nothrow) audio_meta_h);
485         ret = media_info_get_audio(mediaHandle, pAudioHandle.get());
486         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_audio operation.");
487
488         ret = audio_meta_get_bit_rate(*(pAudioHandle.get()), &bitrate);
489         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_bit_rate operation.");
490
491         char* pAudioMetaValue = null;
492         ret = audio_meta_get_title(*(pAudioHandle.get()), &pAudioMetaValue);
493         if (pAudioMetaValue != null)
494         {
495                 pTitle.reset(pAudioMetaValue);
496         }
497         else
498         {
499                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_title operation.");
500         }
501
502         ret = audio_meta_get_album(*(pAudioHandle.get()), &pAudioMetaValue);
503         if (pAudioMetaValue != null)
504         {
505                 pAlbumName.reset(pAudioMetaValue);
506         }
507         else
508         {
509                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_album operation.");
510         }
511
512         ret = audio_meta_get_artist(*(pAudioHandle.get()), &pAudioMetaValue);
513         if (pAudioMetaValue != null)
514         {
515                 pArtistName.reset(pAudioMetaValue);
516         }
517         else
518         {
519                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_artist operation.");
520         }
521
522         ret = audio_meta_get_genre(*(pAudioHandle.get()), &pAudioMetaValue);
523         if (pAudioMetaValue != null)
524         {
525                 pGenreName.reset(pAudioMetaValue);
526         }
527         else
528         {
529                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_genre operation.");
530         }
531
532         ret = audio_meta_get_composer(*(pAudioHandle.get()), &pAudioMetaValue);
533         if (pAudioMetaValue != null)
534         {
535                 pComposerName.reset(pAudioMetaValue);
536         }
537         else
538         {
539                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_composer operation.");
540         }
541
542         ret = audio_meta_get_year(*(pAudioHandle.get()), &pAudioMetaValue);
543         if (pAudioMetaValue != null)
544         {
545                 pYear.reset(pAudioMetaValue);
546         }
547         else
548         {
549                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_year operation.");
550         }
551
552         ret = audio_meta_get_copyright(*(pAudioHandle.get()), &pAudioMetaValue);
553         if (pAudioMetaValue != null)
554         {
555                 pCopyRight.reset(pAudioMetaValue);
556         }
557         else
558         {
559                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_copyright operation.");
560         }
561
562         ret = audio_meta_get_track_num(*(pAudioHandle.get()), &pAudioMetaValue);
563         if (pAudioMetaValue != null)
564         {
565                 pTrackNum.reset(pAudioMetaValue);
566         }
567         else
568         {
569                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_track_num operation.");
570         }
571
572         ret = audio_meta_get_duration(*(pAudioHandle.get()), &duration);
573         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_duration operation.");
574
575         pAudioContentData->bitrate      = bitrate;
576
577         if (pYear.get() != null)
578         {
579                 SysLog(NID_CNT, "pAudioContentData->pYear  = %s", pYear.get());
580
581                 String strYear(pYear.get());
582                 if (strYear.CompareTo(L"Unknown") != 0)
583                 {
584                         r = Integer::Parse(strYear, pAudioContentData->releaseYear);
585                         if (IsFailed(r))
586                         {
587                                 // It is one of the metadata. If error occurs, skip it for other metadata.
588                                 pAudioContentData->releaseYear = 0;
589                                 r = E_SUCCESS;
590                                 SysLog(NID_CNT, "pAudioContentData->pYear(invalid data) = %ls", strYear.GetPointer());
591                         }
592                 }
593         }
594
595         if (pTitle.get() != NULL)
596         {
597                 pAudioContentData->pTitle       = new (std::nothrow) String(pTitle.get());
598                 SysTryReturnResult(NID_CNT, pAudioContentData->pTitle != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
599                 SysLog(NID_CNT, "pAudioContentData->pTitle  = %ls", pAudioContentData->pTitle->GetPointer());
600         }
601
602         if (pArtistName.get() != NULL)
603         {
604                 pAudioContentData->pArtist      = new (std::nothrow) String(pArtistName.get());
605                 SysTryReturnResult(NID_CNT, pAudioContentData->pArtist != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
606                 SysLog(NID_CNT, "pAudioContentData->pArtist = %ls", pAudioContentData->pArtist->GetPointer());
607         }
608
609         if (pGenreName.get() != NULL)
610         {
611                 pAudioContentData->pGenre       = new (std::nothrow) String(pGenreName.get());
612                 SysTryReturnResult(NID_CNT, pAudioContentData->pGenre != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
613                 SysLog(NID_CNT, "pAudioContentData->pGenre = %ls", pAudioContentData->pGenre->GetPointer());
614         }
615
616         if (pComposerName.get() != NULL)
617         {
618                 pAudioContentData->pComposer    = new (std::nothrow) String(pComposerName.get());
619                 SysTryReturnResult(NID_CNT, pAudioContentData->pComposer != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
620                 SysLog(NID_CNT, "pAudioContentData->pComposer = %ls", pAudioContentData->pComposer->GetPointer());
621         }
622
623         if (pAlbumName.get() != NULL)
624         {
625                 pAudioContentData->pAlbumName   = new (std::nothrow) String(pAlbumName.get());
626                 SysTryReturnResult(NID_CNT, pAudioContentData->pAlbumName != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
627                 SysLog(NID_CNT, "pAudioContentData->pAlbumName  = %ls", pAudioContentData->pAlbumName->GetPointer());
628         }
629
630         if (pCopyRight.get() != NULL)
631         {
632                 pAudioContentData->pCopyright   = new (std::nothrow) String(pCopyRight.get());
633                 SysTryReturnResult(NID_CNT, pAudioContentData->pCopyright != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
634                 SysLog(NID_CNT, "pAudioContentData->pCopyright  = %ls", pAudioContentData->pCopyright->GetPointer());
635         }
636
637         if (pTrackNum.get() != NULL)
638         {
639                 pAudioContentData->pTrackInfo   = new (std::nothrow) String(pTrackNum.get());
640                 SysTryReturnResult(NID_CNT, pAudioContentData->pTrackInfo != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
641                 SysLog(NID_CNT, "pAudioContentData->pTrackInfo  = %ls", pAudioContentData->pTrackInfo->GetPointer());
642         }
643
644         pAudioContentData->duration = duration;
645         SysLog(NID_CNT,"pAudioContentData->duration = %d", pAudioContentData->duration);
646
647         return r;
648 }
649
650 // fills video contentinfo information in the video content data object.
651 result
652 _ContentUtility::FillVideoContentData(media_info_h mediaHandle, VideoContentInfo::_VideoContentData* pVideoContentData)
653 {
654         SysTryReturnResult(NID_CNT, mediaHandle != null && pVideoContentData != null, E_INVALID_ARG, "mediaHandle or pVideoContentData is null.");
655
656         int ret  = MEDIA_CONTENT_ERROR_NONE;
657         result r = E_SUCCESS;
658         int width  = 0;
659         int height = 0;
660         std::unique_ptr<char, UtilCharDeleter> pArtistName;
661         std::unique_ptr<char, UtilCharDeleter> pGenreName;
662         std::unique_ptr<char, UtilCharDeleter> pTitle;
663         std::unique_ptr<char, UtilCharDeleter> pAlbumName;
664         int duration = 0;
665
666         std::unique_ptr<video_meta_h, VideoMetaHandleDeleter> pVideoHandle(new (std::nothrow) video_meta_h);
667         ret = media_info_get_video(mediaHandle, pVideoHandle.get());
668         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_video operation.");
669
670         ret = video_meta_get_width(*(pVideoHandle.get()), &width);
671         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_width operation.");
672
673         ret = video_meta_get_height(*(pVideoHandle.get()), &height);
674         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_height operation.");
675
676         char* pVideoMetaValue = null;
677         ret = video_meta_get_artist(*(pVideoHandle.get()), &pVideoMetaValue);
678         if (pVideoMetaValue != null)
679         {
680                 pArtistName.reset(pVideoMetaValue);
681         }
682         else
683         {
684                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_artist operation.");
685         }
686
687         ret = video_meta_get_genre(*(pVideoHandle.get()), &pVideoMetaValue);
688         if (pVideoMetaValue != null)
689         {
690                 pGenreName.reset(pVideoMetaValue);
691         }
692         else
693         {
694                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_genre operation.");
695         }
696
697         ret = video_meta_get_title(*(pVideoHandle.get()), &pVideoMetaValue);
698         if (pVideoMetaValue != null)
699         {
700                 pTitle.reset(pVideoMetaValue);
701         }
702         else
703         {
704                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_title operation.");
705         }
706
707         ret = video_meta_get_album(*(pVideoHandle.get()), &pVideoMetaValue);
708         if (pVideoMetaValue != null)
709         {
710                 pAlbumName.reset(pVideoMetaValue);
711         }
712         else
713         {
714                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_album operation.");
715         }
716
717         ret = video_meta_get_duration(*(pVideoHandle.get()), &duration);
718         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_duration operation.");
719
720         pVideoContentData->width = width;
721         pVideoContentData->height = height;
722
723         if (pTitle.get() != NULL)
724         {
725                 pVideoContentData->pTitle  = new (std::nothrow) String(pTitle.get());
726                 SysTryReturnResult(NID_CNT, pVideoContentData->pTitle != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
727                 SysLog(NID_CNT, "pVideoContentData->pTitle = %ls", pVideoContentData->pTitle->GetPointer());
728         }
729
730         if (pArtistName.get() != NULL)
731         {
732                 pVideoContentData->pArtist = new (std::nothrow) String(pArtistName.get());
733                 SysTryReturnResult(NID_CNT, pVideoContentData->pArtist != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
734                 SysLog(NID_CNT, "pVideoContentData->pArtist = %ls", pVideoContentData->pArtist->GetPointer());
735         }
736
737         if (pGenreName.get() != NULL)
738         {
739                 pVideoContentData->pGenre  = new (std::nothrow) String(pGenreName.get());
740                 SysTryReturnResult(NID_CNT, pVideoContentData->pGenre != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
741                 SysLog(NID_CNT, "pVideoContentData->pGenre = %ls", pVideoContentData->pGenre->GetPointer());
742         }
743
744         if (pAlbumName.get() != NULL)
745         {
746                 pVideoContentData->pAlbumName  = new (std::nothrow) String(pAlbumName.get());
747                 SysTryReturnResult(NID_CNT, pVideoContentData->pAlbumName != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
748                 SysLog(NID_CNT, "pVideoContentData->pAlbumName = %ls", pVideoContentData->pAlbumName->GetPointer());
749         }
750
751         pVideoContentData->duration = duration;
752         SysLog(NID_CNT,"pVideoContentData->duration = %d", pVideoContentData->duration);
753
754         return r;
755 }
756
757 // Convertion of system errors to osp errors
758 result
759 _ContentUtility::MapCoreErrorToNativeResult(int reason)
760 {
761         result r = E_SUCCESS;
762         switch (reason)
763         {
764         case MEDIA_CONTENT_ERROR_NONE:
765                 r = E_SUCCESS;
766                 break;
767         case MEDIA_CONTENT_ERROR_DB_BUSY:
768                 r = E_SERVICE_BUSY;
769                 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_DB_BUSY");
770                 break;
771         case MEDIA_CONTENT_ERROR_INVALID_PARAMETER:
772                 r = E_INVALID_ARG;
773                 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_INVALID_PARAMETER");
774                 break;
775         case MEDIA_CONTENT_ERROR_DB_FAILED:
776                 r = E_DATABASE;
777                 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_DB_FAILED");
778                 break;
779         case MEDIA_CONTENT_ERROR_OUT_OF_MEMORY:
780                 r = E_OUT_OF_MEMORY;
781                 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_OUT_OF_MEMORY");
782                 break;
783         default:
784                 SysLog(NID_CNT, "default");
785                 r = E_SYSTEM;
786                 break;
787         }
788         return r;
789 }
790
791 }}