Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0167/mapping.py @ 4332:71c939e34ca6 default tip @
XEP-0373 (OX): Adjust to gpgme updates: generate with explicit algorithm and subkeys
author | Syndace <me@syndace.dev> |
---|---|
date | Sat, 13 Jul 2024 18:28:28 +0200 |
parents | 33ecebb2c02f |
children |
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 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
46 def generate_sdp_from_session(session: dict, local: bool = False, port: int = 9) -> str: |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 """Generate an SDP string from session data. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 @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
|
50 following structure: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 { |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 "contents": { |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 "<content_id>": { |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 "application_data": { |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 "media": <str: "audio" or "video">, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 "local_data": <media_data dict>, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 "peer_data": <media_data dict>, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 ... |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 }, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 "transport_data": { |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 "local_ice_data": <ice_data dict>, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 "peer_ice_data": <ice_data dict>, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 ... |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 }, |
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 @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
|
72 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
|
73 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
|
74 and not needed in backend, except for debugging purpose. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 @param port: The preferred port for communications. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 @return: The generated SDP string. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 """ |
4121
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
79 contents = session["contents"] |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 sdp_lines = ["v=0"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 # Add originator (o=) line after the version (v=) line |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 username = base64.b64encode(session["local_jid"].full().encode()).decode() |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 session_id = "1" # Increment this for each session |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 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
|
86 network_type = "IN" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 address_type = "IP4" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 connection_address = "0.0.0.0" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 o_line = ( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 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
|
91 f"{connection_address}" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 sdp_lines.append(o_line) |
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 # Add the mandatory "s=" and t=" lines |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 sdp_lines.append("s=-") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 sdp_lines.append("t=0 0") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 # stream direction |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 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
|
101 # 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
|
102 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
|
103 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 sdp_lines.append("a=msid-semantic:WMS *") |
4121
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
105 sdp_lines.append("a=ice-options:trickle") |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 host.trigger.point( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 "XEP-0167_generate_sdp_session", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 session, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 local, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 sdp_lines, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
112 triggers_no_cancel=True, |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 ) |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
114 content_names = sorted(contents) |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
116 for content_name, content_data in [ |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
117 (n, contents[n]) for n in content_names |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
118 ]: # 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 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 # Generate a= lines for rtpmap and fmtp |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 for pt_id, pt in payload_types.items(): |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 name = pt["name"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 clockrate = pt.get("clockrate", "") |
4121
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
149 |
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
150 # 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
|
151 channels = pt.get("channels") |
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
152 if channels: |
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
153 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
|
154 else: |
b2709504586a
plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents:
4116
diff
changeset
|
155 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
|
156 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 if "ptime" in pt: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 sdp_lines.append(f"a=ptime:{pt['ptime']}") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 if "parameters" in pt: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 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
|
162 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
|
163 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 if "bandwidth" in media_data: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 sdp_lines.append(f"a=b:{media_data['bandwidth']}") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 if media_data.get("rtcp-mux"): |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 sdp_lines.append("a=rtcp-mux") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 # 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
|
171 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
|
172 ice_data = content_data["transport_data"][ice_data_key] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 if "fingerprint" in ice_data: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 fingerprint_data = ice_data["fingerprint"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 sdp_lines.append( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 f"a=fingerprint:{fingerprint_data['hash']} " |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 f"{fingerprint_data['fingerprint']}" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 sdp_lines.append(f"a=setup:{fingerprint_data['setup']}") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 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
|
183 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
|
184 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 for candidate in ice_data["candidates"]: |
4276
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
186 candidate_line = generate_candidate_line(candidate) |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
187 sdp_lines.append(f"a={candidate_line}") |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 # Generate a= lines for encryption |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 if "encryption" in media_data: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 for enc_data in media_data["encryption"]: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 crypto_suite = enc_data["crypto-suite"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 key_params = enc_data["key-params"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 session_params = enc_data.get("session-params", "") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 tag = enc_data["tag"] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 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
|
198 if session_params: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 crypto_line += f" {session_params}" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 sdp_lines.append(crypto_line) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 host.trigger.point( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 "XEP-0167_generate_sdp_content", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 session, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 local, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 content_name, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 content_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 sdp_lines, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 application_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 app_data_key, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 media_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 media, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
213 triggers_no_cancel=True, |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 # Combine SDP lines and return the result |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 return "\r\n".join(sdp_lines) + "\r\n" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 |
4276
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
220 def generate_candidate_line(candidate: dict) -> str: |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
221 """Generate a ``candidate:`` attribute line from candidate data. |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
222 |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
223 @param candidate: ICE candidate data. |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
224 @return ICE candidate attribute line. |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
225 """ |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
226 foundation = candidate["foundation"] |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
227 component_id = candidate["component_id"] |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
228 transport = candidate["transport"] |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
229 priority = candidate["priority"] |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
230 address = candidate["address"] |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
231 candidate_port = candidate["port"] |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
232 candidate_type = candidate["type"] |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
233 |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
234 candidate_line = ( |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
235 f"candidate:{foundation} {component_id} {transport} {priority} " |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
236 f"{address} {candidate_port} typ {candidate_type}" |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
237 ) |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
238 |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
239 if "rel_addr" in candidate and "rel_port" in candidate: |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
240 candidate_line += f" raddr {candidate['rel_addr']} rport {candidate['rel_port']}" |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
241 |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
242 if "generation" in candidate: |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
243 candidate_line += f" generation {candidate['generation']}" |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
244 |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
245 if "network" in candidate: |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
246 candidate_line += f" network {candidate['network']}" |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
247 |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
248 return candidate_line |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
249 |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
250 |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
251 def parse_candidate(parts: list[str]) -> dict: |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
252 """Parse parts of a ICE candidate |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
253 |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
254 @param parts: Parts of the candidate line. |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
255 @return: candidate data |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
256 """ |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
257 candidate = { |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
258 "foundation": parts[0], |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
259 "component_id": int(parts[1]), |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
260 "transport": parts[2], |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
261 "priority": int(parts[3]), |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
262 "address": parts[4], |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
263 "port": int(parts[5]), |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
264 "type": parts[7], |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
265 } |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
266 |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
267 for part in parts[8:]: |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
268 if part == "raddr": |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
269 candidate["rel_addr"] = parts[parts.index(part) + 1] |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
270 elif part == "rport": |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
271 candidate["rel_port"] = int(parts[parts.index(part) + 1]) |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
272 elif part == "generation": |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
273 candidate["generation"] = parts[parts.index(part) + 1] |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
274 elif part == "network": |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
275 candidate["network"] = parts[parts.index(part) + 1] |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
276 |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
277 return candidate |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
278 |
00a9316547ed
plugin XEP-0167: move ICE candidates parsing/SDP line building in separate methods:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
279 |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
280 def parse_sdp(sdp: str, role: str) -> dict: |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
281 """Parse SDP string. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
282 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
283 @param sdp: The SDP string to parse. |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
284 @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
|
285 @return: A dictionary containing parsed session data. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
286 """ |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
287 assert host is not None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
288 lines = sdp.strip().split("\r\n") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
289 metadata: Dict[str, Any] = {} |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
290 call_data = {"metadata": metadata} |
4289
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
291 session_attributes: Dict[str, Any] = {} |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
292 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
293 media_type = None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
294 media_data: Optional[Dict[str, Any]] = None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
295 application_data: Optional[Dict[str, Any]] = None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
296 transport_data: Optional[Dict[str, Any]] = None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
297 fingerprint_data: Optional[Dict[str, str]] = None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
298 ice_pwd: Optional[str] = None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
299 ice_ufrag: Optional[str] = None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 payload_types: Optional[Dict[int, dict]] = None |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
301 senders: str = "both" |
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 for line in lines: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
304 try: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
305 parts = line.split() |
4289
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
306 prefix = parts[0][:2] |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
307 parts[0] = parts[0][2:] |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
308 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
309 if prefix == "m=": |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
310 media_type = parts[0] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
311 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 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
|
317 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
|
318 elif media_type == "application": |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4121
diff
changeset
|
319 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
|
320 raise NotImplementedError( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4121
diff
changeset
|
321 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
|
322 ) |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
323 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
324 transport_data = {"port": port} |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
325 if fingerprint_data is not None: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
326 transport_data["fingerprint"] = fingerprint_data |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
327 if ice_pwd is not None: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
328 transport_data["pwd"] = ice_pwd |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
329 if ice_ufrag is not None: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
330 transport_data["ufrag"] = ice_ufrag |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
331 media_data = call_data[media_type] = { |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
332 "application_data": application_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
333 "transport_data": transport_data, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
334 "senders": senders, |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
335 } |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
336 |
4289
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
337 # Apply session attributes to the new media |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
338 for attr, value in session_attributes.items(): |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
339 if attr in ("fingerprint", "ice-pwd", "ice-ufrag"): |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
340 transport_data[attr] = value |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
341 elif attr in ("sendrecv", "sendonly", "recvonly", "inactive"): |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
342 application_data["senders"] = value |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
343 else: |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
344 application_data[attr] = value |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
345 |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
346 elif prefix == "a=": |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
347 if ":" in parts[0]: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
348 attribute, parts[0] = parts[0].split(":", 1) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
349 else: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
350 attribute = parts[0] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
351 |
4289
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
352 if media_type is None: |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
353 # This is a session-level attribute |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
354 if attribute == "fingerprint": |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
355 algorithm, fingerprint = parts[0], parts[1] |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
356 session_attributes["fingerprint"] = { |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
357 "hash": algorithm, |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
358 "fingerprint": fingerprint, |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
359 } |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
360 elif attribute == "ice-pwd": |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
361 session_attributes["ice-pwd"] = parts[0] |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
362 elif attribute == "ice-ufrag": |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
363 session_attributes["ice-ufrag"] = parts[0] |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
364 elif attribute in ("sendrecv", "sendonly", "recvonly", "inactive"): |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
365 if attribute == "sendrecv": |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
366 value = "both" |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
367 elif attribute == "sendonly": |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
368 value = role |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
369 elif attribute == "recvonly": |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
370 value = "responder" if role == "initiator" else "initiator" |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
371 else: |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
372 value = "none" |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
373 session_attributes[attribute] = value |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
374 else: |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
375 session_attributes[attribute] = parts[0] if parts else True |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
376 else: |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
377 # This is a media-level attribute |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
378 if attribute == "mid": |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
379 assert media_data is not None |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
380 try: |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
381 media_data["id"] = parts[0] |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
382 except IndexError: |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
383 log.warning(f"invalid media ID: {line}") |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
384 |
4289
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
385 elif attribute == "rtpmap": |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
386 assert application_data is not None |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
387 assert payload_types is not None |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
388 pt_id = int(parts[0]) |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
389 codec_info = parts[1].split("/") |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
390 codec = codec_info[0] |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
391 clockrate = int(codec_info[1]) |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
392 payload_type = { |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
393 "id": pt_id, |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
394 "name": codec, |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
395 "clockrate": clockrate, |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
396 } |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
397 if len(codec_info) > 2: |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
398 channels = int(codec_info[2]) |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
399 payload_type["channels"] = channels |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
400 |
4289
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
401 payload_types.setdefault(pt_id, {}).update(payload_type) |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
402 |
4289
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
403 elif attribute == "fmtp": |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
404 assert payload_types is not None |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
405 pt_id = int(parts[0]) |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
406 params = parts[1].split(";") |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
407 try: |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
408 payload_type = payload_types[pt_id] |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
409 except KeyError: |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
410 raise ValueError( |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
411 f"Can find content type {pt_id}, ignoring: {line}" |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
412 ) |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
413 |
4289
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
414 try: |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
415 payload_type["parameters"] = { |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
416 name: value |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
417 for name, value in (param.split("=") for param in params) |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
418 } |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
419 except ValueError: |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
420 payload_type.setdefault("exra-parameters", []).extend(params) |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
421 |
4289
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
422 elif attribute == "candidate": |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
423 assert transport_data is not None |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
424 candidate = parse_candidate(parts) |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
425 |
4289
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
426 transport_data.setdefault("candidates", []).append(candidate) |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
427 |
4289
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
428 elif attribute == "fingerprint": |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
429 algorithm, fingerprint = parts[0], parts[1] |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
430 fingerprint_data = {"hash": algorithm, "fingerprint": fingerprint} |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
431 if transport_data is not None: |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
432 transport_data.setdefault("fingerprint", {}).update( |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
433 fingerprint_data |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
434 ) |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
435 elif attribute == "setup": |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
436 assert transport_data is not None |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
437 setup = parts[0] |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
438 transport_data.setdefault("fingerprint", {})["setup"] = setup |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
439 |
4289
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
440 elif attribute == "b": |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
441 assert application_data is not None |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
442 bandwidth = int(parts[0]) |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
443 application_data["bandwidth"] = bandwidth |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
444 |
4289
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
445 elif attribute == "rtcp-mux": |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
446 assert application_data is not None |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
447 application_data["rtcp-mux"] = True |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
448 |
4289
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
449 elif attribute == "ice-ufrag": |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
450 if transport_data is not None: |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
451 transport_data["ufrag"] = parts[0] |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
452 |
4289
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
453 elif attribute == "ice-pwd": |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
454 if transport_data is not None: |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
455 transport_data["pwd"] = parts[0] |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
456 |
4289
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
457 elif attribute in ("sendrecv", "sendonly", "recvonly", "inactive"): |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
458 if attribute == "sendrecv": |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
459 value = "both" |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
460 elif attribute == "sendonly": |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
461 value = role |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
462 elif attribute == "recvonly": |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
463 value = "responder" if role == "initiator" else "initiator" |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
464 else: |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
465 value = "none" |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
466 |
4289
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
467 if application_data is None: |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
468 senders = value |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
469 else: |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
470 application_data["senders"] = value |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
471 |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
472 host.trigger.point( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
473 "XEP-0167_parse_sdp_a", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
474 attribute, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
475 parts, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
476 call_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
477 metadata, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
478 media_type, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
479 application_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
480 transport_data, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
481 triggers_no_cancel=True, |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
482 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
483 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
484 except ValueError as e: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
485 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
|
486 except IndexError as e: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
487 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
|
488 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
489 # 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
|
490 # to handle session data at media level)) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
491 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
|
492 log.debug(f"cleaning remaining private data {key!r}") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
493 del call_data[key] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
494 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
495 all_media = {k: v for k, v in call_data.items() if k in ("audio", "video")} |
4289
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
496 if len(all_media) > 1: |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
497 media_with_candidates = [ |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
498 m for m in all_media.values() if "candidates" in m["transport_data"] |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
499 ] |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
500 if len(media_with_candidates) == 1: |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
501 log.warning( |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
502 "SDP contains ICE candidates only for one media stream. This is non-standard behavior." |
33ecebb2c02f
plugin XEP-0167: fix session level SDP attributes parsing:
Goffi <goffi@goffi.org>
parents:
4276
diff
changeset
|
503 ) |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
504 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
505 return call_data |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
506 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
507 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
508 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
|
509 """Generate <description> element from media data |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
510 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
511 @param media: media type ("audio" or "video") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
512 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
513 @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
|
514 The keys and values are described below: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
515 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
516 - ssrc (str, optional): The synchronization source identifier. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
517 - 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
|
518 type. |
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 - channels (str, optional): Number of audio channels. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
521 - clockrate (str, optional): Clock rate of the media. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
522 - id (str): The unique identifier of the payload type. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
523 - maxptime (str, optional): Maximum packet time. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
524 - name (str, optional): Name of the codec. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
525 - ptime (str, optional): Preferred packet time. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
526 - parameters (dict, optional): A dictionary of codec-specific parameters. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
527 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
|
528 - bandwidth (str, optional): The bandwidth type. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
529 - 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
|
530 not. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
531 - 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
|
532 encryption method. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
533 Each dictionary may contain the following keys: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
534 - tag (str): The unique identifier of the encryption method. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
535 - crypto-suite (str): The encryption suite in use. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
536 - key-params (str): Key parameters for the encryption suite. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
537 - session-params (str, optional): Session parameters for the encryption |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
538 suite. |
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 @return: A <description> element. |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
541 """ |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
542 # 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
|
543 assert host is not None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
544 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
545 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
|
546 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
547 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
|
548 payload_type_elt = desc_elt.addElement("payload-type") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
549 payload_type_elt["id"] = str(pt_id) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
550 for attr in ["channels", "clockrate", "maxptime", "name", "ptime"]: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
551 if attr in pt_data: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
552 payload_type_elt[attr] = str(pt_data[attr]) |
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 "parameters" in pt_data: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
555 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
|
556 param_elt = payload_type_elt.addElement("parameter") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
557 param_elt["name"] = param_name |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
558 param_elt["value"] = param_value |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
559 host.trigger.point( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
560 "XEP-0167_build_description_payload_type", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
561 desc_elt, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
562 media_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
563 pt_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
564 payload_type_elt, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
565 triggers_no_cancel=True, |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
566 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
567 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
568 if "bandwidth" in media_data: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
569 bandwidth_elt = desc_elt.addElement("bandwidth") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
570 bandwidth_elt["type"] = media_data["bandwidth"] |
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 if media_data.get("rtcp-mux"): |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
573 desc_elt.addElement("rtcp-mux") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
574 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
575 # Add encryption element |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
576 if "encryption" in media_data: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
577 encryption_elt = desc_elt.addElement("encryption") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
578 # 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
|
579 encryption_elt["required"] = "1" |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
580 for enc_data in media_data["encryption"]: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
581 crypto_elt = encryption_elt.addElement("crypto") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
582 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
|
583 if attr in enc_data: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
584 crypto_elt[attr] = enc_data[attr] |
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 host.trigger.point( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
587 "XEP-0167_build_description", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
588 desc_elt, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
589 media_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
590 session, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
591 triggers_no_cancel=True, |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
592 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
593 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
594 return desc_elt |
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 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
597 def parse_description(desc_elt: domish.Element) -> dict: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
598 """Parse <desciption> to a dict |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
599 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
600 @param desc_elt: <description> element |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
601 @return: media data as in [build_description] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
602 """ |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
603 # 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
|
604 assert host is not None |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
605 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
606 media_data = {} |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
607 if desc_elt.hasAttribute("ssrc"): |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
608 media_data.setdefault("ssrc", {})[desc_elt["ssrc"]] = {} |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
609 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
610 payload_types = {} |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
611 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
|
612 payload_type_data = { |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
613 attr: payload_type_elt[attr] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
614 for attr in [ |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
615 "channels", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
616 "clockrate", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
617 "maxptime", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
618 "name", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
619 "ptime", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
620 ] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
621 if payload_type_elt.hasAttribute(attr) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
622 } |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
623 try: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
624 pt_id = int(payload_type_elt["id"]) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
625 except KeyError: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
626 log.warning( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
627 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
|
628 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
629 continue |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
630 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
631 parameters = {} |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
632 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
|
633 param_name = param_elt.getAttribute("name") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
634 param_value = param_elt.getAttribute("value") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
635 if not param_name or param_value is None: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
636 log.warning(f"invalid parameter: {param_elt.toXml()}") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
637 continue |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
638 parameters[param_name] = param_value |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
639 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
640 if parameters: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
641 payload_type_data["parameters"] = parameters |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
642 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
643 host.trigger.point( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
644 "XEP-0167_parse_description_payload_type", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
645 desc_elt, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
646 media_data, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
647 payload_type_elt, |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
648 payload_type_data, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
649 triggers_no_cancel=True, |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
650 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
651 payload_types[pt_id] = payload_type_data |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
652 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
653 # bandwidth |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
654 media_data["payload_types"] = payload_types |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
655 try: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
656 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
|
657 except StopIteration: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
658 pass |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
659 else: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
660 bandwidth = bandwidth_elt.getAttribute("type") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
661 if not bandwidth: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
662 log.warning(f"invalid bandwidth: {bandwidth_elt.toXml}") |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
663 else: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
664 media_data["bandwidth"] = bandwidth |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
665 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
666 # rtcp-mux |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
667 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
|
668 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
|
669 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
670 # Encryption |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
671 encryption_data = [] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
672 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
|
673 if encryption_elt: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
674 media_data["encryption_required"] = C.bool( |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
675 encryption_elt.getAttribute("required", C.BOOL_FALSE) |
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 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
678 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
|
679 crypto_data = { |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
680 attr: crypto_elt[attr] |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
681 for attr in [ |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
682 "crypto-suite", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
683 "key-params", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
684 "session-params", |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
685 "tag", |
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 if crypto_elt.hasAttribute(attr) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
688 } |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
689 encryption_data.append(crypto_data) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
690 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
691 if encryption_data: |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
692 media_data["encryption"] = encryption_data |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
693 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
694 host.trigger.point( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
695 "XEP-0167_parse_description", desc_elt, media_data, triggers_no_cancel=True |
4056
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
696 ) |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
697 |
1c4f4aa36d98
plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
698 return media_data |