A TS packet buffer for time shift.
More...
#include <tsTimeShiftBuffer.h>
|
| static int | SilentLevel (bool silent, int default_severity=Severity::Error) |
| | Compute a log severity level from a "silent" parameter.
|
| |
|
|
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.
|
| |
A TS packet buffer for time shift.
The buffer is partly implemented in virtual memory and partly on disk.
◆ TimeShiftBuffer() [1/2]
Constructor.
- Parameters
-
| [in] | report | Where 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] | count | Max number of packets in the buffer. |
◆ TimeShiftBuffer() [2/2]
Constructor.
- Parameters
-
| [in] | delegate | Use the report of another ReporterBase. If delegate is null, log messages are discarded. |
| [in] | count | Max number of packets in the buffer. |
◆ 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] | count | Max 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] | count | Max 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] | directory | Directory 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] | silent | If 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()
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] | packet | On input, contains the packet to push. On output, contains the time-shifted packet. |
| [in,out] | metadata | Packet 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]
Associate this object with another Report to log errors.
- Parameters
-
| [in] | report | Where 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]
Associate this object with another ReporterBase to log errors.
- Parameters
-
| [in] | delegate | Use 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] | mute | It 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] | silent | If true, do not report errors, report debug messages instead. |
| [in] | default_severity | Default 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: