support webm format
[platform/core/multimedia/libmm-fileinfo.git] / utils / mm_file_util_mime.c
1 /*
2  * libmm-fileinfo
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: 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 <stdlib.h>
23 #include <string.h>
24 #include "mm_file_debug.h"
25 #include "mm_file_utils.h"
26
27 typedef struct _mmfileavmimetype {
28         char    mimetype[MMFILE_MIMETYPE_MAX_LEN];
29         char    ffmpegFormat[MMFILE_FILE_FMT_MAX_LEN];
30         char    extension[MMFILE_FILE_EXT_MAX_LEN];
31 } MMFileAVMimeType;
32
33 const MMFileAVMimeType MMFILE_FFMPEG_MIME_TABLE[] = {
34         {"audio/mpeg",          "mp3",      "mp3"},
35         {"audio/mp3",           "mp3",      "mp3"},
36         {"audio/mpg3",          "mp3",      "mp3"},
37         {"audio/mpeg3",         "mp3",      "mp3"},
38         {"audio/mpg",           "mp3",      "mp3"},
39         {"audio/x-mpeg",        "mp3",      "mp3"},
40         {"audio/x-mp3",         "mp3",      "mp3"},
41         {"audio/x-mpeg3",       "mp3",      "mp3"},
42         {"audio/x-mpg",         "mp3",      "mp3"},
43         {"audio/x-mpegaudio",   "mp3",      "mp3"},  /*10 */
44
45         {"video/3gpp",          "mov,mp4,m4a,3gp,3g2,mj2",      "3gp"},
46         {"video/h263",          "mov,mp4,m4a,3gp,3g2,mj2",      "3gp"},
47         {"video/3gp",           "mov,mp4,m4a,3gp,3g2,mj2",      "3gp"},
48         {"video/3gpp",          "mov,mp4,m4a,3gp,3g2,mj2",      "3gp"},
49         {"video/mp4v-es",       "mov,mp4,m4a,3gp,3g2,mj2",      "mp4"},
50         {"video/dvd",           "mov,mp4,m4a,3gp,3g2,mj2",      "mpeg"},
51         {"audio/3gpp",          "mov,mp4,m4a,3gp,3g2,mj2",      "3gp"},  /*17 */
52
53         {"video/mpeg4",         "mov,mp4,m4a,3gp,3g2,mj2",      "mp4"},
54         {"video/mp4",           "mov,mp4,m4a,3gp,3g2,mj2",      "mp4"},
55         {"video/x-mp4",         "mov,mp4,m4a,3gp,3g2,mj2",      "mp4"},
56         {"video/x-pv-mp4",      "mov,mp4,m4a,3gp,3g2,mj2",      "mp4"},
57         {"audio/mp4",           "mov,mp4,m4a,3gp,3g2,mj2",      "mp4"},
58         {"audio/MP4A-LATM",     "mov,mp4,m4a,3gp,3g2,mj2",      "mp4"},
59         {"audio/mpeg4",         "mov,mp4,m4a,3gp,3g2,mj2",      "mp4"},
60         {"audio/m4a",           "mov,mp4,m4a,3gp,3g2,mj2",      "mp4"}, /*25 */
61
62         {"video/avi",           "avi",      "avi"},
63         {"video/divx",          "divx",     "divx"},
64
65         {"audio/x-ms-asf",      "asf",      "asf"},
66         {"video/x-ms-asf",      "asf",      "asf"},
67         {"video/x-ms-asf",      "asf",      "asf"},
68
69         {"video/x-ms-wmv",      "asf",      "wmv"},
70         {"audio/wma",           "asf",      "wma"},
71         {"audio/x-ms-wma",      "asf",      "wma"},
72
73         {"audio/wave",          "wav",      "wav"},     /* Not Sure */
74         {"audio/wav",           "wav",      "wav"},     /* Not Sure */
75         {"audio/x-wave",        "wav",      "wav"},     /* Not Sure */
76         {"audio/x-wav",         "wav",      "wav"},     /* Not Sure */
77
78         {"audio/aac",           "aac",      "aac"},     /* Not Sure */
79         {"audio/g72",           "aac",      "aac"},     /* Not Sure */ /*39 */
80
81         {"audio/AMR",           "amr",      "amr"},     /* Not Sure */
82         {"audio/amr-wb",        "amr",      "amr"},     /* Not Sure */
83         {"audio/x-amr",         "amr",      "amr"},     /* Not Sure */
84
85         {"audio/x-mid",         "mid",      "mid"},     /* Not Sure */
86         {"audio/x-midi",        "mid",      "mid"},     /* Not Sure */
87         {"audio/mid",           "mid",      "mid"},     /* Not Sure */
88         {"audio/midi",          "mid",      "mid"},     /* Not Sure */
89         {"audio/mid",           "mid",      "mid"},     /* Not Sure */  /*47 */
90
91         {"audio/iMelody",       "imy",      "imy"},     /* Not Sure */
92         {"audio/imelody",       "imy",      "imy"},     /* Not Sure */
93         {"audio/melody",        "imy",      "imy"},     /* Not Sure */
94         {"audio/imy",           "imy",      "imy"},     /* Not Sure */
95         {"audio/x-iMelody",     "imy",      "imy"},     /* Not Sure */
96
97         {"audio/basic",         "snd",      ""},     /* Not Sure */
98         {"audio/pmd",           "pmd",      ""},     /* Not Sure */
99         {"audio/sp-midi",       "smp",      ""},     /* Not Sure */ /*55 */
100
101         {"audio/mmf",           "mmf",      "mmf"},     /* Not Sure */
102         {"audio/smaf",          "mmf",      "mmf"},     /* Not Sure */
103         {"audio/x-mmf",         "mmf",      "mmf"},     /* Not Sure */
104         {"audio/x-smaf",        "mmf",      "mmf"},     /* Not Sure */
105
106         {"audio/xmf",           "xmf",      "xmf"},     /* Not Sure */
107         {"audio/mobile-xmf",    "xmf",      "xmf"},     /* Not Sure */
108         {"audio/x-xmf",         "xmf",      "xmf"},     /* Not Sure */ /*62 */
109
110         {"audio/vnd.rn-realaudio",              "rm",   ""},  /* Not Sure */
111         {"audio/x-pn-multirate-realaudio",      "rm",   ""},  /* Not Sure */
112         {"audio/x-pn-multirate-realaudio-live", "rm",   ""},  /* Not Sure */
113         {"video/vnd.rn-realvideo",              "rm",   ""},  /* Not Sure */
114         {"video/vnd.rn-realmedia",              "rm",   ""},  /* Not Sure */
115         {"video/x-pn-multirate-realvideo",      "rm",   ""},  /* Not Sure */ /*68 */
116
117         {"video/ogg",           "ogg",      "ogg"},
118         {"video/theora",        "ogg",      "ogg"},
119         {"audio/ogg",           "ogg",      "ogg"},
120         {"audio/x-ogg",         "ogg",      "ogg"},
121         {"audio/vorbis",        "ogg",      "ogg"},  /*73 */
122
123         {"audio/x-flac",        "flac",      "flac"},  /*74 */
124         {"video/x-flv",        "flv",      "flv"},  /*75 */
125         {"video/MP2T",        "mpegts",      "ts"},
126         {"video/MP2P",        "mpeg",      "mpg"},
127         {"video/mpeg",          "mpegvideo",      "mpeg"}, /*mpeg 1 video */
128 };
129
130
131 EXPORT_API
132 int mmfile_util_get_ffmpeg_format(const char *mime, char *ffmpegFormat)
133 {
134         int i = 0;
135         int table_size = sizeof(MMFILE_FFMPEG_MIME_TABLE) / sizeof(MMFileAVMimeType);
136
137         if (NULL == mime || NULL == ffmpegFormat) {
138                 debug_error(DEBUG, "error: mmfile_util_get_format\n");
139                 return MMFILE_UTIL_FAIL;
140         }
141
142         for (i = 0; i < table_size; i++) {
143                 if (!strcasecmp(MMFILE_FFMPEG_MIME_TABLE[i].mimetype, mime)) {
144                         break;
145                 }
146         }
147
148         if (i == table_size) {
149                 debug_error(DEBUG, "error: not found[%s]\n", mime);
150                 return MMFILE_UTIL_FAIL;
151         }
152
153         memcpy(ffmpegFormat, MMFILE_FFMPEG_MIME_TABLE[i].ffmpegFormat, strlen(MMFILE_FFMPEG_MIME_TABLE[i].ffmpegFormat));
154
155         return MMFILE_UTIL_SUCCESS;
156 }
157
158
159 EXPORT_API
160 int mmfile_util_get_file_ext(const char *mime, char *ext)
161 {
162         int i = 0;
163         int table_size = sizeof(MMFILE_FFMPEG_MIME_TABLE) / sizeof(MMFileAVMimeType);
164
165         if (NULL == mime || NULL == ext) {
166                 debug_error(DEBUG, "error: mmfile_util_get_file_ext\n");
167                 return MMFILE_UTIL_FAIL;
168         }
169
170         for (i = 0; i < table_size; i++) {
171                 if (!strcasecmp(MMFILE_FFMPEG_MIME_TABLE[i].mimetype, mime)) {
172                         break;
173                 }
174         }
175
176         if (i == table_size) {
177                 debug_error(DEBUG, "error: not found[%s]\n", mime);
178                 return MMFILE_UTIL_FAIL;
179         }
180
181         memcpy(ext, MMFILE_FFMPEG_MIME_TABLE[i].extension, strlen(MMFILE_FFMPEG_MIME_TABLE[i].extension));
182
183         return MMFILE_UTIL_SUCCESS;
184 }
185
186