TSDuck v3.46-4965
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::TSPacketQueue Class Reference

#include <tsTSPacketQueue.h>

Public Member Functions

 TSPacketQueue (size_t size=DEFAULT_SIZE)
size_t bufferSize () const
size_t currentSize () const
bool eof () const
bool getPacket (TSPacket &packet, TSPacketMetadata *mdata, BitRate &bitrate)
bool lockWriteBuffer (TSPacket *&buffer, TSPacketMetadata *&mdata, size_t &buffer_size, size_t min_size=1)
void releaseWriteBuffer (size_t count)
void reset (size_t size=NPOS)
void setBitrate (const BitRate &bitrate)
void setEOF ()
void stop ()
bool stopped () const
bool waitPackets (TSPacket *buffer, TSPacketMetadata *mdata, size_t buffer_count, size_t &actual_count, BitRate &bitrate)

Static Public Attributes

static constexpr size_t DEFAULT_SIZE = 1000

Detailed Description

Transport stream packet queue for inter-thread communication.

A writer thread produces packets. The input packets are directly written into the buffer. The writer thread invokes lockWriteBuffer() to get a write window inside the buffer. When packets have been written into this buffer, the writer thread calls releaseWriteBuffer().

A reader thread consumes packets. The packets are consumed one by one and copied out of the buffer using getPacket().

The input bitrate, if known, is transmitted to the reader thread. If the writer thread is aware of the exact bitrate, it calls setBitrate() and the specified value is returned to the reader thread. If the input bitrate is unknown, the buffer automatically computes it based on PCR's.

Termination conditions can be triggered on both sides.

Constructor & Destructor Documentation

◆ TSPacketQueue()

ts::TSPacketQueue::TSPacketQueue ( size_t size = DEFAULT_SIZE)

Default constructor.

Parameters
[in]sizeSize of the buffer in packets.

Member Function Documentation

◆ reset()

void ts::TSPacketQueue::reset ( size_t size = NPOS)

Reset and resize the buffer. It is illegal to reset the buffer while the writer thread has locked the buffer. This is not enforced by this class. It is the responsibility of the application to check this.

Parameters
[in]sizeNew size of the buffer in packets. By default, when set to NPOS, reset the queue without resizing the buffer.

◆ bufferSize()

size_t ts::TSPacketQueue::bufferSize ( ) const

Get the size of the buffer in packets.

Returns
The size of the buffer in packets.

◆ currentSize()

size_t ts::TSPacketQueue::currentSize ( ) const

Get the current number of packets in the buffer.

Returns
The current number of packets in the buffer.

◆ lockWriteBuffer()

bool ts::TSPacketQueue::lockWriteBuffer ( TSPacket *& buffer,
TSPacketMetadata *& mdata,
size_t & buffer_size,
size_t min_size = 1 )

Called by the writer thread to get a write buffer. The writer thread is suspended until enough free space is made in the buffer or the reader thread triggers a stop condition.

Parameters
[out]bufferAddress of the packet write buffer.
[out]mdataAddress of the packet metadata write buffer.
[out]buffer_sizeSize in packets of the write buffer.
[in]min_sizeMinimum number of free packets to get. This is just a hint. The returned size can be smaller, for instance when the write window of the circular buffer is close to the end of the buffer.
Returns
True when the write buffer is correctly available. False when the reader thread has signalled a stop condition.

◆ releaseWriteBuffer()

void ts::TSPacketQueue::releaseWriteBuffer ( size_t count)

Called by the writer thread to release the write buffer. The packets were written by the writer thread at the address which was returned by lockWriteBuffer().

Parameters
[in]countNumber of packets which were written in the buffer. Must be no greater than the size which was returned by lockWriteBuffer().

◆ setBitrate()

void ts::TSPacketQueue::setBitrate ( const BitRate & bitrate)

Called by the writer thread to report the input bitrate.

Parameters
[in]bitrateInput bitrate. If zero, the input bitrate is unknown and will be computed from PCR's.

◆ setEOF()

void ts::TSPacketQueue::setEOF ( )

Called by the writer thread to report the end of input thread.

◆ stopped()

bool ts::TSPacketQueue::stopped ( ) const
inline

Check if the reader thread has reported a stop condition.

Returns
True if the reader thread has reported a stop condition.

◆ getPacket()

bool ts::TSPacketQueue::getPacket ( TSPacket & packet,
TSPacketMetadata * mdata,
BitRate & bitrate )

Called by the reader thread to get the next packet without waiting. The reader thread is never suspended. If no packet is available, return false.

Parameters
[out]packetThe returned packet. Unmodified when no packet is available.
[out]mdataThe returned packet metadata, if not null. Unmodified when no packet is available.
[out]bitrateInput bitrate or zero if unknown.
Returns
True if a packet was returned in packet. False if none was available or an end of file occured.

◆ waitPackets()

bool ts::TSPacketQueue::waitPackets ( TSPacket * buffer,
TSPacketMetadata * mdata,
size_t buffer_count,
size_t & actual_count,
BitRate & bitrate )

Called by the reader thread to wait for packets. The reader thread is suspended until at least one packet is available.

Parameters
[out]bufferAddress of packet buffer.
[out]mdataAddress of the packet metadata buffer. Can be null.
[in]buffer_countSize of buffer in number of packets.
[out]actual_countNumber of returned packets in buffer.
[out]bitrateInput bitrate or zero if unknown.
Returns
True if a packets were returned in buffer. False on error or end of file.

◆ eof()

bool ts::TSPacketQueue::eof ( ) const

Check if the writer thread has reported an end of file condition.

Returns
True if the writer thread has reported an end of file condition.

◆ stop()

void ts::TSPacketQueue::stop ( )

Called by the reader thread to tell the writer thread to stop immediately.

Member Data Documentation

◆ DEFAULT_SIZE

size_t ts::TSPacketQueue::DEFAULT_SIZE = 1000
staticconstexpr

Default size in packets of the buffer.


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