Commit c1c6889e authored by michael's avatar michael

New codec probing system try #1.


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@14184 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 6cb1f290
...@@ -313,6 +313,8 @@ enum CodecID { ...@@ -313,6 +313,8 @@ enum CodecID {
/* other specific kind of codecs (generally used for attachments) */ /* other specific kind of codecs (generally used for attachments) */
CODEC_ID_TTF= 0x18000, CODEC_ID_TTF= 0x18000,
CODEC_ID_PROBE= 0x19000, ///< codec_id is not known (like CODEC_ID_NONE) but lavf should attempt to identify it
CODEC_ID_MPEG2TS= 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS CODEC_ID_MPEG2TS= 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS
* stream (only used by libavformat) */ * stream (only used by libavformat) */
}; };
......
...@@ -264,7 +264,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -264,7 +264,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
if (is_dvr_ms_audio) { if (is_dvr_ms_audio) {
// codec_id and codec_tag are unreliable in dvr_ms // codec_id and codec_tag are unreliable in dvr_ms
// files. Set them later by probing stream. // 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->codec->codec_tag = 0;
} }
st->need_parsing = AVSTREAM_PARSE_FULL; st->need_parsing = AVSTREAM_PARSE_FULL;
......
...@@ -391,6 +391,8 @@ typedef struct AVStream { ...@@ -391,6 +391,8 @@ typedef struct AVStream {
char *filename; /**< source filename of the stream */ char *filename; /**< source filename of the stream */
int disposition; /**< AV_DISPOSITION_* bitfield */ int disposition; /**< AV_DISPOSITION_* bitfield */
AVProbeData probe_data;
} AVStream; } AVStream;
#define AV_PROGRAM_RUNNING 1 #define AV_PROGRAM_RUNNING 1
...@@ -555,6 +557,14 @@ typedef struct AVFormatContext { ...@@ -555,6 +557,14 @@ typedef struct AVFormatContext {
*/ */
int debug; int debug;
#define FF_FDEBUG_TS 0x0001 #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; } AVFormatContext;
typedef struct AVPacketList { typedef struct AVPacketList {
......
...@@ -540,12 +540,30 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -540,12 +540,30 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt)
{ {
int ret; int ret;
AVStream *st; 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); av_init_packet(pkt);
ret= s->iformat->read_packet(s, pkt); ret= s->iformat->read_packet(s, pkt);
if (ret < 0) if (ret < 0)
return ret; return ret;
st= s->streams[pkt->stream_index]; 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){ switch(st->codec->codec_type){
case CODEC_TYPE_VIDEO: case CODEC_TYPE_VIDEO:
if(s->video_codec_id) st->codec->codec_id= s->video_codec_id; if(s->video_codec_id) st->codec->codec_id= s->video_codec_id;
...@@ -558,7 +576,21 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -558,7 +576,21 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt)
break; 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);
}
}
}
} }
/**********************************************************/ /**********************************************************/
......
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