ifm3d
ifm3d::RtspClient Class Reference

RTSP/1.0 client that streams H.264 video from an ifm device and, optionally, decodes it into ifm3d::Frame instances using a compiled-in video decoder. More...

#include <ifm3d/rtsp/rtsp_client.h>

Classes

struct  Config
 Configuration for an RtspClient instance. More...
 

Public Types

enum class  Transport : std::uint8_t { INTERLEAVED = 0 , UDP = 1 }
 RTP transport used for the media stream. More...
 
enum class  State : std::uint8_t {
  IDLE = 0 , CONNECTING = 1 , READY = 2 , PLAYING = 3 ,
  STOPPED = 4 , FAILED = 5
}
 Lifecycle state of the RTSP session.
 
using Ptr = std::shared_ptr< RtspClient >
 
using BufferIdList = std::vector< ifm3d::buffer_id >
 
using NewFrameCallback = std::function< void(ifm3d::Frame::Ptr)>
 
using NalUnitCallback = std::function< void(const ifm3d::NalUnit &)>
 
using ErrorCallback = std::function< void(const ifm3d::Error &)>
 
using StateChangeCallback = std::function< void(State)>
 

Public Member Functions

 RtspClient (ifm3d::Device::Ptr device)
 Constructs a client that streams from the given device using the default configuration. More...
 
 RtspClient (ifm3d::Device::Ptr device, Config config)
 Constructs a client that streams from the given device. More...
 
 RtspClient (ifm3d::Device::Ptr device, const ifm3d::PortInfo &port)
 Constructs a client for a specific port, deriving the RTSP port and stream path from the port's advertised RtspInfo when available. More...
 
 RtspClient (ifm3d::Device::Ptr device, const ifm3d::PortInfo &port, Config config)
 Constructs a client for a specific port, deriving the RTSP port and stream path from the port's advertised RtspInfo when available. More...
 
 RtspClient (const RtspClient &)=delete
 
RtspClientoperator= (const RtspClient &)=delete
 
 RtspClient (RtspClient &&) noexcept
 
RtspClientoperator= (RtspClient &&) noexcept
 
std::shared_future< void > Start (const BufferIdList &buffers={})
 Performs the RTSP handshake and starts streaming. More...
 
std::shared_future< void > Stop ()
 Sends TEARDOWN, stops the worker thread and closes the socket. More...
 
bool IsRunning () const
 
State GetState () const
 
void OnNewFrame (NewFrameCallback callback=nullptr)
 Registers a callback invoked for each received frame.
 
void OnNalUnit (NalUnitCallback callback=nullptr)
 Registers a callback invoked for each reassembled NAL unit.
 
void OnError (ErrorCallback callback=nullptr)
 Registers a callback invoked on terminal errors.
 
void OnStateChange (StateChangeCallback callback=nullptr)
 Registers a callback invoked on every session state transition.
 

Detailed Description

RTSP/1.0 client that streams H.264 video from an ifm device and, optionally, decodes it into ifm3d::Frame instances using a compiled-in video decoder.

The client mirrors the threading model of ifm3d::FrameGrabber: it owns a single asio io_context running on a dedicated worker thread. All user-supplied callbacks are invoked on that thread, so callbacks must not block.

Decoding is delegated to a VideoDecoder selected by the ifm3d::DecoderManager; the core RTSP module never links against an H.264 decoder. The null decoder is selected automatically when no decoded image buffer is requested.

Member Enumeration Documentation

◆ Transport

enum ifm3d::RtspClient::Transport : std::uint8_t
strong

RTP transport used for the media stream.

Enumerator
INTERLEAVED 

RTP/AVP/TCP, interleaved on the RTSP control connection.

UDP 

RTP/AVP over UDP.

Constructor & Destructor Documentation

◆ RtspClient() [1/4]

ifm3d::RtspClient::RtspClient ( ifm3d::Device::Ptr  device)
explicit

Constructs a client that streams from the given device using the default configuration.

Parameters
[in]devicedevice used to discover the stream IP.

◆ RtspClient() [2/4]

ifm3d::RtspClient::RtspClient ( ifm3d::Device::Ptr  device,
Config  config 
)

Constructs a client that streams from the given device.

Parameters
[in]devicedevice used to discover the stream IP (unless config.url is set).
[in]configsession configuration.

◆ RtspClient() [3/4]

ifm3d::RtspClient::RtspClient ( ifm3d::Device::Ptr  device,
const ifm3d::PortInfo port 
)

Constructs a client for a specific port, deriving the RTSP port and stream path from the port's advertised RtspInfo when available.

Parameters
[in]devicedevice used to discover the stream IP.
[in]portport whose RTSP endpoint should be streamed.

◆ RtspClient() [4/4]

ifm3d::RtspClient::RtspClient ( ifm3d::Device::Ptr  device,
const ifm3d::PortInfo port,
Config  config 
)

Constructs a client for a specific port, deriving the RTSP port and stream path from the port's advertised RtspInfo when available.

Parameters
[in]devicedevice used to discover the stream IP (unless config.url is set).
[in]portport whose RTSP endpoint should be streamed.
[in]configsession configuration.

Member Function Documentation

◆ GetState()

State ifm3d::RtspClient::GetState ( ) const
Returns
the current session state.

◆ IsRunning()

bool ifm3d::RtspClient::IsRunning ( ) const
Returns
true while the worker thread is running.

◆ Start()

std::shared_future<void> ifm3d::RtspClient::Start ( const BufferIdList &  buffers = {})

Performs the RTSP handshake and starts streaming.

Parameters
[in]buffersbuffer IDs to receive. Supported IDs are COMPRESSED_H264_FRAME, RGB_IMAGE, YUV420_IMAGE and RGB_INFO
Returns
a future that resolves once the stream is playing, or that holds an ifm3d::Error on failure.

◆ Stop()

std::shared_future<void> ifm3d::RtspClient::Stop ( )

Sends TEARDOWN, stops the worker thread and closes the socket.

Returns
a future that resolves once the client has stopped.

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