2626from inference .core import logger
2727from inference .core .env import (
2828 WEBRTC_DATA_CHANNEL_BUFFER_DRAINING_DELAY ,
29+ WEBRTC_DATA_CHANNEL_BUFFER_SIZE_LIMIT ,
2930 WEBRTC_MODAL_PUBLIC_STUN_SERVERS ,
3031 WEBRTC_MODAL_RTSP_PLACEHOLDER ,
3132 WEBRTC_MODAL_RTSP_PLACEHOLDER_URL ,
7172# WebRTC data channel chunking configuration
7273CHUNK_SIZE = 48 * 1024 # 48KB - safe for all WebRTC implementations
7374
74- # Rate limiting for data channel sends (prevents SCTP buffer overflow)
75- DATA_CHANNEL_BUFFER_SIZE_LIMIT = 1024 * 1024 # 1MB
76-
7775
7876def create_chunked_binary_message (
7977 frame_id : int , chunk_index : int , total_chunks : int , payload : bytes
@@ -149,7 +147,6 @@ class VideoFileUploadHandler:
149147 """
150148
151149 def __init__ (self ):
152- import tempfile
153150
154151 self ._chunks : Dict [int , bytes ] = {}
155152 self ._total_chunks : Optional [int ] = None
@@ -174,6 +171,7 @@ def handle_chunk(self, chunk_index: int, total_chunks: int, data: bytes) -> None
174171 logger .info ("Upload progress: %s/%s chunks" , len (self ._chunks ), total_chunks )
175172
176173 # Auto-complete when all chunks received
174+ # TODO: Handle the file writing without keeping all chunks in memory
177175 if len (self ._chunks ) == total_chunks :
178176 self ._write_to_temp_file ()
179177 self ._state = VideoFileUploadState .COMPLETE
@@ -242,7 +240,7 @@ async def send_chunked_data(
242240 return
243241
244242 sleep_count = 0
245- while data_channel .bufferedAmount > DATA_CHANNEL_BUFFER_SIZE_LIMIT :
243+ while data_channel .bufferedAmount > WEBRTC_DATA_CHANNEL_BUFFER_SIZE_LIMIT :
246244 sleep_count += 1
247245 if sleep_count % 10 == 0 :
248246 logger .debug (
0 commit comments