libtsfuncs is a library for mpeg PSI parsing and generation. https://georgi.unixsol.org/programs/libtsfuncs/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tsfuncs_crc.c 747B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <netdb.h>
  2. #include "tsfuncs.h"
  3. #define CRC32_POLY 0x04C11DB7L
  4. static int crc_table_initialized = 0;
  5. static uint32_t crc32_table[256];
  6. void ts_crc32_init() {
  7. int i, j;
  8. uint32_t crc;
  9. if (crc_table_initialized)
  10. return;
  11. crc_table_initialized = 1;
  12. for (i=0; i<256; i++) {
  13. crc = i << 24;
  14. for (j=0; j<8; j++) {
  15. if (crc & 0x80000000L)
  16. crc = (crc << 1) ^ CRC32_POLY;
  17. else
  18. crc = (crc << 1);
  19. }
  20. crc32_table[i] = crc;
  21. }
  22. crc_table_initialized = 1;
  23. }
  24. uint32_t ts_crc32(uint8_t *data, int data_size) {
  25. int i, j;
  26. uint32_t crc = 0xffffffff;
  27. if (!crc_table_initialized) {
  28. ts_crc32_init();
  29. }
  30. for (j=0; j<data_size; j++) {
  31. i = ((crc >> 24) ^ *data++) & 0xff;
  32. crc = (crc << 8) ^ crc32_table[i];
  33. }
  34. return crc;
  35. }