[FFmpeg-cvslog] swr: add and use function pointers for rematrix

Michael Niedermayer git at videolan.org
Tue May 1 20:42:33 CEST 2012


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Tue May  1 20:20:21 2012 +0200| [aab5a4521c4034c218cbd72325b5d1946a3ec3c2] | committer: Michael Niedermayer

swr: add and use function pointers for rematrix

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

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

 libswresample/rematrix.c            |   31 +++++++++++++------------------
 libswresample/rematrix_template.c   |   17 ++++++++---------
 libswresample/swresample.c          |    5 +++--
 libswresample/swresample_internal.h |    6 +++++-
 4 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c
index 329bd66..27c4e1b 100644
--- a/libswresample/rematrix.c
+++ b/libswresample/rematrix.c
@@ -268,6 +268,8 @@ int swri_rematrix_init(SwrContext *s){
             for (j = 0; j < nb_in; j++)
                 ((int*)s->native_matrix)[i * nb_in + j] = lrintf(s->matrix[i][j] * 32768);
         *((int*)s->native_one) = 32768;
+        s->mix_1_1_f = copy_s16;
+        s->mix_2_1_f = sum2_s16;
     }else if(s->midbuf.fmt == AV_SAMPLE_FMT_FLTP){
         s->native_matrix = av_mallocz(nb_in * nb_out * sizeof(float));
         s->native_one    = av_mallocz(sizeof(float));
@@ -275,6 +277,8 @@ int swri_rematrix_init(SwrContext *s){
             for (j = 0; j < nb_in; j++)
                 ((float*)s->native_matrix)[i * nb_in + j] = s->matrix[i][j];
         *((float*)s->native_one) = 1.0;
+        s->mix_1_1_f = copy_float;
+        s->mix_2_1_f = sum2_float;
     }else
         av_assert0(0);
     //FIXME quantize for integeres
@@ -290,15 +294,6 @@ int swri_rematrix_init(SwrContext *s){
     return 0;
 }
 
-void swri_sum2(enum AVSampleFormat format, void *dst, const void *src0, const void *src1, float coef0, float coef1, int len){
-    if(format == AV_SAMPLE_FMT_FLTP){
-        sum2_float((float  *)dst, (const float  *)src0, (const float  *)src1, coef0, coef1, len);
-    }else{
-        av_assert1(format == AV_SAMPLE_FMT_S16P);
-        sum2_s16  ((int16_t*)dst, (const int16_t*)src0, (const int16_t*)src1, lrintf(coef0 * 32768), lrintf(coef1 * 32768), len);
-    }
-}
-
 void swri_rematrix_free(SwrContext *s){
     av_freep(&s->native_matrix);
     av_freep(&s->native_one);
@@ -317,19 +312,19 @@ int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mus
             break;
         case 1:
             in_i= s->matrix_ch[out_i][1];
-            if(mustcopy || s->matrix[out_i][in_i]!=1.0){
-                if(s->int_sample_fmt == AV_SAMPLE_FMT_FLTP){
-                    copy_float((float  *)out->ch[out_i], (const float  *)in->ch[in_i], s->matrix  [out_i][in_i], len);
-                }else
-                    copy_s16  ((int16_t*)out->ch[out_i], (const int16_t*)in->ch[in_i], s->matrix32[out_i][in_i], len);
+            if(s->matrix[out_i][in_i]!=1.0){
+                s->mix_1_1_f(out->ch[out_i], in->ch[in_i], s->native_matrix, in->ch_count*out_i + in_i, len);
+            }else if(mustcopy){
+                memcpy(out->ch[out_i], in->ch[in_i], len*out->bps);
             }else{
                 out->ch[out_i]= in->ch[in_i];
             }
             break;
-        case 2:
-            swri_sum2(s->int_sample_fmt, out->ch[out_i], in->ch[ s->matrix_ch[out_i][1] ],           in->ch[ s->matrix_ch[out_i][2] ],
-                        s->matrix[out_i][ s->matrix_ch[out_i][1] ], s->matrix[out_i][ s->matrix_ch[out_i][2] ], len);
-            break;
+        case 2: {
+            int in_i1 = s->matrix_ch[out_i][1];
+            int in_i2 = s->matrix_ch[out_i][2];
+            s->mix_2_1_f(out->ch[out_i], in->ch[in_i1], in->ch[in_i2], s->native_matrix, in->ch_count*out_i + in_i1, in->ch_count*out_i + in_i2, len);
+            break;}
         default:
             if(s->int_sample_fmt == AV_SAMPLE_FMT_FLTP){
                 for(i=0; i<len; i++){
diff --git a/libswresample/rematrix_template.c b/libswresample/rematrix_template.c
index 862430e..0b5123c 100644
--- a/libswresample/rematrix_template.c
+++ b/libswresample/rematrix_template.c
@@ -19,20 +19,19 @@
  */
 
 
-static void RENAME(sum2)(SAMPLE *out, const SAMPLE *in1, const SAMPLE *in2, COEFF coeff1, COEFF coeff2, int len){
+static void RENAME(sum2)(SAMPLE *out, const SAMPLE *in1, const SAMPLE *in2, COEFF *coeffp, int index1, int index2, int len){
     int i;
+    COEFF coeff1 = coeffp[index1];
+    COEFF coeff2 = coeffp[index2];
 
     for(i=0; i<len; i++)
         out[i] = R(coeff1*in1[i] + coeff2*in2[i]);
 }
 
-static void RENAME(copy)(SAMPLE *out, const SAMPLE *in, COEFF coeff, int len){
-    if(coeff == ONE){
-        memcpy(out, in, sizeof(SAMPLE)*len);
-    }else{
-        int i;
-        for(i=0; i<len; i++)
-            out[i] = R(coeff*in[i]);
-    }
+static void RENAME(copy)(SAMPLE *out, const SAMPLE *in, COEFF *coeffp, int index, int len){
+    int i;
+    COEFF coeff = coeffp[index];
+    for(i=0; i<len; i++)
+        out[i] = R(coeff*in[i]);
 }
 
diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index 9a4f6a7..0cdf29d 100644
--- a/libswresample/swresample.c
+++ b/libswresample/swresample.c
@@ -314,7 +314,7 @@ av_assert0(s->out.ch_count);
 
     s->dither = s->preout;
 
-    if(s->rematrix)
+    if(s->rematrix || s->dither_method)
         return swri_rematrix_init(s);
 
     return 0;
@@ -554,8 +554,9 @@ static int swr_convert_internal(struct SwrContext *s, AudioData *out, int out_co
 
             if(s->dither_pos + out_count > s->dither.count)
                 s->dither_pos = 0;
+
             for(ch=0; ch<preout->ch_count; ch++)
-                swri_sum2(s->int_sample_fmt, preout->ch[ch], preout->ch[ch], s->dither.ch[ch] + s->dither.bps * s->dither_pos, 1, 1, out_count);
+                s->mix_2_1_f(preout->ch[ch], preout->ch[ch], s->dither.ch[ch] + s->dither.bps * s->dither_pos, s->native_one, 0, 0, out_count);
 
             s->dither_pos += out_count;
         }
diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h
index d34a752..550d7f0 100644
--- a/libswresample/swresample_internal.h
+++ b/libswresample/swresample_internal.h
@@ -23,6 +23,9 @@
 
 #include "swresample.h"
 
+typedef void (mix_1_1_func_type)(void *out, const void *in, void *coeffp, int index, int len);
+typedef void (mix_2_1_func_type)(void *out, const void *in1, const void *in2, void *coeffp, int index1, int index2, int len);
+
 typedef struct AudioData{
     uint8_t *ch[SWR_CH_MAX];    ///< samples buffer per channel
     uint8_t *data;              ///< samples buffer
@@ -84,6 +87,8 @@ struct SwrContext {
     uint8_t *native_one;
     int32_t matrix32[SWR_CH_MAX][SWR_CH_MAX];       ///< 17.15 fixed point rematrixing coefficients
     uint8_t matrix_ch[SWR_CH_MAX][SWR_CH_MAX+1];    ///< Lists of input channels per output channel that have non zero rematrixing coefficients
+    mix_1_1_func_type *mix_1_1_f;
+    mix_2_1_func_type *mix_2_1_f;
 
     /* TODO: callbacks for ASM optimizations */
 };
@@ -100,7 +105,6 @@ int swri_resample_double(struct ResampleContext *c,double  *dst, const double  *
 int swri_rematrix_init(SwrContext *s);
 void swri_rematrix_free(SwrContext *s);
 int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy);
-void swri_sum2(enum AVSampleFormat format, void *dst, const void *src0, const void *src1, float coef0, float coef1, int len);
 
 void swri_get_dither(SwrContext *s, void *dst, int len, unsigned seed, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt);
 



More information about the ffmpeg-cvslog mailing list