[FFmpeg-devel] [PATCH] avformat: export probe score

Michael Niedermayer michaelni at gmx.at
Thu Aug 8 22:45:28 CEST 2013


Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libavformat/avformat.h      |   17 +++++++++++++++--
 libavformat/options_table.h |    1 +
 libavformat/utils.c         |   18 ++++++++++++++----
 3 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index d5f8a29..6afdcf5 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1237,6 +1237,13 @@ typedef struct AVFormatContext {
      */
     int flush_packets;
 
+    /**
+     * format probing score
+     * - encoding: unused
+     * - decoding: set by avformat, read by user via AVOPtions (NO direct access)
+     */
+    int probe_score;
+
     /*****************************************************************
      * 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
@@ -1510,13 +1517,19 @@ AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score
  * @param logctx the log context
  * @param offset the offset within the bytestream to probe from
  * @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
  * 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,
                           const char *filename, void *logctx,
                           unsigned int offset, unsigned int max_probe_size);
-
 /**
  * Open an input stream and read the header. The codecs are not opened.
  * The stream must be closed with av_close_input_file().
diff --git a/libavformat/options_table.h b/libavformat/options_table.h
index a87868e..cf7f2da 100644
--- a/libavformat/options_table.h
+++ b/libavformat/options_table.h
@@ -76,6 +76,7 @@ static const AVOption avformat_options[] = {
 {"skip_initial_bytes", "skip initial bytes", OFFSET(skip_initial_bytes), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX-1, D},
 {"correct_ts_overflow", "correct single timestamp overflows", OFFSET(correct_ts_overflow), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, D},
 {"flush_packets", "enable flushing of the I/O context after each packet", OFFSET(flush_packets), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, E},
+{"probe_score", "score with which the format was probed", OFFSET(probe_score), AV_OPT_TYPE_INT, {.i64 = 0}, 0, AVPROBE_SCORE_MAX, D},
 {NULL},
 };
 
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 727711b..c0ff4fc 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -317,7 +317,7 @@ int av_demuxer_open(AVFormatContext *ic){
 #define PROBE_BUF_MIN 2048
 #define PROBE_BUF_MAX (1<<20)
 
-int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
+int av_probe_input_buffer2(AVIOContext *pb, AVInputFormat **fmt,
                           const char *filename, void *logctx,
                           unsigned int offset, unsigned int max_probe_size)
 {
@@ -398,6 +398,15 @@ int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
     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 */
 static int init_input(AVFormatContext *s, const char *filename, AVDictionary **options)
 {
@@ -408,7 +417,7 @@ static int init_input(AVFormatContext *s, const char *filename, AVDictionary **o
     if (s->pb) {
         s->flags |= AVFMT_FLAG_CUSTOM_IO;
         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)
             av_log(s, AV_LOG_WARNING, "Custom AVIOContext makes no sense and "
                                       "will be ignored with AVFMT_NOFILE format.\n");
@@ -417,14 +426,14 @@ static int init_input(AVFormatContext *s, const char *filename, AVDictionary **o
 
     if ( (s->iformat && s->iformat->flags & AVFMT_NOFILE) ||
         (!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,
                           &s->interrupt_callback, options)) < 0)
         return ret;
     if (s->iformat)
         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,
@@ -484,6 +493,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma
 
     if ((ret = init_input(s, filename, &tmp)) < 0)
         goto fail;
+    s->probe_score = ret;
     avio_skip(s->pb, s->skip_initial_bytes);
 
     /* check filename in case an image number is expected */
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list