aboutsummaryrefslogtreecommitdiffstats
path: root/libswresample/swresample.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-04-29 15:29:28 +0200
committerMichael Niedermayer <michaelni@gmx.at>2012-04-29 15:32:18 +0200
commit2d6c29f5663afecec250f81a74c612bbadee1c71 (patch)
tree45aa5b6ccfbf5102f7e9e00439ab60c9e09554cf /libswresample/swresample.c
parent65722e7fc5918644ca92d5cdfcb88a54b1b64d44 (diff)
downloadffmpeg-2d6c29f5663afecec250f81a74c612bbadee1c71.tar.gz
swr: add set_audiodata_fmt() and use it to simplify code
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libswresample/swresample.c')
-rw-r--r--libswresample/swresample.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index 8e3d3f5286..9297a44ebd 100644
--- a/libswresample/swresample.c
+++ b/libswresample/swresample.c
@@ -153,6 +153,10 @@ struct SwrContext *swr_alloc_set_opts(struct SwrContext *s,
return s;
}
+static void set_audiodata_fmt(AudioData *a, enum AVSampleFormat fmt){
+ a->bps = av_get_bytes_per_sample(fmt);
+ a->planar= av_sample_fmt_is_planar(fmt);
+}
static void free_temp(AudioData *a){
av_free(a->data);
@@ -191,9 +195,6 @@ int swr_init(struct SwrContext *s){
s->flushed = 0;
- s-> in.planar= av_sample_fmt_is_planar(s-> in_sample_fmt);
- s->out.planar= av_sample_fmt_is_planar(s->out_sample_fmt);
-
if(s-> in_sample_fmt >= AV_SAMPLE_FMT_NB){
av_log(s, AV_LOG_ERROR, "Requested input sample format %d is invalid\n", s->in_sample_fmt);
return AVERROR(EINVAL);
@@ -216,6 +217,9 @@ int swr_init(struct SwrContext *s){
return AVERROR(EINVAL);
}
+ set_audiodata_fmt(&s-> in, s-> in_sample_fmt);
+ set_audiodata_fmt(&s->out, s->out_sample_fmt);
+
if (s->out_sample_rate!=s->in_sample_rate || (s->flags & SWR_FLAG_RESAMPLE)){
s->resample = swri_resample_init(s->resample, s->out_sample_rate, s->in_sample_rate, s->filter_size, s->phase_shift, s->linear_interp, s->cutoff, s->int_sample_fmt);
}else
@@ -267,9 +271,6 @@ av_assert0(s->used_ch_count);
av_assert0(s->out.ch_count);
s->resample_first= RSC*s->out.ch_count/s->in.ch_count - RSC < s->out_sample_rate/(float)s-> in_sample_rate - 1.0;
- s-> in.bps= av_get_bytes_per_sample(s-> in_sample_fmt);
- s->int_bps= av_get_bytes_per_sample(s->int_sample_fmt);
- s->out.bps= av_get_bytes_per_sample(s->out_sample_fmt);
s->in_buffer= s->in;
if(!s->resample && !s->rematrix && !s->channel_map){
@@ -300,12 +301,12 @@ av_assert0(s->out.ch_count);
s->in_buffer.ch_count = s->out.ch_count;
}
- s->postin.bps = s->midbuf.bps = s->preout.bps = s->int_bps;
- s->postin.planar = s->midbuf.planar = s->preout.planar = 1;
+ set_audiodata_fmt(&s->postin, s->int_sample_fmt);
+ set_audiodata_fmt(&s->midbuf, s->int_sample_fmt);
+ set_audiodata_fmt(&s->preout, s->int_sample_fmt);
if(s->resample){
- s->in_buffer.bps = s->int_bps;
- s->in_buffer.planar = 1;
+ set_audiodata_fmt(&s->in_buffer, s->int_sample_fmt);
}
s->dither = s->preout;