1 /*
2 * Format register and lookup
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
26
31
32
33 /**
34 * @file
35 * Format register and lookup
36 */
37
39 {
40 const char *ext;
41
42 if (!filename)
43 return 0;
44
45 ext = strrchr(filename, '.');
46 if (ext)
48 return 0;
49 }
50
52 const char *mime_type)
53 {
57 int score_max, score;
58
59 /* specific test for image sequences */
60 #if CONFIG_IMAGE2_MUXER
61 if (!short_name && filename &&
65 }
66 #endif
67 /* Find the proper file type. */
68 score_max = 0;
70 score = 0;
72 score += 100;
74 score += 10;
77 score += 5;
78 }
79 if (score > score_max) {
80 score_max = score;
81 fmt_found = fmt;
82 }
83 }
84 return fmt_found;
85 }
86
88 const char *filename, const char *mime_type,
90 {
93 if (fmt2)
94 fmt = fmt2;
95 }
96
99
100 #if CONFIG_IMAGE2_MUXER
101 if (!strcmp(fmt->
name,
"image2") || !strcmp(fmt->
name,
"image2pipe")) {
103 }
104 #endif
114 else
116 }
117
119 {
124 return fmt;
126 }
127
129 int is_opened, int *score_ret)
130 {
134 int score, score_max = 0;
137 enum nodat {
138 NO_ID3,
139 ID3_ALMOST_GREATER_PROBE,
140 ID3_GREATER_PROBE,
141 ID3_GREATER_MAX_PROBE,
142 } nodat = NO_ID3;
143
145 lpd.
buf = (
unsigned char *) zerobuffer;
146
151 nodat = ID3_ALMOST_GREATER_PROBE;
155 nodat = ID3_GREATER_MAX_PROBE;
156 } else
157 nodat = ID3_GREATER_PROBE;
158 }
159
162 continue;
164 continue;
165 score = 0;
168 if (score)
171 switch (nodat) {
172 case NO_ID3:
173 score =
FFMAX(score, 1);
174 break;
175 case ID3_GREATER_PROBE:
176 case ID3_ALMOST_GREATER_PROBE:
178 break;
179 case ID3_GREATER_MAX_PROBE:
181 break;
182 }
183 }
187 }
192 }
193 }
194 if (score > score_max) {
195 score_max = score;
196 fmt = fmt1;
197 } else if (score == score_max)
199 }
200 if (nodat == ID3_GREATER_PROBE)
202 *score_ret = score_max;
203
204 return fmt;
205 }
206
208 int is_opened, int *score_max)
209 {
210 int score_ret;
212 if (score_ret > *score_max) {
213 *score_max = score_ret;
214 return fmt;
215 } else
217 }
218
220 {
221 int score = 0;
223 }
224
226 const char *filename, void *logctx,
227 unsigned int offset,
unsigned int max_probe_size)
228 {
231 int ret = 0, probe_size, buf_offset = 0;
232 int score = 0;
233 int ret2;
234
235 if (!max_probe_size)
239 "Specified probe size value %u cannot be < %u\n", max_probe_size,
PROBE_BUF_MIN);
241 }
242
243 if (
offset >= max_probe_size)
245
247 uint8_t *mime_type_opt =
NULL;
248 char *semi;
250 pd.
mime_type = (
const char *)mime_type_opt;
252 if (semi) {
253 *semi = '0円';
254 }
255 }
256
257 for (probe_size =
PROBE_BUF_MIN; probe_size <= max_probe_size && !*fmt;
258 probe_size =
FFMIN(probe_size << 1,
259 FFMAX(max_probe_size, probe_size + 1))) {
261
262 /* Read probe data. */
266 probe_size - buf_offset)) < 0) {
267 /* Fail if error was not end of file, otherwise, lower score. */
270
271 score = 0;
272 ret = 0;
/* error was end of file, nothing read */
273 }
276 continue;
279
281
282 /* Guess file format. */
284 if (*fmt) {
285 /* This can only be true in the last iteration. */
288 "Format %s detected only with low score of %d, "
289 "misdetection possible!\n", (*fmt)->name, score);
290 } else
292 "Format %s probed with size=%d and score=%d\n",
293 (*fmt)->name, probe_size, score);
294 #if 0
295 FILE *
f = fopen(
"probestat.tmp",
"ab");
296 fprintf(
f,
"probe_size:%d format:%s score:%d filename:%s\n", probe_size, (*fmt)->name, score, filename);
298 #endif
299 }
300 }
301
302 if (!*fmt)
304
306 /* Rewind. Reuse probe buffer to avoid seeking. */
310
312 return ret < 0 ?
ret : score;
313 }
314
316 const char *filename, void *logctx,
317 unsigned int offset,
unsigned int max_probe_size)
318 {
321 }