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