Fixed CRC calculation for TS Packets, in particular the PAT
This commit is contained in:
parent
7bf5b4093b
commit
fc080f81ca
2 changed files with 13 additions and 13 deletions
|
@ -219,10 +219,10 @@ namespace checksum {
|
|||
0x6D66B4BCU, 0xDA7B75B8U, 0x035D36B5U, 0xB440F7B1U
|
||||
};
|
||||
|
||||
while (len > 0) {
|
||||
crc = table[*data ^ ((crc >> 24) & 0xff)] ^ (crc << 8);
|
||||
data++;
|
||||
len--;
|
||||
const char * tmpData = data;
|
||||
const char * end = tmpData + len;
|
||||
while(tmpData < end){
|
||||
crc = table[((unsigned char) crc) ^ *tmpData++] ^ (crc >> 8);
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
|
|
@ -919,20 +919,20 @@ namespace TS {
|
|||
return ((int)(strBuf[loc]) << 24) | ((int)(strBuf[loc + 1]) << 16) | ((int)(strBuf[loc + 2]) << 8) | strBuf[loc + 3];
|
||||
}
|
||||
|
||||
/// \todo checksum is calculated wrong, but the stream plays. Fix checksum when deadlines are less tight.
|
||||
void ProgramMappingTable::calcCRC() {
|
||||
unsigned int loc = 4 + (AdaptationField() > 1 ? AdaptationFieldLen() + 1 : 0) + getOffset() + 13 + getProgramInfoLength() + (getProgramCount() * 5);
|
||||
unsigned int loc = 4 + (AdaptationField() > 1 ? AdaptationFieldLen() + 1 : 0) + getOffset() + getSectionLength();
|
||||
unsigned int newVal;//this will hold the CRC32 value;
|
||||
unsigned int pidLoc = 4 + (AdaptationField() > 1 ? AdaptationFieldLen() + 1 : 0) + getOffset() + 9;;//location of PCRPID
|
||||
newVal = checksum::crc32LE(0, strBuf.c_str() + pidLoc, loc - pidLoc);//calculating checksum over all the fields from table ID to the last stream element
|
||||
unsigned int pidLoc = 4 + (AdaptationField() > 1 ? AdaptationFieldLen() + 1 : 0) + getOffset() + 1;//location of PCRPID
|
||||
INFO_MSG("Calculating checksum from offset %d, over %d bytes", pidLoc, loc - pidLoc);
|
||||
newVal = checksum::crc32(-1, strBuf.c_str() + pidLoc, loc - pidLoc);//calculating checksum over all the fields from table ID to the last stream element
|
||||
if (strBuf.size() < 188) {
|
||||
strBuf.resize(188);
|
||||
}
|
||||
strBuf[loc] = (newVal >> 24) & 0xFF;
|
||||
strBuf[loc + 1] = (newVal >> 16) & 0xFF;
|
||||
strBuf[loc + 2] = (newVal >> 8) & 0xFF;
|
||||
strBuf[loc + 3] = newVal & 0xFF;
|
||||
memset((void*)(strBuf.c_str() + loc + 4), 0xFF, 180 - loc);
|
||||
strBuf[loc + 3] = (newVal >> 24) & 0xFF;
|
||||
strBuf[loc + 2] = (newVal >> 16) & 0xFF;
|
||||
strBuf[loc + 1] = (newVal >> 8) & 0xFF;
|
||||
strBuf[loc] = newVal & 0xFF;
|
||||
memset((void*)(strBuf.c_str() + loc + 4), 0xFF, 184 - loc);
|
||||
}
|
||||
|
||||
///Print all PMT values in a human readable format
|
||||
|
|
Loading…
Add table
Reference in a new issue