merge with master
[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 <unistd.h>
18 #include <media_content.h>
19 #include <media-thumbnail.h>
20 #include <media_info_private.h>
21 #include <media_util_private.h>
22 #include <media-svc.h>
23 #include <media-util.h>
24
25 static int __media_info_get_media_info_from_db(char *path, media_info_h media);
26 static void __media_info_insert_completed_cb(media_request_result_s *result, void *user_data);
27 static void __media_info_thumbnail_completed_cb(int error, const char *path, void *user_data);
28 static bool __media_info_delete_batch_cb(media_info_h media, void *user_data);
29 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);
30
31 static int __media_info_get_media_info_from_db(char *path, media_info_h media)
32 {
33         int ret = MEDIA_CONTENT_ERROR_NONE;
34         sqlite3_stmt *stmt = NULL;
35         char *select_query = NULL;
36         media_info_s *_media = (media_info_s*)media;
37
38         if(_media == NULL)
39         {
40                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
41                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
42         }
43
44         select_query = sqlite3_mprintf(SELECT_MEDIA_BY_PATH, path);
45
46         ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
47         sqlite3_free(select_query);
48         media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
49
50         if(sqlite3_step(stmt) == SQLITE_ROW)
51         {
52                 _media_info_item_get_detail(stmt, (media_info_h)_media);
53                 media_content_debug("New Media ID: %s", _media->media_id);
54         } else {
55                 media_content_debug("There's no media!!");
56         }
57 /*
58         while(sqlite3_step(stmt) == SQLITE_ROW)
59         {
60                 _media_info_item_get_detail(stmt, (media_info_h)_media);
61                 media_content_debug("New Media ID: %s", _media->media_id);
62         }
63 */
64         SQLITE3_FINALIZE(stmt);
65
66         return ret;
67 }
68
69 static int __media_info_get_media_path_by_id_from_db(const char *media_id, char **path)
70 {
71         int ret = MEDIA_CONTENT_ERROR_NONE;
72         sqlite3_stmt *stmt = NULL;
73         char *select_query = NULL;
74
75         if(!STRING_VALID(media_id))
76         {
77                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
78                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
79         }
80
81         select_query = sqlite3_mprintf(SELECT_MEDIA_PATH_BY_ID, media_id);
82
83         ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
84         sqlite3_free(select_query);
85         media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
86
87         if(sqlite3_step(stmt) == SQLITE_ROW)
88         {
89                 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0)))
90                         *path = strdup((const char *)sqlite3_column_text(stmt, 0));
91         } else {
92                 media_content_debug("There's no media with this ID : %s", media_id);
93                 *path = NULL;
94                 ret = MEDIA_CONTENT_ERROR_DB_FAILED;
95         }
96
97         SQLITE3_FINALIZE(stmt);
98
99         return ret;
100 }
101
102 static void __media_info_insert_completed_cb(media_request_result_s *result, void *user_data)
103 {
104         int ret = MEDIA_CONTENT_ERROR_NONE;
105         media_insert_cb_s *_cb_data = (media_insert_cb_s *)user_data;
106
107         if (_cb_data && _cb_data->insert_completed_cb) {
108                 if (result) {
109                         ret = _content_error_capi(MEDIA_CONTENT_TYPE, result->result);
110                 }
111
112                 _cb_data->insert_completed_cb(ret, _cb_data->user_data);
113
114                 if (STRING_VALID(_cb_data->insert_list_path)) {
115                         if (unlink(_cb_data->insert_list_path) < 0) {
116                                 media_content_error("failed to delete : %s", strerror(errno));
117                         }
118                         SAFE_FREE(_cb_data->insert_list_path);
119                 }
120         }
121
122         SAFE_FREE(_cb_data);
123
124         return;
125 }
126
127 static void __media_info_thumbnail_completed_cb(int error, const char *path, void *user_data)
128 {
129         int error_value = MEDIA_CONTENT_ERROR_NONE;
130
131         media_thumbnail_cb_s *_thumb_cb = (media_thumbnail_cb_s *)user_data;
132         media_info_s *media = NULL;
133
134         if(_thumb_cb != NULL)
135         {
136                 media = _thumb_cb->handle;
137                 if((media != NULL) && STRING_VALID(path))
138                 {
139                         SAFE_FREE(media->thumbnail_path);
140                         media->thumbnail_path = strdup(path);
141                 }
142
143                 media_content_debug("error [%d], thumbnail_path [%s]", error, path);
144                 error_value = _content_error_capi(MEDIA_THUMBNAIL_TYPE, error);
145                 if (_thumb_cb->thumbnail_completed_cb)
146                         _thumb_cb->thumbnail_completed_cb(error_value, path, _thumb_cb->user_data);
147         }
148
149         SAFE_FREE(_thumb_cb);
150
151         return;
152 }
153
154 static bool __media_info_delete_batch_cb(media_info_h media, void *user_data)
155 {
156         char *thumb_path = NULL;
157         media_content_type_e media_type = 0;
158
159         if(media == NULL)
160         {
161                 media_content_debug("NO Item \n");
162                 return true;
163         }
164
165         media_info_get_media_type(media, &media_type);
166         media_content_debug("media_type : [%d] \n", media_type);
167
168         media_info_get_thumbnail_path(media, &thumb_path);
169         if (STRING_VALID(thumb_path)) {
170                 if (strncmp(MEDIA_CONTENT_THUMB_DEFAULT_PATH, thumb_path, strlen(MEDIA_CONTENT_THUMB_DEFAULT_PATH)) != 0) {
171                         media_content_debug("Deleting thumbnail : [%s] \n", thumb_path);
172                         if (unlink(thumb_path) < 0) {
173                                 media_content_error("failed to delete : %s", strerror(errno));
174                         }
175                 }
176
177                 SAFE_FREE(thumb_path);
178         }
179
180         return true;
181 }
182
183 void _media_info_item_get_detail(sqlite3_stmt* stmt, media_info_h media)
184 {
185 //#define MEDIA_INFO_ITEM "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, thumbnail_path, description,
186 //                                                      rating, favourite, author, provider, content_name, category, location_tag, age_rating, keyword, is_drm, storage_type, longitude, latitude, altitude, width, height, datetaken, orientation, title, album, artist, genre, composer, year, recorded_date, copyright, track_num, bitrate, duration, played_count, last_played_time, last_played_position, samplerate, channel"
187
188         media_info_s *_media = (media_info_s*)media;
189
190         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0)))
191                 _media->media_id = strdup((const char *)sqlite3_column_text(stmt, 0));
192
193         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1)))
194                 _media->file_path = strdup((const char *)sqlite3_column_text(stmt, 1));
195
196         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 2)))
197                 _media->display_name = strdup((const char *)sqlite3_column_text(stmt, 2));
198
199         _media->media_type = (int)sqlite3_column_int(stmt, 3);
200
201         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 4)))
202                 _media->mime_type = strdup((const char *)sqlite3_column_text(stmt, 4));
203
204         _media->size = (unsigned long long)sqlite3_column_int64(stmt, 5);
205
206         _media->added_time = (int)sqlite3_column_int(stmt, 6);
207
208         _media->modified_time = (int)sqlite3_column_int(stmt, 7);
209
210         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 8)))
211                 _media->thumbnail_path= strdup((const char *)sqlite3_column_text(stmt, 8));
212
213         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 9)))
214                 _media->description = strdup((const char *)sqlite3_column_text(stmt, 9));
215
216         _media->rating = (int)sqlite3_column_int(stmt,10);
217
218         _media->favourite = (int)sqlite3_column_int(stmt, 11);
219
220         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 12)))
221                 _media->author = strdup((const char *)sqlite3_column_text(stmt, 12));
222
223         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 13)))
224                 _media->provider = strdup((const char *)sqlite3_column_text(stmt, 13));
225
226         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 14)))
227                 _media->content_name = strdup((const char *)sqlite3_column_text(stmt, 14));
228
229         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 15)))
230                 _media->category = strdup((const char *)sqlite3_column_text(stmt, 15));
231
232         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 16)))
233                 _media->location_tag = strdup((const char *)sqlite3_column_text(stmt, 16));
234
235         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 17)))
236                 _media->age_rating = strdup((const char *)sqlite3_column_text(stmt, 17));
237
238         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 18)))
239                 _media->keyword = strdup((const char *)sqlite3_column_text(stmt, 18));
240
241         _media->is_drm = (int)sqlite3_column_int(stmt, 19);
242
243         _media->storage_type = (int)sqlite3_column_int(stmt, 20);
244
245         _media->longitude = (double)sqlite3_column_double(stmt, 21);
246         _media->latitude = (double)sqlite3_column_double(stmt, 22);
247         _media->altitude = (double)sqlite3_column_double(stmt, 23);
248
249         if(_media->media_type == MEDIA_CONTENT_TYPE_IMAGE) {
250                 _media->image_meta = (image_meta_s *)calloc(1, sizeof(image_meta_s));
251                 if(_media->image_meta) {
252                         if(STRING_VALID(_media->media_id))
253                                 _media->image_meta->media_id = strdup(_media->media_id);
254
255                         _media->image_meta->width = sqlite3_column_int(stmt, 24);
256                         _media->image_meta->height = sqlite3_column_int(stmt, 25);
257
258                         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 26)))
259                                 _media->image_meta->date_taken = strdup((const char *)sqlite3_column_text(stmt, 26));
260                 
261                         _media->image_meta->orientation = sqlite3_column_int(stmt, 27);
262
263                         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 44)))
264                                 _media->image_meta->burst_id = strdup((const char *)sqlite3_column_text(stmt, 44));
265                 }
266
267         } else if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
268                 _media->video_meta = (video_meta_s *)calloc(1, sizeof(video_meta_s));
269                 if(_media->video_meta) {
270                         if(STRING_VALID(_media->media_id))
271                                 _media->video_meta->media_id = strdup(_media->media_id);
272
273                         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 28)))
274                                 _media->video_meta->title = strdup((const char *)sqlite3_column_text(stmt, 28));
275
276                         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 29)))
277                                 _media->video_meta->album = strdup((const char *)sqlite3_column_text(stmt, 29));
278
279                         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 30)))
280                                 _media->video_meta->artist = strdup((const char *)sqlite3_column_text(stmt, 30));
281
282                         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 31)))
283                                 _media->video_meta->genre = strdup((const char *)sqlite3_column_text(stmt, 31));
284
285                         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 32)))
286                                 _media->video_meta->composer = strdup((const char *)sqlite3_column_text(stmt, 32));
287
288                         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 33)))
289                                 _media->video_meta->year = strdup((const char *)sqlite3_column_text(stmt, 33));
290
291                         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 34)))
292                                 _media->video_meta->recorded_date = strdup((const char *)sqlite3_column_text(stmt, 34));
293
294                         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 35)))
295                                 _media->video_meta->copyright = strdup((const char *)sqlite3_column_text(stmt, 35));
296
297                         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 36)))
298                                 _media->video_meta->track_num = strdup((const char *)sqlite3_column_text(stmt, 36));
299
300                         _media->video_meta->bitrate = sqlite3_column_int(stmt, 37);
301                         _media->video_meta->duration = sqlite3_column_int(stmt, 38);
302                         _media->video_meta->played_count = sqlite3_column_int(stmt, 39);
303                         _media->video_meta->played_time = sqlite3_column_int(stmt, 40);
304                         _media->video_meta->played_position = sqlite3_column_int(stmt, 41);
305                         _media->video_meta->width = sqlite3_column_int(stmt, 24);
306                         _media->video_meta->height = sqlite3_column_int(stmt, 25);
307                 }
308
309         }
310         else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) {
311                 _media->audio_meta = (audio_meta_s *)calloc(1, sizeof(audio_meta_s));
312                 if(_media->audio_meta) {
313                         if(STRING_VALID(_media->media_id))
314                                 _media->audio_meta->media_id = strdup(_media->media_id);
315
316                         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 28)))
317                                 _media->audio_meta->title = strdup((const char *)sqlite3_column_text(stmt, 28));
318
319                         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 29)))
320                                 _media->audio_meta->album = strdup((const char *)sqlite3_column_text(stmt, 29));
321
322                         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 30)))
323                                 _media->audio_meta->artist = strdup((const char *)sqlite3_column_text(stmt, 30));
324
325                         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 31)))
326                                 _media->audio_meta->genre = strdup((const char *)sqlite3_column_text(stmt, 31));
327
328                         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 32)))
329                                 _media->audio_meta->composer = strdup((const char *)sqlite3_column_text(stmt, 32));
330
331                         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 33)))
332                                 _media->audio_meta->year = strdup((const char *)sqlite3_column_text(stmt, 33));
333
334                         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 34)))
335                                 _media->audio_meta->recorded_date = strdup((const char *)sqlite3_column_text(stmt, 34));
336
337                         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 35)))
338                                 _media->audio_meta->copyright = strdup((const char *)sqlite3_column_text(stmt, 35));
339
340                         if(STRING_VALID((const char *)sqlite3_column_text(stmt, 36)))
341                                 _media->audio_meta->track_num = strdup((const char *)sqlite3_column_text(stmt, 36));
342
343                         _media->audio_meta->bitrate = sqlite3_column_int(stmt, 37);
344                         _media->audio_meta->duration = sqlite3_column_int(stmt, 38);
345                         _media->audio_meta->played_count = sqlite3_column_int(stmt, 39);
346                         _media->audio_meta->played_time = sqlite3_column_int(stmt, 40);
347                         _media->audio_meta->played_position = sqlite3_column_int(stmt, 41);
348                         _media->audio_meta->samplerate = sqlite3_column_int(stmt, 42);
349                         _media->audio_meta->channel = sqlite3_column_int(stmt, 43);
350                 }
351
352         }
353 }
354
355 int media_info_insert_to_db (const char *path, media_info_h *info)
356 {
357         int ret = MEDIA_CONTENT_ERROR_NONE;
358
359         if(!STRING_VALID(path))
360         {
361                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
362                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
363         }
364
365         if(info == NULL)
366         {
367                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
368                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
369         }
370
371 #if 0
372         media_content_debug("Register: %s", path);
373         ret = media_file_register(path);
374         if(ret != MS_MEDIA_ERR_NONE)
375         {
376                 media_content_error("media_file_register failed");
377                 return _content_error_capi(MEDIA_REGISTER_TYPE, ret);
378         }
379
380 #else
381         ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), path);
382         if (ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) {
383                 media_content_debug("media_svc_check_item_exist_by_path : no record : %s", path);
384
385                 media_svc_media_type_e media_type;
386                 media_svc_storage_type_e storage_type;
387                 char mime_type[255] = {0, };
388
389                 ret = media_svc_get_storage_type(path, &storage_type);
390                 if (ret < 0) {
391                         media_content_error("media_svc_get_storage_type failed : %d (%s)", ret, path);
392                         return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
393                 }
394
395                 ret = media_svc_get_mime_type(path, mime_type);
396                 if (ret < 0) {
397                         media_content_error("media_svc_get_mime_type failed : %d (%s)", ret, path);
398                         return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
399                 }
400
401                 ret = media_svc_get_media_type(path, mime_type, &media_type);
402                 if (ret < 0) {
403                         media_content_error("media_svc_get_media_type failed : %d (%s)", ret, path);
404                         return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
405                 }
406
407                 media_content_debug("media_svc_insert_item_immediately: %s", path);
408                 ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_type, path, mime_type, media_type);
409
410                 if (ret < 0) {
411                         media_content_error("media_svc_insert_item_immediately failed : %d (%s)", ret, path);
412                         return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
413                 }
414         } else if (ret != MEDIA_INFO_ERROR_NONE) {
415                 media_content_error("media_svc_check_item_exist_by_path failed : %d (%s)", ret, path);
416                 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
417         }
418 #endif
419
420         media_info_s *_media = (media_info_s*)calloc(1, sizeof(media_info_s));
421         if(_media == NULL)
422         {
423                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
424                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
425         }
426
427         _media->file_path = strdup(path);
428         if(_media->file_path == NULL)
429         {
430                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
431                 SAFE_FREE(_media);
432                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
433         }
434
435         ret = __media_info_get_media_info_from_db(_media->file_path, (media_info_h)_media);
436
437         *info = (media_info_h)_media;
438         return ret;
439 }
440
441 static int __media_info_insert_batch(media_batch_insert_e insert_type, const char **path_array,
442                                         unsigned int array_length,
443                                         media_insert_completed_cb completed_cb,
444                                         void *user_data)
445 {
446         int ret = MEDIA_CONTENT_ERROR_NONE;
447         FILE *fp = NULL;
448         char list_path[255] = {0,};
449         int idx = 0;
450         int nwrites = 0;
451
452         for (idx = 0; idx < BATCH_REQUEST_MAX; idx++) {
453                 snprintf(list_path, sizeof(list_path), "%s/request-%ld-%d", MEDIA_CONTENT_INSERT_FILES_PATH, media_content_gettid(), idx);
454
455                 if (g_file_test(list_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
456                         memset(list_path, 0x00, sizeof(list_path));
457                         continue;
458                 } else {
459                         media_content_debug("The request file list path : %s", list_path);
460                         break;
461                 }
462         }
463
464         if (idx == BATCH_REQUEST_MAX) {
465                 media_content_error("Too many batch request for one thread");
466                 return MEDIA_CONTENT_ERROR_DB_BUSY;
467         }
468
469         fp = fopen(list_path, "w");
470         if (fp == NULL) {
471                 media_content_error("failed to open file : %s [%s]", list_path, strerror(errno));
472                 return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
473         }
474
475         for (idx = 0; idx < array_length; idx++) {
476                 if (STRING_VALID(path_array[idx])) {
477                         int size = strlen(path_array[idx]);
478
479                         nwrites = fwrite(path_array[idx], 1, size, fp);
480                         if (nwrites != size) {
481                                 media_content_error("failed to write thumbnail : %s", strerror(errno));
482                                 fclose(fp);
483                                 if (unlink(list_path) < 0) {
484                                         media_content_error("failed to delete : %s", strerror(errno));
485                                 }
486                                 return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
487                         }
488
489                         nwrites = fwrite("\n", 1, 1, fp);
490                         if (nwrites != 1) {
491                                 media_content_error("failed to write thumbnail : %s", strerror(errno));
492                                 fclose(fp);
493                                 if (unlink(list_path) < 0) {
494                                         media_content_error("failed to delete : %s", strerror(errno));
495                                 }
496                                 return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
497                         }
498                 } else {
499                         media_content_error("path[%d] is invalid string", idx);
500                 }
501         }
502
503         fclose(fp);
504
505         media_insert_cb_s *_cb_data = (media_insert_cb_s *)calloc(1, sizeof(media_insert_cb_s));
506         _cb_data->insert_completed_cb = completed_cb;
507         _cb_data->user_data = user_data;
508         _cb_data->insert_list_path = strdup(list_path);
509
510         if(insert_type == MEDIA_BATCH_INSERT_NORMAL)
511                 ret = media_files_register(list_path, __media_info_insert_completed_cb, _cb_data);
512         else if(insert_type == MEDIA_BATCH_INSERT_BURSTSHOT)
513                 ret = media_burstshot_register(list_path, __media_info_insert_completed_cb, _cb_data);
514         else
515                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
516
517         if (ret != MEDIA_CONTENT_ERROR_NONE) {
518                 media_content_error("media_files_register failed : %d", ret);
519                 if (unlink(list_path) < 0) {
520                         media_content_error("failed to delete : %s", strerror(errno));
521                 }
522                 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
523         }
524
525         return ret;
526 }
527
528 int media_info_insert_batch_to_db(
529                                         const char **path_array,
530                                         unsigned int array_length,
531                                         media_insert_completed_cb completed_cb,
532                                         void *user_data)
533 {
534         if (path_array == NULL)
535         {
536                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
537                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
538         }
539
540         if (array_length <= 0)
541         {
542                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
543                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
544         }
545
546         return __media_info_insert_batch(MEDIA_BATCH_INSERT_NORMAL, path_array, array_length, completed_cb, user_data);
547 }
548
549 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)
550 {
551         if (path_array == NULL)
552         {
553                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
554                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
555         }
556
557         if (array_length <= 0)
558         {
559                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
560                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
561         }
562
563         return __media_info_insert_batch(MEDIA_BATCH_INSERT_BURSTSHOT, path_array, array_length, callback, user_data);
564 }
565
566 int media_info_delete_from_db(const char *media_id)
567 {
568         int ret = MEDIA_CONTENT_ERROR_NONE;
569
570         if(!STRING_VALID(media_id))
571         {
572                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
573                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
574         }
575
576 #if 0
577         char *query_string = NULL;
578         query_string = sqlite3_mprintf(DELETE_MEDIA_FROM_MEDIA, media_id);
579
580         ret = _content_query_sql(query_string);
581
582         sqlite3_free(query_string);
583
584         return ret;
585 #else
586         char *path = NULL;
587
588         ret = __media_info_get_media_path_by_id_from_db(media_id, &path);
589         if (ret < MEDIA_CONTENT_ERROR_NONE) {
590                 media_content_error("__media_info_get_media_path_by_id_from_db failed : %d", ret);
591                 SAFE_FREE(path);
592                 return ret;
593         }
594
595         ret = media_svc_delete_item_by_path(_content_get_db_handle(), path);
596         SAFE_FREE(path);
597
598         return _content_error_capi(ret,MEDIA_CONTENT_TYPE);
599 #endif
600 }
601
602 int media_info_delete_batch_from_db(filter_h filter)
603 {
604         int ret = MEDIA_CONTENT_ERROR_NONE;
605
606         char *query_string = NULL;
607         filter_s *_filter = NULL;
608         attribute_h attr;
609         char *condition_query = NULL;
610
611         if(filter == NULL)
612         {
613                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
614                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
615         }
616
617         /* Delete thumbnail of each item */
618         ret = _media_db_get_group_item(NULL, filter, __media_info_delete_batch_cb, NULL, MEDIA_GROUP_NONE);
619
620         _filter = (filter_s*)filter;
621         attr = _content_get_attirbute_handle();
622
623         if(_filter->condition)
624         {
625                 ret = _media_filter_attribute_generate(attr, _filter->condition, _filter->condition_collate_type, &condition_query);
626                 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
627         }
628
629         if(STRING_VALID(condition_query))
630         {
631                 query_string = sqlite3_mprintf(DELETE_MEDIA_FROM_MEDIA_BATCH, condition_query);
632         }
633         else
634         {
635                 SAFE_FREE(condition_query);
636                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
637         }
638
639         ret = _content_query_sql(query_string);
640         if (ret == MEDIA_CONTENT_ERROR_NONE) {
641                 /*  Send notification for this
642                         In this case, send noti for internal storage and external storage
643                 */
644                 media_content_debug("Batch deletion is successfull. Send notification for this");
645                 media_db_update_send(getpid(), MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, MEDIA_CONTENT_PATH_PHONE, NULL, -1, NULL);
646                 media_db_update_send(getpid(), MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, MEDIA_CONTENT_PATH_MMC, NULL, -1, NULL);
647         }
648
649         SAFE_FREE(condition_query);
650         sqlite3_free(query_string);
651
652         return ret;
653 }
654
655 int media_info_destroy(media_info_h media)
656 {
657         int ret = MEDIA_CONTENT_ERROR_NONE;
658         media_info_s *_media = (media_info_s*)media;
659
660         if(_media)
661         {
662                 SAFE_FREE(_media->media_id);
663                 SAFE_FREE(_media->file_path);
664                 SAFE_FREE(_media->display_name);
665                 SAFE_FREE(_media->mime_type);
666                 SAFE_FREE(_media->thumbnail_path);
667                 SAFE_FREE(_media->description);
668                 SAFE_FREE(_media->author);
669                 SAFE_FREE(_media->provider);
670                 SAFE_FREE(_media->content_name);
671                 SAFE_FREE(_media->category);
672                 SAFE_FREE(_media->location_tag);
673                 SAFE_FREE(_media->age_rating);
674                 SAFE_FREE(_media->keyword);
675
676                 if(_media->image_meta) {
677                         SAFE_FREE(_media->image_meta->media_id);
678                         SAFE_FREE(_media->image_meta->date_taken);
679                         SAFE_FREE(_media->image_meta->burst_id);
680
681                         SAFE_FREE(_media->image_meta);
682                 } else if(_media->video_meta) {
683                         SAFE_FREE(_media->video_meta->media_id);
684                         SAFE_FREE(_media->video_meta->title);
685                         SAFE_FREE(_media->video_meta->album);
686                         SAFE_FREE(_media->video_meta->artist);
687                         SAFE_FREE(_media->video_meta->genre);
688                         SAFE_FREE(_media->video_meta->composer);
689                         SAFE_FREE(_media->video_meta->year);
690                         SAFE_FREE(_media->video_meta->recorded_date);
691                         SAFE_FREE(_media->video_meta->copyright);
692                         SAFE_FREE(_media->video_meta->track_num);
693
694                         SAFE_FREE(_media->video_meta);
695                 } else if(_media->audio_meta) {
696                         SAFE_FREE(_media->audio_meta->media_id);
697                         SAFE_FREE(_media->audio_meta->title);
698                         SAFE_FREE(_media->audio_meta->album);
699                         SAFE_FREE(_media->audio_meta->artist);
700                         SAFE_FREE(_media->audio_meta->genre);
701                         SAFE_FREE(_media->audio_meta->composer);
702                         SAFE_FREE(_media->audio_meta->year);
703                         SAFE_FREE(_media->audio_meta->recorded_date);
704                         SAFE_FREE(_media->audio_meta->copyright);
705                         SAFE_FREE(_media->audio_meta->track_num);
706
707                         SAFE_FREE(_media->audio_meta);
708                 }
709
710                 SAFE_FREE(_media);
711
712                 ret = MEDIA_CONTENT_ERROR_NONE;
713         }
714         else
715         {
716                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
717                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
718         }
719
720         return ret;
721 }
722
723 int media_info_clone(media_info_h *dst, media_info_h src)
724 {
725         int ret = MEDIA_CONTENT_ERROR_NONE;
726         media_info_s *_src = (media_info_s*)src;
727
728
729         if(_src != NULL)
730         {
731                 media_info_s *_dst = (media_info_s*)calloc(1, sizeof(media_info_s));
732
733                 if(_dst == NULL)
734                 {
735                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
736                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
737                 }
738
739                 if(STRING_VALID(_src->media_id))
740                 {
741                         _dst->media_id = strdup(_src->media_id);
742                         if(_dst->media_id == NULL)
743                         {
744                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
745                                 media_info_destroy((media_info_h)_dst);
746                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
747                         }
748                 }
749                 if(STRING_VALID(_src->file_path))
750                 {
751                         _dst->file_path = strdup(_src->file_path);
752                         if(_dst->file_path == NULL)
753                         {
754                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
755                                 media_info_destroy((media_info_h)_dst);
756                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
757                         }
758                 }
759                 if(STRING_VALID(_src->display_name))
760                 {
761                         _dst->display_name = strdup(_src->display_name);
762                         if(_dst->display_name == NULL)
763                         {
764                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
765                                 media_info_destroy((media_info_h)_dst);
766                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
767                         }
768                 }
769                 if(STRING_VALID(_src->mime_type))
770                 {
771                         _dst->mime_type = strdup(_src->mime_type);
772                         if(_dst->mime_type == NULL)
773                         {
774                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
775                                 media_info_destroy((media_info_h)_dst);
776                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
777                         }
778                 }
779                 if(STRING_VALID(_src->thumbnail_path))
780                 {
781                         _dst->thumbnail_path = strdup(_src->thumbnail_path);
782                         if(_dst->thumbnail_path == NULL)
783                         {
784                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
785                                 media_info_destroy((media_info_h)_dst);
786                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
787                         }
788                 }
789                 if(STRING_VALID(_src->description))
790                 {
791                         _dst->description = strdup(_src->description);
792                         if(_dst->description == NULL)
793                         {
794                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
795                                 media_info_destroy((media_info_h)_dst);
796                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
797                         }
798                 }
799                 if(STRING_VALID(_src->author))
800                 {
801                         _dst->author = strdup(_src->author);
802                         if(_dst->author == NULL)
803                         {
804                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
805                                 media_info_destroy((media_info_h)_dst);
806                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
807                         }
808                 }
809                 if(STRING_VALID(_src->provider))
810                 {
811                         _dst->provider = strdup(_src->provider);
812                         if(_dst->provider == NULL)
813                         {
814                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
815                                 media_info_destroy((media_info_h)_dst);
816                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
817                         }
818                 }
819                 if(STRING_VALID(_src->content_name))
820                 {
821                         _dst->content_name = strdup(_src->content_name);
822                         if(_dst->content_name == NULL)
823                         {
824                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
825                                 media_info_destroy((media_info_h)_dst);
826                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
827                         }
828                 }
829                 if(STRING_VALID(_src->category))
830                 {
831                         _dst->category = strdup(_src->category);
832                         if(_dst->category == NULL)
833                         {
834                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
835                                 media_info_destroy((media_info_h)_dst);
836                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
837                         }
838                 }
839                 if(STRING_VALID(_src->location_tag))
840                 {
841                         _dst->location_tag = strdup(_src->location_tag);
842                         if(_dst->location_tag == NULL)
843                         {
844                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
845                                 media_info_destroy((media_info_h)_dst);
846                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
847                         }
848                 }
849                 if(STRING_VALID(_src->age_rating))
850                 {
851                         _dst->age_rating = strdup(_src->age_rating);
852                         if(_dst->age_rating == NULL)
853                         {
854                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
855                                 media_info_destroy((media_info_h)_dst);
856                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
857                         }
858                 }
859                 if(STRING_VALID(_src->keyword))
860                 {
861                         _dst->keyword = strdup(_src->keyword);
862                         if(_dst->keyword == NULL)
863                         {
864                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
865                                 media_info_destroy((media_info_h)_dst);
866                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
867                         }
868                 }
869
870                 _dst->media_type = _src->media_type;
871                 _dst->size = _src->size;
872                 _dst->added_time = _src->added_time;
873                 _dst->modified_time = _src->modified_time;
874                 _dst->longitude = _src->longitude;
875                 _dst->latitude = _src->latitude;
876                 _dst->altitude = _src->altitude;
877                 _dst->rating = _src->rating;
878                 _dst->favourite = _src->favourite;
879                 _dst->is_drm = _src->is_drm;
880                 _dst->storage_type = _src->storage_type;
881
882                 if(_src->media_type == MEDIA_CONTENT_TYPE_IMAGE && _src->image_meta) {
883                         _dst->image_meta = (image_meta_s *)calloc(1, sizeof(image_meta_s));
884                         if(_dst->image_meta == NULL)
885                         {
886                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
887                                 media_info_destroy((media_info_h)_dst);
888                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
889                         }
890
891                         if(STRING_VALID(_src->image_meta->media_id))
892                         {
893                                 _dst->image_meta->media_id = strdup(_src->image_meta->media_id);
894                                 if(_dst->image_meta->media_id == NULL)
895                                 {
896                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
897                                         media_info_destroy((media_info_h)_dst);
898                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
899                                 }
900                         }
901
902                         if(STRING_VALID(_src->image_meta->date_taken))
903                         {
904                                 _dst->image_meta->date_taken = strdup(_src->image_meta->date_taken);
905                                 if(_dst->image_meta->date_taken == NULL)
906                                 {
907                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
908                                         media_info_destroy((media_info_h)_dst);
909                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
910                                 }
911                         }
912
913                         if(STRING_VALID(_src->image_meta->burst_id))
914                         {
915                                 _dst->image_meta->burst_id = strdup(_src->image_meta->burst_id);
916                                 if(_dst->image_meta->burst_id == NULL)
917                                 {
918                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
919                                         media_info_destroy((media_info_h)_dst);
920                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
921                                 }
922                         }
923                         _dst->image_meta->width = _src->image_meta->width;
924                         _dst->image_meta->height = _src->image_meta->height;
925                         _dst->image_meta->orientation = _src->image_meta->orientation;
926
927                 } else if(_src->media_type == MEDIA_CONTENT_TYPE_VIDEO && _src->video_meta) {
928                         _dst->video_meta = (video_meta_s *)calloc(1, sizeof(video_meta_s));
929                         if(_dst->video_meta == NULL)
930                         {
931                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
932                                 media_info_destroy((media_info_h)_dst);
933                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
934                         }
935
936                         if(STRING_VALID(_src->video_meta->media_id))
937                         {
938                                 _dst->video_meta->media_id = strdup(_src->video_meta->media_id);
939                                 if(_dst->video_meta->media_id == NULL)
940                                 {
941                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
942                                         media_info_destroy((media_info_h)_dst);
943                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
944                                 }
945                         }
946                         if(STRING_VALID(_src->video_meta->title))
947                         {
948                                 _dst->video_meta->title = strdup(_src->video_meta->title);
949                                 if(_dst->video_meta->title == NULL)
950                                 {
951                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
952                                         media_info_destroy((media_info_h)_dst);
953                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
954                                 }
955                         }
956                         if(STRING_VALID(_src->video_meta->album))
957                         {
958                                 _dst->video_meta->album = strdup(_src->video_meta->album);
959                                 if(_dst->video_meta->album == NULL)
960                                 {
961                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
962                                         media_info_destroy((media_info_h)_dst);
963                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
964                                 }
965                         }
966                         if(STRING_VALID(_src->video_meta->artist))
967                         {
968                                 _dst->video_meta->artist = strdup(_src->video_meta->artist);
969                                 if(_dst->video_meta->artist == NULL)
970                                 {
971                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
972                                         media_info_destroy((media_info_h)_dst);
973                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
974                                 }
975                         }
976                         if(STRING_VALID(_src->video_meta->genre))
977                         {
978                                 _dst->video_meta->genre = strdup(_src->video_meta->genre);
979                                 if(_dst->video_meta->genre == NULL)
980                                 {
981                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
982                                         media_info_destroy((media_info_h)_dst);
983                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
984                                 }
985                         }
986                         if(STRING_VALID(_src->video_meta->composer))
987                         {
988                                 _dst->video_meta->composer = strdup(_src->video_meta->composer);
989                                 if(_dst->video_meta->composer == 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->video_meta->year))
997                         {
998                                 _dst->video_meta->year = strdup(_src->video_meta->year);
999                                 if(_dst->video_meta->year == 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                         if(STRING_VALID(_src->video_meta->recorded_date))
1007                         {
1008                                 _dst->video_meta->recorded_date = strdup(_src->video_meta->recorded_date);
1009                                 if(_dst->video_meta->recorded_date == NULL)
1010                                 {
1011                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1012                                         media_info_destroy((media_info_h)_dst);
1013                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1014                                 }
1015                         }
1016                         if(STRING_VALID(_src->video_meta->copyright))
1017                         {
1018                                 _dst->video_meta->copyright = strdup(_src->video_meta->copyright);
1019                                 if(_dst->video_meta->copyright == NULL)
1020                                 {
1021                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1022                                         media_info_destroy((media_info_h)_dst);
1023                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1024                                 }
1025                         }
1026                         if(STRING_VALID(_src->video_meta->track_num))
1027                         {
1028                                 _dst->video_meta->track_num = strdup(_src->video_meta->track_num);
1029                                 if(_dst->video_meta->track_num == NULL)
1030                                 {
1031                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1032                                         media_info_destroy((media_info_h)_dst);
1033                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1034                                 }
1035                         }
1036
1037                         _dst->video_meta->width = _src->video_meta->width;
1038                         _dst->video_meta->height = _src->video_meta->height;
1039                         _dst->video_meta->duration = _src->video_meta->duration;
1040                         _dst->video_meta->bitrate = _src->video_meta->bitrate;
1041                         _dst->video_meta->played_count = _src->video_meta->played_count;
1042                         _dst->video_meta->played_time = _src->video_meta->played_time;
1043                         _dst->video_meta->played_position = _src->video_meta->played_position;
1044
1045                 } else if((_src->media_type == MEDIA_CONTENT_TYPE_MUSIC || _src->media_type == MEDIA_CONTENT_TYPE_SOUND) && _src->audio_meta) {
1046                         _dst->audio_meta = (audio_meta_s *)calloc(1, sizeof(audio_meta_s));
1047                         if(_dst->audio_meta == NULL)
1048                         {
1049                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1050                                 media_info_destroy((media_info_h)_dst);
1051                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1052                         }
1053
1054                         if(STRING_VALID(_src->audio_meta->media_id))
1055                         {
1056                                 _dst->audio_meta->media_id = strdup(_src->audio_meta->media_id);
1057                                 if(_dst->audio_meta->media_id == NULL)
1058                                 {
1059                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1060                                         media_info_destroy((media_info_h)_dst);
1061                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1062                                 }
1063                         }
1064                         if(STRING_VALID(_src->audio_meta->title))
1065                         {
1066                                 _dst->audio_meta->title = strdup(_src->audio_meta->title);
1067                                 if(_dst->audio_meta->title == NULL)
1068                                 {
1069                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1070                                         media_info_destroy((media_info_h)_dst);
1071                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1072                                 }
1073                         }
1074                         if(STRING_VALID(_src->audio_meta->album))
1075                         {
1076                                 _dst->audio_meta->album = strdup(_src->audio_meta->album);
1077                                 if(_dst->audio_meta->album == NULL)
1078                                 {
1079                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1080                                         media_info_destroy((media_info_h)_dst);
1081                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1082                                 }
1083                         }
1084                         if(STRING_VALID(_src->audio_meta->artist))
1085                         {
1086                                 _dst->audio_meta->artist = strdup(_src->audio_meta->artist);
1087                                 if(_dst->audio_meta->artist == NULL)
1088                                 {
1089                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1090                                         media_info_destroy((media_info_h)_dst);
1091                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1092                                 }
1093                         }
1094                         if(STRING_VALID(_src->audio_meta->genre))
1095                         {
1096                                 _dst->audio_meta->genre = strdup(_src->audio_meta->genre);
1097                                 if(_dst->audio_meta->genre == NULL)
1098                                 {
1099                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1100                                         media_info_destroy((media_info_h)_dst);
1101                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1102                                 }
1103                         }
1104                         if(STRING_VALID(_src->audio_meta->composer))
1105                         {
1106                                 _dst->audio_meta->composer = strdup(_src->audio_meta->composer);
1107                                 if(_dst->audio_meta->composer == NULL)
1108                                 {
1109                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1110                                         media_info_destroy((media_info_h)_dst);
1111                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1112                                 }
1113                         }
1114                         if(STRING_VALID(_src->audio_meta->year))
1115                         {
1116                                 _dst->audio_meta->year = strdup(_src->audio_meta->year);
1117                                 if(_dst->audio_meta->year == NULL)
1118                                 {
1119                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1120                                         media_info_destroy((media_info_h)_dst);
1121                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1122                                 }
1123                         }
1124                         if(STRING_VALID(_src->audio_meta->recorded_date))
1125                         {
1126                                 _dst->audio_meta->recorded_date = strdup(_src->audio_meta->recorded_date);
1127                                 if(_dst->audio_meta->recorded_date == NULL)
1128                                 {
1129                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1130                                         media_info_destroy((media_info_h)_dst);
1131                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1132                                 }
1133                         }
1134                         if(STRING_VALID(_src->audio_meta->copyright))
1135                         {
1136                                 _dst->audio_meta->copyright = strdup(_src->audio_meta->copyright);
1137                                 if(_dst->audio_meta->copyright == NULL)
1138                                 {
1139                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1140                                         media_info_destroy((media_info_h)_dst);
1141                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1142                                 }
1143                         }
1144                         if(STRING_VALID(_src->audio_meta->track_num))
1145                         {
1146                                 _dst->audio_meta->track_num = strdup(_src->audio_meta->track_num);
1147                                 if(_dst->audio_meta->track_num == NULL)
1148                                 {
1149                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1150                                         media_info_destroy((media_info_h)_dst);
1151                                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1152                                 }
1153                         }
1154
1155                         _dst->audio_meta->channel = _src->audio_meta->channel;
1156                         _dst->audio_meta->samplerate = _src->audio_meta->samplerate;
1157                         _dst->audio_meta->duration = _src->audio_meta->duration;
1158                         _dst->audio_meta->bitrate = _src->audio_meta->bitrate;
1159                         _dst->audio_meta->played_count = _src->audio_meta->played_count;
1160                         _dst->audio_meta->played_time = _src->audio_meta->played_time;
1161                         _dst->audio_meta->played_position = _src->audio_meta->played_position;
1162
1163                 }
1164                 *dst = (media_info_h)_dst;
1165
1166                 ret = MEDIA_CONTENT_ERROR_NONE;
1167         }
1168         else
1169         {
1170                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1171                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1172         }
1173
1174         return ret;
1175 }
1176
1177 int media_info_get_media_count_from_db(filter_h filter, int *media_count)
1178 {
1179         int ret = MEDIA_CONTENT_ERROR_NONE;
1180
1181         media_content_debug_func();
1182
1183         if(media_count == NULL)
1184         {
1185                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1186                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1187
1188                 return ret;
1189         }
1190
1191         ret = _media_db_get_group_item_count(NULL, filter, MEDIA_GROUP_NONE, media_count);
1192
1193         return ret;
1194 }
1195
1196 int media_info_foreach_media_from_db(filter_h filter, media_info_cb callback, void *user_data)
1197 {
1198         int ret = MEDIA_CONTENT_ERROR_NONE;
1199
1200         media_content_debug_func();
1201
1202         if(callback == NULL)
1203         {
1204                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1205                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1206         }
1207
1208         ret = _media_db_get_group_item(NULL, filter, callback, user_data, MEDIA_GROUP_NONE);
1209
1210         return ret;
1211 }
1212
1213 int media_info_get_tag_count_from_db(const char *media_id, filter_h filter, int *tag_count)
1214 {
1215         int ret = MEDIA_CONTENT_ERROR_NONE;
1216
1217         media_content_debug_func();
1218
1219         if(STRING_VALID(media_id) && tag_count)
1220         {
1221                 ret = _media_db_get_group_item_count(media_id, filter, MEDIA_GROUP_TAG_BY_MEDIA_ID, tag_count);
1222         }
1223         else
1224         {
1225                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1226                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1227         }
1228
1229         return ret;
1230 }
1231
1232 int media_info_foreach_tag_from_db(const char *media_id, filter_h filter, media_tag_cb callback, void *user_data)
1233 {
1234         int ret = MEDIA_CONTENT_ERROR_NONE;
1235
1236         media_content_debug_func();
1237
1238         if((callback != NULL) && STRING_VALID(media_id))
1239         {
1240                 ret = _media_db_get_tag(media_id, filter, callback, user_data);
1241         }
1242         else
1243         {
1244                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1245                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1246         }
1247
1248         return ret;
1249 }
1250
1251 int media_info_get_bookmark_count_from_db(const char *media_id, filter_h filter, int *bookmark_count)
1252 {
1253         int ret = MEDIA_CONTENT_ERROR_NONE;
1254
1255         media_content_debug_func();
1256
1257         if(STRING_VALID(media_id) && bookmark_count)
1258         {
1259                 ret = _media_db_get_group_item_count(media_id, filter, MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID, bookmark_count);
1260         }
1261         else
1262         {
1263                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1264                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1265         }
1266
1267         return ret;
1268 }
1269
1270 int media_info_foreach_bookmark_from_db (const char *media_id, filter_h filter, media_bookmark_cb callback, void *user_data)
1271 {
1272         int ret = MEDIA_CONTENT_ERROR_NONE;
1273
1274         media_content_debug_func();
1275
1276         if((callback != NULL) && STRING_VALID(media_id))
1277         {
1278                 ret = _media_db_get_bookmark(media_id, filter, callback, user_data);
1279         }
1280         else
1281         {
1282                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1283                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1284         }
1285
1286         return ret;
1287 }
1288
1289 int media_info_get_image(media_info_h media, image_meta_h *image)
1290 {
1291         int ret = MEDIA_CONTENT_ERROR_NONE;
1292
1293         media_info_s *_media = (media_info_s*)media;
1294         media_content_debug_func();
1295
1296         if(_media == NULL)
1297         {
1298                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1299                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1300         }
1301
1302         if(_media->media_type != MEDIA_CONTENT_TYPE_IMAGE)
1303         {
1304                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1305                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1306         }
1307
1308         if(_media->image_meta == NULL)
1309         {
1310                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1311                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1312         }
1313
1314         image_meta_s *_image = (image_meta_s*)calloc(1, sizeof(image_meta_s));
1315
1316         if(_image == NULL)
1317         {
1318                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1319                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1320         }
1321
1322         if(STRING_VALID(_media->media_id)) {
1323                 _image->media_id = strdup(_media->media_id);
1324         }
1325
1326         _image->width = _media->image_meta->width;
1327         _image->height = _media->image_meta->height;
1328         _image->orientation = _media->image_meta->orientation;
1329
1330         if(STRING_VALID(_media->image_meta->date_taken)) {
1331                 _image->date_taken = strdup(_media->image_meta->date_taken);
1332         }
1333
1334         if(STRING_VALID(_media->image_meta->burst_id)) {
1335                 _image->burst_id = strdup(_media->image_meta->burst_id);
1336         }
1337
1338         *image = (image_meta_h)_image;
1339
1340         return ret;
1341 }
1342
1343 int media_info_get_video(media_info_h media, video_meta_h *video)
1344 {
1345         int ret = MEDIA_CONTENT_ERROR_NONE;
1346
1347         media_info_s *_media = (media_info_s*)media;
1348         media_content_debug_func();
1349
1350         if(_media == NULL)
1351         {
1352                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1353                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1354         }
1355
1356         if(_media->media_type != MEDIA_CONTENT_TYPE_VIDEO)
1357         {
1358                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1359                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1360         }
1361
1362         if(_media->video_meta == NULL)
1363         {
1364                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1365                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1366         }
1367
1368         video_meta_s *_video = (video_meta_s*)calloc(1, sizeof(video_meta_s));
1369
1370         if(_video == NULL)
1371         {
1372                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1373                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1374         }
1375
1376         if(STRING_VALID(_media->media_id)) {
1377                 _video->media_id = strdup(_media->media_id);
1378         }
1379
1380         if(STRING_VALID(_media->video_meta->title)) {
1381                 _video->title = strdup(_media->video_meta->title);
1382         }
1383         if(STRING_VALID(_media->video_meta->album)) {
1384                 _video->album = strdup(_media->video_meta->album);
1385         }
1386         if(STRING_VALID(_media->video_meta->artist)) {
1387                 _video->artist = strdup(_media->video_meta->artist);
1388         }
1389         if(STRING_VALID(_media->video_meta->genre)) {
1390                 _video->genre = strdup(_media->video_meta->genre);
1391         }
1392         if(STRING_VALID(_media->video_meta->composer)) {
1393                 _video->composer = strdup(_media->video_meta->composer);
1394         }
1395         if(STRING_VALID(_media->video_meta->year)) {
1396                 _video->year = strdup(_media->video_meta->year);
1397         }
1398         if(STRING_VALID(_media->video_meta->recorded_date)) {
1399                 _video->recorded_date = strdup(_media->video_meta->recorded_date);
1400         }
1401         if(STRING_VALID(_media->video_meta->copyright)) {
1402                 _video->copyright = strdup(_media->video_meta->copyright);
1403         }
1404         if(STRING_VALID(_media->video_meta->track_num)) {
1405                 _video->track_num = strdup(_media->video_meta->track_num);
1406         }
1407
1408         _video->width = _media->video_meta->width;
1409         _video->height = _media->video_meta->height;
1410         _video->duration = _media->video_meta->duration;
1411         _video->bitrate = _media->video_meta->bitrate;
1412         _video->played_count = _media->video_meta->played_count;
1413         _video->played_time = _media->video_meta->played_time;
1414         _video->played_position = _media->video_meta->played_position;
1415
1416         *video = (video_meta_h)_video;
1417
1418         return ret;
1419 }
1420
1421 int media_info_get_audio(media_info_h media, audio_meta_h *audio)
1422 {
1423         int ret = MEDIA_CONTENT_ERROR_NONE;
1424
1425         media_info_s *_media = (media_info_s*)media;
1426         media_content_debug_func();
1427
1428         if(_media == NULL)
1429         {
1430                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1431                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1432         }
1433
1434         if(_media->media_type != MEDIA_CONTENT_TYPE_MUSIC && _media->media_type != MEDIA_CONTENT_TYPE_SOUND)
1435         {
1436                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1437                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1438         }
1439
1440         if(_media->audio_meta == NULL)
1441         {
1442                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1443                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1444         }
1445
1446         audio_meta_s *_audio = (audio_meta_s*)calloc(1, sizeof(audio_meta_s));
1447
1448         if(_audio == NULL)
1449         {
1450                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1451                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1452         }
1453
1454         if(STRING_VALID(_media->media_id)) {
1455                 _audio->media_id = strdup(_media->media_id);
1456         }
1457
1458         if(STRING_VALID(_media->audio_meta->title)) {
1459                 _audio->title = strdup(_media->audio_meta->title);
1460         }
1461         if(STRING_VALID(_media->audio_meta->album)) {
1462                 _audio->album = strdup(_media->audio_meta->album);
1463         }
1464         if(STRING_VALID(_media->audio_meta->artist)) {
1465                 _audio->artist = strdup(_media->audio_meta->artist);
1466         }
1467         if(STRING_VALID(_media->audio_meta->genre)) {
1468                 _audio->genre = strdup(_media->audio_meta->genre);
1469         }
1470         if(STRING_VALID(_media->audio_meta->composer)) {
1471                 _audio->composer = strdup(_media->audio_meta->composer);
1472         }
1473         if(STRING_VALID(_media->audio_meta->year)) {
1474                 _audio->year = strdup(_media->audio_meta->year);
1475         }
1476         if(STRING_VALID(_media->audio_meta->recorded_date)) {
1477                 _audio->recorded_date = strdup(_media->audio_meta->recorded_date);
1478         }
1479         if(STRING_VALID(_media->audio_meta->copyright)) {
1480                 _audio->copyright = strdup(_media->audio_meta->copyright);
1481         }
1482         if(STRING_VALID(_media->audio_meta->track_num)) {
1483                 _audio->track_num = strdup(_media->audio_meta->track_num);
1484         }
1485
1486         _audio->duration = _media->audio_meta->duration;
1487         _audio->bitrate = _media->audio_meta->bitrate;
1488         _audio->samplerate = _media->audio_meta->samplerate;
1489         _audio->channel = _media->audio_meta->channel;
1490         _audio->played_time = _media->audio_meta->played_time;
1491         _audio->played_count = _media->audio_meta->played_count;
1492         _audio->played_position = _media->audio_meta->played_position;
1493
1494         *audio = (audio_meta_h)_audio;
1495
1496         return ret;
1497 }
1498
1499 int media_info_get_media_id(media_info_h media, char **media_id)
1500 {
1501         int ret = MEDIA_CONTENT_ERROR_NONE;
1502         media_info_s *_media = (media_info_s*)media;
1503
1504         if(_media && media_id)
1505         {
1506                 if(STRING_VALID(_media->media_id))
1507                 {
1508                         *media_id = strdup(_media->media_id);
1509                         if(*media_id == NULL)
1510                         {
1511                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1512                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1513                         }
1514                 }
1515                 else
1516                 {
1517                         *media_id = NULL;
1518                 }
1519                 ret = MEDIA_CONTENT_ERROR_NONE;
1520         }
1521         else
1522         {
1523                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1524                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1525         }
1526
1527         return ret;
1528 }
1529
1530 int media_info_get_file_path(media_info_h media, char **path)
1531 {
1532         int ret = MEDIA_CONTENT_ERROR_NONE;
1533         media_info_s *_media = (media_info_s*)media;
1534
1535         if(_media && path)
1536         {
1537                 if(STRING_VALID(_media->file_path))
1538                 {
1539                         *path = strdup(_media->file_path);
1540                         if(*path == NULL)
1541                         {
1542                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1543                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1544                         }
1545                 }
1546                 else
1547                 {
1548                         *path = NULL;
1549                 }
1550                 ret = MEDIA_CONTENT_ERROR_NONE;
1551
1552         }
1553         else
1554         {
1555                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1556                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1557         }
1558
1559         return ret;
1560 }
1561
1562 int media_info_get_display_name(media_info_h media, char **name)
1563 {
1564         int ret = MEDIA_CONTENT_ERROR_NONE;
1565         media_info_s *_media = (media_info_s*)media;
1566         if(_media && name)
1567         {
1568                 if(STRING_VALID(_media->display_name))
1569                 {
1570                         *name = strdup(_media->display_name);
1571                         if(*name == NULL)
1572                         {
1573                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1574                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1575                         }
1576                 }
1577                 else
1578                 {
1579                         *name = NULL;
1580                 }
1581                 ret = MEDIA_CONTENT_ERROR_NONE;
1582
1583         }
1584         else
1585         {
1586                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1587                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1588         }
1589
1590         return ret;
1591 }
1592
1593 int media_info_get_media_type(media_info_h media, media_content_type_e *type)
1594 {
1595         int ret = MEDIA_CONTENT_ERROR_NONE;
1596         media_info_s *_media = (media_info_s*)media;
1597         if(_media && type)
1598         {
1599                 *type = _media->media_type;
1600                 ret = MEDIA_CONTENT_ERROR_NONE;
1601         }
1602         else
1603         {
1604                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1605                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1606         }
1607
1608         return ret;
1609 }
1610
1611 int media_info_get_mime_type(media_info_h media, char **mime_type)
1612 {
1613         int ret = MEDIA_CONTENT_ERROR_NONE;
1614         media_info_s *_media = (media_info_s*)media;
1615
1616         if(_media && mime_type)
1617         {
1618                 if(STRING_VALID(_media->mime_type))
1619                 {
1620                         *mime_type = strdup(_media->mime_type);
1621                         if(*mime_type == NULL)
1622                         {
1623                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1624                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1625                         }
1626                 }
1627                 else
1628                 {
1629                         *mime_type = NULL;
1630                 }
1631                 ret = MEDIA_CONTENT_ERROR_NONE;
1632         }
1633         else
1634         {
1635                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1636                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1637         }
1638
1639         return ret;
1640 }
1641
1642 int media_info_get_size(media_info_h media, unsigned long long *size)
1643 {
1644         int ret = MEDIA_CONTENT_ERROR_NONE;
1645         media_info_s *_media = (media_info_s*)media;
1646
1647         if(_media && size)
1648         {
1649                 *size = _media->size;
1650                 ret = MEDIA_CONTENT_ERROR_NONE;
1651         }
1652         else
1653         {
1654                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1655                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1656         }
1657
1658         return ret;
1659 }
1660
1661 int media_info_get_added_time(media_info_h media, time_t *added_time)
1662 {
1663         int ret = MEDIA_CONTENT_ERROR_NONE;
1664         media_info_s *_media = (media_info_s*)media;
1665         if(_media && added_time)
1666         {
1667                 *added_time = _media->added_time;
1668                 ret = MEDIA_CONTENT_ERROR_NONE;
1669         }
1670         else
1671         {
1672                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1673                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1674         }
1675
1676         return ret;
1677 }
1678
1679 int media_info_get_modified_time(media_info_h media, time_t* time)
1680 {
1681         int ret = MEDIA_CONTENT_ERROR_NONE;
1682         media_info_s *_media = (media_info_s*)media;
1683         if(_media && time)
1684         {
1685                 *time = _media->modified_time;
1686                 ret = MEDIA_CONTENT_ERROR_NONE;
1687         }
1688         else
1689         {
1690                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1691                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1692         }
1693
1694         return ret;
1695 }
1696
1697 int media_info_get_thumbnail_path(media_info_h media, char **path)
1698 {
1699         int ret = MEDIA_CONTENT_ERROR_NONE;
1700         media_info_s *_media = (media_info_s*)media;
1701         if(_media && path)
1702         {
1703                 if(STRING_VALID(_media->thumbnail_path))
1704                 {
1705                         *path = strdup(_media->thumbnail_path);
1706                         if(*path == NULL)
1707                         {
1708                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1709                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1710                         }
1711                 }
1712                 else
1713                 {
1714                         *path = NULL;
1715                 }
1716                 ret = MEDIA_CONTENT_ERROR_NONE;
1717
1718         }
1719         else
1720         {
1721                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1722                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1723         }
1724
1725         return ret;
1726 }
1727
1728 int media_info_get_description(media_info_h media, char **description)
1729 {
1730         int ret = MEDIA_CONTENT_ERROR_NONE;
1731         media_info_s *_media = (media_info_s*)media;
1732
1733         if(_media && description)
1734         {
1735                 if(STRING_VALID(_media->description))
1736                 {
1737                         *description = strdup(_media->description);
1738                         if(*description == NULL)
1739                         {
1740                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1741                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1742                         }
1743                 }
1744                 else
1745                 {
1746                         *description = NULL;
1747                 }
1748                 ret = MEDIA_CONTENT_ERROR_NONE;
1749         }
1750         else
1751         {
1752                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1753                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1754         }
1755
1756         return ret;
1757 }
1758
1759 int media_info_get_longitude(media_info_h media, double* longitude)
1760 {
1761         int ret = MEDIA_CONTENT_ERROR_NONE;
1762         media_info_s *_media = (media_info_s*)media;
1763
1764         if(_media && longitude)
1765         {
1766                 *longitude = _media->longitude;
1767                 ret = MEDIA_CONTENT_ERROR_NONE;
1768         }
1769         else
1770         {
1771                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1772                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1773         }
1774
1775         return ret;
1776 }
1777 int media_info_get_latitude(media_info_h media, double* latitude)
1778 {
1779         int ret = MEDIA_CONTENT_ERROR_NONE;
1780         media_info_s *_media = (media_info_s*)media;
1781
1782         if(_media && latitude)
1783         {
1784                 *latitude = _media->latitude;
1785                 ret = MEDIA_CONTENT_ERROR_NONE;
1786         }
1787         else
1788         {
1789                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1790                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1791         }
1792
1793         return ret;
1794 }
1795
1796 int media_info_get_altitude(media_info_h media, double *altitude)
1797 {
1798         int ret = MEDIA_CONTENT_ERROR_NONE;
1799         media_info_s *_media = (media_info_s*)media;
1800
1801         if(_media && altitude)
1802         {
1803                 *altitude = _media->altitude;
1804                 ret = MEDIA_CONTENT_ERROR_NONE;
1805         }
1806         else
1807         {
1808                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1809                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1810         }
1811
1812         return ret;
1813 }
1814
1815 int media_info_get_rating(media_info_h media, int *rating)
1816 {
1817         int ret = MEDIA_CONTENT_ERROR_NONE;
1818         media_info_s *_media = (media_info_s*)media;
1819
1820         if(_media && rating)
1821         {
1822                 *rating = _media->rating;
1823                 ret = MEDIA_CONTENT_ERROR_NONE;
1824         }
1825         else
1826         {
1827                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1828                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1829         }
1830
1831         return ret;
1832 }
1833
1834 int media_info_get_favorite(media_info_h media, bool* favorite)
1835 {
1836         int ret = MEDIA_CONTENT_ERROR_NONE;
1837         media_info_s *_media = (media_info_s*)media;
1838
1839         if(_media && favorite)
1840         {
1841
1842                 *favorite = _media->favourite;
1843                 ret = MEDIA_CONTENT_ERROR_NONE;
1844         }
1845         else
1846         {
1847                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1848                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1849         }
1850
1851         return ret;
1852 }
1853
1854 int media_info_get_author(media_info_h media, char **author)
1855 {
1856         int ret = MEDIA_CONTENT_ERROR_NONE;
1857         media_info_s *_media = (media_info_s*)media;
1858
1859         if(_media && author)
1860         {
1861                 if(STRING_VALID(_media->author))
1862                 {
1863                         *author = strdup(_media->author);
1864                         if(*author == NULL)
1865                         {
1866                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1867                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1868                         }
1869                 }
1870                 else
1871                 {
1872                         *author = NULL;
1873                 }
1874                 ret = MEDIA_CONTENT_ERROR_NONE;
1875         }
1876         else
1877         {
1878                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1879                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1880         }
1881
1882         return ret;
1883 }
1884
1885 int media_info_get_provider(media_info_h media, char **provider)
1886 {
1887         int ret = MEDIA_CONTENT_ERROR_NONE;
1888         media_info_s *_media = (media_info_s*)media;
1889
1890         if(_media && provider)
1891         {
1892                 if(STRING_VALID(_media->provider))
1893                 {
1894                         *provider = strdup(_media->provider);
1895                         if(*provider == NULL)
1896                         {
1897                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1898                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1899                         }
1900                 }
1901                 else
1902                 {
1903                         *provider = NULL;
1904                 }
1905                 ret = MEDIA_CONTENT_ERROR_NONE;
1906         }
1907         else
1908         {
1909                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1910                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1911         }
1912
1913         return ret;
1914 }
1915
1916 int media_info_get_content_name(media_info_h media, char **content_name)
1917 {
1918         int ret = MEDIA_CONTENT_ERROR_NONE;
1919         media_info_s *_media = (media_info_s*)media;
1920
1921         if(_media && content_name)
1922         {
1923                 if(STRING_VALID(_media->content_name))
1924                 {
1925                         *content_name = strdup(_media->content_name);
1926                         if(*content_name == NULL)
1927                         {
1928                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1929                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1930                         }
1931                 }
1932                 else
1933                 {
1934                         *content_name = NULL;
1935                 }
1936                 ret = MEDIA_CONTENT_ERROR_NONE;
1937         }
1938         else
1939         {
1940                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1941                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1942         }
1943
1944         return ret;
1945 }
1946
1947 int media_info_get_category(media_info_h media, char **category)
1948 {
1949         int ret = MEDIA_CONTENT_ERROR_NONE;
1950         media_info_s *_media = (media_info_s*)media;
1951
1952         if(_media && category)
1953         {
1954                 if(STRING_VALID(_media->category))
1955                 {
1956                         *category = strdup(_media->category);
1957                         if(*category == NULL)
1958                         {
1959                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1960                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1961                         }
1962                 }
1963                 else
1964                 {
1965                         *category = NULL;
1966                 }
1967                 ret = MEDIA_CONTENT_ERROR_NONE;
1968         }
1969         else
1970         {
1971                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1972                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1973         }
1974
1975         return ret;
1976 }
1977
1978 int media_info_get_location_tag(media_info_h media, char **location_tag)
1979 {
1980         int ret = MEDIA_CONTENT_ERROR_NONE;
1981         media_info_s *_media = (media_info_s*)media;
1982
1983         if(_media && location_tag)
1984         {
1985                 if(STRING_VALID(_media->location_tag))
1986                 {
1987                         *location_tag = strdup(_media->location_tag);
1988                         if(*location_tag == NULL)
1989                         {
1990                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1991                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1992                         }
1993                 }
1994                 else
1995                 {
1996                         *location_tag = NULL;
1997                 }
1998                 ret = MEDIA_CONTENT_ERROR_NONE;
1999         }
2000         else
2001         {
2002                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2003                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2004         }
2005
2006         return ret;
2007 }
2008
2009 int media_info_get_age_rating(media_info_h media, char **age_rating)
2010 {
2011         int ret = MEDIA_CONTENT_ERROR_NONE;
2012         media_info_s *_media = (media_info_s*)media;
2013
2014         if(_media && age_rating)
2015         {
2016                 if(STRING_VALID(_media->age_rating))
2017                 {
2018                         *age_rating = strdup(_media->age_rating);
2019                         if(*age_rating == NULL)
2020                         {
2021                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
2022                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
2023                         }
2024                 }
2025                 else
2026                 {
2027                         *age_rating = NULL;
2028                 }
2029                 ret = MEDIA_CONTENT_ERROR_NONE;
2030         }
2031         else
2032         {
2033                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2034                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2035         }
2036
2037         return ret;
2038 }
2039
2040 int media_info_get_keyword(media_info_h media, char **keyword)
2041 {
2042         int ret = MEDIA_CONTENT_ERROR_NONE;
2043         media_info_s *_media = (media_info_s*)media;
2044
2045         if(_media && keyword)
2046         {
2047                 if(STRING_VALID(_media->keyword))
2048                 {
2049                         *keyword = strdup(_media->keyword);
2050                         if(*keyword == NULL)
2051                         {
2052                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
2053                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
2054                         }
2055                 }
2056                 else
2057                 {
2058                         *keyword = NULL;
2059                 }
2060                 ret = MEDIA_CONTENT_ERROR_NONE;
2061         }
2062         else
2063         {
2064                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2065                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2066         }
2067
2068         return ret;
2069 }
2070
2071 int media_info_is_drm(media_info_h media, bool *is_drm)
2072 {
2073         int ret = MEDIA_CONTENT_ERROR_NONE;
2074         media_info_s *_media = (media_info_s*)media;
2075
2076         if(_media)
2077         {
2078                 *is_drm = _media->is_drm;
2079                 ret = MEDIA_CONTENT_ERROR_NONE;
2080         }
2081         else
2082         {
2083                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2084                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2085         }
2086
2087         return ret;
2088 }
2089
2090 int media_info_get_storage_type(media_info_h media, media_content_storage_e *storage_type)
2091 {
2092         int ret = MEDIA_CONTENT_ERROR_NONE;
2093         media_info_s *_media = (media_info_s*)media;
2094
2095         if(_media && storage_type)
2096         {
2097                 *storage_type = _media->storage_type;
2098                 ret = MEDIA_CONTENT_ERROR_NONE;
2099         }
2100         else
2101         {
2102                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2103                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2104         }
2105
2106         return ret;
2107 }
2108
2109 int media_info_get_media_from_db(const char *media_id, media_info_h *media)
2110 {
2111         int ret = MEDIA_CONTENT_ERROR_NONE;
2112         char select_query[DEFAULT_QUERY_SIZE];
2113         sqlite3_stmt *stmt = NULL;
2114
2115         if(!STRING_VALID(media_id) || (media == NULL))
2116         {
2117                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2118                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2119         }
2120
2121         memset(select_query, 0x00, sizeof(select_query));
2122
2123         snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_MEDIA, media_id);
2124         ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
2125         media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
2126
2127         while(sqlite3_step(stmt) == SQLITE_ROW)
2128         {
2129                 media_info_s *_media = (media_info_s*)calloc(1, sizeof(media_info_s));
2130
2131                 if(_media == NULL)
2132                 {
2133                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
2134                         SQLITE3_FINALIZE(stmt);
2135                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
2136                 }
2137
2138                 _media_info_item_get_detail(stmt, (media_info_h)_media);
2139
2140                 *media = (media_info_h)_media;
2141         }
2142
2143         SQLITE3_FINALIZE(stmt);
2144
2145         return ret;
2146 }
2147
2148 int media_info_set_display_name(media_info_h media, const char *display_name)
2149 {
2150         int ret = MEDIA_CONTENT_ERROR_NONE;
2151         media_info_s *_media = (media_info_s*)media;
2152
2153         if(_media != NULL && STRING_VALID(display_name))
2154         {
2155                 SAFE_FREE(_media->display_name);
2156
2157                 _media->display_name = strdup(display_name);
2158                 if(_media->display_name == NULL)
2159                 {
2160                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
2161                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
2162                 }
2163         }
2164         else
2165         {
2166                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2167                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2168         }
2169
2170         return ret;
2171 }
2172
2173 int media_info_set_description(media_info_h media, const char *description)
2174 {
2175         int ret = MEDIA_CONTENT_ERROR_NONE;
2176         media_info_s *_media = (media_info_s*)media;
2177
2178         if(_media != NULL)
2179         {
2180                 SAFE_FREE(_media->description);
2181
2182                 if(STRING_VALID(description))
2183                 {
2184                         _media->description = strdup(description);
2185
2186                         if(_media->description == NULL)
2187                         {
2188                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
2189                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
2190                         }
2191                 }
2192                 else
2193                 {
2194                         _media->description = NULL;
2195                 }
2196         }
2197         else
2198         {
2199                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2200                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2201         }
2202
2203         return ret;
2204 }
2205
2206 int media_info_set_longitude(media_info_h media, double longitude)
2207 {
2208         int ret = MEDIA_CONTENT_ERROR_NONE;
2209         media_info_s *_media = (media_info_s*)media;
2210
2211         if(_media != NULL)
2212         {
2213                 _media->longitude = longitude;
2214         }
2215         else
2216         {
2217                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2218                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2219         }
2220
2221         return ret;
2222 }
2223
2224 int media_info_set_latitude(media_info_h media, double latitude)
2225 {
2226         int ret = MEDIA_CONTENT_ERROR_NONE;
2227         media_info_s *_media = (media_info_s*)media;
2228
2229         if(_media != NULL)
2230         {
2231                 _media->latitude = latitude;
2232         }
2233         else
2234         {
2235                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2236                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2237         }
2238
2239         return ret;
2240 }
2241
2242 int media_info_set_altitude(media_info_h media, double altitude)
2243 {
2244         int ret = MEDIA_CONTENT_ERROR_NONE;
2245         media_info_s *_media = (media_info_s*)media;
2246
2247         if(_media != NULL)
2248         {
2249                 _media->altitude = altitude;
2250         }
2251         else
2252         {
2253                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2254                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2255         }
2256
2257         return ret;
2258 }
2259
2260 int media_info_set_rating(media_info_h media, int rating)
2261 {
2262         int ret = MEDIA_CONTENT_ERROR_NONE;
2263         media_info_s *_media = (media_info_s*)media;
2264
2265         if(_media != NULL)
2266         {
2267                 _media->rating = rating;
2268         }
2269         else
2270         {
2271                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2272                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2273         }
2274
2275         return ret;
2276 }
2277
2278 int media_info_set_added_time(media_info_h media, time_t added_time)
2279 {
2280         int ret = MEDIA_CONTENT_ERROR_NONE;
2281
2282         media_info_s *_media = (media_info_s*)media;
2283
2284         if((_media != NULL) && (added_time >= 0))
2285         {
2286                 _media->added_time = added_time;
2287         }
2288         else
2289         {
2290                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2291                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2292         }
2293
2294         return ret;
2295 }
2296
2297 int media_info_set_favorite(media_info_h media, bool favorite)
2298 {
2299         int ret = MEDIA_CONTENT_ERROR_NONE;
2300         media_info_s *_media = (media_info_s*)media;
2301
2302         if(_media != NULL)
2303         {
2304                 _media->favourite = favorite;
2305         }
2306         else
2307         {
2308                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2309                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2310         }
2311
2312         return ret;
2313 }
2314
2315 int media_info_set_author(media_info_h media, const char *author)
2316 {
2317         int ret = MEDIA_CONTENT_ERROR_NONE;
2318         media_info_s *_media = (media_info_s*)media;
2319
2320         if(_media != NULL)
2321         {
2322                 if(STRING_VALID(author))
2323                 {
2324                         _media->author = strdup(author);
2325                         if(_media->author == NULL)
2326                         {
2327                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
2328                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
2329                         }
2330                 }
2331                 else
2332                 {
2333                         _media->author = NULL;
2334                 }
2335         }
2336         else
2337         {
2338                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2339                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2340         }
2341
2342         return ret;
2343 }
2344
2345 int media_info_set_provider(media_info_h media, const char *provider)
2346 {
2347         int ret = MEDIA_CONTENT_ERROR_NONE;
2348         media_info_s *_media = (media_info_s*)media;
2349
2350         if(_media != NULL)
2351         {
2352                 SAFE_FREE(_media->provider);
2353
2354                 if(STRING_VALID(provider))
2355                 {
2356                         _media->provider = strdup(provider);
2357                         if(_media->provider == NULL)
2358                         {
2359                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
2360                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
2361                         }
2362                 }
2363                 else
2364                 {
2365                         _media->provider = NULL;
2366                 }
2367         }
2368         else
2369         {
2370                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2371                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2372         }
2373
2374         return ret;
2375 }
2376
2377 int media_info_set_content_name(media_info_h media, const char *content_name)
2378 {
2379         int ret = MEDIA_CONTENT_ERROR_NONE;
2380         media_info_s *_media = (media_info_s*)media;
2381
2382         if(_media != NULL)
2383         {
2384                 SAFE_FREE(_media->content_name);
2385
2386                 if(STRING_VALID(content_name))
2387                 {
2388                         _media->content_name = strdup(content_name);
2389                         if(_media->content_name == NULL)
2390                         {
2391                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
2392                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
2393                         }
2394                 }
2395                 else
2396                 {
2397                         _media->content_name = NULL;
2398                 }
2399         }
2400         else
2401         {
2402                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2403                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2404         }
2405
2406         return ret;
2407 }
2408
2409 int media_info_set_category(media_info_h media, const char *category)
2410 {
2411         int ret = MEDIA_CONTENT_ERROR_NONE;
2412         media_info_s *_media = (media_info_s*)media;
2413
2414         if(_media != NULL)
2415         {
2416                 SAFE_FREE(_media->category);
2417
2418                 if(STRING_VALID(category))
2419                 {
2420                         _media->category = strdup(category);
2421                         if(_media->category == NULL)
2422                         {
2423                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
2424                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
2425                         }
2426                 }
2427                 else
2428                 {
2429                         _media->category = NULL;
2430                 }
2431         }
2432         else
2433         {
2434                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2435                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2436         }
2437
2438         return ret;
2439 }
2440
2441 int media_info_set_location_tag(media_info_h media, const char *location_tag)
2442 {
2443         int ret = MEDIA_CONTENT_ERROR_NONE;
2444         media_info_s *_media = (media_info_s*)media;
2445
2446         if(_media != NULL)
2447         {
2448                 SAFE_FREE(_media->location_tag);
2449
2450                 if(STRING_VALID(location_tag))
2451                 {
2452                         _media->location_tag = strdup(location_tag);
2453                         if(_media->location_tag == NULL)
2454                         {
2455                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
2456                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
2457                         }
2458                 }
2459                 else
2460                 {
2461                         _media->location_tag = NULL;
2462                 }
2463         }
2464         else
2465         {
2466                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2467                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2468         }
2469
2470         return ret;
2471 }
2472
2473 int media_info_set_age_rating(media_info_h media, const char *age_rating)
2474 {
2475         int ret = MEDIA_CONTENT_ERROR_NONE;
2476         media_info_s *_media = (media_info_s*)media;
2477
2478         if(_media != NULL)
2479         {
2480                 SAFE_FREE(_media->age_rating);
2481
2482                 if(STRING_VALID(age_rating))
2483                 {
2484                         _media->age_rating = strdup(age_rating);
2485                         if(_media->age_rating == NULL)
2486                         {
2487                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
2488                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
2489                         }
2490                 }
2491                 else
2492                 {
2493                         _media->age_rating = NULL;
2494                 }
2495         }
2496         else
2497         {
2498                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2499                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2500         }
2501
2502         return ret;
2503 }
2504
2505 int media_info_set_keyword(media_info_h media, const char *keyword)
2506 {
2507         int ret = MEDIA_CONTENT_ERROR_NONE;
2508         media_info_s *_media = (media_info_s*)media;
2509
2510         if(_media != NULL)
2511         {
2512                 SAFE_FREE(_media->keyword);
2513
2514                 if(STRING_VALID(keyword))
2515                 {
2516                         _media->keyword = strdup(keyword);
2517                         if(_media->keyword == NULL)
2518                         {
2519                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
2520                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
2521                         }
2522                 }
2523                 else
2524                 {
2525                         _media->keyword = NULL;
2526                 }
2527         }
2528         else
2529         {
2530                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2531                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2532         }
2533
2534         return ret;
2535 }
2536
2537 int media_info_update_to_db(media_info_h media)
2538 {
2539         int ret = MEDIA_CONTENT_ERROR_NONE;
2540         int len = 0;
2541         media_info_s *_media = (media_info_s*)media;
2542         char *set_sql = NULL;
2543         char sql[MAX_QUERY_SIZE];
2544         memset(sql, '\0', sizeof(sql));
2545
2546         if(_media != NULL && STRING_VALID(_media->media_id))
2547         {
2548                 /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
2549                 /* This code will be removed when sqlite3_mprintf works clearly */
2550                 char *test_sql = sqlite3_mprintf("%f, %f, %f", _media->longitude, _media->latitude, _media->altitude);
2551                 sqlite3_free(test_sql);
2552
2553                 set_sql = sqlite3_mprintf("file_name=%Q, added_time=%d, description=%Q, longitude=%f, latitude=%f, altitude=%f, \
2554                         rating=%d, favourite=%d, author=%Q, provider=%Q, content_name=%Q, category=%Q, location_tag=%Q, age_rating=%Q, keyword=%Q",
2555                         _media->display_name, _media->added_time, _media->description, _media->longitude, _media->latitude, _media->altitude, _media->rating, _media->favourite,
2556                         _media->author, _media->provider, _media->content_name, _media->category, _media->location_tag, _media->age_rating, _media->keyword);
2557
2558                 len = snprintf(sql, sizeof(sql), "UPDATE %s SET %s WHERE media_uuid='%s'", DB_TABLE_MEDIA, set_sql, _media->media_id);
2559                 sqlite3_free(set_sql);
2560                 if (len > 0) {
2561                         sql[len] = '\0';
2562                 } else {
2563                         media_content_error("snprintf failed");
2564                         return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2565                 }
2566
2567                 ret = _content_query_sql(sql);
2568                 if (ret == MEDIA_CONTENT_ERROR_NONE) {
2569                         /*  Send notification for this update */
2570                         media_content_debug("Update is successfull. Send notification for this");
2571                         if (_media->file_path && _media->mime_type) {
2572                                 media_db_update_send(getpid(), MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, _media->file_path, _media->media_id, _media->media_type, _media->mime_type);
2573                         } else {
2574                                 media_content_error("Can't media_db_update_send : path or mime type is NULL");
2575                         }
2576                 }
2577         }
2578         else
2579         {
2580                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2581                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2582         }
2583
2584         return ret;
2585 }
2586
2587 int media_info_refresh_metadata_to_db(const char *media_id)
2588 {
2589         int ret = MEDIA_CONTENT_ERROR_NONE;
2590         media_info_h media = NULL;
2591         char *file_path = NULL;
2592         media_content_type_e media_type = 0;
2593         media_content_storage_e storage_type = 0;
2594
2595         if(!STRING_VALID(media_id))
2596         {
2597                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2598                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2599         }
2600
2601         ret = media_info_get_media_from_db(media_id, &media);
2602         if(ret != MEDIA_CONTENT_ERROR_NONE)
2603         {
2604                 media_info_destroy(media);
2605                 return ret;
2606         }
2607
2608         ret = media_info_get_media_type(media, &media_type);
2609         if(ret != MEDIA_CONTENT_ERROR_NONE)
2610         {
2611                 media_info_destroy(media);
2612                 return ret;
2613         }
2614
2615         ret = media_info_get_storage_type(media, &storage_type);
2616         if(ret != MEDIA_CONTENT_ERROR_NONE)
2617         {
2618                 media_info_destroy(media);
2619                 return ret;
2620         }
2621
2622         ret = media_info_get_file_path(media, &file_path);
2623         if(ret != MEDIA_CONTENT_ERROR_NONE)
2624         {
2625                 media_info_destroy(media);
2626                 return ret;
2627         }
2628
2629         ret = media_svc_refresh_item(_content_get_db_handle(), storage_type, file_path, media_type);
2630
2631         SAFE_FREE(file_path);
2632         media_info_destroy(media);
2633
2634         return ret;
2635 }
2636
2637 int media_info_move_to_db(media_info_h media, const char* dst_path)
2638 {
2639         int ret = MEDIA_CONTENT_ERROR_NONE;
2640
2641         int src_storage_type = 0;
2642         int dst_storage_type = 0;
2643
2644         if(media == NULL || !STRING_VALID(dst_path))
2645         {
2646                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2647                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2648         }
2649
2650         media_info_s *_media = (media_info_s*)media;
2651
2652         ret = _media_util_get_store_type_by_path(_media->file_path, &src_storage_type);
2653         media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
2654         ret = _media_util_get_store_type_by_path(dst_path, &dst_storage_type);
2655         media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
2656
2657         ret = media_svc_move_item(_content_get_db_handle(), src_storage_type, _media->file_path, dst_storage_type, dst_path);
2658         return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2659 }
2660
2661 int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb callback, void *user_data)
2662 {
2663         int ret = MEDIA_CONTENT_ERROR_NONE;
2664         media_info_s *_media = (media_info_s*)media;
2665
2666         if(_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path))
2667         {
2668                 media_thumbnail_cb_s *_thumb_cb = (media_thumbnail_cb_s*)calloc(1, sizeof(media_thumbnail_cb_s));
2669                 _thumb_cb->handle = _media;
2670                 _thumb_cb->user_data = user_data;
2671                 _thumb_cb->thumbnail_completed_cb = callback;
2672
2673                 ret = thumbnail_request_from_db_async(_media->file_path, (ThumbFunc)__media_info_thumbnail_completed_cb, (void *)_thumb_cb);
2674                 ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret);
2675         }
2676         else
2677         {
2678                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2679                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2680         }
2681
2682         return ret;
2683 }
2684
2685 int media_info_cancel_thumbnail(media_info_h media)
2686 {
2687         int ret = MEDIA_CONTENT_ERROR_NONE;
2688         media_info_s *_media = (media_info_s*)media;
2689
2690         if(_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path))
2691         {
2692                 ret = thumbnail_request_cancel_media(_media->file_path);
2693                 ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret);
2694         }
2695         else
2696         {
2697                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2698                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2699         }
2700
2701         return ret;
2702 }