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, score_max = 0;
176 enum nodat {
177 NO_ID3,
178 ID3_ALMOST_GREATER_PROBE,
179 ID3_GREATER_PROBE,
180 ID3_GREATER_MAX_PROBE,
181 } nodat = NO_ID3;
182
184 lpd.
buf = (
unsigned char *) zerobuffer;
185
190 nodat = ID3_ALMOST_GREATER_PROBE;
194 nodat = ID3_GREATER_MAX_PROBE;
195 } else
196 nodat = ID3_GREATER_PROBE;
197 }
198
202 continue;
203 score = 0;
206 if (score)
209 switch (nodat) {
210 case NO_ID3:
211 score =
FFMAX(score, 1);
212 break;
213 case ID3_GREATER_PROBE:
214 case ID3_ALMOST_GREATER_PROBE:
216 break;
217 case ID3_GREATER_MAX_PROBE:
219 break;
220 }
221 }
225 }
228 if (score > score_max) {
229 score_max = score;
230 fmt = fmt1;
231 } else if (score == score_max)
233 }
234 if (nodat == ID3_GREATER_PROBE)
236 *score_ret = score_max;
237
239 }
240
242 {
243 int score_ret;
245 if (score_ret > *score_max) {
246 *score_max = score_ret;
248 } else
250 }
251
253 {
254 int score = 0;
256 }
257
259 const char *filename, void *logctx,
260 unsigned int offset,
unsigned int max_probe_size)
261 {
264 int ret = 0, probe_size, buf_offset = 0;
265 int score = 0;
266 int ret2;
267
268 if (!max_probe_size)
272 "Specified probe size value %u cannot be < %u\n", max_probe_size,
PROBE_BUF_MIN);
274 }
275
276 if (offset >= max_probe_size)
278
281 char *semi;
283 pd.
mime_type = (
const char *)mime_type_opt;
285 if (semi) {
286 *semi = '0円';
287 }
288 }
289 #if 0
293 }
295 }
296 #endif
297
299 probe_size =
FFMIN(probe_size << 1,
300 FFMAX(max_probe_size, probe_size + 1))) {
302
303 /* Read probe data. */
306 if ((ret =
avio_read(pb, buf + buf_offset,
307 probe_size - buf_offset)) < 0) {
308 /* Fail if error was not end of file, otherwise, lower score. */
311
312 score = 0;
313 ret = 0; /* error was end of file, nothing read */
314 }
315 buf_offset += ret;
316 if (buf_offset < offset)
317 continue;
320
322
323 /* Guess file format. */
325 if (*fmt) {
326 /* This can only be true in the last iteration. */
329 "Format %s detected only with low score of %d, "
330 "misdetection possible!\n", (*fmt)->name, score);
331 } else
333 "Format %s probed with size=%d and score=%d\n",
334 (*fmt)->name, probe_size, score);
335 #if 0
336 FILE *f = fopen("probestat.tmp", "ab");
337 fprintf(f, "probe_size:%d format:%s score:%d filename:%s\n", probe_size, (*fmt)->name, score, filename);
338 fclose(f);
339 #endif
340 }
341 }
342
343 if (!*fmt)
345
347 /* Rewind. Reuse probe buffer to avoid seeking. */
349 if (ret >= 0)
350 ret = ret2;
351
353 return ret < 0 ? ret : score;
354 }
355
357 const char *filename, void *logctx,
358 unsigned int offset,
unsigned int max_probe_size)
359 {
361 return ret < 0 ? ret : 0;
362 }
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char **buf, int buf_size)
Rewind the AVIOContext using the specified buffer containing the first buf_size bytes of the file...
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
AVInputFormat * av_probe_input_format3(AVProbeData *pd, int is_opened, int *score_ret)
Guess the file format.
Opaque data information usually continuous.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
const AVClass * av_class
A class for private options.
#define AVERROR_EOF
End of file.
int av_match_ext(const char *filename, const char *extensions)
Return a positive value if the given filename has one of the given extensions, 0 otherwise.
int av_probe_input_buffer2(AVIOContext *pb, AVInputFormat **fmt, const char *filename, void *logctx, unsigned int offset, unsigned int max_probe_size)
Probe a bytestream to determine the input format.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt, const char *filename, void *logctx, unsigned int offset, unsigned int max_probe_size)
Like av_probe_input_buffer2() but returns 0 on success.
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define avpriv_atomic_ptr_cas
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int av_match_name(const char *name, const char *names)
Match instances of a name in a comma-separated list of names.
static const uint8_t offset[127][2]
AVInputFormat * av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max)
Guess the file format.
const char * mime_type
mime_type, when known.
int buf_size
Size of buf except extra allocated bytes.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
enum AVCodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name, const char *filename, const char *mime_type, enum AVMediaType type)
Guess the codec ID based upon muxer and filename.
AVOutputFormat * av_guess_format(const char *short_name, const char *filename, const char *mime_type)
Return the output format in the list of registered output formats which best matches the provided par...
void av_register_input_format(AVInputFormat *format)
AVOutputFormat * av_oformat_next(const AVOutputFormat *f)
If f is NULL, returns the first registered output format, if f is non-NULL, returns the next register...
void av_register_output_format(AVOutputFormat *format)
int av_filename_number_test(const char *filename)
Check whether filename actually is a numbered sequence generator.
static const char * format
This structure contains the data a format has to probe a file.
int ff_id3v2_match(const uint8_t *buf, const char *magic)
Detect ID3v2 Header.
int av_reallocp(void *ptr, size_t size)
Allocate or reallocate a block of memory.
enum AVCodecID ff_guess_image2_codec(const char *filename)
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
int ff_id3v2_tag_len(const uint8_t *buf)
Get the length of an ID3v2 tag.
AVInputFormat * av_probe_input_format(AVProbeData *pd, int is_opened)
Guess the file format.
AVInputFormat * av_iformat_next(const AVInputFormat *f)
If f is NULL, returns the first registered input format, if f is non-NULL, returns the next registere...