Commit d754ed41 authored by Anton Khirnov's avatar Anton Khirnov

riffenc: take an AVStream instead of an AVCodecContext

It will be useful in the following commits.

Also, rename the AVCodecContext pointer name from 'stream' to 'codec'.
parent f792d3cb
...@@ -120,7 +120,7 @@ static int avi_write_counters(AVFormatContext *s, int riff_id) ...@@ -120,7 +120,7 @@ static int avi_write_counters(AVFormatContext *s, int riff_id)
assert(avist->frames_hdr_strm); assert(avist->frames_hdr_strm);
stream = s->streams[n]->codec; stream = s->streams[n]->codec;
avio_seek(pb, avist->frames_hdr_strm, SEEK_SET); avio_seek(pb, avist->frames_hdr_strm, SEEK_SET);
ff_parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale); ff_parse_specific_params(s->streams[n], &au_byterate, &au_ssize, &au_scale);
if (au_ssize == 0) if (au_ssize == 0)
avio_wl32(pb, avist->packet_count); avio_wl32(pb, avist->packet_count);
else else
...@@ -248,7 +248,7 @@ static int avi_write_header(AVFormatContext *s) ...@@ -248,7 +248,7 @@ 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(enc, &au_byterate, &au_ssize, &au_scale); ff_parse_specific_params(st, &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 */
......
...@@ -674,7 +674,7 @@ static int nut_write_header(AVFormatContext *s) ...@@ -674,7 +674,7 @@ static int nut_write_header(AVFormatContext *s)
AVStream *st = s->streams[i]; AVStream *st = s->streams[i];
int ssize; int ssize;
AVRational time_base; AVRational time_base;
ff_parse_specific_params(st->codec, &time_base.den, &ssize, ff_parse_specific_params(st, &time_base.den, &ssize,
&time_base.num); &time_base.num);
avpriv_set_pts_info(st, 64, time_base.num, time_base.den); avpriv_set_pts_info(st, 64, time_base.num, time_base.den);
......
...@@ -53,7 +53,7 @@ int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size); ...@@ -53,7 +53,7 @@ int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size);
extern const AVCodecTag ff_codec_bmp_tags[]; extern const AVCodecTag ff_codec_bmp_tags[];
extern const AVCodecTag ff_codec_wav_tags[]; extern const AVCodecTag ff_codec_wav_tags[];
void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale); void ff_parse_specific_params(AVStream *st, int *au_rate, int *au_ssize, int *au_scale);
int ff_read_riff_info(AVFormatContext *s, int64_t size); int ff_read_riff_info(AVFormatContext *s, int64_t size);
......
...@@ -209,32 +209,33 @@ void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc, ...@@ -209,32 +209,33 @@ void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc,
avio_w8(pb, 0); avio_w8(pb, 0);
} }
void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, void ff_parse_specific_params(AVStream *st, int *au_rate,
int *au_ssize, int *au_scale) int *au_ssize, int *au_scale)
{ {
AVCodecContext *codec = st->codec;
int gcd; int gcd;
int audio_frame_size; int audio_frame_size;
/* We use the known constant frame size for the codec if known, otherwise /* We use the known constant frame size for the codec if known, otherwise
* fall back on using AVCodecContext.frame_size, which is not as reliable * fall back on using AVCodecContext.frame_size, which is not as reliable
* for indicating packet duration. */ * for indicating packet duration. */
audio_frame_size = av_get_audio_frame_duration(stream, 0); audio_frame_size = av_get_audio_frame_duration(codec, 0);
if (!audio_frame_size) if (!audio_frame_size)
audio_frame_size = stream->frame_size; audio_frame_size = codec->frame_size;
*au_ssize = stream->block_align; *au_ssize = codec->block_align;
if (audio_frame_size && stream->sample_rate) { if (audio_frame_size && codec->sample_rate) {
*au_scale = audio_frame_size; *au_scale = audio_frame_size;
*au_rate = stream->sample_rate; *au_rate = codec->sample_rate;
} else if (stream->codec_type == AVMEDIA_TYPE_VIDEO || } else if (codec->codec_type == AVMEDIA_TYPE_VIDEO ||
stream->codec_type == AVMEDIA_TYPE_DATA || codec->codec_type == AVMEDIA_TYPE_DATA ||
stream->codec_type == AVMEDIA_TYPE_SUBTITLE) { codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
*au_scale = stream->time_base.num; *au_scale = codec->time_base.num;
*au_rate = stream->time_base.den; *au_rate = codec->time_base.den;
} else { } else {
*au_scale = stream->block_align ? stream->block_align * 8 : 8; *au_scale = codec->block_align ? codec->block_align * 8 : 8;
*au_rate = stream->bit_rate ? stream->bit_rate : *au_rate = codec->bit_rate ? codec->bit_rate :
8 * stream->sample_rate; 8 * codec->sample_rate;
} }
gcd = av_gcd(*au_scale, *au_rate); gcd = av_gcd(*au_scale, *au_rate);
*au_scale /= gcd; *au_scale /= gcd;
......
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