avienc: sanitize variable naming in write_header()

Do not call an AVCodecContext 'stream', that is highly confusing.
Also, add a local variable for the current AVStream in the loop over all
streams.
This commit is contained in:
Anton Khirnov 2014-05-11 10:07:35 +02:00
parent ab3fdaa713
commit c3311d472a

View File

@ -143,7 +143,7 @@ static int avi_write_header(AVFormatContext *s)
AVIContext *avi = s->priv_data; AVIContext *avi = s->priv_data;
AVIOContext *pb = s->pb; AVIOContext *pb = s->pb;
int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale; int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale;
AVCodecContext *stream, *video_enc; AVCodecContext *video_enc;
int64_t list1, list2, strh, strf; int64_t list1, list2, strh, strf;
AVDictionaryEntry *t = NULL; AVDictionaryEntry *t = NULL;
@ -170,10 +170,10 @@ static int avi_write_header(AVFormatContext *s)
video_enc = NULL; video_enc = NULL;
for (n = 0; n < s->nb_streams; n++) { for (n = 0; n < s->nb_streams; n++) {
stream = s->streams[n]->codec; AVCodecContext *codec = s->streams[n]->codec;
bitrate += stream->bit_rate; bitrate += codec->bit_rate;
if (stream->codec_type == AVMEDIA_TYPE_VIDEO) if (codec->codec_type == AVMEDIA_TYPE_VIDEO)
video_enc = stream; video_enc = codec;
} }
nb_frames = 0; nb_frames = 0;
@ -208,19 +208,19 @@ static int avi_write_header(AVFormatContext *s)
/* stream list */ /* stream list */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
AVIStream *avist = s->streams[i]->priv_data; AVStream *st = s->streams[i];
AVCodecContext *enc = st->codec;
AVIStream *avist = st->priv_data;
list2 = ff_start_tag(pb, "LIST"); list2 = ff_start_tag(pb, "LIST");
ffio_wfourcc(pb, "strl"); ffio_wfourcc(pb, "strl");
stream = s->streams[i]->codec;
/* stream generic header */ /* stream generic header */
strh = ff_start_tag(pb, "strh"); strh = ff_start_tag(pb, "strh");
switch (stream->codec_type) { switch (enc->codec_type) {
case AVMEDIA_TYPE_SUBTITLE: case AVMEDIA_TYPE_SUBTITLE:
// XSUB subtitles behave like video tracks, other subtitles // XSUB subtitles behave like video tracks, other subtitles
// are not (yet) supported. // are not (yet) supported.
if (stream->codec_id != AV_CODEC_ID_XSUB) { if (enc->codec_id != AV_CODEC_ID_XSUB) {
av_log(s, AV_LOG_ERROR, av_log(s, AV_LOG_ERROR,
"Subtitle streams other than DivX XSUB are not supported by the AVI muxer.\n"); "Subtitle streams other than DivX XSUB are not supported by the AVI muxer.\n");
return AVERROR_PATCHWELCOME; return AVERROR_PATCHWELCOME;
@ -238,9 +238,9 @@ static int avi_write_header(AVFormatContext *s)
ffio_wfourcc(pb, "dats"); ffio_wfourcc(pb, "dats");
break; break;
} }
if (stream->codec_type == AVMEDIA_TYPE_VIDEO || if (enc->codec_type == AVMEDIA_TYPE_VIDEO ||
stream->codec_id == AV_CODEC_ID_XSUB) enc->codec_id == AV_CODEC_ID_XSUB)
avio_wl32(pb, stream->codec_tag); avio_wl32(pb, enc->codec_tag);
else else
avio_wl32(pb, 1); avio_wl32(pb, 1);
avio_wl32(pb, 0); /* flags */ avio_wl32(pb, 0); /* flags */
@ -248,11 +248,11 @@ static int avi_write_header(AVFormatContext *s)
avio_wl16(pb, 0); /* language */ avio_wl16(pb, 0); /* language */
avio_wl32(pb, 0); /* initial frame */ avio_wl32(pb, 0); /* initial frame */
ff_parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale); ff_parse_specific_params(enc, &au_byterate, &au_ssize, &au_scale);
avio_wl32(pb, au_scale); /* scale */ avio_wl32(pb, au_scale); /* scale */
avio_wl32(pb, au_byterate); /* rate */ avio_wl32(pb, au_byterate); /* rate */
avpriv_set_pts_info(s->streams[i], 64, au_scale, au_byterate); avpriv_set_pts_info(st, 64, au_scale, au_byterate);
avio_wl32(pb, 0); /* start */ avio_wl32(pb, 0); /* start */
/* remember this offset to fill later */ /* remember this offset to fill later */
@ -264,39 +264,39 @@ static int avi_write_header(AVFormatContext *s)
avio_wl32(pb, 0); /* length, XXX: filled later */ avio_wl32(pb, 0); /* length, XXX: filled later */
/* suggested buffer size */ //FIXME set at the end to largest chunk /* suggested buffer size */ //FIXME set at the end to largest chunk
if (stream->codec_type == AVMEDIA_TYPE_VIDEO) if (enc->codec_type == AVMEDIA_TYPE_VIDEO)
avio_wl32(pb, 1024 * 1024); avio_wl32(pb, 1024 * 1024);
else if (stream->codec_type == AVMEDIA_TYPE_AUDIO) else if (enc->codec_type == AVMEDIA_TYPE_AUDIO)
avio_wl32(pb, 12 * 1024); avio_wl32(pb, 12 * 1024);
else else
avio_wl32(pb, 0); avio_wl32(pb, 0);
avio_wl32(pb, -1); /* quality */ avio_wl32(pb, -1); /* quality */
avio_wl32(pb, au_ssize); /* sample size */ avio_wl32(pb, au_ssize); /* sample size */
avio_wl32(pb, 0); avio_wl32(pb, 0);
avio_wl16(pb, stream->width); avio_wl16(pb, enc->width);
avio_wl16(pb, stream->height); avio_wl16(pb, enc->height);
ff_end_tag(pb, strh); ff_end_tag(pb, strh);
if (stream->codec_type != AVMEDIA_TYPE_DATA) { if (enc->codec_type != AVMEDIA_TYPE_DATA) {
strf = ff_start_tag(pb, "strf"); strf = ff_start_tag(pb, "strf");
switch (stream->codec_type) { switch (enc->codec_type) {
case AVMEDIA_TYPE_SUBTITLE: case AVMEDIA_TYPE_SUBTITLE:
/* XSUB subtitles behave like video tracks, other subtitles /* XSUB subtitles behave like video tracks, other subtitles
* are not (yet) supported. */ * are not (yet) supported. */
if (stream->codec_id != AV_CODEC_ID_XSUB) if (enc->codec_id != AV_CODEC_ID_XSUB)
break; break;
case AVMEDIA_TYPE_VIDEO: case AVMEDIA_TYPE_VIDEO:
ff_put_bmp_header(pb, stream, ff_codec_bmp_tags, 0); ff_put_bmp_header(pb, enc, ff_codec_bmp_tags, 0);
break; break;
case AVMEDIA_TYPE_AUDIO: case AVMEDIA_TYPE_AUDIO:
if (ff_put_wav_header(pb, stream) < 0) if (ff_put_wav_header(pb, enc) < 0)
return -1; return -1;
break; break;
default: default:
return -1; return -1;
} }
ff_end_tag(pb, strf); ff_end_tag(pb, strf);
if ((t = av_dict_get(s->streams[i]->metadata, "title", NULL, 0))) { if ((t = av_dict_get(st->metadata, "title", NULL, 0))) {
ff_riff_write_info_tag(s->pb, "strn", t->value); ff_riff_write_info_tag(s->pb, "strn", t->value);
t = NULL; t = NULL;
} }
@ -316,7 +316,7 @@ static int avi_write_header(AVFormatContext *s)
avio_w8(pb, 0); /* bIndexSubType (0 == frame index) */ avio_w8(pb, 0); /* bIndexSubType (0 == frame index) */
avio_w8(pb, 0); /* bIndexType (0 == AVI_INDEX_OF_INDEXES) */ avio_w8(pb, 0); /* bIndexType (0 == AVI_INDEX_OF_INDEXES) */
avio_wl32(pb, 0); /* nEntriesInUse (will fill out later on) */ avio_wl32(pb, 0); /* nEntriesInUse (will fill out later on) */
ffio_wfourcc(pb, avi_stream2fourcc(tag, i, stream->codec_type)); ffio_wfourcc(pb, avi_stream2fourcc(tag, i, enc->codec_type));
/* dwChunkId */ /* dwChunkId */
avio_wl64(pb, 0); /* dwReserved[3] */ avio_wl64(pb, 0); /* dwReserved[3] */
// avio_wl32(pb, 0); /* Must be 0. */ // avio_wl32(pb, 0); /* Must be 0. */
@ -325,31 +325,31 @@ static int avi_write_header(AVFormatContext *s)
ff_end_tag(pb, avist->indexes.indx_start); ff_end_tag(pb, avist->indexes.indx_start);
} }
if (stream->codec_type == AVMEDIA_TYPE_VIDEO && if (enc->codec_type == AVMEDIA_TYPE_VIDEO &&
s->streams[i]->sample_aspect_ratio.num > 0 && st->sample_aspect_ratio.num > 0 &&
s->streams[i]->sample_aspect_ratio.den > 0) { st->sample_aspect_ratio.den > 0) {
int vprp = ff_start_tag(pb, "vprp"); int vprp = ff_start_tag(pb, "vprp");
AVRational dar = av_mul_q(s->streams[i]->sample_aspect_ratio, AVRational dar = av_mul_q(st->sample_aspect_ratio,
(AVRational) { stream->width, (AVRational) { enc->width,
stream->height }); enc->height });
int num, den; int num, den;
av_reduce(&num, &den, dar.num, dar.den, 0xFFFF); av_reduce(&num, &den, dar.num, dar.den, 0xFFFF);
avio_wl32(pb, 0); // video format = unknown avio_wl32(pb, 0); // video format = unknown
avio_wl32(pb, 0); // video standard = unknown avio_wl32(pb, 0); // video standard = unknown
avio_wl32(pb, lrintf(1.0 / av_q2d(stream->time_base))); avio_wl32(pb, lrintf(1.0 / av_q2d(enc->time_base)));
avio_wl32(pb, stream->width); avio_wl32(pb, enc->width);
avio_wl32(pb, stream->height); avio_wl32(pb, enc->height);
avio_wl16(pb, den); avio_wl16(pb, den);
avio_wl16(pb, num); avio_wl16(pb, num);
avio_wl32(pb, stream->width); avio_wl32(pb, enc->width);
avio_wl32(pb, stream->height); avio_wl32(pb, enc->height);
avio_wl32(pb, 1); // progressive FIXME avio_wl32(pb, 1); // progressive FIXME
avio_wl32(pb, stream->height); avio_wl32(pb, enc->height);
avio_wl32(pb, stream->width); avio_wl32(pb, enc->width);
avio_wl32(pb, stream->height); avio_wl32(pb, enc->height);
avio_wl32(pb, stream->width); avio_wl32(pb, enc->width);
avio_wl32(pb, 0); avio_wl32(pb, 0);
avio_wl32(pb, 0); avio_wl32(pb, 0);