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

#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)
 TimeShiftBuffer (ReporterBase *delegate, size_t count=DEFAULT_TOTAL_PACKETS)
virtual ~TimeShiftBuffer () override
bool close (bool silent=false)
size_t count () const
bool empty () const
bool full () const
bool isOpen () const
bool memoryResident () const
bool muteReport (bool mute)
bool open ()
virtual Report & report () const override
bool setBackupDirectory (const fs::path &directory)
bool setMemoryPackets (size_t count)
Report * setReport (Report *report)
ReporterBase * setReport (ReporterBase *delegate)
bool setTotalPackets (size_t count)
bool shift (TSPacket &packet, TSPacketMetadata &metadata)
size_t size () const

Static Public Member Functions

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

Static Public Attributes

static constexpr size_t DEFAULT_MEMORY_PACKETS = 128
static constexpr size_t DEFAULT_TOTAL_PACKETS = 128
static constexpr size_t MIN_MEMORY_PACKETS = 2
static constexpr size_t MIN_TOTAL_PACKETS = 2

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.

◆ ~TimeShiftBuffer()

virtual ts::TimeShiftBuffer::~TimeShiftBuffer ( )
overridevirtual

Destructor.

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()

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.

Member Data Documentation

◆ MIN_TOTAL_PACKETS

size_t ts::TimeShiftBuffer::MIN_TOTAL_PACKETS = 2
staticconstexpr

Minimum size in packets of a time shift buffer.

◆ DEFAULT_TOTAL_PACKETS

size_t ts::TimeShiftBuffer::DEFAULT_TOTAL_PACKETS = 128
staticconstexpr

Default size in packets of a time shift buffer.

◆ MIN_MEMORY_PACKETS

size_t ts::TimeShiftBuffer::MIN_MEMORY_PACKETS = 2
staticconstexpr

Minimum number of cached packets in memory.

◆ DEFAULT_MEMORY_PACKETS

size_t ts::TimeShiftBuffer::DEFAULT_MEMORY_PACKETS = 128
staticconstexpr

Default number of cached packets in memory.


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