Commit dd50f340 authored by michaelni's avatar michaelni

AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@1714 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent adc85ce6
...@@ -719,6 +719,7 @@ static int dvaudio_decode_frame(AVCodecContext *avctx, ...@@ -719,6 +719,7 @@ static int dvaudio_decode_frame(AVCodecContext *avctx,
return -1; /* Unsupported quantization */ return -1; /* Unsupported quantization */
avctx->sample_rate = dv_audio_frequency[freq]; avctx->sample_rate = dv_audio_frequency[freq];
avctx->channels = 2;
// What about: // What about:
// avctx->bit_rate = // avctx->bit_rate =
// avctx->frame_size = // avctx->frame_size =
......
...@@ -21,6 +21,18 @@ ...@@ -21,6 +21,18 @@
//#define DEBUG //#define DEBUG
static const struct AVI1Handler {
enum CodecID vcid;
enum CodecID acid;
uint32_t tag;
} AVI1Handlers[] = {
{ CODEC_ID_DVVIDEO, CODEC_ID_DVAUDIO, MKTAG('d', 'v', 's', 'd') },
{ CODEC_ID_DVVIDEO, CODEC_ID_DVAUDIO, MKTAG('d', 'v', 'h', 'd') },
{ CODEC_ID_DVVIDEO, CODEC_ID_DVAUDIO, MKTAG('d', 'v', 's', 'l') },
/* This is supposed to be the last one */
{ CODEC_ID_NONE, CODEC_ID_NONE, 0 },
};
typedef struct AVIIndex { typedef struct AVIIndex {
unsigned char tag[4]; unsigned char tag[4];
unsigned int flags, pos, len; unsigned int flags, pos, len;
...@@ -30,6 +42,10 @@ typedef struct AVIIndex { ...@@ -30,6 +42,10 @@ typedef struct AVIIndex {
typedef struct { typedef struct {
int64_t riff_end; int64_t riff_end;
int64_t movi_end; int64_t movi_end;
int type;
uint8_t *buf;
int buf_size;
int stream_index;
offset_t movi_list; offset_t movi_list;
AVIIndex *first, *last; AVIIndex *first, *last;
} AVIContext; } AVIContext;
...@@ -67,7 +83,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -67,7 +83,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
{ {
AVIContext *avi = s->priv_data; AVIContext *avi = s->priv_data;
ByteIOContext *pb = &s->pb; ByteIOContext *pb = &s->pb;
uint32_t tag, tag1; uint32_t tag, tag1, handler;
int codec_type, stream_index, frame_period, bit_rate, scale, rate; int codec_type, stream_index, frame_period, bit_rate, scale, rate;
unsigned int size; unsigned int size;
int i; int i;
...@@ -80,6 +96,11 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -80,6 +96,11 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
stream_index = -1; stream_index = -1;
codec_type = -1; codec_type = -1;
frame_period = 0; frame_period = 0;
avi->type = 2;
avi->buf = av_malloc(1);
if (!avi->buf)
return -1;
avi->buf_size = 1;
for(;;) { for(;;) {
if (url_feof(pb)) if (url_feof(pb))
goto fail; goto fail;
...@@ -126,7 +147,13 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -126,7 +147,13 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
stream_index++; stream_index++;
tag1 = get_le32(pb); tag1 = get_le32(pb);
switch(tag1) { switch(tag1) {
case MKTAG('v', 'i', 'd', 's'): case MKTAG('i', 'a', 'v', 's'):
case MKTAG('i', 'v', 'a', 's'):
if (s->nb_streams != 1)
goto fail;
avi->type = 1;
avi->stream_index = 0;
case MKTAG('v', 'i', 'd', 's'):
codec_type = CODEC_TYPE_VIDEO; codec_type = CODEC_TYPE_VIDEO;
if (stream_index >= s->nb_streams) { if (stream_index >= s->nb_streams) {
...@@ -136,26 +163,48 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -136,26 +163,48 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
st = s->streams[stream_index]; st = s->streams[stream_index];
get_le32(pb); /* codec tag */ handler = get_le32(pb); /* codec tag */
get_le32(pb); /* flags */ get_le32(pb); /* flags */
get_le16(pb); /* priority */ get_le16(pb); /* priority */
get_le16(pb); /* language */ get_le16(pb); /* language */
get_le32(pb); /* XXX: initial frame ? */ get_le32(pb); /* XXX: initial frame ? */
scale= get_le32(pb); /* scale */ scale = get_le32(pb); /* scale */
rate= get_le32(pb); /* rate */ rate = get_le32(pb); /* rate */
if(scale && rate){ if(scale && rate){
st->codec.frame_rate = rate; st->codec.frame_rate = rate;
st->codec.frame_rate_base= scale; st->codec.frame_rate_base = scale;
}else if(frame_period){ }else if(frame_period){
st->codec.frame_rate = 1000000; st->codec.frame_rate = 1000000;
st->codec.frame_rate_base= frame_period; st->codec.frame_rate_base = frame_period;
}else{ }else{
st->codec.frame_rate = 25; st->codec.frame_rate = 25;
st->codec.frame_rate_base = 1; st->codec.frame_rate_base = 1;
} }
url_fskip(pb, size - 7 * 4); if (avi->type == 1) {
AVStream *st = av_mallocz(sizeof(AVStream));
if (!st)
goto fail;
avcodec_get_context_defaults(&st->codec);
s->streams[s->nb_streams++] = st;
stream_index++;
for (i=0; AVI1Handlers[i].tag != 0; ++i)
if (AVI1Handlers[i].tag == handler)
break;
if (AVI1Handlers[i].tag != 0) {
s->streams[0]->codec.codec_type = CODEC_TYPE_VIDEO;
s->streams[0]->codec.codec_id = AVI1Handlers[i].vcid;
s->streams[1]->codec.codec_type = CODEC_TYPE_AUDIO;
s->streams[1]->codec.codec_id = AVI1Handlers[i].acid;
} else
goto fail;
}
url_fskip(pb, size - 7 * 4);
break; break;
case MKTAG('a', 'u', 'd', 's'): case MKTAG('a', 'u', 'd', 's'):
codec_type = CODEC_TYPE_AUDIO; codec_type = CODEC_TYPE_AUDIO;
...@@ -168,7 +217,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -168,7 +217,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
break; break;
case MKTAG('s', 't', 'r', 'f'): case MKTAG('s', 't', 'r', 'f'):
/* stream header */ /* stream header */
if (stream_index >= s->nb_streams) { if (stream_index >= s->nb_streams || avi->type == 1) {
url_fskip(pb, size); url_fskip(pb, size);
} else { } else {
st = s->streams[stream_index]; st = s->streams[stream_index];
...@@ -233,14 +282,23 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -233,14 +282,23 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
return 0; return 0;
} }
static void __destruct_pkt(struct AVPacket *pkt)
{
pkt->data = NULL; pkt->size = 0;
return;
}
static int avi_read_packet(AVFormatContext *s, AVPacket *pkt) static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
{ {
AVIContext *avi = s->priv_data; AVIContext *avi = s->priv_data;
ByteIOContext *pb = &s->pb; ByteIOContext *pb = &s->pb;
int n, d[8], size, i; int n, d[8], size, i;
memset(d, -1, sizeof(int)*8); memset(d, -1, sizeof(int)*8);
if (avi->type == 1 && avi->stream_index)
goto pkt_init;
for(i=url_ftell(pb); !url_feof(pb); i++) { for(i=url_ftell(pb); !url_feof(pb); i++) {
int j; int j;
...@@ -280,24 +338,37 @@ static int avi_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -280,24 +338,37 @@ static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
n= (d[0] - '0') * 10 + (d[1] - '0'); n= (d[0] - '0') * 10 + (d[1] - '0');
if( d[0] >= '0' && d[0] <= '9' if( d[0] >= '0' && d[0] <= '9'
&& d[1] >= '0' && d[1] <= '9' && d[1] >= '0' && d[1] <= '9'
&&((d[2] == 'd' && d[3] == 'c') || (d[2] == 'w' && d[3] == 'b') || (d[2] == 'd' && d[3] == 'b') ) && ((d[2] == 'd' && d[3] == 'c') ||
(d[2] == 'w' && d[3] == 'b') ||
(d[2] == 'd' && d[3] == 'b') ||
(d[2] == '_' && d[3] == '_'))
&& n < s->nb_streams && n < s->nb_streams
&& i + size <= avi->movi_end){ && i + size <= avi->movi_end) {
av_new_packet(pkt, size); uint8_t *tbuf = av_realloc(avi->buf, size + FF_INPUT_BUFFER_PADDING_SIZE);
pkt->stream_index = n; if (!tbuf)
return -1;
get_buffer(pb, pkt->data, pkt->size); avi->buf = tbuf;
avi->buf_size = size;
if (size & 1) get_buffer(pb, avi->buf, size);
get_byte(pb); if (size & 1)
get_byte(pb);
return 0; if (avi->type != 1)
avi->stream_index = n;
goto pkt_init;
} }
} }
return -1; return -1;
pkt_init:
av_init_packet(pkt);
pkt->data = avi->buf;
pkt->size = avi->buf_size;
pkt->destruct = __destruct_pkt;
pkt->stream_index = avi->stream_index;
avi->stream_index = !avi->stream_index;
return 0;
} }
static int avi_read_close(AVFormatContext *s) static int avi_read_close(AVFormatContext *s)
......
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