TS::Packet classes no longer rely on global PMT tracking

This commit is contained in:
Thulinma 2020-08-29 00:54:28 +02:00
parent 7423868de4
commit 3baa8d1524
5 changed files with 63 additions and 36 deletions

View file

@ -27,9 +27,6 @@
"tortor commodo neque, vitae hendrerit nunc sem ut odio."
#endif
std::set<unsigned int> pmt_pids;
std::map<unsigned int, std::string> stream_pids;
/// A standard Program Association Table, as generated by FFMPEG.
/// Seems to be independent of the stream.
// 0x47 = sync byte
@ -47,6 +44,8 @@ std::map<unsigned int, std::string> stream_pids;
// 0x2AB104B2 = CRC32
namespace TS{
std::map<unsigned int, std::string> stream_pids;
char PAT[188] ={
0x47, 0x40, 0x00, 0x10, 0x00, 0x00, 0xB0, 0x0D, 0x00, 0x01, 0xC1, 0x00, 0x00, 0x00, 0x01,
0xF0, 0x00, 0x2A, 0xB1, 0x04, 0xB2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
@ -276,7 +275,7 @@ namespace TS{
/// Prints a packet to stdout, for analyser purposes.
/// If detail level contains bitmask 64, prints raw bytes after packet.
std::string Packet::toPrettyString(size_t indent, int detailLevel) const{
std::string Packet::toPrettyString(const std::set<unsigned int> &pidlist, size_t indent, int detailLevel) const{
if (!(*this)){return "[Invalid packet - no sync byte]";}
std::stringstream output;
output << std::string(indent, ' ') << "[PID " << getPID() << "|" << std::hex
@ -288,7 +287,7 @@ namespace TS{
case 17: output << "SDT"; break;
case 0x1FFF: output << "Null"; break;
default:
if (isPMT()){
if (isPMT(pidlist)){
output << "PMT";
}else{
if (isStream()){
@ -315,7 +314,7 @@ namespace TS{
return output.str();
}
if (pmt_pids.count(getPID())){
if (pidlist.count(getPID())){
// PMT
output << ((ProgramMappingTable *)this)->toPrettyString(indent + 2);
return output.str();
@ -349,7 +348,7 @@ namespace TS{
/// Returns true if this PID contains a PMT.
/// Important caveat: only works if the corresponding PAT has been pretty-printed or had parsePIDs() called on it!
bool Packet::isPMT() const{return pmt_pids.count(getPID());}
bool Packet::isPMT(const std::set<unsigned int> & pidList) const{return pidList.count(getPID());}
/// Returns true if this PID contains a stream known from a PMT.
/// Important caveat: only works if the corresponding PMT was pretty-printed or had parseStreams() called on it!
@ -834,8 +833,8 @@ namespace TS{
((int)(strBuf[loc + 2]) << 8) | strBuf[loc + 3];
}
void ProgramAssociationTable::parsePIDs(){
for (int i = 0; i < getProgramCount(); i++){pmt_pids.insert(getProgramPID(i));}
void ProgramAssociationTable::parsePIDs(std::set<unsigned int> & pidlist){
for (int i = 0; i < getProgramCount(); i++){pidlist.insert(getProgramPID(i));}
}
/// This function prints a program association table,