Sources
Stream source abstractions for WebRTC SDK.
This module defines the StreamSource interface and concrete implementations for different video streaming sources (webcam, RTSP, video files, manual frames).
ManualSource
¶
Bases: StreamSource
Stream source for manually sent frames.
This source allows the user to programmatically send frames to be processed by the workflow using the send() method.
Source code in inference_sdk/webrtc/sources.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |
__init__()
¶
Initialize manual source.
Source code in inference_sdk/webrtc/sources.py
342 343 344 | |
configure_peer_connection(pc)
async
¶
Create manual track and add it to the peer connection.
Source code in inference_sdk/webrtc/sources.py
346 347 348 349 350 | |
get_initialization_params(config)
¶
Return manual mode flag.
Source code in inference_sdk/webrtc/sources.py
352 353 354 | |
send(frame)
¶
Send a frame to be processed by the workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
ndarray
|
BGR numpy array (H, W, 3) uint8 |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If session not started |
Source code in inference_sdk/webrtc/sources.py
356 357 358 359 360 361 362 363 364 365 366 367 | |
RTSPSource
¶
Bases: StreamSource
Stream source for RTSP camera streams.
This source doesn't create a local track - instead, the server captures the RTSP stream and sends processed video back to the client.
Source code in inference_sdk/webrtc/sources.py
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 | |
__init__(url)
¶
Initialize RTSP source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
RTSP URL (e.g., "rtsp://camera.local/stream") Credentials can be included: "rtsp://user:pass@host/stream" |
required |
Source code in inference_sdk/webrtc/sources.py
191 192 193 194 195 196 197 198 199 200 201 202 | |
configure_peer_connection(pc)
async
¶
Add receive-only video transceiver (server sends video to us).
Source code in inference_sdk/webrtc/sources.py
204 205 206 207 208 | |
get_initialization_params(config)
¶
Return RTSP URL for server to capture.
Source code in inference_sdk/webrtc/sources.py
210 211 212 213 | |
StreamSource
¶
Bases: ABC
Base interface for all stream sources.
A StreamSource is responsible for: 1. Configuring the RTCPeerConnection (adding tracks or transceivers) 2. Providing initialization parameters for the server 3. Cleaning up resources when done
Source code in inference_sdk/webrtc/sources.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
cleanup()
async
¶
Cleanup resources when session ends.
Default implementation does nothing. Override if cleanup is needed.
Source code in inference_sdk/webrtc/sources.py
67 68 69 70 71 72 | |
configure_peer_connection(pc)
abstractmethod
async
¶
Configure the peer connection for this source type.
This is where the source decides: - Whether to add a local track (webcam, video file, manual) - Whether to add a receive-only transceiver (RTSP) - Any other peer connection configuration
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pc
|
RTCPeerConnection
|
The RTCPeerConnection to configure |
required |
Source code in inference_sdk/webrtc/sources.py
37 38 39 40 41 42 43 44 45 46 47 48 49 | |
get_initialization_params(config)
abstractmethod
¶
Get parameters to send to server in /initialise_webrtc_worker payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
StreamConfig
|
Stream configuration with stream_output, data_output, etc. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Dict[str, Any]
|
Dictionary of parameters specific to this source type. |
|
Examples |
Dict[str, Any]
|
|
Dict[str, Any]
|
|
|
Dict[str, Any]
|
|
|
Dict[str, Any]
|
|
Source code in inference_sdk/webrtc/sources.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
VideoFileSource
¶
Bases: StreamSource
Stream source for video files.
Uploads video file via datachannel to the server, which processes it and streams results back. This is more efficient than frame-by-frame streaming for pre-recorded video files.
Supports two output modes: - Datachannel mode (default): Frames received as base64 JSON via datachannel. Higher bandwidth but includes all workflow output data inline. - Video track mode: Frames received via WebRTC video track with hardware- accelerated codec (H.264/VP8). Lower bandwidth, workflow data sent separately.
Source code in inference_sdk/webrtc/sources.py
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 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
__init__(path, on_upload_progress=None, use_datachannel_frames=True, realtime_processing=False)
¶
Initialize video file source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to video file (any format supported by FFmpeg) |
required |
on_upload_progress
|
Optional[UploadProgressCallback]
|
Optional callback called during upload with (uploaded_chunks, total_chunks). Use to track upload progress. |
None
|
use_datachannel_frames
|
bool
|
If enabled, frames are received through the datachannel. It consumes much more network bandwidth, but it provides guaranteed in-order and high quality delivery of the frames. If False, frames are received via WebRTC video track with hardware-accelerated codec (lower bandwidth). |
True
|
realtime_processing
|
bool
|
If True, process frames at original video FPS (throttled playback for live preview). If False (default), process all frames as fast as possible (batch mode). |
False
|
Source code in inference_sdk/webrtc/sources.py
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 | |
cleanup()
async
¶
No cleanup needed - upload channel is managed by peer connection.
Source code in inference_sdk/webrtc/sources.py
326 327 328 | |
configure_peer_connection(pc)
async
¶
Configure peer connection for video file upload.
Creates video_upload datachannel for file transfer. In video track mode, also adds a receive-only transceiver for processed video output.
Source code in inference_sdk/webrtc/sources.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
get_initialization_params(config)
¶
Return params for video file processing mode.
In datachannel mode (default), merges stream_output into data_output so frames are received as base64 via the inference datachannel. In video track mode, preserves stream_output for video track rendering.
Source code in inference_sdk/webrtc/sources.py
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 | |
start_upload()
async
¶
Start uploading the video file.
Called by session after connection is established. Uses self.on_upload_progress if provided.
Source code in inference_sdk/webrtc/sources.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
WebcamSource
¶
Bases: StreamSource
Stream source for local webcam/USB camera.
This source creates a local video track that captures frames from a webcam device using OpenCV and sends them to the server.
Source code in inference_sdk/webrtc/sources.py
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 | |
__init__(device_id=0, resolution=None)
¶
Initialize webcam source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_id
|
int
|
Camera device index (0 for default camera) |
0
|
resolution
|
Optional[Tuple[int, int]]
|
Optional (width, height) tuple to set camera resolution |
None
|
Source code in inference_sdk/webrtc/sources.py
146 147 148 149 150 151 152 153 154 155 156 157 158 | |
cleanup()
async
¶
Release webcam resources.
Source code in inference_sdk/webrtc/sources.py
178 179 180 181 | |
configure_peer_connection(pc)
async
¶
Create webcam video track and add it to the peer connection.
Source code in inference_sdk/webrtc/sources.py
160 161 162 163 164 165 166 167 168 169 | |
get_initialization_params(config)
¶
Return FPS if available.
Source code in inference_sdk/webrtc/sources.py
171 172 173 174 175 176 | |