1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

Use optimized function DSPContext.sad[0]() instead of calc_exp_diff().

90% faster compute_exp_strategy().

Originally committed as revision 26033 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Justin Ruggles 2010-12-16 15:06:28 +00:00
parent 4f7d2fe2e3
commit 8846ee54ad

View File

@ -30,6 +30,7 @@
#include "libavutil/crc.h" #include "libavutil/crc.h"
#include "avcodec.h" #include "avcodec.h"
#include "put_bits.h" #include "put_bits.h"
#include "dsputil.h"
#include "ac3.h" #include "ac3.h"
#include "audioconvert.h" #include "audioconvert.h"
@ -84,6 +85,7 @@ typedef struct AC3Block {
*/ */
typedef struct AC3EncodeContext { typedef struct AC3EncodeContext {
PutBitContext pb; ///< bitstream writer context PutBitContext pb; ///< bitstream writer context
DSPContext dsp;
AC3MDCTContext mdct; ///< MDCT context AC3MDCTContext mdct; ///< MDCT context
AC3Block blocks[AC3_MAX_BLOCKS]; ///< per-block info AC3Block blocks[AC3_MAX_BLOCKS]; ///< per-block info
@ -512,19 +514,6 @@ static void extract_exponents(AC3EncodeContext *s)
} }
/**
* 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. * Exponent Difference Threshold.
* New exponents are sent if their SAD exceed this number. * New exponents are sent if their SAD exceed this number.
@ -535,7 +524,7 @@ static int calc_exp_diff(uint8_t *exp1, uint8_t *exp2, int n)
/** /**
* Calculate exponent strategies for all blocks in a single channel. * 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 blk, blk1;
int exp_diff; int exp_diff;
@ -544,7 +533,7 @@ static void compute_exp_strategy_ch(uint8_t *exp_strategy, uint8_t **exp)
reused in the next frame */ reused in the next frame */
exp_strategy[0] = EXP_NEW; exp_strategy[0] = EXP_NEW;
for (blk = 1; blk < AC3_MAX_BLOCKS; blk++) { 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) if (exp_diff > EXP_DIFF_THRESHOLD)
exp_strategy[blk] = EXP_NEW; exp_strategy[blk] = EXP_NEW;
else else
@ -585,7 +574,7 @@ static void compute_exp_strategy(AC3EncodeContext *s)
exp_str1[ch][blk] = s->blocks[blk].exp_strategy[ch]; 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++) for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
s->blocks[blk].exp_strategy[ch] = exp_str1[ch][blk]; s->blocks[blk].exp_strategy[ch] = exp_str1[ch][blk];
@ -1769,6 +1758,8 @@ static av_cold int ac3_encode_init(AVCodecContext *avctx)
avctx->coded_frame= avcodec_alloc_frame(); avctx->coded_frame= avcodec_alloc_frame();
dsputil_init(&s->dsp, avctx);
return 0; return 0;
init_fail: init_fail:
ac3_encode_close(avctx); ac3_encode_close(avctx);