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 /** head of registered input format linked list */
39 /** head of registered output format linked list */
41
44
46 {
47 if (f)
49 else
51 }
52
54 {
55 if (f)
57 else
59 }
60
62 {
64
68 last_iformat = &format->
next;
69 }
70
72 {
74
78 last_oformat = &format->
next;
79 }
80
82 {
83 const char *ext;
84
85 if (!filename)
86 return 0;
87
88 ext = strrchr(filename, '.');
89 if (ext)
91 return 0;
92 }
93
95 const char *mime_type)
96 {
98 int score_max, score;
99
100 /* specific test for image sequences */
101 #if CONFIG_IMAGE2_MUXER
102 if (!short_name && filename &&
106 }
107 #endif
108 /* Find the proper file type. */
110 score_max = 0;
112 score = 0;
114 score += 100;
116 score += 10;
119 score += 5;
120 }
121 if (score > score_max) {
122 score_max = score;
124 }
125 }
126 return fmt_found;
127 }
128
130 const char *filename, const char *mime_type,
132 {
135 if (fmt2)
136 fmt = fmt2;
137 }
138
141
142 #if CONFIG_IMAGE2_MUXER
143 if (!strcmp(fmt->
name,
"image2") || !strcmp(fmt->
name,
"image2pipe")) {
145 }
146 #endif
156 else
158 }
159
161 {
167 }
168
170 int *score_ret)
171 {
174 int score, nodat = 0, score_max = 0;
176
178 lpd.
buf = zerobuffer;
179
186 nodat = 2;
187 } else
188 nodat = 1;
189 }
190
194 continue;
195 score = 0;
199 if (nodat == 0) score =
FFMAX(score, 1);
202 }
206 }
209 if (score > score_max) {
210 score_max = score;
211 fmt = fmt1;
212 } else if (score == score_max)
214 }
215 if (nodat == 1)
217 *score_ret = score_max;
218
220 }
221
223 {
224 int score_ret;
226 if (score_ret > *score_max) {
227 *score_max = score_ret;
229 } else
231 }
232
234 {
235 int score = 0;
237 }
238
240 const char *filename, void *logctx,
241 unsigned int offset,
unsigned int max_probe_size)
242 {
245 int ret = 0, probe_size, buf_offset = 0;
246 int score = 0;
247 int ret2;
248
249 if (!max_probe_size)
253 "Specified probe size value %u cannot be < %u\n", max_probe_size,
PROBE_BUF_MIN);
255 }
256
257 if (offset >= max_probe_size)
259
263 pd.
mime_type = (
const char *)mime_type_opt;
264 }
265 #if 0
269 }
271 }
272 #endif
273
275 probe_size =
FFMIN(probe_size << 1,
276 FFMAX(max_probe_size, probe_size + 1))) {
278
279 /* Read probe data. */
281 goto fail;
282 if ((ret =
avio_read(pb, buf + buf_offset,
283 probe_size - buf_offset)) < 0) {
284 /* Fail if error was not end of file, otherwise, lower score. */
286 goto fail;
287
288 score = 0;
289 ret = 0; /* error was end of file, nothing read */
290 }
292 if (buf_offset < offset)
293 continue;
296
298
299 /* Guess file format. */
301 if (*fmt) {
302 /* This can only be true in the last iteration. */
305 "Format %s detected only with low score of %d, "
306 "misdetection possible!\n", (*fmt)->name, score);
307 } else
309 "Format %s probed with size=%d and score=%d\n",
310 (*fmt)->name, probe_size, score);
311 #if 0
312 FILE *f = fopen("probestat.tmp", "ab");
313 fprintf(f, "probe_size:%d format:%s score:%d filename:%s\n", probe_size, (*fmt)->name, score, filename);
314 fclose(f);
315 #endif
316 }
317 }
318
319 if (!*fmt)
321
322 fail:
323 /* Rewind. Reuse probe buffer to avoid seeking. */
325 if (ret >= 0)
326 ret = ret2;
327
329 return ret < 0 ? ret : score;
330 }
331
333 const char *filename, void *logctx,
334 unsigned int offset,
unsigned int max_probe_size)
335 {
337 return ret < 0 ? ret : 0;
338 }