Skip to content

Commit

Permalink
Add turn server configuration to webrtc connection
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz-roboflow committed Nov 12, 2024
1 parent 4b6b3d6 commit 69887c6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions inference/core/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,7 @@
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")
21 changes: 19 additions & 2 deletions inference/core/interfaces/stream_manager/manager_app/webrtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@
from typing import Dict, Optional, Tuple

import numpy as np
from aiortc import RTCPeerConnection, RTCSessionDescription, VideoStreamTrack
from aiortc import (
RTCConfiguration,
RTCIceServer,
RTCPeerConnection,
RTCSessionDescription,
VideoStreamTrack,
)
from aiortc.contrib.media import MediaRelay
from aiortc.mediastreams import MediaStreamError
from aiortc.rtcrtpreceiver import RemoteStreamTrack
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,
Expand Down Expand Up @@ -218,8 +229,14 @@ async def init_rtc_peer_connection(
webcam_fps=webcam_fps,
)

turn_server = RTCIceServer(
urls=[f"turn:{WEBRTC_TURN_IP}:3478"],
username=WEBRTC_TURN_USERNAME,
credential=WEBRTC_TURN_SHARED_SECRET,
)
peer_connection = RTCPeerConnectionWithFPS(
video_transform_track=video_transform_track
video_transform_track=video_transform_track,
configuration=RTCConfiguration(iceServers=[turn_server]),
)
relay = MediaRelay()

Expand Down

0 comments on commit 69887c6

Please sign in to comment.