diff options
author | Fabrice Bellard <fabrice@bellard.org> | 2003-08-08 17:52:53 +0000 |
---|---|---|
committer | Fabrice Bellard <fabrice@bellard.org> | 2003-08-08 17:52:53 +0000 |
commit | 247eadca9d3158b91d500af27065d68aef7c9347 (patch) | |
tree | c951ea1a3a6a711d6227d6ae2aeee3174541bd26 /libavformat | |
parent | fa26a29d6508e71e52abc6d71ee37279b837de37 (diff) | |
download | ffmpeg-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')
-rw-r--r-- | libavformat/asf.c | 12 | ||||
-rw-r--r-- | libavformat/avidec.c | 58 | ||||
-rw-r--r-- | libavformat/rm.c | 12 |
3 files changed, 54 insertions, 28 deletions
diff --git a/libavformat/asf.c b/libavformat/asf.c index 602c3ef0f4..1712f8f22d 100644 --- a/libavformat/asf.c +++ b/libavformat/asf.c @@ -48,7 +48,7 @@ typedef struct { uint8_t v4[8]; } GUID; -typedef struct __attribute__((packed)) { +typedef struct { GUID guid; // generated by client computer uint64_t file_size; // in bytes // invalid if broadcasting @@ -811,16 +811,16 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) pos1 = url_ftell(pb); - st = av_mallocz(sizeof(AVStream)); + st = av_new_stream(s, 0); if (!st) goto fail; - avcodec_get_context_defaults(&st->codec); - s->streams[s->nb_streams] = st; asf_st = av_mallocz(sizeof(ASFStream)); if (!asf_st) goto fail; st->priv_data = asf_st; - st->time_length = (asf->hdr.send_time - asf->hdr.preroll) / 10; // us + st->start_time = asf->hdr.preroll / (10000000 / AV_TIME_BASE); + st->duration = (asf->hdr.send_time - asf->hdr.preroll) / + (10000000 / AV_TIME_BASE); get_guid(pb, &g); if (!memcmp(&g, &audio_stream, sizeof(GUID))) { type = CODEC_TYPE_AUDIO; @@ -835,7 +835,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) get_le32(pb); st->id = get_le16(pb) & 0x7f; /* stream id */ // mapping of asf ID to AV stream ID; - asf->asfid2avid[st->id] = s->nb_streams++; + asf->asfid2avid[st->id] = s->nb_streams - 1; get_le32(pb); st->codec.codec_type = type; 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; diff --git a/libavformat/rm.c b/libavformat/rm.c index 47b510b323..c4be2e37a3 100644 --- a/libavformat/rm.c +++ b/libavformat/rm.c @@ -473,7 +473,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap) unsigned int tag, v; int tag_size, size, codec_data_size, i; int64_t codec_pos; - unsigned int h263_hack_version; + unsigned int h263_hack_version, start_time, duration; char buf[128]; int flags = 0; @@ -524,19 +524,19 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap) get_str(pb, s->comment, sizeof(s->comment)); break; case MKTAG('M', 'D', 'P', 'R'): - st = av_mallocz(sizeof(AVStream)); + st = av_new_stream(s, 0); if (!st) goto fail; - avcodec_get_context_defaults(&st->codec); - s->streams[s->nb_streams++] = st; st->id = get_be16(pb); get_be32(pb); /* max bit rate */ st->codec.bit_rate = get_be32(pb); /* bit rate */ get_be32(pb); /* max packet size */ get_be32(pb); /* avg packet size */ - get_be32(pb); /* start time */ + start_time = get_be32(pb); /* start time */ get_be32(pb); /* preroll */ - get_be32(pb); /* duration */ + duration = get_be32(pb); /* duration */ + st->start_time = start_time * (AV_TIME_BASE / 1000); + st->duration = duration * (AV_TIME_BASE / 1000); get_str8(pb, buf, sizeof(buf)); /* desc */ get_str8(pb, buf, sizeof(buf)); /* mimetype */ codec_data_size = get_be32(pb); |