Skip to content

Commit 0e5a56a

Browse files
authored
Merge pull request #1778 from roboflow/new-upload-format
New upload format for webrtc file
2 parents 664e444 + 914939f commit 0e5a56a

File tree

4 files changed

+247
-14
lines changed

4 files changed

+247
-14
lines changed

inference/core/env.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,12 @@
782782
WEBRTC_MODAL_USAGE_QUOTA_ENABLED = str2bool(
783783
os.getenv("WEBRTC_MODAL_USAGE_QUOTA_ENABLED", "False")
784784
)
785+
WEBRTC_DATA_CHANNEL_BUFFER_DRAINING_DELAY = float(
786+
os.getenv("WEBRTC_DATA_CHANNEL_BUFFER_DRAINING_DELAY", "0.1")
787+
)
788+
WEBRTC_DATA_CHANNEL_BUFFER_SIZE_LIMIT = int(
789+
os.getenv("WEBRTC_DATA_CHANNEL_BUFFER_SIZE_LIMIT", str(1024 * 1024)) # 1MB
790+
)
785791

786792
HTTP_API_SHARED_WORKFLOWS_THREAD_POOL_ENABLED = str2bool(
787793
os.getenv("HTTP_API_SHARED_WORKFLOWS_THREAD_POOL_ENABLED", "True")

inference/core/interfaces/webrtc_worker/entities.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class WebRTCOutput(BaseModel):
7272
serialized_output_data: Optional[Dict[str, Any]] = None
7373
video_metadata: Optional[WebRTCVideoMetadata] = None
7474
errors: List[str] = Field(default_factory=list)
75+
processing_complete: bool = False # Signals end of video file processing
7576

7677

7778
class WebRTCWorkerResult(BaseModel):
@@ -93,3 +94,18 @@ class DataOutputMode(str, Enum):
9394
NONE = "none" # None or [] -> no data sent
9495
ALL = "all" # ["*"] -> send all (skip images)
9596
SPECIFIC = "specific" # ["field1", "field2"] -> send only these
97+
98+
99+
# Video File Upload Protocol
100+
# Binary header: [chunk_index:u32][total_chunks:u32][payload]
101+
VIDEO_FILE_HEADER_SIZE = 8
102+
103+
104+
class VideoFileUploadState(str, Enum):
105+
"""State of video file upload."""
106+
107+
IDLE = "idle"
108+
UPLOADING = "uploading"
109+
COMPLETE = "complete"
110+
PROCESSING = "processing"
111+
ERROR = "error"

inference/core/interfaces/webrtc_worker/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ctypes
22
import datetime
33
import logging
4+
import struct
45
import time
56
from typing import Any, Dict, List, Optional, Tuple, Union
67

@@ -12,6 +13,7 @@
1213
from inference.core.env import DEBUG_WEBRTC_PROCESSING_LATENCY
1314
from inference.core.interfaces.camera.entities import VideoFrame as InferenceVideoFrame
1415
from inference.core.interfaces.stream.inference_pipeline import InferencePipeline
16+
from inference.core.interfaces.webrtc_worker.entities import VIDEO_FILE_HEADER_SIZE
1517
from inference.core.utils.roboflow import get_model_id_chunks
1618
from inference.core.workflows.execution_engine.entities.base import WorkflowImageData
1719
from inference.models.aliases import resolve_roboflow_model_alias
@@ -186,6 +188,19 @@ def workflow_contains_preloaded_model(
186188
return False
187189

188190

191+
# Video File Upload Protocol
192+
# Header: [chunk_index:u32][total_chunks:u32][payload]
193+
def parse_video_file_chunk(message: bytes) -> Tuple[int, int, bytes]:
194+
"""Parse video file chunk message.
195+
196+
Returns: (chunk_index, total_chunks, payload)
197+
"""
198+
if len(message) < VIDEO_FILE_HEADER_SIZE:
199+
raise ValueError(f"Message too short: {len(message)} bytes")
200+
chunk_index, total_chunks = struct.unpack("<II", message[:8])
201+
return chunk_index, total_chunks, message[8:]
202+
203+
189204
def warmup_cuda(
190205
max_retries: int = 10,
191206
retry_delay: float = 0.5,

0 commit comments

Comments
 (0)