TSDuck Version 3.15-955 (TSDuck - The MPEG Transport Stream Toolkit)
ts::TSFileInputBuffered Class Reference

Transport stream file input with a seekable buffer. More...

Inheritance diagram for ts::TSFileInputBuffered:
Collaboration diagram for ts::TSFileInputBuffered:

Public Member Functions

 TSFileInputBuffered (size_t buffer_size)
 Constructor. More...
 
virtual ~TSFileInputBuffered ()
 Destructor.
 
void abortRead ()
 Abort any currenly read operation in progress. More...
 
bool canSeek (PacketCounter position) const
 Check if we can seek to the specified absolute position. More...
 
bool close (Report &report)
 Close the file. More...
 
size_t getBackwardSeekableCount () const
 Get the backward seekable distance inside the buffer. More...
 
size_t getBufferedCount () const
 Get the number of TS packets in the buffer. More...
 
size_t getBufferFreeSize () const
 Get the size of the free space in the buffer. More...
 
size_t getBufferSize () const
 Get the buffer size. More...
 
int getErrorSeverityLevel () const
 Get the severity level for error reporting. More...
 
UString getFileName () const
 Get the file name. More...
 
size_t getForwardSeekableCount () const
 Get the forward seekable distance inside the buffer. More...
 
PacketCounter getPacketCount () const
 Get the number of read packets. More...
 
bool isOpen () const
 Check if the file is open. More...
 
bool open (const UString &filename, uint64_t start_offset, Report &report)
 Open the file in rewindable mode. More...
 
bool open (const UString &filename, size_t repeat_count, uint64_t start_offset, Report &report)
 Open the file. More...
 
size_t read (TSPacket *buffer, size_t max_packets, Report &report)
 Read TS packets. More...
 
bool seek (PacketCounter position, Report &report)
 Seek to the specified absolute position, if it is inside the buffer. More...
 
bool seekBackward (size_t packet_count, Report &report)
 Seek the file backward the specified number of packets. More...
 
bool seekForward (size_t packet_count, Report &report)
 Seek the file forward the specified number of packets. More...
 
bool setBufferSize (size_t buffer_size, Report &report)
 Set the buffer size. More...
 
void setErrorSeverityLevel (int level)
 Set the severity level for error reporting. More...
 

Static Public Attributes

static const size_t MIN_BUFFER_SIZE = 16
 Minimum buffer size. More...
 

Protected Attributes

UString _filename
 Input file name.
 
PacketCounter _total_packets
 Total read packets.
 

Detailed Description

Transport stream file input with a seekable buffer.

This variant of TSFileInput allows to seek back and forth to some extent without doing I/O's and can work on non-seekable files (pipes for instance).

Constructor & Destructor Documentation

◆ TSFileInputBuffered()

ts::TSFileInputBuffered::TSFileInputBuffered ( size_t  buffer_size)

Constructor.

Parameters
[in]buffer_sizeSize of the seekable buffer in number of TS packets.

Member Function Documentation

◆ setBufferSize()

bool ts::TSFileInputBuffered::setBufferSize ( size_t  buffer_size,
Report report 
)

Set the buffer size.

Can be done only when the file is closed.

Parameters
[in]buffer_sizeSize of the seekable buffer in number of TS packets.
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

◆ getBufferSize()

size_t ts::TSFileInputBuffered::getBufferSize ( ) const
inline

Get the buffer size.

Returns
The buffer size in number of TS packets.

◆ getBufferFreeSize()

size_t ts::TSFileInputBuffered::getBufferFreeSize ( ) const
inline

Get the size of the free space in the buffer.

Returns
The number of free TS packets in the buffer.

◆ getBufferedCount()

size_t ts::TSFileInputBuffered::getBufferedCount ( ) const
inline

Get the number of TS packets in the buffer.

Returns
The number of TS packets in the buffer.

◆ open() [1/2]

bool ts::TSFileInputBuffered::open ( const UString filename,
size_t  repeat_count,
uint64_t  start_offset,
Report report 
)

Open the file.

Override TSFileInput::open(). There is no rewindable version.

Parameters
[in]filenameFile 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_countReading packets loops back after end of file until all repeat are done. If zero, infinitely repeat.
[in]start_offsetOffset in bytes from the beginning of the file where to start reading packets at each iteration.
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

◆ read()

size_t ts::TSFileInputBuffered::read ( TSPacket buffer,
size_t  max_packets,
Report report 
)

Read TS packets.

If the file file was opened with a repeat_count different from 1, reading packets transparently loops back at end if file.

Parameters
[out]bufferAddress of reception packet buffer.
[in]max_packetsSize of buffer in packets.
[in,out]reportWhere to report errors.
Returns
The actual number of read packets. Returning zero means error or end of file repetition.

◆ getBackwardSeekableCount()

size_t ts::TSFileInputBuffered::getBackwardSeekableCount ( ) const
inline

Get the backward seekable distance inside the buffer.

This is the minimum guaranteed seekable distance.

Returns
The buffer size from the highest previously read packet or the beginning of file, whichever comes first.

◆ getForwardSeekableCount()

size_t ts::TSFileInputBuffered::getForwardSeekableCount ( ) const
inline

Get the forward seekable distance inside the buffer.

This is the minimum guaranteed seekable distance.

Returns
The highest previously read packet index, before backward seek.

◆ seekBackward()

bool ts::TSFileInputBuffered::seekBackward ( size_t  packet_count,
Report report 
)

Seek the file backward the specified number of packets.

Parameters
[in]packet_countThe number of packets to seek backward from the current position.
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

◆ seekForward()

bool ts::TSFileInputBuffered::seekForward ( size_t  packet_count,
Report report 
)

Seek the file forward the specified number of packets.

Parameters
[in]packet_countThe number of packets to seek forward from the current position.
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

◆ getPacketCount()

PacketCounter ts::TSFileInputBuffered::getPacketCount ( ) const

Get the number of read packets.

Returns
The number of read packets.

◆ canSeek()

bool ts::TSFileInputBuffered::canSeek ( PacketCounter  position) const

Check if we can seek to the specified absolute position.

Parameters
[in]positionAbsolute packet index in the file.
Returns
True if the specified position is inside the buffer.

◆ seek()

bool ts::TSFileInputBuffered::seek ( PacketCounter  position,
Report report 
)

Seek to the specified absolute position, if it is inside the buffer.

Parameters
[in]positionAbsolute packet index in the file.
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

◆ open() [2/2]

bool ts::TSFileInput::open ( const UString filename,
uint64_t  start_offset,
Report report 
)
inherited

Open the file 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]filenameFile name. If empty, use standard input.
[in]start_offsetOffset in bytes from the beginning of the file where to start reading packets.
[in,out]reportWhere to report errors.
Returns
True on success, false on error.
See also
rewind()
seek()

◆ isOpen()

bool ts::TSFileInput::isOpen ( ) const
inlineinherited

Check if the file is open.

Returns
True if the file is open.

◆ getErrorSeverityLevel()

int ts::TSFileInput::getErrorSeverityLevel ( ) const
inlineinherited

Get the severity level for error reporting.

Returns
The severity level for error reporting.

◆ setErrorSeverityLevel()

void ts::TSFileInput::setErrorSeverityLevel ( int  level)
inlineinherited

Set the severity level for error reporting.

Parameters
[in]levelThe severity level for error reporting. The default is Error.

◆ getFileName()

UString ts::TSFileInput::getFileName ( ) const
inlineinherited

Get the file name.

Returns
The file name.

◆ close()

bool ts::TSFileInput::close ( Report report)
inherited

Close the file.

Parameters
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

◆ abortRead()

void ts::TSFileInput::abortRead ( )
inherited

Abort any currenly read operation in progress.

The file is left in a broken state and can be only closed.

Member Data Documentation

◆ MIN_BUFFER_SIZE

const size_t ts::TSFileInputBuffered::MIN_BUFFER_SIZE = 16
static

Minimum buffer size.

Used to minimize buffer_size in constructor and setBufferSize().


The documentation for this class was generated from the following file: