Mercurial > libervia-backend
comparison tests/unit/test_plugin_xep_0293.py @ 4061:fddd76dedc97
tests (units): tests for plugin XEP-0293:
fix 437
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 29 May 2023 17:58:05 +0200 |
parents | |
children | 4b842c1fb686 |
comparison
equal
deleted
inserted
replaced
4060:fce92ba311f4 | 4061:fddd76dedc97 |
---|---|
1 #!/usr/bin/env python3 | |
2 | |
3 # Libervia: an XMPP client | |
4 # Copyright (C) 2009-2023 Jérôme Poisson (goffi@goffi.org) | |
5 | |
6 # This program is free software: you can redistribute it and/or modify | |
7 # it under the terms of the GNU Affero General Public License as published by | |
8 # the Free Software Foundation, either version 3 of the License, or | |
9 # (at your option) any later version. | |
10 | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU Affero General Public License for more details. | |
15 | |
16 # You should have received a copy of the GNU Affero General Public License | |
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | |
19 from twisted.words.xish import domish | |
20 | |
21 from sat.plugins.plugin_xep_0167.constants import NS_JINGLE_RTP | |
22 from sat.plugins.plugin_xep_0293 import NS_JINGLE_RTP_RTCP_FB, RTCP_FB_KEY, XEP_0293 | |
23 from sat.tools import xml_tools | |
24 | |
25 class TestXEP0293: | |
26 | |
27 def test_parse_sdp_rtcp_fb_general(self, host): | |
28 """Parsing of a general RTCP feedback SDP line.""" | |
29 xep_0293 = XEP_0293(host) | |
30 | |
31 application_data = {} | |
32 transport_data = {} | |
33 | |
34 # SDP line: a=rtcp-fb:* nack pli | |
35 attribute = "rtcp-fb" | |
36 parts = ["*", "nack", "pli"] | |
37 xep_0293._parse_sdp_a_trigger( | |
38 attribute=attribute, | |
39 parts=parts, | |
40 call_data={}, | |
41 metadata={}, | |
42 media_type="video", | |
43 application_data=application_data, | |
44 transport_data=transport_data, | |
45 ) | |
46 assert application_data[RTCP_FB_KEY][0] == ("nack", "pli", {}) | |
47 | |
48 def test_parse_sdp_rtcp_fb_specific(self, host): | |
49 """Parsing of a payload-specific RTCP feedback SDP line.""" | |
50 xep_0293 = XEP_0293(host) | |
51 | |
52 application_data = { | |
53 "payload_types": {96: {}} | |
54 } | |
55 transport_data = {} | |
56 | |
57 # SDP line: a=rtcp-fb:96 nack | |
58 attribute = "rtcp-fb" | |
59 parts = ["96", "nack"] | |
60 xep_0293._parse_sdp_a_trigger( | |
61 attribute=attribute, | |
62 parts=parts, | |
63 call_data={}, | |
64 metadata={}, | |
65 media_type="video", | |
66 application_data=application_data, | |
67 transport_data=transport_data, | |
68 ) | |
69 assert application_data["payload_types"][96][RTCP_FB_KEY][0] == ("nack", None, {}) | |
70 | |
71 def test_parse_sdp_rtcp_fb_trr_int_general(self, host): | |
72 """Parsing of a general RTCP feedback with trr-int SDP line.""" | |
73 xep_0293 = XEP_0293(host) | |
74 | |
75 application_data = {} | |
76 transport_data = {} | |
77 | |
78 # SDP line: a=rtcp-fb-trr-int:* 100 | |
79 attribute = "rtcp-fb-trr-int" | |
80 parts = ["*", "100"] | |
81 xep_0293._parse_sdp_a_trigger( | |
82 attribute=attribute, | |
83 parts=parts, | |
84 call_data={}, | |
85 metadata={}, | |
86 media_type="video", | |
87 application_data=application_data, | |
88 transport_data=transport_data, | |
89 ) | |
90 assert application_data["rtcp-fb-trr-int"] == 100 | |
91 | |
92 def test_parse_sdp_rtcp_fb_trr_int_specific(self, host): | |
93 """Parsing of a payload-specific RTCP feedback with trr-int SDP line.""" | |
94 xep_0293 = XEP_0293(host) | |
95 | |
96 application_data = { | |
97 "payload_types": {96: {}} | |
98 } | |
99 transport_data = {} | |
100 | |
101 # SDP line: a=rtcp-fb-trr-int:96 100 | |
102 attribute = "rtcp-fb-trr-int" | |
103 parts = ["96", "100"] | |
104 xep_0293._parse_sdp_a_trigger( | |
105 attribute=attribute, | |
106 parts=parts, | |
107 call_data={}, | |
108 metadata={}, | |
109 media_type="video", | |
110 application_data=application_data, | |
111 transport_data=transport_data, | |
112 ) | |
113 assert application_data["payload_types"][96]["rtcp-fb-trr-int"] == 100 | |
114 | |
115 def test_generate_sdp_session(self, host): | |
116 """Generation of SDP lines for session data.""" | |
117 xep_0293 = XEP_0293(host) | |
118 sdp_lines = [] | |
119 application_data = {RTCP_FB_KEY: [("nack", "pli", {})], "rtcp-fb-trr-int": 100} | |
120 | |
121 xep_0293._generate_sdp_content_trigger( | |
122 session={}, | |
123 local=True, | |
124 content_name="test", | |
125 content_data={}, | |
126 sdp_lines=sdp_lines, | |
127 application_data=application_data, | |
128 app_data_key="test", | |
129 media_data={}, | |
130 media="video", | |
131 ) | |
132 | |
133 assert sdp_lines[0] == "a=rtcp-fb:* nack pli" | |
134 assert sdp_lines[1] == "a=rtcp-fb:* trr-int 100" | |
135 | |
136 def test_generate_sdp_payload_type(self, host): | |
137 """Generation of SDP lines for each payload type.""" | |
138 xep_0293 = XEP_0293(host) | |
139 sdp_lines = [] | |
140 application_data = {} | |
141 media_data = { | |
142 "payload_types": {96: {RTCP_FB_KEY: [("nack", None, {})], "rtcp-fb-trr-int": 100}} | |
143 } | |
144 | |
145 xep_0293._generate_sdp_content_trigger( | |
146 session={}, | |
147 local=True, | |
148 content_name="test", | |
149 content_data={}, | |
150 sdp_lines=sdp_lines, | |
151 application_data=application_data, | |
152 app_data_key="test", | |
153 media_data=media_data, | |
154 media="video", | |
155 ) | |
156 | |
157 assert sdp_lines[0] == "a=rtcp-fb:96 nack" | |
158 assert sdp_lines[1] == "a=rtcp-fb:96 trr-int 100" | |
159 | |
160 def test_parse_description(self, host): | |
161 """Parsing of <rtcp-fb> and <rtcp-fb-trr-int> elements from a description.""" | |
162 xep_0293 = XEP_0293(host) | |
163 | |
164 desc_element = xml_tools.parse( | |
165 f""" | |
166 <description xmlns="urn:xmpp:jingle:apps:rtp:1" media="audio"> | |
167 <rtcp-fb xmlns="{NS_JINGLE_RTP_RTCP_FB}" type="nack" subtype="pli"/> | |
168 <rtcp-fb-trr-int xmlns="{NS_JINGLE_RTP_RTCP_FB}" value="100"/> | |
169 </description> | |
170 """ | |
171 ) | |
172 | |
173 media_data = {} | |
174 xep_0293._parse_description_trigger(desc_element, media_data) | |
175 | |
176 assert media_data[RTCP_FB_KEY][0] == ("nack", "pli", {}) | |
177 assert media_data["rtcp_fb_trr_int"][0] == 100 | |
178 | |
179 def test_parse_description_payload_type(self, host): | |
180 """Parsing of <rtcp-fb> and <rtcp-fb-trr-int> elements from a payload type.""" | |
181 xep_0293 = XEP_0293(host) | |
182 | |
183 desc_element = xml_tools.parse( | |
184 f""" | |
185 <description xmlns="urn:xmpp:jingle:apps:rtp:1" media="audio"> | |
186 <payload-type id="96"> | |
187 <rtcp-fb xmlns="{NS_JINGLE_RTP_RTCP_FB}" type="nack" subtype="pli"/> | |
188 <rtcp-fb-trr-int xmlns="{NS_JINGLE_RTP_RTCP_FB}" value="100"/> | |
189 </payload-type> | |
190 </description> | |
191 """ | |
192 ) | |
193 | |
194 media_data = {} | |
195 payload_type_elt = desc_element.firstChildElement() | |
196 payload_type_data = {} | |
197 xep_0293._parse_description_payload_type_trigger( | |
198 desc_element, media_data, payload_type_elt, payload_type_data | |
199 ) | |
200 | |
201 assert payload_type_data[RTCP_FB_KEY][0] == ("nack", "pli", {}) | |
202 assert payload_type_data["rtcp_fb_trr_int"][0] == 100 | |
203 | |
204 def test_build_rtcp_fb_elements(self, host): | |
205 """Building the <rtcp-fb> and <rtcp-fb-trr-int> elements.""" | |
206 xep_0293 = XEP_0293(host) | |
207 data = { | |
208 RTCP_FB_KEY: [("nack", "pli", {})], | |
209 "rtcp-fb-trr-int": 100 | |
210 } | |
211 | |
212 # Test _build_description_trigger | |
213 desc_elt = domish.Element((NS_JINGLE_RTP, "description")) | |
214 xep_0293._build_description_trigger(desc_elt, data, {}) | |
215 | |
216 rtcp_fb_elts = list(desc_elt.elements(NS_JINGLE_RTP_RTCP_FB, "rtcp-fb")) | |
217 assert len(rtcp_fb_elts) == 1 | |
218 rtcp_fb_elt = rtcp_fb_elts[0] | |
219 assert rtcp_fb_elt["type"] == "nack" | |
220 assert rtcp_fb_elt["subtype"] == "pli" | |
221 | |
222 rtcp_fb_trr_int_elts = list(desc_elt.elements(NS_JINGLE_RTP_RTCP_FB, "rtcp-fb-trr-int")) | |
223 assert len(rtcp_fb_trr_int_elts) == 1 | |
224 rtcp_fb_trr_int_elt = rtcp_fb_trr_int_elts[0] | |
225 assert int(rtcp_fb_trr_int_elt["value"]) == 100 | |
226 | |
227 # Test _build_description_payload_type_trigger | |
228 desc_elt = domish.Element((NS_JINGLE_RTP, "description")) | |
229 payload_type_elt = desc_elt.addElement((NS_JINGLE_RTP, "payload-type")) | |
230 xep_0293._build_description_payload_type_trigger(desc_elt, {}, data, payload_type_elt) | |
231 | |
232 rtcp_fb_elts = list(payload_type_elt.elements(NS_JINGLE_RTP_RTCP_FB, "rtcp-fb")) | |
233 assert len(rtcp_fb_elts) == 1 | |
234 rtcp_fb_elt = rtcp_fb_elts[0] | |
235 assert rtcp_fb_elt["type"] == "nack" | |
236 assert rtcp_fb_elt["subtype"] == "pli" | |
237 | |
238 rtcp_fb_trr_int_elts = list(payload_type_elt.elements(NS_JINGLE_RTP_RTCP_FB, "rtcp-fb-trr-int")) | |
239 assert len(rtcp_fb_trr_int_elts) == 1 | |
240 rtcp_fb_trr_int_elt = rtcp_fb_trr_int_elts[0] | |
241 assert int(rtcp_fb_trr_int_elt["value"]) == 100 |