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