ifm3d
ifm3d::RtspClient Class Reference

RTSP/1.0 client that streams H.264 video from an ifm device and, optionally, decodes it into ifm3d::Buffer frames 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.
 
enum class  OutputFormat : std::uint8_t { RGB = 0 , YUV420 = 1 }
 Pixel layout of decoded frames delivered to OnNewFrame. More...
 
using Ptr = std::shared_ptr< RtspClient >
 
using NewFrameCallback = std::function< void(ifm3d::Buffer)>
 
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 ()
 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 decoded frame. More...
 
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::Buffer frames 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. When no decoder is available, or when the "null" decoder is selected via Config::decoder, the client operates in NAL-only mode and only the OnNalUnit callback fires.

Member Enumeration Documentation

◆ OutputFormat

enum ifm3d::RtspClient::OutputFormat : std::uint8_t
strong

Pixel layout of decoded frames delivered to OnNewFrame.

Enumerator
RGB 

3-channel RGB.

The decoded YUV420P frame is converted to a width x height x 3 ifm3d::Buffer of 8-bit RGB.

YUV420 

Raw planar I420 (YUV420P): a single-channel ifm3d::Buffer of width x (height * 3 / 2), with the full-resolution Y plane followed by the half-resolution U and V planes.

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

◆ OnNewFrame()

void ifm3d::RtspClient::OnNewFrame ( NewFrameCallback  callback = nullptr)

Registers a callback invoked for each decoded frame.

The Buffer carries any RGB_INFO SEI metadata in its JSON metadata.

◆ Start()

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

Performs the RTSP handshake and starts streaming.

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: