Skip to content

Commit

Permalink
Use Twilio STUN/TURN servers in the sample apps (whitphx#1242)
Browse files Browse the repository at this point in the history
* Use Twilio STUN/TURN servers in the sample apps

* Skip type check in st.cache_data

* Install setuptools in the CI workflow to avoid an error
  • Loading branch information
whitphx authored Apr 25, 2023
1 parent 1a8c45d commit 173cfca
Show file tree
Hide file tree
Showing 17 changed files with 1,797 additions and 1,262 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:

- name: Install a specific version of Streamlit
if: ${{ matrix.streamlit-version }}
run: poetry add -D streamlit=="${STREAMLIT_VERSION}"
run: poetry add -D streamlit=="${STREAMLIT_VERSION}" setuptools
env:
STREAMLIT_VERSION: ${{ matrix.streamlit-version }}
- name: Install dependencies
Expand Down
4 changes: 3 additions & 1 deletion pages/10_sendonly_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
import streamlit as st
from streamlit_webrtc import WebRtcMode, webrtc_streamer

from sample_utils.turn import get_ice_servers

logger = logging.getLogger(__name__)


webrtc_ctx = webrtc_streamer(
key="sendonly-audio",
mode=WebRtcMode.SENDONLY,
audio_receiver_size=256,
rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]},
rtc_configuration={"iceServers": get_ice_servers()},
media_stream_constraints={"audio": True},
)

Expand Down
4 changes: 3 additions & 1 deletion pages/11_programatic_control_playing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import streamlit as st
from streamlit_webrtc import WebRtcMode, webrtc_streamer

from sample_utils.turn import get_ice_servers

playing = st.checkbox("Playing", value=True)

webrtc_streamer(
key="programatic_control",
desired_playing_state=playing,
mode=WebRtcMode.SENDRECV,
rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]},
rtc_configuration={"iceServers": get_ice_servers()},
)
4 changes: 3 additions & 1 deletion pages/12_media_constraints_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import streamlit as st
from streamlit_webrtc import WebRtcMode, webrtc_streamer

from sample_utils.turn import get_ice_servers

frame_rate = 5
webrtc_streamer(
key="media-constraints",
mode=WebRtcMode.SENDRECV,
rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]},
rtc_configuration={"iceServers": get_ice_servers()},
media_stream_constraints={
"video": {"frameRate": {"ideal": frame_rate}},
},
Expand Down
4 changes: 3 additions & 1 deletion pages/13_ui_texts_customization.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from streamlit_webrtc import webrtc_streamer

from sample_utils.turn import get_ice_servers

webrtc_streamer(
key="custom_ui_texts",
rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]},
rtc_configuration={"iceServers": get_ice_servers()},
translations={
"start": "開始",
"stop": "停止",
Expand Down
3 changes: 2 additions & 1 deletion pages/1_object_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from streamlit_webrtc import WebRtcMode, webrtc_streamer

from sample_utils.download import download_file
from sample_utils.turn import get_ice_servers

HERE = Path(__file__).parent
ROOT = HERE.parent
Expand Down Expand Up @@ -137,7 +138,7 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
webrtc_ctx = webrtc_streamer(
key="object-detection",
mode=WebRtcMode.SENDRECV,
rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]},
rtc_configuration={"iceServers": get_ice_servers()},
video_frame_callback=video_frame_callback,
media_stream_constraints={"video": True, "audio": False},
async_processing=True,
Expand Down
4 changes: 3 additions & 1 deletion pages/2_opencv_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import streamlit as st
from streamlit_webrtc import WebRtcMode, webrtc_streamer

from sample_utils.turn import get_ice_servers

_type = st.radio("Select transform type", ("noop", "cartoon", "edges", "rotate"))


Expand Down Expand Up @@ -49,7 +51,7 @@ def callback(frame: av.VideoFrame) -> av.VideoFrame:
webrtc_streamer(
key="opencv-filter",
mode=WebRtcMode.SENDRECV,
rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]},
rtc_configuration={"iceServers": get_ice_servers()},
video_frame_callback=callback,
media_stream_constraints={"video": True, "audio": False},
async_processing=True,
Expand Down
4 changes: 3 additions & 1 deletion pages/3_audio_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import streamlit as st
from streamlit_webrtc import WebRtcMode, webrtc_streamer

from sample_utils.turn import get_ice_servers

gain = st.slider("Gain", -10.0, +20.0, 1.0, 0.05)


Expand Down Expand Up @@ -32,7 +34,7 @@ def process_audio(frame: av.AudioFrame) -> av.AudioFrame:
webrtc_streamer(
key="audio-filter",
mode=WebRtcMode.SENDRECV,
rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]},
rtc_configuration={"iceServers": get_ice_servers()},
audio_frame_callback=process_audio,
async_processing=True,
)
4 changes: 3 additions & 1 deletion pages/4_delayed_echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import streamlit as st
from streamlit_webrtc import WebRtcMode, webrtc_streamer

from sample_utils.turn import get_ice_servers

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -34,7 +36,7 @@ async def queued_audio_frames_callback(
webrtc_streamer(
key="delay",
mode=WebRtcMode.SENDRECV,
rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]},
rtc_configuration={"iceServers": get_ice_servers()},
queued_video_frames_callback=queued_video_frames_callback,
queued_audio_frames_callback=queued_audio_frames_callback,
async_processing=True,
Expand Down
4 changes: 3 additions & 1 deletion pages/5_fork_multi_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import streamlit as st
from streamlit_webrtc import WebRtcMode, webrtc_streamer

from sample_utils.turn import get_ice_servers

st.markdown(
"""
Fork one input to multiple outputs with different video filters.
Expand Down Expand Up @@ -60,7 +62,7 @@ def callback(frame: av.VideoFrame) -> av.VideoFrame:
return callback


COMMON_RTC_CONFIG = {"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]}
COMMON_RTC_CONFIG = {"iceServers": get_ice_servers()}

st.header("Input")
ctx = webrtc_streamer(
Expand Down
4 changes: 3 additions & 1 deletion pages/6_mix_multi_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
webrtc_streamer,
)

from sample_utils.turn import get_ice_servers

st.markdown(
"""
Mix multiple inputs with different video filters into one stream.
Expand Down Expand Up @@ -112,7 +114,7 @@ def mixer_callback(frames: List[av.VideoFrame]) -> av.VideoFrame:
return new_frame


COMMON_RTC_CONFIG = {"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]}
COMMON_RTC_CONFIG = {"iceServers": get_ice_servers()}

st.header("Input 1")
input1_ctx = webrtc_streamer(
Expand Down
4 changes: 3 additions & 1 deletion pages/7_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from aiortc.contrib.media import MediaRecorder
from streamlit_webrtc import WebRtcMode, webrtc_streamer

from sample_utils.turn import get_ice_servers


def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
img = frame.to_ndarray(format="bgr24")
Expand Down Expand Up @@ -39,7 +41,7 @@ def out_recorder_factory() -> MediaRecorder:
webrtc_streamer(
key="record",
mode=WebRtcMode.SENDRECV,
rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]},
rtc_configuration={"iceServers": get_ice_servers()},
media_stream_constraints={
"video": True,
"audio": True,
Expand Down
3 changes: 2 additions & 1 deletion pages/8_media_files_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from streamlit_webrtc import WebRtcMode, WebRtcStreamerContext, webrtc_streamer

from sample_utils.download import download_file
from sample_utils.turn import get_ice_servers

HERE = Path(__file__).parent
ROOT = HERE.parent
Expand Down Expand Up @@ -112,7 +113,7 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
webrtc_streamer(
key=key,
mode=WebRtcMode.RECVONLY,
rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]},
rtc_configuration={"iceServers": get_ice_servers()},
media_stream_constraints={
"video": media_file_info["type"] == "video",
"audio": media_file_info["type"] == "audio",
Expand Down
4 changes: 3 additions & 1 deletion pages/9_sendonly_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import streamlit as st
from streamlit_webrtc import WebRtcMode, webrtc_streamer

from sample_utils.turn import get_ice_servers

logger = logging.getLogger(__name__)


webrtc_ctx = webrtc_streamer(
key="video-sendonly",
mode=WebRtcMode.SENDONLY,
rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]},
rtc_configuration={"iceServers": get_ice_servers()},
media_stream_constraints={"video": True},
)

Expand Down
Loading

0 comments on commit 173cfca

Please sign in to comment.