TSDuck v3.40-4001
MPEG Transport Stream Toolkit
|
Transport stream file input with a seekable buffer. More...
#include <tsTSFileInputBuffered.h>
Public Types | |
enum | OpenFlags { NONE = 0x0000 , READ = 0x0001 , WRITE = 0x0002 , APPEND = 0x0004 , KEEP = 0x0008 , SHARED = 0x0010 , TEMPORARY = 0x0020 , REOPEN = 0x0040 , REOPEN_SPEC = 0x0080 } |
Flags for open(). More... | |
Public Member Functions | |
TSFileInputBuffered (size_t buffer_size) | |
Constructor. | |
virtual | ~TSFileInputBuffered () override |
Destructor. | |
void | abort () |
Abort any currenly read/write operation in progress. | |
bool | canSeek (PacketCounter position) const |
Check if we can seek to the specified absolute position. | |
bool | close (Report &report) |
Close the file. | |
size_t | getBackwardSeekableCount () const |
Get the backward seekable distance inside the buffer. | |
size_t | getBufferedCount () const |
Get the number of TS packets in the buffer. | |
size_t | getBufferFreeSize () const |
Get the size of the free space in the buffer. | |
size_t | getBufferSize () const |
Get the buffer size. | |
UString | getDisplayFileName () const |
Get the file name as a display string. | |
fs::path | getFileName () const |
Get the file name. | |
size_t | getForwardSeekableCount () const |
Get the forward seekable distance inside the buffer. | |
bool | isOpen () const |
Check if the file is open. | |
bool | openRead (const fs::path &filename, size_t repeat_count, uint64_t start_offset, Report &report, TSPacketFormat format=TSPacketFormat::AUTODETECT) |
Open the file. | |
bool | openRead (const fs::path &filename, uint64_t start_offset, Report &report, TSPacketFormat format=TSPacketFormat::AUTODETECT) |
Open the file for read in rewindable mode. | |
TSPacketFormat | packetFormat () const |
Get the file format. | |
UString | packetFormatString () const |
Get the file format as a string. | |
size_t | packetHeaderSize () const |
Get the packet header size, based on the packet format. | |
size_t | packetTrailerSize () const |
Get the packet trailer size, based on the packet format. | |
size_t | read (TSPacket *buffer, size_t max_packets, Report &report, TSPacketMetadata *metadata=nullptr) |
Read TS packets. | |
virtual size_t | readPackets (TSPacket *buffer, TSPacketMetadata *metadata, size_t max_packets, Report &report) override |
Read TS packets from the stream. | |
PacketCounter | readPacketsCount () const |
Get the number of read packets. | |
bool | seek (PacketCounter position, Report &report) |
Seek to the specified absolute position, if it is inside the buffer. | |
bool | seekBackward (size_t packet_count, Report &report) |
Seek the file backward the specified number of packets. | |
bool | seekForward (size_t packet_count, Report &report) |
Seek the file forward the specified number of packets. | |
bool | setBufferSize (size_t buffer_size, Report &report) |
Set the buffer size. | |
void | setStuffing (size_t initial, size_t final) |
Set initial and final artificial stuffing. | |
virtual bool | writePackets (const TSPacket *buffer, const TSPacketMetadata *metadata, size_t packet_count, Report &report) |
Write TS packets to the stream. | |
PacketCounter | writePacketsCount () const |
Get the number of written packets. | |
Static Public Attributes | |
static constexpr size_t | MAX_HEADER_SIZE = ts::TSPacketMetadata::SERIALIZATION_SIZE |
Maximum size in bytes of a packet header for non-TS format. | |
static constexpr size_t | MAX_TRAILER_SIZE = ts::RS_SIZE |
Maximum size in bytes of a packet trailer for non-TS format. | |
static constexpr size_t | MIN_BUFFER_SIZE = 16 |
Minimum buffer size. | |
Protected Member Functions | |
void | resetPacketStream (TSPacketFormat format, AbstractReadStreamInterface *reader, AbstractWriteStreamInterface *writer) |
Reset the stream format and counters. | |
Protected Attributes | |
PacketCounter | _total_read = 0 |
Total read packets. | |
PacketCounter | _total_write = 0 |
Total written packets. | |
Transport stream file input with a seekable buffer.
This variant of TSFile allows to seek back and forth to some extent without doing I/O's and can work on non-seekable files (pipes for instance).
|
inherited |
Flags for open().
ts::TSFileInputBuffered::TSFileInputBuffered | ( | size_t | buffer_size | ) |
Constructor.
[in] | buffer_size | Size of the seekable buffer in number of TS packets. |
bool ts::TSFileInputBuffered::setBufferSize | ( | size_t | buffer_size, |
Report & | report | ||
) |
Set the buffer size.
Can be done only when the file is closed.
[in] | buffer_size | Size of the seekable buffer in number of TS packets. |
[in,out] | report | Where to report errors. |
|
inline |
Get the buffer size.
|
inline |
Get the size of the free space in the buffer.
|
inline |
Get the number of TS packets in the buffer.
bool ts::TSFileInputBuffered::openRead | ( | const fs::path & | filename, |
size_t | repeat_count, | ||
uint64_t | start_offset, | ||
Report & | report, | ||
TSPacketFormat | format = TSPacketFormat::AUTODETECT |
||
) |
Open the file.
Override TSFile::openRead(). There is no rewindable version.
[in] | filename | File name. If empty, use standard input. Must be a regular file is repeat_count is not 1 or if start_offset is not zero. |
[in] | repeat_count | Reading packets loops back after end of file until all repeat are done. If zero, infinitely repeat. |
[in] | start_offset | Offset in bytes from the beginning of the file where to start reading packets at each iteration. |
[in,out] | report | Where to report errors. |
[in] | format | Expected format of the TS file. |
size_t ts::TSFileInputBuffered::read | ( | TSPacket * | buffer, |
size_t | max_packets, | ||
Report & | report, | ||
TSPacketMetadata * | metadata = nullptr |
||
) |
Read TS packets.
Override TSFile::read(). If the file file was opened with a repeat_count different from 1, reading packets transparently loops back at end if file.
[out] | buffer | Address of reception packet buffer. |
[in] | max_packets | Size of buffer in packets. |
[in,out] | report | Where to report errors. |
[in,out] | metadata | Optional packet metadata. If the file format provides time stamps, they are set in the metadata. Ignored if null pointer. |
|
inline |
Get the backward seekable distance inside the buffer.
This is the minimum guaranteed seekable distance.
|
inline |
Get the forward seekable distance inside the buffer.
This is the minimum guaranteed seekable distance.
bool ts::TSFileInputBuffered::seekBackward | ( | size_t | packet_count, |
Report & | report | ||
) |
Seek the file backward the specified number of packets.
[in] | packet_count | The number of packets to seek backward from the current position. |
[in,out] | report | Where to report errors. |
bool ts::TSFileInputBuffered::seekForward | ( | size_t | packet_count, |
Report & | report | ||
) |
Seek the file forward the specified number of packets.
[in] | packet_count | The number of packets to seek forward from the current position. |
[in,out] | report | Where to report errors. |
PacketCounter ts::TSFileInputBuffered::readPacketsCount | ( | ) | const |
Get the number of read packets.
Override TSFile::readPacketsCount().
bool ts::TSFileInputBuffered::canSeek | ( | PacketCounter | position | ) | const |
Check if we can seek to the specified absolute position.
[in] | position | Absolute packet index in the file. |
bool ts::TSFileInputBuffered::seek | ( | PacketCounter | position, |
Report & | report | ||
) |
Seek to the specified absolute position, if it is inside the buffer.
[in] | position | Absolute packet index in the file. |
[in,out] | report | Where to report errors. |
|
inherited |
Open the file for read in rewindable mode.
The file must be a rewindable file, eg. not a pipe. There is no repeat count, rewind must be done explicitly.
[in] | filename | File name. If empty or "-", use standard input. |
[in] | start_offset | Offset in bytes from the beginning of the file where to start reading packets. |
[in,out] | report | Where to report errors. |
[in] | format | Expected format of the TS file. |
|
inlineinherited |
Check if the file is open.
|
inlineinherited |
Get the file name.
|
inherited |
Get the file name as a display string.
|
inherited |
Close the file.
[in,out] | report | Where to report errors. |
|
inherited |
Set initial and final artificial stuffing.
This method shall be called before opening the file. It specifies a number of artificial null packets which are read or written before and after the actual content of the file.
[in] | initial | Number of artificial initial null packets. On read, the first initial read packets are null packets. The actual content of the physical file will be read afterward. On write, opening the file will immediately write initial null packets, before the application has a chance to explicitly write packets. |
[in] | final | Number of artificial final null packets. On read, when the file is completed, after all specified repetitions, reading will successfully continue for the next final packets and returns null packets. On write, closing the file with automatically write final null packets before closing the physical file. |
|
inherited |
Abort any currenly read/write operation in progress.
The file is left in a broken state and can be only closed.
|
overridevirtualinherited |
Read TS packets from the stream.
[out] | buffer | Address of reception packet buffer. |
[out] | metadata | Optional packet metadata. If the file format provides time stamps, they are set in the metadata. Ignored if null pointer. |
[in] | max_packets | Size of buffer in packets. Also size of metadata in number of objects (when specified). |
[in,out] | report | Where to report errors. |
Reimplemented from ts::TSPacketStream.
|
virtualinherited |
Write TS packets to the stream.
[in] | buffer | Address of first packet to write. |
[in] | metadata | Optional packet metadata containing time stamps. If the file format requires time stamps, metadata must not be a null pointer and all packets must have a time stamp. Otherwise, the last written timestamp is repeated. |
[in] | packet_count | Number of packets to write. Also size of metadata in number of objects (when specified). |
[in,out] | report | Where to report errors. |
|
inlineinherited |
Get the number of written packets.
|
inherited |
Get the packet header size, based on the packet format.
This "header" comes before the classical 188-byte TS packet.
|
inherited |
Get the packet trailer size, based on the packet format.
This "trailer" comes after the classical 188-byte TS packet.
|
inlineinherited |
Get the file format.
|
inlineinherited |
Get the file format as a string.
|
protectedinherited |
Reset the stream format and counters.
[in] | format | Initial packet format. |
[in] | reader | Reader interface. If null, all read operations will fail. |
[in] | writer | Writer interface. If null, all write operations will fail. |
|
staticconstexpr |
Minimum buffer size.
Used to minimize buffer_size in constructor and setBufferSize().
|
staticconstexprinherited |
Maximum size in bytes of a packet header for non-TS format.
Must be lower than the TS packet size to allow auto-detection on read.
|
staticconstexprinherited |
Maximum size in bytes of a packet trailer for non-TS format.
Must be lower than the TS packet size to allow auto-detection on read.