Commit e31db621 authored by Michael Niedermayer's avatar Michael Niedermayer

avformat: export probe score

Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 90411f7e
...@@ -137,6 +137,10 @@ non-monotonic negative timestamps. ...@@ -137,6 +137,10 @@ non-monotonic negative timestamps.
Flush the underlying I/O stream after each packet. Default 1 enables it, and Flush the underlying I/O stream after each packet. Default 1 enables it, and
has the effect of reducing the latency; 0 disables it and may slightly has the effect of reducing the latency; 0 disables it and may slightly
increase performance in some cases. increase performance in some cases.
@item probe_score @var{integer} (@emph{input})
This field is only accessible programatically, its value represents the score
by which the format was detected.
@end table @end table
@c man end FORMAT OPTIONS @c man end FORMAT OPTIONS
......
...@@ -1237,6 +1237,15 @@ typedef struct AVFormatContext { ...@@ -1237,6 +1237,15 @@ typedef struct AVFormatContext {
*/ */
int flush_packets; int flush_packets;
/**
* format probing score.
* The maximal score is AVPROBE_SCORE_MAX, its set when the demuxer probes
* the format.
* - encoding: unused
* - decoding: set by avformat, read by user via av_format_get_probe_score() (NO direct access)
*/
int probe_score;
/***************************************************************** /*****************************************************************
* All fields below this line are not part of the public API. They * All fields below this line are not part of the public API. They
* may not be used outside of libavformat and can be changed and * may not be used outside of libavformat and can be changed and
...@@ -1296,6 +1305,8 @@ typedef struct AVFormatContext { ...@@ -1296,6 +1305,8 @@ typedef struct AVFormatContext {
int io_repositioned; int io_repositioned;
} AVFormatContext; } AVFormatContext;
int av_format_get_probe_score(const AVFormatContext *s);
/** /**
* Returns the method used to set ctx->duration. * Returns the method used to set ctx->duration.
* *
...@@ -1504,9 +1515,17 @@ AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score ...@@ -1504,9 +1515,17 @@ AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score
* @param logctx the log context * @param logctx the log context
* @param offset the offset within the bytestream to probe from * @param offset the offset within the bytestream to probe from
* @param max_probe_size the maximum probe buffer size (zero for default) * @param max_probe_size the maximum probe buffer size (zero for default)
* @return 0 in case of success, a negative value corresponding to an * @return the score in case of success, a negative value corresponding to an
* the maximal score is AVPROBE_SCORE_MAX
* AVERROR code otherwise * AVERROR code otherwise
*/ */
int av_probe_input_buffer2(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
*/
int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt, int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
const char *filename, void *logctx, const char *filename, void *logctx,
unsigned int offset, unsigned int max_probe_size); unsigned int offset, unsigned int max_probe_size);
......
...@@ -100,6 +100,11 @@ static int64_t wrap_timestamp(AVStream *st, int64_t timestamp) ...@@ -100,6 +100,11 @@ static int64_t wrap_timestamp(AVStream *st, int64_t timestamp)
MAKE_ACCESSORS(AVStream, stream, AVRational, r_frame_rate) MAKE_ACCESSORS(AVStream, stream, AVRational, r_frame_rate)
int av_format_get_probe_score(const AVFormatContext *s)
{
return s->probe_score;
}
/* an arbitrarily chosen "sane" max packet size -- 50M */ /* an arbitrarily chosen "sane" max packet size -- 50M */
#define SANE_CHUNK_SIZE (50000000) #define SANE_CHUNK_SIZE (50000000)
...@@ -309,7 +314,7 @@ int av_demuxer_open(AVFormatContext *ic){ ...@@ -309,7 +314,7 @@ int av_demuxer_open(AVFormatContext *ic){
} }
int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt, int av_probe_input_buffer2(AVIOContext *pb, AVInputFormat **fmt,
const char *filename, void *logctx, const char *filename, void *logctx,
unsigned int offset, unsigned int max_probe_size) unsigned int offset, unsigned int max_probe_size)
{ {
...@@ -390,6 +395,15 @@ int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt, ...@@ -390,6 +395,15 @@ int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
return ret; return ret;
} }
int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
const char *filename, void *logctx,
unsigned int offset, unsigned int max_probe_size)
{
int ret = av_probe_input_buffer2(pb, fmt, filename, logctx, offset, max_probe_size);
return ret < 0 ? ret : 0;
}
/* open input file and probe the format if necessary */ /* open input file and probe the format if necessary */
static int init_input(AVFormatContext *s, const char *filename, AVDictionary **options) static int init_input(AVFormatContext *s, const char *filename, AVDictionary **options)
{ {
...@@ -400,7 +414,7 @@ static int init_input(AVFormatContext *s, const char *filename, AVDictionary **o ...@@ -400,7 +414,7 @@ static int init_input(AVFormatContext *s, const char *filename, AVDictionary **o
if (s->pb) { if (s->pb) {
s->flags |= AVFMT_FLAG_CUSTOM_IO; s->flags |= AVFMT_FLAG_CUSTOM_IO;
if (!s->iformat) if (!s->iformat)
return av_probe_input_buffer(s->pb, &s->iformat, filename, s, 0, s->probesize); return av_probe_input_buffer2(s->pb, &s->iformat, filename, s, 0, s->probesize);
else if (s->iformat->flags & AVFMT_NOFILE) else if (s->iformat->flags & AVFMT_NOFILE)
av_log(s, AV_LOG_WARNING, "Custom AVIOContext makes no sense and " av_log(s, AV_LOG_WARNING, "Custom AVIOContext makes no sense and "
"will be ignored with AVFMT_NOFILE format.\n"); "will be ignored with AVFMT_NOFILE format.\n");
...@@ -409,14 +423,14 @@ static int init_input(AVFormatContext *s, const char *filename, AVDictionary **o ...@@ -409,14 +423,14 @@ static int init_input(AVFormatContext *s, const char *filename, AVDictionary **o
if ( (s->iformat && s->iformat->flags & AVFMT_NOFILE) || if ( (s->iformat && s->iformat->flags & AVFMT_NOFILE) ||
(!s->iformat && (s->iformat = av_probe_input_format2(&pd, 0, &score)))) (!s->iformat && (s->iformat = av_probe_input_format2(&pd, 0, &score))))
return 0; return score;
if ((ret = avio_open2(&s->pb, filename, AVIO_FLAG_READ | s->avio_flags, if ((ret = avio_open2(&s->pb, filename, AVIO_FLAG_READ | s->avio_flags,
&s->interrupt_callback, options)) < 0) &s->interrupt_callback, options)) < 0)
return ret; return ret;
if (s->iformat) if (s->iformat)
return 0; return 0;
return av_probe_input_buffer(s->pb, &s->iformat, filename, s, 0, s->probesize); return av_probe_input_buffer2(s->pb, &s->iformat, filename, s, 0, s->probesize);
} }
static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt, static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt,
...@@ -476,6 +490,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma ...@@ -476,6 +490,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma
if ((ret = init_input(s, filename, &tmp)) < 0) if ((ret = init_input(s, filename, &tmp)) < 0)
goto fail; goto fail;
s->probe_score = ret;
avio_skip(s->pb, s->skip_initial_bytes); avio_skip(s->pb, s->skip_initial_bytes);
/* check filename in case an image number is expected */ /* check filename in case an image number is expected */
......
...@@ -30,8 +30,8 @@ ...@@ -30,8 +30,8 @@
#include "libavutil/avutil.h" #include "libavutil/avutil.h"
#define LIBAVFORMAT_VERSION_MAJOR 55 #define LIBAVFORMAT_VERSION_MAJOR 55
#define LIBAVFORMAT_VERSION_MINOR 14 #define LIBAVFORMAT_VERSION_MINOR 15
#define LIBAVFORMAT_VERSION_MICRO 102 #define LIBAVFORMAT_VERSION_MICRO 100
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \ LIBAVFORMAT_VERSION_MINOR, \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment