Appearance
modules.vision.streaming.rtsp_stream
Classes Diagram
Module Dependencies
Classes
RtspSource
Inherits from: VideoSource, VideoRecorder
RTSP source + recorder using GStreamer.
This class builds a GStreamer pipeline that reads an RTSP H264 stream, decodes
frames for use in the application (via an appsink) and optionally records the
incoming H264 stream to disk (via separate pipelines). It implements the
VideoSource interface (frame retrieval) and VideoRecorder (start/stop
recording).
Notes: \
- Frame format exposed by
get_frame()is a BGR numpy array compatible
with OpenCV.
- Recording is reference-counted: multiple callers can callstart_recording()and must balance withstop_recording().
Constructor
RtspSource(self, rtsp_url: str, camera_name: str)
Members
_camera_name
_record_requests: int
_app_pipeline: Gst.Pipeline | None
_rec_pipeline: Gst.Pipeline | None
_app_sink: GstApp.AppSink | None
_plays: bool
_last_frame
_fps: float
_current_recording_file
_rtsp_url
Methods
_create_pipeline(self, pipeline_str: str) → None
Create the GST pipeline according to the provided description.
Args:
pipeline_str: the pipeline description.
Returns:
_connect(self) → None
_create_recording_pipeline(rtsp_url: str, output_file: str) → Gst.Pipeline
Create a fresh recording pipeline for each recording session.
_handle_new_sample(self, sink: GstApp.AppSink) → Gst.FlowReturn
GStreamer appsink callback to handle a new decoded sample.
The BGR sample is stored in self._last_frame for retrieval by the
consumer via get_frame().
Args:
sink: The GstApp.AppSink that emitted the "new-sample" signal.
Returns:
A Gst.FlowReturn value. Returns Gst.FlowReturn.OK on success so the
pipeline continues, and Gst.FlowReturn.ERROR on unrecoverable
failures.
start(self) → None
@override
Start playing the RTSP pipeline.
Transitions the internal GStreamer pipeline into PLAYING state so that
frames start being decoded and delivered.
Raises:
RuntimeError: If GStreamer fails to change to the PLAYING state.
stop(self) → None
@override
Stop the RTSP pipeline and release resources.
Transitions the pipeline to NULL state. Consumers should call this
when the source is no longer needed to easy the CPU & memory usage of GST.
Calling this function will also stop the pending recording if one is being done.
Raises:
RuntimeError: If GStreamer fails to change to the NULL state.
start_recording(self, saving_path: str) → None
@override
Begin recording the incoming stream to disk.
This method is reference-counted: the first caller will create a new
recording fragment and open the recorder. Callers must match with stop_recording() to actually stop the recording.
_stop_recording_pipeline(self) → None
Stop a previously requested recording.
Decrements the internal record-request counter. When the counter reaches
zero the recorder valve is closed so that recording stops. The method
does nothing if recording was not active, but callers should ensure
balanced start/stop calls.
stop_recording(self) → None
@override
Stop recording and finalize the file.
get_fps(self) → float
@override
Return the frames-per-second of the incoming stream.
get_frame(self) → tuple[bool, any]
@override
Retrieve the most recent frame.
is_opened(self) → bool
@override
Check if the stream is active.