Datachannel
WebRTC data channel binary chunking utilities.
ChunkReassembler
¶
Helper to reassemble chunked binary messages.
Source code in inference_sdk/webrtc/datachannel.py
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 73 74 75 76 77 78 79 80 81 | |
__init__()
¶
Initialize the chunk reassembler.
Source code in inference_sdk/webrtc/datachannel.py
39 40 41 42 43 44 | |
add_chunk(message)
¶
Parse and add a chunk, returning complete payload and frame_id if all chunks received.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
bytes
|
Raw binary message with 12-byte header |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Optional[bytes], Optional[int]]
|
Tuple of (payload, frame_id) if complete, (None, None) otherwise |
Source code in inference_sdk/webrtc/datachannel.py
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 73 74 75 76 77 78 79 80 81 | |
VideoFileUploader
¶
Uploads a video file through a WebRTC datachannel in chunks.
Protocol: [chunk_index:u32][total_chunks:u32][payload] Server auto-completes when all chunks received.
Features: - Backpressure handling via bufferedAmount monitoring - Progress callback support
Source code in inference_sdk/webrtc/datachannel.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 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 | |
file_size
property
¶
Size of the file in bytes.
total_chunks
property
¶
Total number of chunks to upload.
uploaded_chunks
property
¶
Number of chunks uploaded so far.
__init__(path, channel, chunk_size=WEBRTC_VIDEO_UPLOAD_CHUNK_SIZE, buffer_limit=WEBRTC_VIDEO_UPLOAD_BUFFER_LIMIT)
¶
Initialize video file uploader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the video file to upload |
required |
channel
|
RTCDataChannel
|
RTCDataChannel to send chunks through |
required |
chunk_size
|
int
|
Size of each chunk in bytes (default 48KB) |
WEBRTC_VIDEO_UPLOAD_CHUNK_SIZE
|
buffer_limit
|
int
|
Max buffered bytes before applying backpressure |
WEBRTC_VIDEO_UPLOAD_BUFFER_LIMIT
|
Source code in inference_sdk/webrtc/datachannel.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
upload(on_progress=None)
async
¶
Upload the file in chunks with backpressure handling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
on_progress
|
Optional[Callable[[int, int], None]]
|
Optional callback called after each chunk with (uploaded_chunks, total_chunks) |
None
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If channel closes during upload |
Source code in inference_sdk/webrtc/datachannel.py
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 | |
create_video_upload_chunk(chunk_index, total_chunks, data)
¶
Create a video upload chunk message.
Format: [chunk_index:u32][total_chunks:u32][payload] All integers are uint32 little-endian.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_index
|
int
|
Zero-based index of this chunk |
required |
total_chunks
|
int
|
Total number of chunks in the file |
required |
data
|
bytes
|
Chunk payload bytes |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
Binary message with 8-byte header + payload |
Source code in inference_sdk/webrtc/datachannel.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |