Commit 247eadca authored by Fabrice Bellard's avatar Fabrice Bellard

update duration and start_time - add av_new_stream() usage

Originally committed as revision 2110 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent fa26a29d
...@@ -48,7 +48,7 @@ typedef struct { ...@@ -48,7 +48,7 @@ typedef struct {
uint8_t v4[8]; uint8_t v4[8];
} GUID; } GUID;
typedef struct __attribute__((packed)) { typedef struct {
GUID guid; // generated by client computer GUID guid; // generated by client computer
uint64_t file_size; // in bytes uint64_t file_size; // in bytes
// invalid if broadcasting // invalid if broadcasting
...@@ -811,16 +811,16 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -811,16 +811,16 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
pos1 = url_ftell(pb); pos1 = url_ftell(pb);
st = av_mallocz(sizeof(AVStream)); st = av_new_stream(s, 0);
if (!st) if (!st)
goto fail; goto fail;
avcodec_get_context_defaults(&st->codec);
s->streams[s->nb_streams] = st;
asf_st = av_mallocz(sizeof(ASFStream)); asf_st = av_mallocz(sizeof(ASFStream));
if (!asf_st) if (!asf_st)
goto fail; goto fail;
st->priv_data = asf_st; 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); get_guid(pb, &g);
if (!memcmp(&g, &audio_stream, sizeof(GUID))) { if (!memcmp(&g, &audio_stream, sizeof(GUID))) {
type = CODEC_TYPE_AUDIO; type = CODEC_TYPE_AUDIO;
...@@ -835,7 +835,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -835,7 +835,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
get_le32(pb); get_le32(pb);
st->id = get_le16(pb) & 0x7f; /* stream id */ st->id = get_le16(pb) & 0x7f; /* stream id */
// mapping of asf ID to AV 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); get_le32(pb);
st->codec.codec_type = type; st->codec.codec_type = type;
......
...@@ -85,8 +85,8 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -85,8 +85,8 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
ByteIOContext *pb = &s->pb; ByteIOContext *pb = &s->pb;
uint32_t tag, tag1, handler; 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, nb_frames;
int i; int i, n;
AVStream *st; AVStream *st;
if (get_riff(avi, pb) < 0) if (get_riff(avi, pb) < 0)
...@@ -131,14 +131,11 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -131,14 +131,11 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
frame_period = get_le32(pb); frame_period = get_le32(pb);
bit_rate = get_le32(pb) * 8; bit_rate = get_le32(pb) * 8;
url_fskip(pb, 4 * 4); url_fskip(pb, 4 * 4);
s->nb_streams = get_le32(pb); n = get_le32(pb);
for(i=0;i<s->nb_streams;i++) { for(i=0;i<n;i++) {
AVStream *st = av_mallocz(sizeof(AVStream)); st = av_new_stream(s, 0);
if (!st) if (!st)
goto fail; goto fail;
avcodec_get_context_defaults(&st->codec);
s->streams[i] = st;
} }
url_fskip(pb, size - 7 * 4); url_fskip(pb, size - 7 * 4);
break; break;
...@@ -181,14 +178,20 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -181,14 +178,20 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
st->codec.frame_rate = 25; st->codec.frame_rate = 25;
st->codec.frame_rate_base = 1; 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) { if (avi->type == 1) {
AVStream *st = av_mallocz(sizeof(AVStream)); AVStream *st;
st = av_new_stream(s, 0);
if (!st) if (!st)
goto fail; goto fail;
avcodec_get_context_defaults(&st->codec);
s->streams[s->nb_streams++] = st;
stream_index++; stream_index++;
for (i=0; AVI1Handlers[i].tag != 0; ++i) for (i=0; AVI1Handlers[i].tag != 0; ++i)
...@@ -200,17 +203,40 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -200,17 +203,40 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
s->streams[0]->codec.codec_id = AVI1Handlers[i].vcid; s->streams[0]->codec.codec_id = AVI1Handlers[i].vcid;
s->streams[1]->codec.codec_type = CODEC_TYPE_AUDIO; s->streams[1]->codec.codec_type = CODEC_TYPE_AUDIO;
s->streams[1]->codec.codec_id = AVI1Handlers[i].acid; s->streams[1]->codec.codec_id = AVI1Handlers[i].acid;
} else } else {
goto fail; goto fail;
} }
}
url_fskip(pb, size - 7 * 4); url_fskip(pb, size - 9 * 4);
break; break;
case MKTAG('a', 'u', 'd', 's'): case MKTAG('a', 'u', 'd', 's'):
{
unsigned int length, rate;
codec_type = CODEC_TYPE_AUDIO; codec_type = CODEC_TYPE_AUDIO;
/* nothing really useful */
if (stream_index >= s->nb_streams) {
url_fskip(pb, size - 4); url_fskip(pb, size - 4);
break; 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: default:
goto fail; goto fail;
} }
......
...@@ -473,7 +473,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -473,7 +473,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
unsigned int tag, v; unsigned int tag, v;
int tag_size, size, codec_data_size, i; int tag_size, size, codec_data_size, i;
int64_t codec_pos; int64_t codec_pos;
unsigned int h263_hack_version; unsigned int h263_hack_version, start_time, duration;
char buf[128]; char buf[128];
int flags = 0; int flags = 0;
...@@ -524,19 +524,19 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -524,19 +524,19 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
get_str(pb, s->comment, sizeof(s->comment)); get_str(pb, s->comment, sizeof(s->comment));
break; break;
case MKTAG('M', 'D', 'P', 'R'): case MKTAG('M', 'D', 'P', 'R'):
st = av_mallocz(sizeof(AVStream)); st = av_new_stream(s, 0);
if (!st) if (!st)
goto fail; goto fail;
avcodec_get_context_defaults(&st->codec);
s->streams[s->nb_streams++] = st;
st->id = get_be16(pb); st->id = get_be16(pb);
get_be32(pb); /* max bit rate */ get_be32(pb); /* max bit rate */
st->codec.bit_rate = get_be32(pb); /* bit rate */ st->codec.bit_rate = get_be32(pb); /* bit rate */
get_be32(pb); /* max packet size */ get_be32(pb); /* max packet size */
get_be32(pb); /* avg 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); /* 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)); /* desc */
get_str8(pb, buf, sizeof(buf)); /* mimetype */ get_str8(pb, buf, sizeof(buf)); /* mimetype */
codec_data_size = get_be32(pb); codec_data_size = get_be32(pb);
......
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