comparison libervia/frontends/tools/webrtc_models.py @ 4240:79c8a70e1813

backend, frontend: prepare remote control: This is a series of changes necessary to prepare the implementation of remote control feature: - XEP-0166: add a `priority` attribute to `ApplicationData`: this is needed when several applications are working in a same session, to know which one must be handled first. Will be used to make Remote Control have precedence over Call content. - XEP-0166: `_call_plugins` is now async and is not used with `DeferredList` anymore: the benefit to have methods called in parallels is very low, and it cause a lot of trouble as we can't predict order. Methods are now called sequentially so workflow can be predicted. - XEP-0167: fix `senders` XMPP attribute <=> SDP mapping - XEP-0234: preflight acceptance key is now `pre-accepted` instead of `file-accepted`, so the same key can be used with other jingle applications. - XEP-0167, XEP-0343: move some method to XEP-0167 - XEP-0353: use new `priority` feature to call preflight methods of applications according to it. - frontend (webrtc): refactor the sources/sink handling with a more flexible mechanism based on Pydantic models. It is now possible to have has many Data Channel as necessary, to have them in addition to A/V streams, to specify manually GStreamer sources and sinks, etc. - frontend (webrtc): rework of the pipeline to reduce latency. - frontend: new `portal_desktop` method. Screenshare portal handling has been moved there, and RemoteDesktop portal has been added. - frontend (webrtc): fix `extract_ufrag_pwd` method. rel 436
author Goffi <goffi@goffi.org>
date Sat, 11 May 2024 13:52:41 +0200
parents d01b8d002619
children 0d7bb4df2343
comparison
equal deleted inserted replaced
4239:a38559e6d6e2 4240:79c8a70e1813
14 # GNU Affero General Public License for more details. 14 # GNU Affero General Public License for more details.
15 15
16 # You should have received a copy of the GNU Affero General Public License 16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18
19 from collections.abc import Awaitable
19 from dataclasses import dataclass, field 20 from dataclasses import dataclass, field
20 from typing import Any, Callable 21 from typing import Any, Callable
22 import uuid
23 import gi
24
25 gi.require_versions({"Gst": "1.0", "GstWebRTC": "1.0"})
26 from gi.repository import GstWebRTC
27 from pydantic import BaseModel, Field
21 28
22 from libervia.frontends.tools import jid 29 from libervia.frontends.tools import jid
23 30
24 31
25 @dataclass 32 @dataclass
28 sid: str | None = None 35 sid: str | None = None
29 action_id: str | None = None 36 action_id: str | None = None
30 kwargs: dict[str, Any] = field(default_factory=dict) 37 kwargs: dict[str, Any] = field(default_factory=dict)
31 38
32 39
33 @dataclass 40 class SourcesData(BaseModel):
34 class AppSinkData: 41 """Data for Sources"""
42
43
44 class SourcesNone(SourcesData):
45 """No source is used.
46
47 This is used when the WebRTC connection will be used for data channels only."""
48
49
50 class SourcesAuto(SourcesData):
51 """Automatic Sources (webcam/microphone)"""
52
53
54 class SourcesTest(SourcesData):
55 """Test Sources (pattern)"""
56
57
58 class SourcesDataChannel(SourcesData):
59 """Sources for transmitting data over Data Channel
60
61
62 @param dc_open_cb: Called when Data Channel is open.
63 This callback will be run in a GStreamer thread.
64 """
65 name: str = Field(default_factory=lambda: str(uuid.uuid4()))
66 dc_open_cb: Callable[[GstWebRTC.WebRTCDataChannel], None]
67
68
69 class SourcesPipeline(SourcesData):
70 """Use custom pipeline description as a source.
71
72 @param video_pipeline: pipeline description of video source.
73 None to use automatic video source (same as SourcesAuto).
74 Empty string to disable video.
75 @param audio_pipeline: pipeline description of audio source.
76 None to use automatic audio source (same as SourcesAuto).
77 Empty string to disable audio.
78 @param video_properties: Elements properties to set.
79 @param audio_properties: Elements properties to set.
80
81 """
82 video_pipeline: str|None = None
83 audio_pipeline: str|None = None
84 video_properties: dict = Field(default_factory=lambda: {})
85 audio_properties: dict = Field(default_factory=lambda: {})
86
87
88 class SinksData(BaseModel):
89 """Data for Sinks"""
90
91
92 class SinksNone(SinksData):
93 """No sink is used.
94
95 This is used when the WebRTC connection will be used for data channels only."""
96
97
98 class SinksAuto(SinksData):
99 """Automatic Sinks (create windows/default audio)"""
100
101
102 class SinksApp(SinksData):
35 local_video_cb: Callable 103 local_video_cb: Callable
36 remote_video_cb: Callable|None 104 remote_video_cb: Callable | None
105
106
107 class SinksDataChannel(SinksData):
108 """Sinks for transmitting data over Data Channel
109
110 @param dc_on_data_channel: Called when Data Channel is created.
111 This callback will be run in a GStreamer thread.
112 """
113
114 dc_on_data_channel: (
115 Callable[[GstWebRTC.WebRTCDataChannel], Awaitable[None]] | None
116 ) = None