Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add turn server configuration to webrtc connection #799

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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