Go to the documentation of this file.
48 const QString &sistandard)
74 if ((reg ==
"DTS1") || (reg ==
"DTS2") || (reg ==
"DTS3"))
241 LOG(VB_SIPARSER, LOG_ERR,
242 QString(
"PSIPTable: Failed CRC check 0x%1 != 0x%2 "
243 "for TableID = 0x%3")
259 bool ok = (
psipdata() + (pcnt << 2) + 3 < bufend);
262 LOG(VB_SIPARSER, LOG_ERR,
263 "PSIPTable: PAT: program list extends past end of buffer");
270 LOG(VB_SIPARSER, LOG_ERR,
"PSIPTable: PAT: All values at maximums");
281 LOG(VB_SIPARSER, LOG_ERR,
282 "PSIPTable: PMT: can't query program info length");
288 LOG(VB_SIPARSER, LOG_ERR,
289 "PSIPTable: PMT: reported length too large");
294 const unsigned char *proginfo =
psipdata() + 4;
295 const unsigned char *cpos = proginfo + proginfolen;
298 LOG(VB_SIPARSER, LOG_ERR,
299 "PSIPTable: PMT: program info extends past end of buffer");
303 const unsigned char *pos = cpos;
307 const unsigned char *ptr = pos;
308 if (pos + 4 > bufend)
310 LOG(VB_SIPARSER, LOG_ERR,
311 QString(
"PSIPTable: PMT: stream info %1 extends "
312 "past end of buffer").arg(i));
315 pos += 5 + (((ptr[3] << 8) | ptr[4]) & 0x0fff);
319 LOG(VB_SIPARSER, LOG_ERR,
320 QString(
"PSIPTable: PMT: last stream info %1 extends "
321 "past end of buffer").arg(i));
348 const std::vector<uint>& pnum,
const std::vector<uint>& pid)
350 const uint count = std::min(pnum.size(), pid.size());
359 LOG(VB_GENERAL, LOG_ERR,
360 "PAT::Create: Error, old PAT size exceeds maximum PAT size.");
366 for (
uint i = 0; i < count; i++)
369 pat->
pesdata()[offset++] = pnum[i]>>8;
370 pat->
pesdata()[offset++] = pnum[i] & 0xff;
372 pat->
pesdata()[offset++] = ((pid[i]>>8) & 0x1f) | 0xe0;
373 pat->
pesdata()[offset++] = pid[i] & 0xff;
408 std::vector<uint> pids, std::vector<uint>
types)
410 const uint count = std::min(pids.size(),
types.size());
419 for (
uint i=0; i<count; i++)
429 const std::vector<uint> &pids,
430 const std::vector<uint> &
types,
431 const std::vector<desc_list_t> &prog_desc)
433 const uint count = std::min(pids.size(),
types.size());
442 std::vector<unsigned char> gdesc;
443 for (
const auto *gd : global_desc)
445 uint len = gd[1] + 2;
446 gdesc.insert(gdesc.end(), gd, gd + len);
450 for (
uint i = 0; i < count; i++)
452 std::vector<unsigned char> pdesc;
453 for (
const auto *pd : prog_desc[i])
455 uint len = pd[1] + 2;
456 pdesc.insert(pdesc.end(), pd, pd + len);
463 LOG(VB_SIPARSER, LOG_INFO,
"Created PMT \n" + pmt->
toString());
472 auto *pos =
const_cast<unsigned char*
>(cpos);
478 LOG(VB_SIPARSER, LOG_DEBUG, QString(
"Parsing PMT(0x%1) i(%2) len(%3)")
484 LOG(VB_SIPARSER, LOG_DEBUG, QString(
"Parsed PMT(0x%1)\n%2")
485 .arg((uint64_t)
this, 0, 16) .arg(
toString()));
491 unsigned char* streamInfo,
uint infoLength)
573 QMap<uint,uint> encryption_system;
574 for (
auto & desc : descs)
583 LOG(VB_GENERAL, LOG_INFO,
"DTVsm: " + cad.
toString());
587 return encrypted != 0;
601 QMap<uint,uint> encryption_system;
602 for (
auto & desc : descs)
610 LOG(VB_GENERAL, LOG_INFO,
"DTVsm: " + cad.
toString());
614 return encrypted != 0;
619 static constexpr
unsigned char kStillPictureFlag = 0x01;
627 ((
StreamInfo(i)[2] & kStillPictureFlag) != 0);
643 std::vector<uint> &pids,
644 const QString &sistandard)
const
679 std::vector<uint> &pids,
680 std::vector<uint> &
types,
681 const QString &sistandard,
682 bool normalize)
const
684 uint pids_start = pids.size();
723 for (
size_t i = pids_start; i < pids.size(); i++)
739 uint pid = desired_pid;
766 str.append(QString(
" PSIP tableID(0x%1) length(%2) extension(0x%3)\n")
769 str.append(QString(
" version(%1) current(%2) "
770 "section(%3) last_section(%4)\n")
775 str.append(QString(
" atsc_protocol_version(%1)\n")
791 QString str = QString(
792 R
"(table_id="0x%1" length="%2")")
793 .arg(TableID(), 2, 16, QChar('0'))
798 str += QString(R
"( section="%4" last_section="%5")")
804 str += QString(
"\n%1version=\"%2\" current=\"%3\" "
805 "protocol_version=\"%4\" extension=\"0x%5\"")
818 str.append(QString(
"Program Association Section\n"));
821 str.append(QString(
"programCount(%1)\n").arg(
ProgramCount()));
839 str += QString(
" program number %1 has PID 0x%2\n")
846 str.append(QString(
" also contains %1 dummy programs\n")
847 .arg(cnt0 + cnt1fff));
858 QString str = QString(
859 "%1<ProgramAssociationSection tsid=\"0x%2\" program_count=\"%3\""
870 str += QString(
"%1<Program number=\"%2\" pid=\"0x%3\" %4/>\n")
874 .arg(dummy ?
"comment=\"Dummy Program\" " :
"");
877 return str + indent_0 +
"</ProgramAssociationSection>";
883 QString(
"Program Map Section"
885 " pnum(%2) pid(0x%3) pcrpid(0x%4)")
891 std::vector<const unsigned char*> desc =
893 for (
auto &
d : desc)
895 str.append(QString(
"\n %1")
901 str.append(QString(
"\n Stream #%1 pid(0x%2) type(0x%3 %4)")
906 for (
auto &
d : desc)
908 str.append(QString(
"\n %1")
920 QString str = QString(
921 "%1<ProgramMapSection pcr_pid=\"0x%2\" program_number=\"%3\"\n"
922 "%4program_info_length=\"%5\" stream_count=\"%7\"%8>\n")
931 std::vector<const unsigned char*> gdesc =
933 for (
auto & gd : gdesc)
941 str += QString(
"%1<Stream pid=\"0x%2\" type=\"0x%3\" "
942 "type_desc=\"%4\" stream_info_length=\"%5\"")
948 std::vector<const unsigned char*> ldesc =
950 str += (ldesc.empty()) ?
" />\n" :
">\n";
951 for (
auto & ld : ldesc)
957 str += indent_1 +
"</Stream>\n";
960 return str + indent_0 +
"</ProgramMapSection>";
969 return "video-mpeg2";
971 return "video-mpeg1";
973 return "video-mpeg4";
979 return "video-opencable";
987 return "audio-mp2-layer[1,2,3]";
989 return "audio-mp1-layer[1,2,3]";
991 return "audio-aac-latm";
999 return "private-sec";
1001 return "private-data";
1005 return "dsmcc-a encap";
1007 return "dsmcc-b std data";
1009 return "dsmcc-c NPD data";
1011 return "dsmcc-d data";
1022 return "extended channel name";
1024 return "service location";
1026 return "time-shifted service";
1028 return "component name";
1040 return "11172-2 MPEG-1 Video";
1042 return "13818-2 MPEG-2 Video";
1044 return "14492-2 MPEG-4 Video";
1046 return "H.264 Video";
1048 return "H.265 Video";
1050 return "OpenCable Video";
1052 return "VC-1 Video";
1056 return "11172-2 MPEG-1 Audio";
1058 return "13818-3 MPEG-2 Audio";
1060 return "13818-7 AAC MPEG-2 Audio";
1062 return "13818-3 AAC LATM MPEG-2 Audio";
1066 return "E-AC3 Audio";
1072 return "13818-1 DSM-CC";
1074 return "13818-6 DSM-CC Type A";
1076 return "13818-6 DSM-CC Type B";
1078 return "13818-6 DSM-CC Type C";
1080 return "13818-6 DSM-CC Type D";
1082 return "13818-6 Download";
1084 return "13818-6 Metadata in PES";
1086 return "13818-6 Metadata in Sections";
1088 return "13818-6 Metadata in Data Carousel";
1090 return "13818-6 Metadata in Obj Carousel";
1092 return "13818-6 Metadata in Download";
1096 return "13818-1 Private Sections";
1098 return "13818-3 Private Data";
1100 return "13522 MHEG";
1102 return "ITU H.222.1";
1104 return "13818-1 Aux & ITU H.222.0";
1106 return "14496-1 SL/FlexMux in PES";
1108 return "14496-1 SL/FlexMux in Sections";
1110 return "13818-10 IPMP";
1112 return "13818-10 IPMP2";
1170 if (!lang.isEmpty())
1171 desc += QString(
" (%1)").arg(lang);
1179 QString(
"Conditional Access Section %1")
1182 std::vector<const unsigned char*> gdesc =
1184 for (
auto & gd : gdesc)
1195 QString(
"%1<ConditionalAccessSection %3")
1199 std::vector<const unsigned char*> gdesc =
1201 str += (gdesc.empty()) ?
" />\n" :
">\n";
1202 for (
auto & gd : gdesc)
1208 str += indent_0 +
"</ConditionalAccessSection>\n";
1216 return {
"splice_time(N/A)"};
1218 int64_t abs_pts_time =
PTSTime();
1219 if ((first > 0) && (last > 0))
1221 int64_t elapsed = abs_pts_time - first;
1222 elapsed = (elapsed < 0) ? elapsed + 0x1000000000LL : elapsed;
1223 QTime abs = QTime(0,0,0,0).addMSecs(elapsed/90);
1225 elapsed = abs_pts_time - last;
1226 elapsed = (elapsed < 0) ? elapsed + 0x1000000000LL : elapsed;
1227 QTime rel = QTime(0,0,0,0).addMSecs(elapsed/90);
1229 return QString(
"splice_time(pts: %1 abs: %2, rel: +%3)")
1230 .arg(QString::number(abs_pts_time),
1231 abs.toString(
"hh:mm:ss.zzz"),
1232 rel.toString(
"hh:mm:ss.zzz"));
1235 return QString(
"splice_time(pts: %1)").arg(abs_pts_time);
1239 uint indent_level, int64_t first, int64_t last)
const
1244 return indent +
"<SpliceTime />";
1246 int64_t abs_pts_time =
PTSTime();
1251 int64_t elapsed = abs_pts_time - first;
1252 elapsed = (elapsed < 0) ? elapsed + 0x1000000000LL : elapsed;
1253 QTime abs = QTime(0,0,0,0).addMSecs(elapsed/90);
1254 abs_str = QString(
"absolute=\"%1\" ")
1255 .arg(abs.toString(
"hh:mm:ss.zzz"));
1261 int64_t elapsed = abs_pts_time - last;
1262 elapsed = (elapsed < 0) ? elapsed + 0x1000000000LL : elapsed;
1263 QTime rel = QTime(0,0,0,0).addMSecs(elapsed/90);
1264 rel_str = QString(
"relative=\"+%1\" ")
1265 .arg(rel.toString(
"hh:mm:ss.zzz"));
1268 return QString(
"%1<SpliceTime pts=\"%2\" %3%4/>")
1269 .arg(
indent,QString::number(abs_pts_time),abs_str,rel_str);
1307 const unsigned char *cur =
pesdata() + 15;
1308 for (
uint i = 0; i < splice_count; i++)
1311 bool event_cancel = (cur[4] & 0x80) != 0;
1318 bool program_slice = (cur[5] & 0x40) != 0;
1319 uint component_count = cur[6];
1320 m_ptrs1.push_back(cur + (program_slice ? 10 : 7 * component_count));
1324 bool duration = (
m_ptrs0.back()[5] & 0x2) != 0;
1335 bool splice_cancel = (
pesdata()[18] & 0x80) != 0;
1342 bool program_splice = (
pesdata()[19] & 0x40) != 0;
1343 bool duration = (
pesdata()[19] & 0x20) != 0;
1344 bool splice_immediate = (
pesdata()[19] & 0x10) != 0;
1345 const unsigned char *cur =
pesdata() + 20;
1346 if (program_splice && !splice_immediate)
1350 else if (!program_splice)
1354 for (
uint i = 0; i < component_count; i++)
1357 cur += (splice_immediate) ?
1362 m_ptrs1.push_back(cur + (duration ? 5 : 0));
1379 case kECB:
return "DES-ECB";
1380 case kCBC:
return "DES-CBC";
1381 case k3DES:
return "3DES";
1383 return QString((alg<32) ?
"Reserved(%1)" :
"Private(%1)").arg(alg);
1395 return "SpliceSchedule";
1397 return "SpliceInsert";
1399 return "TimeSignal";
1401 return "BandwidthReservation";
1405 return QString(
"Reserved(%1)").arg(
type);
1412 QString(
"SpliceInformationSection enc_alg(%1) pts_adj(%2)")
1416 str += QString(
" command_len(%1) command_type(%2) scte_pid(0x%3)")
1443 QString(
"eventid(0x%1) cancel(%2) "
1444 "out_of_network(%3) program_splice(%4) "
1445 "duration(%5) immediate(%6)\n ")
1456 str += QString(
" unique_program_id(%1)")
1459 str += QString(
" avail(%1/%2)")
1466 uint indent_level, int64_t first, int64_t last)
const
1470 QString cap_time =
"";
1473 cap_time = QString(
"pts=\"%1\" ").arg(first);
1476 QTime abs = QTime(0,0,0,0).addMSecs((last - first)/90);
1477 cap_time += QString(
"capture_time=\"%1\" ")
1478 .arg(abs.toString(
"hh:mm:ss.zzz"));
1482 QString str = QString(
1483 "%1<SpliceInformationSection %2 encryption_algorithm=\"%3\" "
1484 "pts_adjustment=\"%4\" code_word_index=\"%5\" command_type=\"%6\" scte_pid=\"0x%7\" >\n")
1494 return str +
indent +
"</SpliceInformationSection>";
1510 str +=
indent +
"</SpliceInformationSection>";
1515 uint indent_level, int64_t first, int64_t last)
const
1519 QString str = QString(
1520 "%1<SpliceInsert eventid=\"0x%2\" cancel=\"%3\"\n")
1526 "%1out_of_network=\"%2\" program_splice=\"%3\" duration=\"%4\"\n")
1533 "%1immediate=\"%2\" unique_program_id=\"%3\"\n"
1534 "%4avail_num=\"%5\" avails_expected=\"%6\">\n")
1547 str += indent_0 +
"</SpliceInsert>";
const unsigned char * ProgramInfo(void) const
virtual QString toString(void) const
unsigned char * m_pesData
Pointer to PES data in full buffer.
QString toStringXML(uint indent_level) const override
static const std::array< const uint, 4 > len_for_alloc
@ DSMCC_B
ISO 13818-6 type B Std DSMCC Data.
uint ProgramPID(uint i) const
uint UniqueProgramID(void) const
virtual QString toStringXML(uint indent_level, int64_t first, int64_t last) const
@ DSMCC_A
ISO 13818-6 type A Multi-protocol Encap.
QString CanonicalLanguageString(void) const
@ OpenCableVideo
Always MPEG-2??
uint StreamCount(void) const
SpliceTimeView SpliceTime(void) const
static const uint kPmtHeaderMinOffset
@ DSMCC_C
ISO 13818-6 type C NPT DSMCC Data.
const unsigned char * Descriptors(void) const
bool IsCurrent(void) const
void SetTotalLength(uint len)
void SetProgramInfo(unsigned char *streamInfo, uint infoLength)
const unsigned char * StreamInfo(uint i) const
void SetTranportStreamID(uint gtsid)
const unsigned char * pesdata() const
A PMT table maps a program described in the ProgramAssociationTable to various PID's which describe t...
@ MPEG2AudioAmd1
ISO 13818-3/AMD-1 Audio using LATM syntax.
const TSHeader * tsheader() const
int FindPID(uint pid) const
Locates stream index of pid.
@ FlexMuxPES
ISO 14496-1 SL/FlexMux in PES packets.
uint PCRPID(void) const
stream that contains program clock reference.
bool IsVideo(uint i, const QString &sistandard) const
Returns true iff the stream at index i is a video stream.
uint m_allocSize
Total number of bytes we allocated.
static ProgramMapTable * CreateBlank(bool smallPacket=true)
static const struct wl_interface * types[]
uint ProgramNumber(void) const
QString indentSpaces(unsigned int level, unsigned int size=4)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
@ MPEG2Aux
ISO 13818-1 auxiliary & ITU H.222.0.
uint ProgramCount(void) const
uint ATSCProtocolVersion(void) const
void SetVersionNumber(uint ver)
bool IsEncrypted(const QString &sistandard) const
Returns true iff PMT contains CA descriptor for a vid/aud stream.
@ MetaDataPES
Meta data in PES packets.
@ MetaDataDL
ISO 13818-6 Metadata in Download Protocol.
static const uint kPsipOffset
QString StreamTypeString(uint i) const
Returns a string representation of type at stream index i.
QString FormatIdentifierString(void) const
static bool IsVideo(uint type)
Returns true iff video is an MPEG1/2/3, H264 or open cable video stream.
uint DescriptorsLength(void) const
@ Splice
ANSI/SCTE 35 2007.
@ MPEG_NULL_PID
The all-ones PID value 0x1FFF indicates a Null TS Packet introduced to maintain a constant bit rate o...
uint SpliceEventID(void) const
A PSIP table is a variant of a PES packet containing an MPEG, ATSC or DVB table.
static QString GetDescription(uint stream_id)
@ MPEG2AACAudio
ISO 13818-7 Audio w/ADTS syntax.
virtual QString toString(void) const
bool IsStreamEncrypted(uint pid) const
Returns true iff PMT contains CA descriptor.
@ MPEG2IPMP2
ISO 13818-10 Digital Restrictions Mangment.
void RemoveAllStreams(void)
QString StreamDescription(uint i, const QString &sistandard) const
Returns a better (and more expensive) string representation of type at stream index i than StreamType...
@ PrivSec
ISO 13818-1 private tables & ITU H.222.0.
bool IsSpliceImmediate(void) const
virtual QString toStringXML(uint indent_level) const
Returns XML representation of string the TS Reader XML format.
uint TransportStreamID(void) const
uint ProgramNumber(uint i) const
static desc_list_t Parse(const unsigned char *data, uint len)
@ VC1Video
SMPTE 421M video codec (aka VC1) in Blu-Ray.
QString toString(void) const override
MBASE_PUBLIC long long copy(QFile &dst, QFile &src, uint block_size=0)
Copies src file to dst file.
uint SystemID(void) const
bool HasSectionNumber(void) const
static bool IsAudio(uint type)
Returns true iff audio is MPEG1/2, AAC, AC3 or DTS audio stream.
@ DSMCC_D
ISO 13818-6 type D Any DSMCC Data.
Used to access the data of a Transport Stream packet.
uint StreamType(uint i) const
QString toString(void) const override
std::vector< const unsigned char * > desc_list_t
static desc_list_t ParseOnlyInclude(const unsigned char *data, uint len, int excluded_descid)
uint FindUnusedPID(uint desired_pid=0x20) const
QString toString(void) const override
static ProgramAssociationTable * CreateBlank(bool smallPacket=true)
uint AvailsExpected(void) const
virtual QString toStringXML(uint indent_level) const
bool IsOutOfNetwork(void) const
@ DSMCC_DL
ISO 13818-6 Download Protocol.
@ H264Video
ISO 14492-10 & ITU H.264 (aka MPEG-4-AVC)
@ MetaDataSec
Meta data in metadata_section's.
@ H265Video
ISO 23008-2 & ITU H.265 (aka HEVC, Ultra HD)
bool IsStillPicture(const QString &sistandard) const
Returns true iff PMT contains a still-picture video stream.
void SetStreamPID(uint i, uint pid)
Contains Packet Identifier numeric values.
@ PrivData
ISO 13818-1 PES private data & ITU H.222.0.
@ DSMCC
ISO 13818-1 Annex A DSM-CC & ITU H.222.0.
The Program Association Table lists all the programs in a stream, and is always found on PID 0.
@ MPEG4Video
ISO 14492-2 (aka MPEG-4)
@ MetaDataDC
ISO 13818-6 Metadata in Data Carousel.
static TSPacket * CreatePayloadOnlyPacket(void)
uint LastSection(void) const
uint FindPIDs(uint type, std::vector< uint > &pids, const QString &sistandard) const
Finds all pids matching type.
bool HasCRC(void) const override
1 bit Cyclic Redundancy Check present
bool IsSpliceEventCancel(void) const
bool IsAudio(uint i, const QString &sistandard) const
Returns true iff the stream at index i is an audio stream.
static constexpr unsigned int kPayloadSize
static ProgramMapTable * Create(uint programNumber, uint basepid, uint pcrpid, uint version, std::vector< uint > pids, std::vector< uint > types)
QString LanguageString(void) const
void AppendStream(uint pid, uint type, unsigned char *streamInfo=nullptr, uint infoLength=0)
void SetStreamProgramInfo(uint i, unsigned char *streamInfo, uint infoLength)
@ MetaDataOC
ISO 13818-6 Metadata in Object Carousel.
bool VerifyPSIP(bool verify_crc) const
uint SectionLength(void) const
uint ProgramInfoLength(void) const
@ FlexMuxSec
ISO 14496-1 SL/FlexMux in 14496_sections.
static PSIPTable View(const TSPacket &tspacket)
bool IsProgramSplice(void) const
void SetProgramNumber(uint num)
virtual QString toStringXML(uint indent_level, int64_t first, int64_t last) const
static const char * toString(uint streamID)
ProgramAssociationTable(const ProgramAssociationTable &table)
@ AC3Audio
A/53 Part 3:2009 6.7.1.
uint AvailNum(void) const
uint TableIDExtension(void) const
const std::array< const uint8_t, 8 > DEFAULT_PAT_HEADER
uint64_t PTSTime(void) const
QString toStringXML(uint indent_level) const override
virtual QString toString(int64_t first, int64_t last) const
static ProgramAssociationTable * Create(uint tsid, uint version, const std::vector< uint > &pnum, const std::vector< uint > &pid)
@ MPEG2Video
ISO 13818-2 & ITU H.262 (aka MPEG-2)
void SetStreamType(uint i, uint type)
QString toString() const override
QString XMLValues(uint indent_level) const
unsigned char * m_fullBuffer
Pointer to allocated data.
uint GetAudioType(uint i) const
Returns the audio type from the iso 639 descriptor.
static const iso6937table * d
std::vector< unsigned char * > m_ptrs
QString toStringXML(uint indent_level) const override
uint StreamInfoLength(uint i) const
static uint Normalize(uint stream_id, const desc_list_t &desc, const QString &sistandard)
static const unsigned char * Find(const desc_list_t &parsed, uint desc_tag)
QString GetLanguage(uint i) const
Returns the canonical language if we find the iso639 descriptor.
static QString indent(uint level)
bool IsTimeSpecified(void) const
@ MPEG1Video
ISO 11172-2 (aka MPEG-1)
QString bool_to_string(bool val)
This is equivalent to QVariant(bool).toString()
bool IsProgramEncrypted(void) const
Returns true iff PMT's ProgramInfo contains CA descriptor.
bool IsDuration(void) const
uint StreamPID(uint i) const
virtual QString toString(int64_t first, int64_t last) const
ProgramMapTable(const ProgramMapTable &table)
@ EAC3Audio
A/53 Part 3:2009 6.7.3.
const std::array< const uint8_t, 12 > DEFAULT_PMT_HEADER
@ MPEG2IPMP
ISO 13818-10 Digital Restrictions Mangment.
const unsigned char * psipdata(void) const