Client API Reference
pythorvision.client
Stream
Bases: BaseModel
Represents an active video stream and its associated resources.
Attributes:
Name | Type | Description |
---|---|---|
camera |
Camera
|
The camera being streamed. |
capability |
Capability
|
The capability used for the stream. |
port |
int
|
The network port used for the SRT stream. |
video_path |
Path
|
The path to the recorded video file. |
gstreamer_pipeline |
str
|
The GStreamer pipeline command used. |
process |
Popen
|
The Popen object for the running GStreamer process. |
gstreamer_log_file |
Optional[TextIOBase]
|
The file handle for GStreamer logs. |
gstreamer_log_file_path |
Optional[Path]
|
The path to the GStreamer log file. |
created_at |
datetime
|
The timestamp when the stream was created. |
ThorVisionClient
Bases: BaseModel
Client for interacting with the ThorVision server to manage camera streams.
Attributes:
Name | Type | Description |
---|---|---|
host |
str
|
The hostname or IP address of the ThorVision server. |
port |
int
|
The port number of the ThorVision server. |
streams |
Dict[int, Stream]
|
A dictionary of active streams, keyed by camera ID. |
__del__
clean_streams
Stop all active streams and clean up all resources.
This is useful for gracefully shutting down the client.
Source code in pythorvision/client.py
list_cameras
Retrieve a list of available cameras from the ThorVision server.
Returns:
Type | Description |
---|---|
List[Camera]
|
List[Camera]: A list of Camera objects. |
Raises:
Type | Description |
---|---|
RequestException
|
If there is an issue communicating with the server. |
Source code in pythorvision/client.py
model_post_init
Initialize the client after the model is created.
This method sets up the base URL for the server and performs initial checks for server connectivity and GStreamer installation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__context
|
Any
|
The context for model initialization. |
required |
Source code in pythorvision/client.py
start_stream_with_recording
start_stream_with_recording(camera, capability, output_dir, split_max_files=0, split_max_time_sec=0, split_max_size_mb=0, gstreamer_debug=False)
Start a camera stream and record it to a file.
This method requests the server to start streaming a camera's feed, then launches a local GStreamer process to receive and record the stream. The recording can be split into multiple files based on time, size, or number of files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
camera
|
Camera
|
The camera to start streaming. |
required |
capability
|
Capability
|
The desired stream capability (resolution, format, etc.). |
required |
output_dir
|
str
|
The directory to save the recording files. |
required |
split_max_files
|
Optional[int]
|
The maximum number of files to create before overwriting. 0 for no limit. Defaults to 0. |
0
|
split_max_time_sec
|
Optional[int]
|
The maximum duration of each file in seconds. 0 for no limit. Defaults to 0. |
0
|
split_max_size_mb
|
Optional[int]
|
The maximum size of each file in megabytes. 0 for no limit. Defaults to 0. |
0
|
gstreamer_debug
|
bool
|
If True, enables GStreamer debug logging. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
Stream |
Stream
|
A Stream object representing the active stream. |
Raises:
Type | Description |
---|---|
ValueError
|
If the selected capability is not a supported format. |
RuntimeError
|
If the stream fails to start on the server or if the local GStreamer process fails. |
Source code in pythorvision/client.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
stop_stream
Stop the stream for a specific camera.
This terminates the local GStreamer process by sending an interrupt signal, allowing it to finalize recordings. It then sends a request to the server to stop sending the stream.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
camera_id
|
int
|
The ID of the camera to stop. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If no active stream is found for the given camera ID. |