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
22 #include "config_components.h"
23
28
35
36
37 /**
38 * @file
39 * Format register and lookup
40 */
41
43 {
44 const char *ext;
45
46 if (!filename)
47 return 0;
48
49 ext = strrchr(filename, '.');
50 if (ext)
52 return 0;
53 }
54
56 {
57 const char *ext;
60 char scratchpad[128];
61
62 if (!url)
63 return 0;
64
68 for (ext = uc.
query; *ext !=
'.' && ext > uc.
path; ext--)
69 ;
70
71 if (*ext != '.')
72 return 0;
73 if (uc.
query - ext >
sizeof(scratchpad))
74 return AVERROR(ENOMEM);
//not enough memory in our scratchpad
76
78 }
79
81 const char *mime_type)
82 {
86 int score_max, score;
87
88 /* specific test for image sequences */
89 #if CONFIG_IMAGE2_MUXER
90 if (!short_name && filename &&
94 }
95 #endif
96 /* Find the proper file type. */
97 score_max = 0;
99 score = 0;
101 score += 100;
103 score += 10;
106 score += 5;
107 }
108 if (score > score_max) {
109 score_max = score;
110 fmt_found = fmt;
111 }
112 }
113 return fmt_found;
114 }
115
117 const char *filename, const char *mime_type,
119 {
122 if (fmt2)
123 fmt = fmt2;
124 }
125
128
129 #if CONFIG_IMAGE2_MUXER || CONFIG_IMAGE2PIPE_MUXER
130 if (!strcmp(fmt->
name,
"image2") || !strcmp(fmt->
name,
"image2pipe")) {
132 }
133 #endif
141 else
143 }
144
146 {
151 return fmt;
153 }
154
156 int is_opened, int *score_ret)
157 {
161 int score, score_max = 0;
164 enum nodat {
165 NO_ID3,
166 ID3_ALMOST_GREATER_PROBE,
167 ID3_GREATER_PROBE,
168 ID3_GREATER_MAX_PROBE,
169 } nodat = NO_ID3;
170
172 lpd.
buf = (
unsigned char *) zerobuffer;
173
178 nodat = ID3_ALMOST_GREATER_PROBE;
182 nodat = ID3_GREATER_MAX_PROBE;
183 } else
184 nodat = ID3_GREATER_PROBE;
185 }
186
189 continue;
191 continue;
192 score = 0;
195 if (score)
198 switch (nodat) {
199 case NO_ID3:
200 score =
FFMAX(score, 1);
201 break;
202 case ID3_GREATER_PROBE:
203 case ID3_ALMOST_GREATER_PROBE:
205 break;
206 case ID3_GREATER_MAX_PROBE:
208 break;
209 }
210 }
214 }
219 }
220 }
221 if (score > score_max) {
222 score_max = score;
223 fmt = fmt1;
224 } else if (score == score_max)
226 }
227 if (nodat == ID3_GREATER_PROBE)
229 *score_ret = score_max;
230
231 return fmt;
232 }
233
235 int is_opened, int *score_max)
236 {
237 int score_ret;
239 if (score_ret > *score_max) {
240 *score_max = score_ret;
241 return fmt;
242 } else
244 }
245
247 {
248 int score = 0;
250 }
251
253 const char *filename, void *logctx,
254 unsigned int offset,
unsigned int max_probe_size)
255 {
258 int ret = 0, probe_size, buf_offset = 0;
259 int score = 0;
260 int ret2;
261 int eof = 0;
262
263 if (!max_probe_size)
267 "Specified probe size value %u cannot be < %u\n", max_probe_size,
PROBE_BUF_MIN);
269 }
270
271 if (
offset >= max_probe_size)
273
275 uint8_t *mime_type_opt =
NULL;
276 char *semi;
278 pd.
mime_type = (
const char *)mime_type_opt;
280 if (semi) {
281 *semi = '0円';
282 }
283 }
284
285 for (probe_size =
PROBE_BUF_MIN; probe_size <= max_probe_size && !*fmt && !eof;
286 probe_size =
FFMIN(probe_size << 1,
287 FFMAX(max_probe_size, probe_size + 1))) {
289
290 /* Read probe data. */
294 probe_size - buf_offset)) < 0) {
295 /* Fail if error was not end of file, otherwise, lower score. */
298
299 score = 0;
300 ret = 0;
/* error was end of file, nothing read */
301 eof = 1;
302 }
305 continue;
308
310
311 /* Guess file format. */
313 if (*fmt) {
314 /* This can only be true in the last iteration. */
317 "Format %s detected only with low score of %d, "
318 "misdetection possible!\n", (*fmt)->name, score);
319 } else
321 "Format %s probed with size=%d and score=%d\n",
322 (*fmt)->name, probe_size, score);
323 #if 0
324 FILE *
f = fopen(
"probestat.tmp",
"ab");
325 fprintf(
f,
"probe_size:%d format:%s score:%d filename:%s\n", probe_size, (*fmt)->name, score, filename);
327 #endif
328 }
329 }
330
331 if (!*fmt)
333
335 /* Rewind. Reuse probe buffer to avoid seeking. */
339
341 return ret < 0 ?
ret : score;
342 }
343
345 const char *filename, void *logctx,
346 unsigned int offset,
unsigned int max_probe_size)
347 {
350 }