TSDuck v3.40-4120
MPEG Transport Stream Toolkit
|
A specialized form of transport stream output file with resynchronized PID and continuity counters. More...
#include <tsTSFileOutputResync.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 | |
TSFileOutputResync () | |
Default constructor. | |
virtual | ~TSFileOutputResync () 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) override |
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. | |
bool | writePackets (TSPacket *buffer, const TSPacketMetadata *metadata, size_t packet_count, PID pid, Report &report) |
Write TS packets to the file. | |
bool | writePackets (TSPacket *buffer, const TSPacketMetadata *metadata, size_t packet_count, Report &report) |
Write TS packets to the file. | |
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. | |
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. | |
A specialized form of transport stream output file with resynchronized PID and continuity counters.
On each PID, the continuity counters are automatically updated and synchronized. It is also possible to force the PID of packets.
|
inherited |
Flags for open().
|
overridevirtual |
Open or create the file (generic form).
The file is rewindable if the underlying file is seekable, eg. not a pipe.
[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. |
Reimplemented from ts::TSFile.
bool ts::TSFileOutputResync::writePackets | ( | TSPacket * | buffer, |
const TSPacketMetadata * | metadata, | ||
size_t | packet_count, | ||
Report & | report | ||
) |
Write TS packets to the file.
[in,out] | buffer | Address of first packet to write. The continuity counters of all packets are modified. |
[in] | packet_count | Number of packets to write. |
[in,out] | report | Where to report errors. |
[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. |
bool ts::TSFileOutputResync::writePackets | ( | TSPacket * | buffer, |
const TSPacketMetadata * | metadata, | ||
size_t | packet_count, | ||
PID | pid, | ||
Report & | report | ||
) |
Write TS packets to the file.
[in,out] | buffer | Address of first packet to write. The continuity counters of all packets are modified. |
[in] | packet_count | Number of packets to write. |
[in] | pid | The PID of all packets is forced to this value. |
[in,out] | report | Where to report errors. |
[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. |
|
inherited |
Open the file for read.
[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. |
|
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.
|
inlineinherited |
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.
[in,out] | report | Where to report errors. |
|
inherited |
Seek the file at a specified packet index.
The file must have been opened in rewindable mode.
[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. |
|
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.
|
inlineinherited |
Get the number of read packets.
|
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. |
|
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.