![]() |
TSDuck v3.46-4965
MPEG Transport Stream Toolkit
|
#include <tsTSPacket.h>
Public Types | |
| enum | { DUMP_RAW = 0x00010000 , DUMP_TS_HEADER = 0x00020000 , DUMP_PES_HEADER = 0x00040000 , DUMP_PAYLOAD = 0x00080000 , DUMP_AF = 0x00100000 } |
Public Member Functions | |
| void | clearDiscontinuityIndicator () |
| void | clearESPI () |
| void | clearPriority () |
| void | clearPUSI () |
| void | clearRandomAccessIndicator () |
| void | clearTEI () |
| void | copyFrom (const void *source) |
| void | copyTo (void *dest) const |
| std::ostream & | display (std::ostream &strm, uint32_t flags=0, size_t indent=0, size_t size=PKT_SIZE) const |
| size_t | getAFSize () const |
| size_t | getAFStuffingSize () const |
| uint8_t | getCC () const |
| bool | getDiscontinuityIndicator () const |
| uint64_t | getDTS () const |
| bool | getESPI () const |
| size_t | getHeaderSize () const |
| uint64_t | getOPCR () const |
| uint8_t * | getPayload () |
| const uint8_t * | getPayload () const |
| size_t | getPayloadSize () const |
| uint64_t | getPCR () const |
| size_t | getPESHeaderSize () const |
| bool | getPESHeaderStuffingArea (const uint8_t *&addr, size_t &pes_size, size_t &ts_size) const |
| bool | getPESHeaderStuffingArea (uint8_t *&addr, size_t &pes_size, size_t &ts_size) |
| PID | getPID () const |
| bool | getPriority () const |
| uint8_t * | getPrivateData () |
| const uint8_t * | getPrivateData () const |
| void | getPrivateData (ByteBlock &data) const |
| size_t | getPrivateDataSize () const |
| uint64_t | getPTS () const |
| bool | getPUSI () const |
| bool | getRandomAccessIndicator () const |
| uint8_t | getScrambling () const |
| int8_t | getSpliceCountdown () const |
| bool | getTEI () const |
| bool | hasAF () const |
| bool | hasDTS () const |
| bool | hasOPCR () const |
| bool | hasPayload () const |
| bool | hasPCR () const |
| bool | hasPrivateData () const |
| bool | hasPTS () const |
| bool | hasSpliceCountdown () const |
| bool | hasValidSync () const |
| void | init (PID pid=PID_NULL, uint8_t cc=0, uint8_t data=0xFF) |
| bool | isClear () const |
| bool | isDuplicate (const TSPacket &other) const |
| bool | isScrambled () const |
| bool | operator== (const TSPacket &p) const |
| std::istream & | read (std::istream &strm, bool check_sync=true, Report &report=(ts::CerrReport::Instance())) |
| void | removeOPCR () |
| void | removePCR () |
| void | removePrivateData () |
| void | removeSpliceCountdown () |
| bool | reserveStuffing (size_t size, bool shift_payload=false, bool enforce_af=false) |
| bool | samePayload (const TSPacket &other) const |
| void | setCC (uint8_t cc) |
| bool | setDiscontinuityIndicator (bool shift_payload=false) |
| void | setDTS (const uint64_t &dts) |
| bool | setESPI (bool shift_payload=false) |
| bool | setOPCR (const uint64_t &opcr, bool shift_payload=false) |
| bool | setPayloadSize (size_t size, bool shift_payload=false, uint8_t pad=0xFF) |
| bool | setPCR (const uint64_t &pcr, bool shift_payload=false) |
| void | setPID (PID pid) |
| void | setPriority () |
| void | setPriority (bool on) |
| bool | setPrivateData (const ByteBlock &data, bool shift_payload=false) |
| bool | setPrivateData (const void *data, size_t size, bool shift_payload=false) |
| void | setPTS (const uint64_t &pts) |
| void | setPUSI () |
| void | setPUSI (bool on) |
| bool | setRandomAccessIndicator (bool shift_payload=false) |
| void | setScrambling (uint8_t sc) |
| bool | setSpliceCountdown (int8_t count, bool shift_payload=false) |
| void | setTEI () |
| void | setTEI (bool on) |
| bool | startPES () const |
| std::ostream & | write (std::ostream &strm, Report &report=(ts::CerrReport::Instance())) const |
Static Public Member Functions | |
| static void | Copy (TSPacket *dest, const TSPacket *source, size_t count=1) |
| static void | Copy (TSPacket *dest, const uint8_t *source, size_t count=1, size_t packet_size=PKT_SIZE) |
| static void | Copy (uint8_t *dest, const TSPacket *source, size_t count=1, size_t packet_size=PKT_SIZE) |
| static uint64_t | GetPCR (const uint8_t *b) |
| static bool | Locate (const uint8_t *buffer, size_t buffer_size, size_t &start_index, size_t &packet_count, size_t &packet_size) |
| static void | PutPCR (uint8_t *b, const uint64_t &pcr) |
| static void | SanityCheck () |
Public Attributes | |
| uint8_t | b [PKT_SIZE] |
Static Public Attributes | |
| static constexpr size_t | PCR_BYTES = 6 |
Basic definition of an MPEG-2 transport packet.
Physically, an object of this class is exactly implemented as a 188-byte TS packets. It is safe to consider that arrays or vectors of this class have the physical layout of a transport stream.
For performance reason, there is no constructor. Uninitialized packets have undefined binary content.
| anonymous enum |
|
inline |
Equality operator.
| [in] | p | Other packet to compare. |
Initialize a TS packet. This method should be used when initializing with NullPacket or EmptyPacket is not appropriate. The packet payload is 184 bytes long and filled with the data byte.
| [in] | pid | PID value. |
| [in] | cc | Continuity counter. |
| [in] | data | Byte value to fill the payload with. |
|
inline |
Check if the sync byte is valid.
|
inline |
Extract payload_unit_start_indicator (PUSI) - 1 bit
|
inline |
Clear payload_unit_start_indicator (PUSI) - 1 bit
|
inline |
Set payload_unit_start_indicator (PUSI) - 1 bit
|
inline |
Set payload_unit_start_indicator (PUSI) - 1 bit
| [in] | on | The value to set. |
|
inline |
Extract transport_error_indicator (TEI) - 1 bit
|
inline |
Clear transport_error_indicator (TEI) - 1 bit
|
inline |
Set transport_error_indicator (TEI) - 1 bit
|
inline |
Set transport_error_indicator (TEI) - 1 bit
| [in] | on | The value to set. |
|
inline |
Extract transport_priority - 1 bit
|
inline |
Clear transport_priority - 1 bit
|
inline |
Set transport_priority - 1 bit
|
inline |
Set transport_priority - 1 bit
| [in] | on | The value to set. |
|
inline |
Extract transport_scrambling_control - 2 bits
|
inline |
Check if the packet is clear (ie not scrambled).
|
inline |
Check if the packet is scrambled.
|
inline |
Set transport_scrambling_control - 2 bits.
| [in] | sc | New transport_scrambling_control value. |
|
inline |
Extract continuity_counter (CC) - 4 bits
|
inline |
Set continuity_counter (CC) - 4 bits
| [in] | cc | New continuity_counter value. |
|
inline |
Check if packet has an adaptation_field (AF)
|
inline |
Compute adaptation_field (AF) size.
| size_t ts::TSPacket::getAFStuffingSize | ( | ) | const |
Compute the size of the stuffing part in the adaptation_field.
|
inline |
Compute the size of the TS header.
|
inline |
Check if packet has a payload
|
inline |
Get payload start address.
|
inline |
Get payload start address.
|
inline |
Compute payload size.
| bool ts::TSPacket::setPayloadSize | ( | size_t | size, |
| bool | shift_payload = false, | ||
| uint8_t | pad = 0xFF ) |
Set the payload size. If the payload shall be shrunk, the adaptation field is enlarged with stuffing. If the payload shall be enlarged, reduce the amount of stuffing in the adaptation field. This method should be used only when creating a packet from scratch, before filling the payload.
| [in] | size | The requested payload size. |
| [in] | shift_payload | If true, the payload is shifted so that the start of its content remains the same. When the payload is shrunk, its end is truncated. When the paylaod is enlarged, it is padded with pad values. When shift_payload is false, the data in the memory area of the payload is not modified. In that case, the memory is silently overwritten, losing the payload content. |
| [in] | pad | Byte value to use when padding the adaptation field or payload. |
|
inline |
Check if packet has a discontinuity_indicator set - 1 bit
|
inline |
Clear discontinuity_indicator - 1 bit
|
inline |
Set discontinuity_indicator - 1 bit
| [in] | shift_payload | If true, the payload can be shifted and truncated when the adaptation field needs to be created. |
|
inline |
Check if packet has a random_access_indicator set - 1 bit
|
inline |
Clear random_access_indicator - 1 bit
|
inline |
Set random_access_indicator - 1 bit
| [in] | shift_payload | If true, the payload can be shifted and truncated when the adaptation field needs to be created. |
|
inline |
Check if packet has a elementary_stream_priority_indicator (ESPI) set - 1 bit
|
inline |
Clear elementary_stream_priority_indicator (ESPI) - 1 bit
|
inline |
Set elementary_stream_priority_indicator (ESPI) - 1 bit
| [in] | shift_payload | If true, the payload can be shifted and truncated when the adaptation field needs to be created. |
|
inline |
| uint64_t ts::TSPacket::getPCR | ( | ) | const |
| bool ts::TSPacket::setPCR | ( | const uint64_t & | pcr, |
| bool | shift_payload = false ) |
Create or replace the PCR value - 42 bits.
| [in] | pcr | The new PCR value. |
| [in] | shift_payload | If true, the payload can be shifted and truncated when the adaptation field needs to be enlarged. |
|
inline |
Remove the Program Clock Reference (PCR) from the packet, if there is one. The adaptation field size is unchanged, its stuffing part is enlarged.
|
inline |
Check if packet has an Original Program Clock Reference (OPCR)
| uint64_t ts::TSPacket::getOPCR | ( | ) | const |
Get the OPCR - 42 bits.
| bool ts::TSPacket::setOPCR | ( | const uint64_t & | opcr, |
| bool | shift_payload = false ) |
Create or replace the OPCR value - 42 bits.
| [in] | opcr | The new OPCR value. |
| [in] | shift_payload | If true, the payload can be shifted and truncated when the adaptation field needs to be enlarged. |
|
inline |
Remove the Original Program Clock Reference (OPCR) from the packet, if there is one. The adaptation field size is unchanged, its stuffing part is enlarged.
|
static |
|
static |
|
inline |
Check if packet has splicing point countdown
| int8_t ts::TSPacket::getSpliceCountdown | ( | ) | const |
Get the splicing point countdown - 8 bits (signed).
| bool ts::TSPacket::setSpliceCountdown | ( | int8_t | count, |
| bool | shift_payload = false ) |
Create or replace the splicing point countdown - 8 bits.
| [in] | count | The new splicing point countdown value. |
| [in] | shift_payload | If true, the payload can be shifted and truncated when the adaptation field needs to be enlarged. |
|
inline |
Remove the splicing point countdown from the packet, if there is one. The adaptation field size is unchanged, its stuffing part is enlarged.
|
inline |
Check if packet has private data in adaptation field.
| size_t ts::TSPacket::getPrivateDataSize | ( | ) | const |
Get size in bytes of private data from adaptation field.
| const uint8_t * ts::TSPacket::getPrivateData | ( | ) | const |
Get address of private data in adaptation field.
| uint8_t * ts::TSPacket::getPrivateData | ( | ) |
Get address of private data in adaptation field.
| void ts::TSPacket::getPrivateData | ( | ByteBlock & | data | ) | const |
Get private data from adaptation field.
| [out] | data | Private data from adaptation field. |
| bool ts::TSPacket::setPrivateData | ( | const void * | data, |
| size_t | size, | ||
| bool | shift_payload = false ) |
Set private data in adaptation field.
| [in] | data | Address of private data to set in the packet. |
| [in] | size | Size in bytes of private data to set in the packet. |
| [in] | shift_payload | If true, the payload can be shifted and truncated when the adaptation field needs to be created or enlarged. |
| bool ts::TSPacket::setPrivateData | ( | const ByteBlock & | data, |
| bool | shift_payload = false ) |
Set private data in adaptation field.
| [in] | data | Private data to set in the packet. |
| [in] | shift_payload | If true, the payload can be shifted and truncated when the adaptation field needs to be created or enlarged. |
| void ts::TSPacket::removePrivateData | ( | ) |
Remove the private data from the adaptation field, if there is one. The adaptation field size is unchanged, its stuffing part is enlarged.
| bool ts::TSPacket::reserveStuffing | ( | size_t | size, |
| bool | shift_payload = false, | ||
| bool | enforce_af = false ) |
Reserve some given space in the stuffing part of the adaptation field.
| [in] | size | The expected stuffing size in bytes, in the adaptation field. If the AF stuffing is already that size or larger, do nothing. Otherwise, attempt to increase the AF size by shifting and truncating the payload. |
| [in] | shift_payload | If true, the payload can be shifted and truncated when the adaptation field needs to be enlarged. |
| [in] | enforce_af | When true, try to create the AF anyway, even if size is zero, making sure that the flags field of the AF is present. |
| bool ts::TSPacket::startPES | ( | ) | const |
Check if the packet contains the start of a clear PES header.
| size_t ts::TSPacket::getPESHeaderSize | ( | ) | const |
Get the size of the PES header in the packet, if one is present.
| bool ts::TSPacket::getPESHeaderStuffingArea | ( | const uint8_t *& | addr, |
| size_t & | pes_size, | ||
| size_t & | ts_size ) const |
Get the address and size of the stuffing area of the PES header in the TS packet.
| [out] | addr | Address of the PES header stuffing area. This address points inside the TS packet payload. |
| [out] | pes_size | Size in bytes of the PES header stuffing area. This is the complete size, some of which can be outside the TS packet. |
| [out] | ts_size | Size in bytes of the PES header stuffing area which is in the TS packet. This size can be lower than the returned pes_size if the stuffing area continues in another TS packet. |
| bool ts::TSPacket::getPESHeaderStuffingArea | ( | uint8_t *& | addr, |
| size_t & | pes_size, | ||
| size_t & | ts_size ) |
Get the address and size of the stuffing area of the PES header in the TS packet.
| [out] | addr | Address of the PES header stuffing area. This address points inside the TS packet payload. |
| [out] | pes_size | Size in bytes of the PES header stuffing area. This is the complete size, some of which can be outside the TS packet. |
| [out] | ts_size | Size in bytes of the PES header stuffing area which is in the TS packet. This size can be lower than the returned pes_size if the stuffing area continues in another TS packet. |
|
inline |
Check if the TS packet contains a Presentation Time Stamp (PTS). Technically, the PTS and DTS are part of the PES packet, not the TS packet. If the TS packet is the first TS packet of a PES packet, it is possible that the PTS and/or DTS are present in the PES packet but outside the first TS packet. This is possible but rare. So, we provide here a fast way of getting PTS and/or DTS from the TS packet if available.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
| bool ts::TSPacket::samePayload | ( | const TSPacket & | other | ) | const |
Check if this packet has the same payload as another one.
| [in] | other | The other packet to compare. |
| bool ts::TSPacket::isDuplicate | ( | const TSPacket & | other | ) | const |
Check if this packet is a duplicate as another one. A valid "true" pair of duplicate packets is made of two consecutive packets with same continuity counter and same payload. It must also have the same adaptation field, with the exception of the PCR which can (should?) be different.
| [in] | other | The other packet to compare. |
| std::istream & ts::TSPacket::read | ( | std::istream & | strm, |
| bool | check_sync = true, | ||
| Report & | report = (ts::CerrReport::Instance()) ) |
Read a packet from standard streams (binary mode).
| [in,out] | strm | A standard stream in input mode. |
| [in] | check_sync | If true, the sync byte of the input packet is checked. If it is not valid, set the failbit of the stream. |
| [in,out] | report | Where to report errors. |
| std::ostream & ts::TSPacket::write | ( | std::ostream & | strm, |
| Report & | report = (ts::CerrReport::Instance()) ) const |
Write a packet to standard streams (binary mode).
| [in,out] | strm | A standard stream in output mode. |
| [in,out] | report | Where to report errors. |
| std::ostream & ts::TSPacket::display | ( | std::ostream & | strm, |
| uint32_t | flags = 0, | ||
| size_t | indent = 0, | ||
| size_t | size = PKT_SIZE ) const |
This method displays the content of a transport packet.
| [in,out] | strm | A standard stream in output mode (text mode). |
| [in] | flags | Indicate which part must be dumped. If DUMP_RAW or DUMP_PAYLOAD is specified, flags from ts::UString::HexaFlags may also be used. |
| [in] | indent | Indicates the base indentation of lines. |
| [in] | size | Maximum size to display in the packet. |
| void ts::TSPacket::copyFrom | ( | const void * | source | ) |
Init packet from a memory area.
| [in] | source | Address of the memory area to read. Must contain at least PKT_SIZE bytes. |
| void ts::TSPacket::copyTo | ( | void * | dest | ) | const |
Copy packet content to a memory area.
| [out] | dest | Address of the memory area to write. Must contain at least PKT_SIZE bytes. |
Copy contiguous TS packets.
| [out] | dest | Address of the first contiguous TS packet to write. |
| [in] | source | Address of the first contiguous TS packet to read. |
| [in] | count | Number of TS packets to copy. |
|
static |
Copy contiguous TS packets from raw memory.
| [out] | dest | Address of the first contiguous TS packet to write. |
| [in] | source | Address of the memory area to read. |
| [in] | count | Number of TS packets to copy. |
| [in] | packet_size | Individual packet size in the source memory area. |
|
static |
Copy contiguous TS packets into raw memory.
| [out] | dest | Address of the memory area to write. |
| [in] | source | Address of the first contiguous TS packet to read. |
| [in] | count | Number of TS packets to copy. |
| [in] | packet_size | Individual packet size in the destination memory area. |
|
static |
Locate contiguous TS packets into a buffer.
This static method is typically used to locate useful packets in a UDP datagram. Basically, we expect the message to contain only TS packets. However, we also face the following situations:
To face the first situation, we look backward from the end of the message, looking for a 0x47 sync byte every 188 or 204 bytes, going backward.
If no TS packet is found using the first method, we restart from the beginning of the message, looking for a 0x47 sync byte every 188 or 204 bytes, going forward. If we find this pattern, followed by less than 188 or 204 bytes, then we have found a sequence of TS packets.
| [in] | buffer | Address of a message buffer containing TS packets. |
| [in] | buffer_size | Size in bytes of the buffer. |
| [out] | start_index | Start index in bytes of the first TS packet in the buffer. |
| [out] | packet_count | Number of TS packets in the buffer. |
| [in,out] | packet_size | On input, indicate the previous packet size from the same source. If different from PKT_SIZE (188) and PKT_RS_SIZE (204), assume an unknown packet size. On output, if packets were found, it is set to the packet size. |
|
static |
Sanity check routine. Ensure that the TSPacket structure can be used in contiguous memory array and array of packets. Can be used once at startup time in paranoid applications. Abort application on error.
| uint8_t ts::TSPacket::b[PKT_SIZE] |
The public content is the 188-byte array representing the TS packet.
|
staticconstexpr |
Size in bytes of a Program Clock Reference (PCR) as stored in a TS packet.