ts crc32 验证与计算

/****************************************************************************
***  作用  :
***        第一,求ts流中pat,pmt表的crc32;
             第二,验证crc32是否正确,验证时,把len加4,把4个字节的crc写到crc32_table的后面,得到crc为0,则crc为正确的。
***  备注  : crc32_table是根据32位的crc码字得来。在vlc的开源代码中有代码。
****************************************************************************/


#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>


int MakeTable(uint32_t *crc32_table)
{
    for(uint32_t i = 0; i < 256; i++ ) {
        uint32_t k = 0;
        for(uint32_t j = (i << 24) | 0x800000; j != 0x80000000; j <<= 1 ) {
            k = (k << 1) ^ (((k ^ j) & 0x80000000) ? 0x04c11db7 : 0);
        }

        crc32_table[i] = k;
    }
}
uint32_t Crc32Calculate(uint8_t *buffer, uint32_t size, uint32_t *crc32_table)
{
    uint32_t crc32_reg = 0xFFFFFFFF
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值