[content] Fix a buf on ContentTransfer
[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         image_meta_h tempMeta = NULL;
420
421         ret = media_info_get_image(mediaHandle, &tempMeta);
422         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_image operation.");
423
424         std::unique_ptr<image_meta_s, ImageMetaHandleDeleter> pImageHandle(tempMeta);
425         SysTryReturnResult(NID_CNT, pImageHandle != null, E_OUT_OF_MEMORY, "pImageHandle is null.");
426
427         ret = image_meta_get_width(pImageHandle.get(), &width);
428         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform image_meta_get_width operation.");
429
430         ret = image_meta_get_orientation(pImageHandle.get(), &orientation);
431         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform image_meta_get_orientation operation.");
432
433         ret = image_meta_get_height(pImageHandle.get(), &height);
434         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform image_meta_get_height operation.");
435
436         pImageContentData->width        = width;
437         pImageContentData->height = height;
438         pImageContentData->orientationType      = static_cast<ImageOrientationType>(orientation);
439
440         if (pDisplayName != NULL)
441         {
442                 int pos = 0;
443                 String fileName = L"";
444                 String strTitle(pDisplayName.get());
445
446                 r = strTitle.LastIndexOf(L'.', strTitle.GetLength() - 1, pos);
447                 if (r == E_SUCCESS)
448                 {
449                         r = strTitle.SubString(0, pos, fileName);
450                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform string.SubString operation.");
451                 }
452                 else
453                 {
454                         // Without extension
455                         r = E_SUCCESS;
456                         fileName = strTitle;
457                 }
458                 pImageContentData->title = fileName;
459                 SysLog(NID_CNT, "pImageContentData->title = %ls", pImageContentData->title.GetPointer());
460         }
461
462         return r;
463 }
464
465 // fills audio contentinfo information in the audio content data object.
466 result
467 _ContentUtility::FillAudioContentData(media_info_h mediaHandle, AudioContentInfo::_AudioContentData* pAudioContentData)
468 {
469         SysTryReturnResult(NID_CNT, mediaHandle != null && pAudioContentData != null, E_INVALID_ARG, "mediaHandle or pAudioContentData is null.");
470
471         int ret  = MEDIA_CONTENT_ERROR_NONE;
472         result r = E_SUCCESS;
473         int bitrate = 0;
474         int duration = 0;
475
476         std::unique_ptr<char, UtilCharDeleter> pTitle;
477         std::unique_ptr<char, UtilCharDeleter> pAlbumName;
478         std::unique_ptr<char, UtilCharDeleter> pArtistName;
479         std::unique_ptr<char, UtilCharDeleter> pGenreName;
480         std::unique_ptr<char, UtilCharDeleter> pComposerName;
481         std::unique_ptr<char, UtilCharDeleter> pYear;
482         std::unique_ptr<char, UtilCharDeleter> pCopyRight;
483         std::unique_ptr<char, UtilCharDeleter> pTrackNum;
484
485         audio_meta_h tempMeta = NULL;
486
487         ret = media_info_get_audio(mediaHandle, &tempMeta);
488         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_audio operation.");
489
490         std::unique_ptr<audio_meta_s, AudioMetaHandleDeleter> pAudioHandle(tempMeta);
491         SysTryReturnResult(NID_CNT, pAudioHandle != null, E_OUT_OF_MEMORY, "pAudioHandle is null.");
492
493         ret = audio_meta_get_bit_rate(pAudioHandle.get(), &bitrate);
494         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_bit_rate operation.");
495
496         char* pAudioMetaValue = null;
497         ret = audio_meta_get_title(pAudioHandle.get(), &pAudioMetaValue);
498         if (pAudioMetaValue != null)
499         {
500                 pTitle.reset(pAudioMetaValue);
501         }
502         else
503         {
504                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_title operation.");
505         }
506
507         ret = audio_meta_get_album(pAudioHandle.get(), &pAudioMetaValue);
508         if (pAudioMetaValue != null)
509         {
510                 pAlbumName.reset(pAudioMetaValue);
511         }
512         else
513         {
514                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_album operation.");
515         }
516
517         ret = audio_meta_get_artist(pAudioHandle.get(), &pAudioMetaValue);
518         if (pAudioMetaValue != null)
519         {
520                 pArtistName.reset(pAudioMetaValue);
521         }
522         else
523         {
524                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_artist operation.");
525         }
526
527         ret = audio_meta_get_genre(pAudioHandle.get(), &pAudioMetaValue);
528         if (pAudioMetaValue != null)
529         {
530                 pGenreName.reset(pAudioMetaValue);
531         }
532         else
533         {
534                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_genre operation.");
535         }
536
537         ret = audio_meta_get_composer(pAudioHandle.get(), &pAudioMetaValue);
538         if (pAudioMetaValue != null)
539         {
540                 pComposerName.reset(pAudioMetaValue);
541         }
542         else
543         {
544                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_composer operation.");
545         }
546
547         ret = audio_meta_get_year(pAudioHandle.get(), &pAudioMetaValue);
548         if (pAudioMetaValue != null)
549         {
550                 pYear.reset(pAudioMetaValue);
551         }
552         else
553         {
554                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_year operation.");
555         }
556
557         ret = audio_meta_get_copyright(pAudioHandle.get(), &pAudioMetaValue);
558         if (pAudioMetaValue != null)
559         {
560                 pCopyRight.reset(pAudioMetaValue);
561         }
562         else
563         {
564                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_copyright operation.");
565         }
566
567         ret = audio_meta_get_track_num(pAudioHandle.get(), &pAudioMetaValue);
568         if (pAudioMetaValue != null)
569         {
570                 pTrackNum.reset(pAudioMetaValue);
571         }
572         else
573         {
574                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_track_num operation.");
575         }
576
577         ret = audio_meta_get_duration(pAudioHandle.get(), &duration);
578         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform audio_meta_get_duration operation.");
579
580         pAudioContentData->bitrate      = bitrate;
581
582         if (pYear.get() != null)
583         {
584                 SysLog(NID_CNT, "pAudioContentData->pYear  = %s", pYear.get());
585
586                 String strYear(pYear.get());
587                 if (strYear.CompareTo(L"Unknown") != 0)
588                 {
589                         r = Integer::Parse(strYear, pAudioContentData->releaseYear);
590                         if (IsFailed(r))
591                         {
592                                 // It is one of the metadata. If error occurs, skip it for other metadata.
593                                 pAudioContentData->releaseYear = 0;
594                                 r = E_SUCCESS;
595                                 SysLog(NID_CNT, "pAudioContentData->pYear(invalid data) = %ls", strYear.GetPointer());
596                         }
597                 }
598         }
599
600         if (pTitle.get() != NULL)
601         {
602                 pAudioContentData->pTitle = new (std::nothrow) String(pTitle.get());
603                 SysTryReturnResult(NID_CNT, pAudioContentData->pTitle != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
604                 SysLog(NID_CNT, "pAudioContentData->pTitle  = %ls", pAudioContentData->pTitle->GetPointer());
605         }
606
607         if (pArtistName.get() != NULL)
608         {
609                 pAudioContentData->pArtist      = new (std::nothrow) String(pArtistName.get());
610                 SysTryReturnResult(NID_CNT, pAudioContentData->pArtist != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
611                 SysLog(NID_CNT, "pAudioContentData->pArtist = %ls", pAudioContentData->pArtist->GetPointer());
612         }
613
614         if (pGenreName.get() != NULL)
615         {
616                 pAudioContentData->pGenre       = new (std::nothrow) String(pGenreName.get());
617                 SysTryReturnResult(NID_CNT, pAudioContentData->pGenre != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
618                 SysLog(NID_CNT, "pAudioContentData->pGenre = %ls", pAudioContentData->pGenre->GetPointer());
619         }
620
621         if (pComposerName.get() != NULL)
622         {
623                 pAudioContentData->pComposer    = new (std::nothrow) String(pComposerName.get());
624                 SysTryReturnResult(NID_CNT, pAudioContentData->pComposer != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
625                 SysLog(NID_CNT, "pAudioContentData->pComposer = %ls", pAudioContentData->pComposer->GetPointer());
626         }
627
628         if (pAlbumName.get() != NULL)
629         {
630                 pAudioContentData->pAlbumName   = new (std::nothrow) String(pAlbumName.get());
631                 SysTryReturnResult(NID_CNT, pAudioContentData->pAlbumName != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
632                 SysLog(NID_CNT, "pAudioContentData->pAlbumName  = %ls", pAudioContentData->pAlbumName->GetPointer());
633         }
634
635         if (pCopyRight.get() != NULL)
636         {
637                 pAudioContentData->pCopyright   = new (std::nothrow) String(pCopyRight.get());
638                 SysTryReturnResult(NID_CNT, pAudioContentData->pCopyright != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
639                 SysLog(NID_CNT, "pAudioContentData->pCopyright  = %ls", pAudioContentData->pCopyright->GetPointer());
640         }
641
642         if (pTrackNum.get() != NULL)
643         {
644                 pAudioContentData->pTrackInfo   = new (std::nothrow) String(pTrackNum.get());
645                 SysTryReturnResult(NID_CNT, pAudioContentData->pTrackInfo != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
646                 SysLog(NID_CNT, "pAudioContentData->pTrackInfo  = %ls", pAudioContentData->pTrackInfo->GetPointer());
647         }
648
649         pAudioContentData->duration = duration;
650         SysLog(NID_CNT,"pAudioContentData->duration = %d", pAudioContentData->duration);
651
652         return r;
653 }
654
655 // fills video contentinfo information in the video content data object.
656 result
657 _ContentUtility::FillVideoContentData(media_info_h mediaHandle, VideoContentInfo::_VideoContentData* pVideoContentData)
658 {
659         SysTryReturnResult(NID_CNT, mediaHandle != null && pVideoContentData != null, E_INVALID_ARG, "mediaHandle or pVideoContentData is null.");
660
661         int ret  = MEDIA_CONTENT_ERROR_NONE;
662         result r = E_SUCCESS;
663         int width  = 0;
664         int height = 0;
665         std::unique_ptr<char, UtilCharDeleter> pArtistName;
666         std::unique_ptr<char, UtilCharDeleter> pGenreName;
667         std::unique_ptr<char, UtilCharDeleter> pTitle;
668         std::unique_ptr<char, UtilCharDeleter> pAlbumName;
669         int duration = 0;
670
671         video_meta_h tempMeta = NULL;
672
673         ret = media_info_get_video(mediaHandle, &tempMeta);
674         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform media_info_get_video operation.");
675
676         std::unique_ptr<video_meta_s, VideoMetaHandleDeleter> pVideoHandle(tempMeta);
677         SysTryReturnResult(NID_CNT, pVideoHandle != null, E_OUT_OF_MEMORY, "pVideoHandle is null.");
678
679         ret = video_meta_get_width(pVideoHandle.get(), &width);
680         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_width operation.");
681
682         ret = video_meta_get_height(pVideoHandle.get(), &height);
683         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_height operation.");
684
685         char* pVideoMetaValue = null;
686         ret = video_meta_get_artist(pVideoHandle.get(), &pVideoMetaValue);
687         if (pVideoMetaValue != null)
688         {
689                 pArtistName.reset(pVideoMetaValue);
690         }
691         else
692         {
693                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_artist operation.");
694         }
695
696         ret = video_meta_get_genre(pVideoHandle.get(), &pVideoMetaValue);
697         if (pVideoMetaValue != null)
698         {
699                 pGenreName.reset(pVideoMetaValue);
700         }
701         else
702         {
703                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_genre operation.");
704         }
705
706         ret = video_meta_get_title(pVideoHandle.get(), &pVideoMetaValue);
707         if (pVideoMetaValue != null)
708         {
709                 pTitle.reset(pVideoMetaValue);
710         }
711         else
712         {
713                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_title operation.");
714         }
715
716         ret = video_meta_get_album(pVideoHandle.get(), &pVideoMetaValue);
717         if (pVideoMetaValue != null)
718         {
719                 pAlbumName.reset(pVideoMetaValue);
720         }
721         else
722         {
723                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_album operation.");
724         }
725
726         ret = video_meta_get_duration(pVideoHandle.get(), &duration);
727         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, MapCoreErrorToNativeResult(ret), "Failed to perform video_meta_get_duration operation.");
728
729         pVideoContentData->width = width;
730         pVideoContentData->height = height;
731
732         if (pTitle.get() != NULL)
733         {
734                 pVideoContentData->pTitle  = new (std::nothrow) String(pTitle.get());
735                 SysTryReturnResult(NID_CNT, pVideoContentData->pTitle != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
736                 SysLog(NID_CNT, "pVideoContentData->pTitle = %ls", pVideoContentData->pTitle->GetPointer());
737         }
738
739         if (pArtistName.get() != NULL)
740         {
741                 pVideoContentData->pArtist = new (std::nothrow) String(pArtistName.get());
742                 SysTryReturnResult(NID_CNT, pVideoContentData->pArtist != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
743                 SysLog(NID_CNT, "pVideoContentData->pArtist = %ls", pVideoContentData->pArtist->GetPointer());
744         }
745
746         if (pGenreName.get() != NULL)
747         {
748                 pVideoContentData->pGenre  = new (std::nothrow) String(pGenreName.get());
749                 SysTryReturnResult(NID_CNT, pVideoContentData->pGenre != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
750                 SysLog(NID_CNT, "pVideoContentData->pGenre = %ls", pVideoContentData->pGenre->GetPointer());
751         }
752
753         if (pAlbumName.get() != NULL)
754         {
755                 pVideoContentData->pAlbumName  = new (std::nothrow) String(pAlbumName.get());
756                 SysTryReturnResult(NID_CNT, pVideoContentData->pAlbumName != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
757                 SysLog(NID_CNT, "pVideoContentData->pAlbumName = %ls", pVideoContentData->pAlbumName->GetPointer());
758         }
759
760         pVideoContentData->duration = duration;
761         SysLog(NID_CNT,"pVideoContentData->duration = %d", pVideoContentData->duration);
762
763         return r;
764 }
765
766 // Convertion of system errors to osp errors
767 result
768 _ContentUtility::MapCoreErrorToNativeResult(int reason)
769 {
770         result r = E_SUCCESS;
771         switch (reason)
772         {
773         case MEDIA_CONTENT_ERROR_NONE:
774                 r = E_SUCCESS;
775                 break;
776         case MEDIA_CONTENT_ERROR_DB_BUSY:
777                 r = E_SERVICE_BUSY;
778                 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_DB_BUSY");
779                 break;
780         case MEDIA_CONTENT_ERROR_INVALID_PARAMETER:
781                 r = E_INVALID_ARG;
782                 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_INVALID_PARAMETER");
783                 break;
784         case MEDIA_CONTENT_ERROR_DB_FAILED:
785                 r = E_DATABASE;
786                 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_DB_FAILED");
787                 break;
788         case MEDIA_CONTENT_ERROR_OUT_OF_MEMORY:
789                 r = E_OUT_OF_MEMORY;
790                 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_OUT_OF_MEMORY");
791                 break;
792         default:
793                 SysLog(NID_CNT, "default");
794                 r = E_SYSTEM;
795                 break;
796         }
797         return r;
798 }
799
800 }}