Remove drm source code.
[platform/core/multimedia/libmedia-service.git] / src / include / common / media-svc-util.h
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
23
24 #ifndef _MEDIA_SVC_UTIL_H_
25 #define _MEDIA_SVC_UTIL_H_
26
27 #include <string.h>
28 #include <stdbool.h>
29 #include <sqlite3.h>
30 #include "media-svc-types.h"
31 #include "media-svc-env.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 #ifndef FALSE
38 #define FALSE  0
39 #endif
40 #ifndef TRUE
41 #define TRUE   1
42 #endif
43
44 #define SAFE_FREE(src)      { if(src) {free(src); src = NULL;}}
45 #define STRING_VALID(str)       \
46         ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
47
48 char *_media_info_generate_uuid(void);
49 char *_media_svc_escape_str(char *input, int len);
50 void _strncpy_safe(char *x_dst, const char *x_src, int max_len);
51 unsigned int _media_svc_get_current_time(void);
52 int _media_svc_rename_file( const char *old_name, const char *new_name);
53 bool _media_svc_remove_file(const char *path);
54 int _media_svc_remove_all_files_in_dir(const char *dir_path);
55 char *_media_svc_get_title_from_filepath (const char *path);
56 int _media_svc_save_image(void *image, int size, char *image_path, uid_t uid);
57 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);
58 bool _media_svc_get_file_ext(const char *file_path, char *file_ext);
59 int _media_svc_get_file_time(const char *full_path);
60 int _media_svc_set_media_info(media_svc_content_info_s *content_info, media_svc_storage_type_e storage_type,
61                           const char *path, media_svc_media_type_e *media_type, bool refresh);
62 int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info, media_svc_media_type_e media_type);
63 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type, uid_t uid);
64 int __media_svc_malloc_and_strncpy(char **dst, const char *src);
65 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info);
66 int _media_svc_get_store_type_by_path(const char *path, media_svc_storage_type_e *storage_type);
67 char *_media_svc_replace_path(char *s, const char *olds, const char *news);
68 char* _media_svc_get_thumb_internal_path(uid_t uid);
69 char* _media_svc_get_thumb_external_path(uid_t uid);
70 int _media_svc_error_convert(int error);
71
72 /* Define data structures for media type and mime type */
73 #define MEDIA_SVC_CATEGORY_UNKNOWN      0x00000000      /**< Default */
74 #define MEDIA_SVC_CATEGORY_ETC          0x00000001      /**< ETC category */
75 #define MEDIA_SVC_CATEGORY_IMAGE        0x00000002      /**< Image category */
76 #define MEDIA_SVC_CATEGORY_VIDEO        0x00000004      /**< Video category */
77 #define MEDIA_SVC_CATEGORY_MUSIC        0x00000008      /**< Music category */
78 #define MEDIA_SVC_CATEGORY_SOUND        0x00000010      /**< Sound category */
79
80 #define CONTENT_TYPE_NUM 4
81 #define MUSIC_MIME_NUM 29
82 #define SOUND_MIME_NUM 1
83 #define MIME_TYPE_LENGTH 255
84 #define MIME_LENGTH 50
85 #define _3GP_FILE ".3gp"
86 #define _MP4_FILE ".mp4"
87
88 typedef struct {
89         char content_type[15];
90         int category_by_mime;
91 } _media_svc_content_table_s;
92
93 static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
94         {"audio", MEDIA_SVC_CATEGORY_SOUND},
95         {"image", MEDIA_SVC_CATEGORY_IMAGE},
96         {"video", MEDIA_SVC_CATEGORY_VIDEO},
97         {"application", MEDIA_SVC_CATEGORY_ETC},
98 };
99
100 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
101         /*known mime types of normal files*/
102         "mpeg",
103         "ogg",
104         "x-ms-wma",
105         "x-flac",
106         "mp4",
107         /* known mime types of drm files*/
108         "mp3",
109         "x-mp3", /*alias of audio/mpeg*/
110         "x-mpeg", /*alias of audio/mpeg*/
111         "3gpp",
112         "x-ogg", /*alias of  audio/ogg*/
113         "vnd.ms-playready.media.pya:*.pya", /*playready*/
114         "wma",
115         "aac",
116         "x-m4a", /*alias of audio/mp4*/
117         /* below mimes are rare*/
118         "x-vorbis+ogg",
119         "x-flac+ogg",
120         "x-matroska",
121         "ac3",
122         "mp2",
123         "x-ape",
124         "x-ms-asx",
125         "vnd.rn-realaudio",
126
127         "x-vorbis", /*alias of audio/x-vorbis+ogg*/
128         "vorbis", /*alias of audio/x-vorbis+ogg*/
129         "x-oggflac",
130         "x-mp2", /*alias of audio/mp2*/
131         "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
132         "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
133         "x-wav",
134 };
135
136 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
137         "x-smaf",
138 };
139
140 bool _media_svc_is_drm_file(const char *path);
141 int _media_svc_get_content_type_from_mime(const char * path, const char * mimetype, int * category);
142 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str);
143 bool _media_svc_check_pinyin_support(void);
144 int _media_svc_get_mime_type(const char *path, char *mimetype);
145 int _media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type);
146
147 #ifdef __cplusplus
148 }
149 #endif
150
151 #endif /*_MEDIA_SVC_UTIL_H_*/