A TS packet buffer for time shift. More...
Public Member Functions | |
TimeShiftBuffer (size_t count=DEFAULT_TOTAL_PACKETS) | |
Constructor. More... | |
virtual | ~TimeShiftBuffer () |
Destructor. | |
bool | close (Report &report) |
Close the buffer. More... | |
size_t | count () const |
Get the current number of packets in the time-shift buffer. More... | |
bool | empty () const |
Check if the buffer is empty. More... | |
bool | full () const |
Check if the buffer is full. More... | |
bool | isOpen () const |
Check if the buffer is open. More... | |
bool | memoryResident () const |
Check if the buffer is completely memory resident. More... | |
bool | open (Report &report) |
Open the buffer. More... | |
bool | setBackupDirectory (const UString &directory) |
Set the directory for the backup file on disk. More... | |
bool | setMemoryPackets (size_t count) |
Set the maximum number of cached packets to be held in memory. More... | |
bool | setTotalPackets (size_t count) |
Set the total size of the time shift buffer in packets. More... | |
bool | shift (TSPacket &packet, TSPacketMetadata &metadata, Report &report) |
Push a packet in the time-shift buffer and pull the oldest one. More... | |
size_t | size () const |
Get the total size in packets of the time-shift buffer. More... | |
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. | |
A TS packet buffer for time shift.
The buffer is partly implemented in virtual memory and partly on disk.
ts::TimeShiftBuffer::TimeShiftBuffer | ( | size_t | count = DEFAULT_TOTAL_PACKETS | ) |
Constructor.
[in] | count | Max number of packets in the buffer. |
bool ts::TimeShiftBuffer::setTotalPackets | ( | size_t | count | ) |
Set the total size of the time shift buffer in packets.
Must be called before open().
[in] | count | Max number of packets in the buffer. |
bool ts::TimeShiftBuffer::setMemoryPackets | ( | size_t | count | ) |
Set the maximum number of cached packets to be held in memory.
Must be called before open().
[in] | count | Max number of cached packets in memory. |
bool ts::TimeShiftBuffer::setBackupDirectory | ( | const UString & | 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.
[in] | directory | Directory name. |
bool ts::TimeShiftBuffer::open | ( | Report & | report | ) |
Open the buffer.
[in,out] | report | Where to report errors. |
bool ts::TimeShiftBuffer::close | ( | Report & | report | ) |
Close the buffer.
The memory is freed and the disk backup file is deleted.
[in,out] | report | Where to report errors. |
|
inline |
Check if the buffer is open.
|
inline |
Get the total size in packets of the time-shift buffer.
|
inline |
Get the current number of packets in the time-shift buffer.
|
inline |
Check if the buffer is empty.
|
inline |
Check if the buffer is full.
|
inline |
Check if the buffer is completely memory resident.
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().
[in,out] | packet | On input, contains the packet to push. On output, contains the time-shifted packet. |
[in,out] | metadata | Packet metadata. |
[in,out] | report | Where to report errors. |