2
* CRC functions for mpeg PSI tables
3
* Copyright (C) 2010-2011 Unix Solutions Ltd.
5
* Released under MIT license.
6
* See LICENSE-MIT.txt for license terms.
12
#define CRC32_POLY 0x04C11DB7L
14
static int crc_table_initialized = 0;
15
static uint32_t crc32_table[256];
17
void ts_crc32_init(void) {
20
if (crc_table_initialized)
22
crc_table_initialized = 1;
23
for (i=0; i<256; i++) {
26
if (crc & 0x80000000L)
27
crc = (crc << 1) ^ CRC32_POLY;
33
crc_table_initialized = 1;
36
uint32_t ts_crc32(uint8_t *data, int data_size) {
38
uint32_t crc = 0xffffffff;
39
if (!crc_table_initialized) {
42
for (j=0; j<data_size; j++) {
43
i = ((crc >> 24) ^ *data++) & 0xff;
44
crc = (crc << 8) ^ crc32_table[i];
49
u_int32_t ts_crc32_section(struct ts_section_header *section_header) {
50
return ts_crc32(section_header->section_data, section_header->section_data_len);
53
int ts_crc32_section_check(struct ts_section_header *section_header, char *table) {
54
uint32_t check_crc = ts_crc32(section_header->section_data, section_header->section_data_len);
57
ts_LOGf("!!! Wrong %s table CRC! It should be 0 but it is 0x%08x (CRC in data is 0x%08x)\n",