streaming

Media streaming and broadcast systems in Go
Log | Files | Refs | README | LICENSE

commit 2e101735bcb571463fd083fff12c7c8b294422aa
parent e7e2b86dca1304f64b739b15f24f474b5cffedeb
Author: blackfalcon <blackfalcon.ru@gmail.com>
Date:   Sat,  1 Jun 2024 03:59:57 -0300

scte35: use updateCRC

Diffstat:
Mscte35/crc_32.go | 11+++++------
Mscte35/splice.go | 2+-
2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/scte35/crc_32.go b/scte35/crc_32.go @@ -41,11 +41,10 @@ func makeCRC32Table(poly uint32) crc32.Table { return tab } -// checksum calculates the checksum for the given bytes using tab. -func checksum(b []byte, tab *crc32.Table) uint32 { - crc := int32(-1) - for i := range b { - crc = (crc << 8) ^ int32(tab[((crc>>24)^int32(b[i]))&0xFF]) +func updateCRC(val uint32, b []byte) uint32 { + crc := ^val + for _, v := range b { + crc = crctab[byte(crc>>24)^v] ^ (crc << 8) } - return uint32(crc) + return ^crc } diff --git a/scte35/splice.go b/scte35/splice.go @@ -143,7 +143,7 @@ func Encode(splice *Splice) ([]byte, error) { buf[1] |= byte(buflen >> 8) buf[2] = byte(buflen) - crc := checksum(buf, &crctab) + crc := ^updateCRC(0, buf) return binary.BigEndian.AppendUint32(buf, crc), nil }