[SCM] libav/experimental: Pre-calculate crc_inv at codec init. 20% faster output_frame_end().
siretart at users.alioth.debian.org
siretart at users.alioth.debian.org
Sun Jun 30 17:20:42 UTC 2013
The following commit has been merged in the experimental branch:
commit a81d7c6aa343be8f94d9a77aa3cc091aa871833d
Author: Justin Ruggles <justin.ruggles at gmail.com>
Date: Tue Dec 21 18:26:13 2010 +0000
Pre-calculate crc_inv at codec init.
20% faster output_frame_end().
Originally committed as revision 26069 to svn://svn.ffmpeg.org/ffmpeg/trunk
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index d372e6a..ccf3e45 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -101,6 +101,7 @@ typedef struct AC3EncodeContext {
int frame_size_min; ///< minimum frame size in case rounding is necessary
int frame_size; ///< current frame size in bytes
int frame_size_code; ///< frame size code (frmsizecod)
+ uint16_t crc_inv[2];
int bits_written; ///< bit count (used to avg. bitrate)
int samples_written; ///< sample count (used to avg. bitrate)
@@ -1587,8 +1588,7 @@ static void output_frame_end(AC3EncodeContext *s)
/* this is not so easy because it is at the beginning of the data... */
crc1 = av_bswap16(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0,
frame + 4, frame_size_58 - 4));
- /* XXX: could precompute crc_inv */
- crc_inv = pow_poly((CRC16_POLY >> 1), (8 * frame_size_58) - 16, CRC16_POLY);
+ crc_inv = s->crc_inv[s->frame_size > s->frame_size_min];
crc1 = mul_poly(crc_inv, crc1, CRC16_POLY);
AV_WB16(frame + 2, crc1);
@@ -1897,7 +1897,7 @@ alloc_fail:
static av_cold int ac3_encode_init(AVCodecContext *avctx)
{
AC3EncodeContext *s = avctx->priv_data;
- int ret;
+ int ret, frame_size_58;
avctx->frame_size = AC3_FRAME_SIZE;
@@ -1915,6 +1915,14 @@ static av_cold int ac3_encode_init(AVCodecContext *avctx)
s->samples_written = 0;
s->frame_size = s->frame_size_min;
+ /* calculate crc_inv for both possible frame sizes */
+ frame_size_58 = (( s->frame_size >> 2) + ( s->frame_size >> 4)) << 1;
+ s->crc_inv[0] = pow_poly((CRC16_POLY >> 1), (8 * frame_size_58) - 16, CRC16_POLY);
+ if (s->bit_alloc.sr_code == 1) {
+ frame_size_58 = (((s->frame_size+2) >> 2) + ((s->frame_size+2) >> 4)) << 1;
+ s->crc_inv[1] = pow_poly((CRC16_POLY >> 1), (8 * frame_size_58) - 16, CRC16_POLY);
+ }
+
set_bandwidth(s);
exponent_init(s);
--
Libav/FFmpeg packaging
More information about the pkg-multimedia-commits
mailing list