Add code for ACR-420
[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 = 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(_content_get_db_handle(), 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(_content_get_db_handle(), MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, MEDIA_ROOT_PATH_INTERNAL, -1, NULL, NULL);
572                         media_svc_publish_noti(_content_get_db_handle(), 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 (STRING_VALID(_src->media_id)) {
673                         _dst->media_id = 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 (STRING_VALID(_src->file_path)) {
681                         _dst->file_path = 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 (STRING_VALID(_src->display_name)) {
689                         _dst->display_name = 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 (STRING_VALID(_src->mime_type)) {
697                         _dst->mime_type = 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 (STRING_VALID(_src->thumbnail_path)) {
705                         _dst->thumbnail_path = 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 (STRING_VALID(_src->description)) {
713                         _dst->description = 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 (STRING_VALID(_src->weather)) {
722                         _dst->weather = 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 (STRING_VALID(_src->title)) {
731                         _dst->title = 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 (STRING_VALID(_src->author)) {
739                         _dst->author = 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 (STRING_VALID(_src->provider)) {
747                         _dst->provider = 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 (STRING_VALID(_src->content_name)) {
755                         _dst->content_name = 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 (STRING_VALID(_src->category)) {
763                         _dst->category = 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 (STRING_VALID(_src->location_tag)) {
771                         _dst->location_tag = 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 (STRING_VALID(_src->age_rating)) {
779                         _dst->age_rating = 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 (STRING_VALID(_src->keyword)) {
787                         _dst->keyword = 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 (STRING_VALID(_src->storage_uuid)) {
796                         _dst->storage_uuid = 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
821                 if (_src->media_type == MEDIA_CONTENT_TYPE_IMAGE && _src->image_meta) {
822                         _dst->image_meta = (image_meta_s *)calloc(1, sizeof(image_meta_s));
823                         if (_dst->image_meta == NULL) {
824                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
825                                 media_info_destroy((media_info_h)_dst);
826                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
827                         }
828
829                         if (STRING_VALID(_src->image_meta->media_id)) {
830                                 _dst->image_meta->media_id = strdup(_src->image_meta->media_id);
831                                 if (_dst->image_meta->media_id == NULL) {
832                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
833                                         media_info_destroy((media_info_h)_dst);
834                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
835                                 }
836                         }
837
838                         if (STRING_VALID(_src->image_meta->date_taken)) {
839                                 _dst->image_meta->date_taken = strdup(_src->image_meta->date_taken);
840                                 if (_dst->image_meta->date_taken == NULL) {
841                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
842                                         media_info_destroy((media_info_h)_dst);
843                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
844                                 }
845                         }
846
847                         if (STRING_VALID(_src->image_meta->burst_id)) {
848                                 _dst->image_meta->burst_id = strdup(_src->image_meta->burst_id);
849                                 if (_dst->image_meta->burst_id == NULL) {
850                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
851                                         media_info_destroy((media_info_h)_dst);
852                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
853                                 }
854                         }
855
856                         if (STRING_VALID(_src->image_meta->weather)) {
857                                 _dst->image_meta->weather = strdup(_src->image_meta->weather);
858                                 if (_dst->image_meta->weather == NULL) {
859                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
860                                         media_info_destroy((media_info_h)_dst);
861                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
862                                 }
863                         }
864
865                         if (STRING_VALID(_src->image_meta->exposure_time)) {
866                                 _dst->image_meta->exposure_time = strdup(_src->image_meta->exposure_time);
867                                 if (_dst->image_meta->exposure_time == NULL) {
868                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
869                                         media_info_destroy((media_info_h)_dst);
870                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
871                                 }
872                         }
873
874                         if (STRING_VALID(_src->image_meta->model)) {
875                                 _dst->image_meta->model = strdup(_src->image_meta->model);
876                                 if (_dst->image_meta->model == NULL) {
877                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
878                                         media_info_destroy((media_info_h)_dst);
879                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
880                                 }
881                         }
882
883                         _dst->image_meta->fnumber = _src->image_meta->fnumber;
884                         _dst->image_meta->iso = _src->image_meta->iso;
885                         _dst->image_meta->width = _src->image_meta->width;
886                         _dst->image_meta->height = _src->image_meta->height;
887                         _dst->image_meta->orientation = _src->image_meta->orientation;
888
889                 } else if (_src->media_type == MEDIA_CONTENT_TYPE_VIDEO && _src->video_meta) {
890                         _dst->video_meta = (video_meta_s *)calloc(1, sizeof(video_meta_s));
891                         if (_dst->video_meta == NULL) {
892                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
893                                 media_info_destroy((media_info_h)_dst);
894                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
895                         }
896
897                         if (STRING_VALID(_src->video_meta->media_id)) {
898                                 _dst->video_meta->media_id = strdup(_src->video_meta->media_id);
899                                 if (_dst->video_meta->media_id == NULL) {
900                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
901                                         media_info_destroy((media_info_h)_dst);
902                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
903                                 }
904                         }
905                         if (STRING_VALID(_src->video_meta->title)) {
906                                 _dst->video_meta->title = strdup(_src->video_meta->title);
907                                 if (_dst->video_meta->title == NULL) {
908                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
909                                         media_info_destroy((media_info_h)_dst);
910                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
911                                 }
912                         }
913                         if (STRING_VALID(_src->video_meta->album)) {
914                                 _dst->video_meta->album = strdup(_src->video_meta->album);
915                                 if (_dst->video_meta->album == NULL) {
916                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
917                                         media_info_destroy((media_info_h)_dst);
918                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
919                                 }
920                         }
921                         if (STRING_VALID(_src->video_meta->artist)) {
922                                 _dst->video_meta->artist = strdup(_src->video_meta->artist);
923                                 if (_dst->video_meta->artist == NULL) {
924                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
925                                         media_info_destroy((media_info_h)_dst);
926                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
927                                 }
928                         }
929                         if (STRING_VALID(_src->video_meta->album_artist)) {
930                                 _dst->video_meta->album_artist = strdup(_src->video_meta->album_artist);
931                                 if (_dst->video_meta->album_artist == NULL) {
932                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
933                                         media_info_destroy((media_info_h)_dst);
934                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
935                                 }
936                         }
937                         if (STRING_VALID(_src->video_meta->genre)) {
938                                 _dst->video_meta->genre = strdup(_src->video_meta->genre);
939                                 if (_dst->video_meta->genre == NULL) {
940                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
941                                         media_info_destroy((media_info_h)_dst);
942                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
943                                 }
944                         }
945                         if (STRING_VALID(_src->video_meta->composer)) {
946                                 _dst->video_meta->composer = strdup(_src->video_meta->composer);
947                                 if (_dst->video_meta->composer == NULL) {
948                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
949                                         media_info_destroy((media_info_h)_dst);
950                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
951                                 }
952                         }
953                         if (STRING_VALID(_src->video_meta->year)) {
954                                 _dst->video_meta->year = strdup(_src->video_meta->year);
955                                 if (_dst->video_meta->year == NULL) {
956                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
957                                         media_info_destroy((media_info_h)_dst);
958                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
959                                 }
960                         }
961                         if (STRING_VALID(_src->video_meta->recorded_date)) {
962                                 _dst->video_meta->recorded_date = strdup(_src->video_meta->recorded_date);
963                                 if (_dst->video_meta->recorded_date == NULL) {
964                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
965                                         media_info_destroy((media_info_h)_dst);
966                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
967                                 }
968                         }
969                         if (STRING_VALID(_src->video_meta->copyright)) {
970                                 _dst->video_meta->copyright = strdup(_src->video_meta->copyright);
971                                 if (_dst->video_meta->copyright == NULL) {
972                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
973                                         media_info_destroy((media_info_h)_dst);
974                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
975                                 }
976                         }
977                         if (STRING_VALID(_src->video_meta->track_num)) {
978                                 _dst->video_meta->track_num = strdup(_src->video_meta->track_num);
979                                 if (_dst->video_meta->track_num == NULL) {
980                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
981                                         media_info_destroy((media_info_h)_dst);
982                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
983                                 }
984                         }
985
986                         _dst->video_meta->width = _src->video_meta->width;
987                         _dst->video_meta->height = _src->video_meta->height;
988                         _dst->video_meta->duration = _src->video_meta->duration;
989                         _dst->video_meta->bitrate = _src->video_meta->bitrate;
990                         _dst->video_meta->played_count = _src->video_meta->played_count;
991                         _dst->video_meta->played_time = _src->video_meta->played_time;
992                         _dst->video_meta->played_position = _src->video_meta->played_position;
993
994                 } else if ((_src->media_type == MEDIA_CONTENT_TYPE_MUSIC || _src->media_type == MEDIA_CONTENT_TYPE_SOUND) && _src->audio_meta) {
995                         _dst->audio_meta = (audio_meta_s *)calloc(1, sizeof(audio_meta_s));
996                         if (_dst->audio_meta == NULL) {
997                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
998                                 media_info_destroy((media_info_h)_dst);
999                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1000                         }
1001
1002                         if (STRING_VALID(_src->audio_meta->media_id)) {
1003                                 _dst->audio_meta->media_id = strdup(_src->audio_meta->media_id);
1004                                 if (_dst->audio_meta->media_id == NULL) {
1005                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1006                                         media_info_destroy((media_info_h)_dst);
1007                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1008                                 }
1009                         }
1010                         if (STRING_VALID(_src->audio_meta->title)) {
1011                                 _dst->audio_meta->title = strdup(_src->audio_meta->title);
1012                                 if (_dst->audio_meta->title == NULL) {
1013                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1014                                         media_info_destroy((media_info_h)_dst);
1015                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1016                                 }
1017                         }
1018                         if (STRING_VALID(_src->audio_meta->album)) {
1019                                 _dst->audio_meta->album = strdup(_src->audio_meta->album);
1020                                 if (_dst->audio_meta->album == NULL) {
1021                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1022                                         media_info_destroy((media_info_h)_dst);
1023                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1024                                 }
1025                         }
1026                         if (STRING_VALID(_src->audio_meta->artist)) {
1027                                 _dst->audio_meta->artist = strdup(_src->audio_meta->artist);
1028                                 if (_dst->audio_meta->artist == NULL) {
1029                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1030                                         media_info_destroy((media_info_h)_dst);
1031                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1032                                 }
1033                         }
1034                         if (STRING_VALID(_src->audio_meta->album_artist)) {
1035                                 _dst->audio_meta->album_artist = strdup(_src->audio_meta->album_artist);
1036                                 if (_dst->audio_meta->album_artist == NULL) {
1037                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1038                                         media_info_destroy((media_info_h)_dst);
1039                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1040                                 }
1041                         }
1042                         if (STRING_VALID(_src->audio_meta->genre)) {
1043                                 _dst->audio_meta->genre = strdup(_src->audio_meta->genre);
1044                                 if (_dst->audio_meta->genre == NULL) {
1045                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1046                                         media_info_destroy((media_info_h)_dst);
1047                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1048                                 }
1049                         }
1050                         if (STRING_VALID(_src->audio_meta->composer)) {
1051                                 _dst->audio_meta->composer = strdup(_src->audio_meta->composer);
1052                                 if (_dst->audio_meta->composer == NULL) {
1053                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1054                                         media_info_destroy((media_info_h)_dst);
1055                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1056                                 }
1057                         }
1058                         if (STRING_VALID(_src->audio_meta->year)) {
1059                                 _dst->audio_meta->year = strdup(_src->audio_meta->year);
1060                                 if (_dst->audio_meta->year == NULL) {
1061                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1062                                         media_info_destroy((media_info_h)_dst);
1063                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1064                                 }
1065                         }
1066                         if (STRING_VALID(_src->audio_meta->recorded_date)) {
1067                                 _dst->audio_meta->recorded_date = strdup(_src->audio_meta->recorded_date);
1068                                 if (_dst->audio_meta->recorded_date == NULL) {
1069                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1070                                         media_info_destroy((media_info_h)_dst);
1071                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1072                                 }
1073                         }
1074                         if (STRING_VALID(_src->audio_meta->copyright)) {
1075                                 _dst->audio_meta->copyright = strdup(_src->audio_meta->copyright);
1076                                 if (_dst->audio_meta->copyright == NULL) {
1077                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1078                                         media_info_destroy((media_info_h)_dst);
1079                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1080                                 }
1081                         }
1082                         if (STRING_VALID(_src->audio_meta->track_num)) {
1083                                 _dst->audio_meta->track_num = strdup(_src->audio_meta->track_num);
1084                                 if (_dst->audio_meta->track_num == NULL) {
1085                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1086                                         media_info_destroy((media_info_h)_dst);
1087                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1088                                 }
1089                         }
1090
1091                         _dst->audio_meta->channel = _src->audio_meta->channel;
1092                         _dst->audio_meta->samplerate = _src->audio_meta->samplerate;
1093                         _dst->audio_meta->duration = _src->audio_meta->duration;
1094                         _dst->audio_meta->bitrate = _src->audio_meta->bitrate;
1095                         _dst->audio_meta->bitpersample = _src->audio_meta->bitpersample;
1096                         _dst->audio_meta->played_count = _src->audio_meta->played_count;
1097                         _dst->audio_meta->played_time = _src->audio_meta->played_time;
1098                         _dst->audio_meta->played_position = _src->audio_meta->played_position;
1099
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 (STRING_VALID(_media->display_name)) {
1380                         *name = 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 (STRING_VALID(_media->thumbnail_path)) {
1498                         *path = 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 (STRING_VALID(_media->title)) {
1520                         *title = 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 (STRING_VALID(_media->description)) {
1541                         *description = 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 (STRING_VALID(_media->weather)) {
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 (STRING_VALID(_media->author)) {
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 (STRING_VALID(_media->provider)) {
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 (STRING_VALID(_media->content_name)) {
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 (STRING_VALID(_media->category)) {
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 (STRING_VALID(_media->location_tag)) {
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 (STRING_VALID(_media->age_rating)) {
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 (STRING_VALID(_media->keyword)) {
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(_content_get_db_handle(), _media->display_name, &file_name_pinyin);
2306                         if (STRING_VALID(_media->description))
2307                                 media_svc_get_pinyin(_content_get_db_handle(), _media->description, &description_pinyin);
2308                         if (STRING_VALID(_media->author))
2309                                 media_svc_get_pinyin(_content_get_db_handle(), _media->author, &author_pinyin);
2310                         if (STRING_VALID(_media->provider))
2311                                 media_svc_get_pinyin(_content_get_db_handle(), _media->provider, &provider_pinyin);
2312                         if (STRING_VALID(_media->content_name))
2313                                 media_svc_get_pinyin(_content_get_db_handle(), _media->content_name, &content_name_pinyin);
2314                         if (STRING_VALID(_media->category))
2315                                 media_svc_get_pinyin(_content_get_db_handle(), _media->category, &category_pinyin);
2316                         if (STRING_VALID(_media->location_tag))
2317                                 media_svc_get_pinyin(_content_get_db_handle(), _media->location_tag, &location_tag_pinyin);
2318                         if (STRING_VALID(_media->age_rating))
2319                                 media_svc_get_pinyin(_content_get_db_handle(), _media->age_rating, &age_rating_pinyin);
2320                         if (STRING_VALID(_media->keyword))
2321                                 media_svc_get_pinyin(_content_get_db_handle(), _media->keyword, &keyword_pinyin);
2322                 }
2323
2324                 set_sql = sqlite3_mprintf("file_name=%Q, added_time=%d, description=%Q, longitude=%f, latitude=%f, altitude=%f, \
2325                         played_count=%d, last_played_time=%d, last_played_position=%d, \
2326                         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, \
2327                         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",
2328                         _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,
2329                         _media->author, _media->provider, _media->content_name, _media->category, _media->location_tag, _media->age_rating, _media->keyword, _media->weather, _media->sync_status,
2330                         file_name_pinyin, description_pinyin, author_pinyin, provider_pinyin, content_name_pinyin, category_pinyin, location_tag_pinyin, age_rating_pinyin, keyword_pinyin, _media->title);
2331
2332                 sql = sqlite3_mprintf("UPDATE %Q SET %s WHERE media_uuid=%Q", _media->storage_uuid, set_sql, _media->media_id);
2333
2334                 ret = _content_query_sql(sql);
2335                 SQLITE3_SAFE_FREE(set_sql);
2336                 SQLITE3_SAFE_FREE(sql);
2337
2338                 SAFE_FREE(description_pinyin);
2339                 SAFE_FREE(author_pinyin);
2340                 SAFE_FREE(provider_pinyin);
2341                 SAFE_FREE(content_name_pinyin);
2342                 SAFE_FREE(category_pinyin);
2343                 SAFE_FREE(location_tag_pinyin);
2344                 SAFE_FREE(age_rating_pinyin);
2345                 SAFE_FREE(keyword_pinyin);
2346
2347                 if (_media->storage_type == MEDIA_CONTENT_STORAGE_CLOUD) {
2348                         set_sql = NULL;
2349                         sql = NULL;
2350
2351                         if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
2352                                 set_sql = sqlite3_mprintf("title=%Q, album=%Q, artist=%Q, genre=%Q, duration=%d, width=%d, height=%d", \
2353                                 _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);
2354                         } else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) {
2355                                 set_sql = sqlite3_mprintf("title=%Q, album=%Q, artist=%Q, genre=%Q, duration=%d", \
2356                                 _media->title, _media->audio_meta->album, _media->audio_meta->artist, _media->audio_meta->genre, _media->audio_meta->duration);
2357                         } else if (_media->media_type == MEDIA_CONTENT_TYPE_IMAGE) {
2358                                 set_sql = sqlite3_mprintf("title=%Q, width=%d, height=%d", _media->title, _media->image_meta->width, _media->image_meta->height);
2359                         } else {
2360                                 set_sql = sqlite3_mprintf("title=%Q", _media->title);
2361                         }
2362
2363                         sql = sqlite3_mprintf("UPDATE %Q SET %s WHERE media_uuid=%Q", _media->storage_uuid, set_sql, _media->media_id);
2364
2365                         ret = _content_query_sql(sql);
2366
2367                         SQLITE3_SAFE_FREE(set_sql);
2368                         SQLITE3_SAFE_FREE(sql);
2369                 }
2370
2371                 if (ret == MEDIA_CONTENT_ERROR_NONE) {
2372                         /*  Send notification for this update */
2373                         media_content_debug("Update is successfull. Send notification for this");
2374                         if (_media->file_path && _media->mime_type)
2375                                 media_svc_publish_noti(_content_get_db_handle(), MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, _media->file_path, _media->media_type, _media->media_id, _media->mime_type);
2376                         else
2377                                 media_content_error("Can't Send Noti : path or mime type is NULL");
2378                 }
2379         } else {
2380                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2381                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2382         }
2383
2384         return ret;
2385 }
2386
2387 int media_info_refresh_metadata_to_db(const char *media_id)
2388 {
2389         int ret = MEDIA_CONTENT_ERROR_NONE;
2390         media_info_h media = NULL;
2391         char *file_path = NULL;
2392         media_content_storage_e storage_type = 0;
2393         char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
2394
2395         if (!STRING_VALID(media_id)) {
2396                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2397                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2398         }
2399
2400         ret = media_info_get_media_from_db(media_id, &media);
2401         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2402                 media_info_destroy(media);
2403                 return ret;
2404         }
2405
2406         ret = media_info_get_storage_type(media, &storage_type);
2407         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2408                 media_info_destroy(media);
2409                 return ret;
2410         }
2411
2412         if (storage_type == MEDIA_CONTENT_STORAGE_CLOUD) {
2413                 media_info_destroy(media);
2414                 media_content_error("Can't refresh cloud content!!");
2415                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2416         }
2417
2418         ret = media_info_get_file_path(media, &file_path);
2419         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2420                 media_info_destroy(media);
2421                 return ret;
2422         }
2423
2424         ret = _media_util_check_file_exist(file_path);
2425         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2426                 SAFE_FREE(file_path);
2427                 media_info_destroy(media);
2428                 return ret;
2429         }
2430
2431         memset(storage_id, 0x00, sizeof(storage_id));
2432         ret = media_svc_get_storage_id(_content_get_db_handle(), file_path, storage_id);
2433         if (ret != MS_MEDIA_ERR_NONE) {
2434                 media_content_error("media_svc_get_storage_id failed : %d", ret);
2435                 SAFE_FREE(file_path);
2436                 media_info_destroy(media);
2437                 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2438         }
2439
2440         ret = media_svc_refresh_item(_content_get_db_handle(), storage_id, storage_type, file_path, tzplatform_getuid(TZ_USER_NAME));
2441         if (ret != MS_MEDIA_ERR_NONE)
2442                 ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2443
2444         SAFE_FREE(file_path);
2445         media_info_destroy(media);
2446
2447         return ret;
2448 }
2449
2450 int media_info_move_to_db(media_info_h media, const char* dst_path)
2451 {
2452         int ret = MEDIA_CONTENT_ERROR_NONE;
2453         bool ignore_file = FALSE;
2454         bool ignore_dir = FALSE;
2455         char *folder_path = NULL;
2456         media_svc_storage_type_e src_storage_type = 0;
2457         media_svc_storage_type_e dst_storage_type = 0;
2458         char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
2459
2460         media_content_retvm_if(media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media");
2461         media_content_retvm_if(!STRING_VALID(dst_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid dst_path");
2462
2463         media_info_s *_media = (media_info_s*)media;
2464
2465         ret = _media_util_check_ignore_file(dst_path, &ignore_file);
2466         media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
2467
2468         ret = _media_util_check_file_exist(dst_path);
2469         media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
2470
2471         folder_path = g_path_get_dirname(dst_path);
2472         ret = _media_util_check_ignore_dir(folder_path, &ignore_dir);
2473         SAFE_FREE(folder_path);
2474
2475         media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
2476
2477         ret = media_svc_get_storage_type(_media->file_path, &src_storage_type, tzplatform_getuid(TZ_USER_NAME));
2478         if (ret != MS_MEDIA_ERR_NONE) {
2479                 media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
2480                 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2481         }
2482
2483         ret = media_svc_get_storage_type(dst_path, &dst_storage_type, tzplatform_getuid(TZ_USER_NAME));
2484         if (ret != MS_MEDIA_ERR_NONE) {
2485                 media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
2486                 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2487         }
2488
2489         memset(storage_id, 0x00, sizeof(storage_id));
2490         ret = media_svc_get_storage_id(_content_get_db_handle(), _media->file_path, storage_id);
2491         if (ret != MS_MEDIA_ERR_NONE) {
2492                 media_content_error("media_svc_get_storage_id failed : %d", ret);
2493                 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2494         }
2495
2496         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));
2497         return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2498 }
2499
2500 int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb callback, void *user_data)
2501 {
2502         int ret = MEDIA_CONTENT_ERROR_NONE;
2503         media_info_s *_media = (media_info_s*)media;
2504
2505         if (_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path)) {
2506                 media_thumbnail_cb_s *_thumb_cb = (media_thumbnail_cb_s*)calloc(1, sizeof(media_thumbnail_cb_s));
2507                 media_content_retvm_if(_thumb_cb == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2508
2509                 _thumb_cb->handle = _media;
2510                 _thumb_cb->user_data = user_data;
2511                 _thumb_cb->thumbnail_completed_cb = callback;
2512
2513                 ret = thumbnail_request_from_db_async(_media->file_path, (ThumbFunc)__media_info_thumbnail_completed_cb, (void *)_thumb_cb, tzplatform_getuid(TZ_USER_NAME));
2514                 ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret);
2515         } else {
2516                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2517                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2518         }
2519
2520         return ret;
2521 }
2522
2523 int media_info_cancel_thumbnail(media_info_h media)
2524 {
2525         int ret = MEDIA_CONTENT_ERROR_NONE;
2526         media_info_s *_media = (media_info_s*)media;
2527
2528         if (_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path)) {
2529                 ret = thumbnail_request_cancel_media(_media->file_path);
2530                 ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret);
2531         } else {
2532                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2533                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2534         }
2535
2536         return ret;
2537 }
2538
2539 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)
2540 {
2541         media_content_retvm_if(media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle");
2542
2543         media_svc_content_info_s *svc_content_info = calloc(1, sizeof(media_svc_content_info_s));
2544         media_content_retvm_if(svc_content_info == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2545
2546         svc_content_info->path = g_strdup(media->file_path);
2547         svc_content_info->file_name = g_strdup(media->display_name);
2548         svc_content_info->media_type = media->media_type;
2549         svc_content_info->mime_type = g_strdup(media->mime_type);
2550         svc_content_info->size = media->size;
2551         svc_content_info->storage_type = storage_type;
2552         svc_content_info->storage_uuid = g_strdup(media->storage_uuid);
2553
2554         svc_content_info->added_time = media->added_time;
2555         svc_content_info->modified_time = media->modified_time;
2556         svc_content_info->thumbnail_path = g_strdup(media->thumbnail_path);
2557         svc_content_info->is_drm = media->is_drm;
2558         svc_content_info->last_played_time = media->played_time;
2559         svc_content_info->played_count = media->played_count;
2560         svc_content_info->favourate = media->favourite;
2561
2562         svc_content_info->media_meta.title = g_strdup(media->title);
2563         svc_content_info->media_meta.rating = media->rating;
2564         svc_content_info->media_meta.description = g_strdup(media->description);
2565         svc_content_info->media_meta.longitude = media->longitude;
2566         svc_content_info->media_meta.latitude = media->latitude;
2567         svc_content_info->media_meta.altitude = media->altitude;
2568         svc_content_info->media_meta.weather = g_strdup(media->weather);
2569         svc_content_info->media_meta.category = g_strdup(media->category);
2570         svc_content_info->media_meta.keyword = g_strdup(media->keyword);
2571         svc_content_info->media_meta.location_tag = g_strdup(media->location_tag);
2572         svc_content_info->media_meta.content_name = g_strdup(media->content_name);
2573         svc_content_info->media_meta.age_rating = g_strdup(media->age_rating);
2574         svc_content_info->media_meta.author = g_strdup(media->author);
2575         svc_content_info->media_meta.provider = g_strdup(media->provider);
2576
2577         svc_content_info->media_meta.album = g_strdup(media->audio_meta->album);
2578         svc_content_info->media_meta.artist = g_strdup(media->audio_meta->artist);
2579         svc_content_info->media_meta.genre = g_strdup(media->audio_meta->genre);
2580         svc_content_info->media_meta.recorded_date = g_strdup(media->audio_meta->recorded_date);
2581
2582         if (storage_type == MEDIA_CONTENT_STORAGE_CLOUD) {
2583                 switch (media->media_type) {
2584                 case MEDIA_CONTENT_TYPE_IMAGE:
2585                         svc_content_info->media_meta.width = media->image_meta->width;
2586                         svc_content_info->media_meta.height = media->image_meta->height;
2587                         svc_content_info->media_meta.datetaken = g_strdup(media->image_meta->date_taken);
2588                         svc_content_info->media_meta.orientation = media->image_meta->orientation;
2589                         break;
2590                 case MEDIA_CONTENT_TYPE_VIDEO:
2591                         svc_content_info->media_meta.album_artist = g_strdup(media->audio_meta->album_artist);
2592                         svc_content_info->media_meta.composer = g_strdup(media->audio_meta->composer);
2593                         svc_content_info->media_meta.year = g_strdup(media->audio_meta->year);
2594                         svc_content_info->media_meta.copyright = g_strdup(media->audio_meta->copyright);
2595                         svc_content_info->media_meta.track_num = g_strdup(media->audio_meta->track_num);
2596                         svc_content_info->media_meta.bitrate = media->audio_meta->bitrate;
2597                         svc_content_info->media_meta.duration = media->audio_meta->duration;
2598                         svc_content_info->media_meta.width = media->image_meta->width;
2599                         svc_content_info->media_meta.height = media->image_meta->height;
2600                         break;
2601                 case MEDIA_CONTENT_TYPE_SOUND:
2602                 case MEDIA_CONTENT_TYPE_MUSIC:
2603                         svc_content_info->media_meta.album_artist = g_strdup(media->audio_meta->album_artist);
2604                         svc_content_info->media_meta.composer = g_strdup(media->audio_meta->composer);
2605                         svc_content_info->media_meta.year = g_strdup(media->audio_meta->year);
2606                         svc_content_info->media_meta.copyright = g_strdup(media->audio_meta->copyright);
2607                         svc_content_info->media_meta.track_num = g_strdup(media->audio_meta->track_num);
2608                         svc_content_info->media_meta.bitrate = media->audio_meta->bitrate;
2609                         svc_content_info->media_meta.duration = media->audio_meta->duration;
2610                         svc_content_info->media_meta.channel = media->audio_meta->channel;
2611                         svc_content_info->media_meta.samplerate = media->audio_meta->samplerate;
2612                         break;
2613                 case MEDIA_CONTENT_TYPE_OTHERS:
2614                 default:
2615                         break;
2616                 }
2617         }
2618
2619         *service_content = svc_content_info;
2620
2621         return MEDIA_CONTENT_ERROR_NONE;
2622 }
2623
2624 static int __media_info_set_str_data(media_info_h media, media_info_item_e data_type, const char *str_data)
2625 {
2626         media_info_s *_media = (media_info_s*)media;
2627
2628         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
2629
2630         switch (data_type) {
2631         case MEDIA_INFO_PATH:
2632                 SAFE_FREE(_media->file_path);
2633                 if (STRING_VALID(str_data)) {
2634                         _media->file_path = strdup(str_data);
2635                         media_content_retvm_if(_media->file_path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2636                 } else {
2637                         _media->file_path = NULL;
2638                 }
2639                 break;
2640         case MEDIA_INFO_MIME_TYPE:
2641                 SAFE_FREE(_media->mime_type);
2642                 if (STRING_VALID(str_data)) {
2643                         _media->mime_type = strdup(str_data);
2644                         media_content_retvm_if(_media->mime_type == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2645                 } else {
2646                         _media->mime_type = NULL;
2647                 }
2648                 break;
2649         case MEDIA_INFO_THUMBNAIL_PATH:
2650                 SAFE_FREE(_media->thumbnail_path);
2651                 if (STRING_VALID(str_data)) {
2652                         _media->thumbnail_path = strdup(str_data);
2653                         media_content_retvm_if(_media->thumbnail_path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2654                 } else {
2655                         _media->thumbnail_path = NULL;
2656                 }
2657                 break;
2658         case MEDIA_INFO_TITLE:
2659                 SAFE_FREE(_media->title);
2660                 if (STRING_VALID(str_data)) {
2661                         _media->title = strdup(str_data);
2662                         media_content_retvm_if(_media->title == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2663                 } else {
2664                         _media->title = NULL;
2665                 }
2666                 break;
2667         case MEDIA_INFO_STORAGE_UUID:
2668                 SAFE_FREE(_media->storage_uuid);
2669                 if (STRING_VALID(str_data)) {
2670                         _media->storage_uuid = strdup(str_data);
2671                         media_content_retvm_if(_media->storage_uuid == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2672                 } else {
2673                         _media->storage_uuid = NULL;
2674                 }
2675                 break;
2676         case MEDIA_INFO_ALBUM:
2677                 /* if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) */
2678                 {
2679                         SAFE_FREE(_media->video_meta->album);
2680                         if (STRING_VALID(str_data)) {
2681                                 _media->video_meta->album = strdup(str_data);
2682                                 media_content_retvm_if(_media->video_meta->album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2683                         } else {
2684                                 _media->video_meta->album = NULL;
2685                         }
2686                 }
2687                 /* else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) */
2688                 {
2689                         SAFE_FREE(_media->audio_meta->album);
2690                         if (STRING_VALID(str_data)) {
2691                                 _media->audio_meta->album = strdup(str_data);
2692                                 media_content_retvm_if(_media->audio_meta->album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2693                         } else {
2694                                 _media->audio_meta->album = NULL;
2695                         }
2696                 }
2697                 break;
2698         case MEDIA_INFO_ARTIST:
2699                 /* if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) */
2700                 {
2701                         SAFE_FREE(_media->video_meta->artist);
2702                         if (STRING_VALID(str_data)) {
2703                                 _media->video_meta->artist = strdup(str_data);
2704                                 media_content_retvm_if(_media->video_meta->artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2705                         } else {
2706                                 _media->video_meta->artist = NULL;
2707                         }
2708                 }
2709                 /* else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) */
2710                 {
2711                         SAFE_FREE(_media->audio_meta->artist);
2712                         if (STRING_VALID(str_data)) {
2713                                 _media->audio_meta->artist = strdup(str_data);
2714                                 media_content_retvm_if(_media->audio_meta->artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2715                         } else {
2716                                 _media->audio_meta->artist = NULL;
2717                         }
2718                 }
2719                 break;
2720         case MEDIA_INFO_GENRE:
2721                 /* if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) */
2722                 {
2723                         SAFE_FREE(_media->video_meta->genre);
2724                         if (STRING_VALID(str_data)) {
2725                                 _media->video_meta->genre = strdup(str_data);
2726                                 media_content_retvm_if(_media->video_meta->genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2727                         } else {
2728                                 _media->video_meta->genre = NULL;
2729                         }
2730                 }
2731                 /* else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) */
2732                 {
2733                         SAFE_FREE(_media->audio_meta->genre);
2734                         if (STRING_VALID(str_data)) {
2735                                 _media->audio_meta->genre = strdup(str_data);
2736                                 media_content_retvm_if(_media->audio_meta->genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2737                         } else {
2738                                 _media->audio_meta->genre = NULL;
2739                         }
2740                 }
2741                 break;
2742         case MEDIA_INFO_RECORDED_DATE:
2743                 /* if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) */
2744                 {
2745                         SAFE_FREE(_media->video_meta->recorded_date);
2746                         if (STRING_VALID(str_data)) {
2747                                 _media->video_meta->recorded_date = strdup(str_data);
2748                                 media_content_retvm_if(_media->video_meta->recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2749                         } else {
2750                                 _media->video_meta->recorded_date = NULL;
2751                         }
2752                 }
2753                 /* else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) */
2754                 {
2755                         SAFE_FREE(_media->audio_meta->recorded_date);
2756                         if (STRING_VALID(str_data)) {
2757                                 _media->audio_meta->recorded_date = strdup(str_data);
2758                                 media_content_retvm_if(_media->audio_meta->recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2759                         } else {
2760                                 _media->audio_meta->recorded_date = NULL;
2761                         }
2762                 }
2763                 break;
2764         default:
2765                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2766                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2767         }
2768
2769         return MEDIA_CONTENT_ERROR_NONE;
2770 }
2771
2772 static int __media_info_destroy(media_info_h media)
2773 {
2774         int ret = MEDIA_CONTENT_ERROR_NONE;
2775         media_info_s *_media = (media_info_s*)media;
2776
2777         if (_media) {
2778                 SAFE_FREE(_media->media_id);
2779                 SAFE_FREE(_media->file_path);
2780                 SAFE_FREE(_media->display_name);
2781                 SAFE_FREE(_media->mime_type);
2782                 SAFE_FREE(_media->thumbnail_path);
2783                 SAFE_FREE(_media->description);
2784                 SAFE_FREE(_media->author);
2785                 SAFE_FREE(_media->provider);
2786                 SAFE_FREE(_media->content_name);
2787                 SAFE_FREE(_media->category);
2788                 SAFE_FREE(_media->location_tag);
2789                 SAFE_FREE(_media->age_rating);
2790                 SAFE_FREE(_media->keyword);
2791                 SAFE_FREE(_media->title);
2792                 SAFE_FREE(_media->weather);
2793                 SAFE_FREE(_media->storage_uuid);
2794
2795                 if (_media->image_meta) {
2796                         SAFE_FREE(_media->image_meta->media_id);
2797                         SAFE_FREE(_media->image_meta->date_taken);
2798                         SAFE_FREE(_media->image_meta->burst_id);
2799                         SAFE_FREE(_media->image_meta->exposure_time);
2800                         SAFE_FREE(_media->image_meta->model);
2801                         SAFE_FREE(_media->image_meta->title);
2802                         SAFE_FREE(_media->image_meta->weather);
2803
2804                         SAFE_FREE(_media->image_meta);
2805                 }
2806
2807                 if (_media->video_meta) {
2808                         SAFE_FREE(_media->video_meta->media_id);
2809                         SAFE_FREE(_media->video_meta->title);
2810                         SAFE_FREE(_media->video_meta->album);
2811                         SAFE_FREE(_media->video_meta->artist);
2812                         SAFE_FREE(_media->video_meta->album_artist);
2813                         SAFE_FREE(_media->video_meta->genre);
2814                         SAFE_FREE(_media->video_meta->composer);
2815                         SAFE_FREE(_media->video_meta->year);
2816                         SAFE_FREE(_media->video_meta->recorded_date);
2817                         SAFE_FREE(_media->video_meta->copyright);
2818                         SAFE_FREE(_media->video_meta->track_num);
2819
2820                         SAFE_FREE(_media->video_meta);
2821                 }
2822
2823                 if (_media->audio_meta) {
2824                         SAFE_FREE(_media->audio_meta->media_id);
2825                         SAFE_FREE(_media->audio_meta->title);
2826                         SAFE_FREE(_media->audio_meta->album);
2827                         SAFE_FREE(_media->audio_meta->artist);
2828                         SAFE_FREE(_media->audio_meta->album_artist);
2829                         SAFE_FREE(_media->audio_meta->genre);
2830                         SAFE_FREE(_media->audio_meta->composer);
2831                         SAFE_FREE(_media->audio_meta->year);
2832                         SAFE_FREE(_media->audio_meta->recorded_date);
2833                         SAFE_FREE(_media->audio_meta->copyright);
2834                         SAFE_FREE(_media->audio_meta->track_num);
2835
2836                         SAFE_FREE(_media->audio_meta);
2837                 }
2838
2839                 ret = MEDIA_CONTENT_ERROR_NONE;
2840         } else {
2841                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2842                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2843         }
2844
2845         return ret;
2846 }
2847
2848 int media_info_insert_to_db_with_data(media_info_h media)
2849 {
2850         int ret = MEDIA_CONTENT_ERROR_NONE;
2851
2852         media_info_s *_media = (media_info_s*)media;
2853
2854         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
2855         media_content_retvm_if(!STRING_VALID(_media->file_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid file_path");
2856         media_content_retvm_if(!STRING_VALID(_media->storage_uuid), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid storage_uuid");
2857         media_content_retvm_if(_media->storage_type < 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid storage_type [%d]", _media->storage_type);
2858
2859         /* Cloud Item should be filled whole info*/
2860         if (_media->storage_type == MEDIA_CONTENT_STORAGE_CLOUD) {
2861                 media_content_retvm_if(!STRING_VALID(_media->mime_type), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid mime_type");
2862                 media_content_retvm_if(!STRING_VALID(_media->title), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid title");
2863                 media_content_retvm_if(_media->size <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid size [%d]", _media->size);
2864                 media_content_retvm_if(_media->modified_time <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid modified_time [%d]", _media->modified_time);
2865
2866                 if ((_media->media_type < MEDIA_CONTENT_TYPE_IMAGE) || (_media->media_type > MEDIA_CONTENT_TYPE_OTHERS)) {
2867                         media_content_error("invalid media type [%d]", _media->media_type);
2868                         return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2869                 }
2870         }
2871
2872         media_content_sec_debug("storage[%d], path[%s], media_type[%d]", _media->storage_type, _media->file_path, _media->media_type);
2873
2874         media_svc_content_info_s *svc_content_info = NULL;
2875
2876         ret = __media_info_map_data_usr_to_svc(_media, &svc_content_info, _media->storage_type);
2877         media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "__media_info_map_data_usr_to_svc fail");
2878
2879         ret = media_svc_insert_item_immediately_with_data(_content_get_db_handle(), svc_content_info, tzplatform_getuid(TZ_USER_NAME));
2880         if (ret != MS_MEDIA_ERR_NONE) {
2881                 media_content_sec_error("media_svc_insert_item_immediately_with_data failed : %d (%s)", ret, _media->file_path);
2882                 media_svc_destroy_content_info(svc_content_info);
2883                 SAFE_FREE(svc_content_info);
2884                 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2885         }
2886         /*free the svc_content_info*/
2887         media_svc_destroy_content_info(svc_content_info);
2888         SAFE_FREE(svc_content_info);
2889
2890         /*Fill out the handle*/
2891         char *media_file_path = g_strdup(_media->file_path);
2892         char *media_string_uuid = g_strdup(_media->storage_uuid);
2893
2894         __media_info_destroy(media);
2895         ret = _media_info_get_media_info_from_db(media_file_path, media_string_uuid, media);
2896         if (ret != MEDIA_CONTENT_ERROR_NONE)
2897                 media_content_error("_media_info_get_media_info_from_db fail", ret);
2898
2899         SAFE_FREE(media_file_path);
2900         SAFE_FREE(media_string_uuid);
2901
2902         return ret;
2903 }
2904
2905 int media_info_create(const char *path, media_info_h *media)
2906 {
2907         int ret = MEDIA_CONTENT_ERROR_NONE;
2908         char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
2909         media_svc_storage_type_e storage_type = 0;
2910
2911         media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
2912         media_content_retvm_if(media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
2913
2914         memset(storage_id, 0x00, sizeof(storage_id));
2915
2916         if (STRING_VALID(MEDIA_ROOT_PATH_CLOUD) && (strstr(MEDIA_ROOT_PATH_CLOUD, path) == NULL)) {
2917                 bool ignore_file = FALSE;
2918                 bool ignore_dir = FALSE;
2919                 char *folder_path = NULL;
2920
2921                 ret = _media_util_check_ignore_file(path, &ignore_file);
2922                 media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
2923
2924                 ret = _media_util_check_file_exist(path);
2925                 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
2926
2927                 folder_path = g_path_get_dirname(path);
2928                 ret = _media_util_check_ignore_dir(folder_path, &ignore_dir);
2929                 SAFE_FREE(folder_path);
2930                 media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
2931
2932                 ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id);
2933                 if (ret != MS_MEDIA_ERR_NONE) {
2934                         media_content_error("media_svc_get_storage_id failed : %d", ret);
2935                         return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2936                 }
2937
2938                 ret = media_svc_get_storage_type(path, &storage_type, tzplatform_getuid(TZ_USER_NAME));
2939                 if (ret != MS_MEDIA_ERR_NONE) {
2940                         media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
2941                         return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2942                 }
2943         }
2944
2945         media_info_s *_media = (media_info_s*)calloc(1, sizeof(media_info_s));
2946         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2947
2948         _media->audio_meta = (audio_meta_s *)calloc(1, sizeof(audio_meta_s));
2949         if (_media->audio_meta == NULL) {
2950                 SAFE_FREE(_media);
2951                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
2952                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
2953         }
2954
2955         _media->video_meta = (video_meta_s *)calloc(1, sizeof(video_meta_s));
2956         if (_media->video_meta == NULL) {
2957                 SAFE_FREE(_media->audio_meta);
2958                 SAFE_FREE(_media);
2959                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
2960                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
2961         }
2962
2963         _media->image_meta = (image_meta_s *)calloc(1, sizeof(image_meta_s));
2964         if (_media->image_meta == NULL) {
2965                 SAFE_FREE(_media->audio_meta);
2966                 SAFE_FREE(_media->video_meta);
2967                 SAFE_FREE(_media);
2968                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
2969                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
2970         }
2971
2972         _media->file_path = g_strdup(path);
2973         _media->storage_type = -1;
2974         _media->media_type = 0;
2975         _media->modified_time = 0;
2976         _media->size = 0;
2977         _media->longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
2978         _media->latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
2979         _media->altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
2980
2981         if (STRING_VALID(storage_id)) {
2982                 _media->storage_uuid = g_strdup(storage_id);
2983                 _media->storage_type = storage_type;
2984         }
2985
2986         *media = (media_info_h)_media;
2987
2988         return ret;
2989 }
2990
2991 int media_info_set_path(media_info_h media, const char *path)
2992 {
2993         return __media_info_set_str_data(media, MEDIA_INFO_PATH, path);
2994 }
2995
2996 int media_info_set_mime_type(media_info_h media, const char *mime_type)
2997 {
2998         return __media_info_set_str_data(media, MEDIA_INFO_MIME_TYPE, mime_type);
2999 }
3000
3001 int media_info_set_title(media_info_h media, const char *title)
3002 {
3003         return __media_info_set_str_data(media, MEDIA_INFO_TITLE, title);
3004 }
3005
3006 int media_info_set_album(media_info_h media, const char *album)
3007 {
3008         return __media_info_set_str_data(media, MEDIA_INFO_ALBUM, album);
3009 }
3010
3011 int media_info_set_artist(media_info_h media, const char *artist)
3012 {
3013         return __media_info_set_str_data(media, MEDIA_INFO_ARTIST, artist);
3014 }
3015
3016 int media_info_set_genre(media_info_h media, const char *genre)
3017 {
3018         return __media_info_set_str_data(media, MEDIA_INFO_GENRE, genre);
3019 }
3020
3021 int media_info_set_recorded_date(media_info_h media, const char *recorded_date)
3022 {
3023         return __media_info_set_str_data(media, MEDIA_INFO_RECORDED_DATE, recorded_date);
3024 }
3025
3026 int media_info_set_thumbnail_path(media_info_h media, const char *thumbnail_path)
3027 {
3028         return __media_info_set_str_data(media, MEDIA_INFO_THUMBNAIL_PATH, thumbnail_path);
3029 }
3030
3031 int media_info_set_storage_id(media_info_h media, const char *storage_id)
3032 {
3033         return __media_info_set_str_data(media, MEDIA_INFO_STORAGE_UUID, storage_id);
3034 }
3035
3036 int media_info_set_size(media_info_h media, unsigned long long size)
3037 {
3038         media_info_s *_media = (media_info_s*)media;
3039
3040         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3041
3042         _media->size = size;
3043
3044         return MEDIA_CONTENT_ERROR_NONE;
3045 }
3046
3047 int media_info_set_modified_time(media_info_h media, time_t modified_time)
3048 {
3049         media_info_s *_media = (media_info_s*)media;
3050
3051         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3052
3053         _media->modified_time = modified_time;
3054
3055         return MEDIA_CONTENT_ERROR_NONE;
3056 }
3057
3058 int media_info_set_media_type(media_info_h media, media_content_type_e type)
3059 {
3060         media_info_s *_media = (media_info_s*)media;
3061
3062         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3063
3064         _media->media_type = type;
3065
3066         return MEDIA_CONTENT_ERROR_NONE;
3067 }
3068
3069 int media_info_set_duration(media_info_h media, int duration)
3070 {
3071         media_info_s *_media = (media_info_s*)media;
3072
3073         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3074
3075         if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3076                 _media->video_meta->duration = duration;
3077         else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND))
3078                 _media->audio_meta->duration = duration;
3079         else {
3080                 media_content_error("Invalid media type");
3081                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3082         }
3083
3084         return MEDIA_CONTENT_ERROR_NONE;
3085 }
3086
3087 int media_info_set_width(media_info_h media, int width)
3088 {
3089         media_info_s *_media = (media_info_s*)media;
3090
3091         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3092
3093         if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3094                 _media->video_meta->width = width;
3095         else if (_media->media_type == MEDIA_CONTENT_TYPE_IMAGE)
3096                 _media->image_meta->width = width;
3097         else {
3098                 media_content_error("Invalid media type");
3099                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3100         }
3101
3102         return MEDIA_CONTENT_ERROR_NONE;
3103 }
3104
3105 int media_info_set_height(media_info_h media, int height)
3106 {
3107         media_info_s *_media = (media_info_s*)media;
3108
3109         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3110
3111         if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3112                 _media->video_meta->height = height;
3113         else if (_media->media_type == MEDIA_CONTENT_TYPE_IMAGE)
3114                 _media->image_meta->height = height;
3115         else {
3116                 media_content_error("Invalid media type");
3117                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3118         }
3119
3120         return MEDIA_CONTENT_ERROR_NONE;
3121 }
3122
3123 int media_info_set_storage_type(media_info_h media, media_content_storage_e storage_type)
3124 {
3125         media_info_s *_media = (media_info_s*)media;
3126
3127         media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3128
3129         _media->storage_type = storage_type;
3130
3131         return MEDIA_CONTENT_ERROR_NONE;
3132 }