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
33
34
35 /**
36 * @file
37 * Format register and lookup
38 */
39
41 {
42 const char *ext;
43
44 if (!filename)
45 return 0;
46
47 ext = strrchr(filename, '.');
48 if (ext)
50 return 0;
51 }
52
54 const char *mime_type)
55 {
59 int score_max, score;
60
61 /* specific test for image sequences */
62 #if CONFIG_IMAGE2_MUXER
63 if (!short_name && filename &&
67 }
68 #endif
69 /* Find the proper file type. */
70 score_max = 0;
72 score = 0;
74 score += 100;
76 score += 10;
79 score += 5;
80 }
81 if (score > score_max) {
82 score_max = score;
83 fmt_found = fmt;
84 }
85 }
86 return fmt_found;
87 }
88
90 const char *filename, const char *mime_type,
92 {
95 if (fmt2)
96 fmt = fmt2;
97 }
98
101
102 #if CONFIG_IMAGE2_MUXER || CONFIG_IMAGE2PIPE_MUXER
103 if (!strcmp(fmt->
name,
"image2") || !strcmp(fmt->
name,
"image2pipe")) {
105 }
106 #endif
116 else
118 }
119
121 {
126 return fmt;
128 }
129
131 int is_opened, int *score_ret)
132 {
136 int score, score_max = 0;
139 enum nodat {
140 NO_ID3,
141 ID3_ALMOST_GREATER_PROBE,
142 ID3_GREATER_PROBE,
143 ID3_GREATER_MAX_PROBE,
144 } nodat = NO_ID3;
145
147 lpd.
buf = (
unsigned char *) zerobuffer;
148
153 nodat = ID3_ALMOST_GREATER_PROBE;
157 nodat = ID3_GREATER_MAX_PROBE;
158 } else
159 nodat = ID3_GREATER_PROBE;
160 }
161
164 continue;
166 continue;
167 score = 0;
170 if (score)
173 switch (nodat) {
174 case NO_ID3:
175 score =
FFMAX(score, 1);
176 break;
177 case ID3_GREATER_PROBE:
178 case ID3_ALMOST_GREATER_PROBE:
180 break;
181 case ID3_GREATER_MAX_PROBE:
183 break;
184 }
185 }
189 }
194 }
195 }
196 if (score > score_max) {
197 score_max = score;
198 fmt = fmt1;
199 } else if (score == score_max)
201 }
202 if (nodat == ID3_GREATER_PROBE)
204 *score_ret = score_max;
205
206 return fmt;
207 }
208
210 int is_opened, int *score_max)
211 {
212 int score_ret;
214 if (score_ret > *score_max) {
215 *score_max = score_ret;
216 return fmt;
217 } else
219 }
220
222 {
223 int score = 0;
225 }
226
228 const char *filename, void *logctx,
229 unsigned int offset,
unsigned int max_probe_size)
230 {
233 int ret = 0, probe_size, buf_offset = 0;
234 int score = 0;
235 int ret2;
236
237 if (!max_probe_size)
241 "Specified probe size value %u cannot be < %u\n", max_probe_size,
PROBE_BUF_MIN);
243 }
244
245 if (
offset >= max_probe_size)
247
249 uint8_t *mime_type_opt =
NULL;
250 char *semi;
252 pd.
mime_type = (
const char *)mime_type_opt;
254 if (semi) {
255 *semi = '0円';
256 }
257 }
258
259 for (probe_size =
PROBE_BUF_MIN; probe_size <= max_probe_size && !*fmt;
260 probe_size =
FFMIN(probe_size << 1,
261 FFMAX(max_probe_size, probe_size + 1))) {
263
264 /* Read probe data. */
268 probe_size - buf_offset)) < 0) {
269 /* Fail if error was not end of file, otherwise, lower score. */
272
273 score = 0;
274 ret = 0;
/* error was end of file, nothing read */
275 }
278 continue;
281
283
284 /* Guess file format. */
286 if (*fmt) {
287 /* This can only be true in the last iteration. */
290 "Format %s detected only with low score of %d, "
291 "misdetection possible!\n", (*fmt)->name, score);
292 } else
294 "Format %s probed with size=%d and score=%d\n",
295 (*fmt)->name, probe_size, score);
296 #if 0
297 FILE *
f = fopen(
"probestat.tmp",
"ab");
298 fprintf(
f,
"probe_size:%d format:%s score:%d filename:%s\n", probe_size, (*fmt)->name, score, filename);
300 #endif
301 }
302 }
303
304 if (!*fmt)
306
308 /* Rewind. Reuse probe buffer to avoid seeking. */
312
314 return ret < 0 ?
ret : score;
315 }
316
318 const char *filename, void *logctx,
319 unsigned int offset,
unsigned int max_probe_size)
320 {
323 }