TSDuck v3.45-4766
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::TSPacketStream Class Reference

Read/write TS packets on a stream. More...

#include <tsTSPacketStream.h>

Inheritance diagram for ts::TSPacketStream:

Public Member Functions

 TSPacketStream (ReporterInterface &reporter, TSPacketFormat format=TSPacketFormat::AUTODETECT, StreamInterface *stream=nullptr)
 Constructor.
 
virtual ~TSPacketStream ()
 Destructor.
 
TSPacketFormat packetFormat () const
 Get the file format.
 
UString packetFormatString () const
 Get the file format as a string.
 
size_t packetHeaderSize () const
 Get the packet header size, based on the packet format of this file.
 
size_t packetTrailerSize () const
 Get the packet trailer size, based on the packet format of this file.
 
virtual size_t readPackets (TSPacket *buffer, TSPacketMetadata *metadata, size_t max_packets)
 Read TS packets from the stream.
 
PacketCounter readPacketsCount () const
 Get the number of read packets.
 
virtual bool writePackets (const TSPacket *buffer, const TSPacketMetadata *metadata, size_t packet_count)
 Write TS packets to the stream.
 
PacketCounter writePacketsCount () const
 Get the number of written packets.
 

Static Public Member Functions

static size_t PacketHeaderSize (TSPacketFormat format)
 Get the packet header size for a given packet format.
 
static size_t PacketTrailerSize (TSPacketFormat format)
 Get the packet trailer size for a given packet format.
 

Static Public Attributes

static constexpr size_t MAX_HEADER_SIZE = ts::TSPacketMetadata::SERIALIZATION_SIZE
 Maximum size in bytes of a packet header for non-TS format.
 
static constexpr size_t MAX_TRAILER_SIZE = ts::RS_SIZE
 Maximum size in bytes of a packet trailer for non-TS format.
 

Protected Member Functions

void resetPacketStream (TSPacketFormat format, StreamInterface *stream)
 Reset the stream format and counters.
 

Protected Attributes

PacketCounter _total_read = 0
 Total read packets.
 
PacketCounter _total_write = 0
 Total written packets.
 

Detailed Description

Read/write TS packets on a stream.

Constructor & Destructor Documentation

◆ TSPacketStream()

ts::TSPacketStream::TSPacketStream ( ReporterInterface reporter,
TSPacketFormat  format = TSPacketFormat::AUTODETECT,
StreamInterface stream = nullptr 
)

Constructor.

Parameters
[in,out]reporterReference to an object providing a Report. This reference is kept in the constructed object instance.
[in]formatInitial packet format.
[in]streamStream read/write interface. Can be null and replaced later.

Member Function Documentation

◆ readPackets()

virtual size_t ts::TSPacketStream::readPackets ( TSPacket buffer,
TSPacketMetadata metadata,
size_t  max_packets 
)
virtual

Read TS packets from the stream.

Parameters
[out]bufferAddress of reception packet buffer.
[out]metadataOptional packet metadata. If the file format provides time stamps, they are set in the metadata. Ignored if null pointer.
[in]max_packetsSize of buffer in packets. Also size of metadata in number of objects (when specified).
Returns
The actual number of read packets. Returning zero means error or end of stream.

Reimplemented in ts::TSFile.

◆ writePackets()

virtual bool ts::TSPacketStream::writePackets ( const TSPacket buffer,
const TSPacketMetadata metadata,
size_t  packet_count 
)
virtual

Write TS packets to the stream.

Parameters
[in]bufferAddress of first packet to write.
[in]metadataOptional packet metadata containing time stamps. If the file format requires time stamps, metadata must not be a null pointer and all packets must have a time stamp. Otherwise, the last written timestamp is repeated.
[in]packet_countNumber of packets to write. Also size of metadata in number of objects (when specified).
Returns
True on success, false on error.

◆ readPacketsCount()

PacketCounter ts::TSPacketStream::readPacketsCount ( ) const
inline

Get the number of read packets.

Returns
The number of read packets.

◆ writePacketsCount()

PacketCounter ts::TSPacketStream::writePacketsCount ( ) const
inline

Get the number of written packets.

Returns
The number of written packets.

◆ PacketHeaderSize()

static size_t ts::TSPacketStream::PacketHeaderSize ( TSPacketFormat  format)
static

Get the packet header size for a given packet format.

This "header" comes before the classical 188-byte TS packet.

Parameters
[in]formatInitial packet format.
Returns
The packet header size in bytes (before the TS packet).

◆ PacketTrailerSize()

static size_t ts::TSPacketStream::PacketTrailerSize ( TSPacketFormat  format)
static

Get the packet trailer size for a given packet format.

This "trailer" comes after the classical 188-byte TS packet.

Parameters
[in]formatInitial packet format.
Returns
The packet trailer size in bytes (before the TS packet).

◆ packetHeaderSize()

size_t ts::TSPacketStream::packetHeaderSize ( ) const
inline

Get the packet header size, based on the packet format of this file.

This "header" comes before the classical 188-byte TS packet.

Returns
The packet header size in bytes (before the TS packet).

◆ packetTrailerSize()

size_t ts::TSPacketStream::packetTrailerSize ( ) const
inline

Get the packet trailer size, based on the packet format of this file.

This "trailer" comes after the classical 188-byte TS packet.

Returns
The packet trailer size in bytes (before the TS packet).

◆ packetFormat()

TSPacketFormat ts::TSPacketStream::packetFormat ( ) const
inline

Get the file format.

Returns
The file format.

◆ packetFormatString()

UString ts::TSPacketStream::packetFormatString ( ) const
inline

Get the file format as a string.

Returns
The file format as a string.

◆ resetPacketStream()

void ts::TSPacketStream::resetPacketStream ( TSPacketFormat  format,
StreamInterface stream 
)
protected

Reset the stream format and counters.

Parameters
[in]formatInitial packet format.
[in]streamStream read/write interface.

Member Data Documentation

◆ MAX_HEADER_SIZE

constexpr size_t ts::TSPacketStream::MAX_HEADER_SIZE = ts::TSPacketMetadata::SERIALIZATION_SIZE
staticconstexpr

Maximum size in bytes of a packet header for non-TS format.

Must be lower than the TS packet size to allow auto-detection on read.

◆ MAX_TRAILER_SIZE

constexpr size_t ts::TSPacketStream::MAX_TRAILER_SIZE = ts::RS_SIZE
staticconstexpr

Maximum size in bytes of a packet trailer for non-TS format.

Must be lower than the TS packet size to allow auto-detection on read.


The documentation for this class was generated from the following file: