mirror of
https://github.com/HumanAIGC-Engineering/gradio-webrtc.git
synced 2026-02-05 09:59:22 +08:00
* Allow extra tracks (#231) * Add allow_extra_tracks to WebRTC component --------- Co-authored-by: Marcus Valtonen Örnhag <marcus.valtonen.ornhag@ericsson.com>
This commit is contained in:
committed by
GitHub
parent
e89f0699b5
commit
aed34825e3
@@ -65,6 +65,7 @@ class Stream(WebRTCConnectionMixin):
|
||||
modality: Literal["video", "audio", "audio-video"] = "video",
|
||||
concurrency_limit: int | None | Literal["default"] = "default",
|
||||
time_limit: float | None = None,
|
||||
allow_extra_tracks: bool = False,
|
||||
rtp_params: dict[str, Any] | None = None,
|
||||
rtc_configuration: dict[str, Any] | None = None,
|
||||
track_constraints: dict[str, Any] | None = None,
|
||||
@@ -85,6 +86,7 @@ class Stream(WebRTCConnectionMixin):
|
||||
int | Literal["default"] | None, concurrency_limit
|
||||
)
|
||||
self.time_limit = time_limit
|
||||
self.allow_extra_tracks = allow_extra_tracks
|
||||
self.additional_output_components = additional_outputs
|
||||
self.additional_input_components = additional_inputs
|
||||
self.additional_outputs_handler = additional_outputs_handler
|
||||
|
||||
@@ -82,6 +82,7 @@ class WebRTC(Component, WebRTCConnectionMixin):
|
||||
rtc_configuration: dict[str, Any] | None = None,
|
||||
track_constraints: dict[str, Any] | None = None,
|
||||
time_limit: float | None = None,
|
||||
allow_extra_tracks: bool = False,
|
||||
mode: Literal["send-receive", "receive", "send"] = "send-receive",
|
||||
modality: Literal["video", "audio", "audio-video"] = "video",
|
||||
rtp_params: dict[str, Any] | None = None,
|
||||
@@ -114,6 +115,7 @@ class WebRTC(Component, WebRTCConnectionMixin):
|
||||
rtc_configuration: WebRTC configuration options. See https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection . If running the demo on a remote server, you will need to specify a rtc_configuration. See https://freddyaboulton.github.io/gradio-webrtc/deployment/
|
||||
track_constraints: Media track constraints for WebRTC. For example, to set video height, width use {"width": {"exact": 800}, "height": {"exact": 600}, "aspectRatio": {"exact": 1.33333}}
|
||||
time_limit: Maximum duration in seconds for recording.
|
||||
allow_extra_tracks: Allow tracks not supported by the modality. For example, a peer connection with an audio track would be allowed even if modality is 'video', which normally throws a ``ValueError`` exception.
|
||||
mode: WebRTC mode - "send-receive", "receive", or "send".
|
||||
modality: Type of media - "video" or "audio".
|
||||
rtp_params: See https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSender/setParameters. If you are changing the video resolution, you can set this to {"degradationPreference": "maintain-framerate"} to keep the frame rate consistent.
|
||||
@@ -130,6 +132,7 @@ class WebRTC(Component, WebRTCConnectionMixin):
|
||||
self.mirror_webcam = mirror_webcam
|
||||
self.concurrency_limit = 1
|
||||
self.rtc_configuration = rtc_configuration
|
||||
self.allow_extra_tracks = allow_extra_tracks
|
||||
self.mode = mode
|
||||
self.modality = modality
|
||||
self.icon_button_color = icon_button_color
|
||||
|
||||
@@ -81,6 +81,7 @@ class WebRTCConnectionMixin:
|
||||
self.time_limit: float | None
|
||||
self.modality: Literal["video", "audio", "audio-video"]
|
||||
self.mode: Literal["send", "receive", "send-receive"]
|
||||
self.allow_extra_tracks: bool
|
||||
|
||||
@staticmethod
|
||||
async def wait_for_time_limit(pc: RTCPeerConnection, time_limit: float):
|
||||
@@ -329,6 +330,8 @@ class WebRTCConnectionMixin:
|
||||
if self.modality not in ["video", "audio", "audio-video"]:
|
||||
msg = "Modality must be either video, audio, or audio-video"
|
||||
else:
|
||||
if self.allow_extra_tracks:
|
||||
return
|
||||
msg = f"Unsupported track kind '{track.kind}' for modality '{self.modality}'"
|
||||
raise ValueError(msg)
|
||||
if body["webrtc_id"] not in self.connections:
|
||||
|
||||
Reference in New Issue
Block a user