Merge "[ACR-644] Add 360 content feature" into tizen
[platform/core/api/media-content.git] / src / media_info.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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 #include <media_info.h>
18 #include <media-thumbnail.h>
19 #include <media_info_private.h>
20 #include <media_util_private.h>
21
22 static void __media_info_insert_completed_cb(media_request_result_s *result, void *user_data);
23 static void __media_info_thumbnail_completed_cb(int error, const char *path, void *user_data);
24 static bool __media_info_delete_batch_cb(media_info_h media, void *user_data);
25 static int __media_info_insert_batch(media_batch_insert_e insert_type, const char **path_array, unsigned int array_length, media_insert_completed_cb completed_cb, void *user_data);
26
27 static int __media_info_get_media_path_by_id_from_db(const char *media_id, char **path)
28 {
29         int ret = MEDIA_CONTENT_ERROR_NONE;
30         sqlite3_stmt *stmt = NULL;
31         char *select_query = NULL;
32
33         media_content_retvm_if(!STRING_VALID(media_id), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media_id");
34
35         select_query = sqlite3_mprintf(SELECT_MEDIA_PATH_BY_ID, media_id);
36
37         ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
38         SQLITE3_SAFE_FREE(select_query);
39         media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
40
41         if (sqlite3_step(stmt) == SQLITE_ROW) {
42                 *path = g_strdup((const char *)sqlite3_column_text(stmt, 0));
43         } else {
44                 media_content_error("There's no media with this ID : %s", media_id);
45                 *path = NULL;
46                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
47         }
48
49         SQLITE3_FINALIZE(stmt);
50
51         return ret;
52 }
53
54 static void __media_info_insert_completed_cb(media_request_result_s *result, void *user_data)
55 {
56         int ret = MEDIA_CONTENT_ERROR_NONE;
57         media_insert_cb_s *_cb_data = (media_insert_cb_s *)user_data;
58
59         if (_cb_data) {
60                 if (result)
61                         ret = _content_error_capi(MEDIA_CONTENT_TYPE, result->result);
62
63                 if (_cb_data->insert_completed_cb)
64                         _cb_data->insert_completed_cb(ret, _cb_data->user_data);
65
66                 if (STRING_VALID(_cb_data->insert_list_path)) {
67                         if (unlink(_cb_data->insert_list_path) < 0)
68                                 media_content_stderror("failed to delete");
69                         SAFE_FREE(_cb_data->insert_list_path);
70                 }
71         }
72
73         SAFE_FREE(_cb_data);
74
75         return;
76 }
77
78 static void __media_info_thumbnail_completed_cb(int error, const char *path, void *user_data)
79 {
80         int error_value = MEDIA_CONTENT_ERROR_NONE;
81
82         media_thumbnail_cb_s *_thumb_cb = (media_thumbnail_cb_s *)user_data;
83         media_info_s *media = NULL;
84
85         if (_thumb_cb != NULL) {
86                 media = _thumb_cb->handle;
87                 if ((media != NULL) && STRING_VALID(path)) {
88                         SAFE_FREE(media->thumbnail_path);
89                         media->thumbnail_path = g_strdup(path);
90                 }
91
92                 media_content_debug("error [%d], thumbnail_path [%s]", error, path);
93                 error_value = _content_error_capi(MEDIA_THUMBNAIL_TYPE, error);
94                 if (_thumb_cb->thumbnail_completed_cb)
95                         _thumb_cb->thumbnail_completed_cb(error_value, path, _thumb_cb->user_data);
96         }
97
98         SAFE_FREE(_thumb_cb);
99
100         return;
101 }
102
103 static bool __media_info_delete_batch_cb(media_info_h media, void *user_data)
104 {
105         int err = MEDIA_CONTENT_ERROR_NONE;
106         char *thumb_path = NULL;
107         media_content_type_e media_type = 0;
108         GArray *thumb_list = (GArray *)user_data;
109
110         if (media == NULL) {
111                 media_content_debug("NO Item");
112                 return true;
113         }
114
115         err = media_info_get_media_type(media, &media_type);
116         if (err == MEDIA_CONTENT_ERROR_NONE) {
117                 media_content_debug("media_type : [%d]", media_type);
118
119                 media_info_get_thumbnail_path(media, &thumb_path);
120                 if (STRING_VALID(thumb_path) && STRING_VALID(MEDIA_CONTENT_THUMB_DEFAULT_PATH)) {
121                         if (strncmp(MEDIA_CONTENT_THUMB_DEFAULT_PATH, thumb_path, strlen(MEDIA_CONTENT_THUMB_DEFAULT_PATH)) != 0)
122                                 g_array_append_val(thumb_list, thumb_path);
123                 }
124         } else {
125                 media_content_error("media_info_get_media_type failed");
126         }
127
128         return true;
129 }
130
131 static int __media_info_insert_batch(media_batch_insert_e insert_type, const char **path_array,
132                                         unsigned int array_length,
133                                         media_insert_completed_cb completed_cb,
134                                         void *user_data)
135 {
136         int ret = MEDIA_CONTENT_ERROR_NONE;
137         FILE *fp = NULL;
138         char list_path[255] = {0, };
139         unsigned int idx = 0;
140         int nwrites = 0;
141
142         for (idx = 0; idx < BATCH_REQUEST_MAX; idx++) {
143                 snprintf(list_path, sizeof(list_path), "%s/request-%ld-%d", MEDIA_CONTENT_INSERT_FILES_PATH, media_content_gettid(), idx);
144
145                 if (g_file_test(list_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
146                         memset(list_path, 0x00, sizeof(list_path));
147                         continue;
148                 } else {
149                         media_content_debug("The request file list path : %s", list_path);
150                         break;
151                 }
152         }
153
154         if (idx == BATCH_REQUEST_MAX) {
155                 media_content_error("Too many batch request for one thread");
156                 return MEDIA_CONTENT_ERROR_DB_BUSY;
157         }
158
159         fp = fopen(list_path, "w");
160         if (fp == NULL) {
161                 media_content_error("failed to open file : [%s]", list_path);
162                 media_content_stderror("failed to open file");
163                 return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
164         }
165
166         for (idx = 0; idx < array_length; idx++) {
167                 if (STRING_VALID(path_array[idx])) {
168                         int size = strlen(path_array[idx]);
169
170                         ret = _media_util_check_file_exist(path_array[idx]);
171                         if (ret != MEDIA_CONTENT_ERROR_NONE) {
172                                 fclose(fp);
173                                 if (unlink(list_path) < 0)
174                                         media_content_stderror("failed to delete");
175                                 return ret;
176                         }
177
178                         nwrites = fwrite(path_array[idx], 1, size, fp);
179                         if (nwrites != size) {
180                                 media_content_stderror("failed to write");
181                                 fclose(fp);
182                                 if (unlink(list_path) < 0)
183                                         media_content_stderror("failed to delete");
184                                 return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
185                         }
186
187                         nwrites = fwrite("\n", 1, 1, fp);
188                         if (nwrites != 1) {
189                                 media_content_stderror("failed to write");
190                                 fclose(fp);
191                                 if (unlink(list_path) < 0)
192                                         media_content_stderror("failed to delete");
193                                 return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
194                         }
195                 } else {
196                         media_content_error("path[%d] is invalid string", idx);
197                 }
198         }
199
200         fclose(fp);
201
202         media_insert_cb_s *_cb_data = (media_insert_cb_s *)calloc(1, sizeof(media_insert_cb_s));
203         media_content_retvm_if(_cb_data == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
204
205         _cb_data->insert_completed_cb = completed_cb;
206         _cb_data->user_data = user_data;
207         _cb_data->insert_list_path = g_strdup(list_path);
208
209         if (insert_type == MEDIA_BATCH_INSERT_NORMAL)
210                 ret = media_files_register(list_path, __media_info_insert_completed_cb, _cb_data, tzplatform_getuid(TZ_USER_NAME));
211         else if (insert_type == MEDIA_BATCH_INSERT_BURSTSHOT)
212                 ret = media_burstshot_register(list_path, __media_info_insert_completed_cb, _cb_data, tzplatform_getuid(TZ_USER_NAME));
213         else
214                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
215
216         if (ret != MEDIA_CONTENT_ERROR_NONE) {
217                 media_content_error("media_files_register failed : %d", ret);
218                 if (unlink(list_path) < 0)
219                         media_content_stderror("failed to delete");
220                 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
221         }
222
223         return ret;
224 }
225
226 void _media_info_item_get_detail(sqlite3_stmt* stmt, media_info_h media)
227 {
228         media_info_s *_media = (media_info_s*)media;
229
230         _media->media_id = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_UUID));
231         _media->file_path = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_PATH));
232         _media->display_name = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_FILE_NAME));
233         _media->media_type = (int)sqlite3_column_int(stmt, MEDIA_INFO_TYPE);
234         _media->mime_type = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_MIME_TYPE));
235         _media->size = (unsigned long long)sqlite3_column_int64(stmt, MEDIA_INFO_SIZE);
236         _media->added_time = (int)sqlite3_column_int(stmt, MEDIA_INFO_ADDED_TIME);
237         _media->modified_time = (int)sqlite3_column_int(stmt, MEDIA_INFO_MODIFIED_TIME);
238         _media->thumbnail_path = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_THUMBNAIL_PATH));
239         _media->description = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_DESCRIPTION));
240         _media->rating = (int)sqlite3_column_int(stmt, MEDIA_INFO_RATING);
241         _media->favourite = (int)sqlite3_column_int(stmt, MEDIA_INFO_FAVOURITE);
242         _media->author = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_AUTHOR));
243         _media->provider = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_PROVIDER));
244         _media->content_name = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_CONTENT_NAME));
245         _media->category = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_CATEGORY));
246         _media->location_tag = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_LOCATION_TAG));
247         _media->age_rating = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_AGE_RATING));
248         _media->keyword = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_KEYWORD));
249         _media->is_drm = (int)sqlite3_column_int(stmt, MEDIA_INFO_IS_DRM);
250         _media->storage_type = (int)sqlite3_column_int(stmt, MEDIA_INFO_STORAGE_TYPE);
251         _media->longitude = (double)sqlite3_column_double(stmt, MEDIA_INFO_LONGITUDE);
252         _media->latitude = (double)sqlite3_column_double(stmt, MEDIA_INFO_LATITUDE);
253         _media->altitude = (double)sqlite3_column_double(stmt, MEDIA_INFO_ALTITUDE);
254         _media->played_count = sqlite3_column_int(stmt, MEDIA_INFO_PLAYED_COUNT);
255         _media->played_time = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_TIME);
256         _media->played_position = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_POSITION);
257         _media->title = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE));
258         _media->timeline = (double)sqlite3_column_double(stmt, MEDIA_INFO_TIMELINE);
259         _media->weather = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_WEATHER));
260         _media->sync_status = (int)sqlite3_column_int(stmt, MEDIA_INFO_SYNC_STATUS);
261         _media->storage_uuid = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_STORAGE_UUID));
262         _media->is_360 = (int)sqlite3_column_int(stmt, MEDIA_INFO_IS_360);
263
264         if (_media->media_type == MEDIA_CONTENT_TYPE_IMAGE) {
265                 _media->image_meta = (image_meta_s *)calloc(1, sizeof(image_meta_s));
266                 if (_media->image_meta) {
267                         _media->image_meta->media_id = g_strdup(_media->media_id);
268                         _media->image_meta->width = sqlite3_column_int(stmt, MEDIA_INFO_WIDTH);
269                         _media->image_meta->height = sqlite3_column_int(stmt, MEDIA_INFO_HEIGHT);
270                         _media->image_meta->fnumber = (double)sqlite3_column_double(stmt, MEDIA_INFO_FNUMBER);
271                         _media->image_meta->iso = sqlite3_column_int(stmt, MEDIA_INFO_ISO);
272                         _media->image_meta->date_taken = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_DATETAKEN));
273                         _media->image_meta->orientation = sqlite3_column_int(stmt, MEDIA_INFO_ORIENTATION);
274                         _media->image_meta->title = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE));
275                         _media->image_meta->burst_id = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_BURST_ID));
276                         _media->image_meta->weather = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_WEATHER));
277                         _media->image_meta->exposure_time = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_EXPOSURE_TIME));
278                         _media->image_meta->model = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_MODEL));
279                 }
280         } else if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
281                 _media->video_meta = (video_meta_s *)calloc(1, sizeof(video_meta_s));
282                 if (_media->video_meta) {
283                         _media->video_meta->media_id = g_strdup(_media->media_id);
284                         _media->video_meta->width = sqlite3_column_int(stmt, MEDIA_INFO_WIDTH);
285                         _media->video_meta->height = sqlite3_column_int(stmt, MEDIA_INFO_HEIGHT);
286                         _media->video_meta->title = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE));
287                         _media->video_meta->album = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM));
288                         _media->video_meta->artist = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ARTIST));
289                         _media->video_meta->album_artist = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM_ARTIST));
290                         _media->video_meta->genre = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_GENRE));
291                         _media->video_meta->composer = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COMPOSER));
292                         _media->video_meta->year = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_YEAR));
293                         _media->video_meta->recorded_date = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_RECORDED_DATE));
294                         _media->video_meta->copyright = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COPYRIGHT));
295                         _media->video_meta->track_num = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TRACK_NUM));
296                         _media->video_meta->bitrate = sqlite3_column_int(stmt, MEDIA_INFO_BITRATE);
297                         _media->video_meta->duration = sqlite3_column_int(stmt, MEDIA_INFO_DURATION);
298                         _media->video_meta->played_count = sqlite3_column_int(stmt, MEDIA_INFO_PLAYED_COUNT);
299                         _media->video_meta->played_time = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_TIME);
300                         _media->video_meta->played_position = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_POSITION);
301                 }
302
303         } else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) {
304                 _media->audio_meta = (audio_meta_s *)calloc(1, sizeof(audio_meta_s));
305                 if (_media->audio_meta) {
306                         _media->audio_meta->media_id = g_strdup(_media->media_id);
307                         _media->audio_meta->title = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE));
308                         _media->audio_meta->album = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM));
309                         _media->audio_meta->artist = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ARTIST));
310                         _media->audio_meta->album_artist = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM_ARTIST));
311                         _media->audio_meta->genre = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_GENRE));
312                         _media->audio_meta->composer = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COMPOSER));
313                         _media->audio_meta->year = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_YEAR));
314                         _media->audio_meta->recorded_date = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_RECORDED_DATE));
315                         _media->audio_meta->copyright = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COPYRIGHT));
316                         _media->audio_meta->track_num = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TRACK_NUM));
317                         _media->audio_meta->bitrate = sqlite3_column_int(stmt, MEDIA_INFO_BITRATE);
318                         _media->audio_meta->bitpersample = sqlite3_column_int(stmt, MEDIA_INFO_BITPERSAMPLE);
319                         _media->audio_meta->duration = sqlite3_column_int(stmt, MEDIA_INFO_DURATION);
320                         _media->audio_meta->played_count = sqlite3_column_int(stmt, MEDIA_INFO_PLAYED_COUNT);
321                         _media->audio_meta->played_time = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_TIME);
322                         _media->audio_meta->played_position = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_POSITION);
323                         _media->audio_meta->samplerate = sqlite3_column_int(stmt, MEDIA_INFO_SAMPLERATE);
324                         _media->audio_meta->channel = sqlite3_column_int(stmt, MEDIA_INFO_CHANNEL);
325                 }
326         }
327 }
328
329 int _media_info_get_media_info_from_db(const char *path, const char *storage_id, media_info_h media)
330 {
331         int ret = MEDIA_CONTENT_ERROR_NONE;
332         sqlite3_stmt *stmt = NULL;
333         char *select_query = NULL;
334         media_info_s *_media = (media_info_s*)media;
335
336         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media");
337
338         select_query = sqlite3_mprintf(SELECT_MEDIA_BY_PATH, storage_id, path);
339
340         ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
341         SQLITE3_SAFE_FREE(select_query);
342         media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
343
344         if (sqlite3_step(stmt) == SQLITE_ROW) {
345                 _media_info_item_get_detail(stmt, (media_info_h)_media);
346         } else {
347                 media_content_error("There's no media!!");
348                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
349         }
350
351         SQLITE3_FINALIZE(stmt);
352
353         return ret;
354 }
355
356 int media_info_insert_to_db(const char *path, media_info_h *info)
357 {
358         bool ignore_file = FALSE;
359         bool ignore_dir = FALSE;
360         char *folder_path = NULL;
361         char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
362         int ret = MEDIA_CONTENT_ERROR_NONE;
363
364         media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid path");
365         media_content_retvm_if(info == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid info");
366
367         ret = _media_util_check_ignore_file(path, &ignore_file);
368         media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
369
370         ret = _media_util_check_file_exist(path);
371         media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
372
373         folder_path = g_path_get_dirname(path);
374         ret = _media_util_check_ignore_dir(folder_path, &ignore_dir);
375         SAFE_FREE(folder_path);
376
377         media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
378
379         memset(storage_id, 0x00, sizeof(storage_id));
380         ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id);
381         if (ret != MS_MEDIA_ERR_NONE) {
382                 media_content_error("media_svc_get_storage_id failed : %d", ret);
383                 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
384         }
385
386         ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), storage_id, path);
387         if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
388                 media_content_sec_debug("media_svc_check_item_exist_by_path : no record : %s", path);
389
390                 media_svc_storage_type_e storage_type = 0;
391
392                 ret = media_svc_get_storage_type(path, &storage_type, tzplatform_getuid(TZ_USER_NAME));
393                 if (ret != MS_MEDIA_ERR_NONE) {
394                         media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
395                         return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
396                 }
397
398                 ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_id, storage_type, path, tzplatform_getuid(TZ_USER_NAME));
399
400                 if (ret != MS_MEDIA_ERR_NONE) {
401                         if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
402                                 media_content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", path);
403                                 ret = MEDIA_CONTENT_ERROR_NONE;
404                         } else {
405                                 media_content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, path);
406                         }
407
408                         return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
409                 }
410         } else if (ret != MS_MEDIA_ERR_NONE) {
411                 media_content_sec_error("media_svc_check_item_exist_by_path failed : %d (%s)", ret, path);
412                 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
413         }
414
415         media_info_s *_media = (media_info_s*)calloc(1, sizeof(media_info_s));
416         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
417
418         ret = _media_info_get_media_info_from_db(path, DEFAULT_MEDIA_STORAGE_ID, (media_info_h)_media);
419
420         *info = (media_info_h)_media;
421         return ret;
422 }
423
424 int media_info_insert_batch_to_db(
425                                         const char **path_array,
426                                         unsigned int array_length,
427                                         media_insert_completed_cb completed_cb,
428                                         void *user_data)
429 {
430         media_content_retvm_if(path_array == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path_array");
431         media_content_retvm_if(array_length <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid array_length");
432
433         return __media_info_insert_batch(MEDIA_BATCH_INSERT_NORMAL, path_array, array_length, completed_cb, user_data);
434 }
435
436 int media_info_insert_burst_shot_to_db(const char **path_array, unsigned int array_length, media_insert_burst_shot_completed_cb callback, void *user_data)
437 {
438         media_content_retvm_if(path_array == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path_array");
439         media_content_retvm_if(array_length <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid array_length");
440
441         return __media_info_insert_batch(MEDIA_BATCH_INSERT_BURSTSHOT, path_array, array_length, callback, user_data);
442 }
443
444 int media_info_delete_from_db(const char *media_id)
445 {
446         int ret = MEDIA_CONTENT_ERROR_NONE;
447         char *path = NULL;
448         char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
449
450         if (!STRING_VALID(media_id)) {
451                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
452                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
453         }
454
455         memset(storage_id, 0x00, sizeof(storage_id));
456
457         ret = __media_info_get_media_path_by_id_from_db(media_id, &path);
458         if (ret != MEDIA_CONTENT_ERROR_NONE) {
459                 media_content_error("__media_info_get_media_path_by_id_from_db failed : %d", ret);
460                 SAFE_FREE(path);
461                 return ret;
462         }
463
464         ret = _media_db_get_storage_id_by_media_id(media_id, storage_id);
465         if (ret != MEDIA_CONTENT_ERROR_NONE) {
466                 media_content_error("_media_db_get_storage_id_by_media_id failed : %d", ret);
467                 SAFE_FREE(path);
468                 return ret;
469         }
470
471         ret = media_svc_delete_item_by_path(_content_get_db_handle(), storage_id, path, tzplatform_getuid(TZ_USER_NAME));
472         SAFE_FREE(path);
473
474         return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
475 }
476
477 static int __media_info_delete_thumb_from_list(GArray *thumb_list)
478 {
479         int i = 0;
480         int list_len = 0;
481         char *thumb_path = NULL;
482
483         if (thumb_list != NULL) {
484                 list_len = thumb_list->len;
485                 for (i = 0; i < list_len; i++) {
486                         thumb_path = g_array_index(thumb_list, char*, i);
487                         media_content_debug("thumb path [%s]", thumb_path);
488                         if (unlink(thumb_path) < 0)
489                                 media_content_stderror("failed to delete");
490                 }
491         }
492         return MEDIA_CONTENT_ERROR_NONE;
493 }
494
495 static int __media_info_release_thumb_list(GArray *thumb_list)
496 {
497         int i = 0;
498         int list_len = 0;
499         char *thumb_path = NULL;
500
501         if (thumb_list != NULL) {
502                 list_len = thumb_list->len;
503                 for (i = 0; i < list_len; i++) {
504                         thumb_path = g_array_index(thumb_list, char*, 0);
505                         g_array_remove_index(thumb_list, 0);
506                         SAFE_FREE(thumb_path);
507                 }
508
509                 g_array_free(thumb_list, FALSE);
510         }
511
512         return MEDIA_CONTENT_ERROR_NONE;
513 }
514
515 int media_info_delete_batch_from_db(filter_h filter)
516 {
517         int ret = MEDIA_CONTENT_ERROR_NONE;
518
519         char *query_string = NULL;
520         filter_s *_filter = NULL;
521         attribute_h attr;
522         char *condition_query = NULL;
523         GArray *thumb_list = NULL;
524
525         media_content_retvm_if(filter == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid filter");
526
527         thumb_list = g_array_new(FALSE, FALSE, sizeof(char*));
528
529         /* Delete thumbnail of each item */
530         ret = _media_db_get_group_item(NULL, filter, __media_info_delete_batch_cb, thumb_list, MEDIA_GROUP_NONE);
531
532         _filter = (filter_s*)filter;
533         attr = _content_get_attirbute_handle();
534
535         if (_filter->condition) {
536                 ret = _media_filter_attribute_generate(attr, _filter->condition, _filter->condition_collate_type, &condition_query);
537                 if (ret != MEDIA_CONTENT_ERROR_NONE) {
538                         __media_info_release_thumb_list(thumb_list);
539                         return ret;
540                 }
541         }
542
543         if (STRING_VALID(condition_query)) {
544                 if (_filter->storage_id == NULL) {
545                         /*FIX ME*/
546                         query_string = sqlite3_mprintf(DELETE_MEDIA_FROM_MEDIA_BATCH, "media", condition_query);
547                 } else {
548                         query_string = sqlite3_mprintf(DELETE_MEDIA_FROM_MEDIA_BATCH, _filter->storage_id, condition_query);
549                 }
550         } else {
551                 SAFE_FREE(condition_query);
552                 __media_info_release_thumb_list(thumb_list);
553
554                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
555         }
556
557         ret = _content_query_sql(query_string);
558         if (ret == MEDIA_CONTENT_ERROR_NONE) {
559                 /* Send notification for this
560                         In this case, send noti for internal storage and external storage
561                 */
562                 media_content_debug("Batch deletion is successfull. Send notification for this");
563                 if (_filter->storage_id != NULL) {
564                         char *storage_path = NULL;
565                         media_svc_get_storage_path(_content_get_db_handle(), _filter->storage_id, &storage_path);
566                         if (STRING_VALID(storage_path))
567                                 media_svc_publish_noti(MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, storage_path, -1, NULL, NULL);
568
569                         SAFE_FREE(storage_path);
570                 } else {
571                         /*FIX ME*/
572                         media_svc_publish_noti(MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, MEDIA_ROOT_PATH_INTERNAL, -1, NULL, NULL);
573                         media_svc_publish_noti(MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, MEDIA_ROOT_PATH_SDCARD, -1, NULL, NULL);
574                 }
575
576                 __media_info_delete_thumb_from_list(thumb_list);
577                 __media_info_release_thumb_list(thumb_list);
578         }
579
580         SAFE_FREE(condition_query);
581         SQLITE3_SAFE_FREE(query_string);
582
583         return ret;
584 }
585
586 int media_info_destroy(media_info_h media)
587 {
588         int ret = MEDIA_CONTENT_ERROR_NONE;
589         media_info_s *_media = (media_info_s*)media;
590
591         if (_media) {
592                 SAFE_FREE(_media->media_id);
593                 SAFE_FREE(_media->file_path);
594                 SAFE_FREE(_media->display_name);
595                 SAFE_FREE(_media->mime_type);
596                 SAFE_FREE(_media->thumbnail_path);
597                 SAFE_FREE(_media->description);
598                 SAFE_FREE(_media->author);
599                 SAFE_FREE(_media->provider);
600                 SAFE_FREE(_media->content_name);
601                 SAFE_FREE(_media->category);
602                 SAFE_FREE(_media->location_tag);
603                 SAFE_FREE(_media->age_rating);
604                 SAFE_FREE(_media->keyword);
605                 SAFE_FREE(_media->title);
606                 SAFE_FREE(_media->weather);
607                 SAFE_FREE(_media->storage_uuid);
608
609                 if (_media->image_meta) {
610                         SAFE_FREE(_media->image_meta->media_id);
611                         SAFE_FREE(_media->image_meta->date_taken);
612                         SAFE_FREE(_media->image_meta->burst_id);
613                         SAFE_FREE(_media->image_meta->exposure_time);
614                         SAFE_FREE(_media->image_meta->model);
615                         SAFE_FREE(_media->image_meta->title);
616                         SAFE_FREE(_media->image_meta->weather);
617
618                         SAFE_FREE(_media->image_meta);
619                 }
620
621                 if (_media->video_meta) {
622                         SAFE_FREE(_media->video_meta->media_id);
623                         SAFE_FREE(_media->video_meta->title);
624                         SAFE_FREE(_media->video_meta->album);
625                         SAFE_FREE(_media->video_meta->artist);
626                         SAFE_FREE(_media->video_meta->album_artist);
627                         SAFE_FREE(_media->video_meta->genre);
628                         SAFE_FREE(_media->video_meta->composer);
629                         SAFE_FREE(_media->video_meta->year);
630                         SAFE_FREE(_media->video_meta->recorded_date);
631                         SAFE_FREE(_media->video_meta->copyright);
632                         SAFE_FREE(_media->video_meta->track_num);
633
634                         SAFE_FREE(_media->video_meta);
635                 }
636
637                 if (_media->audio_meta) {
638                         SAFE_FREE(_media->audio_meta->media_id);
639                         SAFE_FREE(_media->audio_meta->title);
640                         SAFE_FREE(_media->audio_meta->album);
641                         SAFE_FREE(_media->audio_meta->artist);
642                         SAFE_FREE(_media->audio_meta->album_artist);
643                         SAFE_FREE(_media->audio_meta->genre);
644                         SAFE_FREE(_media->audio_meta->composer);
645                         SAFE_FREE(_media->audio_meta->year);
646                         SAFE_FREE(_media->audio_meta->recorded_date);
647                         SAFE_FREE(_media->audio_meta->copyright);
648                         SAFE_FREE(_media->audio_meta->track_num);
649
650                         SAFE_FREE(_media->audio_meta);
651                 }
652
653                 SAFE_FREE(_media);
654
655                 ret = MEDIA_CONTENT_ERROR_NONE;
656         } else {
657                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
658                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
659         }
660
661         return ret;
662 }
663
664 int media_info_clone(media_info_h *dst, media_info_h src)
665 {
666         int ret = MEDIA_CONTENT_ERROR_NONE;
667         media_info_s *_src = (media_info_s*)src;
668
669         if (_src != NULL) {
670                 media_info_s *_dst = (media_info_s*)calloc(1, sizeof(media_info_s));
671                 media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
672
673                 if (_src->media_id) {
674                         _dst->media_id = g_strdup(_src->media_id);
675                         if (_dst->media_id == NULL) {
676                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
677                                 media_info_destroy((media_info_h)_dst);
678                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
679                         }
680                 }
681                 if (_src->file_path) {
682                         _dst->file_path = g_strdup(_src->file_path);
683                         if (_dst->file_path == NULL) {
684                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
685                                 media_info_destroy((media_info_h)_dst);
686                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
687                         }
688                 }
689                 if (_src->display_name != NULL) {
690                         _dst->display_name = g_strdup(_src->display_name);
691                         if (_dst->display_name == NULL) {
692                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
693                                 media_info_destroy((media_info_h)_dst);
694                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
695                         }
696                 }
697                 if (_src->mime_type) {
698                         _dst->mime_type = g_strdup(_src->mime_type);
699                         if (_dst->mime_type == NULL) {
700                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
701                                 media_info_destroy((media_info_h)_dst);
702                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
703                         }
704                 }
705                 if (_src->thumbnail_path != NULL) {
706                         _dst->thumbnail_path = g_strdup(_src->thumbnail_path);
707                         if (_dst->thumbnail_path == NULL) {
708                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
709                                 media_info_destroy((media_info_h)_dst);
710                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
711                         }
712                 }
713                 if (_src->description != NULL) {
714                         _dst->description = g_strdup(_src->description);
715                         if (_dst->description == NULL) {
716                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
717                                 media_info_destroy((media_info_h)_dst);
718                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
719                         }
720                 }
721
722                 if (_src->weather != NULL) {
723                         _dst->weather = g_strdup(_src->weather);
724                         if (_dst->weather == NULL) {
725                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
726                                 media_info_destroy((media_info_h)_dst);
727                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
728                         }
729                 }
730
731                 if (_src->title != NULL) {
732                         _dst->title = g_strdup(_src->title);
733                         if (_dst->title == NULL) {
734                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
735                                 media_info_destroy((media_info_h)_dst);
736                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
737                         }
738                 }
739                 if (_src->author != NULL) {
740                         _dst->author = g_strdup(_src->author);
741                         if (_dst->author == NULL) {
742                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
743                                 media_info_destroy((media_info_h)_dst);
744                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
745                         }
746                 }
747                 if (_src->provider != NULL) {
748                         _dst->provider = g_strdup(_src->provider);
749                         if (_dst->provider == NULL) {
750                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
751                                 media_info_destroy((media_info_h)_dst);
752                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
753                         }
754                 }
755                 if (_src->content_name != NULL) {
756                         _dst->content_name = g_strdup(_src->content_name);
757                         if (_dst->content_name == NULL) {
758                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
759                                 media_info_destroy((media_info_h)_dst);
760                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
761                         }
762                 }
763                 if (_src->category != NULL) {
764                         _dst->category = g_strdup(_src->category);
765                         if (_dst->category == NULL) {
766                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
767                                 media_info_destroy((media_info_h)_dst);
768                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
769                         }
770                 }
771                 if (_src->location_tag != NULL) {
772                         _dst->location_tag = g_strdup(_src->location_tag);
773                         if (_dst->location_tag == NULL) {
774                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
775                                 media_info_destroy((media_info_h)_dst);
776                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
777                         }
778                 }
779                 if (_src->age_rating != NULL) {
780                         _dst->age_rating = g_strdup(_src->age_rating);
781                         if (_dst->age_rating == NULL) {
782                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
783                                 media_info_destroy((media_info_h)_dst);
784                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
785                         }
786                 }
787                 if (_src->keyword != NULL) {
788                         _dst->keyword = g_strdup(_src->keyword);
789                         if (_dst->keyword == NULL) {
790                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
791                                 media_info_destroy((media_info_h)_dst);
792                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
793                         }
794                 }
795
796                 if (_src->storage_uuid != NULL) {
797                         _dst->storage_uuid = g_strdup(_src->storage_uuid);
798                         if (_dst->storage_uuid == NULL) {
799                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
800                                 media_info_destroy((media_info_h)_dst);
801                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
802                         }
803                 }
804
805                 _dst->media_type = _src->media_type;
806                 _dst->size = _src->size;
807                 _dst->added_time = _src->added_time;
808                 _dst->modified_time = _src->modified_time;
809                 _dst->timeline = _src->timeline;
810                 _dst->longitude = _src->longitude;
811                 _dst->latitude = _src->latitude;
812                 _dst->altitude = _src->altitude;
813                 _dst->rating = _src->rating;
814                 _dst->favourite = _src->favourite;
815                 _dst->is_drm = _src->is_drm;
816                 _dst->storage_type = _src->storage_type;
817                 _dst->played_count = _src->played_count;
818                 _dst->played_time = _src->played_time;
819                 _dst->played_position = _src->played_position;
820                 _dst->sync_status = _src->sync_status;
821                 _dst->request_id = _src->request_id;
822                 _dst->is_360 = _src->is_360;
823
824                 if (_src->media_type == MEDIA_CONTENT_TYPE_IMAGE && _src->image_meta) {
825                         _dst->image_meta = (image_meta_s *)calloc(1, sizeof(image_meta_s));
826                         if (_dst->image_meta == NULL) {
827                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
828                                 media_info_destroy((media_info_h)_dst);
829                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
830                         }
831
832                         if (_src->image_meta->media_id != NULL) {
833                                 _dst->image_meta->media_id = g_strdup(_src->image_meta->media_id);
834                                 if (_dst->image_meta->media_id == NULL) {
835                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
836                                         media_info_destroy((media_info_h)_dst);
837                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
838                                 }
839                         }
840
841                         if (_src->image_meta->date_taken != NULL) {
842                                 _dst->image_meta->date_taken = g_strdup(_src->image_meta->date_taken);
843                                 if (_dst->image_meta->date_taken == NULL) {
844                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
845                                         media_info_destroy((media_info_h)_dst);
846                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
847                                 }
848                         }
849
850                         if (_src->image_meta->burst_id != NULL) {
851                                 _dst->image_meta->burst_id = g_strdup(_src->image_meta->burst_id);
852                                 if (_dst->image_meta->burst_id == NULL) {
853                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
854                                         media_info_destroy((media_info_h)_dst);
855                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
856                                 }
857                         }
858
859                         if (_src->image_meta->weather != NULL) {
860                                 _dst->image_meta->weather = g_strdup(_src->image_meta->weather);
861                                 if (_dst->image_meta->weather == NULL) {
862                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
863                                         media_info_destroy((media_info_h)_dst);
864                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
865                                 }
866                         }
867
868                         if (_src->image_meta->exposure_time != NULL) {
869                                 _dst->image_meta->exposure_time = g_strdup(_src->image_meta->exposure_time);
870                                 if (_dst->image_meta->exposure_time == NULL) {
871                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
872                                         media_info_destroy((media_info_h)_dst);
873                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
874                                 }
875                         }
876
877                         if (_src->image_meta->model != NULL) {
878                                 _dst->image_meta->model = g_strdup(_src->image_meta->model);
879                                 if (_dst->image_meta->model == NULL) {
880                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
881                                         media_info_destroy((media_info_h)_dst);
882                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
883                                 }
884                         }
885
886                         _dst->image_meta->fnumber = _src->image_meta->fnumber;
887                         _dst->image_meta->iso = _src->image_meta->iso;
888                         _dst->image_meta->width = _src->image_meta->width;
889                         _dst->image_meta->height = _src->image_meta->height;
890                         _dst->image_meta->orientation = _src->image_meta->orientation;
891
892                 } else if (_src->media_type == MEDIA_CONTENT_TYPE_VIDEO && _src->video_meta) {
893                         _dst->video_meta = (video_meta_s *)calloc(1, sizeof(video_meta_s));
894                         if (_dst->video_meta == NULL) {
895                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
896                                 media_info_destroy((media_info_h)_dst);
897                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
898                         }
899
900                         if (_src->video_meta->media_id != NULL) {
901                                 _dst->video_meta->media_id = g_strdup(_src->video_meta->media_id);
902                                 if (_dst->video_meta->media_id == NULL) {
903                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
904                                         media_info_destroy((media_info_h)_dst);
905                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
906                                 }
907                         }
908                         if (_src->video_meta->title != NULL) {
909                                 _dst->video_meta->title = g_strdup(_src->video_meta->title);
910                                 if (_dst->video_meta->title == NULL) {
911                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
912                                         media_info_destroy((media_info_h)_dst);
913                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
914                                 }
915                         }
916                         if (_src->video_meta->album != NULL) {
917                                 _dst->video_meta->album = g_strdup(_src->video_meta->album);
918                                 if (_dst->video_meta->album == NULL) {
919                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
920                                         media_info_destroy((media_info_h)_dst);
921                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
922                                 }
923                         }
924                         if (_src->video_meta->artist != NULL) {
925                                 _dst->video_meta->artist = g_strdup(_src->video_meta->artist);
926                                 if (_dst->video_meta->artist == NULL) {
927                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
928                                         media_info_destroy((media_info_h)_dst);
929                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
930                                 }
931                         }
932                         if (_src->video_meta->album_artist != NULL) {
933                                 _dst->video_meta->album_artist = g_strdup(_src->video_meta->album_artist);
934                                 if (_dst->video_meta->album_artist == NULL) {
935                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
936                                         media_info_destroy((media_info_h)_dst);
937                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
938                                 }
939                         }
940                         if (_src->video_meta->genre != NULL) {
941                                 _dst->video_meta->genre = g_strdup(_src->video_meta->genre);
942                                 if (_dst->video_meta->genre == NULL) {
943                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
944                                         media_info_destroy((media_info_h)_dst);
945                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
946                                 }
947                         }
948                         if (_src->video_meta->composer != NULL) {
949                                 _dst->video_meta->composer = g_strdup(_src->video_meta->composer);
950                                 if (_dst->video_meta->composer == NULL) {
951                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
952                                         media_info_destroy((media_info_h)_dst);
953                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
954                                 }
955                         }
956                         if (_src->video_meta->year != NULL) {
957                                 _dst->video_meta->year = g_strdup(_src->video_meta->year);
958                                 if (_dst->video_meta->year == NULL) {
959                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
960                                         media_info_destroy((media_info_h)_dst);
961                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
962                                 }
963                         }
964                         if (_src->video_meta->recorded_date != NULL) {
965                                 _dst->video_meta->recorded_date = g_strdup(_src->video_meta->recorded_date);
966                                 if (_dst->video_meta->recorded_date == NULL) {
967                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
968                                         media_info_destroy((media_info_h)_dst);
969                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
970                                 }
971                         }
972                         if (_src->video_meta->copyright != NULL) {
973                                 _dst->video_meta->copyright = g_strdup(_src->video_meta->copyright);
974                                 if (_dst->video_meta->copyright == NULL) {
975                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
976                                         media_info_destroy((media_info_h)_dst);
977                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
978                                 }
979                         }
980                         if (_src->video_meta->track_num != NULL) {
981                                 _dst->video_meta->track_num = g_strdup(_src->video_meta->track_num);
982                                 if (_dst->video_meta->track_num == NULL) {
983                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
984                                         media_info_destroy((media_info_h)_dst);
985                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
986                                 }
987                         }
988
989                         _dst->video_meta->width = _src->video_meta->width;
990                         _dst->video_meta->height = _src->video_meta->height;
991                         _dst->video_meta->duration = _src->video_meta->duration;
992                         _dst->video_meta->bitrate = _src->video_meta->bitrate;
993                         _dst->video_meta->played_count = _src->video_meta->played_count;
994                         _dst->video_meta->played_time = _src->video_meta->played_time;
995                         _dst->video_meta->played_position = _src->video_meta->played_position;
996
997                 } else if ((_src->media_type == MEDIA_CONTENT_TYPE_MUSIC || _src->media_type == MEDIA_CONTENT_TYPE_SOUND) && _src->audio_meta) {
998                         _dst->audio_meta = (audio_meta_s *)calloc(1, sizeof(audio_meta_s));
999                         if (_dst->audio_meta == NULL) {
1000                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1001                                 media_info_destroy((media_info_h)_dst);
1002                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1003                         }
1004
1005                         if (_src->audio_meta->media_id != NULL) {
1006                                 _dst->audio_meta->media_id = g_strdup(_src->audio_meta->media_id);
1007                                 if (_dst->audio_meta->media_id == NULL) {
1008                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1009                                         media_info_destroy((media_info_h)_dst);
1010                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1011                                 }
1012                         }
1013                         if (_src->audio_meta->title != NULL) {
1014                                 _dst->audio_meta->title = g_strdup(_src->audio_meta->title);
1015                                 if (_dst->audio_meta->title == NULL) {
1016                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1017                                         media_info_destroy((media_info_h)_dst);
1018                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1019                                 }
1020                         }
1021                         if (_src->audio_meta->album != NULL) {
1022                                 _dst->audio_meta->album = g_strdup(_src->audio_meta->album);
1023                                 if (_dst->audio_meta->album == NULL) {
1024                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1025                                         media_info_destroy((media_info_h)_dst);
1026                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1027                                 }
1028                         }
1029                         if (_src->audio_meta->artist != NULL) {
1030                                 _dst->audio_meta->artist = g_strdup(_src->audio_meta->artist);
1031                                 if (_dst->audio_meta->artist == NULL) {
1032                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1033                                         media_info_destroy((media_info_h)_dst);
1034                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1035                                 }
1036                         }
1037                         if (_src->audio_meta->album_artist != NULL) {
1038                                 _dst->audio_meta->album_artist = g_strdup(_src->audio_meta->album_artist);
1039                                 if (_dst->audio_meta->album_artist == NULL) {
1040                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1041                                         media_info_destroy((media_info_h)_dst);
1042                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1043                                 }
1044                         }
1045                         if (_src->audio_meta->genre != NULL) {
1046                                 _dst->audio_meta->genre = g_strdup(_src->audio_meta->genre);
1047                                 if (_dst->audio_meta->genre == NULL) {
1048                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1049                                         media_info_destroy((media_info_h)_dst);
1050                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1051                                 }
1052                         }
1053                         if (_src->audio_meta->composer != NULL) {
1054                                 _dst->audio_meta->composer = g_strdup(_src->audio_meta->composer);
1055                                 if (_dst->audio_meta->composer == NULL) {
1056                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1057                                         media_info_destroy((media_info_h)_dst);
1058                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1059                                 }
1060                         }
1061                         if (_src->audio_meta->year != NULL) {
1062                                 _dst->audio_meta->year = g_strdup(_src->audio_meta->year);
1063                                 if (_dst->audio_meta->year == NULL) {
1064                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1065                                         media_info_destroy((media_info_h)_dst);
1066                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1067                                 }
1068                         }
1069                         if (_src->audio_meta->recorded_date != NULL) {
1070                                 _dst->audio_meta->recorded_date = g_strdup(_src->audio_meta->recorded_date);
1071                                 if (_dst->audio_meta->recorded_date == NULL) {
1072                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1073                                         media_info_destroy((media_info_h)_dst);
1074                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1075                                 }
1076                         }
1077                         if (_src->audio_meta->copyright != NULL) {
1078                                 _dst->audio_meta->copyright = g_strdup(_src->audio_meta->copyright);
1079                                 if (_dst->audio_meta->copyright == NULL) {
1080                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1081                                         media_info_destroy((media_info_h)_dst);
1082                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1083                                 }
1084                         }
1085                         if (_src->audio_meta->track_num != NULL) {
1086                                 _dst->audio_meta->track_num = g_strdup(_src->audio_meta->track_num);
1087                                 if (_dst->audio_meta->track_num == NULL) {
1088                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1089                                         media_info_destroy((media_info_h)_dst);
1090                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1091                                 }
1092                         }
1093
1094                         _dst->audio_meta->channel = _src->audio_meta->channel;
1095                         _dst->audio_meta->samplerate = _src->audio_meta->samplerate;
1096                         _dst->audio_meta->duration = _src->audio_meta->duration;
1097                         _dst->audio_meta->bitrate = _src->audio_meta->bitrate;
1098                         _dst->audio_meta->bitpersample = _src->audio_meta->bitpersample;
1099                         _dst->audio_meta->played_count = _src->audio_meta->played_count;
1100                         _dst->audio_meta->played_time = _src->audio_meta->played_time;
1101                         _dst->audio_meta->played_position = _src->audio_meta->played_position;
1102                 }
1103                 *dst = (media_info_h)_dst;
1104
1105                 ret = MEDIA_CONTENT_ERROR_NONE;
1106         } else {
1107                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1108                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1109         }
1110
1111         return ret;
1112 }
1113
1114 int media_info_get_media_count_from_db(filter_h filter, int *media_count)
1115 {
1116         int ret = MEDIA_CONTENT_ERROR_NONE;
1117
1118         if (media_count == NULL) {
1119                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1120                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1121
1122                 return ret;
1123         }
1124
1125         ret = _media_db_get_group_item_count(NULL, filter, MEDIA_GROUP_NONE, media_count);
1126
1127         return ret;
1128 }
1129
1130 int media_info_foreach_media_from_db(filter_h filter, media_info_cb callback, void *user_data)
1131 {
1132         int ret = MEDIA_CONTENT_ERROR_NONE;
1133
1134         media_content_retvm_if(callback == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid callback");
1135
1136         ret = _media_db_get_group_item(NULL, filter, callback, user_data, MEDIA_GROUP_NONE);
1137
1138         return ret;
1139 }
1140
1141 int media_info_get_tag_count_from_db(const char *media_id, filter_h filter, int *tag_count)
1142 {
1143         int ret = MEDIA_CONTENT_ERROR_NONE;
1144
1145         if (STRING_VALID(media_id) && tag_count) {
1146                 ret = _media_db_get_group_item_count(media_id, filter, MEDIA_GROUP_TAG_BY_MEDIA_ID, tag_count);
1147         } else {
1148                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1149                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1150         }
1151
1152         return ret;
1153 }
1154
1155 int media_info_foreach_tag_from_db(const char *media_id, filter_h filter, media_tag_cb callback, void *user_data)
1156 {
1157         int ret = MEDIA_CONTENT_ERROR_NONE;
1158
1159         if ((callback != NULL) && STRING_VALID(media_id)) {
1160                 ret = _media_db_get_tag(media_id, filter, callback, user_data);
1161         } else {
1162                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1163                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1164         }
1165
1166         return ret;
1167 }
1168
1169 int media_info_get_bookmark_count_from_db(const char *media_id, filter_h filter, int *bookmark_count)
1170 {
1171         int ret = MEDIA_CONTENT_ERROR_NONE;
1172
1173         if (STRING_VALID(media_id) && bookmark_count) {
1174                 ret = _media_db_get_group_item_count(media_id, filter, MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID, bookmark_count);
1175         } else {
1176                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1177                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1178         }
1179
1180         return ret;
1181 }
1182
1183 int media_info_foreach_bookmark_from_db(const char *media_id, filter_h filter, media_bookmark_cb callback, void *user_data)
1184 {
1185         int ret = MEDIA_CONTENT_ERROR_NONE;
1186
1187         if ((callback != NULL) && STRING_VALID(media_id)) {
1188                 ret = _media_db_get_bookmark(media_id, filter, callback, user_data);
1189         } else {
1190                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1191                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1192         }
1193
1194         return ret;
1195 }
1196
1197 int media_info_get_face_count_from_db(const char *media_id, filter_h filter, int *face_count)
1198 {
1199         int ret = MEDIA_CONTENT_ERROR_NONE;
1200
1201         if (STRING_VALID(media_id) && face_count) {
1202                 ret = _media_db_get_group_item_count(media_id, filter, MEDIA_GROUP_FACE_BY_MEDIA_ID, face_count);
1203         } else {
1204                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1205                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1206         }
1207
1208         return ret;
1209 }
1210
1211 int media_info_foreach_face_from_db(const char *media_id, filter_h filter, media_face_cb callback, void *user_data)
1212 {
1213         int ret = MEDIA_CONTENT_ERROR_NONE;
1214
1215         if ((callback != NULL) && STRING_VALID(media_id)) {
1216                 ret = _media_db_get_face(media_id, filter, callback, user_data);
1217         } else {
1218                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1219                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1220         }
1221
1222         return ret;
1223 }
1224
1225 int media_info_get_image(media_info_h media, image_meta_h *image)
1226 {
1227         int ret = MEDIA_CONTENT_ERROR_NONE;
1228
1229         media_info_s *_media = (media_info_s*)media;
1230
1231         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
1232         media_content_retvm_if(_media->media_type != MEDIA_CONTENT_TYPE_IMAGE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_type");
1233         media_content_retvm_if(_media->image_meta == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid image_meta");
1234
1235         image_meta_s *_image = (image_meta_s*)calloc(1, sizeof(image_meta_s));
1236         media_content_retvm_if(_image == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1237
1238         _image->media_id = g_strdup(_media->media_id);
1239         _image->width = _media->image_meta->width;
1240         _image->height = _media->image_meta->height;
1241         _image->orientation = _media->image_meta->orientation;
1242         _image->fnumber = _media->image_meta->fnumber;
1243         _image->iso = _media->image_meta->iso;
1244         _image->date_taken = g_strdup(_media->image_meta->date_taken);
1245         _image->title = g_strdup(_media->image_meta->title);
1246         _image->burst_id = g_strdup(_media->image_meta->burst_id);
1247         _image->weather = g_strdup(_media->image_meta->weather);
1248         _image->exposure_time = g_strdup(_media->image_meta->exposure_time);
1249         _image->model = g_strdup(_media->image_meta->model);
1250
1251         *image = (image_meta_h)_image;
1252
1253         return ret;
1254 }
1255
1256 int media_info_get_video(media_info_h media, video_meta_h *video)
1257 {
1258         int ret = MEDIA_CONTENT_ERROR_NONE;
1259
1260         media_info_s *_media = (media_info_s*)media;
1261
1262         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
1263         media_content_retvm_if(_media->media_type != MEDIA_CONTENT_TYPE_VIDEO, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_type");
1264         media_content_retvm_if(_media->video_meta == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid video_meta");
1265
1266         video_meta_s *_video = (video_meta_s*)calloc(1, sizeof(video_meta_s));
1267         media_content_retvm_if(_video == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1268
1269         _video->media_id = g_strdup(_media->media_id);
1270         _video->title = g_strdup(_media->video_meta->title);
1271         _video->album = g_strdup(_media->video_meta->album);
1272         _video->artist = g_strdup(_media->video_meta->artist);
1273         _video->album_artist = g_strdup(_media->video_meta->album_artist);
1274         _video->genre = g_strdup(_media->video_meta->genre);
1275         _video->composer = g_strdup(_media->video_meta->composer);
1276         _video->year = g_strdup(_media->video_meta->year);
1277         _video->recorded_date = g_strdup(_media->video_meta->recorded_date);
1278         _video->copyright = g_strdup(_media->video_meta->copyright);
1279         _video->track_num = g_strdup(_media->video_meta->track_num);
1280
1281         _video->width = _media->video_meta->width;
1282         _video->height = _media->video_meta->height;
1283         _video->duration = _media->video_meta->duration;
1284         _video->bitrate = _media->video_meta->bitrate;
1285         _video->played_count = _media->video_meta->played_count;
1286         _video->played_time = _media->video_meta->played_time;
1287         _video->played_position = _media->video_meta->played_position;
1288
1289         *video = (video_meta_h)_video;
1290
1291         return ret;
1292 }
1293
1294 int media_info_get_audio(media_info_h media, audio_meta_h *audio)
1295 {
1296         int ret = MEDIA_CONTENT_ERROR_NONE;
1297
1298         media_info_s *_media = (media_info_s*)media;
1299
1300         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
1301         media_content_retvm_if(_media->media_type != MEDIA_CONTENT_TYPE_MUSIC && _media->media_type != MEDIA_CONTENT_TYPE_SOUND, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_type");
1302         media_content_retvm_if(_media->audio_meta == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid audio_meta");
1303
1304         audio_meta_s *_audio = (audio_meta_s*)calloc(1, sizeof(audio_meta_s));
1305         media_content_retvm_if(_audio == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1306
1307         _audio->media_id = g_strdup(_media->media_id);
1308         _audio->title = g_strdup(_media->audio_meta->title);
1309         _audio->album = g_strdup(_media->audio_meta->album);
1310         _audio->artist = g_strdup(_media->audio_meta->artist);
1311         _audio->album_artist = g_strdup(_media->audio_meta->album_artist);
1312         _audio->genre = g_strdup(_media->audio_meta->genre);
1313         _audio->composer = g_strdup(_media->audio_meta->composer);
1314         _audio->year = g_strdup(_media->audio_meta->year);
1315         _audio->recorded_date = g_strdup(_media->audio_meta->recorded_date);
1316         _audio->copyright = g_strdup(_media->audio_meta->copyright);
1317         _audio->track_num = g_strdup(_media->audio_meta->track_num);
1318
1319         _audio->duration = _media->audio_meta->duration;
1320         _audio->bitrate = _media->audio_meta->bitrate;
1321         _audio->bitpersample = _media->audio_meta->bitpersample;
1322         _audio->samplerate = _media->audio_meta->samplerate;
1323         _audio->channel = _media->audio_meta->channel;
1324         _audio->played_time = _media->audio_meta->played_time;
1325         _audio->played_count = _media->audio_meta->played_count;
1326         _audio->played_position = _media->audio_meta->played_position;
1327
1328         *audio = (audio_meta_h)_audio;
1329
1330         return ret;
1331 }
1332
1333 int media_info_get_media_id(media_info_h media, char **media_id)
1334 {
1335         int ret = MEDIA_CONTENT_ERROR_NONE;
1336         media_info_s *_media = (media_info_s*)media;
1337
1338         if (_media && media_id) {
1339                 if (STRING_VALID(_media->media_id)) {
1340                         *media_id = strdup(_media->media_id);
1341                         media_content_retvm_if(*media_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1342                 } else {
1343                         *media_id = NULL;
1344                 }
1345                 ret = MEDIA_CONTENT_ERROR_NONE;
1346         } else {
1347                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1348                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1349         }
1350
1351         return ret;
1352 }
1353
1354 int media_info_get_file_path(media_info_h media, char **path)
1355 {
1356         int ret = MEDIA_CONTENT_ERROR_NONE;
1357         media_info_s *_media = (media_info_s*)media;
1358
1359         if (_media && path) {
1360                 if (STRING_VALID(_media->file_path)) {
1361                         *path = strdup(_media->file_path);
1362                         media_content_retvm_if(*path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1363                 } else {
1364                         *path = NULL;
1365                 }
1366                 ret = MEDIA_CONTENT_ERROR_NONE;
1367
1368         } else {
1369                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1370                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1371         }
1372
1373         return ret;
1374 }
1375
1376 int media_info_get_display_name(media_info_h media, char **name)
1377 {
1378         int ret = MEDIA_CONTENT_ERROR_NONE;
1379         media_info_s *_media = (media_info_s*)media;
1380         if (_media && name) {
1381                 if (_media->display_name != NULL) {
1382                         *name = g_strdup(_media->display_name);
1383                         media_content_retvm_if(*name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1384                 } else {
1385                         *name = NULL;
1386                 }
1387                 ret = MEDIA_CONTENT_ERROR_NONE;
1388
1389         } else {
1390                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1391                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1392         }
1393
1394         return ret;
1395 }
1396
1397 int media_info_get_media_type(media_info_h media, media_content_type_e *type)
1398 {
1399         int ret = MEDIA_CONTENT_ERROR_NONE;
1400         media_info_s *_media = (media_info_s*)media;
1401         if (_media && type) {
1402                 *type = _media->media_type;
1403                 ret = MEDIA_CONTENT_ERROR_NONE;
1404         } else {
1405                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1406                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1407         }
1408
1409         return ret;
1410 }
1411
1412 int media_info_get_mime_type(media_info_h media, char **mime_type)
1413 {
1414         int ret = MEDIA_CONTENT_ERROR_NONE;
1415         media_info_s *_media = (media_info_s*)media;
1416
1417         if (_media && mime_type) {
1418                 if (STRING_VALID(_media->mime_type)) {
1419                         *mime_type = strdup(_media->mime_type);
1420                         media_content_retvm_if(*mime_type == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1421                 } else {
1422                         *mime_type = NULL;
1423                 }
1424                 ret = MEDIA_CONTENT_ERROR_NONE;
1425         } else {
1426                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1427                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1428         }
1429
1430         return ret;
1431 }
1432
1433 int media_info_get_size(media_info_h media, unsigned long long *size)
1434 {
1435         int ret = MEDIA_CONTENT_ERROR_NONE;
1436         media_info_s *_media = (media_info_s*)media;
1437
1438         if (_media && size) {
1439                 *size = _media->size;
1440                 ret = MEDIA_CONTENT_ERROR_NONE;
1441         } else {
1442                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1443                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1444         }
1445
1446         return ret;
1447 }
1448
1449 int media_info_get_added_time(media_info_h media, time_t *added_time)
1450 {
1451         int ret = MEDIA_CONTENT_ERROR_NONE;
1452         media_info_s *_media = (media_info_s*)media;
1453         if (_media && added_time) {
1454                 *added_time = _media->added_time;
1455                 ret = MEDIA_CONTENT_ERROR_NONE;
1456         } else {
1457                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1458                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1459         }
1460
1461         return ret;
1462 }
1463
1464 int media_info_get_modified_time(media_info_h media, time_t* time)
1465 {
1466         int ret = MEDIA_CONTENT_ERROR_NONE;
1467         media_info_s *_media = (media_info_s*)media;
1468         if (_media && time) {
1469                 *time = _media->modified_time;
1470                 ret = MEDIA_CONTENT_ERROR_NONE;
1471         } else {
1472                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1473                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1474         }
1475
1476         return ret;
1477 }
1478
1479 int media_info_get_timeline(media_info_h media, time_t* time)
1480 {
1481         int ret = MEDIA_CONTENT_ERROR_NONE;
1482         media_info_s *_media = (media_info_s*)media;
1483         if (_media && time) {
1484                 *time = _media->timeline;
1485                 ret = MEDIA_CONTENT_ERROR_NONE;
1486         } else {
1487                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1488                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1489         }
1490
1491         return ret;
1492 }
1493
1494 int media_info_get_thumbnail_path(media_info_h media, char **path)
1495 {
1496         int ret = MEDIA_CONTENT_ERROR_NONE;
1497         media_info_s *_media = (media_info_s*)media;
1498         if (_media && path) {
1499                 if (_media->thumbnail_path != NULL) {
1500                         *path = g_strdup(_media->thumbnail_path);
1501                         media_content_retvm_if(*path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1502                 } else {
1503                         *path = NULL;
1504                 }
1505                 ret = MEDIA_CONTENT_ERROR_NONE;
1506
1507         } else {
1508                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1509                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1510         }
1511
1512         return ret;
1513 }
1514
1515 int media_info_get_title(media_info_h media, char **title)
1516 {
1517         int ret = MEDIA_CONTENT_ERROR_NONE;
1518         media_info_s *_media = (media_info_s*)media;
1519
1520         if (_media && title)    { /*title can be empty string*/
1521                 if (_media->title != NULL) {
1522                         *title = g_strdup(_media->title);
1523                         media_content_retvm_if(*title == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1524                 } else {
1525                         *title = NULL;
1526                 }
1527                 ret = MEDIA_CONTENT_ERROR_NONE;
1528         } else {
1529                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1530                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1531         }
1532
1533         return ret;
1534 }
1535
1536 int media_info_get_description(media_info_h media, char **description)
1537 {
1538         int ret = MEDIA_CONTENT_ERROR_NONE;
1539         media_info_s *_media = (media_info_s*)media;
1540
1541         if (_media && description) {
1542                 if (_media->description != NULL) {      /*description can be empty string*/
1543                         *description = g_strdup(_media->description);
1544                         media_content_retvm_if(*description == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1545                 } else {
1546                         *description = NULL;
1547                 }
1548                 ret = MEDIA_CONTENT_ERROR_NONE;
1549         } else {
1550                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1551                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1552         }
1553
1554         return ret;
1555 }
1556
1557 int media_info_get_longitude(media_info_h media, double* longitude)
1558 {
1559         int ret = MEDIA_CONTENT_ERROR_NONE;
1560         media_info_s *_media = (media_info_s*)media;
1561
1562         if (_media && longitude) {
1563                 *longitude = _media->longitude;
1564                 ret = MEDIA_CONTENT_ERROR_NONE;
1565         } else {
1566                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1567                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1568         }
1569
1570         return ret;
1571 }
1572 int media_info_get_latitude(media_info_h media, double* latitude)
1573 {
1574         int ret = MEDIA_CONTENT_ERROR_NONE;
1575         media_info_s *_media = (media_info_s*)media;
1576
1577         if (_media && latitude) {
1578                 *latitude = _media->latitude;
1579                 ret = MEDIA_CONTENT_ERROR_NONE;
1580         } else {
1581                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1582                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1583         }
1584
1585         return ret;
1586 }
1587
1588 int media_info_get_altitude(media_info_h media, double *altitude)
1589 {
1590         int ret = MEDIA_CONTENT_ERROR_NONE;
1591         media_info_s *_media = (media_info_s*)media;
1592
1593         if (_media && altitude) {
1594                 *altitude = _media->altitude;
1595                 ret = MEDIA_CONTENT_ERROR_NONE;
1596         } else {
1597                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1598                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1599         }
1600
1601         return ret;
1602 }
1603
1604 int media_info_get_weather(media_info_h media, char **weather)
1605 {
1606         int ret = MEDIA_CONTENT_ERROR_NONE;
1607         media_info_s *_media = (media_info_s*)media;
1608
1609         if (_media && weather) {
1610                 if (_media->weather != NULL) {
1611                         *weather = strdup(_media->weather);
1612                         media_content_retvm_if(*weather == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1613                 } else {
1614                         *weather = NULL;
1615                 }
1616                 ret = MEDIA_CONTENT_ERROR_NONE;
1617         } else {
1618                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1619                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1620         }
1621
1622         return ret;
1623 }
1624
1625 int media_info_get_rating(media_info_h media, int *rating)
1626 {
1627         int ret = MEDIA_CONTENT_ERROR_NONE;
1628         media_info_s *_media = (media_info_s*)media;
1629
1630         if (_media && rating) {
1631                 *rating = _media->rating;
1632                 ret = MEDIA_CONTENT_ERROR_NONE;
1633         } else {
1634                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1635                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1636         }
1637
1638         return ret;
1639 }
1640
1641 int media_info_get_favorite(media_info_h media, bool* favorite)
1642 {
1643         int ret = MEDIA_CONTENT_ERROR_NONE;
1644         media_info_s *_media = (media_info_s*)media;
1645
1646         if (_media && favorite) {
1647                 *favorite = _media->favourite;
1648                 ret = MEDIA_CONTENT_ERROR_NONE;
1649         } else {
1650                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1651                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1652         }
1653
1654         return ret;
1655 }
1656
1657 int media_info_get_author(media_info_h media, char **author)
1658 {
1659         int ret = MEDIA_CONTENT_ERROR_NONE;
1660         media_info_s *_media = (media_info_s*)media;
1661
1662         if (_media && author) {
1663                 if (_media->author != NULL) {
1664                         *author = strdup(_media->author);
1665                         media_content_retvm_if(*author == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1666                 } else {
1667                         *author = NULL;
1668                 }
1669                 ret = MEDIA_CONTENT_ERROR_NONE;
1670         } else {
1671                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1672                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1673         }
1674
1675         return ret;
1676 }
1677
1678 int media_info_get_provider(media_info_h media, char **provider)
1679 {
1680         int ret = MEDIA_CONTENT_ERROR_NONE;
1681         media_info_s *_media = (media_info_s*)media;
1682
1683         if (_media && provider) {
1684                 if (_media->provider != NULL) {
1685                         *provider = strdup(_media->provider);
1686                         media_content_retvm_if(*provider == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1687                 } else {
1688                         *provider = NULL;
1689                 }
1690                 ret = MEDIA_CONTENT_ERROR_NONE;
1691         } else {
1692                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1693                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1694         }
1695
1696         return ret;
1697 }
1698
1699 int media_info_get_content_name(media_info_h media, char **content_name)
1700 {
1701         int ret = MEDIA_CONTENT_ERROR_NONE;
1702         media_info_s *_media = (media_info_s*)media;
1703
1704         if (_media && content_name) {
1705                 if (_media->content_name != NULL) {
1706                         *content_name = strdup(_media->content_name);
1707                         media_content_retvm_if(*content_name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1708                 } else {
1709                         *content_name = NULL;
1710                 }
1711                 ret = MEDIA_CONTENT_ERROR_NONE;
1712         } else {
1713                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1714                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1715         }
1716
1717         return ret;
1718 }
1719
1720 int media_info_get_category(media_info_h media, char **category)
1721 {
1722         int ret = MEDIA_CONTENT_ERROR_NONE;
1723         media_info_s *_media = (media_info_s*)media;
1724
1725         if (_media && category) {
1726                 if (_media->category != NULL) {
1727                         *category = strdup(_media->category);
1728                         media_content_retvm_if(*category == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1729                 } else {
1730                         *category = NULL;
1731                 }
1732                 ret = MEDIA_CONTENT_ERROR_NONE;
1733         } else {
1734                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1735                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1736         }
1737
1738         return ret;
1739 }
1740
1741 int media_info_get_location_tag(media_info_h media, char **location_tag)
1742 {
1743         int ret = MEDIA_CONTENT_ERROR_NONE;
1744         media_info_s *_media = (media_info_s*)media;
1745
1746         if (_media && location_tag) {
1747                 if (_media->location_tag != NULL) {
1748                         *location_tag = strdup(_media->location_tag);
1749                         media_content_retvm_if(*location_tag == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1750                 } else {
1751                         *location_tag = NULL;
1752                 }
1753                 ret = MEDIA_CONTENT_ERROR_NONE;
1754         } else {
1755                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1756                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1757         }
1758
1759         return ret;
1760 }
1761
1762 int media_info_get_age_rating(media_info_h media, char **age_rating)
1763 {
1764         int ret = MEDIA_CONTENT_ERROR_NONE;
1765         media_info_s *_media = (media_info_s*)media;
1766
1767         if (_media && age_rating) {
1768                 if (_media->age_rating != NULL) {
1769                         *age_rating = strdup(_media->age_rating);
1770                         media_content_retvm_if(*age_rating == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1771                 } else {
1772                         *age_rating = NULL;
1773                 }
1774                 ret = MEDIA_CONTENT_ERROR_NONE;
1775         } else {
1776                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1777                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1778         }
1779
1780         return ret;
1781 }
1782
1783 int media_info_get_keyword(media_info_h media, char **keyword)
1784 {
1785         int ret = MEDIA_CONTENT_ERROR_NONE;
1786         media_info_s *_media = (media_info_s*)media;
1787
1788         if (_media && keyword) {
1789                 if (_media->keyword != NULL) {
1790                         *keyword = strdup(_media->keyword);
1791                         media_content_retvm_if(*keyword == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1792                 } else {
1793                         *keyword = NULL;
1794                 }
1795                 ret = MEDIA_CONTENT_ERROR_NONE;
1796         } else {
1797                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1798                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1799         }
1800
1801         return ret;
1802 }
1803
1804 int media_info_get_storage_id(media_info_h media, char **storage_id)
1805 {
1806         int ret = MEDIA_CONTENT_ERROR_NONE;
1807         media_info_s *_media = (media_info_s*)media;
1808
1809         if (_media && storage_id) {
1810                 if (STRING_VALID(_media->storage_uuid)) {
1811                         *storage_id = strdup(_media->storage_uuid);
1812                         media_content_retvm_if(*storage_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1813                 } else {
1814                         *storage_id = NULL;
1815                 }
1816                 ret = MEDIA_CONTENT_ERROR_NONE;
1817         } else {
1818                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1819                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1820         }
1821
1822         return ret;
1823 }
1824
1825 int media_info_is_drm(media_info_h media, bool *is_drm)
1826 {
1827         int ret = MEDIA_CONTENT_ERROR_NONE;
1828         media_info_s *_media = (media_info_s*)media;
1829
1830         if (_media) {
1831                 *is_drm = _media->is_drm;
1832                 ret = MEDIA_CONTENT_ERROR_NONE;
1833         } else {
1834                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1835                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1836         }
1837
1838         return ret;
1839 }
1840
1841 int media_info_is_360_content(media_info_h media, bool *is_360)
1842 {
1843         int ret = MEDIA_CONTENT_ERROR_NONE;
1844         media_info_s *_media = (media_info_s*)media;
1845
1846         if (_media) {
1847                 *is_360 = _media->is_360;
1848                 ret = MEDIA_CONTENT_ERROR_NONE;
1849         } else {
1850                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1851                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1852         }
1853
1854         return ret;
1855 }
1856
1857 int media_info_get_storage_type(media_info_h media, media_content_storage_e *storage_type)
1858 {
1859         int ret = MEDIA_CONTENT_ERROR_NONE;
1860         media_info_s *_media = (media_info_s*)media;
1861
1862         if (_media && storage_type) {
1863                 *storage_type = _media->storage_type;
1864                 ret = MEDIA_CONTENT_ERROR_NONE;
1865         } else {
1866                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1867                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1868         }
1869
1870         return ret;
1871 }
1872
1873 int media_info_get_played_count(media_info_h media, int *played_count)
1874 {
1875         int ret = MEDIA_CONTENT_ERROR_NONE;
1876         media_info_s *_media = (media_info_s*)media;
1877
1878         if (_media) {
1879                 *played_count = _media->played_count;
1880                 ret = MEDIA_CONTENT_ERROR_NONE;
1881         } else {
1882                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1883                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1884         }
1885
1886         return ret;
1887 }
1888
1889 int media_info_get_played_time(media_info_h media, time_t* played_time)
1890 {
1891         int ret = MEDIA_CONTENT_ERROR_NONE;
1892         media_info_s *_media = (media_info_s*)media;
1893
1894         if (_media) {
1895                 *played_time = _media->played_time;
1896                 ret = MEDIA_CONTENT_ERROR_NONE;
1897         } else {
1898                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1899                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1900         }
1901
1902         return ret;
1903 }
1904
1905 int media_info_increase_played_count(media_info_h media)
1906 {
1907         int ret = MEDIA_CONTENT_ERROR_NONE;
1908
1909         media_info_s *_media = (media_info_s*)media;
1910
1911         if (_media) {
1912                 _media->played_count += 1;
1913         } else {
1914                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1915                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1916         }
1917
1918         return ret;
1919 }
1920
1921 int media_info_set_played_time(media_info_h media)
1922 {
1923         int ret = MEDIA_CONTENT_ERROR_NONE;
1924         time_t current_time;
1925
1926         media_info_s *_media = (media_info_s*)media;
1927
1928         if (_media != NULL) {
1929                 time(&current_time);
1930                 _media->played_time = current_time;
1931         } else {
1932                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1933                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1934         }
1935
1936         return ret;
1937 }
1938
1939 int media_info_get_media_from_db(const char *media_id, media_info_h *media)
1940 {
1941         int ret = MEDIA_CONTENT_ERROR_NONE;
1942         char select_query[DEFAULT_QUERY_SIZE];
1943         char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
1944         sqlite3_stmt *stmt = NULL;
1945
1946         if (!STRING_VALID(media_id) || (media == NULL)) {
1947                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1948                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1949         }
1950
1951         memset(select_query, 0x00, sizeof(select_query));
1952         memset(storage_id, 0x00, sizeof(storage_id));
1953
1954         ret = _media_db_get_storage_id_by_media_id(media_id, storage_id);
1955         media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1956
1957         snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_MEDIA, storage_id, media_id);
1958
1959         ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
1960         media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1961
1962         media_info_s *_media = NULL;
1963
1964         while (sqlite3_step(stmt) == SQLITE_ROW) {
1965                 if (_media)
1966                         media_info_destroy((media_info_h)_media);
1967
1968                 _media = (media_info_s*)calloc(1, sizeof(media_info_s));
1969
1970                 if (_media == NULL) {
1971                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1972                         SQLITE3_FINALIZE(stmt);
1973                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1974                 }
1975
1976                 _media_info_item_get_detail(stmt, (media_info_h)_media);
1977
1978                 *media = (media_info_h)_media;
1979         }
1980
1981         SQLITE3_FINALIZE(stmt);
1982
1983         return ret;
1984 }
1985
1986 int media_info_set_display_name(media_info_h media, const char *display_name)
1987 {
1988         int ret = MEDIA_CONTENT_ERROR_NONE;
1989         media_info_s *_media = (media_info_s*)media;
1990
1991         if (_media != NULL && STRING_VALID(display_name)) {
1992                 SAFE_FREE(_media->display_name);
1993
1994                 _media->display_name = strdup(display_name);
1995                 media_content_retvm_if(_media->display_name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1996         } else {
1997                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1998                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1999         }
2000
2001         return ret;
2002 }
2003
2004 int media_info_set_description(media_info_h media, const char *description)
2005 {
2006         int ret = MEDIA_CONTENT_ERROR_NONE;
2007         media_info_s *_media = (media_info_s*)media;
2008
2009         if (_media != NULL) {
2010                 SAFE_FREE(_media->description);
2011
2012                 if (STRING_VALID(description)) {
2013                         _media->description = strdup(description);
2014                         media_content_retvm_if(_media->description == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2015                 } else {
2016                         _media->description = NULL;
2017                 }
2018         } else {
2019                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2020                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2021         }
2022
2023         return ret;
2024 }
2025
2026 int media_info_set_longitude(media_info_h media, double longitude)
2027 {
2028         int ret = MEDIA_CONTENT_ERROR_NONE;
2029         media_info_s *_media = (media_info_s*)media;
2030
2031         if (_media != NULL) {
2032                 _media->longitude = longitude;
2033         } else {
2034                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2035                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2036         }
2037
2038         return ret;
2039 }
2040
2041 int media_info_set_latitude(media_info_h media, double latitude)
2042 {
2043         int ret = MEDIA_CONTENT_ERROR_NONE;
2044         media_info_s *_media = (media_info_s*)media;
2045
2046         if (_media != NULL) {
2047                 _media->latitude = latitude;
2048         } else {
2049                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2050                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2051         }
2052
2053         return ret;
2054 }
2055
2056 int media_info_set_altitude(media_info_h media, double altitude)
2057 {
2058         int ret = MEDIA_CONTENT_ERROR_NONE;
2059         media_info_s *_media = (media_info_s*)media;
2060
2061         if (_media != NULL) {
2062                 _media->altitude = altitude;
2063         } else {
2064                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2065                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2066         }
2067
2068         return ret;
2069 }
2070
2071 int media_info_set_weather(media_info_h media, const char *weather)
2072 {
2073         int ret = MEDIA_CONTENT_ERROR_NONE;
2074         media_info_s *_media = (media_info_s*)media;
2075
2076         if (_media != NULL) {
2077                 SAFE_FREE(_media->weather);
2078
2079                 if (STRING_VALID(weather)) {
2080                         _media->weather = strdup(weather);
2081                         media_content_retvm_if(_media->weather == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2082                 } else {
2083                         _media->weather = NULL;
2084                 }
2085         } else {
2086                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2087                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2088         }
2089
2090         return ret;
2091 }
2092
2093 int media_info_set_rating(media_info_h media, int rating)
2094 {
2095         int ret = MEDIA_CONTENT_ERROR_NONE;
2096         media_info_s *_media = (media_info_s*)media;
2097
2098         if (_media != NULL) {
2099                 _media->rating = rating;
2100         } else {
2101                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2102                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2103         }
2104
2105         return ret;
2106 }
2107
2108 int media_info_set_added_time(media_info_h media, time_t added_time)
2109 {
2110         int ret = MEDIA_CONTENT_ERROR_NONE;
2111
2112         media_info_s *_media = (media_info_s*)media;
2113
2114         if ((_media != NULL) && (added_time >= 0)) {
2115                 _media->added_time = added_time;
2116         } else {
2117                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2118                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2119         }
2120
2121         return ret;
2122 }
2123
2124 int media_info_set_favorite(media_info_h media, bool favorite)
2125 {
2126         int ret = MEDIA_CONTENT_ERROR_NONE;
2127         media_info_s *_media = (media_info_s*)media;
2128
2129         if (_media != NULL) {
2130                 if (favorite == TRUE)
2131                         time(&_media->favourite);
2132                 else
2133                         _media->favourite = 0;
2134         } else {
2135                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2136                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2137         }
2138
2139         return ret;
2140 }
2141
2142 int media_info_set_author(media_info_h media, const char *author)
2143 {
2144         int ret = MEDIA_CONTENT_ERROR_NONE;
2145         media_info_s *_media = (media_info_s*)media;
2146
2147         if (_media != NULL) {
2148                 if (STRING_VALID(author)) {
2149                         _media->author = strdup(author);
2150                         media_content_retvm_if(_media->author == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2151                 } else {
2152                         _media->author = NULL;
2153                 }
2154         } else {
2155                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2156                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2157         }
2158
2159         return ret;
2160 }
2161
2162 int media_info_set_provider(media_info_h media, const char *provider)
2163 {
2164         int ret = MEDIA_CONTENT_ERROR_NONE;
2165         media_info_s *_media = (media_info_s*)media;
2166
2167         if (_media != NULL) {
2168                 SAFE_FREE(_media->provider);
2169
2170                 if (STRING_VALID(provider)) {
2171                         _media->provider = strdup(provider);
2172                         media_content_retvm_if(_media->provider == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2173                 } else {
2174                         _media->provider = NULL;
2175                 }
2176         } else {
2177                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2178                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2179         }
2180
2181         return ret;
2182 }
2183
2184 int media_info_set_content_name(media_info_h media, const char *content_name)
2185 {
2186         int ret = MEDIA_CONTENT_ERROR_NONE;
2187         media_info_s *_media = (media_info_s*)media;
2188
2189         if (_media != NULL) {
2190                 SAFE_FREE(_media->content_name);
2191
2192                 if (STRING_VALID(content_name)) {
2193                         _media->content_name = strdup(content_name);
2194                         media_content_retvm_if(_media->content_name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2195                 } else {
2196                         _media->content_name = NULL;
2197                 }
2198         } else {
2199                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2200                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2201         }
2202
2203         return ret;
2204 }
2205
2206 int media_info_set_category(media_info_h media, const char *category)
2207 {
2208         int ret = MEDIA_CONTENT_ERROR_NONE;
2209         media_info_s *_media = (media_info_s*)media;
2210
2211         if (_media != NULL) {
2212                 SAFE_FREE(_media->category);
2213
2214                 if (STRING_VALID(category)) {
2215                         _media->category = strdup(category);
2216                         media_content_retvm_if(_media->category == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2217                 } else {
2218                         _media->category = NULL;
2219                 }
2220         } else {
2221                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2222                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2223         }
2224
2225         return ret;
2226 }
2227
2228 int media_info_set_location_tag(media_info_h media, const char *location_tag)
2229 {
2230         int ret = MEDIA_CONTENT_ERROR_NONE;
2231         media_info_s *_media = (media_info_s*)media;
2232
2233         if (_media != NULL) {
2234                 SAFE_FREE(_media->location_tag);
2235
2236                 if (STRING_VALID(location_tag)) {
2237                         _media->location_tag = strdup(location_tag);
2238                         media_content_retvm_if(_media->location_tag == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2239                 } else {
2240                         _media->location_tag = NULL;
2241                 }
2242         } else {
2243                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2244                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2245         }
2246
2247         return ret;
2248 }
2249
2250 int media_info_set_age_rating(media_info_h media, const char *age_rating)
2251 {
2252         int ret = MEDIA_CONTENT_ERROR_NONE;
2253         media_info_s *_media = (media_info_s*)media;
2254
2255         if (_media != NULL) {
2256                 SAFE_FREE(_media->age_rating);
2257
2258                 if (STRING_VALID(age_rating)) {
2259                         _media->age_rating = strdup(age_rating);
2260                         media_content_retvm_if(_media->age_rating == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2261                 } else {
2262                         _media->age_rating = NULL;
2263                 }
2264         } else {
2265                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2266                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2267         }
2268
2269         return ret;
2270 }
2271
2272 int media_info_set_keyword(media_info_h media, const char *keyword)
2273 {
2274         int ret = MEDIA_CONTENT_ERROR_NONE;
2275         media_info_s *_media = (media_info_s*)media;
2276
2277         if (_media != NULL) {
2278                 SAFE_FREE(_media->keyword);
2279
2280                 if (STRING_VALID(keyword)) {
2281                         _media->keyword = strdup(keyword);
2282                         media_content_retvm_if(_media->keyword == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2283                 } else {
2284                         _media->keyword = NULL;
2285                 }
2286         } else {
2287                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2288                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2289         }
2290
2291         return ret;
2292 }
2293
2294 int media_info_update_to_db(media_info_h media)
2295 {
2296         int ret = MEDIA_CONTENT_ERROR_NONE;
2297         media_info_s *_media = (media_info_s*)media;
2298         char *set_sql = NULL;
2299         char *sql = NULL;
2300
2301         if (_media != NULL && STRING_VALID(_media->media_id)) {
2302                 /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
2303                 /* This code will be removed when sqlite3_mprintf works clearly */
2304                 char *test_sql = sqlite3_mprintf("%f, %f, %f", _media->longitude, _media->latitude, _media->altitude);
2305                 SQLITE3_SAFE_FREE(test_sql);
2306
2307                 /*Update Pinyin If Support Pinyin*/
2308                 char *file_name_pinyin = NULL;
2309                 char *description_pinyin = NULL;
2310                 char *author_pinyin = NULL;
2311                 char *provider_pinyin = NULL;
2312                 char *content_name_pinyin = NULL;
2313                 char *category_pinyin = NULL;
2314                 char *location_tag_pinyin = NULL;
2315                 char *age_rating_pinyin = NULL;
2316                 char *keyword_pinyin = NULL;
2317                 bool pinyin_support = FALSE;
2318
2319                 /*Update Pinyin If Support Pinyin*/
2320                 media_svc_check_pinyin_support(&pinyin_support);
2321                 if (pinyin_support) {
2322                         if (STRING_VALID(_media->display_name))
2323                                 media_svc_get_pinyin(_media->display_name, &file_name_pinyin);
2324                         if (STRING_VALID(_media->description))
2325                                 media_svc_get_pinyin(_media->description, &description_pinyin);
2326                         if (STRING_VALID(_media->author))
2327                                 media_svc_get_pinyin(_media->author, &author_pinyin);
2328                         if (STRING_VALID(_media->provider))
2329                                 media_svc_get_pinyin(_media->provider, &provider_pinyin);
2330                         if (STRING_VALID(_media->content_name))
2331                                 media_svc_get_pinyin(_media->content_name, &content_name_pinyin);
2332                         if (STRING_VALID(_media->category))
2333                                 media_svc_get_pinyin(_media->category, &category_pinyin);
2334                         if (STRING_VALID(_media->location_tag))
2335                                 media_svc_get_pinyin(_media->location_tag, &location_tag_pinyin);
2336                         if (STRING_VALID(_media->age_rating))
2337                                 media_svc_get_pinyin(_media->age_rating, &age_rating_pinyin);
2338                         if (STRING_VALID(_media->keyword))
2339                                 media_svc_get_pinyin(_media->keyword, &keyword_pinyin);
2340                 }
2341
2342                 char *album = NULL;
2343                 char *artist = NULL;
2344                 char *genre = NULL;
2345                 char *recorded_date = NULL;
2346
2347                 if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
2348                         if (_media->video_meta->album != NULL)
2349                                 album = strdup(_media->video_meta->album);
2350                         if (_media->video_meta->artist != NULL)
2351                                 artist = strdup(_media->video_meta->artist);
2352                         if (_media->video_meta->genre != NULL)
2353                                 genre = strdup(_media->video_meta->genre);
2354                         if (_media->video_meta->recorded_date != NULL)
2355                                 recorded_date = strdup(_media->video_meta->recorded_date);
2356                 } else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) {
2357                         if (_media->audio_meta->album != NULL)
2358                                 album = strdup(_media->audio_meta->album);
2359                         if (_media->audio_meta->artist != NULL)
2360                                 artist = strdup(_media->audio_meta->artist);
2361                         if (_media->audio_meta->genre != NULL)
2362                                 genre = strdup(_media->audio_meta->genre);
2363                         if (_media->audio_meta->recorded_date != NULL)
2364                                 recorded_date = strdup(_media->audio_meta->recorded_date);
2365                 }
2366
2367                 set_sql = sqlite3_mprintf("file_name=%Q, added_time=%d, description=%Q, longitude=%f, latitude=%f, altitude=%f, \
2368                         played_count=%d, last_played_time=%d, last_played_position=%d, \
2369                         rating=%d, favourite=%d, author=%Q, provider=%Q, content_name=%Q, category=%Q, location_tag=%Q, age_rating=%Q, keyword=%Q, weather=%Q, sync_status=%d, \
2370                         file_name_pinyin=%Q, description_pinyin=%Q, author_pinyin=%Q, provider_pinyin=%Q, content_name_pinyin=%Q, category_pinyin=%Q, location_tag_pinyin=%Q, age_rating_pinyin=%Q, keyword_pinyin=%Q, title=%Q, \
2371                         album=%Q, artist=%Q, genre=%Q, recorded_date=%Q",
2372                         _media->display_name, _media->added_time, _media->description, _media->longitude, _media->latitude, _media->altitude, _media->played_count, _media->played_time, _media->played_position, _media->rating, _media->favourite,
2373                         _media->author, _media->provider, _media->content_name, _media->category, _media->location_tag, _media->age_rating, _media->keyword, _media->weather, _media->sync_status,
2374                         file_name_pinyin, description_pinyin, author_pinyin, provider_pinyin, content_name_pinyin, category_pinyin, location_tag_pinyin, age_rating_pinyin, keyword_pinyin, _media->title,
2375                         album, artist, genre, recorded_date);
2376
2377                 sql = sqlite3_mprintf("UPDATE %Q SET %s WHERE media_uuid=%Q", _media->storage_uuid, set_sql, _media->media_id);
2378
2379                 ret = _content_query_sql(sql);
2380                 SQLITE3_SAFE_FREE(set_sql);
2381                 SQLITE3_SAFE_FREE(sql);
2382
2383                 SAFE_FREE(description_pinyin);
2384                 SAFE_FREE(author_pinyin);
2385                 SAFE_FREE(provider_pinyin);
2386                 SAFE_FREE(content_name_pinyin);
2387                 SAFE_FREE(category_pinyin);
2388                 SAFE_FREE(location_tag_pinyin);
2389                 SAFE_FREE(age_rating_pinyin);
2390                 SAFE_FREE(keyword_pinyin);
2391
2392                 SAFE_FREE(album);
2393                 SAFE_FREE(artist);
2394                 SAFE_FREE(genre);
2395                 SAFE_FREE(recorded_date);
2396
2397                 if (_media->storage_type == MEDIA_CONTENT_STORAGE_CLOUD) {
2398                         set_sql = NULL;
2399                         sql = NULL;
2400
2401                         if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
2402                                 set_sql = sqlite3_mprintf("title=%Q, album=%Q, artist=%Q, genre=%Q, duration=%d, width=%d, height=%d", \
2403                                 _media->title, _media->video_meta->album, _media->video_meta->artist, _media->video_meta->genre, _media->video_meta->duration, _media->video_meta->width, _media->video_meta->height);
2404                         } else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) {
2405                                 set_sql = sqlite3_mprintf("title=%Q, album=%Q, artist=%Q, genre=%Q, duration=%d", \
2406                                 _media->title, _media->audio_meta->album, _media->audio_meta->artist, _media->audio_meta->genre, _media->audio_meta->duration);
2407                         } else if (_media->media_type == MEDIA_CONTENT_TYPE_IMAGE) {
2408                                 set_sql = sqlite3_mprintf("title=%Q, width=%d, height=%d", _media->title, _media->image_meta->width, _media->image_meta->height);
2409                         } else {
2410                                 set_sql = sqlite3_mprintf("title=%Q", _media->title);
2411                         }
2412
2413                         sql = sqlite3_mprintf("UPDATE %Q SET %s WHERE media_uuid=%Q", _media->storage_uuid, set_sql, _media->media_id);
2414
2415                         ret = _content_query_sql(sql);
2416
2417                         SQLITE3_SAFE_FREE(set_sql);
2418                         SQLITE3_SAFE_FREE(sql);
2419                 }
2420
2421                 if (ret == MEDIA_CONTENT_ERROR_NONE) {
2422                         /* Send notification for this update */
2423                         media_content_debug("Update is successfull. Send notification for this");
2424                         if (_media->file_path && _media->mime_type)
2425                                 media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, _media->file_path, _media->media_type, _media->media_id, _media->mime_type);
2426                         else
2427                                 media_content_error("Can't Send Noti : path or mime type is NULL");
2428                 }
2429         } else {
2430                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2431                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2432         }
2433
2434         return ret;
2435 }
2436
2437 int media_info_refresh_metadata_to_db(const char *media_id)
2438 {
2439         int ret = MEDIA_CONTENT_ERROR_NONE;
2440         media_info_h media = NULL;
2441         char *file_path = NULL;
2442         media_content_storage_e storage_type = 0;
2443         char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
2444
2445         if (!STRING_VALID(media_id)) {
2446                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2447                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2448         }
2449
2450         ret = media_info_get_media_from_db(media_id, &media);
2451         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2452                 media_info_destroy(media);
2453                 return ret;
2454         }
2455
2456         ret = media_info_get_storage_type(media, &storage_type);
2457         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2458                 media_info_destroy(media);
2459                 return ret;
2460         }
2461
2462         if (storage_type == MEDIA_CONTENT_STORAGE_CLOUD) {
2463                 media_info_destroy(media);
2464                 media_content_error("Can't refresh cloud content!!");
2465                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2466         }
2467
2468         ret = media_info_get_file_path(media, &file_path);
2469         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2470                 media_info_destroy(media);
2471                 return ret;
2472         }
2473
2474         ret = _media_util_check_file_exist(file_path);
2475         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2476                 SAFE_FREE(file_path);
2477                 media_info_destroy(media);
2478                 return ret;
2479         }
2480
2481         memset(storage_id, 0x00, sizeof(storage_id));
2482         ret = media_svc_get_storage_id(_content_get_db_handle(), file_path, storage_id);
2483         if (ret != MS_MEDIA_ERR_NONE) {
2484                 media_content_error("media_svc_get_storage_id failed : %d", ret);
2485                 SAFE_FREE(file_path);
2486                 media_info_destroy(media);
2487                 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2488         }
2489
2490         ret = media_svc_refresh_item(_content_get_db_handle(), storage_id, storage_type, file_path, tzplatform_getuid(TZ_USER_NAME));
2491         if (ret != MS_MEDIA_ERR_NONE)
2492                 ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2493
2494         SAFE_FREE(file_path);
2495         media_info_destroy(media);
2496
2497         return ret;
2498 }
2499
2500 int media_info_move_to_db(media_info_h media, const char* dst_path)
2501 {
2502         int ret = MEDIA_CONTENT_ERROR_NONE;
2503         bool ignore_file = FALSE;
2504         bool ignore_dir = FALSE;
2505         char *folder_path = NULL;
2506         media_svc_storage_type_e src_storage_type = 0;
2507         media_svc_storage_type_e dst_storage_type = 0;
2508         char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
2509
2510         media_content_retvm_if(media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media");
2511         media_content_retvm_if(!STRING_VALID(dst_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid dst_path");
2512
2513         media_info_s *_media = (media_info_s*)media;
2514
2515         ret = _media_util_check_ignore_file(dst_path, &ignore_file);
2516         media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
2517
2518         ret = _media_util_check_file_exist(dst_path);
2519         media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
2520
2521         folder_path = g_path_get_dirname(dst_path);
2522         ret = _media_util_check_ignore_dir(folder_path, &ignore_dir);
2523         SAFE_FREE(folder_path);
2524
2525         media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
2526
2527         ret = media_svc_get_storage_type(_media->file_path, &src_storage_type, tzplatform_getuid(TZ_USER_NAME));
2528         if (ret != MS_MEDIA_ERR_NONE) {
2529                 media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
2530                 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2531         }
2532
2533         ret = media_svc_get_storage_type(dst_path, &dst_storage_type, tzplatform_getuid(TZ_USER_NAME));
2534         if (ret != MS_MEDIA_ERR_NONE) {
2535                 media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
2536                 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2537         }
2538
2539         memset(storage_id, 0x00, sizeof(storage_id));
2540         ret = media_svc_get_storage_id(_content_get_db_handle(), _media->file_path, storage_id);
2541         if (ret != MS_MEDIA_ERR_NONE) {
2542                 media_content_error("media_svc_get_storage_id failed : %d", ret);
2543                 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2544         }
2545
2546         ret = media_svc_move_item(_content_get_db_handle(), storage_id, src_storage_type, _media->file_path, dst_storage_type, dst_path, tzplatform_getuid(TZ_USER_NAME));
2547         return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2548 }
2549
2550 int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb callback, void *user_data)
2551 {
2552         int ret = MEDIA_CONTENT_ERROR_NONE;
2553         static unsigned int req_id = 0;
2554         media_info_s *_media = (media_info_s*)media;
2555
2556         if (_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path)) {
2557                 media_thumbnail_cb_s *_thumb_cb = (media_thumbnail_cb_s*)calloc(1, sizeof(media_thumbnail_cb_s));
2558                 media_content_retvm_if(_thumb_cb == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2559                 req_id++;
2560                 _media->request_id = req_id;
2561
2562                 _thumb_cb->handle = _media;
2563                 _thumb_cb->user_data = user_data;
2564                 _thumb_cb->thumbnail_completed_cb = callback;
2565
2566                 ret = thumbnail_request_from_db_async(_media->request_id, _media->file_path, (ThumbFunc)__media_info_thumbnail_completed_cb, (void *)_thumb_cb, tzplatform_getuid(TZ_USER_NAME));
2567                 ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret);
2568         } else {
2569                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2570                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2571         }
2572
2573         return ret;
2574 }
2575
2576 int media_info_cancel_thumbnail(media_info_h media)
2577 {
2578         int ret = MEDIA_CONTENT_ERROR_NONE;
2579         media_info_s *_media = (media_info_s*)media;
2580
2581         if (_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path) && _media->request_id > 0) {
2582                 ret = thumbnail_request_cancel_media(_media->request_id, _media->file_path);
2583                 ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret);
2584         } else {
2585                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2586                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2587         }
2588
2589         return ret;
2590 }
2591
2592 static int __media_info_map_data_usr_to_svc(media_info_s *media, media_svc_content_info_s **service_content, media_content_storage_e storage_type)
2593 {
2594         media_content_retvm_if(media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle");
2595
2596         media_svc_content_info_s *svc_content_info = calloc(1, sizeof(media_svc_content_info_s));
2597         media_content_retvm_if(svc_content_info == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2598
2599         svc_content_info->path = g_strdup(media->file_path);
2600         svc_content_info->file_name = g_strdup(media->display_name);
2601         svc_content_info->media_type = media->media_type;
2602         svc_content_info->mime_type = g_strdup(media->mime_type);
2603         svc_content_info->size = media->size;
2604         svc_content_info->storage_type = storage_type;
2605         svc_content_info->storage_uuid = g_strdup(media->storage_uuid);
2606
2607         svc_content_info->added_time = media->added_time;
2608         svc_content_info->modified_time = media->modified_time;
2609         svc_content_info->thumbnail_path = g_strdup(media->thumbnail_path);
2610         svc_content_info->is_drm = media->is_drm;
2611         svc_content_info->last_played_time = media->played_time;
2612         svc_content_info->played_count = media->played_count;
2613         svc_content_info->favourate = media->favourite;
2614
2615         svc_content_info->media_meta.title = g_strdup(media->title);
2616         svc_content_info->media_meta.rating = media->rating;
2617         svc_content_info->media_meta.description = g_strdup(media->description);
2618         svc_content_info->media_meta.longitude = media->longitude;
2619         svc_content_info->media_meta.latitude = media->latitude;
2620         svc_content_info->media_meta.altitude = media->altitude;
2621         svc_content_info->media_meta.weather = g_strdup(media->weather);
2622         svc_content_info->media_meta.category = g_strdup(media->category);
2623         svc_content_info->media_meta.keyword = g_strdup(media->keyword);
2624         svc_content_info->media_meta.location_tag = g_strdup(media->location_tag);
2625         svc_content_info->media_meta.content_name = g_strdup(media->content_name);
2626         svc_content_info->media_meta.age_rating = g_strdup(media->age_rating);
2627         svc_content_info->media_meta.author = g_strdup(media->author);
2628         svc_content_info->media_meta.provider = g_strdup(media->provider);
2629
2630         svc_content_info->media_meta.album = g_strdup(media->audio_meta->album);
2631         svc_content_info->media_meta.artist = g_strdup(media->audio_meta->artist);
2632         svc_content_info->media_meta.genre = g_strdup(media->audio_meta->genre);
2633         svc_content_info->media_meta.recorded_date = g_strdup(media->audio_meta->recorded_date);
2634
2635         if (storage_type == MEDIA_CONTENT_STORAGE_CLOUD) {
2636                 switch (media->media_type) {
2637                 case MEDIA_CONTENT_TYPE_IMAGE:
2638                         svc_content_info->media_meta.width = media->image_meta->width;
2639                         svc_content_info->media_meta.height = media->image_meta->height;
2640                         svc_content_info->media_meta.datetaken = g_strdup(media->image_meta->date_taken);
2641                         svc_content_info->media_meta.orientation = media->image_meta->orientation;
2642                         break;
2643                 case MEDIA_CONTENT_TYPE_VIDEO:
2644                         svc_content_info->media_meta.album_artist = g_strdup(media->audio_meta->album_artist);
2645                         svc_content_info->media_meta.composer = g_strdup(media->audio_meta->composer);
2646                         svc_content_info->media_meta.year = g_strdup(media->audio_meta->year);
2647                         svc_content_info->media_meta.copyright = g_strdup(media->audio_meta->copyright);
2648                         svc_content_info->media_meta.track_num = g_strdup(media->audio_meta->track_num);
2649                         svc_content_info->media_meta.bitrate = media->audio_meta->bitrate;
2650                         svc_content_info->media_meta.duration = media->audio_meta->duration;
2651                         svc_content_info->media_meta.width = media->image_meta->width;
2652                         svc_content_info->media_meta.height = media->image_meta->height;
2653                         break;
2654                 case MEDIA_CONTENT_TYPE_SOUND:
2655                 case MEDIA_CONTENT_TYPE_MUSIC:
2656                         svc_content_info->media_meta.album_artist = g_strdup(media->audio_meta->album_artist);
2657                         svc_content_info->media_meta.composer = g_strdup(media->audio_meta->composer);
2658                         svc_content_info->media_meta.year = g_strdup(media->audio_meta->year);
2659                         svc_content_info->media_meta.copyright = g_strdup(media->audio_meta->copyright);
2660                         svc_content_info->media_meta.track_num = g_strdup(media->audio_meta->track_num);
2661                         svc_content_info->media_meta.bitrate = media->audio_meta->bitrate;
2662                         svc_content_info->media_meta.duration = media->audio_meta->duration;
2663                         svc_content_info->media_meta.channel = media->audio_meta->channel;
2664                         svc_content_info->media_meta.samplerate = media->audio_meta->samplerate;
2665                         break;
2666                 case MEDIA_CONTENT_TYPE_OTHERS:
2667                 default:
2668                         break;
2669                 }
2670         }
2671
2672         *service_content = svc_content_info;
2673
2674         return MEDIA_CONTENT_ERROR_NONE;
2675 }
2676
2677 static int __media_info_set_str_data(media_info_h media, media_info_item_e data_type, const char *str_data)
2678 {
2679         media_info_s *_media = (media_info_s*)media;
2680
2681         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
2682
2683         switch (data_type) {
2684         case MEDIA_INFO_PATH:
2685                 SAFE_FREE(_media->file_path);
2686                 if (STRING_VALID(str_data)) {
2687                         _media->file_path = strdup(str_data);
2688                         media_content_retvm_if(_media->file_path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2689                 } else {
2690                         _media->file_path = NULL;
2691                 }
2692                 break;
2693         case MEDIA_INFO_MIME_TYPE:
2694                 SAFE_FREE(_media->mime_type);
2695                 if (STRING_VALID(str_data)) {
2696                         _media->mime_type = strdup(str_data);
2697                         media_content_retvm_if(_media->mime_type == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2698                 } else {
2699                         _media->mime_type = NULL;
2700                 }
2701                 break;
2702         case MEDIA_INFO_THUMBNAIL_PATH:
2703                 SAFE_FREE(_media->thumbnail_path);
2704                 if (STRING_VALID(str_data)) {
2705                         _media->thumbnail_path = strdup(str_data);
2706                         media_content_retvm_if(_media->thumbnail_path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2707                 } else {
2708                         _media->thumbnail_path = NULL;
2709                 }
2710                 break;
2711         case MEDIA_INFO_TITLE:
2712                 SAFE_FREE(_media->title);
2713                 if (STRING_VALID(str_data)) {
2714                         _media->title = strdup(str_data);
2715                         media_content_retvm_if(_media->title == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2716                 } else {
2717                         _media->title = NULL;
2718                 }
2719                 break;
2720         case MEDIA_INFO_STORAGE_UUID:
2721                 SAFE_FREE(_media->storage_uuid);
2722                 if (STRING_VALID(str_data)) {
2723                         _media->storage_uuid = strdup(str_data);
2724                         media_content_retvm_if(_media->storage_uuid == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2725                 } else {
2726                         _media->storage_uuid = NULL;
2727                 }
2728                 break;
2729         case MEDIA_INFO_ALBUM:
2730                 if (STRING_VALID(_media->media_id)) {
2731                         if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
2732                                 SAFE_FREE(_media->video_meta->album);
2733                                 if (str_data != NULL) {
2734                                         _media->video_meta->album = strdup(str_data);
2735                                         media_content_retvm_if(_media->video_meta->album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2736                                 }
2737                         } else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) {
2738                                 SAFE_FREE(_media->audio_meta->album);
2739                                 if (str_data != NULL) {
2740                                         _media->audio_meta->album = strdup(str_data);
2741                                         media_content_retvm_if(_media->audio_meta->album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2742                                 }
2743                         }
2744                 } else {
2745                         SAFE_FREE(_media->video_meta->album);
2746                         if (str_data != NULL) {
2747                                 _media->video_meta->album = strdup(str_data);
2748                                 media_content_retvm_if(_media->video_meta->album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2749                         }
2750
2751                         SAFE_FREE(_media->audio_meta->album);
2752                         if (str_data != NULL) {
2753                                 _media->audio_meta->album = strdup(str_data);
2754                                 media_content_retvm_if(_media->audio_meta->album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2755                         }
2756                 }
2757                 break;
2758         case MEDIA_INFO_ARTIST:
2759                 if (STRING_VALID(_media->media_id)) {
2760                         if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
2761                                 SAFE_FREE(_media->video_meta->artist);
2762                                 if (str_data != NULL) {
2763                                         _media->video_meta->artist = strdup(str_data);
2764                                         media_content_retvm_if(_media->video_meta->artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2765                                 }
2766                         } else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) {
2767                                 SAFE_FREE(_media->audio_meta->artist);
2768                                 if (str_data != NULL) {
2769                                         _media->audio_meta->artist = strdup(str_data);
2770                                         media_content_retvm_if(_media->audio_meta->artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2771                                 }
2772                         }
2773                 } else {
2774                         SAFE_FREE(_media->video_meta->artist);
2775                         if (str_data != NULL) {
2776                                 _media->video_meta->artist = strdup(str_data);
2777                                 media_content_retvm_if(_media->video_meta->artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2778                         }
2779
2780                         SAFE_FREE(_media->audio_meta->artist);
2781                         if (str_data != NULL) {
2782                                 _media->audio_meta->artist = strdup(str_data);
2783                                 media_content_retvm_if(_media->audio_meta->artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2784                         }
2785                 }
2786                 break;
2787         case MEDIA_INFO_GENRE:
2788                 if (STRING_VALID(_media->media_id)) {
2789                         if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
2790                                 SAFE_FREE(_media->video_meta->genre);
2791                                 if (str_data != NULL) {
2792                                         _media->video_meta->genre = strdup(str_data);
2793                                         media_content_retvm_if(_media->video_meta->genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2794                                 }
2795                         } else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) {
2796                                 SAFE_FREE(_media->audio_meta->genre);
2797                                 if (str_data != NULL) {
2798                                         _media->audio_meta->genre = strdup(str_data);
2799                                         media_content_retvm_if(_media->audio_meta->genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2800                                 }
2801                         }
2802                 } else {
2803                         SAFE_FREE(_media->video_meta->genre);
2804                         if (str_data != NULL) {
2805                                 _media->video_meta->genre = strdup(str_data);
2806                                 media_content_retvm_if(_media->video_meta->genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2807                         }
2808
2809                         SAFE_FREE(_media->audio_meta->genre);
2810                         if (str_data != NULL) {
2811                                 _media->audio_meta->genre = strdup(str_data);
2812                                 media_content_retvm_if(_media->audio_meta->genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2813                         }
2814                 }
2815                 break;
2816         case MEDIA_INFO_RECORDED_DATE:
2817                 if (STRING_VALID(_media->media_id)) {
2818                         if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
2819                                 SAFE_FREE(_media->video_meta->recorded_date);
2820                                 if (str_data != NULL) {
2821                                         _media->video_meta->recorded_date = strdup(str_data);
2822                                         media_content_retvm_if(_media->video_meta->recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2823                                 }
2824                         } else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) {
2825                                 SAFE_FREE(_media->audio_meta->recorded_date);
2826                                 if (str_data != NULL) {
2827                                         _media->audio_meta->recorded_date = strdup(str_data);
2828                                         media_content_retvm_if(_media->audio_meta->recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2829                                 }
2830                         }
2831                 } else {
2832                         SAFE_FREE(_media->video_meta->recorded_date);
2833                         if (str_data != NULL) {
2834                                 _media->video_meta->recorded_date = strdup(str_data);
2835                                 media_content_retvm_if(_media->video_meta->recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2836                         }
2837
2838                         SAFE_FREE(_media->audio_meta->recorded_date);
2839                         if (str_data != NULL) {
2840                                 _media->audio_meta->recorded_date = strdup(str_data);
2841                                 media_content_retvm_if(_media->audio_meta->recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2842                         }
2843                 }
2844                 break;
2845         default:
2846                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2847                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2848         }
2849
2850         return MEDIA_CONTENT_ERROR_NONE;
2851 }
2852
2853 static int __media_info_destroy(media_info_h media)
2854 {
2855         int ret = MEDIA_CONTENT_ERROR_NONE;
2856         media_info_s *_media = (media_info_s*)media;
2857
2858         if (_media) {
2859                 SAFE_FREE(_media->media_id);
2860                 SAFE_FREE(_media->file_path);
2861                 SAFE_FREE(_media->display_name);
2862                 SAFE_FREE(_media->mime_type);
2863                 SAFE_FREE(_media->thumbnail_path);
2864                 SAFE_FREE(_media->description);
2865                 SAFE_FREE(_media->author);
2866                 SAFE_FREE(_media->provider);
2867                 SAFE_FREE(_media->content_name);
2868                 SAFE_FREE(_media->category);
2869                 SAFE_FREE(_media->location_tag);
2870                 SAFE_FREE(_media->age_rating);
2871                 SAFE_FREE(_media->keyword);
2872                 SAFE_FREE(_media->title);
2873                 SAFE_FREE(_media->weather);
2874                 SAFE_FREE(_media->storage_uuid);
2875
2876                 if (_media->image_meta) {
2877                         SAFE_FREE(_media->image_meta->media_id);
2878                         SAFE_FREE(_media->image_meta->date_taken);
2879                         SAFE_FREE(_media->image_meta->burst_id);
2880                         SAFE_FREE(_media->image_meta->exposure_time);
2881                         SAFE_FREE(_media->image_meta->model);
2882                         SAFE_FREE(_media->image_meta->title);
2883                         SAFE_FREE(_media->image_meta->weather);
2884
2885                         SAFE_FREE(_media->image_meta);
2886                 }
2887
2888                 if (_media->video_meta) {
2889                         SAFE_FREE(_media->video_meta->media_id);
2890                         SAFE_FREE(_media->video_meta->title);
2891                         SAFE_FREE(_media->video_meta->album);
2892                         SAFE_FREE(_media->video_meta->artist);
2893                         SAFE_FREE(_media->video_meta->album_artist);
2894                         SAFE_FREE(_media->video_meta->genre);
2895                         SAFE_FREE(_media->video_meta->composer);
2896                         SAFE_FREE(_media->video_meta->year);
2897                         SAFE_FREE(_media->video_meta->recorded_date);
2898                         SAFE_FREE(_media->video_meta->copyright);
2899                         SAFE_FREE(_media->video_meta->track_num);
2900
2901                         SAFE_FREE(_media->video_meta);
2902                 }
2903
2904                 if (_media->audio_meta) {
2905                         SAFE_FREE(_media->audio_meta->media_id);
2906                         SAFE_FREE(_media->audio_meta->title);
2907                         SAFE_FREE(_media->audio_meta->album);
2908                         SAFE_FREE(_media->audio_meta->artist);
2909                         SAFE_FREE(_media->audio_meta->album_artist);
2910                         SAFE_FREE(_media->audio_meta->genre);
2911                         SAFE_FREE(_media->audio_meta->composer);
2912                         SAFE_FREE(_media->audio_meta->year);
2913                         SAFE_FREE(_media->audio_meta->recorded_date);
2914                         SAFE_FREE(_media->audio_meta->copyright);
2915                         SAFE_FREE(_media->audio_meta->track_num);
2916
2917                         SAFE_FREE(_media->audio_meta);
2918                 }
2919
2920                 ret = MEDIA_CONTENT_ERROR_NONE;
2921         } else {
2922                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2923                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2924         }
2925
2926         return ret;
2927 }
2928
2929 int media_info_insert_to_db_with_data(media_info_h media)
2930 {
2931         int ret = MEDIA_CONTENT_ERROR_NONE;
2932
2933         media_info_s *_media = (media_info_s*)media;
2934
2935         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
2936         media_content_retvm_if(!STRING_VALID(_media->file_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid file_path");
2937         media_content_retvm_if(!STRING_VALID(_media->storage_uuid), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid storage_uuid");
2938         media_content_retvm_if(_media->storage_type < 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid storage_type [%d]", _media->storage_type);
2939
2940         /* Cloud Item should be filled whole info*/
2941         if (_media->storage_type == MEDIA_CONTENT_STORAGE_CLOUD) {
2942                 media_content_retvm_if(!STRING_VALID(_media->mime_type), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid mime_type");
2943                 media_content_retvm_if(!STRING_VALID(_media->title), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid title");
2944                 media_content_retvm_if(_media->size <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid size [%d]", _media->size);
2945                 media_content_retvm_if(_media->modified_time <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid modified_time [%d]", _media->modified_time);
2946
2947                 if ((_media->media_type < MEDIA_CONTENT_TYPE_IMAGE) || (_media->media_type > MEDIA_CONTENT_TYPE_OTHERS)) {
2948                         media_content_error("invalid media type [%d]", _media->media_type);
2949                         return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2950                 }
2951         }
2952
2953         media_content_sec_debug("storage[%d], path[%s], media_type[%d]", _media->storage_type, _media->file_path, _media->media_type);
2954
2955         media_svc_content_info_s *svc_content_info = NULL;
2956
2957         ret = __media_info_map_data_usr_to_svc(_media, &svc_content_info, _media->storage_type);
2958         media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "__media_info_map_data_usr_to_svc fail");
2959
2960         ret = media_svc_insert_item_immediately_with_data(_content_get_db_handle(), svc_content_info, tzplatform_getuid(TZ_USER_NAME));
2961         if (ret != MS_MEDIA_ERR_NONE) {
2962                 media_content_sec_error("media_svc_insert_item_immediately_with_data failed : %d (%s)", ret, _media->file_path);
2963                 media_svc_destroy_content_info(svc_content_info);
2964                 SAFE_FREE(svc_content_info);
2965                 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2966         }
2967         /*free the svc_content_info*/
2968         media_svc_destroy_content_info(svc_content_info);
2969         SAFE_FREE(svc_content_info);
2970
2971         /*Fill out the handle*/
2972         char *media_file_path = g_strdup(_media->file_path);
2973         char *media_string_uuid = g_strdup(_media->storage_uuid);
2974
2975         __media_info_destroy(media);
2976         ret = _media_info_get_media_info_from_db(media_file_path, media_string_uuid, media);
2977         if (ret != MEDIA_CONTENT_ERROR_NONE)
2978                 media_content_error("_media_info_get_media_info_from_db fail", ret);
2979
2980         SAFE_FREE(media_file_path);
2981         SAFE_FREE(media_string_uuid);
2982
2983         return ret;
2984 }
2985
2986 int media_info_create(const char *path, media_info_h *media)
2987 {
2988         int ret = MEDIA_CONTENT_ERROR_NONE;
2989         char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
2990         media_svc_storage_type_e storage_type = 0;
2991         bool ignore_file = FALSE;
2992
2993         media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
2994         media_content_retvm_if(media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
2995
2996         ret = _media_util_check_ignore_file(path, &ignore_file);
2997         media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
2998
2999         memset(storage_id, 0x00, sizeof(storage_id));
3000
3001         if (STRING_VALID(MEDIA_ROOT_PATH_CLOUD) && (strstr(path, MEDIA_ROOT_PATH_CLOUD) == NULL)) {
3002                 bool ignore_dir = FALSE;
3003                 char *folder_path = NULL;
3004
3005                 ret = _media_util_check_file_exist(path);
3006                 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
3007
3008                 folder_path = g_path_get_dirname(path);
3009                 ret = _media_util_check_ignore_dir(folder_path, &ignore_dir);
3010                 SAFE_FREE(folder_path);
3011                 media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
3012
3013                 ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id);
3014                 if (ret != MS_MEDIA_ERR_NONE) {
3015                         media_content_error("media_svc_get_storage_id failed : %d", ret);
3016                         return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
3017                 }
3018
3019                 ret = media_svc_get_storage_type(path, &storage_type, tzplatform_getuid(TZ_USER_NAME));
3020                 if (ret != MS_MEDIA_ERR_NONE) {
3021                         media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
3022                         return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
3023                 }
3024         }
3025
3026         media_info_s *_media = (media_info_s*)calloc(1, sizeof(media_info_s));
3027         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3028
3029         _media->audio_meta = (audio_meta_s *)calloc(1, sizeof(audio_meta_s));
3030         if (_media->audio_meta == NULL) {
3031                 SAFE_FREE(_media);
3032                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
3033                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
3034         }
3035
3036         _media->video_meta = (video_meta_s *)calloc(1, sizeof(video_meta_s));
3037         if (_media->video_meta == NULL) {
3038                 SAFE_FREE(_media->audio_meta);
3039                 SAFE_FREE(_media);
3040                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
3041                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
3042         }
3043
3044         _media->image_meta = (image_meta_s *)calloc(1, sizeof(image_meta_s));
3045         if (_media->image_meta == NULL) {
3046                 SAFE_FREE(_media->audio_meta);
3047                 SAFE_FREE(_media->video_meta);
3048                 SAFE_FREE(_media);
3049                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
3050                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
3051         }
3052
3053         _media->file_path = g_strdup(path);
3054         _media->storage_type = -1;
3055         _media->media_type = 0;
3056         _media->modified_time = 0;
3057         _media->size = 0;
3058         _media->request_id = 0;
3059         _media->longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
3060         _media->latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
3061         _media->altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
3062
3063         if (STRING_VALID(storage_id)) {
3064                 _media->storage_uuid = g_strdup(storage_id);
3065                 _media->storage_type = storage_type;
3066         }
3067
3068         *media = (media_info_h)_media;
3069
3070         return ret;
3071 }
3072
3073 int media_info_set_mime_type(media_info_h media, const char *mime_type)
3074 {
3075         return __media_info_set_str_data(media, MEDIA_INFO_MIME_TYPE, mime_type);
3076 }
3077
3078 int media_info_set_title(media_info_h media, const char *title)
3079 {
3080         return __media_info_set_str_data(media, MEDIA_INFO_TITLE, title);
3081 }
3082
3083 int media_info_set_album(media_info_h media, const char *album)
3084 {
3085         return __media_info_set_str_data(media, MEDIA_INFO_ALBUM, album);
3086 }
3087
3088 int media_info_set_artist(media_info_h media, const char *artist)
3089 {
3090         return __media_info_set_str_data(media, MEDIA_INFO_ARTIST, artist);
3091 }
3092
3093 int media_info_set_genre(media_info_h media, const char *genre)
3094 {
3095         return __media_info_set_str_data(media, MEDIA_INFO_GENRE, genre);
3096 }
3097
3098 int media_info_set_recorded_date(media_info_h media, const char *recorded_date)
3099 {
3100         return __media_info_set_str_data(media, MEDIA_INFO_RECORDED_DATE, recorded_date);
3101 }
3102
3103 int media_info_set_thumbnail_path(media_info_h media, const char *thumbnail_path)
3104 {
3105         return __media_info_set_str_data(media, MEDIA_INFO_THUMBNAIL_PATH, thumbnail_path);
3106 }
3107
3108 int media_info_set_storage_id(media_info_h media, const char *storage_id)
3109 {
3110         return __media_info_set_str_data(media, MEDIA_INFO_STORAGE_UUID, storage_id);
3111 }
3112
3113 int media_info_set_size(media_info_h media, unsigned long long size)
3114 {
3115         media_info_s *_media = (media_info_s*)media;
3116
3117         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3118
3119         _media->size = size;
3120
3121         return MEDIA_CONTENT_ERROR_NONE;
3122 }
3123
3124 int media_info_set_modified_time(media_info_h media, time_t modified_time)
3125 {
3126         media_info_s *_media = (media_info_s*)media;
3127
3128         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3129
3130         _media->modified_time = modified_time;
3131
3132         return MEDIA_CONTENT_ERROR_NONE;
3133 }
3134
3135 int media_info_set_media_type(media_info_h media, media_content_type_e type)
3136 {
3137         media_info_s *_media = (media_info_s*)media;
3138
3139         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3140
3141         _media->media_type = type;
3142
3143         return MEDIA_CONTENT_ERROR_NONE;
3144 }
3145
3146 int media_info_set_duration(media_info_h media, int duration)
3147 {
3148         media_info_s *_media = (media_info_s*)media;
3149
3150         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3151
3152         if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3153                 _media->video_meta->duration = duration;
3154         else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND))
3155                 _media->audio_meta->duration = duration;
3156         else {
3157                 media_content_error("Invalid media type");
3158                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3159         }
3160
3161         return MEDIA_CONTENT_ERROR_NONE;
3162 }
3163
3164 int media_info_set_width(media_info_h media, int width)
3165 {
3166         media_info_s *_media = (media_info_s*)media;
3167
3168         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3169
3170         if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3171                 _media->video_meta->width = width;
3172         else if (_media->media_type == MEDIA_CONTENT_TYPE_IMAGE)
3173                 _media->image_meta->width = width;
3174         else {
3175                 media_content_error("Invalid media type");
3176                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3177         }
3178
3179         return MEDIA_CONTENT_ERROR_NONE;
3180 }
3181
3182 int media_info_set_height(media_info_h media, int height)
3183 {
3184         media_info_s *_media = (media_info_s*)media;
3185
3186         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3187
3188         if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3189                 _media->video_meta->height = height;
3190         else if (_media->media_type == MEDIA_CONTENT_TYPE_IMAGE)
3191                 _media->image_meta->height = height;
3192         else {
3193                 media_content_error("Invalid media type");
3194                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3195         }
3196
3197         return MEDIA_CONTENT_ERROR_NONE;
3198 }
3199
3200 int media_info_set_storage_type(media_info_h media, media_content_storage_e storage_type)
3201 {
3202         media_info_s *_media = (media_info_s*)media;
3203
3204         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3205
3206         _media->storage_type = storage_type;
3207
3208         return MEDIA_CONTENT_ERROR_NONE;
3209 }