Add g_free macro
[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                         ret = MEDIA_CONTENT_ERROR_DB_FAILED;
1816                 }
1817                 ret = MEDIA_CONTENT_ERROR_NONE;
1818         } else {
1819                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1820                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1821         }
1822
1823         return ret;
1824 }
1825
1826 int media_info_is_drm(media_info_h media, bool *is_drm)
1827 {
1828         int ret = MEDIA_CONTENT_ERROR_NONE;
1829         media_info_s *_media = (media_info_s*)media;
1830
1831         if (_media) {
1832                 *is_drm = _media->is_drm;
1833                 ret = MEDIA_CONTENT_ERROR_NONE;
1834         } else {
1835                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1836                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1837         }
1838
1839         return ret;
1840 }
1841
1842 int media_info_is_360_content(media_info_h media, bool *is_360)
1843 {
1844         int ret = MEDIA_CONTENT_ERROR_NONE;
1845         media_info_s *_media = (media_info_s*)media;
1846
1847         if (_media) {
1848                 *is_360 = _media->is_360;
1849                 ret = MEDIA_CONTENT_ERROR_NONE;
1850         } else {
1851                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1852                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1853         }
1854
1855         return ret;
1856 }
1857
1858 int media_info_get_storage_type(media_info_h media, media_content_storage_e *storage_type)
1859 {
1860         int ret = MEDIA_CONTENT_ERROR_NONE;
1861         media_info_s *_media = (media_info_s*)media;
1862
1863         if (_media && storage_type) {
1864                 *storage_type = _media->storage_type;
1865                 ret = MEDIA_CONTENT_ERROR_NONE;
1866         } else {
1867                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1868                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1869         }
1870
1871         return ret;
1872 }
1873
1874 int media_info_get_played_count(media_info_h media, int *played_count)
1875 {
1876         int ret = MEDIA_CONTENT_ERROR_NONE;
1877         media_info_s *_media = (media_info_s*)media;
1878
1879         if (_media) {
1880                 *played_count = _media->played_count;
1881                 ret = MEDIA_CONTENT_ERROR_NONE;
1882         } else {
1883                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1884                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1885         }
1886
1887         return ret;
1888 }
1889
1890 int media_info_get_played_time(media_info_h media, time_t* played_time)
1891 {
1892         int ret = MEDIA_CONTENT_ERROR_NONE;
1893         media_info_s *_media = (media_info_s*)media;
1894
1895         if (_media) {
1896                 *played_time = _media->played_time;
1897                 ret = MEDIA_CONTENT_ERROR_NONE;
1898         } else {
1899                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1900                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1901         }
1902
1903         return ret;
1904 }
1905
1906 int media_info_increase_played_count(media_info_h media)
1907 {
1908         int ret = MEDIA_CONTENT_ERROR_NONE;
1909
1910         media_info_s *_media = (media_info_s*)media;
1911
1912         if (_media) {
1913                 _media->played_count += 1;
1914         } else {
1915                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1916                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1917         }
1918
1919         return ret;
1920 }
1921
1922 int media_info_set_played_time(media_info_h media)
1923 {
1924         int ret = MEDIA_CONTENT_ERROR_NONE;
1925         time_t current_time;
1926
1927         media_info_s *_media = (media_info_s*)media;
1928
1929         if (_media != NULL) {
1930                 time(&current_time);
1931                 _media->played_time = current_time;
1932         } else {
1933                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1934                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1935         }
1936
1937         return ret;
1938 }
1939
1940 int media_info_get_media_from_db(const char *media_id, media_info_h *media)
1941 {
1942         int ret = MEDIA_CONTENT_ERROR_NONE;
1943         char select_query[DEFAULT_QUERY_SIZE];
1944         char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
1945         sqlite3_stmt *stmt = NULL;
1946
1947         if (!STRING_VALID(media_id) || (media == NULL)) {
1948                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1949                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1950         }
1951
1952         memset(select_query, 0x00, sizeof(select_query));
1953         memset(storage_id, 0x00, sizeof(storage_id));
1954
1955         ret = _media_db_get_storage_id_by_media_id(media_id, storage_id);
1956         media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1957
1958         snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_MEDIA, storage_id, media_id);
1959
1960         ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
1961         media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1962
1963         media_info_s *_media = NULL;
1964
1965         while (sqlite3_step(stmt) == SQLITE_ROW) {
1966                 if (_media)
1967                         media_info_destroy((media_info_h)_media);
1968
1969                 _media = (media_info_s*)calloc(1, sizeof(media_info_s));
1970
1971                 if (_media == NULL) {
1972                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1973                         SQLITE3_FINALIZE(stmt);
1974                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1975                 }
1976
1977                 _media_info_item_get_detail(stmt, (media_info_h)_media);
1978
1979                 *media = (media_info_h)_media;
1980         }
1981
1982         SQLITE3_FINALIZE(stmt);
1983
1984         return ret;
1985 }
1986
1987 int media_info_set_display_name(media_info_h media, const char *display_name)
1988 {
1989         int ret = MEDIA_CONTENT_ERROR_NONE;
1990         media_info_s *_media = (media_info_s*)media;
1991
1992         if (_media != NULL && STRING_VALID(display_name)) {
1993                 SAFE_FREE(_media->display_name);
1994
1995                 _media->display_name = strdup(display_name);
1996                 media_content_retvm_if(_media->display_name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1997         } else {
1998                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1999                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2000         }
2001
2002         return ret;
2003 }
2004
2005 int media_info_set_description(media_info_h media, const char *description)
2006 {
2007         int ret = MEDIA_CONTENT_ERROR_NONE;
2008         media_info_s *_media = (media_info_s*)media;
2009
2010         if (_media != NULL) {
2011                 SAFE_FREE(_media->description);
2012
2013                 if (STRING_VALID(description)) {
2014                         _media->description = strdup(description);
2015                         media_content_retvm_if(_media->description == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2016                 } else {
2017                         _media->description = NULL;
2018                 }
2019         } else {
2020                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2021                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2022         }
2023
2024         return ret;
2025 }
2026
2027 int media_info_set_longitude(media_info_h media, double longitude)
2028 {
2029         int ret = MEDIA_CONTENT_ERROR_NONE;
2030         media_info_s *_media = (media_info_s*)media;
2031
2032         if (_media != NULL) {
2033                 _media->longitude = longitude;
2034         } else {
2035                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2036                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2037         }
2038
2039         return ret;
2040 }
2041
2042 int media_info_set_latitude(media_info_h media, double latitude)
2043 {
2044         int ret = MEDIA_CONTENT_ERROR_NONE;
2045         media_info_s *_media = (media_info_s*)media;
2046
2047         if (_media != NULL) {
2048                 _media->latitude = latitude;
2049         } else {
2050                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2051                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2052         }
2053
2054         return ret;
2055 }
2056
2057 int media_info_set_altitude(media_info_h media, double altitude)
2058 {
2059         int ret = MEDIA_CONTENT_ERROR_NONE;
2060         media_info_s *_media = (media_info_s*)media;
2061
2062         if (_media != NULL) {
2063                 _media->altitude = altitude;
2064         } else {
2065                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2066                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2067         }
2068
2069         return ret;
2070 }
2071
2072 int media_info_set_weather(media_info_h media, const char *weather)
2073 {
2074         int ret = MEDIA_CONTENT_ERROR_NONE;
2075         media_info_s *_media = (media_info_s*)media;
2076
2077         if (_media != NULL) {
2078                 SAFE_FREE(_media->weather);
2079
2080                 if (STRING_VALID(weather)) {
2081                         _media->weather = strdup(weather);
2082                         media_content_retvm_if(_media->weather == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2083                 } else {
2084                         _media->weather = NULL;
2085                 }
2086         } else {
2087                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2088                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2089         }
2090
2091         return ret;
2092 }
2093
2094 int media_info_set_rating(media_info_h media, int rating)
2095 {
2096         int ret = MEDIA_CONTENT_ERROR_NONE;
2097         media_info_s *_media = (media_info_s*)media;
2098
2099         if (_media != NULL) {
2100                 _media->rating = rating;
2101         } else {
2102                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2103                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2104         }
2105
2106         return ret;
2107 }
2108
2109 int media_info_set_added_time(media_info_h media, time_t added_time)
2110 {
2111         int ret = MEDIA_CONTENT_ERROR_NONE;
2112
2113         media_info_s *_media = (media_info_s*)media;
2114
2115         if ((_media != NULL) && (added_time >= 0)) {
2116                 _media->added_time = added_time;
2117         } else {
2118                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2119                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2120         }
2121
2122         return ret;
2123 }
2124
2125 int media_info_set_favorite(media_info_h media, bool favorite)
2126 {
2127         int ret = MEDIA_CONTENT_ERROR_NONE;
2128         media_info_s *_media = (media_info_s*)media;
2129
2130         if (_media != NULL) {
2131                 if (favorite == TRUE)
2132                         time(&_media->favourite);
2133                 else
2134                         _media->favourite = 0;
2135         } else {
2136                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2137                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2138         }
2139
2140         return ret;
2141 }
2142
2143 int media_info_set_author(media_info_h media, const char *author)
2144 {
2145         int ret = MEDIA_CONTENT_ERROR_NONE;
2146         media_info_s *_media = (media_info_s*)media;
2147
2148         if (_media != NULL) {
2149                 if (STRING_VALID(author)) {
2150                         _media->author = strdup(author);
2151                         media_content_retvm_if(_media->author == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2152                 } else {
2153                         _media->author = NULL;
2154                 }
2155         } else {
2156                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2157                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2158         }
2159
2160         return ret;
2161 }
2162
2163 int media_info_set_provider(media_info_h media, const char *provider)
2164 {
2165         int ret = MEDIA_CONTENT_ERROR_NONE;
2166         media_info_s *_media = (media_info_s*)media;
2167
2168         if (_media != NULL) {
2169                 SAFE_FREE(_media->provider);
2170
2171                 if (STRING_VALID(provider)) {
2172                         _media->provider = strdup(provider);
2173                         media_content_retvm_if(_media->provider == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2174                 } else {
2175                         _media->provider = NULL;
2176                 }
2177         } else {
2178                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2179                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2180         }
2181
2182         return ret;
2183 }
2184
2185 int media_info_set_content_name(media_info_h media, const char *content_name)
2186 {
2187         int ret = MEDIA_CONTENT_ERROR_NONE;
2188         media_info_s *_media = (media_info_s*)media;
2189
2190         if (_media != NULL) {
2191                 SAFE_FREE(_media->content_name);
2192
2193                 if (STRING_VALID(content_name)) {
2194                         _media->content_name = strdup(content_name);
2195                         media_content_retvm_if(_media->content_name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2196                 } else {
2197                         _media->content_name = NULL;
2198                 }
2199         } else {
2200                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2201                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2202         }
2203
2204         return ret;
2205 }
2206
2207 int media_info_set_category(media_info_h media, const char *category)
2208 {
2209         int ret = MEDIA_CONTENT_ERROR_NONE;
2210         media_info_s *_media = (media_info_s*)media;
2211
2212         if (_media != NULL) {
2213                 SAFE_FREE(_media->category);
2214
2215                 if (STRING_VALID(category)) {
2216                         _media->category = strdup(category);
2217                         media_content_retvm_if(_media->category == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2218                 } else {
2219                         _media->category = NULL;
2220                 }
2221         } else {
2222                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2223                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2224         }
2225
2226         return ret;
2227 }
2228
2229 int media_info_set_location_tag(media_info_h media, const char *location_tag)
2230 {
2231         int ret = MEDIA_CONTENT_ERROR_NONE;
2232         media_info_s *_media = (media_info_s*)media;
2233
2234         if (_media != NULL) {
2235                 SAFE_FREE(_media->location_tag);
2236
2237                 if (STRING_VALID(location_tag)) {
2238                         _media->location_tag = strdup(location_tag);
2239                         media_content_retvm_if(_media->location_tag == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2240                 } else {
2241                         _media->location_tag = NULL;
2242                 }
2243         } else {
2244                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2245                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2246         }
2247
2248         return ret;
2249 }
2250
2251 int media_info_set_age_rating(media_info_h media, const char *age_rating)
2252 {
2253         int ret = MEDIA_CONTENT_ERROR_NONE;
2254         media_info_s *_media = (media_info_s*)media;
2255
2256         if (_media != NULL) {
2257                 SAFE_FREE(_media->age_rating);
2258
2259                 if (STRING_VALID(age_rating)) {
2260                         _media->age_rating = strdup(age_rating);
2261                         media_content_retvm_if(_media->age_rating == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2262                 } else {
2263                         _media->age_rating = NULL;
2264                 }
2265         } else {
2266                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2267                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2268         }
2269
2270         return ret;
2271 }
2272
2273 int media_info_set_keyword(media_info_h media, const char *keyword)
2274 {
2275         int ret = MEDIA_CONTENT_ERROR_NONE;
2276         media_info_s *_media = (media_info_s*)media;
2277
2278         if (_media != NULL) {
2279                 SAFE_FREE(_media->keyword);
2280
2281                 if (STRING_VALID(keyword)) {
2282                         _media->keyword = strdup(keyword);
2283                         media_content_retvm_if(_media->keyword == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2284                 } else {
2285                         _media->keyword = NULL;
2286                 }
2287         } else {
2288                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2289                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2290         }
2291
2292         return ret;
2293 }
2294
2295 int media_info_update_to_db(media_info_h media)
2296 {
2297         int ret = MEDIA_CONTENT_ERROR_NONE;
2298         media_info_s *_media = (media_info_s*)media;
2299         char *set_sql = NULL;
2300         char *sql = NULL;
2301
2302         if (_media != NULL && STRING_VALID(_media->media_id)) {
2303                 /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
2304                 /* This code will be removed when sqlite3_mprintf works clearly */
2305                 char *test_sql = sqlite3_mprintf("%f, %f, %f", _media->longitude, _media->latitude, _media->altitude);
2306                 SQLITE3_SAFE_FREE(test_sql);
2307
2308                 /*Update Pinyin If Support Pinyin*/
2309                 char *file_name_pinyin = NULL;
2310                 char *description_pinyin = NULL;
2311                 char *author_pinyin = NULL;
2312                 char *provider_pinyin = NULL;
2313                 char *content_name_pinyin = NULL;
2314                 char *category_pinyin = NULL;
2315                 char *location_tag_pinyin = NULL;
2316                 char *age_rating_pinyin = NULL;
2317                 char *keyword_pinyin = NULL;
2318                 bool pinyin_support = FALSE;
2319
2320                 /*Update Pinyin If Support Pinyin*/
2321                 media_svc_check_pinyin_support(&pinyin_support);
2322                 if (pinyin_support) {
2323                         if (STRING_VALID(_media->display_name))
2324                                 media_svc_get_pinyin(_media->display_name, &file_name_pinyin);
2325                         if (STRING_VALID(_media->description))
2326                                 media_svc_get_pinyin(_media->description, &description_pinyin);
2327                         if (STRING_VALID(_media->author))
2328                                 media_svc_get_pinyin(_media->author, &author_pinyin);
2329                         if (STRING_VALID(_media->provider))
2330                                 media_svc_get_pinyin(_media->provider, &provider_pinyin);
2331                         if (STRING_VALID(_media->content_name))
2332                                 media_svc_get_pinyin(_media->content_name, &content_name_pinyin);
2333                         if (STRING_VALID(_media->category))
2334                                 media_svc_get_pinyin(_media->category, &category_pinyin);
2335                         if (STRING_VALID(_media->location_tag))
2336                                 media_svc_get_pinyin(_media->location_tag, &location_tag_pinyin);
2337                         if (STRING_VALID(_media->age_rating))
2338                                 media_svc_get_pinyin(_media->age_rating, &age_rating_pinyin);
2339                         if (STRING_VALID(_media->keyword))
2340                                 media_svc_get_pinyin(_media->keyword, &keyword_pinyin);
2341                 }
2342
2343                 char *album = NULL;
2344                 char *artist = NULL;
2345                 char *genre = NULL;
2346                 char *recorded_date = NULL;
2347
2348                 if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
2349                         if (_media->video_meta->album != NULL)
2350                                 album = strdup(_media->video_meta->album);
2351                         if (_media->video_meta->artist != NULL)
2352                                 artist = strdup(_media->video_meta->artist);
2353                         if (_media->video_meta->genre != NULL)
2354                                 genre = strdup(_media->video_meta->genre);
2355                         if (_media->video_meta->recorded_date != NULL)
2356                                 recorded_date = strdup(_media->video_meta->recorded_date);
2357                 } else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) {
2358                         if (_media->audio_meta->album != NULL)
2359                                 album = strdup(_media->audio_meta->album);
2360                         if (_media->audio_meta->artist != NULL)
2361                                 artist = strdup(_media->audio_meta->artist);
2362                         if (_media->audio_meta->genre != NULL)
2363                                 genre = strdup(_media->audio_meta->genre);
2364                         if (_media->audio_meta->recorded_date != NULL)
2365                                 recorded_date = strdup(_media->audio_meta->recorded_date);
2366                 }
2367
2368                 set_sql = sqlite3_mprintf("file_name=%Q, added_time=%d, description=%Q, longitude=%f, latitude=%f, altitude=%f, \
2369                         played_count=%d, last_played_time=%d, last_played_position=%d, \
2370                         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, \
2371                         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, \
2372                         album=%Q, artist=%Q, genre=%Q, recorded_date=%Q",
2373                         _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,
2374                         _media->author, _media->provider, _media->content_name, _media->category, _media->location_tag, _media->age_rating, _media->keyword, _media->weather, _media->sync_status,
2375                         file_name_pinyin, description_pinyin, author_pinyin, provider_pinyin, content_name_pinyin, category_pinyin, location_tag_pinyin, age_rating_pinyin, keyword_pinyin, _media->title,
2376                         album, artist, genre, recorded_date);
2377
2378                 sql = sqlite3_mprintf("UPDATE %Q SET %s WHERE media_uuid=%Q", _media->storage_uuid, set_sql, _media->media_id);
2379
2380                 ret = _content_query_sql(sql);
2381                 SQLITE3_SAFE_FREE(set_sql);
2382                 SQLITE3_SAFE_FREE(sql);
2383
2384                 SAFE_FREE(description_pinyin);
2385                 SAFE_FREE(author_pinyin);
2386                 SAFE_FREE(provider_pinyin);
2387                 SAFE_FREE(content_name_pinyin);
2388                 SAFE_FREE(category_pinyin);
2389                 SAFE_FREE(location_tag_pinyin);
2390                 SAFE_FREE(age_rating_pinyin);
2391                 SAFE_FREE(keyword_pinyin);
2392
2393                 SAFE_FREE(album);
2394                 SAFE_FREE(artist);
2395                 SAFE_FREE(genre);
2396                 SAFE_FREE(recorded_date);
2397
2398                 if (_media->storage_type == MEDIA_CONTENT_STORAGE_CLOUD) {
2399                         set_sql = NULL;
2400                         sql = NULL;
2401
2402                         if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
2403                                 set_sql = sqlite3_mprintf("title=%Q, album=%Q, artist=%Q, genre=%Q, duration=%d, width=%d, height=%d", \
2404                                 _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);
2405                         } else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) {
2406                                 set_sql = sqlite3_mprintf("title=%Q, album=%Q, artist=%Q, genre=%Q, duration=%d", \
2407                                 _media->title, _media->audio_meta->album, _media->audio_meta->artist, _media->audio_meta->genre, _media->audio_meta->duration);
2408                         } else if (_media->media_type == MEDIA_CONTENT_TYPE_IMAGE) {
2409                                 set_sql = sqlite3_mprintf("title=%Q, width=%d, height=%d", _media->title, _media->image_meta->width, _media->image_meta->height);
2410                         } else {
2411                                 set_sql = sqlite3_mprintf("title=%Q", _media->title);
2412                         }
2413
2414                         sql = sqlite3_mprintf("UPDATE %Q SET %s WHERE media_uuid=%Q", _media->storage_uuid, set_sql, _media->media_id);
2415
2416                         ret = _content_query_sql(sql);
2417
2418                         SQLITE3_SAFE_FREE(set_sql);
2419                         SQLITE3_SAFE_FREE(sql);
2420                 }
2421
2422                 if (ret == MEDIA_CONTENT_ERROR_NONE) {
2423                         /* Send notification for this update */
2424                         media_content_debug("Update is successfull. Send notification for this");
2425                         if (_media->file_path && _media->mime_type)
2426                                 media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, _media->file_path, _media->media_type, _media->media_id, _media->mime_type);
2427                         else
2428                                 media_content_error("Can't Send Noti : path or mime type is NULL");
2429                 }
2430         } else {
2431                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2432                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2433         }
2434
2435         return ret;
2436 }
2437
2438 int media_info_refresh_metadata_to_db(const char *media_id)
2439 {
2440         int ret = MEDIA_CONTENT_ERROR_NONE;
2441         media_info_h media = NULL;
2442         char *file_path = NULL;
2443         media_content_storage_e storage_type = 0;
2444         char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
2445
2446         if (!STRING_VALID(media_id)) {
2447                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2448                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2449         }
2450
2451         ret = media_info_get_media_from_db(media_id, &media);
2452         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2453                 media_info_destroy(media);
2454                 return ret;
2455         }
2456
2457         ret = media_info_get_storage_type(media, &storage_type);
2458         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2459                 media_info_destroy(media);
2460                 return ret;
2461         }
2462
2463         if (storage_type == MEDIA_CONTENT_STORAGE_CLOUD) {
2464                 media_info_destroy(media);
2465                 media_content_error("Can't refresh cloud content!!");
2466                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2467         }
2468
2469         ret = media_info_get_file_path(media, &file_path);
2470         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2471                 media_info_destroy(media);
2472                 return ret;
2473         }
2474
2475         ret = _media_util_check_file_exist(file_path);
2476         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2477                 SAFE_FREE(file_path);
2478                 media_info_destroy(media);
2479                 return ret;
2480         }
2481
2482         memset(storage_id, 0x00, sizeof(storage_id));
2483         ret = media_svc_get_storage_id(_content_get_db_handle(), file_path, storage_id);
2484         if (ret != MS_MEDIA_ERR_NONE) {
2485                 media_content_error("media_svc_get_storage_id failed : %d", ret);
2486                 SAFE_FREE(file_path);
2487                 media_info_destroy(media);
2488                 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2489         }
2490
2491         ret = media_svc_refresh_item(_content_get_db_handle(), storage_id, storage_type, file_path, tzplatform_getuid(TZ_USER_NAME));
2492         if (ret != MS_MEDIA_ERR_NONE)
2493                 ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2494
2495         SAFE_FREE(file_path);
2496         media_info_destroy(media);
2497
2498         return ret;
2499 }
2500
2501 int media_info_move_to_db(media_info_h media, const char* dst_path)
2502 {
2503         int ret = MEDIA_CONTENT_ERROR_NONE;
2504         bool ignore_file = FALSE;
2505         bool ignore_dir = FALSE;
2506         char *folder_path = NULL;
2507         media_svc_storage_type_e src_storage_type = 0;
2508         media_svc_storage_type_e dst_storage_type = 0;
2509         char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
2510
2511         media_content_retvm_if(media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media");
2512         media_content_retvm_if(!STRING_VALID(dst_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid dst_path");
2513
2514         media_info_s *_media = (media_info_s*)media;
2515
2516         ret = _media_util_check_ignore_file(dst_path, &ignore_file);
2517         media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
2518
2519         ret = _media_util_check_file_exist(dst_path);
2520         media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
2521
2522         folder_path = g_path_get_dirname(dst_path);
2523         ret = _media_util_check_ignore_dir(folder_path, &ignore_dir);
2524         SAFE_FREE(folder_path);
2525
2526         media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
2527
2528         ret = media_svc_get_storage_type(_media->file_path, &src_storage_type, tzplatform_getuid(TZ_USER_NAME));
2529         if (ret != MS_MEDIA_ERR_NONE) {
2530                 media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
2531                 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2532         }
2533
2534         ret = media_svc_get_storage_type(dst_path, &dst_storage_type, tzplatform_getuid(TZ_USER_NAME));
2535         if (ret != MS_MEDIA_ERR_NONE) {
2536                 media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
2537                 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2538         }
2539
2540         memset(storage_id, 0x00, sizeof(storage_id));
2541         ret = media_svc_get_storage_id(_content_get_db_handle(), _media->file_path, storage_id);
2542         if (ret != MS_MEDIA_ERR_NONE) {
2543                 media_content_error("media_svc_get_storage_id failed : %d", ret);
2544                 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2545         }
2546
2547         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));
2548         return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2549 }
2550
2551 int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb callback, void *user_data)
2552 {
2553         int ret = MEDIA_CONTENT_ERROR_NONE;
2554         static unsigned int req_id = 0;
2555         media_info_s *_media = (media_info_s*)media;
2556
2557         if (_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path)) {
2558                 media_thumbnail_cb_s *_thumb_cb = (media_thumbnail_cb_s*)calloc(1, sizeof(media_thumbnail_cb_s));
2559                 media_content_retvm_if(_thumb_cb == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2560                 req_id++;
2561                 _media->request_id = req_id;
2562
2563                 _thumb_cb->handle = _media;
2564                 _thumb_cb->user_data = user_data;
2565                 _thumb_cb->thumbnail_completed_cb = callback;
2566
2567                 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));
2568                 ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret);
2569         } else {
2570                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2571                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2572         }
2573
2574         return ret;
2575 }
2576
2577 int media_info_cancel_thumbnail(media_info_h media)
2578 {
2579         int ret = MEDIA_CONTENT_ERROR_NONE;
2580         media_info_s *_media = (media_info_s*)media;
2581
2582         if (_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path) && _media->request_id > 0) {
2583                 ret = thumbnail_request_cancel_media(_media->request_id, _media->file_path);
2584                 ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret);
2585         } else {
2586                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2587                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2588         }
2589
2590         return ret;
2591 }
2592
2593 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)
2594 {
2595         media_content_retvm_if(media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle");
2596
2597         media_svc_content_info_s *svc_content_info = calloc(1, sizeof(media_svc_content_info_s));
2598         media_content_retvm_if(svc_content_info == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2599
2600         svc_content_info->path = g_strdup(media->file_path);
2601         svc_content_info->file_name = g_strdup(media->display_name);
2602         svc_content_info->media_type = media->media_type;
2603         svc_content_info->mime_type = g_strdup(media->mime_type);
2604         svc_content_info->size = media->size;
2605         svc_content_info->storage_type = storage_type;
2606         svc_content_info->storage_uuid = g_strdup(media->storage_uuid);
2607
2608         svc_content_info->added_time = media->added_time;
2609         svc_content_info->modified_time = media->modified_time;
2610         svc_content_info->thumbnail_path = g_strdup(media->thumbnail_path);
2611         svc_content_info->is_drm = media->is_drm;
2612         svc_content_info->last_played_time = media->played_time;
2613         svc_content_info->played_count = media->played_count;
2614         svc_content_info->favourate = media->favourite;
2615
2616         svc_content_info->media_meta.title = g_strdup(media->title);
2617         svc_content_info->media_meta.rating = media->rating;
2618         svc_content_info->media_meta.description = g_strdup(media->description);
2619         svc_content_info->media_meta.longitude = media->longitude;
2620         svc_content_info->media_meta.latitude = media->latitude;
2621         svc_content_info->media_meta.altitude = media->altitude;
2622         svc_content_info->media_meta.weather = g_strdup(media->weather);
2623         svc_content_info->media_meta.category = g_strdup(media->category);
2624         svc_content_info->media_meta.keyword = g_strdup(media->keyword);
2625         svc_content_info->media_meta.location_tag = g_strdup(media->location_tag);
2626         svc_content_info->media_meta.content_name = g_strdup(media->content_name);
2627         svc_content_info->media_meta.age_rating = g_strdup(media->age_rating);
2628         svc_content_info->media_meta.author = g_strdup(media->author);
2629         svc_content_info->media_meta.provider = g_strdup(media->provider);
2630
2631         svc_content_info->media_meta.album = g_strdup(media->audio_meta->album);
2632         svc_content_info->media_meta.artist = g_strdup(media->audio_meta->artist);
2633         svc_content_info->media_meta.genre = g_strdup(media->audio_meta->genre);
2634         svc_content_info->media_meta.recorded_date = g_strdup(media->audio_meta->recorded_date);
2635
2636         if (storage_type == MEDIA_CONTENT_STORAGE_CLOUD) {
2637                 switch (media->media_type) {
2638                 case MEDIA_CONTENT_TYPE_IMAGE:
2639                         svc_content_info->media_meta.width = media->image_meta->width;
2640                         svc_content_info->media_meta.height = media->image_meta->height;
2641                         svc_content_info->media_meta.datetaken = g_strdup(media->image_meta->date_taken);
2642                         svc_content_info->media_meta.orientation = media->image_meta->orientation;
2643                         break;
2644                 case MEDIA_CONTENT_TYPE_VIDEO:
2645                         svc_content_info->media_meta.album_artist = g_strdup(media->audio_meta->album_artist);
2646                         svc_content_info->media_meta.composer = g_strdup(media->audio_meta->composer);
2647                         svc_content_info->media_meta.year = g_strdup(media->audio_meta->year);
2648                         svc_content_info->media_meta.copyright = g_strdup(media->audio_meta->copyright);
2649                         svc_content_info->media_meta.track_num = g_strdup(media->audio_meta->track_num);
2650                         svc_content_info->media_meta.bitrate = media->audio_meta->bitrate;
2651                         svc_content_info->media_meta.duration = media->audio_meta->duration;
2652                         svc_content_info->media_meta.width = media->image_meta->width;
2653                         svc_content_info->media_meta.height = media->image_meta->height;
2654                         break;
2655                 case MEDIA_CONTENT_TYPE_SOUND:
2656                 case MEDIA_CONTENT_TYPE_MUSIC:
2657                         svc_content_info->media_meta.album_artist = g_strdup(media->audio_meta->album_artist);
2658                         svc_content_info->media_meta.composer = g_strdup(media->audio_meta->composer);
2659                         svc_content_info->media_meta.year = g_strdup(media->audio_meta->year);
2660                         svc_content_info->media_meta.copyright = g_strdup(media->audio_meta->copyright);
2661                         svc_content_info->media_meta.track_num = g_strdup(media->audio_meta->track_num);
2662                         svc_content_info->media_meta.bitrate = media->audio_meta->bitrate;
2663                         svc_content_info->media_meta.duration = media->audio_meta->duration;
2664                         svc_content_info->media_meta.channel = media->audio_meta->channel;
2665                         svc_content_info->media_meta.samplerate = media->audio_meta->samplerate;
2666                         break;
2667                 case MEDIA_CONTENT_TYPE_OTHERS:
2668                 default:
2669                         break;
2670                 }
2671         }
2672
2673         *service_content = svc_content_info;
2674
2675         return MEDIA_CONTENT_ERROR_NONE;
2676 }
2677
2678 static int __media_info_set_str_data(media_info_h media, media_info_item_e data_type, const char *str_data)
2679 {
2680         media_info_s *_media = (media_info_s*)media;
2681
2682         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
2683
2684         switch (data_type) {
2685         case MEDIA_INFO_PATH:
2686                 SAFE_FREE(_media->file_path);
2687                 if (STRING_VALID(str_data)) {
2688                         _media->file_path = strdup(str_data);
2689                         media_content_retvm_if(_media->file_path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2690                 } else {
2691                         _media->file_path = NULL;
2692                 }
2693                 break;
2694         case MEDIA_INFO_MIME_TYPE:
2695                 SAFE_FREE(_media->mime_type);
2696                 if (STRING_VALID(str_data)) {
2697                         _media->mime_type = strdup(str_data);
2698                         media_content_retvm_if(_media->mime_type == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2699                 } else {
2700                         _media->mime_type = NULL;
2701                 }
2702                 break;
2703         case MEDIA_INFO_THUMBNAIL_PATH:
2704                 SAFE_FREE(_media->thumbnail_path);
2705                 if (STRING_VALID(str_data)) {
2706                         _media->thumbnail_path = strdup(str_data);
2707                         media_content_retvm_if(_media->thumbnail_path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2708                 } else {
2709                         _media->thumbnail_path = NULL;
2710                 }
2711                 break;
2712         case MEDIA_INFO_TITLE:
2713                 SAFE_FREE(_media->title);
2714                 if (STRING_VALID(str_data)) {
2715                         _media->title = strdup(str_data);
2716                         media_content_retvm_if(_media->title == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2717                 } else {
2718                         _media->title = NULL;
2719                 }
2720                 break;
2721         case MEDIA_INFO_STORAGE_UUID:
2722                 SAFE_FREE(_media->storage_uuid);
2723                 if (STRING_VALID(str_data)) {
2724                         _media->storage_uuid = strdup(str_data);
2725                         media_content_retvm_if(_media->storage_uuid == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2726                 } else {
2727                         _media->storage_uuid = NULL;
2728                 }
2729                 break;
2730         case MEDIA_INFO_ALBUM:
2731                 if (STRING_VALID(_media->media_id)) {
2732                         if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
2733                                 SAFE_FREE(_media->video_meta->album);
2734                                 if (str_data != NULL) {
2735                                         _media->video_meta->album = strdup(str_data);
2736                                         media_content_retvm_if(_media->video_meta->album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2737                                 }
2738                         } else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) {
2739                                 SAFE_FREE(_media->audio_meta->album);
2740                                 if (str_data != NULL) {
2741                                         _media->audio_meta->album = strdup(str_data);
2742                                         media_content_retvm_if(_media->audio_meta->album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2743                                 }
2744                         }
2745                 } else {
2746                         SAFE_FREE(_media->video_meta->album);
2747                         if (str_data != NULL) {
2748                                 _media->video_meta->album = strdup(str_data);
2749                                 media_content_retvm_if(_media->video_meta->album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2750                         }
2751
2752                         SAFE_FREE(_media->audio_meta->album);
2753                         if (str_data != NULL) {
2754                                 _media->audio_meta->album = strdup(str_data);
2755                                 media_content_retvm_if(_media->audio_meta->album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2756                         }
2757                 }
2758                 break;
2759         case MEDIA_INFO_ARTIST:
2760                 if (STRING_VALID(_media->media_id)) {
2761                         if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
2762                                 SAFE_FREE(_media->video_meta->artist);
2763                                 if (str_data != NULL) {
2764                                         _media->video_meta->artist = strdup(str_data);
2765                                         media_content_retvm_if(_media->video_meta->artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2766                                 }
2767                         } else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) {
2768                                 SAFE_FREE(_media->audio_meta->artist);
2769                                 if (str_data != NULL) {
2770                                         _media->audio_meta->artist = strdup(str_data);
2771                                         media_content_retvm_if(_media->audio_meta->artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2772                                 }
2773                         }
2774                 } else {
2775                         SAFE_FREE(_media->video_meta->artist);
2776                         if (str_data != NULL) {
2777                                 _media->video_meta->artist = strdup(str_data);
2778                                 media_content_retvm_if(_media->video_meta->artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2779                         }
2780
2781                         SAFE_FREE(_media->audio_meta->artist);
2782                         if (str_data != NULL) {
2783                                 _media->audio_meta->artist = strdup(str_data);
2784                                 media_content_retvm_if(_media->audio_meta->artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2785                         }
2786                 }
2787                 break;
2788         case MEDIA_INFO_GENRE:
2789                 if (STRING_VALID(_media->media_id)) {
2790                         if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
2791                                 SAFE_FREE(_media->video_meta->genre);
2792                                 if (str_data != NULL) {
2793                                         _media->video_meta->genre = strdup(str_data);
2794                                         media_content_retvm_if(_media->video_meta->genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2795                                 }
2796                         } else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) {
2797                                 SAFE_FREE(_media->audio_meta->genre);
2798                                 if (str_data != NULL) {
2799                                         _media->audio_meta->genre = strdup(str_data);
2800                                         media_content_retvm_if(_media->audio_meta->genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2801                                 }
2802                         }
2803                 } else {
2804                         SAFE_FREE(_media->video_meta->genre);
2805                         if (str_data != NULL) {
2806                                 _media->video_meta->genre = strdup(str_data);
2807                                 media_content_retvm_if(_media->video_meta->genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2808                         }
2809
2810                         SAFE_FREE(_media->audio_meta->genre);
2811                         if (str_data != NULL) {
2812                                 _media->audio_meta->genre = strdup(str_data);
2813                                 media_content_retvm_if(_media->audio_meta->genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2814                         }
2815                 }
2816                 break;
2817         case MEDIA_INFO_RECORDED_DATE:
2818                 if (STRING_VALID(_media->media_id)) {
2819                         if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
2820                                 SAFE_FREE(_media->video_meta->recorded_date);
2821                                 if (str_data != NULL) {
2822                                         _media->video_meta->recorded_date = strdup(str_data);
2823                                         media_content_retvm_if(_media->video_meta->recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2824                                 }
2825                         } else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) {
2826                                 SAFE_FREE(_media->audio_meta->recorded_date);
2827                                 if (str_data != NULL) {
2828                                         _media->audio_meta->recorded_date = strdup(str_data);
2829                                         media_content_retvm_if(_media->audio_meta->recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2830                                 }
2831                         }
2832                 } else {
2833                         SAFE_FREE(_media->video_meta->recorded_date);
2834                         if (str_data != NULL) {
2835                                 _media->video_meta->recorded_date = strdup(str_data);
2836                                 media_content_retvm_if(_media->video_meta->recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2837                         }
2838
2839                         SAFE_FREE(_media->audio_meta->recorded_date);
2840                         if (str_data != NULL) {
2841                                 _media->audio_meta->recorded_date = strdup(str_data);
2842                                 media_content_retvm_if(_media->audio_meta->recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2843                         }
2844                 }
2845                 break;
2846         default:
2847                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2848                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2849         }
2850
2851         return MEDIA_CONTENT_ERROR_NONE;
2852 }
2853
2854 static int __media_info_destroy(media_info_h media)
2855 {
2856         int ret = MEDIA_CONTENT_ERROR_NONE;
2857         media_info_s *_media = (media_info_s*)media;
2858
2859         if (_media) {
2860                 SAFE_FREE(_media->media_id);
2861                 SAFE_FREE(_media->file_path);
2862                 SAFE_FREE(_media->display_name);
2863                 SAFE_FREE(_media->mime_type);
2864                 SAFE_FREE(_media->thumbnail_path);
2865                 SAFE_FREE(_media->description);
2866                 SAFE_FREE(_media->author);
2867                 SAFE_FREE(_media->provider);
2868                 SAFE_FREE(_media->content_name);
2869                 SAFE_FREE(_media->category);
2870                 SAFE_FREE(_media->location_tag);
2871                 SAFE_FREE(_media->age_rating);
2872                 SAFE_FREE(_media->keyword);
2873                 SAFE_FREE(_media->title);
2874                 SAFE_FREE(_media->weather);
2875                 SAFE_FREE(_media->storage_uuid);
2876
2877                 if (_media->image_meta) {
2878                         SAFE_FREE(_media->image_meta->media_id);
2879                         SAFE_FREE(_media->image_meta->date_taken);
2880                         SAFE_FREE(_media->image_meta->burst_id);
2881                         SAFE_FREE(_media->image_meta->exposure_time);
2882                         SAFE_FREE(_media->image_meta->model);
2883                         SAFE_FREE(_media->image_meta->title);
2884                         SAFE_FREE(_media->image_meta->weather);
2885
2886                         SAFE_FREE(_media->image_meta);
2887                 }
2888
2889                 if (_media->video_meta) {
2890                         SAFE_FREE(_media->video_meta->media_id);
2891                         SAFE_FREE(_media->video_meta->title);
2892                         SAFE_FREE(_media->video_meta->album);
2893                         SAFE_FREE(_media->video_meta->artist);
2894                         SAFE_FREE(_media->video_meta->album_artist);
2895                         SAFE_FREE(_media->video_meta->genre);
2896                         SAFE_FREE(_media->video_meta->composer);
2897                         SAFE_FREE(_media->video_meta->year);
2898                         SAFE_FREE(_media->video_meta->recorded_date);
2899                         SAFE_FREE(_media->video_meta->copyright);
2900                         SAFE_FREE(_media->video_meta->track_num);
2901
2902                         SAFE_FREE(_media->video_meta);
2903                 }
2904
2905                 if (_media->audio_meta) {
2906                         SAFE_FREE(_media->audio_meta->media_id);
2907                         SAFE_FREE(_media->audio_meta->title);
2908                         SAFE_FREE(_media->audio_meta->album);
2909                         SAFE_FREE(_media->audio_meta->artist);
2910                         SAFE_FREE(_media->audio_meta->album_artist);
2911                         SAFE_FREE(_media->audio_meta->genre);
2912                         SAFE_FREE(_media->audio_meta->composer);
2913                         SAFE_FREE(_media->audio_meta->year);
2914                         SAFE_FREE(_media->audio_meta->recorded_date);
2915                         SAFE_FREE(_media->audio_meta->copyright);
2916                         SAFE_FREE(_media->audio_meta->track_num);
2917
2918                         SAFE_FREE(_media->audio_meta);
2919                 }
2920
2921                 ret = MEDIA_CONTENT_ERROR_NONE;
2922         } else {
2923                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2924                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2925         }
2926
2927         return ret;
2928 }
2929
2930 int media_info_insert_to_db_with_data(media_info_h media)
2931 {
2932         int ret = MEDIA_CONTENT_ERROR_NONE;
2933
2934         media_info_s *_media = (media_info_s*)media;
2935
2936         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
2937         media_content_retvm_if(!STRING_VALID(_media->file_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid file_path");
2938         media_content_retvm_if(!STRING_VALID(_media->storage_uuid), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid storage_uuid");
2939         media_content_retvm_if(_media->storage_type < 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid storage_type [%d]", _media->storage_type);
2940
2941         /* Cloud Item should be filled whole info*/
2942         if (_media->storage_type == MEDIA_CONTENT_STORAGE_CLOUD) {
2943                 media_content_retvm_if(!STRING_VALID(_media->mime_type), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid mime_type");
2944                 media_content_retvm_if(!STRING_VALID(_media->title), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid title");
2945                 media_content_retvm_if(_media->size <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid size [%d]", _media->size);
2946                 media_content_retvm_if(_media->modified_time <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid modified_time [%d]", _media->modified_time);
2947
2948                 if ((_media->media_type < MEDIA_CONTENT_TYPE_IMAGE) || (_media->media_type > MEDIA_CONTENT_TYPE_OTHERS)) {
2949                         media_content_error("invalid media type [%d]", _media->media_type);
2950                         return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2951                 }
2952         }
2953
2954         media_content_sec_debug("storage[%d], path[%s], media_type[%d]", _media->storage_type, _media->file_path, _media->media_type);
2955
2956         media_svc_content_info_s *svc_content_info = NULL;
2957
2958         ret = __media_info_map_data_usr_to_svc(_media, &svc_content_info, _media->storage_type);
2959         media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "__media_info_map_data_usr_to_svc fail");
2960
2961         ret = media_svc_insert_item_immediately_with_data(_content_get_db_handle(), svc_content_info, tzplatform_getuid(TZ_USER_NAME));
2962         if (ret != MS_MEDIA_ERR_NONE) {
2963                 media_content_sec_error("media_svc_insert_item_immediately_with_data failed : %d (%s)", ret, _media->file_path);
2964                 media_svc_destroy_content_info(svc_content_info);
2965                 SAFE_FREE(svc_content_info);
2966                 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2967         }
2968         /*free the svc_content_info*/
2969         media_svc_destroy_content_info(svc_content_info);
2970         SAFE_FREE(svc_content_info);
2971
2972         /*Fill out the handle*/
2973         char *media_file_path = g_strdup(_media->file_path);
2974         char *media_string_uuid = g_strdup(_media->storage_uuid);
2975
2976         __media_info_destroy(media);
2977         ret = _media_info_get_media_info_from_db(media_file_path, media_string_uuid, media);
2978         if (ret != MEDIA_CONTENT_ERROR_NONE)
2979                 media_content_error("_media_info_get_media_info_from_db fail", ret);
2980
2981         SAFE_FREE(media_file_path);
2982         SAFE_FREE(media_string_uuid);
2983
2984         return ret;
2985 }
2986
2987 int media_info_create(const char *path, media_info_h *media)
2988 {
2989         int ret = MEDIA_CONTENT_ERROR_NONE;
2990         char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
2991         media_svc_storage_type_e storage_type = 0;
2992         bool ignore_file = FALSE;
2993
2994         media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
2995         media_content_retvm_if(media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
2996
2997         ret = _media_util_check_ignore_file(path, &ignore_file);
2998         media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
2999
3000         memset(storage_id, 0x00, sizeof(storage_id));
3001
3002         if (STRING_VALID(MEDIA_ROOT_PATH_CLOUD) && (strstr(path, MEDIA_ROOT_PATH_CLOUD) == NULL)) {
3003                 bool ignore_dir = FALSE;
3004                 char *folder_path = NULL;
3005
3006                 ret = _media_util_check_file_exist(path);
3007                 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
3008
3009                 folder_path = g_path_get_dirname(path);
3010                 ret = _media_util_check_ignore_dir(folder_path, &ignore_dir);
3011                 SAFE_FREE(folder_path);
3012                 media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
3013
3014                 ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id);
3015                 if (ret != MS_MEDIA_ERR_NONE) {
3016                         media_content_error("media_svc_get_storage_id failed : %d", ret);
3017                         return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
3018                 }
3019
3020                 ret = media_svc_get_storage_type(path, &storage_type, tzplatform_getuid(TZ_USER_NAME));
3021                 if (ret != MS_MEDIA_ERR_NONE) {
3022                         media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
3023                         return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
3024                 }
3025         }
3026
3027         media_info_s *_media = (media_info_s*)calloc(1, sizeof(media_info_s));
3028         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3029
3030         _media->audio_meta = (audio_meta_s *)calloc(1, sizeof(audio_meta_s));
3031         if (_media->audio_meta == NULL) {
3032                 SAFE_FREE(_media);
3033                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
3034                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
3035         }
3036
3037         _media->video_meta = (video_meta_s *)calloc(1, sizeof(video_meta_s));
3038         if (_media->video_meta == NULL) {
3039                 SAFE_FREE(_media->audio_meta);
3040                 SAFE_FREE(_media);
3041                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
3042                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
3043         }
3044
3045         _media->image_meta = (image_meta_s *)calloc(1, sizeof(image_meta_s));
3046         if (_media->image_meta == NULL) {
3047                 SAFE_FREE(_media->audio_meta);
3048                 SAFE_FREE(_media->video_meta);
3049                 SAFE_FREE(_media);
3050                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
3051                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
3052         }
3053
3054         _media->file_path = g_strdup(path);
3055         _media->storage_type = -1;
3056         _media->media_type = 0;
3057         _media->modified_time = 0;
3058         _media->size = 0;
3059         _media->request_id = 0;
3060         _media->longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
3061         _media->latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
3062         _media->altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
3063
3064         if (STRING_VALID(storage_id)) {
3065                 _media->storage_uuid = g_strdup(storage_id);
3066                 _media->storage_type = storage_type;
3067         }
3068
3069         *media = (media_info_h)_media;
3070
3071         return ret;
3072 }
3073
3074 int media_info_set_mime_type(media_info_h media, const char *mime_type)
3075 {
3076         return __media_info_set_str_data(media, MEDIA_INFO_MIME_TYPE, mime_type);
3077 }
3078
3079 int media_info_set_title(media_info_h media, const char *title)
3080 {
3081         return __media_info_set_str_data(media, MEDIA_INFO_TITLE, title);
3082 }
3083
3084 int media_info_set_album(media_info_h media, const char *album)
3085 {
3086         return __media_info_set_str_data(media, MEDIA_INFO_ALBUM, album);
3087 }
3088
3089 int media_info_set_artist(media_info_h media, const char *artist)
3090 {
3091         return __media_info_set_str_data(media, MEDIA_INFO_ARTIST, artist);
3092 }
3093
3094 int media_info_set_genre(media_info_h media, const char *genre)
3095 {
3096         return __media_info_set_str_data(media, MEDIA_INFO_GENRE, genre);
3097 }
3098
3099 int media_info_set_recorded_date(media_info_h media, const char *recorded_date)
3100 {
3101         return __media_info_set_str_data(media, MEDIA_INFO_RECORDED_DATE, recorded_date);
3102 }
3103
3104 int media_info_set_thumbnail_path(media_info_h media, const char *thumbnail_path)
3105 {
3106         return __media_info_set_str_data(media, MEDIA_INFO_THUMBNAIL_PATH, thumbnail_path);
3107 }
3108
3109 int media_info_set_storage_id(media_info_h media, const char *storage_id)
3110 {
3111         return __media_info_set_str_data(media, MEDIA_INFO_STORAGE_UUID, storage_id);
3112 }
3113
3114 int media_info_set_size(media_info_h media, unsigned long long size)
3115 {
3116         media_info_s *_media = (media_info_s*)media;
3117
3118         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3119
3120         _media->size = size;
3121
3122         return MEDIA_CONTENT_ERROR_NONE;
3123 }
3124
3125 int media_info_set_modified_time(media_info_h media, time_t modified_time)
3126 {
3127         media_info_s *_media = (media_info_s*)media;
3128
3129         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3130
3131         _media->modified_time = modified_time;
3132
3133         return MEDIA_CONTENT_ERROR_NONE;
3134 }
3135
3136 int media_info_set_media_type(media_info_h media, media_content_type_e type)
3137 {
3138         media_info_s *_media = (media_info_s*)media;
3139
3140         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3141
3142         _media->media_type = type;
3143
3144         return MEDIA_CONTENT_ERROR_NONE;
3145 }
3146
3147 int media_info_set_duration(media_info_h media, int duration)
3148 {
3149         media_info_s *_media = (media_info_s*)media;
3150
3151         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3152
3153         if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3154                 _media->video_meta->duration = duration;
3155         else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND))
3156                 _media->audio_meta->duration = duration;
3157         else {
3158                 media_content_error("Invalid media type");
3159                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3160         }
3161
3162         return MEDIA_CONTENT_ERROR_NONE;
3163 }
3164
3165 int media_info_set_width(media_info_h media, int width)
3166 {
3167         media_info_s *_media = (media_info_s*)media;
3168
3169         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3170
3171         if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3172                 _media->video_meta->width = width;
3173         else if (_media->media_type == MEDIA_CONTENT_TYPE_IMAGE)
3174                 _media->image_meta->width = width;
3175         else {
3176                 media_content_error("Invalid media type");
3177                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3178         }
3179
3180         return MEDIA_CONTENT_ERROR_NONE;
3181 }
3182
3183 int media_info_set_height(media_info_h media, int height)
3184 {
3185         media_info_s *_media = (media_info_s*)media;
3186
3187         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3188
3189         if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3190                 _media->video_meta->height = height;
3191         else if (_media->media_type == MEDIA_CONTENT_TYPE_IMAGE)
3192                 _media->image_meta->height = height;
3193         else {
3194                 media_content_error("Invalid media type");
3195                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3196         }
3197
3198         return MEDIA_CONTENT_ERROR_NONE;
3199 }
3200
3201 int media_info_set_storage_type(media_info_h media, media_content_storage_e storage_type)
3202 {
3203         media_info_s *_media = (media_info_s*)media;
3204
3205         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3206
3207         _media->storage_type = storage_type;
3208
3209         return MEDIA_CONTENT_ERROR_NONE;
3210 }