ifm3dpy.rtsp.RtspClient

class ifm3dpy.rtsp.RtspClient

Bases: object

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

__init__(self: ifm3dpy.rtsp.RtspClient, device: ifm3dpy.device.Device, url: str | None = None, port: int | ifm3dpy.device.PortInfo = 8554, stream_path: str = 'port1', transport: ifm3dpy.rtsp.RtspClient.Transport = <Transport.INTERLEAVED: 0>, decoder: str | None = None) None

Constructs a client that streams from the given device.

Parameters
  • device (ifm3dpy.device.Device) – Device used to discover the stream IP (unless url is set).

  • url (str, optional) – Full RTSP URL override (e.g. rtsp://192.168.0.69:8554/port1). When unset the URL is built from the device IP, port and stream_path.

  • port (int or ifm3dpy.device.PortInfo, optional) – Either the RTSP server port, or the port whose RTSP endpoint should be streamed. When a PortInfo is given the RTSP port and the stream path are derived from its advertised RtspInfo when available, and stream_path is ignored. Used when url is unset.

  • stream_path (str, optional) – Stream path appended to the device IP, used when url is unset and port is not a PortInfo.

  • transport (ifm3dpy.rtsp.RtspClient.Transport, optional) – RTP transport selection.

  • decoder (str, optional) – Override the decoder name used for decoding h264 video into buffers. When unset the decoder is chosen automatically.

Methods

__init__(self, device, url, port, ...)

Constructs a client that streams from the given device.

get_state(self)

Returns the current session state.

is_running(self)

Returns true while the worker thread is running.

on_error(self[, callback])

Registers a callback invoked on terminal errors.

on_nal_unit(self[, callback])

Registers a callback invoked for each reassembled NAL unit.

on_new_frame(self[, callback])

Registers a callback invoked for each received frame.

on_state_change(self[, callback])

Registers a callback invoked on every session state transition.

start(self[, buffers])

Performs the RTSP handshake and starts streaming.

stop(self)

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

Nested types

State

Lifecycle state of the RTSP session.

Transport

RTP transport used for the media stream.

class State

Bases: IntEnum

Lifecycle state of the RTSP session.

CONNECTING = 1
FAILED = 5
IDLE = 0
PLAYING = 3
READY = 2
STOPPED = 4
class Transport

Bases: IntEnum

RTP transport used for the media stream.

INTERLEAVED = 0
UDP = 1
get_state(self: RtspClient) State

Returns the current session state.

is_running(self: RtspClient) bool

Returns true while the worker thread is running.

on_error(self: RtspClient, callback: Callable[[Error], None] = None) None

Registers a callback invoked on terminal errors.

on_nal_unit(self: RtspClient, callback: Callable[[NalUnit], None] = None) None

Registers a callback invoked for each reassembled NAL unit.

on_new_frame(self: RtspClient, callback: Callable[[Frame], None] = None) None

Registers a callback invoked for each received frame.

Parameters

callback (Callable[[ifm3dpy.framegrabber.Frame], None], optional) – The callback receiving each decoded frame. Pass None to remove a previously registered callback.

on_state_change(self: RtspClient, callback: Callable[[State], None] = None) None

Registers a callback invoked on every session state transition.

start(self: RtspClient, buffers: Sequence[buffer_id] = []) Awaitable

Performs the RTSP handshake and starts streaming.

Parameters

buffers (list[ifm3dpy.framegrabber.buffer_id], optional) – Buffers to make available on each received frame. Supported ids are COMPRESSED_H264_FRAME, RGB_IMAGE, YUV420_IMAGE and RGB_INFO. An empty list, the default, requests all four; each one costs additional per-frame work, so pass only what you consume.

Returns

Resolves once the stream is playing, or raises on failure.

Return type

Awaitable

stop(self: RtspClient) Awaitable

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

Returns

Resolves once the client has stopped.

Return type

Awaitable