swr: add set_audiodata_fmt() and use it to simplify code

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2012-04-29 15:29:28 +02:00
parent 65722e7fc5
commit 2d6c29f566
2 changed files with 11 additions and 11 deletions

View File

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

View File

@ -57,7 +57,6 @@ struct SwrContext {
int linear_interp; /**< if 1 then the resampling FIR filter will be linearly interpolated */
double cutoff; /**< resampling cutoff frequency. 1.0 corresponds to half the output sample rate */
int int_bps; ///< internal bytes per sample
int resample_first; ///< 1 if resampling must come first, 0 if rematrixing
int rematrix; ///< flag to indicate if rematrixing is needed (basically if input and output layouts mismatch)
int rematrix_custom; ///< flag to indicate that a custom matrix has been defined