summaryrefslogtreecommitdiff
path: root/libavformat/format.c
diff options
context:
space:
mode:
authorLuca Barbato <lu_zero@gentoo.org>2014-03-13 22:11:12 +0100
committerLuca Barbato <lu_zero@gentoo.org>2014-07-29 17:47:26 +0200
commit3a19405d574a467c68b48e4b824c76617fd59de0 (patch)
treefab823ed19b1b1cf1ee30c9a9f6b1388bd2f0fef /libavformat/format.c
parent69e7336b8e16ee65226fc20381baf537f4b125e6 (diff)
avformat: Use the mime type information in input probe
It should provide a quicker guess for elementary streams provided by http.
Diffstat (limited to 'libavformat/format.c')
-rw-r--r--libavformat/format.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/libavformat/format.c b/libavformat/format.c
index 1dd83f5587..93829ae072 100644
--- a/libavformat/format.c
+++ b/libavformat/format.c
@@ -20,6 +20,7 @@
*/
#include "libavutil/avstring.h"
+#include "libavutil/opt.h"
#include "avio_internal.h"
#include "avformat.h"
@@ -194,6 +195,10 @@ AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened,
if (av_match_ext(lpd.filename, fmt1->extensions))
score = AVPROBE_SCORE_EXTENSION;
}
+#ifdef FF_API_PROBE_MIME
+ if (av_match_name(lpd.mime_type, fmt1->mime_type))
+ score = FFMAX(score, AVPROBE_SCORE_EXTENSION);
+#endif
if (score > *score_max) {
*score_max = score;
fmt = fmt1;
@@ -251,7 +256,10 @@ int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
return AVERROR(EINVAL);
avio_skip(pb, offset);
max_probe_size -= offset;
-
+#ifdef FF_API_PROBE_MIME
+ if (pb->av_class)
+ av_opt_get(pb, "mime_type", AV_OPT_SEARCH_CHILDREN, &pd.mime_type);
+#endif
for (probe_size = PROBE_BUF_MIN; probe_size <= max_probe_size && !*fmt;
probe_size = FFMIN(probe_size << 1,
FFMAX(max_probe_size, probe_size + 1))) {
@@ -259,14 +267,13 @@ int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
/* Read probe data. */
if ((ret = av_reallocp(&buf, probe_size + AVPROBE_PADDING_SIZE)) < 0)
- return ret;
+ goto fail;
if ((ret = avio_read(pb, buf + pd.buf_size,
probe_size - pd.buf_size)) < 0) {
/* Fail if error was not end of file, otherwise, lower score. */
- if (ret != AVERROR_EOF) {
- av_free(buf);
- return ret;
- }
+ if (ret != AVERROR_EOF)
+ goto fail;
+
score = 0;
ret = 0; /* error was end of file, nothing read */
}
@@ -289,14 +296,17 @@ int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
}
}
- if (!*fmt) {
- av_free(buf);
- return AVERROR_INVALIDDATA;
- }
+ if (!*fmt)
+ ret = AVERROR_INVALIDDATA;
+fail:
/* Rewind. Reuse probe buffer to avoid seeking. */
- if ((ret = ffio_rewind_with_probe_data(pb, buf, pd.buf_size)) < 0)
+ if (ret < 0 ||
+ (ret = ffio_rewind_with_probe_data(pb, buf, pd.buf_size)) < 0) {
av_free(buf);
-
+ }
+#ifdef FF_API_PROBE_MIME
+ av_free(pd.mime_type);
+#endif
return ret;
}