TSDuck v3.40-3963
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::TimeShiftBuffer Class Reference

A TS packet buffer for time shift. More...

#include <tsTimeShiftBuffer.h>

Public Member Functions

 TimeShiftBuffer (size_t count=DEFAULT_TOTAL_PACKETS)
 Constructor.
 
virtual ~TimeShiftBuffer ()
 Destructor.
 
bool close (Report &report)
 Close the buffer.
 
size_t count () const
 Get the current number of packets in the time-shift buffer.
 
bool empty () const
 Check if the buffer is empty.
 
bool full () const
 Check if the buffer is full.
 
bool isOpen () const
 Check if the buffer is open.
 
bool memoryResident () const
 Check if the buffer is completely memory resident.
 
bool open (Report &report)
 Open the buffer.
 
bool setBackupDirectory (const fs::path &directory)
 Set the directory for the backup file on disk.
 
bool setMemoryPackets (size_t count)
 Set the maximum number of cached packets to be held in memory.
 
bool setTotalPackets (size_t count)
 Set the total size of the time shift buffer in packets.
 
bool shift (TSPacket &packet, TSPacketMetadata &metadata, Report &report)
 Push a packet in the time-shift buffer and pull the oldest one.
 
size_t size () const
 Get the total size in packets of the time-shift buffer.
 

Static Public Attributes

static constexpr size_t DEFAULT_MEMORY_PACKETS = 128
 Default number of cached packets in memory.
 
static constexpr size_t DEFAULT_TOTAL_PACKETS = 128
 Default size in packets of a time shift buffer.
 
static constexpr size_t MIN_MEMORY_PACKETS = 2
 Minimum number of cached packets in memory.
 
static constexpr size_t MIN_TOTAL_PACKETS = 2
 Minimum size in packets of a time shift buffer.
 

Detailed Description

A TS packet buffer for time shift.

The buffer is partly implemented in virtual memory and partly on disk.

Constructor & Destructor Documentation

◆ TimeShiftBuffer()

ts::TimeShiftBuffer::TimeShiftBuffer ( size_t  count = DEFAULT_TOTAL_PACKETS)

Constructor.

Parameters
[in]countMax number of packets in the buffer.

Member Function Documentation

◆ setTotalPackets()

bool ts::TimeShiftBuffer::setTotalPackets ( size_t  count)

Set the total size of the time shift buffer in packets.

Must be called before open().

Parameters
[in]countMax number of packets in the buffer.
Returns
True on success, false if already open.

◆ setMemoryPackets()

bool ts::TimeShiftBuffer::setMemoryPackets ( size_t  count)

Set the maximum number of cached packets to be held in memory.

Must be called before open().

Parameters
[in]countMax number of cached packets in memory.
Returns
True on success, false if already open.

◆ setBackupDirectory()

bool ts::TimeShiftBuffer::setBackupDirectory ( const fs::path &  directory)

Set the directory for the backup file on disk.

Must be called before open(). By default, the file is created in the system-dependent temporary directory. When the maximum number of cached packets in memory is larger than the buffer size, the buffer is entirely resident in memory and no file is created. The back file is automatically deleted when the time-shift buffer is closed.

Parameters
[in]directoryDirectory name.
Returns
True on success, false if already open or too small.

◆ open()

bool ts::TimeShiftBuffer::open ( Report report)

Open the buffer.

Parameters
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

◆ close()

bool ts::TimeShiftBuffer::close ( Report report)

Close the buffer.

The memory is freed and the disk backup file is deleted.

Parameters
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

◆ isOpen()

bool ts::TimeShiftBuffer::isOpen ( ) const
inline

Check if the buffer is open.

Returns
True if the buffer is open.

◆ size()

size_t ts::TimeShiftBuffer::size ( ) const
inline

Get the total size in packets of the time-shift buffer.

Returns
The total size in packets of the time-shift buffer.

◆ count()

size_t ts::TimeShiftBuffer::count ( ) const
inline

Get the current number of packets in the time-shift buffer.

Returns
The current number of packets in the time-shift buffer.

◆ empty()

bool ts::TimeShiftBuffer::empty ( ) const
inline

Check if the buffer is empty.

Returns
True when the buffer is empty, false otherwise.

◆ full()

bool ts::TimeShiftBuffer::full ( ) const
inline

Check if the buffer is full.

Returns
True when the buffer is full, false otherwise.

◆ memoryResident()

bool ts::TimeShiftBuffer::memoryResident ( ) const
inline

Check if the buffer is completely memory resident.

Returns
True when the buffer is memory resident, false when it is backup by a file.

◆ shift()

bool ts::TimeShiftBuffer::shift ( TSPacket packet,
TSPacketMetadata metadata,
Report report 
)

Push a packet in the time-shift buffer and pull the oldest one.

As long as the buffer is not full, a null packet is returned. When the buffer is full, the oldest packet is returned and removed from the buffer. Initial null packets which are generated while the time-shift buffer is filling can be recognized as they are marked as "input stuffing" in their metadata, after returning from shift().

Parameters
[in,out]packetOn input, contains the packet to push. On output, contains the time-shifted packet.
[in,out]metadataPacket metadata.
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

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