From 5dfebb5b26f1e453f15ab0c89b9328df5d41be96 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Tue, 27 Dec 2016 23:28:50 +0100 Subject: [PATCH] Improved TS packet class internals --- lib/ts_packet.cpp | 40 +++++++++++++++++++++++----------------- lib/ts_packet.h | 2 ++ 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/lib/ts_packet.cpp b/lib/ts_packet.cpp index 1636531e..5fdd460d 100644 --- a/lib/ts_packet.cpp +++ b/lib/ts_packet.cpp @@ -225,6 +225,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{ if (!(*this)){ return "[Invalid packet - no sync byte]"; @@ -238,10 +239,10 @@ namespace TS { case 17: output << "SDT"; break; case 0x1FFF: output << "Null"; break; default: - if (pmt_pids.count(getPID())){ + if (isPMT()){ output << "PMT"; }else{ - if (stream_pids.count(getPID())){ + if (isStream()){ output << stream_pids[getPID()]; }else{ output << "Unknown"; @@ -273,33 +274,23 @@ namespace TS { output << std::endl; if (!getPID()) { //PAT - if (detailLevel >= 2){ - output << ((ProgramAssociationTable *)this)->toPrettyString(indent + 2); - }else{ - ((ProgramAssociationTable *)this)->toPrettyString(indent + 2); - } + output << ((ProgramAssociationTable *)this)->toPrettyString(indent + 2); return output.str(); } if (pmt_pids.count(getPID())){ //PMT - if (detailLevel >= 2){ - output << ((ProgramMappingTable *)this)->toPrettyString(indent + 2); - }else{ - ((ProgramMappingTable *)this)->toPrettyString(indent + 2); - } + output << ((ProgramMappingTable *)this)->toPrettyString(indent + 2); return output.str(); } if (getPID() == 17){ //SDT - if (detailLevel >= 2){ - output << ((ServiceDescriptionTable *)this)->toPrettyString(indent + 2); - } + output << ((ServiceDescriptionTable *)this)->toPrettyString(indent + 2); return output.str(); } - if (detailLevel >= 10){ + if (detailLevel & 64){ output << std::string(indent+2, ' ') << "Raw data bytes:"; unsigned int size = getDataSize(); @@ -323,11 +314,17 @@ namespace TS { } /// Returns true if this PID contains a PMT. - /// Important caveat: only works if the corresponding PAT has been pretty-printed earlier! + /// 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()); } + /// 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! + bool Packet::isStream() const{ + return stream_pids.count(getPID()); + } + /// Sets the start of a new unit in this Packet. /// \param NewVal The new value for the start of a unit. void Packet::setUnitStart(bool NewVal) { @@ -979,6 +976,15 @@ namespace TS { memset((void*)(strBuf + loc + 4), 0xFF, 184 - loc); } + /// Parses the PMT for streams, keeping track of their PIDs to make the Packet::isStream() function work + void ProgramMappingTable::parseStreams(){ + ProgramMappingEntry entry = getEntry(0); + while (entry) { + stream_pids[entry.getElementaryPid()] = entry.getCodec() + std::string(" ") + entry.getStreamTypeString(); + entry.advance(); + } + } + ///Print all PMT values in a human readable format ///\param indent The indentation of the string printed as wanted by the user ///\return The string with human readable data from a PMT table diff --git a/lib/ts_packet.h b/lib/ts_packet.h index 2086f438..4e411a1c 100644 --- a/lib/ts_packet.h +++ b/lib/ts_packet.h @@ -59,6 +59,7 @@ namespace TS { //Helper functions operator bool() const; bool isPMT() const; + bool isStream() const; void clear(); void setDefaultPAT(); unsigned int getDataSize() const; @@ -157,6 +158,7 @@ namespace TS { void setPCRPID(short newVal); short getProgramInfoLength() const; void setProgramInfoLength(short newVal); + void parseStreams(); ProgramMappingEntry getEntry(int index) const; int getCRC() const; void calcCRC();