[PATCH 1/3] avformat: add support for codecs to set probe fallbacks

Anssi Hannula anssi.hannula
Tue Aug 10 17:02:02 CEST 2010


---
 libavformat/avformat.h |   12 +++++++++++-
 libavformat/utils.c    |   33 +++++++++++++++++++++++++++++++--
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 8ba2d81..45596a9 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -22,7 +22,7 @@
 #define AVFORMAT_AVFORMAT_H
 
 #define LIBAVFORMAT_VERSION_MAJOR 52
-#define LIBAVFORMAT_VERSION_MINOR 77
+#define LIBAVFORMAT_VERSION_MINOR 78
 #define LIBAVFORMAT_VERSION_MICRO  0
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
@@ -536,6 +536,16 @@ typedef struct AVStream {
      * Number of frames that have been demuxed during av_find_stream_info()
      */
     int codec_info_nb_frames;
+
+    /**
+     * Codec id to select if no codec is found by probe.
+     * When set, codec probe will select the fallback id immediately when no
+     * codec with score >= AVPROBE_SCORE_MAX / 4 is found, or if the maximum
+     * probe packet count is reached before any codec with
+     * score > AVPROBE_SCORE_MAX / 4 is found.
+     * Not part of public API.
+     */
+    enum CodecID probe_fallback_codec_id;
 } AVStream;
 
 #define AV_PROGRAM_RUNNING 1
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 1aa965c..247cfec 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -387,7 +387,24 @@ static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, AVProbeDa
         { "mpegvideo", CODEC_ID_MPEG2VIDEO, AVMEDIA_TYPE_VIDEO },
         { 0 }
     };
-    AVInputFormat *fmt = av_probe_input_format2(pd, 1, &score);
+    AVInputFormat *fmt;
+    int min_score = score;
+
+    /* for detecting the "continue probe" case where probe score matches the
+       probe score threshold */
+    if (st->probe_fallback_codec_id)
+        score--;
+
+    fmt = av_probe_input_format2(pd, 1, &score);
+
+    if (st->probe_fallback_codec_id) {
+        if (!fmt) {
+            st->codec->codec_id = st->probe_fallback_codec_id;
+            av_log(s, AV_LOG_DEBUG, "Selected fallback codec id with size=%d, packets=%d\n",
+                   pd->buf_size, MAX_PROBE_PACKETS - st->probe_packets);
+        } else if (score == min_score)
+            fmt = NULL;
+    }
 
     if (fmt) {
         int i;
@@ -702,7 +719,17 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt)
 
             if(av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)){
                 //FIXME we dont reduce score to 0 for the case of running out of buffer space in bytes
-                set_codec_from_probe_data(s, st, pd, st->probe_packets > 0 ? AVPROBE_SCORE_MAX/4 : 0);
+                int score = AVPROBE_SCORE_MAX / 4;
+                if (st->probe_packets <= 0) {
+                    if (st->probe_fallback_codec_id) {
+                        st->codec->codec_id = st->probe_fallback_codec_id;
+                        av_log(s, AV_LOG_DEBUG, "selected fallback codec id "
+                                                "for %d\n", st->index);
+                        continue;
+                    } else
+                        score = 0;
+                }
+                set_codec_from_probe_data(s, st, pd, score);
                 if(st->codec->codec_id != CODEC_ID_PROBE){
                     pd->buf_size=0;
                     av_freep(&pd->buf);
@@ -2254,6 +2281,8 @@ int av_find_stream_info(AVFormatContext *ic)
             ret = -1; /* we could not have all the codec parameters before EOF */
             for(i=0;i<ic->nb_streams;i++) {
                 st = ic->streams[i];
+                if (st->probe_fallback_codec_id && st->codec->codec_id == CODEC_ID_PROBE)
+                    st->codec->codec_id = st->probe_fallback_codec_id;
                 if (!has_codec_parameters(st->codec)){
                     char buf[256];
                     avcodec_string(buf, sizeof(buf), st->codec, 0);
-- 
1.7.2


--Boundary-00=_S0YYMo0jwG/RQ63
Content-Type: text/x-patch;
  charset="iso-8859-15";
  name="0002-raw-dts-return-a-low-score-if-markers-detected-in-a-.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
	filename="0002-raw-dts-return-a-low-score-if-markers-detected-in-a-.patch"




More information about the ffmpeg-devel mailing list