Transport stream file, input and/or output.
More...
#include <tsTSFile.h>
|
| TSFile () |
| Default constructor.
|
|
| TSFile (TSFile &&other) noexcept |
| Move constructor.
|
|
virtual | ~TSFile () override |
| Destructor.
|
|
void | abort () |
| Abort any currenly read/write operation in progress.
|
|
bool | close (Report &report) |
| Close the file.
|
|
UString | getDisplayFileName () const |
| Get the file name as a display string.
|
|
fs::path | getFileName () const |
| Get the file name.
|
|
bool | isOpen () const |
| Check if the file is open.
|
|
virtual bool | open (const fs::path &filename, OpenFlags flags, Report &report, TSPacketFormat format=TSPacketFormat::AUTODETECT) |
| Open or create the file (generic form).
|
|
bool | openRead (const fs::path &filename, size_t repeat_count, uint64_t start_offset, Report &report, TSPacketFormat format=TSPacketFormat::AUTODETECT) |
| Open the file for read.
|
|
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.
|
|
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 | rewind (Report &report) |
| Rewind the file.
|
|
bool | seek (PacketCounter packet_index, Report &report) |
| Seek the file at a specified packet index.
|
|
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.
|
|
Transport stream file, input and/or output.
◆ OpenFlags
Flags for open().
Enumerator |
---|
NONE | No option, do not open the file.
|
READ | Read the file.
|
WRITE | Write the file.
|
APPEND | Append packets to an existing file.
|
KEEP | Keep previous file with same name. Fail if it already exists.
|
SHARED | Write open with shared read for other processes. Windows only. Always shared on Unix.
|
TEMPORARY | Temporary file, deleted on close, not always visible in the file system.
|
REOPEN | Close and reopen the file instead of rewind to start of file when looping on input file.
|
REOPEN_SPEC | Force REOPEN when the file is not a regular file.
|
◆ TSFile()
ts::TSFile::TSFile |
( |
TSFile && |
other | ) |
|
|
noexcept |
Move constructor.
The full state is moved The move constructor is required to have vectors of TSFile.
- Parameters
-
[in,out] | other | Other instance to move. Closed on return. |
◆ openRead() [1/2]
Open the file for read.
- Parameters
-
[in] | filename | File name. If empty or "-", use standard input. Must be a regular file if start_offset is not zero. If repeat_count is not 1 and the file is not a regular one, the file is closed and reopened instead of being rewound. |
[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. |
- Returns
- True on success, false on error.
◆ openRead() [2/2]
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.
- Parameters
-
[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. |
- Returns
- True on success, false on error.
- See also
- rewind()
-
seek()
◆ open()
Open or create the file (generic form).
The file is rewindable if the underlying file is seekable, eg. not a pipe.
- Parameters
-
[in] | filename | File name. If empty or "-", use standard input or output. If filename is empty, flags cannot contain both READ and WRITE. |
[in] | flags | Bit mask of open flags. |
[in,out] | report | Where to report errors. |
[in] | format | Format of the TS file. |
- Returns
- True on success, false on error.
Reimplemented in ts::TSFileOutputResync.
◆ isOpen()
bool ts::TSFile::isOpen |
( |
| ) |
const |
|
inline |
Check if the file is open.
- Returns
- True if the file is open.
◆ getFileName()
fs::path ts::TSFile::getFileName |
( |
| ) |
const |
|
inline |
Get the file name.
- Returns
- The file name.
◆ getDisplayFileName()
UString ts::TSFile::getDisplayFileName |
( |
| ) |
const |
Get the file name as a display string.
- Returns
- The file name as a display string. Not always a valid file name. Use in error messages only.
◆ close()
bool ts::TSFile::close |
( |
Report & |
report | ) |
|
Close the file.
- Parameters
-
[in,out] | report | Where to report errors. |
- Returns
- True on success, false on error.
◆ setStuffing()
void ts::TSFile::setStuffing |
( |
size_t |
initial, |
|
|
size_t |
final |
|
) |
| |
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.
- Parameters
-
[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. |
◆ abort()
void ts::TSFile::abort |
( |
| ) |
|
Abort any currenly read/write operation in progress.
The file is left in a broken state and can be only closed.
◆ rewind()
bool ts::TSFile::rewind |
( |
Report & |
report | ) |
|
|
inline |
Rewind the file.
The file must have been opened in rewindable mode. If the file file was opened with a start_offset different from 0, rewinding the file means restarting at this start_offset.
- Parameters
-
[in,out] | report | Where to report errors. |
- Returns
- True on success, false on error.
◆ seek()
Seek the file at a specified packet index.
The file must have been opened in rewindable mode.
- Parameters
-
[in] | packet_index | Seek the file to this specified packet index (plus the specified start_offset from open()). |
[in,out] | report | Where to report errors. |
- Returns
- True on success, false on error.
◆ readPackets()
Read TS packets from the stream.
- Parameters
-
[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. |
- Returns
- The actual number of read packets. Returning zero means error or end of stream.
Reimplemented from ts::TSPacketStream.
◆ writePackets()
Write TS packets to the stream.
- Parameters
-
[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. |
- Returns
- True on success, false on error.
◆ readPacketsCount()
Get the number of read packets.
- Returns
- The number of read packets.
◆ writePacketsCount()
Get the number of written packets.
- Returns
- The number of written packets.
◆ packetHeaderSize()
size_t ts::TSPacketStream::packetHeaderSize |
( |
| ) |
const |
|
inherited |
Get the packet header size, based on the packet format.
This "header" comes before the classical 188-byte TS packet.
- Returns
- The packet header size in bytes (before the TS packet).
◆ packetTrailerSize()
size_t ts::TSPacketStream::packetTrailerSize |
( |
| ) |
const |
|
inherited |
Get the packet trailer size, based on the packet format.
This "trailer" comes after the classical 188-byte TS packet.
- Returns
- The packet trailer size in bytes (before the TS packet).
◆ packetFormat()
Get the file format.
- Returns
- The file format.
◆ packetFormatString()
UString ts::TSPacketStream::packetFormatString |
( |
| ) |
const |
|
inlineinherited |
Get the file format as a string.
- Returns
- The file format as a string.
◆ resetPacketStream()
Reset the stream format and counters.
- Parameters
-
[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. |
◆ MAX_HEADER_SIZE
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.
◆ MAX_TRAILER_SIZE
constexpr size_t ts::TSPacketStream::MAX_TRAILER_SIZE = ts::RS_SIZE |
|
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.
The documentation for this class was generated from the following file: