update duration and start_time - add av_new_stream() usage

Originally committed as revision 2110 to svn://svn.ffmpeg.org/ffmpeg/trunk
pull/126/head
Fabrice Bellard 22 years ago
parent fa26a29d65
commit 247eadca9d
  1. 12
      libavformat/asf.c
  2. 58
      libavformat/avidec.c
  3. 12
      libavformat/rm.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;

@ -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;

@ -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);

Loading…
Cancel
Save