diff --git a/lib/bitfields.h b/lib/bitfields.h index 8fb8dc98..77422a08 100644 --- a/lib/bitfields.h +++ b/lib/bitfields.h @@ -39,7 +39,7 @@ namespace Bit{ } /// Retrieves a long in network order from the pointer p. - inline unsigned long btoh24(char * p) { + inline unsigned long btoh24(const char * p) { return ((unsigned long)p[0] << 16) | ((unsigned long)p[1] << 8) | p[2]; } @@ -51,7 +51,7 @@ namespace Bit{ } /// Retrieves a long long in network order from the pointer p. - inline unsigned long long btohll(char * p) { + inline unsigned long long btohll(const char * p) { return ((unsigned long long)p[0] << 56) | ((unsigned long long)p[1] << 48) | ((unsigned long long)p[2] << 40) | ((unsigned long long)p[3] << 32) | ((unsigned long)p[4] << 24) | ((unsigned long)p[5] << 16) | ((unsigned long)p[6] << 8) | p[7]; } diff --git a/lib/dtscmeta.cpp b/lib/dtscmeta.cpp index cca7ed8e..3385a5fe 100644 --- a/lib/dtscmeta.cpp +++ b/lib/dtscmeta.cpp @@ -211,6 +211,10 @@ namespace DTSC { //bpos, if >= 0, adds 9 bytes (integer type) and 6 bytes (2+namelen) //keyframe, if true, adds 9 bytes (integer type) and 10 bytes (2+namelen) //data adds packDataSize+5 bytes (string type) and 6 bytes (2+namelen) + if (packDataSize < 1){ + FAIL_MSG("Attempted to fill a packet with %lli bytes!", packDataSize); + return; + } unsigned int sendLen = 24 + (packOffset?17:0) + (packBytePos?15:0) + (isKeyframe?19:0) + packDataSize+11; resize(sendLen); //set internal variables diff --git a/lib/h264.cpp b/lib/h264.cpp index a256b61e..79101e05 100644 --- a/lib/h264.cpp +++ b/lib/h264.cpp @@ -10,7 +10,8 @@ namespace h264 { std::deque res; int offset = 0; - while (offset < len){ + //Make sure entire packet is within len + while (offset+5 < len && Bit::btohl(data + offset)+offset+4 <= len){ nalu::nalData entry; entry.nalSize = Bit::btohl(data + offset); entry.nalType = (data + offset)[4] & 0x1F; diff --git a/lib/ts_packet.cpp b/lib/ts_packet.cpp index 2e36a805..0e61f829 100644 --- a/lib/ts_packet.cpp +++ b/lib/ts_packet.cpp @@ -230,18 +230,22 @@ namespace TS { } std::stringstream output; output << std::string(indent, ' ') << "[PID " << getPID() << "|" << std::hex << getContinuityCounter() << std::dec << ": " << getDataSize() << "b "; - if (!getPID()){ - output << "PAT"; - }else{ - if (pmt_pids.count(getPID())){ - output << "PMT"; - }else{ - if (stream_pids.count(getPID())){ - output << stream_pids[getPID()]; + switch (getPID()){ + case 0: output << "PAT"; break; + case 1: output << "CAT"; break; + case 2: output << "TSDT"; break; + case 0x1FFF: output << "Null"; break; + default: + if (pmt_pids.count(getPID())){ + output << "PMT"; }else{ - output << "Unknown"; + if (stream_pids.count(getPID())){ + output << stream_pids[getPID()]; + }else{ + output << "Unknown"; + } } - } + break; } output << "]"; if (getUnitStart()){ @@ -649,6 +653,12 @@ namespace TS { return ((int)(strBuf[loc]) << 24) | ((int)(strBuf[loc + 1]) << 16) | ((int)(strBuf[loc + 2]) << 8) | strBuf[loc + 3]; } + void ProgramAssociationTable::parsePIDs(){ + for (int i = 0; i < getProgramCount(); i++) { + pmt_pids.insert(getProgramPID(i)); + } + } + ///This function prints a program association table, ///prints all values in a human readable format ///\param indent The indentation of the string printed as wanted by the user @@ -669,7 +679,6 @@ namespace TS { output << std::string(indent + 4, ' ') << "[" << i + 1 << "] "; output << "Program Number: " << getProgramNumber(i) << ", "; output << (getProgramNumber(i) == 0 ? "Network" : "Program Map") << " PID: " << getProgramPID(i); - pmt_pids.insert(getProgramPID(i)); output << std::endl; } output << std::string(indent + 2, ' ') << "CRC32: " << std::hex << std::setw(8) << std::setfill('0') << std::uppercase << getCRC() << std::dec << std::endl; @@ -950,7 +959,11 @@ namespace TS { while (entry) { output << std::string(indent + 4, ' '); stream_pids[entry.getElementaryPid()] = entry.getCodec() + std::string(" ") + entry.getStreamTypeString(); - output << "Stream " << entry.getElementaryPid() << ": " << stream_pids[entry.getElementaryPid()] << " (" << entry.getStreamType() << "), InfoLen = " << entry.getESInfoLength() << std::endl; + output << "Stream " << entry.getElementaryPid() << ": " << stream_pids[entry.getElementaryPid()] << " (" << entry.getStreamType() << "), Info (" << entry.getESInfoLength() << ") = "; + for (unsigned int i = 0; i