Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0167/mapping.py @ 4266:9fc3d28bc3f6
core (main): add a mechanism to have a shared temp directory:
this directory may be used to share files between backend and frontends. Normally, an
os-dependent temporary directory is created for that, but if this option is set, the
directory will be created in <local_dir>/<cache_dir>, which may be useful in some use case
(e.g. containerized frontends and backend).
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 12 Jun 2024 22:47:34 +0200 |
parents | 79c8a70e1813 |
children | 0d7bb4df2343 |
rev | line source |
---|---|
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
4058
adb9dc9c8114
plugin XEP-0167: fix wrong copy/pasted header
Goffi <goffi@goffi.org>
parents:
4056
diff
changeset
|
3 # Libervia: an XMPP client |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Copyright (C) 2009-2023 Jérôme Poisson (goffi@goffi.org) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 import base64 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from typing import Any, Dict, Optional |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from twisted.words.xish import domish |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4058
diff
changeset
|
24 from libervia.backend.core.constants import Const as C |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4058
diff
changeset
|
25 from libervia.backend.core.log import getLogger |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from .constants import NS_JINGLE_RTP |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 log = getLogger(__name__) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 host = None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 def senders_to_sdp(senders: str, session: dict) -> str: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 """Returns appropriate SDP attribute corresponding to Jingle senders attribute""" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 if senders == "both": |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 return "a=sendrecv" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 elif senders == "none": |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 return "a=inactive" |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
40 elif session["role"] != senders: |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 return "a=sendonly" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 else: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 return "a=recvonly" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 def generate_sdp_from_session( |
4121
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
47 session: dict, local: bool = False, port: int = 9 |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 ) -> str: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 """Generate an SDP string from session data. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 @param session: A dictionary containing the session data. It should have the |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 following structure: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 { |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 "contents": { |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 "<content_id>": { |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 "application_data": { |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 "media": <str: "audio" or "video">, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 "local_data": <media_data dict>, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 "peer_data": <media_data dict>, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 ... |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 }, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 "transport_data": { |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 "local_ice_data": <ice_data dict>, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 "peer_ice_data": <ice_data dict>, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 ... |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 }, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 ... |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 }, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 ... |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 } |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 } |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 @param local: A boolean value indicating whether to generate SDP for the local or |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 peer entity. If True, the method will generate SDP for the local entity, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 otherwise for the peer entity. Generally the local SDP is received from frontends |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 and not needed in backend, except for debugging purpose. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 @param port: The preferred port for communications. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 @return: The generated SDP string. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 """ |
4121
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
81 contents = session["contents"] |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 sdp_lines = ["v=0"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 # Add originator (o=) line after the version (v=) line |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 username = base64.b64encode(session["local_jid"].full().encode()).decode() |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 session_id = "1" # Increment this for each session |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 session_version = "1" # Increment this when the session is updated |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 network_type = "IN" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 address_type = "IP4" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 connection_address = "0.0.0.0" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 o_line = ( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 f"o={username} {session_id} {session_version} {network_type} {address_type} " |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 f"{connection_address}" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 sdp_lines.append(o_line) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 # Add the mandatory "s=" and t=" lines |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 sdp_lines.append("s=-") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 sdp_lines.append("t=0 0") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 # stream direction |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 all_senders = {c["senders"] for c in session["contents"].values()} |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 # if we don't have a common senders for all contents, we set them at media level |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 senders = all_senders.pop() if len(all_senders) == 1 else None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 sdp_lines.append("a=msid-semantic:WMS *") |
4121
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
107 sdp_lines.append("a=ice-options:trickle") |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 host.trigger.point( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 "XEP-0167_generate_sdp_session", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 session, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 local, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 sdp_lines, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 triggers_no_cancel=True |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 ) |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
116 content_names = sorted(contents) |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
118 for content_name, content_data in [(n, contents[n]) for n in content_names]: # contents.items(): |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 app_data_key = "local_data" if local else "peer_data" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 application_data = content_data["application_data"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 media_data = application_data[app_data_key] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 media = application_data["media"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 payload_types = media_data.get("payload_types", {}) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 # Generate m= line |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4121
diff
changeset
|
126 if media == "application": |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4121
diff
changeset
|
127 transport = "UDP/DTLS/SCTP" |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4121
diff
changeset
|
128 m_line = f"m={media} {port} {transport} webrtc-datachannel" |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4121
diff
changeset
|
129 else: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4121
diff
changeset
|
130 transport = "UDP/TLS/RTP/SAVPF" |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4121
diff
changeset
|
131 payload_type_ids = [str(pt_id) for pt_id in payload_types] |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4121
diff
changeset
|
132 m_line = f"m={media} {port} {transport} {' '.join(payload_type_ids)}" |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 sdp_lines.append(m_line) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 sdp_lines.append(f"c={network_type} {address_type} {connection_address}") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 sdp_lines.append(f"a=mid:{content_name}") |
4121
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
138 if senders is not None: |
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
139 sdp_lines.append(senders_to_sdp(senders, session)) |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 # stream direction |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 if senders is None: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 sdp_lines.append(senders_to_sdp(content_data["senders"], session)) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 |
4121
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
145 |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 # Generate a= lines for rtpmap and fmtp |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 for pt_id, pt in payload_types.items(): |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 name = pt["name"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 clockrate = pt.get("clockrate", "") |
4121
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
150 |
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
151 # Check if "channels" is in pt and append it to the line |
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
152 channels = pt.get("channels") |
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
153 if channels: |
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
154 sdp_lines.append(f"a=rtpmap:{pt_id} {name}/{clockrate}/{channels}") |
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
155 else: |
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
156 sdp_lines.append(f"a=rtpmap:{pt_id} {name}/{clockrate}") |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 if "ptime" in pt: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 sdp_lines.append(f"a=ptime:{pt['ptime']}") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 if "parameters" in pt: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 fmtp_params = ";".join([f"{k}={v}" for k, v in pt["parameters"].items()]) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 sdp_lines.append(f"a=fmtp:{pt_id} {fmtp_params}") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 if "bandwidth" in media_data: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 sdp_lines.append(f"a=b:{media_data['bandwidth']}") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 if media_data.get("rtcp-mux"): |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 sdp_lines.append("a=rtcp-mux") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 # Generate a= lines for fingerprint, ICE ufrag, pwd and candidates |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 ice_data_key = "local_ice_data" if local else "peer_ice_data" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 ice_data = content_data["transport_data"][ice_data_key] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 if "fingerprint" in ice_data: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 fingerprint_data = ice_data["fingerprint"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 sdp_lines.append( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 f"a=fingerprint:{fingerprint_data['hash']} " |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 f"{fingerprint_data['fingerprint']}" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 sdp_lines.append(f"a=setup:{fingerprint_data['setup']}") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 sdp_lines.append(f"a=ice-ufrag:{ice_data['ufrag']}") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 sdp_lines.append(f"a=ice-pwd:{ice_data['pwd']}") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 for candidate in ice_data["candidates"]: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 foundation = candidate["foundation"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 component_id = candidate["component_id"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 transport = candidate["transport"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 priority = candidate["priority"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 address = candidate["address"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 candidate_port = candidate["port"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 candidate_type = candidate["type"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 candidate_line = ( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 f"a=candidate:{foundation} {component_id} {transport} {priority} " |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 f"{address} {candidate_port} typ {candidate_type}" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 if "rel_addr" in candidate and "rel_port" in candidate: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 candidate_line += ( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 f" raddr {candidate['rel_addr']} rport {candidate['rel_port']}" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 if "generation" in candidate: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 candidate_line += f" generation {candidate['generation']}" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 if "network" in candidate: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 candidate_line += f" network {candidate['network']}" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 sdp_lines.append(candidate_line) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 # Generate a= lines for encryption |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 if "encryption" in media_data: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 for enc_data in media_data["encryption"]: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 crypto_suite = enc_data["crypto-suite"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 key_params = enc_data["key-params"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 session_params = enc_data.get("session-params", "") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 tag = enc_data["tag"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 crypto_line = f"a=crypto:{tag} {crypto_suite} {key_params}" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 if session_params: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 crypto_line += f" {session_params}" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 sdp_lines.append(crypto_line) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
226 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 host.trigger.point( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 "XEP-0167_generate_sdp_content", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 session, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 local, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 content_name, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 content_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 sdp_lines, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 application_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 app_data_key, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 media_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 media, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 triggers_no_cancel=True |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 # Combine SDP lines and return the result |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 return "\r\n".join(sdp_lines) + "\r\n" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
245 def parse_sdp(sdp: str, role: str) -> dict: |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
246 """Parse SDP string. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 @param sdp: The SDP string to parse. |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
249 @param role: Role of the entities which produces the SDP. |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 @return: A dictionary containing parsed session data. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 """ |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 # FIXME: to be removed once host is accessible from global var |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 assert host is not None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 lines = sdp.strip().split("\r\n") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 # session metadata |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 metadata: Dict[str, Any] = {} |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 call_data = {"metadata": metadata} |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 media_type = None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 media_data: Optional[Dict[str, Any]] = None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
261 application_data: Optional[Dict[str, Any]] = None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
262 transport_data: Optional[Dict[str, Any]] = None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
263 fingerprint_data: Optional[Dict[str, str]] = None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
264 ice_pwd: Optional[str] = None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
265 ice_ufrag: Optional[str] = None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
266 payload_types: Optional[Dict[int, dict]] = None |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
267 # default value, will be be modified by SDP |
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
268 senders: str = "both" |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 for line in lines: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 try: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
272 parts = line.split() |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
273 prefix = parts[0][:2] # Extract the 'a=', 'm=', etc., prefix |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
274 parts[0] = parts[0][2:] # Remove the prefix from the first element |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
275 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
276 if prefix == "m=": |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
277 media_type = parts[0] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
278 port = int(parts[1]) |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4121
diff
changeset
|
279 application_data = {"media": media_type} |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4121
diff
changeset
|
280 if media_type in ("video", "audio"): |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4121
diff
changeset
|
281 payload_types = application_data["payload_types"] = {} |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4121
diff
changeset
|
282 for payload_type_id in [int(pt_id) for pt_id in parts[3:]]: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4121
diff
changeset
|
283 payload_type = {"id": payload_type_id} |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4121
diff
changeset
|
284 payload_types[payload_type_id] = payload_type |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4121
diff
changeset
|
285 elif media_type == "application": |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4121
diff
changeset
|
286 if parts[3] != "webrtc-datachannel": |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4121
diff
changeset
|
287 raise NotImplementedError( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4121
diff
changeset
|
288 f"{media_type!r} application is not supported" |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4121
diff
changeset
|
289 ) |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
290 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
291 transport_data = {"port": port} |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
292 if fingerprint_data is not None: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
293 transport_data["fingerprint"] = fingerprint_data |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
294 if ice_pwd is not None: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
295 transport_data["pwd"] = ice_pwd |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
296 if ice_ufrag is not None: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
297 transport_data["ufrag"] = ice_ufrag |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
298 media_data = call_data[media_type] = { |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
299 "application_data": application_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 "transport_data": transport_data, |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
301 "senders": senders |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
302 } |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
303 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
304 elif prefix == "a=": |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
305 if ":" in parts[0]: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
306 attribute, parts[0] = parts[0].split(":", 1) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
307 else: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
308 attribute = parts[0] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
309 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
310 if ( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
311 media_type is None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
312 or application_data is None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
313 or transport_data is None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
314 ) and not ( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
315 attribute |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
316 in ( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 "sendrecv", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
318 "sendonly", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 "recvonly", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
320 "inactive", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
321 "fingerprint", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 "group", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
323 "ice-options", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
324 "msid-semantic", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
325 "ice-pwd", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
326 "ice-ufrag", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
327 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
328 ): |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
329 log.warning( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
330 "Received attribute before media description, this is " |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
331 f"invalid: {line}" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
332 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
333 continue |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
334 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
335 if attribute == "mid": |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
336 assert media_data is not None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
337 try: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
338 media_data["id"] = parts[0] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
339 except IndexError: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
340 log.warning(f"invalid media ID: {line}") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
341 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
342 elif attribute == "rtpmap": |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
343 assert application_data is not None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
344 assert payload_types is not None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
345 pt_id = int(parts[0]) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
346 codec_info = parts[1].split("/") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
347 codec = codec_info[0] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
348 clockrate = int(codec_info[1]) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
349 payload_type = { |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
350 "id": pt_id, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
351 "name": codec, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
352 "clockrate": clockrate, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
353 } |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
354 # Handle optional channel count |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
355 if len(codec_info) > 2: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
356 channels = int(codec_info[2]) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
357 payload_type["channels"] = channels |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
358 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
359 payload_types.setdefault(pt_id, {}).update(payload_type) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
360 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
361 elif attribute == "fmtp": |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
362 assert payload_types is not None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
363 pt_id = int(parts[0]) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
364 params = parts[1].split(";") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
365 try: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
366 payload_type = payload_types[pt_id] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
367 except KeyError: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
368 raise ValueError( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
369 f"Can find content type {pt_id}, ignoring: {line}" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
370 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
371 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
372 try: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
373 payload_type["parameters"] = { |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
374 name: value |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
375 for name, value in (param.split("=") for param in params) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
376 } |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
377 except ValueError: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
378 payload_type.setdefault("exra-parameters", []).extend(params) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
379 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
380 elif attribute == "candidate": |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
381 assert transport_data is not None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
382 candidate = { |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
383 "foundation": parts[0], |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
384 "component_id": int(parts[1]), |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
385 "transport": parts[2], |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
386 "priority": int(parts[3]), |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
387 "address": parts[4], |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
388 "port": int(parts[5]), |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
389 "type": parts[7], |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
390 } |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
391 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
392 for part in parts[8:]: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
393 if part == "raddr": |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
394 candidate["rel_addr"] = parts[parts.index(part) + 1] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
395 elif part == "rport": |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
396 candidate["rel_port"] = int(parts[parts.index(part) + 1]) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
397 elif part == "generation": |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
398 candidate["generation"] = parts[parts.index(part) + 1] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
399 elif part == "network": |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
400 candidate["network"] = parts[parts.index(part) + 1] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
401 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
402 transport_data.setdefault("candidates", []).append(candidate) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
403 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
404 elif attribute == "fingerprint": |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
405 algorithm, fingerprint = parts[0], parts[1] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
406 fingerprint_data = {"hash": algorithm, "fingerprint": fingerprint} |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
407 if transport_data is not None: |
4121
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
408 transport_data.setdefault("fingerprint", {}).update( |
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
409 fingerprint_data |
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
410 ) |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
411 elif attribute == "setup": |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
412 assert transport_data is not None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
413 setup = parts[0] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
414 transport_data.setdefault("fingerprint", {})["setup"] = setup |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
415 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
416 elif attribute == "b": |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
417 assert application_data is not None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
418 bandwidth = int(parts[0]) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
419 application_data["bandwidth"] = bandwidth |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
420 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
421 elif attribute == "rtcp-mux": |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
422 assert application_data is not None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
423 application_data["rtcp-mux"] = True |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
424 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
425 elif attribute == "ice-ufrag": |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
426 if transport_data is not None: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
427 transport_data["ufrag"] = parts[0] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
428 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
429 elif attribute == "ice-pwd": |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
430 if transport_data is not None: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
431 transport_data["pwd"] = parts[0] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
432 |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
433 elif attribute in ("sendrecv", "sendonly", "recvonly", "inactive"): |
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
434 if attribute == "sendrecv": |
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
435 value = "both" |
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
436 elif attribute == "sendonly": |
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
437 value = role |
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
438 elif attribute == "recvonly": |
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
439 value = "responder" if role == "initiator" else "initiator" |
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
440 else: |
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
441 value = "none" |
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
442 |
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
443 if application_data is None: |
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
444 # this is a global value, we use is as new default value |
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
445 senders = value |
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
446 else: |
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
447 # this is a media specific value, it will replace the one used as |
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
448 # default for this media |
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
449 application_data["senders"] = value |
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
450 |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
451 host.trigger.point( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
452 "XEP-0167_parse_sdp_a", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
453 attribute, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
454 parts, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
455 call_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
456 metadata, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
457 media_type, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
458 application_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
459 transport_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
460 triggers_no_cancel=True |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
461 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
462 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
463 except ValueError as e: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
464 raise ValueError(f"Could not parse line. Invalid format ({e}): {line}") from e |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
465 except IndexError as e: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
466 raise IndexError(f"Incomplete line. Missing data: {line}") from e |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
467 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
468 # we remove private data (data starting with _, used by some plugins (e.g. XEP-0294) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
469 # to handle session data at media level)) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
470 for key in [k for k in call_data if k.startswith("_")]: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
471 log.debug(f"cleaning remaining private data {key!r}") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
472 del call_data[key] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
473 |
4121
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
474 # FIXME: is this really useful? |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
475 # ICE candidates may only be specified for the first media, this |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
476 # duplicate the candidate for the other in this case |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
477 all_media = {k:v for k,v in call_data.items() if k in ("audio", "video")} |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
478 if len(all_media) > 1 and not all( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
479 "candidates" in c["transport_data"] for c in all_media.values() |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
480 ): |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
481 first_content = next(iter(all_media.values())) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
482 try: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
483 ice_candidates = first_content["transport_data"]["candidates"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
484 except KeyError: |
4116
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
485 ice_candidates = [] |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
486 for idx, content in enumerate(all_media.values()): |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
487 if idx == 0: |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
488 continue |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
489 content["transport_data"].setdefault("candidates", ice_candidates) |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
490 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
491 return call_data |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
492 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
493 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
494 def build_description(media: str, media_data: dict, session: dict) -> domish.Element: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
495 """Generate <description> element from media data |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
496 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
497 @param media: media type ("audio" or "video") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
498 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
499 @param media_data: A dictionary containing the media description data. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
500 The keys and values are described below: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
501 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
502 - ssrc (str, optional): The synchronization source identifier. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
503 - payload_types (list): A list of dictionaries, each representing a payload |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
504 type. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
505 Each dictionary may contain the following keys: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
506 - channels (str, optional): Number of audio channels. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
507 - clockrate (str, optional): Clock rate of the media. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
508 - id (str): The unique identifier of the payload type. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
509 - maxptime (str, optional): Maximum packet time. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
510 - name (str, optional): Name of the codec. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
511 - ptime (str, optional): Preferred packet time. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
512 - parameters (dict, optional): A dictionary of codec-specific parameters. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
513 Key-value pairs represent the parameter name and value, respectively. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
514 - bandwidth (str, optional): The bandwidth type. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
515 - rtcp-mux (bool, optional): Indicates whether RTCP multiplexing is enabled or |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
516 not. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
517 - encryption (list, optional): A list of dictionaries, each representing an |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
518 encryption method. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
519 Each dictionary may contain the following keys: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
520 - tag (str): The unique identifier of the encryption method. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
521 - crypto-suite (str): The encryption suite in use. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
522 - key-params (str): Key parameters for the encryption suite. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
523 - session-params (str, optional): Session parameters for the encryption |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
524 suite. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
525 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
526 @return: A <description> element. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
527 """ |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
528 # FIXME: to be removed once host is accessible from global var |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
529 assert host is not None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
530 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
531 desc_elt = domish.Element((NS_JINGLE_RTP, "description"), attribs={"media": media}) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
532 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
533 for pt_id, pt_data in media_data.get("payload_types", {}).items(): |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
534 payload_type_elt = desc_elt.addElement("payload-type") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
535 payload_type_elt["id"] = str(pt_id) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
536 for attr in ["channels", "clockrate", "maxptime", "name", "ptime"]: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
537 if attr in pt_data: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
538 payload_type_elt[attr] = str(pt_data[attr]) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
539 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
540 if "parameters" in pt_data: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
541 for param_name, param_value in pt_data["parameters"].items(): |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
542 param_elt = payload_type_elt.addElement("parameter") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
543 param_elt["name"] = param_name |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
544 param_elt["value"] = param_value |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
545 host.trigger.point( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
546 "XEP-0167_build_description_payload_type", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
547 desc_elt, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
548 media_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
549 pt_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
550 payload_type_elt, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
551 triggers_no_cancel=True |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
552 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
553 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
554 if "bandwidth" in media_data: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
555 bandwidth_elt = desc_elt.addElement("bandwidth") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
556 bandwidth_elt["type"] = media_data["bandwidth"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
557 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
558 if media_data.get("rtcp-mux"): |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
559 desc_elt.addElement("rtcp-mux") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
560 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
561 # Add encryption element |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
562 if "encryption" in media_data: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
563 encryption_elt = desc_elt.addElement("encryption") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
564 # we always want require encryption if the `encryption` data is present |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
565 encryption_elt["required"] = "1" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
566 for enc_data in media_data["encryption"]: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
567 crypto_elt = encryption_elt.addElement("crypto") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
568 for attr in ["tag", "crypto-suite", "key-params", "session-params"]: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
569 if attr in enc_data: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
570 crypto_elt[attr] = enc_data[attr] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
571 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
572 host.trigger.point( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
573 "XEP-0167_build_description", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
574 desc_elt, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
575 media_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
576 session, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
577 triggers_no_cancel=True |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
578 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
579 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
580 return desc_elt |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
581 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
582 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
583 def parse_description(desc_elt: domish.Element) -> dict: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
584 """Parse <desciption> to a dict |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
585 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
586 @param desc_elt: <description> element |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
587 @return: media data as in [build_description] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
588 """ |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
589 # FIXME: to be removed once host is accessible from global var |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
590 assert host is not None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
591 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
592 media_data = {} |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
593 if desc_elt.hasAttribute("ssrc"): |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
594 media_data.setdefault("ssrc", {})[desc_elt["ssrc"]] = {} |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
595 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
596 payload_types = {} |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
597 for payload_type_elt in desc_elt.elements(NS_JINGLE_RTP, "payload-type"): |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
598 payload_type_data = { |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
599 attr: payload_type_elt[attr] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
600 for attr in [ |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
601 "channels", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
602 "clockrate", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
603 "maxptime", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
604 "name", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
605 "ptime", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
606 ] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
607 if payload_type_elt.hasAttribute(attr) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
608 } |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
609 try: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
610 pt_id = int(payload_type_elt["id"]) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
611 except KeyError: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
612 log.warning( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
613 f"missing ID in payload type, ignoring: {payload_type_elt.toXml()}" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
614 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
615 continue |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
616 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
617 parameters = {} |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
618 for param_elt in payload_type_elt.elements(NS_JINGLE_RTP, "parameter"): |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
619 param_name = param_elt.getAttribute("name") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
620 param_value = param_elt.getAttribute("value") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
621 if not param_name or param_value is None: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
622 log.warning(f"invalid parameter: {param_elt.toXml()}") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
623 continue |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
624 parameters[param_name] = param_value |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
625 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
626 if parameters: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
627 payload_type_data["parameters"] = parameters |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
628 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
629 host.trigger.point( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
630 "XEP-0167_parse_description_payload_type", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
631 desc_elt, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
632 media_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
633 payload_type_elt, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
634 payload_type_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
635 triggers_no_cancel=True |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
636 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
637 payload_types[pt_id] = payload_type_data |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
638 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
639 # bandwidth |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
640 media_data["payload_types"] = payload_types |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
641 try: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
642 bandwidth_elt = next(desc_elt.elements(NS_JINGLE_RTP, "bandwidth")) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
643 except StopIteration: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
644 pass |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
645 else: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
646 bandwidth = bandwidth_elt.getAttribute("type") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
647 if not bandwidth: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
648 log.warning(f"invalid bandwidth: {bandwidth_elt.toXml}") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
649 else: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
650 media_data["bandwidth"] = bandwidth |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
651 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
652 # rtcp-mux |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
653 rtcp_mux_elt = next(desc_elt.elements(NS_JINGLE_RTP, "rtcp-mux"), None) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
654 media_data["rtcp-mux"] = rtcp_mux_elt is not None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
655 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
656 # Encryption |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
657 encryption_data = [] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
658 encryption_elt = next(desc_elt.elements(NS_JINGLE_RTP, "encryption"), None) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
659 if encryption_elt: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
660 media_data["encryption_required"] = C.bool( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
661 encryption_elt.getAttribute("required", C.BOOL_FALSE) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
662 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
663 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
664 for crypto_elt in encryption_elt.elements(NS_JINGLE_RTP, "crypto"): |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
665 crypto_data = { |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
666 attr: crypto_elt[attr] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
667 for attr in [ |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
668 "crypto-suite", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
669 "key-params", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
670 "session-params", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
671 "tag", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
672 ] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
673 if crypto_elt.hasAttribute(attr) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
674 } |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
675 encryption_data.append(crypto_data) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
676 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
677 if encryption_data: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
678 media_data["encryption"] = encryption_data |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
679 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
680 host.trigger.point( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
681 "XEP-0167_parse_description", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
682 desc_elt, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
683 media_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
684 triggers_no_cancel=True |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
685 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
686 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
687 return media_data |