1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
"""
Test StreamError events when new content is rejected in-call.
"""
import dbus
from gabbletest import make_result_iq, sync_stream, exec_test
from servicetest import (
make_channel_proxy, unwrap, EventPattern, assertEquals, assertLength)
from jingletest2 import JingleTest2, JingleProtocol031
import constants as cs
from twisted.words.xish import xpath
from config import VOIP_ENABLED
if not VOIP_ENABLED:
print "NOTE: built with --disable-voip"
raise SystemExit(77)
def _content_reject_predicate(event):
reason = xpath.queryForNodes("/iq"
"/jingle[@action='content-reject']"
"/reason/failed-application",
event.stanza)
return bool(reason)
def _start_audio_session(jp, q, bus, conn, stream, incoming):
jt = JingleTest2(jp, conn, q, stream, 'test@localhost', 'foo@bar.com/Foo')
jt.prepare()
self_handle = conn.GetSelfHandle()
remote_handle = conn.RequestHandles(cs.HT_CONTACT, [jt.peer])[0]
if incoming:
jt.incoming_call()
else:
ret = conn.Requests.CreateChannel(
{ cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_STREAMED_MEDIA,
cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT,
cs.TARGET_HANDLE: remote_handle,
cs.INITIAL_AUDIO: True
})
nc, e = q.expect_many(
EventPattern('dbus-signal', signal='NewChannel',
predicate=lambda e: cs.CHANNEL_TYPE_CONTACT_LIST not in e.args),
EventPattern('dbus-signal', signal='NewSessionHandler'))
path = nc.args[0]
media_chan = make_channel_proxy(conn, path, 'Channel.Interface.Group')
media_iface = make_channel_proxy(conn, path, 'Channel.Type.StreamedMedia')
# S-E was notified about new session handler, and calls Ready on it
session_handler = make_channel_proxy(conn, e.args[0],
'Media.SessionHandler')
session_handler.Ready()
nsh_event = q.expect('dbus-signal', signal='NewStreamHandler')
# S-E gets notified about a newly-created stream
stream_handler = make_channel_proxy(conn, nsh_event.args[0],
'Media.StreamHandler')
group_props = media_chan.GetAll(
cs.CHANNEL_IFACE_GROUP, dbus_interface=dbus.PROPERTIES_IFACE)
if incoming:
assertEquals([remote_handle], group_props['Members'])
assertEquals(unwrap(group_props['LocalPendingMembers']),
[(self_handle, remote_handle, cs.GC_REASON_INVITED, '')])
else:
assertEquals([self_handle], group_props['Members'])
streams = media_chan.ListStreams(
dbus_interface=cs.CHANNEL_TYPE_STREAMED_MEDIA)
stream_id = streams[0][0]
stream_handler.NewNativeCandidate("fake", jt.get_remote_transports_dbus())
stream_handler.Ready(jt.dbusify_codecs([("FOO", 5, 8000, {})]))
msg = u"None of the codecs are good for us, damn!"
expected_events = []
if incoming:
stream_handler.StreamState(cs.MEDIA_STREAM_STATE_CONNECTED)
stream_handler.SupportedCodecs(jt.get_audio_codecs_dbus())
e = q.expect('stream-iq', predicate=jp.action_predicate('transport-info'))
assertEquals(jt.peer, e.query['initiator'])
content = xpath.queryForNodes('/iq/jingle/content', e.stanza)[0]
assertEquals('initiator', content['creator'])
stream.send(make_result_iq(stream, e.stanza))
media_chan.AddMembers([self_handle], 'accepted')
memb, acc, _, _, _ = q.expect_many(
EventPattern('dbus-signal', signal='MembersChanged',
args=[u'', [self_handle], [], [], [], self_handle,
cs.GC_REASON_NONE]),
EventPattern('stream-iq',
predicate=jp.action_predicate('session-accept')),
EventPattern('dbus-signal', signal='SetStreamSending',
args=[True]),
EventPattern('dbus-signal', signal='SetStreamPlaying',
args=[True]),
EventPattern('dbus-signal', signal='StreamDirectionChanged',
args=[stream_id,
cs.MEDIA_STREAM_DIRECTION_BIDIRECTIONAL, 0]))
stream.send(make_result_iq(stream, acc.stanza))
active_event = jp.rtp_info_event("active")
if active_event is not None:
q.expect_many(active_event)
members = media_chan.GetMembers()
assert set(members) == set([self_handle, remote_handle]), members
else:
stream_handler.StreamState(cs.MEDIA_STREAM_STATE_CONNECTED)
session_initiate = q.expect(
'stream-iq',
predicate=jp.action_predicate('session-initiate'))
q.expect('dbus-signal', signal='MembersChanged', path=path,
args=['', [], [], [], [remote_handle], self_handle,
cs.GC_REASON_INVITED])
jt.parse_session_initiate(session_initiate.query)
stream.send(jp.xml(jp.ResultIq('test@localhost',
session_initiate.stanza, [])))
jt.accept()
q.expect_many(
EventPattern('stream-iq', iq_type='result'),
# Call accepted
EventPattern('dbus-signal', signal='MembersChanged',
args=['', [remote_handle], [], [], [], remote_handle,
cs.GC_REASON_NONE]),
)
return jt, media_iface
def _start_audio_session_outgoing(jp, q, bus, conn, stream):
return _start_audio_session(jp, q, bus, conn, stream, False)
def _start_audio_session_incoming(jp, q, bus, conn, stream):
return _start_audio_session(jp, q, bus, conn, stream, True)
def _remote_content_add(jp, q, bus, conn, stream, initiate_call_func):
jt, chan = initiate_call_func(jp, q, bus, conn, stream)
video_codecs = [
jp.PayloadType(name, str(rate), str(id), parameters) \
for (name, id, rate, parameters) in jt.video_codecs]
node = jp.SetIq(jt.peer, jt.jid, [
jp.Jingle(jt.sid, jt.peer, 'content-add', [
jp.Content(
'videostream', 'initiator', 'both',
jp.Description('video', video_codecs),
jp.TransportGoogleP2P()) ]) ])
stream.send(jp.xml(node))
_, nsh = q.expect_many(
EventPattern('dbus-signal', signal='StreamAdded'),
EventPattern('dbus-signal', signal='NewStreamHandler'))
stream_handler_path, stream_id, media_type, direction = nsh.args
video_handler = make_channel_proxy(conn, stream_handler_path,
'Media.StreamHandler')
video_handler.NewNativeCandidate("fake",
jt.get_remote_transports_dbus())
video_handler.Ready(jt.dbusify_codecs([("FOO", 5, 8000, {})]))
msg = u"None of the codecs are good for us, damn!"
video_handler.Error(cs.MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED, msg)
q.expect_many(
EventPattern('dbus-signal', signal='StreamError',
args=[stream_id,
cs.MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED,
msg]),
EventPattern('stream-iq', predicate=_content_reject_predicate))
def _local_content_add(jp, q, bus, conn, stream, initiate_call_func):
jt, chan = initiate_call_func(jp, q, bus, conn, stream)
remote_handle = conn.RequestHandles(cs.HT_CONTACT, [jt.peer])[0]
chan.RequestStreams(remote_handle, [cs.MEDIA_STREAM_TYPE_VIDEO])
nsh = q.expect('dbus-signal', signal='NewStreamHandler')
stream_handler_path, stream_id, media_type, direction = nsh.args
video_handler = make_channel_proxy(conn, stream_handler_path,
'Media.StreamHandler')
video_handler.NewNativeCandidate("fake", jt.get_remote_transports_dbus())
video_handler.Ready(jt.get_audio_codecs_dbus())
video_handler.StreamState(cs.MEDIA_STREAM_STATE_CONNECTED)
e = q.expect('stream-iq', predicate=jp.action_predicate('content-add'))
c = e.query.firstChildElement()
stream.send(make_result_iq(stream, e.stanza))
node = jp.SetIq(jt.peer, jt.jid, [
jp.Jingle(jt.sid, jt.peer, 'content-reject', [
('reason', None, {}, [
('failed-application', None, {}, [])]),
jp.Content(c['name'], c['creator'], c['senders']) ]) ])
stream.send(jp.xml(node))
q.expect('dbus-signal', signal='StreamError',
args=[stream_id,
cs.MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED,
""]),
def test_remote_content_add_incoming(jp, q, bus, conn, stream):
_remote_content_add(jp, q, bus, conn, stream,
_start_audio_session_incoming)
def test_remote_content_add_outgoing(jp, q, bus, conn, stream):
_remote_content_add(jp, q, bus, conn, stream,
_start_audio_session_outgoing)
def test_local_content_add_incoming(jp, q, bus, conn, stream):
_local_content_add(jp, q, bus, conn, stream, _start_audio_session_incoming)
def test_local_content_add_outgoing(jp, q, bus, conn, stream):
_local_content_add(jp, q, bus, conn, stream, _start_audio_session_outgoing)
if __name__ == '__main__':
for f in (test_local_content_add_incoming,
test_local_content_add_outgoing,
test_remote_content_add_incoming,
test_remote_content_add_outgoing):
exec_test(
lambda q, b, c, s: f(JingleProtocol031(), q, b, c, s))
|