Go to the documentation of this file.
39 static 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")));
PrintDVBOtherStreamListener(MythMediaBuffer *out, bool use_xml)
void HandleSVCT(const ShortVirtualChannelTable *svct) override
This table contains information about the channels transmitted on this multiplex.
const QHash< uint, bool > & m_usePid
void HandleNIT(const NetworkInformationTable *nit) override
void HandleSTT(const SCTESystemTimeTable *stt) override
void HandleTDT(const TimeDateTable *tdt) override
PrintOutput(MythMediaBuffer *out, bool use_xml)
No one has had time to decode this table yet...
This table gives the current DVB stream time.
void HandleCVCT(uint, const CableVirtualChannelTable *) override
MythCommFlagCommandLineParser cmdline
bool ProcessAudioTSPacket(const TSPacket &tspacket) override
No one has had time to decode this table yet...
void HandleNITo(const NetworkInformationTable *nit) override
void HandleSplice(const SpliceInformationTable *sit) override
void HandleNTT(const NetworkTextTable *ntt) override
void HandleBAT(const BouquetAssociationTable *bat) override
std::array< int64_t, 256 > m_ptsFirst
static int resync_stream(const char *buffer, int curr_pos, int len, int packet_size)
A PMT table maps a program described in the ProgramAssociationTable to various PID's which describe t...
unsigned int AFCOffset(void) const
void HandleEIT(const DVBEventInformationTable *eit) override
std::array< int64_t, 256 > m_ptsLast
void HandleEIT(uint pid, const EventInformationTable *eit) override
void HandleSDT(uint, const ServiceDescriptionTable *sdt) override
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
int64_t GetLastPTS(void) const
No one has had time to decode this table yet...
PrintMPEGStreamListener(MythMediaBuffer *out, PTSListener &ptsl, bool autopts, MPEGStreamData *sd, const QHash< uint, bool > &use_pid, bool use_xml)
void HandleSDTo(uint, const ServiceDescriptionTable *sdt) override
void HandleDCCT(const DirectedChannelChangeTable *dcct) override
void Output(const PSIPTable *psip) const
PrintATSCAuxStreamListener(MythMediaBuffer *out, bool use_xml)
A PSIP table is a variant of a PES packet containing an MPEG, ATSC or DVB table.
virtual QString toString(void) const
void HandlePMT(uint, const ProgramMapTable *pmt) override
@ GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
void HandleRRT(const RatingRegionTable *rrt) override
void HandleCAT(const ConditionalAccessTable *cat) override
@ GENERIC_EXIT_OK
Exited with no error.
Used to access the data of a Transport Stream packet.
Encapsulates data about MPEG stream and emits events for each table.
This table tells the decoder on which PIDs to find A/V data.
PrintDVBMainStreamListener(MythMediaBuffer *out, bool use_xml)
void HandleTVCT(uint, const TerrestrialVirtualChannelTable *) override
virtual QString toStringXML(uint indent_level) const
uint toUInt(const QString &key) const
Returns stored QVariant as an unsigned integer, falling to default if not provided.
void HandleMGT(const MasterGuideTable *mgt) override
PrintSCTEMainStreamListener(MythMediaBuffer *out, bool use_xml)
PrintATSCEITStreamListener(MythMediaBuffer *out, bool use_xml)
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...
int64_t GetFirstPTS(void) const
The Program Association Table lists all the programs in a stream, and is always found on PID 0.
void HandleETT(uint pid, const ExtendedTextTable *ett) override
void HandleSTT(const SystemTimeTable *stt) override
bool start_code_is_valid(uint32_t start_code)
Test whether a start code found by find_start_code() is valid.
bool ProcessTSPacket(const TSPacket &tspacket) override
void HandleDCCSCT(const DirectedChannelChangeSelectionCodeTable *dccsct) override
void registerMPEGUtils(UtilMap &utilMap)
const PTSListener & m_ptsl
This table tells the decoder on which PIDs to find other tables, and their sizes and each table's cur...
Tells what channels can be found on each transponder for one bouquet (a bunch of channels from one pr...
virtual void AddWritingPID(uint pid, PIDPriority priority=kPIDPriorityHigh)
int64_t GetElapsedPTS(void) const
QMap< QString, UtilFunc > UtilMap
QString toString(const QString &key) const
Returns stored QVariant as a QString, falling to default if not provided.
std::array< uint32_t, 256 > m_ptsCount
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
static int pid_counter(const MythUtilCommandLineParser &cmdline)
static int pid_printer(const MythUtilCommandLineParser &cmdline)
This table contains information about the terrestrial channels transmitted on this multiplex.
void HandlePNM(const ProgramNameMessageTable *pnm) override
The CAT is used to transmit additional ConditionalAccessDescriptor instances, in addition to the ones...
void Output(const QString &msg) const
void HandleNIT(const SCTENetworkInformationTable *nit) override
static int pid_filter(const MythUtilCommandLineParser &cmdline)
void HandlePIM(const ProgramInformationMessageTable *pim) override
@ GENERIC_EXIT_NOT_OK
Exited with error.
std::chrono::duration< CHRONO_TYPE, std::ratio< 1, 90000 > > pts
This table contains information about the cable channels transmitted on this multiplex.
void HandleEncryptionStatus(uint, bool) override
virtual void AddListeningPID(uint pid, PIDPriority priority=kPIDPriorityNormal)
void HandleVCT(uint, const VirtualChannelTable *vct) override
ExtendedTextTable contain additional text not contained in EventInformationTables.
PrintDVBEITStreamListener(MythMediaBuffer *out, bool use_xml)
static constexpr uint8_t SYNC_BYTE
PrintATSCMainStreamListener(MythMediaBuffer *out, bool use_xml)
void HandleADET(const AggregateDataEventTable *adet) override
void HandleEIT(const PremiereContentInformationTable *pcit) override
QMap< uint, uint > m_ptsStreams
const MTV_PUBLIC 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...
void HandlePAT(const ProgramAssociationTable *pat) override
static constexpr unsigned int kSize
bool ProcessVideoTSPacket(const TSPacket &tspacket) override