Skip to content

Commit

Permalink
Merge pull request #801 from roboflow/feature/accept-webrtc-turn-conf…
Browse files Browse the repository at this point in the history
…ig-in-request

Pass webrtc TURN config as request parameter when calling POST /inference_pipelines/initialise_webrtc
  • Loading branch information
PawelPeczek-Roboflow authored Nov 13, 2024
2 parents a7e01e5 + f3cbe6b commit 91e792d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
4 changes: 0 additions & 4 deletions inference/core/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,3 @@
WORKFLOW_BLOCKS_WRITE_DIRECTORY = os.getenv("WORKFLOW_BLOCKS_WRITE_DIRECTORY")

DEDICATED_DEPLOYMENT_ID = os.getenv("DEDICATED_DEPLOYMENT_ID")

WEBRTC_TURN_IP = os.getenv("WEBRTC_TURN_IP")
WEBRTC_TURN_USERNAME = os.getenv("WEBRTC_TURN_USERNAME")
WEBRTC_TURN_SHARED_SECRET = os.getenv("WEBRTC_TURN_SHARED_SECRET")
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,15 @@ class WebRTCOffer(BaseModel):
sdp: str


class WebRTCTURNConfig(BaseModel):
urls: str
username: str
credential: str


class InitialiseWebRTCPipelinePayload(InitialisePipelinePayload):
webrtc_offer: WebRTCOffer
webrtc_turn_config: WebRTCTURNConfig
stream_output: Optional[List[str]] = Field(default_factory=list)
data_output: Optional[List[str]] = Field(default_factory=list)
webrtc_peer_timeout: float = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def start_loop(loop: asyncio.AbstractEventLoop):
t.start()

webrtc_offer = parsed_payload.webrtc_offer
webrtc_turn_config = parsed_payload.webrtc_turn_config
webcam_fps = parsed_payload.webcam_fps
to_inference_queue = SyncAsyncQueue(loop=loop)
from_inference_queue = SyncAsyncQueue(loop=loop)
Expand All @@ -251,6 +252,7 @@ def start_loop(loop: asyncio.AbstractEventLoop):
future = asyncio.run_coroutine_threadsafe(
init_rtc_peer_connection(
webrtc_offer=webrtc_offer,
webrtc_turn_config=webrtc_turn_config,
to_inference_queue=to_inference_queue,
from_inference_queue=from_inference_queue,
webrtc_peer_timeout=parsed_payload.webrtc_peer_timeout,
Expand Down
17 changes: 8 additions & 9 deletions inference/core/interfaces/stream_manager/manager_app/webrtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@
from av import VideoFrame

from inference.core import logger
from inference.core.env import (
WEBRTC_TURN_IP,
WEBRTC_TURN_SHARED_SECRET,
WEBRTC_TURN_USERNAME,
)
from inference.core.interfaces.camera.entities import (
SourceProperties,
VideoFrameProducer,
)
from inference.core.interfaces.stream_manager.manager_app.entities import WebRTCOffer
from inference.core.interfaces.stream_manager.manager_app.entities import (
WebRTCOffer,
WebRTCTURNConfig,
)
from inference.core.utils.async_utils import Queue as SyncAsyncQueue
from inference.core.utils.function import experimental

Expand Down Expand Up @@ -214,6 +212,7 @@ def __init__(self, video_transform_track: VideoTransformTrack, *args, **kwargs):

async def init_rtc_peer_connection(
webrtc_offer: WebRTCOffer,
webrtc_turn_config: WebRTCTURNConfig,
to_inference_queue: "SyncAsyncQueue[VideoFrame]",
from_inference_queue: "SyncAsyncQueue[np.ndarray]",
webrtc_peer_timeout: float,
Expand All @@ -230,9 +229,9 @@ async def init_rtc_peer_connection(
)

turn_server = RTCIceServer(
urls=[f"turn:{WEBRTC_TURN_IP}:3478"],
username=WEBRTC_TURN_USERNAME,
credential=WEBRTC_TURN_SHARED_SECRET,
urls=[webrtc_turn_config.urls],
username=webrtc_turn_config.username,
credential=webrtc_turn_config.credential,
)
peer_connection = RTCPeerConnectionWithFPS(
video_transform_track=video_transform_track,
Expand Down
2 changes: 1 addition & 1 deletion requirements/_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pybase64<2.0.0
scikit-image>=0.19.0
requests-toolbelt>=1.0.0
wheel>=0.38.1
setuptools>=70.0.0,<=72.1.0
setuptools>=70.0.0
pytest-asyncio<=0.21.1
networkx>=3.1
pydantic~=2.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements.sdk.http.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pillow>=9.0.0
requests>=2.27.0
supervision>=0.20.0,<1.0.0
numpy<=1.26.4
aiohttp>=3.9.0
aiohttp>=3.9.0,<=3.10.11
backoff>=2.2.0
aioresponses>=0.7.6
py-cpuinfo>=9.0.0

0 comments on commit 91e792d

Please sign in to comment.