Go to the documentation of this file.
37 static QHash<uint,bool>
extract_pids(
const QString &pidsStr,
bool required)
39 QHash<uint,bool> use_pid;
40 if (pidsStr.isEmpty())
43 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
"Missing --pids option\n");
47 QStringList pidsList = pidsStr.split(
",");
48 for (
const QString &pidStr : qAsConst(pidsList))
51 uint tmp = pidStr.toUInt(&ok, 0);
52 if (ok && (
tmp < 0x2000))
55 if (required && use_pid.empty())
57 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
58 "At least one pid must be specified\n");
65 const char *buffer,
int curr_pos,
int len,
int packet_size)
69 int nextpos = pos + packet_size;
88 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
"Missing --infile option\n");
96 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
"Couldn't open input URL\n");
101 if (packet_size == 0)
105 else if (packet_size != 188 &&
106 packet_size != (188+16) &&
107 packet_size != (188+20))
109 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
110 QString(
"Invalid packet size %1, must be 188, 204, or 208\n")
115 const int kBufSize = 2 * 1024 * 1024;
116 std::array<uint64_t,0x2000> pid_count {};
117 char *buffer =
new char[kBufSize];
119 long long total_count = 0;
123 int r = srcbuffer->
Read(&buffer[offset], kBufSize - offset);
127 int len = offset + r;
128 while (pos + 187 < len)
138 int pid = ((buffer[pos+1]<<8) | buffer[pos+2]) & 0x1fff;
146 memcpy(buffer, buffer + pos, len - pos);
155 "Processed %1 packets")
163 for (
uint i = 0; i < 0x2000; i++)
167 LOG(VB_STDIO|VB_FLUSH, LOG_CRIT,
168 QString(
"PID 0x%1 -- %2\n")
169 .arg(i,4,16,QChar(
'0'))
170 .arg(pid_count[i],11));
181 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
"Missing --infile option\n");
188 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
"Missing --outfile option\n");
194 if (packet_size == 0)
198 else if (packet_size != 188 &&
199 packet_size != (188+16) &&
200 packet_size != (188+20))
202 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
203 QString(
"Invalid packet size %1, must be 188, 204, or 208\n")
215 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
"Couldn't open input URL\n");
222 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
"Couldn't open output URL\n");
227 const int kBufSize = 2 * 1024 * 1024;
228 char *buffer =
new char[kBufSize];
230 long long total_count = 0;
231 long long write_count = 0;
235 int r = srcbuffer->
Read(&buffer[offset], kBufSize - offset);
239 int len = offset + r;
240 while (pos + 187 < len)
250 int pid = ((buffer[pos+1]<<8) | buffer[pos+2]) & 0x1fff;
253 destRB->
Write(buffer+pos, packet_size);
262 memcpy(buffer, buffer + pos, len - pos);
271 "Processed %1 packets")
280 LOG(VB_STDIO|VB_FLUSH,
logLevel, QString(
"Wrote %1 of %2 packets\n")
281 .arg(write_count).arg(total_count));
306 uint32_t pts_count = 0;
319 uint32_t pts_count = 0;
332 return (elapsed < 0) ? elapsed + 0x1000000000LL : elapsed;
357 const uint8_t *bufptr = tspacket.
data() + tspacket.
AFCOffset();
360 while (bufptr < bufend)
362 bufptr = avpriv_find_start_code(bufptr, bufend, &
m_startCode);
363 int bytes_left = bufend - bufptr;
369 if ((stream_id < 0xc0) || (stream_id > 0xef) ||
374 bool has_pts = (bufptr[3] & 0x80) != 0;
375 if (has_pts && (bytes_left > 5+5))
379 (uint64_t(bufptr[i+0] & 0x0e) << 29) |
380 (uint64_t(bufptr[i+1] ) << 22) |
381 (uint64_t(bufptr[i+2] & 0xfe) << 14) |
382 (uint64_t(bufptr[i+3] ) << 7) |
383 (uint64_t(bufptr[i+4] & 0xfe) >> 1);
412 QByteArray ba = msg.toUtf8();
438 MPEGStreamData *sd,
const QHash<uint,bool> &use_pid,
bool use_xml) :
452 for (
uint i = 0; i < pat->ProgramCount(); i++)
471 for (
uint i = 0; i < pmt->StreamCount(); i++)
473 if (pmt->IsVideo(i,
"mpeg"))
474 video_pid = pmt->StreamPID(i);
475 else if (pmt->IsAudio(i,
"mpeg"))
476 audio_pid = pmt->StreamPID(i);
484 LOG(VB_STDIO|VB_FLUSH, LOG_WARNING,
485 "Couldn't find PTS stream\n");
505 ot.toString(
"hh:mm:ss.zzz") +
" " +
630 Output(QString(
"EIT PID 0x%1\n").arg(pid,0,16) + eit->toString());
636 Output(QString(
"ETT PID 0x%1\n").arg(pid,0,16) + ett->toString());
710 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
"Missing --infile option\n");
718 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
"Couldn't open input URL\n");
726 QHash<uint,bool> use_pid_for_pts =
736 LOG(VB_STDIO|VB_FLUSH, LOG_ERR,
"Couldn't open output URL\n");
746 for (QHash<uint,bool>::iterator it = use_pid.begin();
747 it != use_pid.end(); ++it)
749 sd->AddListeningPID(it.key());
752 for (QHash<uint,bool>::iterator it = use_pid_for_pts.begin();
753 it != use_pid_for_pts.end(); ++it)
755 sd->AddWritingPID(it.key());
769 sd->AddWritingListener(ptsl);
770 sd->AddMPEGListener(pmsl);
771 sd->AddATSCMainListener(pasl);
772 sd->AddSCTEMainListener(pssl);
773 sd->AddATSCAuxListener(paasl);
774 sd->AddATSCEITListener(paesl);
775 sd->AddDVBMainListener(pdmsl);
776 sd->AddDVBOtherListener(pdosl);
777 sd->AddDVBEITListener(pdesl);
779 const int kBufSize = 2 * 1024 * 1024;
780 char *buffer =
new char[kBufSize];
782 uint64_t totalBytes = 0ULL;
786 pmsl->Output(QString(R
"(<?xml version="1.0" encoding="UTF-8" ?>)"));
787 pmsl->Output(QString("<MPEGSections>"));
792 int r = srcRB->
Read(&buffer[offset], kBufSize - offset);
796 int len = offset + r;
798 offset = sd->ProcessData((
const unsigned char*)buffer, len);
800 totalBytes += len - offset;
803 "Processed %1 bytes")
809 pmsl->Output(QString(
"</MPEGSections>"));
814 if (ptsl->GetFirstPTS() >= 0)
816 QTime ot = QTime(0,0,0,0).addMSecs(ptsl->GetElapsedPTS()/90);
819 QString(
"First PTS %1, Last PTS %2, elapsed %3 %4\n")
820 .arg(ptsl->GetFirstPTS()).arg(ptsl->GetLastPTS())
821 .arg(ptsl->GetElapsedPTS())
822 .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
#define GENERIC_EXIT_OK
Exited with no error.
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...
#define GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
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
void HandleRRT(const RatingRegionTable *rrt) override
void HandleCAT(const ConditionalAccessTable *cat) override
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 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.
#define GENERIC_EXIT_NOT_OK
Exited with error.
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
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)
PrintATSCMainStreamListener(MythMediaBuffer *out, bool use_xml)
void HandleADET(const AggregateDataEventTable *adet) override
void HandleEIT(const PremiereContentInformationTable *pcit) override
QMap< uint, uint > m_ptsStreams
void HandlePAT(const ProgramAssociationTable *pat) override
static constexpr unsigned int kSize
bool ProcessVideoTSPacket(const TSPacket &tspacket) override