[FFmpeg-cvslog] r26033 - trunk/libavcodec/ac3enc.c

jbr subversion
Thu Dec 16 16:06:28 CET 2010


Author: jbr
Date: Thu Dec 16 16:06:28 2010
New Revision: 26033

Log:
Use optimized function DSPContext.sad[0]() instead of calc_exp_diff().
90% faster compute_exp_strategy().

Modified:
   trunk/libavcodec/ac3enc.c

Modified: trunk/libavcodec/ac3enc.c
==============================================================================
--- trunk/libavcodec/ac3enc.c	Thu Dec 16 09:41:17 2010	(r26032)
+++ trunk/libavcodec/ac3enc.c	Thu Dec 16 16:06:28 2010	(r26033)
@@ -30,6 +30,7 @@
 #include "libavutil/crc.h"
 #include "avcodec.h"
 #include "put_bits.h"
+#include "dsputil.h"
 #include "ac3.h"
 #include "audioconvert.h"
 
@@ -84,6 +85,7 @@ typedef struct AC3Block {
  */
 typedef struct AC3EncodeContext {
     PutBitContext pb;                       ///< bitstream writer context
+    DSPContext dsp;
     AC3MDCTContext mdct;                    ///< MDCT context
 
     AC3Block blocks[AC3_MAX_BLOCKS];        ///< per-block info
@@ -513,19 +515,6 @@ static void extract_exponents(AC3EncodeC
 
 
 /**
- * Calculate the sum of absolute differences (SAD) between 2 sets of exponents.
- */
-static int calc_exp_diff(uint8_t *exp1, uint8_t *exp2, int n)
-{
-    int sum, i;
-    sum = 0;
-    for (i = 0; i < n; i++)
-        sum += abs(exp1[i] - exp2[i]);
-    return sum;
-}
-
-
-/**
  * Exponent Difference Threshold.
  * New exponents are sent if their SAD exceed this number.
  */
@@ -535,7 +524,7 @@ static int calc_exp_diff(uint8_t *exp1, 
 /**
  * Calculate exponent strategies for all blocks in a single channel.
  */
-static void compute_exp_strategy_ch(uint8_t *exp_strategy, uint8_t **exp)
+static void compute_exp_strategy_ch(AC3EncodeContext *s, uint8_t *exp_strategy, uint8_t **exp)
 {
     int blk, blk1;
     int exp_diff;
@@ -544,7 +533,7 @@ static void compute_exp_strategy_ch(uint
        reused in the next frame */
     exp_strategy[0] = EXP_NEW;
     for (blk = 1; blk < AC3_MAX_BLOCKS; blk++) {
-        exp_diff = calc_exp_diff(exp[blk], exp[blk-1], AC3_MAX_COEFS);
+        exp_diff = s->dsp.sad[0](NULL, exp[blk], exp[blk-1], 16, 16);
         if (exp_diff > EXP_DIFF_THRESHOLD)
             exp_strategy[blk] = EXP_NEW;
         else
@@ -585,7 +574,7 @@ static void compute_exp_strategy(AC3Enco
             exp_str1[ch][blk] = s->blocks[blk].exp_strategy[ch];
         }
 
-        compute_exp_strategy_ch(exp_str1[ch], exp1[ch]);
+        compute_exp_strategy_ch(s, exp_str1[ch], exp1[ch]);
 
         for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
             s->blocks[blk].exp_strategy[ch] = exp_str1[ch][blk];
@@ -1769,6 +1758,8 @@ static av_cold int ac3_encode_init(AVCod
 
     avctx->coded_frame= avcodec_alloc_frame();
 
+    dsputil_init(&s->dsp, avctx);
+
     return 0;
 init_fail:
     ac3_encode_close(avctx);



More information about the ffmpeg-cvslog mailing list