Revision 3abe5fbd libavutil/crc.c

View differences:

libavutil/crc.c
21 21
#include "common.h"
22 22
#include "crc.h"
23 23

  
24
#if LIBAVUTIL_VERSION_INT  < (50<<16)
25
AVCRC *av_crcEDB88320;
26
AVCRC *av_crc04C11DB7;
27
AVCRC *av_crc8005    ;
28
AVCRC *av_crc07      ;
24
#ifdef CONFIG_HARDCODED_TABLES
25
#include "crc_data.h"
29 26
#else
30
AVCRC av_crcEDB88320[257];
31
AVCRC av_crc04C11DB7[257];
32
AVCRC av_crc8005    [257];
33
AVCRC av_crc07      [257];
27
static struct {
28
    uint8_t  le;
29
    uint8_t  bits;
30
    uint32_t poly;
31
} av_crc_table_params[AV_CRC_MAX] = {
32
    [AV_CRC_8_ATM]      = { 0,  8,       0x07 },
33
    [AV_CRC_16_ANSI]    = { 0, 16,     0x8005 },
34
    [AV_CRC_16_CCITT]   = { 0, 16,     0x1021 },
35
    [AV_CRC_32_IEEE]    = { 0, 32, 0x04C11DB7 },
36
    [AV_CRC_32_IEEE_LE] = { 1, 32, 0xEDB88320 },
37
};
38
static AVCRC av_crc_table[AV_CRC_MAX][257];
34 39
#endif
35 40

  
36 41
/**
......
80 85
}
81 86

  
82 87
/**
88
 * Get an initialized standard CRC table.
89
 * @param crc_id ID of a standard CRC
90
 * @return a pointer to the CRC table or NULL on failure
91
 */
92
const AVCRC *av_crc_get_table(AVCRCId crc_id){
93
#ifndef CONFIG_HARDCODED_TABLES
94
    if (!av_crc_table[crc_id][sizeof(av_crc_table[crc_id])-1])
95
        if (av_crc_init(av_crc_table[crc_id],
96
                        av_crc_table_params[crc_id].le,
97
                        av_crc_table_params[crc_id].bits,
98
                        av_crc_table_params[crc_id].poly,
99
                        sizeof(av_crc_table[crc_id])) < 0)
100
            return NULL;
101
#endif
102
    return av_crc_table[crc_id];
103
}
104

  
105
/**
83 106
 * Calculate the CRC of a block
84 107
 * @param crc CRC of previous blocks if any or initial value for CRC.
85 108
 * @return CRC updated with the data from the given block
......
110 133
main(void){
111 134
    uint8_t buf[1999];
112 135
    int i;
113
    int p[4][4]={{1, 32, AV_CRC_32_IEEE_LE, 0x3D5CDD04},
114
                 {0, 32, AV_CRC_32_IEEE   , 0xC0F5BAE0},
115
                 {0, 16, AV_CRC_16        , 0x1FBB    },
116
                 {0,  8, AV_CRC_8_ATM     , 0xE3      },};
117
    AVCRC ctx[1 ? 1024:257];
136
    int p[4][3]={{AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04},
137
                 {AV_CRC_32_IEEE   , 0x04C11DB7, 0xC0F5BAE0},
138
                 {AV_CRC_16_ANSI   , 0x8005,     0x1FBB    },
139
                 {AV_CRC_8_ATM     , 0x07,       0xE3      },};
140
    const AVCRC *ctx;
118 141

  
119 142
    for(i=0; i<sizeof(buf); i++)
120 143
        buf[i]= i+i*i;
121 144

  
122 145
    for(i=0; i<4; i++){
123
        av_crc_init(ctx, p[i][0], p[i][1], p[i][2], sizeof(ctx));
124
        printf("crc %08X =%X\n", p[i][2], av_crc(ctx, 0, buf, sizeof(buf)));
146
        ctx = av_crc_get_table(p[i][0]);
147
        printf("crc %08X =%X\n", p[i][1], av_crc(ctx, 0, buf, sizeof(buf)));
125 148
    }
126 149
}
127 150
#endif

Also available in: Unified diff