TSDuck v3.38-3699
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::TSForkPipe Class Reference

A subclass of ts::ForkPipe which exchanges TS packets on the pipe. More...

#include <tsTSForkPipe.h>

Inheritance diagram for ts::TSForkPipe:
Collaboration diagram for ts::TSForkPipe:

Public Types

enum  InputMode {
  STDIN_PARENT ,
  STDIN_PIPE ,
  STDIN_NONE
}
 How to standard input in the created process. More...
 
enum  OutputMode {
  KEEP_BOTH ,
  STDOUT_ONLY ,
  STDERR_ONLY ,
  STDOUT_PIPE ,
  STDOUTERR_PIPE
}
 How to merge standard output and standard error in the created process. More...
 
using SuperClass = std::basic_ostream< char >
 Explicit reference to the public superclass.
 
enum  WaitMode {
  ASYNCHRONOUS ,
  SYNCHRONOUS ,
  EXIT_PROCESS
}
 How to wait for the created process when close() is invoked. More...
 

Public Member Functions

 TSForkPipe ()
 Default constructor.
 
virtual ~TSForkPipe () override
 Destructor.
 
void abortPipeReadWrite ()
 Abort any currenly input/output operation in the pipe.
 
bool close (Report &report)
 Close the pipe.
 
virtual bool endOfStream () override
 Check if the end of stream was reached.
 
bool getIgnoreAbort () const
 Get "ignore abort".
 
bool isBroken () const
 Check if the pipe was broken.
 
bool isOpen () const
 Check if the process is running and the pipe is open (when used).
 
bool isSynchronous () const
 Check if synchronous mode is active (ie.
 
bool open (const UString &command, WaitMode wait_mode, size_t buffer_size, Report &report, OutputMode out_mode, InputMode in_mode)
 Create the process, open the optional pipe.
 
bool open (const UString &command, WaitMode wait_mode, size_t buffer_size, Report &report, OutputMode out_mode, InputMode in_mode, TSPacketFormat format=TSPacketFormat::AUTODETECT)
 Create the process, open the optional pipe.
 
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)
 Read TS packets from the stream.
 
PacketCounter readPacketsCount () const
 Get the number of read packets.
 
virtual bool readStreamChunks (void *addr, size_t max_size, size_t chunk_size, size_t &ret_size, Report &report)
 Read chunks of data from the stream.
 
virtual bool readStreamComplete (void *addr, size_t max_size, size_t &ret_size, Report &report)
 Read complete data from the stream.
 
virtual bool readStreamPartial (void *addr, size_t max_size, size_t &ret_size, Report &report) override
 Read partial data from the stream.
 
void setIgnoreAbort (bool on)
 Set "ignore abort".
 
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.
 
virtual bool writeStream (const void *addr, size_t size, size_t &written_size, Report &report) override
 Write data to the stream.
 

Static Public Member Functions

static bool Launch (const UString &command, Report &report, OutputMode out_mode=KEEP_BOTH, InputMode in_mode=STDIN_PARENT)
 This static method asynchronously launches a command, without pipe, without waiting for the completion of the command process.
 

Static Public Attributes

static constexpr size_t DEFAULT_STREAM_BUFFER_SIZE = 1024
 Default stream buffer size in bytes.
 
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.
 
virtual bool writeStreamBuffer (const void *addr, size_t size) override
 Write buffered data to underlying output devicen whatever it is.
 

Protected Attributes

PacketCounter _total_read = 0
 Total read packets.
 
PacketCounter _total_write = 0
 Total written packets.
 

Detailed Description

A subclass of ts::ForkPipe which exchanges TS packets on the pipe.

Member Enumeration Documentation

◆ WaitMode

enum ts::ForkPipe::WaitMode
inherited

How to wait for the created process when close() is invoked.

No pipe can be used with EXIT_PROCESS because there would be nobody on the other end of the pipe.

Enumerator
ASYNCHRONOUS 

Don't wait, close() will return immediately.

SYNCHRONOUS 

Wait for process completion during close().

EXIT_PROCESS 

Exit parent process during open(). UNIX: call exec(), Windows: call exit() after process creation.

◆ InputMode

enum ts::ForkPipe::InputMode
inherited

How to standard input in the created process.

The pipe can be used either on input or output, but not both. So, STDIN_PIPE is also forbidden with output mode is either STDOUT_PIPE or STDOUTERR_PIPE.

Enumerator
STDIN_PARENT 

Keep same stdin as current (parent) process.

STDIN_PIPE 

Use the pipe as stdin.

STDIN_NONE 

No standard input (the null device in fact).

◆ OutputMode

enum ts::ForkPipe::OutputMode
inherited

How to merge standard output and standard error in the created process.

Enumerator
KEEP_BOTH 

Keep same stdout and stderr as current (parent) process.

STDOUT_ONLY 

Merge stderr into current stdout.

STDERR_ONLY 

Merge stdout into current stderr.

STDOUT_PIPE 

Use the pipe to receive stdout, keep same stderr as current (parent) process.

STDOUTERR_PIPE 

Use the pipe to receive a merge of stdout and stderr.

Member Function Documentation

◆ open() [1/2]

bool ts::TSForkPipe::open ( const UString command,
WaitMode  wait_mode,
size_t  buffer_size,
Report report,
OutputMode  out_mode,
InputMode  in_mode,
TSPacketFormat  format = TSPacketFormat::AUTODETECT 
)

Create the process, open the optional pipe.

Parameters
[in]commandThe command to execute.
[in]wait_modeHow to wait for process termination in close().
[in]buffer_sizeThe pipe buffer size in bytes. Used on Windows only. Zero means default.
[in,out]reportWhere to report errors.
[in]out_modeHow to handle stdout and stderr.
[in]in_modeHow to handle stdin. Use the pipe by default. When set to KEEP_STDIN, no pipe is created.
[in]formatFormat of the TS streams over the pipe.
Returns
True on success, false on error. Do not return on success when wait_mode is EXIT_PROCESS.

◆ open() [2/2]

bool ts::ForkPipe::open ( const UString command,
WaitMode  wait_mode,
size_t  buffer_size,
Report report,
OutputMode  out_mode,
InputMode  in_mode 
)
inherited

Create the process, open the optional pipe.

Parameters
[in]commandThe command to execute.
[in]wait_modeHow to wait for process termination in close().
[in]buffer_sizeThe pipe buffer size in bytes. Used on Windows only. Zero means default.
[in,out]reportWhere to report errors.
[in]out_modeHow to handle stdout and stderr.
[in]in_modeHow to handle stdin. Use the pipe by default. When set to KEEP_STDIN, no pipe is created.
Returns
True on success, false on error. Do not return on success when wait_mode is EXIT_PROCESS.

◆ close()

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

Close the pipe.

Optionally wait for process termination if wait_mode was SYNCHRONOUS on open().

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

◆ isOpen()

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

Check if the process is running and the pipe is open (when used).

Returns
True if the process is running and the pipe is open.

◆ isBroken()

bool ts::ForkPipe::isBroken ( ) const
inlineinherited

Check if the pipe was broken.

Returns
True if was broken (unexpected process termination for instance).

◆ isSynchronous()

bool ts::ForkPipe::isSynchronous ( ) const
inlineinherited

Check if synchronous mode is active (ie.

will wait for process termination).

Returns
True if synchronous mode is active.

◆ setIgnoreAbort()

void ts::ForkPipe::setIgnoreAbort ( bool  on)
inlineinherited

Set "ignore abort".

Parameters
[in]onIf true and the process aborts, do not report error when writing data. when writing data.

◆ getIgnoreAbort()

bool ts::ForkPipe::getIgnoreAbort ( ) const
inlineinherited

Get "ignore abort".

Returns
True if, when the process aborts, do not report error when writing data.

◆ abortPipeReadWrite()

void ts::ForkPipe::abortPipeReadWrite ( )
inherited

Abort any currenly input/output operation in the pipe.

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

◆ Launch()

static bool ts::ForkPipe::Launch ( const UString command,
Report report,
OutputMode  out_mode = KEEP_BOTH,
InputMode  in_mode = STDIN_PARENT 
)
staticinherited

This static method asynchronously launches a command, without pipe, without waiting for the completion of the command process.

Parameters
[in]commandThe command to execute.
[in,out]reportWhere to report errors.
[in]out_modeHow to handle stdout and stderr. Keep both by default. Output modes using pipes are forbidden.
[in]in_modeHow to handle stdin. Keep the parent input by default. Input modes using pipes are forbidden.
Returns
True on success, false on error.

◆ endOfStream()

virtual bool ts::ForkPipe::endOfStream ( )
overridevirtualinherited

Check if the end of stream was reached.

Returns
True on end of stream, false otherwise.

Implements ts::AbstractReadStreamInterface.

◆ readStreamPartial()

virtual bool ts::ForkPipe::readStreamPartial ( void *  addr,
size_t  max_size,
size_t &  ret_size,
Report report 
)
overridevirtualinherited

Read partial data from the stream.

Wait and read at least one byte. Don't try to read exactly max_size bytes. If ret_size is less than max_bytes, it is possible to read more.

Parameters
[out]addrAddress of the buffer for the incoming data.
[in]max_sizeMaximum size in bytes of the buffer.
[out]ret_sizeReturned input size in bytes. If zero, end of file has been reached or an error occurred.
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

Implements ts::AbstractReadStreamInterface.

◆ writeStream()

virtual bool ts::ForkPipe::writeStream ( const void *  addr,
size_t  size,
size_t &  written_size,
Report report 
)
overridevirtualinherited

Write data to the stream.

All bytes are written to the stream, blocking or retrying when necessary.

Parameters
[in]addrAddress of the data to write.
[in]sizeSize in bytes of the data to write.
[out]written_sizeActually written size in bytes. Can be less than size in case of error in the middle of the write.
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

Implements ts::AbstractWriteStreamInterface.

◆ writeStreamBuffer()

virtual bool ts::ForkPipe::writeStreamBuffer ( const void *  addr,
size_t  size 
)
overrideprotectedvirtualinherited

Write buffered data to underlying output devicen whatever it is.

Must be implemented by subclasses.

Parameters
[in]addrBuffered data address.
[in]sizeBuffered data size in bytes.
Returns
True on success, false on error.

Implements ts::AbstractOutputStream.

◆ readStreamComplete()

virtual bool ts::AbstractReadStreamInterface::readStreamComplete ( void *  addr,
size_t  max_size,
size_t &  ret_size,
Report report 
)
virtualinherited

Read complete data from the stream.

Wait and read exactly max_size bytes. If ret_size is less than max_bytes, it is not possible to read more. End of file has probably been reached.

Parameters
[out]addrAddress of the buffer for the incoming data.
[in]max_sizeMaximum size in bytes of the buffer.
[out]ret_sizeReturned input size in bytes.
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

◆ readStreamChunks()

virtual bool ts::AbstractReadStreamInterface::readStreamChunks ( void *  addr,
size_t  max_size,
size_t  chunk_size,
size_t &  ret_size,
Report report 
)
virtualinherited

Read chunks of data from the stream.

Parameters
[out]addrAddress of the buffer for the incoming data.
[in]max_sizeMaximum size in bytes of the buffer.
[in]chunk_sizeIf not zero, make sure that the input size is always a multiple of chunk_size. If the initial read ends in the middle of a chunk, read again and again, up to the end of the current chunk or end of file.
[out]ret_sizeReturned input size in bytes.
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

◆ readPackets()

virtual size_t ts::TSPacketStream::readPackets ( TSPacket buffer,
TSPacketMetadata metadata,
size_t  max_packets,
Report report 
)
virtualinherited

Read TS packets from the stream.

Parameters
[out]bufferAddress of reception packet buffer.
[out]metadataOptional packet metadata. If the file format provides time stamps, they are set in the metadata. Ignored if null pointer.
[in]max_packetsSize of buffer in packets. Also size of metadata in number of objects (when specified).
[in,out]reportWhere to report errors.
Returns
The actual number of read packets. Returning zero means error or end of stream.

Reimplemented in ts::TSFile.

◆ writePackets()

virtual bool ts::TSPacketStream::writePackets ( const TSPacket buffer,
const TSPacketMetadata metadata,
size_t  packet_count,
Report report 
)
virtualinherited

Write TS packets to the stream.

Parameters
[in]bufferAddress of first packet to write.
[in]metadataOptional 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_countNumber of packets to write. Also size of metadata in number of objects (when specified).
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

◆ readPacketsCount()

PacketCounter ts::TSPacketStream::readPacketsCount ( ) const
inlineinherited

Get the number of read packets.

Returns
The number of read packets.

◆ writePacketsCount()

PacketCounter ts::TSPacketStream::writePacketsCount ( ) const
inlineinherited

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()

TSPacketFormat ts::TSPacketStream::packetFormat ( ) const
inlineinherited

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()

void ts::TSPacketStream::resetPacketStream ( TSPacketFormat  format,
AbstractReadStreamInterface reader,
AbstractWriteStreamInterface writer 
)
protectedinherited

Reset the stream format and counters.

Parameters
[in]formatInitial packet format.
[in]readerReader interface. If null, all read operations will fail.
[in]writerWriter interface. If null, all write operations will fail.

Member Data Documentation

◆ MAX_HEADER_SIZE

constexpr size_t ts::TSPacketStream::MAX_HEADER_SIZE = ts::TSPacketMetadata::SERIALIZATION_SIZE
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.

◆ 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: