MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / av_probe_input_buffer2

Function av_probe_input_buffer2

libavformat/format.c:256–346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

254}
255
256int av_probe_input_buffer2(AVIOContext *pb, const AVInputFormat **fmt,
257 const char *filename, void *logctx,
258 unsigned int offset, unsigned int max_probe_size)
259{
260 AVProbeData pd = { filename ? filename : "" };
261 uint8_t *buf = NULL;
262 int ret = 0, probe_size, buf_offset = 0;
263 int score = 0;
264 int ret2;
265 int eof = 0;
266
267 if (!max_probe_size)
268 max_probe_size = PROBE_BUF_MAX;
269 else if (max_probe_size < PROBE_BUF_MIN) {
270 av_log(logctx, AV_LOG_ERROR,
271 "Specified probe size value %u cannot be < %u\n", max_probe_size, PROBE_BUF_MIN);
272 return AVERROR(EINVAL);
273 }
274
275 if (offset >= max_probe_size)
276 return AVERROR(EINVAL);
277
278 if (pb->av_class) {
279 uint8_t *mime_type_opt = NULL;
280 char *semi;
281 av_opt_get(pb, "mime_type", AV_OPT_SEARCH_CHILDREN, &mime_type_opt);
282 pd.mime_type = (const char *)mime_type_opt;
283 semi = pd.mime_type ? strchr(pd.mime_type, ';') : NULL;
284 if (semi) {
285 *semi = '\0';
286 }
287 }
288
289 for (probe_size = PROBE_BUF_MIN; probe_size <= max_probe_size && !*fmt && !eof;
290 probe_size = FFMIN(probe_size << 1,
291 FFMAX(max_probe_size, probe_size + 1))) {
292 score = probe_size < max_probe_size ? AVPROBE_SCORE_RETRY : 0;
293
294 /* Read probe data. */
295 if ((ret = av_reallocp(&buf, probe_size + AVPROBE_PADDING_SIZE)) < 0)
296 goto fail;
297 if ((ret = avio_read(pb, buf + buf_offset,
298 probe_size - buf_offset)) < 0) {
299 /* Fail if error was not end of file, otherwise, lower score. */
300 if (ret != AVERROR_EOF)
301 goto fail;
302
303 score = 0;
304 ret = 0; /* error was end of file, nothing read */
305 eof = 1;
306 }
307 buf_offset += ret;
308 if (buf_offset < offset)
309 continue;
310 pd.buf_size = buf_offset - offset;
311 pd.buf = &buf[offset];
312
313 memset(pd.buf + pd.buf_size, 0, AVPROBE_PADDING_SIZE);

Callers 2

init_inputFunction · 0.85
av_probe_input_bufferFunction · 0.85

Calls 7

av_logFunction · 0.85
av_opt_getFunction · 0.85
av_reallocpFunction · 0.85
avio_readFunction · 0.85
av_probe_input_format2Function · 0.85
av_freepFunction · 0.85

Tested by

no test coverage detected