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 #ifndef _MEDIA_SVC_UTIL_H_
25 #define _MEDIA_SVC_UTIL_H_
30 #include <drm_client.h>
31 #include "media-svc-types.h"
32 #include "media-svc-env.h"
45 #define SAFE_FREE(src) { if(src) {free(src); src = NULL;}}
46 #define STRING_VALID(str) \
47 ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
49 char *_media_info_generate_uuid(void);
50 char *_media_svc_escape_str(char *input, int len);
51 void _strncpy_safe(char *x_dst, const char *x_src, int max_len);
52 unsigned int _media_svc_get_current_time(void);
53 int _media_svc_rename_file( const char *old_name, const char *new_name);
54 bool _media_svc_remove_file(const char *path);
55 int _media_svc_remove_all_files_in_dir(const char *dir_path);
56 char *_media_svc_get_title_from_filepath (const char *path);
57 int _media_svc_save_image(void *image, int size, char *image_path, uid_t uid);
58 bool _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid);
59 bool _media_svc_get_file_ext(const char *file_path, char *file_ext);
60 int _media_svc_get_file_time(const char *full_path);
61 int _media_svc_set_media_info(media_svc_content_info_s *content_info, media_svc_storage_type_e storage_type,
62 const char *path, media_svc_media_type_e *media_type, bool refresh, drm_content_info_s **drm_contentInfo);
63 int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info, media_svc_media_type_e media_type);
64 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type, drm_content_info_s *drm_contentInfo, uid_t uid);
65 int __media_svc_malloc_and_strncpy(char **dst, const char *src);
66 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info);
67 int _media_svc_get_store_type_by_path(const char *path, media_svc_storage_type_e *storage_type);
68 char *_media_svc_replace_path(char *s, const char *olds, const char *news);
69 char* _media_svc_get_thumb_internal_path(uid_t uid);
70 char* _media_svc_get_thumb_external_path(uid_t uid);
71 int _media_svc_error_convert(int error);
73 /* Define data structures for media type and mime type */
74 #define MEDIA_SVC_CATEGORY_UNKNOWN 0x00000000 /**< Default */
75 #define MEDIA_SVC_CATEGORY_ETC 0x00000001 /**< ETC category */
76 #define MEDIA_SVC_CATEGORY_IMAGE 0x00000002 /**< Image category */
77 #define MEDIA_SVC_CATEGORY_VIDEO 0x00000004 /**< Video category */
78 #define MEDIA_SVC_CATEGORY_MUSIC 0x00000008 /**< Music category */
79 #define MEDIA_SVC_CATEGORY_SOUND 0x00000010 /**< Sound category */
81 #define CONTENT_TYPE_NUM 4
82 #define MUSIC_MIME_NUM 29
83 #define SOUND_MIME_NUM 1
84 #define MIME_TYPE_LENGTH 255
85 #define MIME_LENGTH 50
86 #define _3GP_FILE ".3gp"
87 #define _MP4_FILE ".mp4"
90 char content_type[15];
92 } _media_svc_content_table_s;
94 static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
95 {"audio", MEDIA_SVC_CATEGORY_SOUND},
96 {"image", MEDIA_SVC_CATEGORY_IMAGE},
97 {"video", MEDIA_SVC_CATEGORY_VIDEO},
98 {"application", MEDIA_SVC_CATEGORY_ETC},
101 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
102 /*known mime types of normal files*/
108 /* known mime types of drm files*/
110 "x-mp3", /*alias of audio/mpeg*/
111 "x-mpeg", /*alias of audio/mpeg*/
113 "x-ogg", /*alias of audio/ogg*/
114 "vnd.ms-playready.media.pya:*.pya", /*playready*/
117 "x-m4a", /*alias of audio/mp4*/
118 /* below mimes are rare*/
128 "x-vorbis", /*alias of audio/x-vorbis+ogg*/
129 "vorbis", /*alias of audio/x-vorbis+ogg*/
131 "x-mp2", /*alias of audio/mp2*/
132 "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
133 "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
137 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
141 bool _media_svc_is_drm_file(const char *path);
142 int _media_svc_get_mime_in_drm_info(const char *path, char *mime, drm_content_info_s **drm_contentInfo);
143 int _media_svc_get_content_type_from_mime(const char * path, const char * mimetype, int * category);
145 int _media_svc_get_mime_type(const char *path, char *mimetype, drm_bool_type_e *is_drm, drm_content_info_s **drm_contentInfo);
147 int _media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type);
153 #endif /*_MEDIA_SVC_UTIL_H_*/