Made TS packet resize on right times
CRC checksum is now a library call
This commit is contained in:
parent
2e0b73f726
commit
6260df4a32
5 changed files with 133 additions and 86 deletions
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <string.h>
|
||||
#include "ts_packet.h"
|
||||
#include "defines.h"
|
||||
|
||||
|
@ -707,6 +708,9 @@ namespace TS {
|
|||
|
||||
void ProgramMappingTable::setTableId(char newVal) {
|
||||
unsigned int loc = 4 + (AdaptationField() > 1 ? AdaptationFieldLen() + 1 : 0) + getOffset() + 1;
|
||||
if (strBuf.size() < loc + 1) {
|
||||
strBuf.resize(loc + 1);
|
||||
}
|
||||
strBuf[loc] = newVal;
|
||||
}
|
||||
|
||||
|
@ -717,7 +721,10 @@ namespace TS {
|
|||
|
||||
void ProgramMappingTable::setSectionLength(short newVal) {
|
||||
unsigned int loc = 4 + (AdaptationField() > 1 ? AdaptationFieldLen() + 1 : 0) + getOffset() + 2;
|
||||
strBuf[loc] = (char)((newVal >> 8) & 0x0F);
|
||||
if (strBuf.size() < loc + 2) {
|
||||
strBuf.resize(loc + 2);
|
||||
}
|
||||
strBuf[loc] = (char)(newVal >> 8);
|
||||
strBuf[loc+1] = (char)newVal;
|
||||
}
|
||||
|
||||
|
@ -728,6 +735,9 @@ namespace TS {
|
|||
|
||||
void ProgramMappingTable::setProgramNumber(short newVal) {
|
||||
unsigned int loc = 4 + (AdaptationField() > 1 ? AdaptationFieldLen() + 1 : 0) + getOffset() + 4;
|
||||
if (strBuf.size() < loc + 2) {
|
||||
strBuf.resize(loc + 2);
|
||||
}
|
||||
strBuf[loc] = (char)(newVal >> 8);
|
||||
strBuf[loc+1] = (char)newVal;
|
||||
}
|
||||
|
@ -739,7 +749,10 @@ namespace TS {
|
|||
|
||||
void ProgramMappingTable::setVersionNumber(char newVal) {
|
||||
unsigned int loc = 4 + (AdaptationField() > 1 ? AdaptationFieldLen() + 1 : 0) + getOffset() + 6;
|
||||
strBuf[loc] = ((newVal & 0x1F) << 1) | strBuf[loc] & 0xC1;//note: using "| strBuf" to not touch other bits
|
||||
if (strBuf.size() < loc + 1) {
|
||||
strBuf.resize(loc + 1);
|
||||
}
|
||||
strBuf[loc] = ((newVal & 0x1F) << 1) | 0xC1;
|
||||
}
|
||||
|
||||
///Retrieves the "current/next" indicator
|
||||
|
@ -751,7 +764,10 @@ namespace TS {
|
|||
///Sets the "current/next" indicator
|
||||
void ProgramMappingTable::setCurrentNextIndicator(bool newVal) {
|
||||
unsigned int loc = 4 + (AdaptationField() > 1 ? AdaptationFieldLen() + 1 : 0) + getOffset() + 6;
|
||||
strBuf[loc] = (((char)newVal) << 1) | strBuf[loc] & 0xFD;
|
||||
if (strBuf.size() < loc + 1) {
|
||||
strBuf.resize(loc + 1);
|
||||
}
|
||||
strBuf[loc] = (((char)newVal) << 1) | 0xFD;
|
||||
}
|
||||
|
||||
///Retrieves the section number
|
||||
|
@ -763,6 +779,9 @@ namespace TS {
|
|||
///Sets the section number
|
||||
void ProgramMappingTable::setSectionNumber(char newVal) {
|
||||
unsigned int loc = 4 + (AdaptationField() > 1 ? AdaptationFieldLen() + 1 : 0) + getOffset() + 7;
|
||||
if (strBuf.size() < loc + 1) {
|
||||
strBuf.resize(loc + 1);
|
||||
}
|
||||
strBuf[loc] = newVal;
|
||||
}
|
||||
|
||||
|
@ -775,6 +794,9 @@ namespace TS {
|
|||
///Sets the last section number
|
||||
void ProgramMappingTable::setLastSectionNumber(char newVal) {
|
||||
unsigned int loc = 4 + (AdaptationField() > 1 ? AdaptationFieldLen() + 1 : 0) + getOffset() + 8;
|
||||
if (strBuf.size() < loc + 1) {
|
||||
strBuf.resize(loc + 1);
|
||||
}
|
||||
strBuf[loc] = newVal;
|
||||
}
|
||||
|
||||
|
@ -785,7 +807,10 @@ namespace TS {
|
|||
|
||||
void ProgramMappingTable::setPCRPID(short newVal) {
|
||||
unsigned int loc = 4 + (AdaptationField() > 1 ? AdaptationFieldLen() + 1 : 0) + getOffset() + 9;
|
||||
strBuf[loc] = (char)((newVal >> 8) & 0x1F);
|
||||
if (strBuf.size() < loc + 2) {
|
||||
strBuf.resize(loc + 2);
|
||||
}
|
||||
strBuf[loc] = (char)((newVal >> 8) & 0x1F) | 0xE0;
|
||||
strBuf[loc+1] = (char)newVal;
|
||||
}
|
||||
|
||||
|
@ -796,7 +821,10 @@ namespace TS {
|
|||
|
||||
void ProgramMappingTable::setProgramInfoLength(short newVal) {
|
||||
unsigned int loc = 4 + (AdaptationField() > 1 ? AdaptationFieldLen() + 1 : 0) + getOffset() + 11;
|
||||
strBuf[loc] = (char)((newVal >> 8) & 0x0F);
|
||||
if (strBuf.size() < loc + 2) {
|
||||
strBuf.resize(loc + 2);
|
||||
}
|
||||
strBuf[loc] = (char)((newVal >> 8) & 0x0F) | 0xF0;
|
||||
strBuf[loc+1] = (char)newVal;
|
||||
}
|
||||
|
||||
|
@ -821,6 +849,9 @@ namespace TS {
|
|||
return;
|
||||
}
|
||||
unsigned int loc = 4 + (AdaptationField() > 1 ? AdaptationFieldLen() + 1 : 0) + getOffset() + 13 + getProgramInfoLength();
|
||||
if (strBuf.size() < loc + (index*5) + 1) {
|
||||
strBuf.resize(loc + (index*5) + 1);
|
||||
}
|
||||
strBuf[loc + (index * 5)] = newVal;
|
||||
}
|
||||
|
||||
|
@ -837,8 +868,10 @@ namespace TS {
|
|||
return;
|
||||
}
|
||||
unsigned int loc = 4 + (AdaptationField() > 1 ? AdaptationFieldLen() + 1 : 0) + getOffset() + 13 + getProgramInfoLength();
|
||||
//return (((short)strBuf[loc + (index * 5) + 1] & 0x1F) << 8) | strBuf[loc + (index * 5) + 2];
|
||||
strBuf[loc + (index * 5)+1] = (newVal >> 8) & 0x1F;
|
||||
if (strBuf.size() < loc + (index*5) + 3) {
|
||||
strBuf.resize(loc + (index*5) + 3);
|
||||
}
|
||||
strBuf[loc + (index * 5)+1] = ((newVal >> 8) & 0x1F )| 0xE0;
|
||||
strBuf[loc + (index * 5)+2] = (char)newVal;
|
||||
}
|
||||
|
||||
|
@ -856,7 +889,10 @@ namespace TS {
|
|||
}
|
||||
unsigned int loc = 4 + (AdaptationField() > 1 ? AdaptationFieldLen() + 1 : 0) + getOffset() + 13 + getProgramInfoLength();
|
||||
//return (((short)strBuf[loc + (index * 5) + 3] & 0x0F) << 8) | strBuf[loc + (index * 5) + 4];
|
||||
strBuf[loc + (index * 5)+3] = (newVal >> 8) & 0x0F;
|
||||
if (strBuf.size() < loc + (index*5) + 5) {
|
||||
strBuf.resize(loc + (index*5) + 5);
|
||||
}
|
||||
strBuf[loc + (index * 5)+3] = ((newVal >> 8) & 0x0F) | 0xF0;
|
||||
strBuf[loc + (index * 5)+4] = (char)newVal;
|
||||
}
|
||||
|
||||
|
@ -865,13 +901,20 @@ namespace TS {
|
|||
return ((int)(strBuf[loc]) << 24) | ((int)(strBuf[loc + 1]) << 16) | ((int)(strBuf[loc + 2]) << 8) | strBuf[loc + 3];
|
||||
}
|
||||
|
||||
void ProgramMappingTable::setCRC(int newVal) {
|
||||
void ProgramMappingTable::calcCRC() {
|
||||
unsigned int loc = 4 + (AdaptationField() > 1 ? AdaptationFieldLen() + 1 : 0) + getOffset() + 13 + getProgramInfoLength() + (getProgramCount() * 5);
|
||||
//return ((int)(strBuf[loc]) << 24) | ((int)(strBuf[loc + 1]) << 16) | ((int)(strBuf[loc + 2]) << 8) | strBuf[loc + 3];
|
||||
unsigned int newVal;//this will hold the CRC32 value;
|
||||
unsigned int tidLoc = 4 + (AdaptationField() > 1 ? AdaptationFieldLen() + 1 : 0) + getOffset() + 1;//location of table ID
|
||||
newVal = checksum::crc32(0, strBuf.c_str() + tidLoc, loc - tidLoc);//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;
|
||||
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);
|
||||
}
|
||||
|
||||
///Print all PMT values in a human readable format
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue