upload tizen1.0 source
[framework/multimedia/libmedia-service.git] / plugin / media-svc-plugin.c
1 /*
2  * libmedia-service
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <string.h>
23 #include <mm_file.h>
24 #include <media-thumbnail.h>
25 #include "media-svc.h"
26 #include "audio-svc.h"
27 #include "visual-svc.h"
28
29 #define MEDIA_SVC_PLUGIN_ERROR_NONE             0
30 #define MEDIA_SVC_PLUGIN_ERROR                  -1
31 #define MEDIA_SVC_PLUGIN_STORAGE_INTERNAL       0
32 #define MEDIA_SVC_PLUGIN_STORAGE_EXTERNAL       1
33
34 #define STRING_VALID(str)       \
35         ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
36 #define STORAGE_VALID(storage)\
37         (((storage == MEDIA_SVC_PLUGIN_STORAGE_INTERNAL) || (storage == MEDIA_SVC_PLUGIN_STORAGE_EXTERNAL)) ? TRUE : FALSE)
38
39 typedef enum{
40         CONTENT_TYPE_SOUND,
41         CONTENT_TYPE_MUSIC,
42         CONTENT_TYPE_IMAGE,
43         CONTENT_TYPE_VIDEO,
44         CONTENT_TYPE_MAX,
45 }media_svc_content_type_e;
46
47 typedef enum{
48         ERR_FILE_PATH = 1,
49         ERR_HANDLE,
50         ERR_MIME_TYPE,
51         ERR_NOT_MEDIAFILE,
52         ERR_STORAGE_TYPE,
53         ERR_CHECK_ITEM,
54         ERR_MAX,
55 }media_svc_error_type_e;
56
57 #define MS_CATEGORY_UNKNOWN     0x00000000      /**< Default */
58 #define MS_CATEGORY_ETC         0x00000001      /**< ETC category */
59 #define MS_CATEGORY_IMAGE               0x00000002      /**< Image category */
60 #define MS_CATEGORY_VIDEO               0x00000004      /**< Video category */
61 #define MS_CATEGORY_MUSIC               0x00000008      /**< Music category */
62 #define MS_CATEGORY_SOUND       0x00000010      /**< Sound category */
63
64 #define CONTENT_TYPE_NUM 4
65 #define MUSIC_MIME_NUM 28
66 #define SOUND_MIME_NUM 1
67 #define MIME_TYPE_LENGTH 255
68 #define MIME_LENGTH 50
69 #define _3GP_FILE ".3gp"
70 #define _MP4_FILE ".mp4"
71
72
73 typedef struct {
74         char content_type[15];
75         int category_by_mime;
76 } fex_content_table_t;
77
78 static const fex_content_table_t content_category[CONTENT_TYPE_NUM] = {
79         {"audio", MS_CATEGORY_SOUND},
80         {"image", MS_CATEGORY_IMAGE},
81         {"video", MS_CATEGORY_VIDEO},
82         {"application", MS_CATEGORY_ETC},
83 };
84
85 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
86         /*known mime types of normal files*/
87         "mpeg",
88         "ogg",
89         "x-ms-wma",
90         "x-flac",
91         "mp4",
92         /* known mime types of drm files*/
93         "mp3",
94         "x-mp3", /*alias of audio/mpeg*/
95         "x-mpeg", /*alias of audio/mpeg*/
96         "3gpp",
97         "x-ogg", /*alias of  audio/ogg*/
98         "vnd.ms-playready.media.pya:*.pya", /*playready*/
99         "wma",
100         "aac",
101         "x-m4a", /*alias of audio/mp4*/
102         /* below mimes are rare*/
103         "x-vorbis+ogg",
104         "x-flac+ogg",
105         "x-matroska",
106         "ac3",
107         "mp2",
108         "x-ape",
109         "x-ms-asx",
110         "vnd.rn-realaudio",
111
112         "x-vorbis", /*alias of audio/x-vorbis+ogg*/
113         "vorbis", /*alias of audio/x-vorbis+ogg*/
114         "x-oggflac",
115         "x-mp2", /*alias of audio/mp2*/
116         "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
117         "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
118 };
119
120 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
121         "x-smaf",
122 };
123
124 static int __get_content_type_from_mime(const char * path, const char * mimetype, int * category);
125 static int __get_content_type(const char * file_path, const char * mime_type);
126 static void __set_error_message(int err_type, char ** err_msg);
127
128 static int __get_content_type_from_mime(const char * path, const char * mimetype, int * category)
129 {
130         int i = 0;
131         int err = 0;
132
133         *category = MS_CATEGORY_UNKNOWN;
134
135         //MS_DBG("mime type : %s", mimetype);
136
137         /*categorize from mimetype */
138         for (i = 0; i < CONTENT_TYPE_NUM; i++) {
139                 if (strstr(mimetype, content_category[i].content_type) != NULL) {
140                         *category = (*category | content_category[i].category_by_mime);
141                         break;
142                 }
143         }
144
145         /*in application type, exitst sound file ex) x-smafs */
146         if (*category & MS_CATEGORY_ETC) {
147                 int prefix_len = strlen(content_category[0].content_type);
148
149                 for (i = 0; i < SOUND_MIME_NUM; i++) {
150                         if (strstr(mimetype + prefix_len, sound_mime_table[i]) != NULL) {
151                                 *category ^= MS_CATEGORY_ETC;
152                                 *category |= MS_CATEGORY_SOUND;
153                                 break;
154                         }
155                 }
156         }
157
158         /*check music file in soun files. */
159         if (*category & MS_CATEGORY_SOUND) {
160                 int prefix_len = strlen(content_category[0].content_type) + 1;
161
162                 //MS_DBG("mime_type : %s", mimetype + prefix_len);
163
164                 for (i = 0; i < MUSIC_MIME_NUM; i++) {
165                         if (strcmp(mimetype + prefix_len, music_mime_table[i]) == 0) {
166                                 *category ^= MS_CATEGORY_SOUND;
167                                 *category |= MS_CATEGORY_MUSIC;
168                                 break;
169                         }
170                 }
171         } else if (*category & MS_CATEGORY_VIDEO) {
172                 /*some video files don't have video stream. in this case it is categorize as music. */
173                 char *ext;
174                 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
175                 ext = strrchr(path, '.');
176                 if (ext != NULL) {
177                         if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
178                                 int audio = 0;
179                                 int video = 0;
180
181                                 err = mm_file_get_stream_info(path, &audio, &video);
182                                 if (err == 0) {
183                                         if (audio > 0 && video == 0) {
184                                                 *category ^= MS_CATEGORY_VIDEO;
185                                                 *category |= MS_CATEGORY_MUSIC;
186                                         }
187                                 }
188                         }
189                 }
190         }
191
192         //MS_DBG("category_from_ext : %d", *category);
193
194         return err;
195 }
196
197 static int __get_content_type(const char * file_path, const char * mime_type)
198 {
199         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
200         int category = 0;
201
202         ret = __get_content_type_from_mime(file_path, mime_type, &category);
203         if(ret < 0)
204                 return ret;
205
206         if (category & MS_CATEGORY_SOUND)               return CONTENT_TYPE_SOUND;
207         else if (category & MS_CATEGORY_MUSIC)  return CONTENT_TYPE_MUSIC;
208         else if (category & MS_CATEGORY_IMAGE)  return CONTENT_TYPE_IMAGE;
209         else if (category & MS_CATEGORY_VIDEO)  return CONTENT_TYPE_VIDEO;
210         else    return CONTENT_TYPE_MAX;
211
212 }
213
214 static void __set_error_message(int err_type, char ** err_msg)
215 {
216         if (err_msg)
217                 *err_msg = NULL;
218
219         if(err_type == ERR_FILE_PATH)
220                 *err_msg = strdup("invalid file path");
221         if(err_type == ERR_HANDLE)
222                 *err_msg = strdup("invalid handle");
223         else if(err_type == ERR_MIME_TYPE)
224                 *err_msg = strdup("invalid mime type");
225         else if(err_type == ERR_NOT_MEDIAFILE)
226                 *err_msg = strdup("not media content");
227         else if(err_type == ERR_STORAGE_TYPE)
228                         *err_msg = strdup("invalid storage type");
229         else if(err_type == ERR_CHECK_ITEM)
230                 *err_msg = strdup("item does not exist");
231         else if(err_type == MEDIA_INFO_ERROR_DATABASE_CONNECT)
232                 *err_msg = strdup("DB connect error");
233         else if(err_type == MEDIA_INFO_ERROR_DATABASE_DISCONNECT)
234                 *err_msg = strdup("DB disconnect error");
235         else if((err_type == AUDIO_SVC_ERROR_INVALID_PARAMETER) || (err_type == MB_SVC_ERROR_INVALID_PARAMETER))
236                 *err_msg = strdup("invalid parameter");
237         else if((err_type == AUDIO_SVC_ERROR_DB_INTERNAL) ||(err_type == MB_SVC_ERROR_DB_INTERNAL))
238                 *err_msg = strdup("DB internal error");
239         else if((err_type == AUDIO_SVC_ERROR_INTERNAL) || (err_type == MB_SVC_ERROR_INTERNAL))
240                 *err_msg = strdup("media service internal error");
241         else
242                 *err_msg = strdup("error unknown");
243
244 }
245
246 int check_item(const char *file_path, const char * mime_type, char ** err_msg)
247 {
248         int content_type = 0;
249
250         if (!STRING_VALID(file_path)) {
251                 __set_error_message(ERR_FILE_PATH, err_msg);
252                 return MEDIA_SVC_PLUGIN_ERROR;
253         }
254
255         if (!STRING_VALID(mime_type)) {
256                 __set_error_message(ERR_MIME_TYPE, err_msg);
257                 return MEDIA_SVC_PLUGIN_ERROR;
258         }
259
260         content_type = __get_content_type(file_path, mime_type);
261
262         if(content_type == CONTENT_TYPE_MAX) {
263                 __set_error_message(ERR_NOT_MEDIAFILE, err_msg);
264                 return MEDIA_SVC_PLUGIN_ERROR;          //not media file
265         }
266         else
267                 return MEDIA_SVC_PLUGIN_ERROR_NONE;     //media file
268
269 }
270
271 int connect(void ** handle, char ** err_msg)
272 {
273         int ret = media_svc_connect(handle);
274
275         if(ret < 0) {
276                 __set_error_message(ret, err_msg);
277                 return MEDIA_SVC_PLUGIN_ERROR;
278         }
279
280         return MEDIA_SVC_PLUGIN_ERROR_NONE;
281 }
282
283 int disconnect(void * handle, char ** err_msg)
284 {
285         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
286
287         if(handle == NULL) {
288                 __set_error_message(ERR_HANDLE, err_msg);
289                 return MEDIA_SVC_PLUGIN_ERROR;
290         }
291
292         ret = media_svc_disconnect(handle);
293         if(ret < 0) {
294                 __set_error_message(ret, err_msg);
295                 return MEDIA_SVC_PLUGIN_ERROR;
296         }
297
298         return MEDIA_SVC_PLUGIN_ERROR_NONE;
299 }
300
301 int check_item_exist(void* handle, const char *file_path, int storage_type, char ** err_msg)
302 {
303         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
304
305         if(handle == NULL) {
306                 __set_error_message(ERR_HANDLE, err_msg);
307                 return MEDIA_SVC_PLUGIN_ERROR;
308         }
309
310         if (!STRING_VALID(file_path)) {
311                 __set_error_message(ERR_FILE_PATH, err_msg);
312                 return MEDIA_SVC_PLUGIN_ERROR;
313         }
314
315         if(!STORAGE_VALID(storage_type)) {
316                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
317                 return MEDIA_SVC_PLUGIN_ERROR;
318         }
319
320         ret = audio_svc_check_item_exist(handle, file_path);
321         if(ret == 0)
322                 return MEDIA_SVC_PLUGIN_ERROR_NONE;     //exist
323
324         ret = minfo_check_item_exist(handle, file_path);
325         if(ret == 0)
326                 return MEDIA_SVC_PLUGIN_ERROR_NONE;     //exist
327
328         __set_error_message(ERR_CHECK_ITEM, err_msg);
329         return MEDIA_SVC_PLUGIN_ERROR;          //not exist
330
331 }
332
333 int insert_item_begin(void * handle, int item_cnt, char ** err_msg)
334 {
335         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
336
337         if(handle == NULL) {
338                 __set_error_message(ERR_HANDLE, err_msg);
339                 return MEDIA_SVC_PLUGIN_ERROR;
340         }
341
342         ret = audio_svc_insert_item_start(handle, item_cnt);
343         if(ret < 0) {
344                 __set_error_message(ret, err_msg);
345                 return MEDIA_SVC_PLUGIN_ERROR;
346         }
347
348         ret = minfo_add_media_start(handle, item_cnt);
349         if(ret < 0) {
350                 __set_error_message(ret, err_msg);
351                 return MEDIA_SVC_PLUGIN_ERROR;
352         }
353
354         return MEDIA_SVC_PLUGIN_ERROR_NONE;
355 }
356
357 int insert_item_end(void * handle, char ** err_msg)
358 {
359         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
360
361         if(handle == NULL) {
362                 __set_error_message(ERR_HANDLE, err_msg);
363                 return MEDIA_SVC_PLUGIN_ERROR;
364         }
365
366         ret = audio_svc_insert_item_end(handle);
367         if(ret < 0) {
368                 __set_error_message(ret, err_msg);
369                 return MEDIA_SVC_PLUGIN_ERROR;
370         }
371
372         ret = minfo_add_media_end(handle);
373         if(ret < 0) {
374                 __set_error_message(ret, err_msg);
375                 return MEDIA_SVC_PLUGIN_ERROR;
376         }
377
378         return MEDIA_SVC_PLUGIN_ERROR_NONE;
379 }
380
381 int insert_item(void * handle, const char *file_path, int storage_type, const char * mime_type, char ** err_msg)
382 {
383         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
384
385         if(handle == NULL) {
386                 __set_error_message(ERR_HANDLE, err_msg);
387                 return MEDIA_SVC_PLUGIN_ERROR;
388         }
389
390         if (!STRING_VALID(file_path)) {
391                 __set_error_message(ERR_FILE_PATH, err_msg);
392                 return MEDIA_SVC_PLUGIN_ERROR;
393         }
394
395         if (!STRING_VALID(mime_type)) {
396                 __set_error_message(ERR_MIME_TYPE, err_msg);
397                 return MEDIA_SVC_PLUGIN_ERROR;
398         }
399
400         if(!STORAGE_VALID(storage_type)) {
401                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
402                 return MEDIA_SVC_PLUGIN_ERROR;
403         }
404
405         media_svc_content_type_e content_type = __get_content_type(file_path, mime_type);
406
407         if(content_type == CONTENT_TYPE_SOUND || content_type == CONTENT_TYPE_MUSIC)    {
408
409                 if(storage_type == MEDIA_SVC_PLUGIN_STORAGE_INTERNAL) {
410
411                         if(content_type == CONTENT_TYPE_SOUND)
412                                 ret = audio_svc_insert_item(handle, AUDIO_SVC_STORAGE_PHONE, file_path, AUDIO_SVC_CATEGORY_SOUND);
413                         else
414                                 ret = audio_svc_insert_item(handle, AUDIO_SVC_STORAGE_PHONE, file_path, AUDIO_SVC_CATEGORY_MUSIC);
415
416                 } else if (storage_type == MEDIA_SVC_PLUGIN_STORAGE_EXTERNAL) {
417
418                         if(content_type == CONTENT_TYPE_SOUND)
419                                 ret = audio_svc_insert_item(handle, AUDIO_SVC_STORAGE_MMC, file_path, AUDIO_SVC_CATEGORY_SOUND);
420                         else
421                                 ret = audio_svc_insert_item(handle, AUDIO_SVC_STORAGE_MMC, file_path, AUDIO_SVC_CATEGORY_MUSIC);
422
423                 }
424
425         } else if (content_type == CONTENT_TYPE_IMAGE || content_type == CONTENT_TYPE_VIDEO) {
426
427                 if(content_type == CONTENT_TYPE_IMAGE)
428                         ret = minfo_add_media_batch(handle, file_path, MINFO_ITEM_IMAGE);
429                 else
430                         ret = minfo_add_media_batch(handle, file_path, MINFO_ITEM_VIDEO);
431
432         } else {
433
434                 __set_error_message(ERR_NOT_MEDIAFILE, err_msg);
435                 return MEDIA_SVC_PLUGIN_ERROR;
436
437         }
438
439         if(ret < 0) {
440                 __set_error_message(ret, err_msg);
441                 return MEDIA_SVC_PLUGIN_ERROR;
442         }
443
444         return MEDIA_SVC_PLUGIN_ERROR_NONE;
445 }
446
447 int insert_item_immediately(void * handle, const char *file_path, int storage_type, const char * mime_type, char ** err_msg)
448 {
449         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
450
451         if(handle == NULL) {
452                 __set_error_message(ERR_HANDLE, err_msg);
453                 return MEDIA_SVC_PLUGIN_ERROR;
454         }
455
456         if (!STRING_VALID(file_path)) {
457                 __set_error_message(ERR_FILE_PATH, err_msg);
458                 return MEDIA_SVC_PLUGIN_ERROR;
459         }
460
461         if (!STRING_VALID(mime_type)) {
462                 __set_error_message(ERR_MIME_TYPE, err_msg);
463                 return MEDIA_SVC_PLUGIN_ERROR;
464         }
465
466         if(!STORAGE_VALID(storage_type)) {
467                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
468                 return MEDIA_SVC_PLUGIN_ERROR;
469         }
470
471         media_svc_content_type_e content_type = __get_content_type(file_path, mime_type);
472
473         if(content_type == CONTENT_TYPE_SOUND || content_type == CONTENT_TYPE_MUSIC)    {
474
475                 if(storage_type == 0) {
476
477                         if(content_type == CONTENT_TYPE_SOUND)
478                                 ret = audio_svc_insert_item_immediately(handle, AUDIO_SVC_STORAGE_PHONE, file_path, AUDIO_SVC_CATEGORY_SOUND);
479                         else
480                                 ret = audio_svc_insert_item_immediately(handle, AUDIO_SVC_STORAGE_PHONE, file_path, AUDIO_SVC_CATEGORY_MUSIC);
481
482                 } else if (storage_type == 1) {
483
484                         if(content_type == CONTENT_TYPE_SOUND)
485                                 ret = audio_svc_insert_item_immediately(handle, AUDIO_SVC_STORAGE_MMC, file_path, AUDIO_SVC_CATEGORY_SOUND);
486                         else
487                                 ret = audio_svc_insert_item_immediately(handle, AUDIO_SVC_STORAGE_MMC, file_path, AUDIO_SVC_CATEGORY_MUSIC);
488
489                 }
490
491         } else if (content_type == CONTENT_TYPE_IMAGE || content_type == CONTENT_TYPE_VIDEO) {
492
493                 if(content_type == CONTENT_TYPE_IMAGE)
494                         ret = minfo_add_media(handle, file_path, MINFO_ITEM_IMAGE);
495                 else
496                         ret = minfo_add_media(handle, file_path, MINFO_ITEM_VIDEO);
497
498         } else {
499
500                 __set_error_message(ERR_NOT_MEDIAFILE, err_msg);
501                 return MEDIA_SVC_PLUGIN_ERROR;
502
503         }
504
505         if(ret < 0) {
506                 __set_error_message(ret, err_msg);
507                 return MEDIA_SVC_PLUGIN_ERROR;
508         }
509
510         return MEDIA_SVC_PLUGIN_ERROR_NONE;
511 }
512
513
514 int move_item_begin(void * handle, int item_cnt, char ** err_msg)
515 {
516         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
517
518         if(handle == NULL) {
519                 __set_error_message(ERR_HANDLE, err_msg);
520                 return MEDIA_SVC_PLUGIN_ERROR;
521         }
522
523         ret = audio_svc_move_item_start(handle, item_cnt);
524         if(ret < 0) {
525                 __set_error_message(ret, err_msg);
526                 return MEDIA_SVC_PLUGIN_ERROR;
527         }
528
529         ret = minfo_move_media_start(handle, item_cnt);
530         if(ret < 0) {
531                 __set_error_message(ret, err_msg);
532                 return MEDIA_SVC_PLUGIN_ERROR;
533         }
534
535         return MEDIA_SVC_PLUGIN_ERROR_NONE;
536 }
537
538 int move_item_end(void * handle, char ** err_msg)
539 {
540         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
541
542         if(handle == NULL) {
543                 __set_error_message(ERR_HANDLE, err_msg);
544                 return MEDIA_SVC_PLUGIN_ERROR;
545         }
546
547         ret = audio_svc_move_item_end(handle);
548         if(ret < 0) {
549                 __set_error_message(ret, err_msg);
550                 return MEDIA_SVC_PLUGIN_ERROR;
551         }
552
553         ret = minfo_move_media_end(handle);
554         if(ret < 0) {
555                 __set_error_message(ret, err_msg);
556                 return MEDIA_SVC_PLUGIN_ERROR;
557         }
558
559         return MEDIA_SVC_PLUGIN_ERROR_NONE;
560 }
561
562 int move_item(void * handle, const char *src_path, int src_storage_type, const char *dest_path, int dest_storage_type, const char * mime_type, char ** err_msg)
563 {
564         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
565
566         if(handle == NULL) {
567                 __set_error_message(ERR_HANDLE, err_msg);
568                 return MEDIA_SVC_PLUGIN_ERROR;
569         }
570
571         if ((!STRING_VALID(src_path)) || (!STRING_VALID(dest_path))) {
572                 __set_error_message(ERR_FILE_PATH, err_msg);
573                 return MEDIA_SVC_PLUGIN_ERROR;
574         }
575
576         if (!STRING_VALID(mime_type)) {
577                 __set_error_message(ERR_MIME_TYPE, err_msg);
578                 return MEDIA_SVC_PLUGIN_ERROR;
579         }
580
581         if((!STORAGE_VALID(src_storage_type)) || (!STORAGE_VALID(dest_storage_type))) {
582                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
583                 return MEDIA_SVC_PLUGIN_ERROR;
584         }
585
586         media_svc_content_type_e content_type = __get_content_type(src_path, mime_type);
587
588         if(content_type == CONTENT_TYPE_SOUND || content_type == CONTENT_TYPE_MUSIC)    {
589
590                 ret = audio_svc_move_item(handle, src_storage_type, src_path, dest_storage_type, dest_path);
591
592         } else if (content_type == CONTENT_TYPE_IMAGE || content_type == CONTENT_TYPE_VIDEO) {
593
594                 if(content_type == CONTENT_TYPE_IMAGE)
595                         ret = minfo_move_media(handle, src_path, dest_path, MINFO_ITEM_IMAGE);
596                 else
597                         ret = minfo_move_media(handle, src_path, dest_path, MINFO_ITEM_VIDEO);
598
599         } else {
600
601                 __set_error_message(ERR_NOT_MEDIAFILE, err_msg);
602                 return MEDIA_SVC_PLUGIN_ERROR;
603
604         }
605
606         if(ret < 0) {
607                 __set_error_message(ret, err_msg);
608                 return MEDIA_SVC_PLUGIN_ERROR;
609         }
610
611         return MEDIA_SVC_PLUGIN_ERROR_NONE;
612 }
613
614
615 int set_all_storage_items_validity(void * handle, int storage_type, int validity, char ** err_msg)
616 {
617         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
618
619         if(handle == NULL) {
620                 __set_error_message(ERR_HANDLE, err_msg);
621                 return MEDIA_SVC_PLUGIN_ERROR;
622         }
623
624         if(!STORAGE_VALID(storage_type)) {
625                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
626                 return MEDIA_SVC_PLUGIN_ERROR;
627         }
628
629         if(storage_type == MEDIA_SVC_PLUGIN_STORAGE_INTERNAL) {
630                 ret = audio_svc_set_db_valid(handle, AUDIO_SVC_STORAGE_PHONE, validity);
631                 if(ret < 0) {
632                         __set_error_message(ret, err_msg);
633                         return MEDIA_SVC_PLUGIN_ERROR;
634                 }
635
636                 ret = minfo_set_db_valid(handle, MINFO_PHONE, validity);
637                 if(ret < 0) {
638                         __set_error_message(ret, err_msg);
639                         return MEDIA_SVC_PLUGIN_ERROR;
640                 }
641
642         } else if(storage_type == MEDIA_SVC_PLUGIN_STORAGE_EXTERNAL) {
643
644                 ret = audio_svc_set_db_valid(handle, AUDIO_SVC_STORAGE_MMC, validity);
645                 if(ret < 0) {
646                         __set_error_message(ret, err_msg);
647                         return MEDIA_SVC_PLUGIN_ERROR;
648                 }
649
650                 ret = minfo_set_db_valid(handle, MINFO_MMC, validity);
651                 if(ret < 0) {
652                         __set_error_message(ret, err_msg);
653                         return MEDIA_SVC_PLUGIN_ERROR;
654                 }
655         }
656
657         return MEDIA_SVC_PLUGIN_ERROR_NONE;
658 }
659
660 int set_item_validity_begin(void * handle, int item_cnt, char ** err_msg)
661 {
662         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
663
664         if(handle == NULL) {
665                 __set_error_message(ERR_HANDLE, err_msg);
666                 return MEDIA_SVC_PLUGIN_ERROR;
667         }
668
669         ret = audio_svc_set_item_valid_start(handle, item_cnt);
670         if(ret < 0) {
671                 __set_error_message(ret, err_msg);
672                 return MEDIA_SVC_PLUGIN_ERROR;
673         }
674
675         ret = minfo_set_item_valid_start(handle, item_cnt);
676         if(ret < 0) {
677                 __set_error_message(ret, err_msg);
678                 return MEDIA_SVC_PLUGIN_ERROR;
679         }
680
681         return MEDIA_SVC_PLUGIN_ERROR_NONE;
682 }
683
684 int set_item_validity_end(void * handle, char ** err_msg)
685 {
686         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
687
688         if(handle == NULL) {
689                 __set_error_message(ERR_HANDLE, err_msg);
690                 return MEDIA_SVC_PLUGIN_ERROR;
691         }
692
693         ret = audio_svc_set_item_valid_end(handle);
694         if(ret < 0) {
695                 __set_error_message(ret, err_msg);
696                 return MEDIA_SVC_PLUGIN_ERROR;
697         }
698
699         ret = minfo_set_item_valid_end(handle);
700         if(ret < 0) {
701                 __set_error_message(ret, err_msg);
702                 return MEDIA_SVC_PLUGIN_ERROR;
703         }
704
705         return MEDIA_SVC_PLUGIN_ERROR_NONE;
706 }
707
708 int set_item_validity(void * handle, const char *file_path, int storage_type, const char * mime_type, int validity, char ** err_msg)
709 {
710         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
711
712         if(handle == NULL) {
713                 __set_error_message(ERR_HANDLE, err_msg);
714                 return MEDIA_SVC_PLUGIN_ERROR;
715         }
716
717         if (!STRING_VALID(file_path)) {
718                 __set_error_message(ERR_FILE_PATH, err_msg);
719                 return MEDIA_SVC_PLUGIN_ERROR;
720         }
721
722         if (!STRING_VALID(mime_type)) {
723                 __set_error_message(ERR_MIME_TYPE, err_msg);
724                 return MEDIA_SVC_PLUGIN_ERROR;
725         }
726
727         if(!STORAGE_VALID(storage_type)) {
728                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
729                 return MEDIA_SVC_PLUGIN_ERROR;
730         }
731
732         media_svc_content_type_e content_type = __get_content_type(file_path, mime_type);
733
734         if(content_type == CONTENT_TYPE_SOUND || content_type == CONTENT_TYPE_MUSIC)    {
735
736                 ret = audio_svc_set_item_valid(handle, file_path, validity);
737
738         } else if (content_type == CONTENT_TYPE_IMAGE || content_type == CONTENT_TYPE_VIDEO) {
739
740                         if(storage_type == MEDIA_SVC_PLUGIN_STORAGE_INTERNAL)
741                                 ret = minfo_set_item_valid(handle, MINFO_PHONE, file_path, validity);
742                         else if(storage_type == MEDIA_SVC_PLUGIN_STORAGE_EXTERNAL)
743                                 ret = minfo_set_item_valid(handle, MINFO_MMC, file_path, validity);
744
745         } else {
746
747                 __set_error_message(ERR_NOT_MEDIAFILE, err_msg);
748                 return MEDIA_SVC_PLUGIN_ERROR;
749
750         }
751
752         if(ret < 0) {
753                 __set_error_message(ret, err_msg);
754                 return MEDIA_SVC_PLUGIN_ERROR;
755         }
756
757         return MEDIA_SVC_PLUGIN_ERROR_NONE;
758 }
759
760 int delete_item(void * handle, const char *file_path, int storage_type, char ** err_msg)
761 {
762         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
763
764         if(handle == NULL) {
765                 __set_error_message(ERR_HANDLE, err_msg);
766                 return MEDIA_SVC_PLUGIN_ERROR;
767         }
768
769         if (!STRING_VALID(file_path)) {
770                 __set_error_message(ERR_FILE_PATH, err_msg);
771                 return MEDIA_SVC_PLUGIN_ERROR;
772         }
773
774         if(!STORAGE_VALID(storage_type)) {
775                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
776                 return MEDIA_SVC_PLUGIN_ERROR;
777         }
778
779         ret = audio_svc_check_item_exist(handle, file_path);
780         if(ret == 0) {          /*audio file*/
781                 ret = audio_svc_delete_item_by_path(handle, file_path);
782
783                 if(ret < 0) {
784                         __set_error_message(ret, err_msg);
785                         return MEDIA_SVC_PLUGIN_ERROR;
786                 } else
787                         return MEDIA_SVC_PLUGIN_ERROR_NONE;
788         }
789
790         ret = minfo_check_item_exist(handle, file_path);
791         if(ret == 0) {          /*visual file*/
792                 ret = minfo_delete_media(handle, file_path);
793
794                 if(ret < 0) {
795                         __set_error_message(ret, err_msg);
796                         return MEDIA_SVC_PLUGIN_ERROR;
797                 }
798                 else
799                         return MEDIA_SVC_PLUGIN_ERROR_NONE;
800         } 
801
802         __set_error_message(ERR_CHECK_ITEM, err_msg);   //not exist in DB so can't delete item.
803         return MEDIA_SVC_PLUGIN_ERROR;
804 }
805
806 int delete_all_items_in_storage(void * handle, int storage_type, char ** err_msg)
807 {
808         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
809
810         if(handle == NULL) {
811                 __set_error_message(ERR_HANDLE, err_msg);
812                 return MEDIA_SVC_PLUGIN_ERROR;
813         }
814
815         if(!STORAGE_VALID(storage_type)) {
816                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
817                 return MEDIA_SVC_PLUGIN_ERROR;
818         }
819
820         if(storage_type == MEDIA_SVC_PLUGIN_STORAGE_INTERNAL) {
821
822                 ret = audio_svc_delete_all(handle, AUDIO_SVC_STORAGE_PHONE);
823                 if(ret < 0) {
824                         __set_error_message(ret, err_msg);
825                         return MEDIA_SVC_PLUGIN_ERROR;
826                 }
827
828                 ret = minfo_delete_all_media_records(handle, MINFO_PHONE);
829                 if(ret < 0) {
830                         __set_error_message(ret, err_msg);
831                         return MEDIA_SVC_PLUGIN_ERROR;
832                 }
833
834         } else if(storage_type == MEDIA_SVC_PLUGIN_STORAGE_EXTERNAL) {
835
836                 ret = audio_svc_delete_all(handle,AUDIO_SVC_STORAGE_MMC);
837                 if(ret < 0) {
838                         __set_error_message(ret, err_msg);
839                         return MEDIA_SVC_PLUGIN_ERROR;
840                 }
841                 ret = minfo_delete_all_media_records(handle, MINFO_MMC);
842                 if(ret < 0) {
843                         __set_error_message(ret, err_msg);
844                         return MEDIA_SVC_PLUGIN_ERROR;
845                 }
846         }
847
848         return MEDIA_SVC_PLUGIN_ERROR_NONE;
849 }
850
851 int delete_all_invalid_items_in_storage(void * handle, int storage_type, char ** err_msg)
852 {
853         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
854
855         if(handle == NULL) {
856                 __set_error_message(ERR_HANDLE, err_msg);
857                 return MEDIA_SVC_PLUGIN_ERROR;
858         }
859
860         if(!STORAGE_VALID(storage_type)) {
861                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
862                 return MEDIA_SVC_PLUGIN_ERROR;
863         }
864
865         if(storage_type == MEDIA_SVC_PLUGIN_STORAGE_INTERNAL) {
866
867                 ret =  audio_svc_delete_invalid_items(handle,AUDIO_SVC_STORAGE_PHONE);
868                 if(ret < 0) {
869                         __set_error_message(ret, err_msg);
870                         return MEDIA_SVC_PLUGIN_ERROR;
871                 }
872
873                 ret = minfo_delete_invalid_media_records(handle, MINFO_PHONE);
874                 if(ret < 0) {
875                         __set_error_message(ret, err_msg);
876                         return MEDIA_SVC_PLUGIN_ERROR;
877                 }
878
879         } else if(storage_type == MEDIA_SVC_PLUGIN_STORAGE_EXTERNAL) {
880
881                 ret =  audio_svc_delete_invalid_items(handle,AUDIO_SVC_STORAGE_MMC);
882                 if(ret < 0) {
883                         __set_error_message(ret, err_msg);
884                         return MEDIA_SVC_PLUGIN_ERROR;
885                 }
886
887                 ret = minfo_delete_invalid_media_records(handle, MINFO_MMC);
888                 if(ret < 0) {
889                         __set_error_message(ret, err_msg);
890                         return MEDIA_SVC_PLUGIN_ERROR;
891                 }
892         }
893
894         return MEDIA_SVC_PLUGIN_ERROR_NONE;
895 }
896
897 int delete_all_items(void * handle, char ** err_msg)
898 {
899         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
900
901         if(handle == NULL) {
902                 __set_error_message(ERR_HANDLE, err_msg);
903                 return MEDIA_SVC_PLUGIN_ERROR;
904         }
905
906         ret = delete_all_items_in_storage(handle, MEDIA_SVC_PLUGIN_STORAGE_INTERNAL, err_msg);
907         if(ret < 0)
908                 return MEDIA_SVC_PLUGIN_ERROR;
909
910         ret = delete_all_items_in_storage(handle, MEDIA_SVC_PLUGIN_STORAGE_EXTERNAL, err_msg);
911         if(ret < 0)
912                 return MEDIA_SVC_PLUGIN_ERROR;
913
914         return MEDIA_SVC_PLUGIN_ERROR_NONE;
915 }
916
917 int update_begin(void)
918 {
919         return MEDIA_SVC_PLUGIN_ERROR_NONE;
920 }
921
922 int update_end(void)
923 {
924         return MEDIA_SVC_PLUGIN_ERROR_NONE;
925 }