ifm3dpy.rtsp.RtspClient
- class ifm3dpy.rtsp.RtspClient
Bases:
objectRTSP/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 (unlessurlis 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,portandstream_path.port (
intorifm3dpy.device.PortInfo, optional) – Either the RTSP server port, or the port whose RTSP endpoint should be streamed. When aPortInfois given the RTSP port and the stream path are derived from its advertisedRtspInfowhen available, andstream_pathis ignored. Used whenurlis unset.stream_path (
str, optional) – Stream path appended to the device IP, used whenurlis unset andportis not aPortInfo.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
Lifecycle state of the RTSP session.
RTP transport used for the media stream.
- class State
Bases:
IntEnumLifecycle state of the RTSP session.
- CONNECTING = 1
- FAILED = 5
- IDLE = 0
- PLAYING = 3
- READY = 2
- STOPPED = 4
- 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. PassNoneto 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 areCOMPRESSED_H264_FRAME,RGB_IMAGE,YUV420_IMAGEandRGB_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