Commit 844c023b by kimvde Committed by Oliver Woodman

Add CRC-8 method in Util

PiperOrigin-RevId: 279727618
parent 13cf2360
...@@ -114,7 +114,7 @@ public final class SectionReader implements TsPayloadReader { ...@@ -114,7 +114,7 @@ public final class SectionReader implements TsPayloadReader {
if (bytesRead == totalSectionLength) { if (bytesRead == totalSectionLength) {
if (sectionSyntaxIndicator) { if (sectionSyntaxIndicator) {
// This section has common syntax as defined in ISO/IEC 13818-1, section 2.4.4.11. // This section has common syntax as defined in ISO/IEC 13818-1, section 2.4.4.11.
if (Util.crc(sectionData.data, 0, totalSectionLength, 0xFFFFFFFF) != 0) { if (Util.crc32(sectionData.data, 0, totalSectionLength, 0xFFFFFFFF) != 0) {
// The CRC is invalid so discard the section. // The CRC is invalid so discard the section.
waitingForPayloadStart = true; waitingForPayloadStart = true;
return; return;
......
...@@ -267,6 +267,30 @@ public class UtilTest { ...@@ -267,6 +267,30 @@ public class UtilTest {
} }
@Test @Test
public void testCrc32() {
byte[] bytes = {0x5F, 0x78, 0x04, 0x7B, 0x5F};
int start = 1;
int end = 4;
int initialValue = 0xFFFFFFFF;
int result = Util.crc32(bytes, start, end, initialValue);
assertThat(result).isEqualTo(0x67ce9747);
}
@Test
public void testCrc8() {
byte[] bytes = {0x5F, 0x78, 0x04, 0x7B, 0x5F};
int start = 1;
int end = 4;
int initialValue = 0;
int result = Util.crc8(bytes, start, end, initialValue);
assertThat(result).isEqualTo(0x4);
}
@Test
public void testInflate() { public void testInflate() {
byte[] testData = TestUtil.buildTestData(/*arbitrary test data size*/ 256 * 1024); byte[] testData = TestUtil.buildTestData(/*arbitrary test data size*/ 256 * 1024);
byte[] compressedData = new byte[testData.length * 2]; byte[] compressedData = new byte[testData.length * 2];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment