changeset 6108:75804d49f33b libavcodec

improve CRC API - don't export any global var - provide either generated or hardcoded tables
author aurel
date Fri, 04 Jan 2008 23:09:58 +0000
parents 99e470e62bad
children c8b9b73b979f
files ac3dec.c ac3enc.c flac.c flacenc.c utils.c
diffstat 5 files changed, 12 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/ac3dec.c	Fri Jan 04 20:02:10 2008 +0000
+++ b/ac3dec.c	Fri Jan 04 23:09:58 2008 +0000
@@ -1110,7 +1110,7 @@
 
     /* check for crc mismatch */
     if(avctx->error_resilience > 0) {
-        if(av_crc(av_crc8005, 0, &buf[2], s->frame_size-2)) {
+        if(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, &buf[2], s->frame_size-2)) {
             av_log(avctx, AV_LOG_ERROR, "frame CRC mismatch\n");
             return -1;
         }
--- a/ac3enc.c	Fri Jan 04 20:02:10 2008 +0000
+++ b/ac3enc.c	Fri Jan 04 23:09:58 2008 +0000
@@ -1141,13 +1141,16 @@
     /* Now we must compute both crcs : this is not so easy for crc1
        because it is at the beginning of the data... */
     frame_size_58 = (frame_size >> 1) + (frame_size >> 3);
-    crc1 = bswap_16(av_crc(av_crc8005, 0, frame + 4, 2 * frame_size_58 - 4));
+    crc1 = bswap_16(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0,
+                           frame + 4, 2 * frame_size_58 - 4));
     /* XXX: could precompute crc_inv */
     crc_inv = pow_poly((CRC16_POLY >> 1), (16 * frame_size_58) - 16, CRC16_POLY);
     crc1 = mul_poly(crc_inv, crc1, CRC16_POLY);
     AV_WB16(frame+2,crc1);
 
-    crc2 = bswap_16(av_crc(av_crc8005, 0, frame + 2 * frame_size_58, (frame_size - frame_size_58) * 2 - 2));
+    crc2 = bswap_16(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0,
+                           frame + 2 * frame_size_58,
+                           (frame_size - frame_size_58) * 2 - 2));
     AV_WB16(frame+2*frame_size-2,crc2);
 
     //    printf("n=%d frame_size=%d\n", n, frame_size);
--- a/flac.c	Fri Jan 04 20:02:10 2008 +0000
+++ b/flac.c	Fri Jan 04 23:09:58 2008 +0000
@@ -558,7 +558,8 @@
     }
 
     skip_bits(&s->gb, 8);
-    crc8= av_crc(av_crc07, 0, s->gb.buffer, get_bits_count(&s->gb)/8);
+    crc8 = av_crc(av_crc_get_table(AV_CRC_8_ATM), 0,
+                  s->gb.buffer, get_bits_count(&s->gb)/8);
     if(crc8){
         av_log(s->avctx, AV_LOG_ERROR, "header crc mismatch crc=%2X\n", crc8);
         return -1;
--- a/flacenc.c	Fri Jan 04 20:02:10 2008 +0000
+++ b/flacenc.c	Fri Jan 04 23:09:58 2008 +0000
@@ -1283,7 +1283,8 @@
         put_bits(&s->pb, 16, s->sr_code[1]);
     }
     flush_put_bits(&s->pb);
-    crc = av_crc(av_crc07, 0, s->pb.buf, put_bits_count(&s->pb)>>3);
+    crc = av_crc(av_crc_get_table(AV_CRC_8_ATM), 0,
+                 s->pb.buf, put_bits_count(&s->pb)>>3);
     put_bits(&s->pb, 8, crc);
 }
 
@@ -1425,7 +1426,8 @@
 {
     int crc;
     flush_put_bits(&s->pb);
-    crc = bswap_16(av_crc(av_crc8005, 0, s->pb.buf, put_bits_count(&s->pb)>>3));
+    crc = bswap_16(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0,
+                          s->pb.buf, put_bits_count(&s->pb)>>3));
     put_bits(&s->pb, 16, crc);
     flush_put_bits(&s->pb);
 }
--- a/utils.c	Fri Jan 04 20:02:10 2008 +0000
+++ b/utils.c	Fri Jan 04 23:09:58 2008 +0000
@@ -1247,17 +1247,6 @@
   return LIBAVCODEC_BUILD;
 }
 
-static void init_crcs(void){
-#if LIBAVUTIL_VERSION_INT  < (50<<16)
-    av_crc04C11DB7= av_mallocz_static(sizeof(AVCRC) * 257);
-    av_crc8005    = av_mallocz_static(sizeof(AVCRC) * 257);
-    av_crc07      = av_mallocz_static(sizeof(AVCRC) * 257);
-#endif
-    av_crc_init(av_crc04C11DB7, 0, 32, AV_CRC_32_IEEE, sizeof(AVCRC)*257);
-    av_crc_init(av_crc8005    , 0, 16, AV_CRC_16     , sizeof(AVCRC)*257);
-    av_crc_init(av_crc07      , 0,  8, AV_CRC_8_ATM  , sizeof(AVCRC)*257);
-}
-
 void avcodec_init(void)
 {
     static int inited = 0;
@@ -1267,7 +1256,6 @@
     inited = 1;
 
     dsputil_static_init();
-    init_crcs();
 }
 
 void avcodec_flush_buffers(AVCodecContext *avctx)