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

Secure Reliable Transport (SRT) Socket. More...

#include <tsSRTSocket.h>

Public Member Functions

 SRTSocket ()
 Constructor.
 
 ~SRTSocket ()
 Destructor.
 
bool close (Report &report=(ts::CerrReport::Instance()))
 Close the socket.
 
void defineArgs (Args &args)
 Add command line option definitions in an Args.
 
bool getMessageApi () const
 Check if the SRT socket uses the Message API.
 
int getSocket () const
 Get the underlying SRT socket handle (use with care).
 
bool getSockOpt (int optName, const char *optNameStr, void *optval, int &optlen, Report &report=(ts::CerrReport::Instance())) const
 Get SRT option.
 
bool loadArgs (DuckContext &duck, Args &args)
 Load arguments from command line.
 
bool open (Report &report=(ts::CerrReport::Instance()))
 Open the socket using parameters from the command line.
 
bool open (SRTSocketMode mode, const IPv4SocketAddress &local_address, const IPv4SocketAddress &remote_address, Report &report=(ts::CerrReport::Instance()))
 Open the socket.
 
bool peerDisconnected () const
 Check if the connection was disconnected by the peer.
 
bool receive (void *data, size_t max_size, size_t &ret_size, cn::microseconds &timestamp, Report &report=(ts::CerrReport::Instance()))
 Receive a message with timestamp.
 
bool receive (void *data, size_t max_size, size_t &ret_size, Report &report=(ts::CerrReport::Instance()))
 Receive a message.
 
bool reportStatistics (SRTStatMode mode=SRTStatMode::ALL, Report &report=(ts::CerrReport::Instance()))
 Get statistics about the socket and report them.
 
bool send (const void *data, size_t size, Report &report=(ts::CerrReport::Instance()))
 Send a message to the default destination address and port.
 
bool setAddresses (const UString &listener_address, const UString &caller_address, const UString &local_interface=UString(), Report &report=(ts::CerrReport::Instance()))
 Preset local and remote socket addresses in string form.
 
size_t totalReceivedBytes () const
 Get the total number of received bytes since the socket was opened.
 
size_t totalSentBytes () const
 Get the total number of sent bytes since the socket was opened.
 

Static Public Member Functions

static UString GetLibraryVersion ()
 Get the version of the SRT library.
 

Detailed Description

Secure Reliable Transport (SRT) Socket.

If the libsrt is not available during compilation of this class, all methods will fail with an error status.

See also
https://github.com/Haivision/srt
https://www.srtalliance.org/

Member Function Documentation

◆ open() [1/2]

bool ts::SRTSocket::open ( Report report = (ts::CerrReport::Instance()))
inline

Open the socket using parameters from the command line.

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

◆ open() [2/2]

bool ts::SRTSocket::open ( SRTSocketMode  mode,
const IPv4SocketAddress local_address,
const IPv4SocketAddress remote_address,
Report report = (ts::CerrReport::Instance()) 
)

Open the socket.

Parameters
[in]modeSRT socket mode. If set to DEFAULT, the mode must have been specified in the command line options.
[in]local_addressLocal socket address. Ignored in DEFAULT mode. Optional local IP address used in CALLER mode.
[in]remote_addressRemote socket address. Ignored in DEFAULT and LISTENER modes.
[in,out]reportWhere to report error.
Returns
True on success, false on error.

◆ close()

bool ts::SRTSocket::close ( Report report = (ts::CerrReport::Instance()))

Close the socket.

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

◆ defineArgs()

void ts::SRTSocket::defineArgs ( Args args)

Add command line option definitions in an Args.

Parameters
[in,out]argsCommand line arguments to update.

◆ loadArgs()

bool ts::SRTSocket::loadArgs ( DuckContext duck,
Args args 
)

Load arguments from command line.

Args error indicator is set in case of incorrect arguments.

Parameters
[in,out]duckTSDuck execution context.
[in,out]argsCommand line arguments.
Returns
True on success, false on error in argument line.

◆ setAddresses()

bool ts::SRTSocket::setAddresses ( const UString listener_address,
const UString caller_address,
const UString local_interface = UString(),
Report report = (ts::CerrReport::Instance()) 
)
inline

Preset local and remote socket addresses in string form.

  • If only listener_address is not empty, the socket is set in listener mode.
  • If only caller_address is not empty, the socket is set in caller mode.
  • If both strings are not empty, the socket is set in rendezvous mode.
  • If both strings are empty, the current mode of the socket is reset and local and/or remote addresses must be specified by command line arguments or through open().
    Parameters
    [in]listener_addressLocal "[address:]port".
    [in]caller_addressRemote "address:port".
    [in]local_interfaceOptional, can be empty. In caller mode, specify the local outgoing IP address.
    [in,out]reportWhere to report error.
    Returns
    True on success, false on error.

◆ send()

bool ts::SRTSocket::send ( const void *  data,
size_t  size,
Report report = (ts::CerrReport::Instance()) 
)

Send a message to the default destination address and port.

Parameters
[in]dataAddress of the message to send.
[in]sizeSize in bytes of the message to send.
[in,out]reportWhere to report error.
Returns
True on success, false on error.

◆ receive() [1/2]

bool ts::SRTSocket::receive ( void *  data,
size_t  max_size,
size_t &  ret_size,
Report report = (ts::CerrReport::Instance()) 
)

Receive a message.

Parameters
[out]dataAddress of the buffer for the received message.
[in]max_sizeSize in bytes of the reception buffer.
[out]ret_sizeSize in bytes of the received message. Will never be larger than max_size.
[in,out]reportWhere to report error.
Returns
True on success, false on error.

◆ receive() [2/2]

bool ts::SRTSocket::receive ( void *  data,
size_t  max_size,
size_t &  ret_size,
cn::microseconds &  timestamp,
Report report = (ts::CerrReport::Instance()) 
)

Receive a message with timestamp.

Parameters
[out]dataAddress of the buffer for the received message.
[in]max_sizeSize in bytes of the reception buffer.
[out]ret_sizeSize in bytes of the received message. Will never be larger than max_size.
[out]timestampSource timestamp in micro-seconds, negative if not available.
[in,out]reportWhere to report error.
Returns
True on success, false on error.

◆ totalSentBytes()

size_t ts::SRTSocket::totalSentBytes ( ) const

Get the total number of sent bytes since the socket was opened.

Returns
The total number of sent bytes since the socket was opened.

◆ totalReceivedBytes()

size_t ts::SRTSocket::totalReceivedBytes ( ) const

Get the total number of received bytes since the socket was opened.

Returns
The total number of received bytes since the socket was opened.

◆ peerDisconnected()

bool ts::SRTSocket::peerDisconnected ( ) const

Check if the connection was disconnected by the peer.

This can be used after a send/receive error to differentiate between "end of session" and actual error.

Returns
True if the connection was closed by the peer.

◆ reportStatistics()

bool ts::SRTSocket::reportStatistics ( SRTStatMode  mode = SRTStatMode::ALL,
Report report = (ts::CerrReport::Instance()) 
)

Get statistics about the socket and report them.

Parameters
[in]modeType of statistics to report (or'ing bitmask values is allowed).
[in,out]reportWhere to report statistics and errors.
Returns
True on success, false on error.

◆ getSockOpt()

bool ts::SRTSocket::getSockOpt ( int  optName,
const char *  optNameStr,
void *  optval,
int &  optlen,
Report report = (ts::CerrReport::Instance()) 
) const

Get SRT option.

Parameters
[in]optNameOption name as enumeration. The possible values for optName are given by the enumeration type SRT_SOCKOPT in libsrt. The profile of this method uses "int" to remain portable in the absence of libsrt, but the actual values come from SRT_SOCKOPT in libsrt.
[in]optNameStrOption name as ASCII string.
[out]optvalAddress of returned value.
[in,out]optlenSize of returned buffer (input), updated to size of returned value.
[in,out]reportWhere to report error.
Returns
True on success, false on error.

◆ getSocket()

int ts::SRTSocket::getSocket ( ) const

Get the underlying SRT socket handle (use with care).

This method is reserved for low-level operations and should not be used by normal applications.

Returns
The underlying SRT socket handle.

◆ getMessageApi()

bool ts::SRTSocket::getMessageApi ( ) const

Check if the SRT socket uses the Message API.

Returns
True if the SRT socket uses the Message API. False if it uses the Buffer API.

◆ GetLibraryVersion()

static UString ts::SRTSocket::GetLibraryVersion ( )
static

Get the version of the SRT library.

Returns
A string describing the SRT library version (or the lack of SRT support).

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