[FFmpeg-cvslog] swr: add set_audiodata_fmt() and use it to simplify code

Michael Niedermayer git at videolan.org
Sun Apr 29 15:45:13 CEST 2012


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sun Apr 29 15:29:28 2012 +0200| [2d6c29f5663afecec250f81a74c612bbadee1c71] | committer: Michael Niedermayer

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

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2d6c29f5663afecec250f81a74c612bbadee1c71
---

 libswresample/swresample.c          |   21 +++++++++++----------
 libswresample/swresample_internal.h |    1 -
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index 8e3d3f5..9297a44 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;
diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h
index 293075b..4f2e9ee 100644
--- a/libswresample/swresample_internal.h
+++ b/libswresample/swresample_internal.h
@@ -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



More information about the ffmpeg-cvslog mailing list