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