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

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

#include <tsTimeShiftBuffer.h>

Inheritance diagram for ts::TimeShiftBuffer:
Collaboration diagram for ts::TimeShiftBuffer:

Public Member Functions

 TimeShiftBuffer (Report *report, size_t count=DEFAULT_TOTAL_PACKETS)
 Constructor.
 
 TimeShiftBuffer (ReporterBase *delegate, size_t count=DEFAULT_TOTAL_PACKETS)
 Constructor.
 
virtual ~TimeShiftBuffer () override
 Destructor.
 
bool close (bool silent=false)
 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 muteReport (bool mute)
 Temporarily mute the associated report.
 
bool open ()
 Open the buffer.
 
virtual Reportreport () const override
 Access the Report which is associated with this object.
 
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.
 
ReportsetReport (Report *report)
 Associate this object with another Report to log errors.
 
ReporterBasesetReport (ReporterBase *delegate)
 Associate this object with another ReporterBase to log errors.
 
bool setTotalPackets (size_t count)
 Set the total size of the time shift buffer in packets.
 
bool shift (TSPacket &packet, TSPacketMetadata &metadata)
 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 Member Functions

static int SilentLevel (bool silent, int default_severity=Severity::Error)
 Compute a log severity level from a "silent" parameter.
 

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() [1/2]

ts::TimeShiftBuffer::TimeShiftBuffer ( Report report,
size_t  count = DEFAULT_TOTAL_PACKETS 
)
explicit

Constructor.

Parameters
[in]reportWhere to report errors. The report object must remain valid as long as this object exists or setReport() is used with another Report object. If report is null, log messages are discarded.
[in]countMax number of packets in the buffer.

◆ TimeShiftBuffer() [2/2]

ts::TimeShiftBuffer::TimeShiftBuffer ( ReporterBase delegate,
size_t  count = DEFAULT_TOTAL_PACKETS 
)
explicit

Constructor.

Parameters
[in]delegateUse the report of another ReporterBase. If delegate is null, log messages are discarded.
[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 ( )

Open the buffer.

Returns
True on success, false on error.

◆ close()

bool ts::TimeShiftBuffer::close ( bool  silent = false)

Close the buffer.

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

Parameters
[in]silentIf true, do not report errors. This is typically useful when the object is in some error condition and closing it is necessary although it may generate additional meaningless 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 
)

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.
Returns
True on success, false on error.

◆ report()

virtual Report & ts::ReporterBase::report ( ) const
overridevirtualinherited

Access the Report which is associated with this object.

Can be called from another thread only if the Report object is thread-safe.

Returns
A reference to the associated report.

Implements ts::ReporterInterface.

◆ setReport() [1/2]

Report * ts::ReporterBase::setReport ( Report report)
inherited

Associate this object with another Report to log errors.

Parameters
[in]reportWhere to report errors. The report object must remain valid as long as this object exists or setReport() is used with another Report object. If report is null, log messages are discarded.
Returns
The address of the previous Report object or a null pointer if there was none.

◆ setReport() [2/2]

ReporterBase * ts::ReporterBase::setReport ( ReporterBase delegate)
inherited

Associate this object with another ReporterBase to log errors.

Parameters
[in]delegateUse the report of another ReporterBase. If delegate is null, the previous explicit Report is used..
Returns
The address of the previous ReporterBase object or a null pointer if there was none.

◆ muteReport()

bool ts::ReporterBase::muteReport ( bool  mute)
inherited

Temporarily mute the associated report.

Parameters
[in]muteIt true, report() will return a null report (log messages are discarded), until muteReport() is invoked again with mute set to false.
Returns
Previous state of the mute field.

◆ SilentLevel()

static int ts::ReporterBase::SilentLevel ( bool  silent,
int  default_severity = Severity::Error 
)
inlinestaticinherited

Compute a log severity level from a "silent" parameter.

Some subclass methods have a "silent" parameter to avoid reporting errors which may be insignificant, typically when closing a device after an error, in which case the close operation may produce other errors if the previous error left the device in an inconsistent state. While those errors should not be displayed as errors, we still display them at debug level.

Parameters
[in]silentIf true, do not report errors, report debug messages instead.
[in]default_severityDefault severity, in non-silent mode (error by default).
Returns
Error when silent is false, Debug otherwise.

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