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