aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/avidec.c
diff options
context:
space:
mode:
authorFabrice Bellard <fabrice@bellard.org>2003-08-08 17:52:53 +0000
committerFabrice Bellard <fabrice@bellard.org>2003-08-08 17:52:53 +0000
commit247eadca9d3158b91d500af27065d68aef7c9347 (patch)
treec951ea1a3a6a711d6227d6ae2aeee3174541bd26 /libavformat/avidec.c
parentfa26a29d6508e71e52abc6d71ee37279b837de37 (diff)
downloadffmpeg-247eadca9d3158b91d500af27065d68aef7c9347.tar.gz
update duration and start_time - add av_new_stream() usage
Originally committed as revision 2110 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/avidec.c')
-rw-r--r--libavformat/avidec.c58
1 files changed, 42 insertions, 16 deletions
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index dbfef1db38..050769b870 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -85,8 +85,8 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
ByteIOContext *pb = &s->pb;
uint32_t tag, tag1, handler;
int codec_type, stream_index, frame_period, bit_rate, scale, rate;
- unsigned int size;
- int i;
+ unsigned int size, nb_frames;
+ int i, n;
AVStream *st;
if (get_riff(avi, pb) < 0)
@@ -131,14 +131,11 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
frame_period = get_le32(pb);
bit_rate = get_le32(pb) * 8;
url_fskip(pb, 4 * 4);
- s->nb_streams = get_le32(pb);
- for(i=0;i<s->nb_streams;i++) {
- AVStream *st = av_mallocz(sizeof(AVStream));
+ n = get_le32(pb);
+ for(i=0;i<n;i++) {
+ st = av_new_stream(s, 0);
if (!st)
goto fail;
- avcodec_get_context_defaults(&st->codec);
-
- s->streams[i] = st;
}
url_fskip(pb, size - 7 * 4);
break;
@@ -181,14 +178,20 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
st->codec.frame_rate = 25;
st->codec.frame_rate_base = 1;
}
+ get_le32(pb); /* start */
+ nb_frames = get_le32(pb);
+ st->start_time = 0;
+ st->duration = (double)nb_frames *
+ st->codec.frame_rate_base * AV_TIME_BASE /
+ st->codec.frame_rate;
if (avi->type == 1) {
- AVStream *st = av_mallocz(sizeof(AVStream));
+ AVStream *st;
+
+ st = av_new_stream(s, 0);
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)
@@ -200,16 +203,39 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
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
+ } else {
goto fail;
+ }
}
- url_fskip(pb, size - 7 * 4);
+ url_fskip(pb, size - 9 * 4);
break;
case MKTAG('a', 'u', 'd', 's'):
- codec_type = CODEC_TYPE_AUDIO;
- /* nothing really useful */
- url_fskip(pb, size - 4);
+ {
+ unsigned int length, rate;
+
+ codec_type = CODEC_TYPE_AUDIO;
+
+ if (stream_index >= s->nb_streams) {
+ url_fskip(pb, size - 4);
+ break;
+ }
+ st = s->streams[stream_index];
+
+ get_le32(pb); /* tag */
+ get_le32(pb); /* flags */
+ get_le16(pb); /* priority */
+ get_le16(pb); /* language */
+ get_le32(pb); /* initial frame */
+ get_le32(pb); /* scale */
+ rate = get_le32(pb);
+ get_le32(pb); /* start */
+ length = get_le32(pb); /* length, in samples or bytes */
+ st->start_time = 0;
+ if (rate != 0)
+ st->duration = (int64_t)length * AV_TIME_BASE / rate;
+ url_fskip(pb, size - 9 * 4);
+ }
break;
default:
goto fail;