39static QHash<uint,bool>
extract_pids(
const QString &pidsStr,
bool required)
41 QHash<uint,bool> use_pid;
42 if (pidsStr.isEmpty())
45 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
"Missing --pids option\n");
49 QStringList pidsList = pidsStr.split(
",");
50 for (
const QString &pidStr : std::as_const(pidsList))
53 uint tmp = pidStr.toUInt(&ok, 0);
54 if (ok && (
tmp < 0x2000))
57 if (required && use_pid.empty())
59 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
60 "At least one pid must be specified\n");
67 const char *buffer,
int curr_pos,
int len,
int packet_size)
71 int nextpos = pos + packet_size;
90 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
"Missing --infile option\n");
98 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
"Couldn't open input URL\n");
103 if (packet_size == 0)
107 else if (packet_size != 188 &&
108 packet_size != (188+16) &&
109 packet_size != (188+20))
111 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
112 QString(
"Invalid packet size %1, must be 188, 204, or 208\n")
117 const int kBufSize = 2 * 1024 * 1024;
118 std::array<uint64_t,0x2000> pid_count {};
119 char *buffer =
new char[kBufSize];
121 long long total_count = 0;
125 int r = srcbuffer->
Read(&buffer[offset], kBufSize - offset);
129 int len = offset + r;
130 while (pos + 187 < len)
140 int pid = ((buffer[pos+1]<<8) | buffer[pos+2]) & 0x1fff;
148 memcpy(buffer, buffer + pos, len - pos);
157 "Processed %1 packets")
165 for (
uint i = 0; i < 0x2000; i++)
169 LOG(VB_STDIO|VB_FLUSH, LOG_CRIT,
170 QString(
"PID 0x%1 -- %2\n")
171 .arg(i,4,16,QChar(
'0'))
172 .arg(pid_count[i],11));
183 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
"Missing --infile option\n");
190 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
"Missing --outfile option\n");
196 if (packet_size == 0)
200 else if (packet_size != 188 &&
201 packet_size != (188+16) &&
202 packet_size != (188+20))
204 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
205 QString(
"Invalid packet size %1, must be 188, 204, or 208\n")
217 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
"Couldn't open input URL\n");
224 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
"Couldn't open output URL\n");
229 const int kBufSize = 2 * 1024 * 1024;
230 char *buffer =
new char[kBufSize];
232 long long total_count = 0;
233 long long write_count = 0;
237 int r = srcbuffer->
Read(&buffer[offset], kBufSize - offset);
241 int len = offset + r;
242 while (pos + 187 < len)
252 int pid = ((buffer[pos+1]<<8) | buffer[pos+2]) & 0x1fff;
255 destRB->
Write(buffer+pos, packet_size);
264 memcpy(buffer, buffer + pos, len - pos);
273 "Processed %1 packets")
282 LOG(VB_STDIO|VB_FLUSH,
logLevel, QString(
"Wrote %1 of %2 packets\n")
283 .arg(write_count).arg(total_count));
308 uint32_t pts_count = 0;
321 uint32_t pts_count = 0;
334 return (elapsed < 0) ? elapsed + 0x1000000000LL : elapsed;
359 const uint8_t *bufptr = tspacket.
data() + tspacket.
AFCOffset();
362 while (bufptr < bufend)
365 int bytes_left = bufend - bufptr;
371 if ((stream_id < 0xc0) || (stream_id > 0xef) ||
376 bool has_pts = (bufptr[3] & 0x80) != 0;
377 if (has_pts && (bytes_left > 5+5))
381 (uint64_t(bufptr[i+0] & 0x0e) << 29) |
382 (uint64_t(bufptr[i+1] ) << 22) |
383 (uint64_t(bufptr[i+2] & 0xfe) << 14) |
384 (uint64_t(bufptr[i+3] ) << 7) |
385 (uint64_t(bufptr[i+4] & 0xfe) >> 1);
414 QByteArray ba = msg.toUtf8();
440 MPEGStreamData *sd,
const QHash<uint,bool> &use_pid,
bool use_xml) :
454 for (
uint i = 0; i < pat->ProgramCount(); i++)
473 for (
uint i = 0; i < pmt->StreamCount(); i++)
475 if (pmt->IsVideo(i,
"mpeg"))
476 video_pid = pmt->StreamPID(i);
477 else if (pmt->IsAudio(i,
"mpeg"))
478 audio_pid = pmt->StreamPID(i);
486 LOG(VB_STDIO|VB_FLUSH, LOG_WARNING,
487 "Couldn't find PTS stream\n");
507 ot.toString(
"hh:mm:ss.zzz") +
" " +
632 Output(QString(
"EIT PID 0x%1\n").arg(pid,0,16) + eit->toString());
638 Output(QString(
"ETT PID 0x%1\n").arg(pid,0,16) + ett->toString());
712 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
"Missing --infile option\n");
720 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
"Couldn't open input URL\n");
728 QHash<uint,bool> use_pid_for_pts =
738 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
"Couldn't open output URL\n");
748 for (QHash<uint,bool>::iterator it = use_pid.begin();
749 it != use_pid.end(); ++it)
751 sd->AddListeningPID(it.key());
754 for (QHash<uint,bool>::iterator it = use_pid_for_pts.begin();
755 it != use_pid_for_pts.end(); ++it)
757 sd->AddWritingPID(it.key());
771 sd->AddWritingListener(ptsl);
772 sd->AddMPEGListener(pmsl);
773 sd->AddATSCMainListener(pasl);
774 sd->AddSCTEMainListener(pssl);
775 sd->AddATSCAuxListener(paasl);
776 sd->AddATSCEITListener(paesl);
777 sd->AddDVBMainListener(pdmsl);
778 sd->AddDVBOtherListener(pdosl);
779 sd->AddDVBEITListener(pdesl);
781 const int kBufSize = 2 * 1024 * 1024;
782 char *buffer =
new char[kBufSize];
784 uint64_t totalBytes = 0ULL;
788 pmsl->Output(QString(R
"(<?xml version="1.0" encoding="UTF-8" ?>)"));
789 pmsl->Output(QString("<MPEGSections>"));
794 int r = srcRB->
Read(&buffer[offset], kBufSize - offset);
798 int len = offset + r;
800 offset = sd->ProcessData((
const unsigned char*)buffer, len);
802 totalBytes += len - offset;
805 "Processed %1 bytes")
811 pmsl->Output(QString(
"</MPEGSections>"));
816 if (ptsl->GetFirstPTS() >= 0)
818 QTime ot = QTime(0,0,0,0).addMSecs(ptsl->GetElapsedPTS()/90);
821 QString(
"First PTS %1, Last PTS %2, elapsed %3 %4\n")
822 .arg(ptsl->GetFirstPTS()).arg(ptsl->GetLastPTS())
823 .arg(ptsl->GetElapsedPTS())
824 .arg(ot.toString(
"hh:mm:ss.zzz")));
This is in libmythtv because that is where the parsers, which are its main users, are.
Tells what channels can be found on each transponder for one bouquet (a bunch of channels from one pr...
This table contains information about the cable channels transmitted on this multiplex.
The CAT is used to transmit additional ConditionalAccessDescriptor instances, in addition to the ones...
No one has had time to decode this table yet...
No one has had time to decode this table yet...
ExtendedTextTable contain additional text not contained in EventInformationTables.
Encapsulates data about MPEG stream and emits events for each table.
virtual void AddWritingPID(uint pid, PIDPriority priority=kPIDPriorityHigh)
virtual void AddListeningPID(uint pid, PIDPriority priority=kPIDPriorityNormal)
This table tells the decoder on which PIDs to find other tables, and their sizes and each table's cur...
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
QString toString(const QString &key) const
Returns stored QVariant as a QString, falling to default if not provided.
uint toUInt(const QString &key) const
Returns stored QVariant as an unsigned integer, falling to default if not provided.
A PSIP table is a variant of a PES packet containing an MPEG, ATSC or DVB table.
virtual QString toStringXML(uint indent_level) const
virtual QString toString(void) const
int64_t GetLastPTS(void) const
int64_t GetFirstPTS(void) const
std::array< int64_t, 256 > m_ptsFirst
QMap< uint, uint > m_ptsStreams
std::array< uint32_t, 256 > m_ptsCount
std::array< int64_t, 256 > m_ptsLast
bool ProcessAudioTSPacket(const TSPacket &tspacket) override
int64_t GetElapsedPTS(void) const
bool ProcessTSPacket(const TSPacket &tspacket) override
bool ProcessVideoTSPacket(const TSPacket &tspacket) override
void HandleDCCT(const DirectedChannelChangeTable *dcct) override
void HandleCVCT(uint, const CableVirtualChannelTable *) override
void HandleRRT(const RatingRegionTable *rrt) override
void HandleTVCT(uint, const TerrestrialVirtualChannelTable *) override
PrintATSCAuxStreamListener(MythMediaBuffer *out, bool use_xml)
void HandleDCCSCT(const DirectedChannelChangeSelectionCodeTable *dccsct) override
void HandleETT(uint pid, const ExtendedTextTable *ett) override
PrintATSCEITStreamListener(MythMediaBuffer *out, bool use_xml)
void HandleEIT(uint pid, const EventInformationTable *eit) override
void HandleSTT(const SystemTimeTable *stt) override
void HandleVCT(uint, const VirtualChannelTable *vct) override
PrintATSCMainStreamListener(MythMediaBuffer *out, bool use_xml)
void HandleMGT(const MasterGuideTable *mgt) override
void HandleEIT(const DVBEventInformationTable *eit) override
void HandleEIT(const PremiereContentInformationTable *pcit) override
PrintDVBEITStreamListener(MythMediaBuffer *out, bool use_xml)
PrintDVBMainStreamListener(MythMediaBuffer *out, bool use_xml)
void HandleTDT(const TimeDateTable *tdt) override
void HandleSDT(uint, const ServiceDescriptionTable *sdt) override
void HandleNIT(const NetworkInformationTable *nit) override
void HandleSDTo(uint, const ServiceDescriptionTable *sdt) override
void HandleNITo(const NetworkInformationTable *nit) override
PrintDVBOtherStreamListener(MythMediaBuffer *out, bool use_xml)
void HandleBAT(const BouquetAssociationTable *bat) override
void HandleEncryptionStatus(uint, bool) override
PrintMPEGStreamListener(MythMediaBuffer *out, PTSListener &ptsl, bool autopts, MPEGStreamData *sd, const QHash< uint, bool > &use_pid, bool use_xml)
void HandlePMT(uint, const ProgramMapTable *pmt) override
void HandleCAT(const ConditionalAccessTable *cat) override
const PTSListener & m_ptsl
void HandlePAT(const ProgramAssociationTable *pat) override
const QHash< uint, bool > & m_usePid
void HandleSplice(const SpliceInformationTable *sit) override
PrintOutput(MythMediaBuffer *out, bool use_xml)
void Output(const PSIPTable *psip) const
void Output(const QString &msg) const
void HandlePNM(const ProgramNameMessageTable *pnm) override
void HandleSTT(const SCTESystemTimeTable *stt) override
void HandleNTT(const NetworkTextTable *ntt) override
void HandleNIT(const SCTENetworkInformationTable *nit) override
void HandleSVCT(const ShortVirtualChannelTable *svct) override
void HandlePIM(const ProgramInformationMessageTable *pim) override
void HandleADET(const AggregateDataEventTable *adet) override
PrintSCTEMainStreamListener(MythMediaBuffer *out, bool use_xml)
The Program Association Table lists all the programs in a stream, and is always found on PID 0.
A PMT table maps a program described in the ProgramAssociationTable to various PID's which describe t...
No one has had time to decode this table yet...
This table tells the decoder on which PIDs to find A/V data.
Used to access the data of a Transport Stream packet.
unsigned int AFCOffset(void) const
static constexpr unsigned int kSize
This table contains information about the terrestrial channels transmitted on this multiplex.
This table gives the current DVB stream time.
This table contains information about the channels transmitted on this multiplex.
@ GENERIC_EXIT_OK
Exited with no error.
@ GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
@ GENERIC_EXIT_NOT_OK
Exited with error.
void registerMPEGUtils(UtilMap &utilMap)
static QHash< uint, bool > extract_pids(const QString &pidsStr, bool required)
MPEG-TS processing utilities (for debugging.) Copyright (c) 2003-2004, Daniel Thor Kristjansson Copyr...
static int resync_stream(const char *buffer, int curr_pos, int len, int packet_size)
static int pid_filter(const MythUtilCommandLineParser &cmdline)
static int pid_printer(const MythUtilCommandLineParser &cmdline)
static int pid_counter(const MythUtilCommandLineParser &cmdline)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
QMap< QString, UtilFunc > UtilMap
bool start_code_is_valid(uint32_t start_code)
Test whether a start code found by find_start_code() is valid.
MTV_PUBLIC const uint8_t * find_start_code_truncated(const uint8_t *p, const uint8_t *end, uint32_t *start_code)
By preserving the start_code value between subsequent calls, the caller can detect start codes across...
MythCommFlagCommandLineParser cmdline
std::chrono::duration< CHRONO_TYPE, std::ratio< 1, 90000 > > pts
static constexpr uint8_t SYNC_BYTE