Mercurial > libervia-backend
diff libervia/frontends/tools/webrtc.py @ 4270:0d7bb4df2343
Reformatted code base using black.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 19 Jun 2024 18:44:57 +0200 |
parents | 79c8a70e1813 |
children | 2992f9d1e039 |
line wrap: on
line diff
--- a/libervia/frontends/tools/webrtc.py Tue Jun 18 12:06:45 2024 +0200 +++ b/libervia/frontends/tools/webrtc.py Wed Jun 19 18:44:57 2024 +0200 @@ -82,13 +82,13 @@ self, bridge, profile: str, - sources_data: SourcesData|None = None, - sinks_data: SinksData|None = None, + sources_data: SourcesData | None = None, + sinks_data: SinksData | None = None, reset_cb: Callable | None = None, merge_pip: bool | None = None, target_size: tuple[int, int] | None = None, call_start_cb: Callable[[str, dict, str], Awaitable[str]] | None = None, - dc_data_list: list[SourcesDataChannel|SinksDataChannel]|None = None + dc_data_list: list[SourcesDataChannel | SinksDataChannel] | None = None, ) -> None: """Initializes a new WebRTC instance. @@ -386,32 +386,32 @@ @param sdp: The Session Description Protocol offer string. """ lines = sdp.splitlines() - media = '' + media = "" mid_media_map = {} bundle_media = set() - bundle_ufrag = '' - bundle_pwd = '' + bundle_ufrag = "" + bundle_pwd = "" in_bundle = False for line in lines: - if line.startswith('m='): - media = line.split('=')[1].split()[0] - elif line.startswith('a=mid:'): - mid = line.split(':')[1].strip() + if line.startswith("m="): + media = line.split("=")[1].split()[0] + elif line.startswith("a=mid:"): + mid = line.split(":")[1].strip() mid_media_map[mid] = media - elif line.startswith('a=group:BUNDLE'): + elif line.startswith("a=group:BUNDLE"): in_bundle = True - bundle_media = set(line.split(':')[1].strip().split()) - elif line.startswith('a=ice-ufrag:'): + bundle_media = set(line.split(":")[1].strip().split()) + elif line.startswith("a=ice-ufrag:"): if in_bundle: - bundle_ufrag = line.split(':')[1].strip() + bundle_ufrag = line.split(":")[1].strip() else: - self.ufrag[media] = line.split(':')[1].strip() - elif line.startswith('a=ice-pwd:'): + self.ufrag[media] = line.split(":")[1].strip() + elif line.startswith("a=ice-pwd:"): if in_bundle: - bundle_pwd = line.split(':')[1].strip() + bundle_pwd = line.split(":")[1].strip() else: - self.pwd[media] = line.split(':')[1].strip() + self.pwd[media] = line.split(":")[1].strip() else: in_bundle = False @@ -487,11 +487,10 @@ assert role in ("initiator", "responder") self.role = role - if isinstance(self.sources_data, SourcesPipeline): - if self.sources_data.video_pipeline!= "" and video_pt is None: + if self.sources_data.video_pipeline != "" and video_pt is None: raise NotImplementedError(NONE_NOT_IMPLEMENTED_MSG) - if self.sources_data.audio_pipeline!= "" and audio_pt is None: + if self.sources_data.audio_pipeline != "" and audio_pt is None: raise NotImplementedError(NONE_NOT_IMPLEMENTED_MSG) elif isinstance(self.sources_data, SourcesNone): pass @@ -559,7 +558,8 @@ if video_source_elt: # Video source with an input-selector to switch between normal and video mute # (or desktop sharing). - gst_pipe_elements.append(f""" + gst_pipe_elements.append( + f""" input-selector name=video_selector ! videorate drop-only=1 max-rate=30 ! video/x-raw,framerate=30/1 @@ -581,20 +581,24 @@ ! rtpvp8pay picture-id-mode=15-bit ! application/x-rtp,media=video,encoding-name=VP8,payload={video_pt} ! sendrecv. - """) + """ + ) if local_video_sink_elt: # Local video feedback. - gst_pipe_elements.append(f""" + gst_pipe_elements.append( + f""" t. ! queue max-size-buffers=1 max-size-time=0 max-size-bytes=0 leaky=downstream ! videoconvert ! {local_video_sink_elt} - """) + """ + ) if audio_source_elt: # Audio with a valve for muting. - gst_pipe_elements.append(r""" + gst_pipe_elements.append( + r""" {audio_source_elt} name=audio_src ! valve ! queue max-size-buffers=10 max-size-time=0 max-size-bytes=0 leaky=downstream @@ -604,7 +608,8 @@ ! rtpopuspay ! application/x-rtp,media=audio,encoding-name=OPUS,payload={audio_pt} ! sendrecv. - """) + """ + ) self.gst_pipe_desc = "\n\n".join(gst_pipe_elements) @@ -708,7 +713,7 @@ for dc_data in self.dc_data_list: self.create_data_channel(dc_data) - def create_data_channel(self, dc_data: SourcesDataChannel|SinksDataChannel) -> None: + def create_data_channel(self, dc_data: SourcesDataChannel | SinksDataChannel) -> None: """Create a Data Channel and connect relevant callbacks.""" assert self.pipeline is not None if isinstance(dc_data, SourcesDataChannel): @@ -729,9 +734,7 @@ elif isinstance(dc_data, SinksDataChannel): self.webrtcbin.connect("on-data-channel", dc_data.dc_on_data_channel) else: - raise ValueError( - "Only SourcesDataChannel or SinksDataChannel are allowed." - ) + raise ValueError("Only SourcesDataChannel or SinksDataChannel are allowed.") def start_pipeline(self) -> None: """Starts the GStreamer pipeline.""" @@ -1100,7 +1103,7 @@ ice_data = { "ufrag": self.ufrag[media_type], "pwd": self.pwd[media_type], - "candidates": [parsed_candidate] + "candidates": [parsed_candidate], } self._a_call( self.bridge.ice_candidates_add,