changeset 3568:c24546b44906 libavformat

New codec probing system try #1.
author michael
date Sat, 12 Jul 2008 18:42:00 +0000
parents 6c1263967c7c
children d5a8fa1db677
files asf.c avformat.h utils.c
diffstat 3 files changed, 44 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/asf.c	Sat Jul 12 16:43:46 2008 +0000
+++ b/asf.c	Sat Jul 12 18:42:00 2008 +0000
@@ -264,7 +264,7 @@
                 if (is_dvr_ms_audio) {
                     // codec_id and codec_tag are unreliable in dvr_ms
                     // files. Set them later by probing stream.
-                    st->codec->codec_id = CODEC_ID_NONE;
+                    st->codec->codec_id = CODEC_ID_PROBE;
                     st->codec->codec_tag = 0;
                 }
                 st->need_parsing = AVSTREAM_PARSE_FULL;
--- a/avformat.h	Sat Jul 12 16:43:46 2008 +0000
+++ b/avformat.h	Sat Jul 12 18:42:00 2008 +0000
@@ -391,6 +391,8 @@
     char *filename; /**< source filename of the stream */
 
     int disposition; /**< AV_DISPOSITION_* bitfield */
+
+    AVProbeData probe_data;
 } AVStream;
 
 #define AV_PROGRAM_RUNNING 1
@@ -555,6 +557,14 @@
      */
     int debug;
 #define FF_FDEBUG_TS        0x0001
+
+    /**
+     * raw packets from the demuxer, prior to parsing and decoding.
+     * This buffer is used for buffering packets until the codec can
+     * be identified, as parsing cannot be done without knowing the
+     * codec.
+     */
+    struct AVPacketList *raw_packet_buffer;
 } AVFormatContext;
 
 typedef struct AVPacketList {
--- a/utils.c	Sat Jul 12 16:43:46 2008 +0000
+++ b/utils.c	Sat Jul 12 18:42:00 2008 +0000
@@ -540,12 +540,30 @@
 {
     int ret;
     AVStream *st;
+
+    for(;;){
+        AVPacketList *pktl = s->raw_packet_buffer;
+
+        if (pktl) {
+            *pkt = pktl->pkt;
+            if(s->streams[pkt->stream_index]->codec->codec_id != CODEC_ID_PROBE){
+                s->raw_packet_buffer = pktl->next;
+                av_free(pktl);
+                return 0;
+            }
+        }
+
     av_init_packet(pkt);
     ret= s->iformat->read_packet(s, pkt);
     if (ret < 0)
         return ret;
     st= s->streams[pkt->stream_index];
 
+        if(!pktl && st->codec->codec_id!=CODEC_ID_PROBE)
+            return ret;
+
+        add_to_pktbuf(&s->raw_packet_buffer, pkt);
+
     switch(st->codec->codec_type){
     case CODEC_TYPE_VIDEO:
         if(s->video_codec_id)   st->codec->codec_id= s->video_codec_id;
@@ -558,7 +576,21 @@
         break;
     }
 
-    return ret;
+        if(st->codec->codec_id == CODEC_ID_PROBE){
+            AVProbeData *pd = &st->probe_data;
+
+            pd->buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE);
+            memcpy(pd->buf+pd->buf_size, pkt->data, pkt->size);
+            pd->buf_size += pkt->size;
+            memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE);
+
+            set_codec_from_probe_data(st, pd, 1);
+            if(st->codec->codec_id != CODEC_ID_PROBE){
+                pd->buf_size=0;
+                av_freep(&pd->buf);
+            }
+        }
+    }
 }
 
 /**********************************************************/