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

jbr subversion
Tue Dec 21 19:26:14 CET 2010


Author: jbr
Date: Tue Dec 21 19:26:13 2010
New Revision: 26069

Log:
Pre-calculate crc_inv at codec init.
20% faster output_frame_end().

Modified:
   trunk/libavcodec/ac3enc.c

Modified: trunk/libavcodec/ac3enc.c
==============================================================================
--- trunk/libavcodec/ac3enc.c	Tue Dec 21 12:19:59 2010	(r26068)
+++ trunk/libavcodec/ac3enc.c	Tue Dec 21 19:26:13 2010	(r26069)
@@ -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(AC3EncodeCo
     /* 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(AVCod
     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);



More information about the ffmpeg-cvslog mailing list