4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 #include <media-thumbnail.h>
25 #include "media-svc.h"
27 #define MEDIA_SVC_PLUGIN_ERROR_NONE 0
28 #define MEDIA_SVC_PLUGIN_ERROR -1
30 #define STRING_VALID(str) \
31 ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
32 #define STORAGE_VALID(storage)\
33 (((storage == MEDIA_SVC_STORAGE_INTERNAL) || (storage == MEDIA_SVC_STORAGE_EXTERNAL)) ? TRUE : FALSE)
45 }media_svc_error_type_e;
47 #define MS_CATEGORY_UNKNOWN 0x00000000 /**< Default */
48 #define MS_CATEGORY_ETC 0x00000001 /**< ETC category */
49 #define MS_CATEGORY_IMAGE 0x00000002 /**< Image category */
50 #define MS_CATEGORY_VIDEO 0x00000004 /**< Video category */
51 #define MS_CATEGORY_MUSIC 0x00000008 /**< Music category */
52 #define MS_CATEGORY_SOUND 0x00000010 /**< Sound category */
54 #define CONTENT_TYPE_NUM 4
55 #define MUSIC_MIME_NUM 29
56 #define SOUND_MIME_NUM 1
57 #define MIME_TYPE_LENGTH 255
58 #define MIME_LENGTH 50
59 #define _3GP_FILE ".3gp"
60 #define _MP4_FILE ".mp4"
64 char content_type[15];
66 } fex_content_table_t;
68 static const fex_content_table_t content_category[CONTENT_TYPE_NUM] = {
69 {"audio", MS_CATEGORY_SOUND},
70 {"image", MS_CATEGORY_IMAGE},
71 {"video", MS_CATEGORY_VIDEO},
72 {"application", MS_CATEGORY_ETC},
75 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
76 /*known mime types of normal files*/
82 /* known mime types of drm files*/
84 "x-mp3", /*alias of audio/mpeg*/
85 "x-mpeg", /*alias of audio/mpeg*/
87 "x-ogg", /*alias of audio/ogg*/
88 "vnd.ms-playready.media.pya:*.pya", /*playready*/
91 "x-m4a", /*alias of audio/mp4*/
92 /* below mimes are rare*/
102 "x-vorbis", /*alias of audio/x-vorbis+ogg*/
103 "vorbis", /*alias of audio/x-vorbis+ogg*/
105 "x-mp2", /*alias of audio/mp2*/
106 "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
107 "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
111 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
115 static void __set_error_message(int err_type, char ** err_msg);
117 static void __set_error_message(int err_type, char ** err_msg)
124 if(err_type == ERR_HANDLE)
125 *err_msg = strdup("invalid handle");
126 else if(err_type == ERR_FILE_PATH)
127 *err_msg = strdup("invalid file path");
128 else if(err_type == ERR_FOLDER_PATH)
129 *err_msg = strdup("invalid folder path");
130 else if(err_type == ERR_MIME_TYPE)
131 *err_msg = strdup("invalid mime type");
132 else if(err_type == ERR_NOT_MEDIAFILE)
133 *err_msg = strdup("not media content");
134 else if(err_type == ERR_STORAGE_TYPE)
135 *err_msg = strdup("invalid storage type");
136 else if(err_type == ERR_CHECK_ITEM)
137 *err_msg = strdup("item does not exist");
138 else if(err_type == MEDIA_INFO_ERROR_DATABASE_CONNECT)
139 *err_msg = strdup("DB connect error");
140 else if(err_type == MEDIA_INFO_ERROR_DATABASE_DISCONNECT)
141 *err_msg = strdup("DB disconnect error");
142 else if(err_type == MEDIA_INFO_ERROR_INVALID_PARAMETER)
143 *err_msg = strdup("invalid parameter");
144 else if(err_type == MEDIA_INFO_ERROR_DATABASE_INTERNAL)
145 *err_msg = strdup("DB internal error");
146 else if(err_type == MEDIA_INFO_ERROR_DATABASE_NO_RECORD)
147 *err_msg = strdup("not found in DB");
148 else if(err_type == MEDIA_INFO_ERROR_INTERNAL)
149 *err_msg = strdup("media service internal error");
151 *err_msg = strdup("error unknown");
156 int check_item(const char *file_path, char ** err_msg)
158 if (!STRING_VALID(file_path)) {
159 __set_error_message(ERR_FILE_PATH, err_msg);
160 return MEDIA_SVC_PLUGIN_ERROR;
163 return MEDIA_SVC_PLUGIN_ERROR_NONE;
166 int connect(void ** handle, uid_t uid, char ** err_msg)
168 int ret = media_svc_connect(handle,uid);
171 __set_error_message(ret, err_msg);
172 return MEDIA_SVC_PLUGIN_ERROR;
175 return MEDIA_SVC_PLUGIN_ERROR_NONE;
178 int disconnect(void * handle, char ** err_msg)
180 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
183 __set_error_message(ERR_HANDLE, err_msg);
184 return MEDIA_SVC_PLUGIN_ERROR;
187 ret = media_svc_disconnect(handle);
189 __set_error_message(ret, err_msg);
190 return MEDIA_SVC_PLUGIN_ERROR;
193 return MEDIA_SVC_PLUGIN_ERROR_NONE;
196 int check_item_exist(void* handle, const char *file_path, int storage_type, char ** err_msg)
198 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
201 __set_error_message(ERR_HANDLE, err_msg);
202 return MEDIA_SVC_PLUGIN_ERROR;
205 if (!STRING_VALID(file_path)) {
206 __set_error_message(ERR_FILE_PATH, err_msg);
207 return MEDIA_SVC_PLUGIN_ERROR;
210 if(!STORAGE_VALID(storage_type)) {
211 __set_error_message(ERR_STORAGE_TYPE, err_msg);
212 return MEDIA_SVC_PLUGIN_ERROR;
215 ret = media_svc_check_item_exist_by_path(handle, file_path);
216 if(ret == MEDIA_INFO_ERROR_NONE)
217 return MEDIA_SVC_PLUGIN_ERROR_NONE; //exist
219 __set_error_message(ERR_CHECK_ITEM, err_msg);
221 return MEDIA_SVC_PLUGIN_ERROR; //not exist
224 int insert_item_begin(void * handle, int item_cnt, int with_noti, int from_pid, char ** err_msg)
226 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
229 __set_error_message(ERR_HANDLE, err_msg);
230 return MEDIA_SVC_PLUGIN_ERROR;
233 ret = media_svc_insert_item_begin(handle, item_cnt, with_noti, from_pid);
235 __set_error_message(ret, err_msg);
236 return MEDIA_SVC_PLUGIN_ERROR;
239 return MEDIA_SVC_PLUGIN_ERROR_NONE;
242 int insert_item_end(void * handle, uid_t uid, char ** err_msg)
244 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
247 __set_error_message(ERR_HANDLE, err_msg);
248 return MEDIA_SVC_PLUGIN_ERROR;
251 ret = media_svc_insert_item_end(handle, uid);
253 __set_error_message(ret, err_msg);
254 return MEDIA_SVC_PLUGIN_ERROR;
257 return MEDIA_SVC_PLUGIN_ERROR_NONE;
260 int insert_item(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg)
262 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
265 __set_error_message(ERR_HANDLE, err_msg);
266 return MEDIA_SVC_PLUGIN_ERROR;
269 if (!STRING_VALID(file_path)) {
270 __set_error_message(ERR_FILE_PATH, err_msg);
271 return MEDIA_SVC_PLUGIN_ERROR;
274 if(!STORAGE_VALID(storage_type)) {
275 __set_error_message(ERR_STORAGE_TYPE, err_msg);
276 return MEDIA_SVC_PLUGIN_ERROR;
279 ret = media_svc_insert_item_bulk(handle, storage_type, file_path, FALSE, uid);
281 __set_error_message(ret, err_msg);
282 return MEDIA_SVC_PLUGIN_ERROR;
285 return MEDIA_SVC_PLUGIN_ERROR_NONE;
288 int insert_item_immediately(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg)
290 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
293 __set_error_message(ERR_HANDLE, err_msg);
294 return MEDIA_SVC_PLUGIN_ERROR;
297 if (!STRING_VALID(file_path)) {
298 __set_error_message(ERR_FILE_PATH, err_msg);
299 return MEDIA_SVC_PLUGIN_ERROR;
302 if(!STORAGE_VALID(storage_type)) {
303 __set_error_message(ERR_STORAGE_TYPE, err_msg);
304 return MEDIA_SVC_PLUGIN_ERROR;
307 ret = media_svc_insert_item_immediately(handle, storage_type, file_path, uid);
309 __set_error_message(ret, err_msg);
310 return MEDIA_SVC_PLUGIN_ERROR;
313 return MEDIA_SVC_PLUGIN_ERROR_NONE;
316 int insert_burst_item(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg)
318 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
321 __set_error_message(ERR_HANDLE, err_msg);
322 return MEDIA_SVC_PLUGIN_ERROR;
325 if (!STRING_VALID(file_path)) {
326 __set_error_message(ERR_FILE_PATH, err_msg);
327 return MEDIA_SVC_PLUGIN_ERROR;
330 if(!STORAGE_VALID(storage_type)) {
331 __set_error_message(ERR_STORAGE_TYPE, err_msg);
332 return MEDIA_SVC_PLUGIN_ERROR;
335 ret = media_svc_insert_item_bulk(handle, storage_type, file_path, TRUE, uid);
337 __set_error_message(ret, err_msg);
338 return MEDIA_SVC_PLUGIN_ERROR;
341 return MEDIA_SVC_PLUGIN_ERROR_NONE;
344 int move_item_begin(void * handle, int item_cnt, char ** err_msg)
346 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
349 __set_error_message(ERR_HANDLE, err_msg);
350 return MEDIA_SVC_PLUGIN_ERROR;
353 ret = media_svc_move_item_begin(handle, item_cnt);
355 __set_error_message(ret, err_msg);
356 return MEDIA_SVC_PLUGIN_ERROR;
359 return MEDIA_SVC_PLUGIN_ERROR_NONE;
362 int move_item_end(void * handle, uid_t uid, char ** err_msg)
364 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
367 __set_error_message(ERR_HANDLE, err_msg);
368 return MEDIA_SVC_PLUGIN_ERROR;
371 ret = media_svc_move_item_end(handle, uid);
373 __set_error_message(ret, err_msg);
374 return MEDIA_SVC_PLUGIN_ERROR;
377 return MEDIA_SVC_PLUGIN_ERROR_NONE;
380 int move_item(void * handle, const char *src_path, int src_storage_type, const char *dest_path, int dest_storage_type, uid_t uid, char ** err_msg)
382 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
385 __set_error_message(ERR_HANDLE, err_msg);
386 return MEDIA_SVC_PLUGIN_ERROR;
389 if ((!STRING_VALID(src_path)) || (!STRING_VALID(dest_path))) {
390 __set_error_message(ERR_FILE_PATH, err_msg);
391 return MEDIA_SVC_PLUGIN_ERROR;
394 if((!STORAGE_VALID(src_storage_type)) || (!STORAGE_VALID(dest_storage_type))) {
395 __set_error_message(ERR_STORAGE_TYPE, err_msg);
396 return MEDIA_SVC_PLUGIN_ERROR;
399 ret = media_svc_move_item(handle, src_storage_type, src_path, dest_storage_type, dest_path, uid);
401 __set_error_message(ret, err_msg);
402 return MEDIA_SVC_PLUGIN_ERROR;
405 return MEDIA_SVC_PLUGIN_ERROR_NONE;
408 int set_all_storage_items_validity(void * handle, int storage_type, int validity, uid_t uid, char ** err_msg)
410 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
413 __set_error_message(ERR_HANDLE, err_msg);
414 return MEDIA_SVC_PLUGIN_ERROR;
417 if(!STORAGE_VALID(storage_type)) {
418 __set_error_message(ERR_STORAGE_TYPE, err_msg);
419 return MEDIA_SVC_PLUGIN_ERROR;
422 ret = media_svc_set_all_storage_items_validity(handle, storage_type, validity, uid);
424 __set_error_message(ret, err_msg);
425 return MEDIA_SVC_PLUGIN_ERROR;
428 return MEDIA_SVC_PLUGIN_ERROR_NONE;
431 int set_folder_item_validity(void * handle, const char * folder_path, int validity, int recursive, uid_t uid, char ** err_msg)
433 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
436 __set_error_message(ERR_HANDLE, err_msg);
437 return MEDIA_SVC_PLUGIN_ERROR;
440 if (!STRING_VALID(folder_path)) {
441 __set_error_message(ERR_FOLDER_PATH, err_msg);
442 return MEDIA_SVC_PLUGIN_ERROR;
445 ret = media_svc_set_folder_items_validity(handle, folder_path, validity, recursive, uid);
447 __set_error_message(ret, err_msg);
448 return MEDIA_SVC_PLUGIN_ERROR;
451 return MEDIA_SVC_PLUGIN_ERROR_NONE;
454 int set_item_validity_begin(void * handle, int item_cnt, char ** err_msg)
456 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
459 __set_error_message(ERR_HANDLE, err_msg);
460 return MEDIA_SVC_PLUGIN_ERROR;
463 ret = media_svc_set_item_validity_begin(handle, item_cnt);
465 __set_error_message(ret, err_msg);
466 return MEDIA_SVC_PLUGIN_ERROR;
469 return MEDIA_SVC_PLUGIN_ERROR_NONE;
472 int set_item_validity_end(void * handle, uid_t uid, char ** err_msg)
474 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
477 __set_error_message(ERR_HANDLE, err_msg);
478 return MEDIA_SVC_PLUGIN_ERROR;
481 ret = media_svc_set_item_validity_end(handle, uid);
483 __set_error_message(ret, err_msg);
484 return MEDIA_SVC_PLUGIN_ERROR;
487 return MEDIA_SVC_PLUGIN_ERROR_NONE;
490 int set_item_validity(void * handle, const char *file_path, int storage_type, int validity, uid_t uid, char ** err_msg)
492 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
495 __set_error_message(ERR_HANDLE, err_msg);
496 return MEDIA_SVC_PLUGIN_ERROR;
499 if (!STRING_VALID(file_path)) {
500 __set_error_message(ERR_FILE_PATH, err_msg);
501 return MEDIA_SVC_PLUGIN_ERROR;
504 if(!STORAGE_VALID(storage_type)) {
505 __set_error_message(ERR_STORAGE_TYPE, err_msg);
506 return MEDIA_SVC_PLUGIN_ERROR;
509 ret = media_svc_set_item_validity(handle, file_path, validity, uid);
512 __set_error_message(ret, err_msg);
513 return MEDIA_SVC_PLUGIN_ERROR;
516 return MEDIA_SVC_PLUGIN_ERROR_NONE;
519 int delete_item(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg)
521 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
524 __set_error_message(ERR_HANDLE, err_msg);
525 return MEDIA_SVC_PLUGIN_ERROR;
528 if (!STRING_VALID(file_path)) {
529 __set_error_message(ERR_FILE_PATH, err_msg);
530 return MEDIA_SVC_PLUGIN_ERROR;
533 if(!STORAGE_VALID(storage_type)) {
534 __set_error_message(ERR_STORAGE_TYPE, err_msg);
535 return MEDIA_SVC_PLUGIN_ERROR;
538 ret = media_svc_check_item_exist_by_path(handle, file_path);
540 ret = media_svc_delete_item_by_path(handle, file_path, uid);
543 __set_error_message(ret, err_msg);
544 return MEDIA_SVC_PLUGIN_ERROR;
547 return MEDIA_SVC_PLUGIN_ERROR_NONE;
550 __set_error_message(ERR_CHECK_ITEM, err_msg); //not exist in DB so can't delete item.
551 return MEDIA_SVC_PLUGIN_ERROR;
554 int delete_all_items_in_storage(void * handle, int storage_type, uid_t uid, char ** err_msg)
556 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
559 __set_error_message(ERR_HANDLE, err_msg);
560 return MEDIA_SVC_PLUGIN_ERROR;
563 if(!STORAGE_VALID(storage_type)) {
564 __set_error_message(ERR_STORAGE_TYPE, err_msg);
565 return MEDIA_SVC_PLUGIN_ERROR;
568 ret = media_svc_delete_all_items_in_storage(handle, storage_type, uid);
570 __set_error_message(ret, err_msg);
571 return MEDIA_SVC_PLUGIN_ERROR;
574 return MEDIA_SVC_PLUGIN_ERROR_NONE;
577 int delete_all_invalid_items_in_storage(void * handle, int storage_type, uid_t uid, char ** err_msg)
579 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
582 __set_error_message(ERR_HANDLE, err_msg);
583 return MEDIA_SVC_PLUGIN_ERROR;
586 if(!STORAGE_VALID(storage_type)) {
587 __set_error_message(ERR_STORAGE_TYPE, err_msg);
588 return MEDIA_SVC_PLUGIN_ERROR;
591 ret = media_svc_delete_invalid_items_in_storage(handle, storage_type, uid);
593 __set_error_message(ret, err_msg);
594 return MEDIA_SVC_PLUGIN_ERROR;
597 return MEDIA_SVC_PLUGIN_ERROR_NONE;
600 int delete_all_invalid_items_in_folder(void * handle, const char *folder_path, uid_t uid, char ** err_msg)
602 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
605 __set_error_message(ERR_HANDLE, err_msg);
606 return MEDIA_SVC_PLUGIN_ERROR;
609 if (!STRING_VALID(folder_path)) {
610 __set_error_message(ERR_FOLDER_PATH, err_msg);
611 return MEDIA_SVC_PLUGIN_ERROR;
614 ret = media_svc_delete_invalid_items_in_folder(handle, folder_path, uid);
616 __set_error_message(ret, err_msg);
617 return MEDIA_SVC_PLUGIN_ERROR;
620 return MEDIA_SVC_PLUGIN_ERROR_NONE;
623 int delete_all_items(void * handle, uid_t uid ,char ** err_msg)
625 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
628 __set_error_message(ERR_HANDLE, err_msg);
629 return MEDIA_SVC_PLUGIN_ERROR;
632 ret = delete_all_items_in_storage(handle, MEDIA_SVC_STORAGE_INTERNAL, uid, err_msg);
634 return MEDIA_SVC_PLUGIN_ERROR;
636 ret = delete_all_items_in_storage(handle, MEDIA_SVC_STORAGE_EXTERNAL, uid, err_msg);
638 return MEDIA_SVC_PLUGIN_ERROR;
640 return MEDIA_SVC_PLUGIN_ERROR_NONE;
643 int refresh_item(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg)
645 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
648 __set_error_message(ERR_HANDLE, err_msg);
649 return MEDIA_SVC_PLUGIN_ERROR;
652 if (!STRING_VALID(file_path)) {
653 __set_error_message(ERR_FILE_PATH, err_msg);
654 return MEDIA_SVC_PLUGIN_ERROR;
657 if(!STORAGE_VALID(storage_type)) {
658 __set_error_message(ERR_STORAGE_TYPE, err_msg);
659 return MEDIA_SVC_PLUGIN_ERROR;
662 ret = media_svc_refresh_item(handle, storage_type, file_path, uid);
664 __set_error_message(ret, err_msg);
665 return MEDIA_SVC_PLUGIN_ERROR;
668 return MEDIA_SVC_PLUGIN_ERROR_NONE;
671 int update_begin(void)
673 return MEDIA_SVC_PLUGIN_ERROR_NONE;
676 int update_end(uid_t uid)
678 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
680 ret = thumbnail_request_extract_all_thumbs(uid);
682 return MEDIA_SVC_PLUGIN_ERROR;
685 return MEDIA_SVC_PLUGIN_ERROR_NONE;
688 int send_dir_update_noti(void * handle, const char *dir_path, char **err_msg)
690 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
692 if (!STRING_VALID(dir_path)) {
693 __set_error_message(ERR_FOLDER_PATH, err_msg);
694 return MEDIA_SVC_PLUGIN_ERROR;
697 ret = media_svc_send_dir_update_noti(handle, dir_path);
699 __set_error_message(ret, err_msg);
700 return MEDIA_SVC_PLUGIN_ERROR;
703 return MEDIA_SVC_PLUGIN_ERROR_NONE;
706 int count_delete_items_in_folder(void * handle, const char *folder_path, int *count, char ** err_msg)
708 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
711 __set_error_message(ERR_HANDLE, err_msg);
712 return MEDIA_SVC_PLUGIN_ERROR;
716 __set_error_message(ERR_HANDLE, err_msg);
717 return MEDIA_SVC_PLUGIN_ERROR;
720 if (!STRING_VALID(folder_path)) {
721 __set_error_message(ERR_FOLDER_PATH, err_msg);
722 return MEDIA_SVC_PLUGIN_ERROR;
725 ret = media_svc_count_invalid_items_in_folder(handle, folder_path, count);
727 __set_error_message(ret, err_msg);
728 return MEDIA_SVC_PLUGIN_ERROR;
731 return MEDIA_SVC_PLUGIN_ERROR_NONE;