blob: 9bf33066c400eed2235eb700b5cc81629f09f3b8 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:361/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:363 *
kjellanderb24317b2016-02-10 15:54:434 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:369 */
10
Yves Gerey3e707812018-11-28 15:47:4911#include <limits.h>
12#include <stdint.h>
13#include <string.h>
kwibergd1fe2812016-04-27 13:47:2914#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:3615#include <string>
kwiberg0eb15ed2015-12-17 11:04:1516#include <utility>
Yves Gerey3e707812018-11-28 15:47:4917#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:3618
Karl Wiberg918f50c2018-07-05 09:40:3319#include "absl/memory/memory.h"
Steve Anton1c9c9fc2019-02-14 23:13:0920#include "absl/strings/str_replace.h"
Yves Gerey3e707812018-11-28 15:47:4921#include "absl/types/optional.h"
22#include "api/audio/audio_mixer.h"
23#include "api/audio_codecs/audio_decoder_factory.h"
24#include "api/audio_codecs/audio_encoder_factory.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3125#include "api/audio_codecs/builtin_audio_decoder_factory.h"
26#include "api/audio_codecs/builtin_audio_encoder_factory.h"
Steve Anton10542f22019-01-11 17:11:0027#include "api/call/call_factory_interface.h"
Mirko Bonadei2ff3f492018-11-22 08:00:1328#include "api/create_peerconnection_factory.h"
Steve Anton10542f22019-01-11 17:11:0029#include "api/data_channel_interface.h"
Yves Gerey3e707812018-11-28 15:47:4930#include "api/jsep.h"
Steve Anton10542f22019-01-11 17:11:0031#include "api/jsep_session_description.h"
32#include "api/media_stream_interface.h"
33#include "api/media_types.h"
34#include "api/peer_connection_interface.h"
35#include "api/rtc_error.h"
36#include "api/rtc_event_log_output.h"
Niels Möllerd8b9ed72019-05-08 11:53:5137#include "api/rtc_event_log_output_file.h"
Steve Anton10542f22019-01-11 17:11:0038#include "api/rtp_receiver_interface.h"
39#include "api/rtp_sender_interface.h"
40#include "api/rtp_transceiver_interface.h"
Mirko Bonadeid9708072019-01-25 19:26:4841#include "api/scoped_refptr.h"
Anders Carlsson67537952018-05-03 09:28:2942#include "api/video_codecs/builtin_video_decoder_factory.h"
43#include "api/video_codecs/builtin_video_encoder_factory.h"
Yves Gerey3e707812018-11-28 15:47:4944#include "api/video_codecs/video_decoder_factory.h"
45#include "api/video_codecs/video_encoder_factory.h"
Yves Gerey3e707812018-11-28 15:47:4946#include "logging/rtc_event_log/rtc_event_log.h"
Bjorn Tereliusb8b3c992019-01-09 10:15:3447#include "logging/rtc_event_log/rtc_event_log_factory.h"
Yves Gerey3e707812018-11-28 15:47:4948#include "logging/rtc_event_log/rtc_event_log_factory_interface.h"
49#include "media/base/codec.h"
Steve Anton10542f22019-01-11 17:11:0050#include "media/base/media_config.h"
51#include "media/base/media_engine.h"
52#include "media/base/stream_params.h"
Steve Anton10542f22019-01-11 17:11:0053#include "media/engine/webrtc_media_engine.h"
54#include "media/sctp/sctp_transport_internal.h"
Yves Gerey3e707812018-11-28 15:47:4955#include "modules/audio_device/include/audio_device.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3156#include "modules/audio_processing/include/audio_processing.h"
Steve Anton10542f22019-01-11 17:11:0057#include "p2p/base/fake_port_allocator.h"
58#include "p2p/base/p2p_constants.h"
Yves Gerey3e707812018-11-28 15:47:4959#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 17:11:0060#include "p2p/base/port_allocator.h"
61#include "p2p/base/transport_description.h"
62#include "p2p/base/transport_info.h"
63#include "pc/audio_track.h"
64#include "pc/media_session.h"
65#include "pc/media_stream.h"
66#include "pc/peer_connection.h"
67#include "pc/peer_connection_factory.h"
68#include "pc/rtc_stats_collector.h"
69#include "pc/rtp_sender.h"
70#include "pc/session_description.h"
71#include "pc/stream_collection.h"
72#include "pc/test/fake_audio_capture_module.h"
73#include "pc/test/fake_rtc_certificate_generator.h"
74#include "pc/test/fake_video_track_source.h"
75#include "pc/test/mock_peer_connection_observers.h"
76#include "pc/test/test_sdp_strings.h"
77#include "pc/video_track.h"
Yves Gerey3e707812018-11-28 15:47:4978#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 17:11:0079#include "rtc_base/copy_on_write_buffer.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3180#include "rtc_base/gunit.h"
Yves Gerey3e707812018-11-28 15:47:4981#include "rtc_base/platform_file.h"
Steve Anton10542f22019-01-11 17:11:0082#include "rtc_base/ref_counted_object.h"
83#include "rtc_base/rtc_certificate_generator.h"
Steve Anton10542f22019-01-11 17:11:0084#include "rtc_base/socket_address.h"
Yves Gerey3e707812018-11-28 15:47:4985#include "rtc_base/thread.h"
Steve Anton10542f22019-01-11 17:11:0086#include "rtc_base/time_utils.h"
87#include "rtc_base/virtual_socket_server.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3188#include "test/gmock.h"
Yves Gerey3e707812018-11-28 15:47:4989#include "test/gtest.h"
Steve Anton10542f22019-01-11 17:11:0090#include "test/testsupport/file_utils.h"
kwibergac9f8762016-10-01 05:29:4391
92#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 17:11:0093#include "pc/test/android_test_initializer.h"
kwibergac9f8762016-10-01 05:29:4394#endif
henrike@webrtc.org28e20752013-07-10 00:45:3695
Mirko Bonadeiab64e8a2018-12-12 11:10:1896namespace webrtc {
97namespace {
98
Seth Hampson845e8782018-03-02 19:34:1099static const char kStreamId1[] = "local_stream_1";
100static const char kStreamId2[] = "local_stream_2";
101static const char kStreamId3[] = "local_stream_3";
henrike@webrtc.org28e20752013-07-10 00:45:36102static const int kDefaultStunPort = 3478;
103static const char kStunAddressOnly[] = "stun:address";
104static const char kStunInvalidPort[] = "stun:address:-1";
105static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
106static const char kStunAddressPortAndMore2[] = "stun:address:port more";
Niels Möllerdb4def92019-03-18 15:53:59107static const char kTurnIceServerUri[] = "turn:turn.example.org";
henrike@webrtc.org28e20752013-07-10 00:45:36108static const char kTurnUsername[] = "user";
109static const char kTurnPassword[] = "password";
110static const char kTurnHostname[] = "turn.example.org";
Peter Boström0c4e06b2015-10-07 10:23:21111static const uint32_t kTimeout = 10000U;
henrike@webrtc.org28e20752013-07-10 00:45:36112
deadbeefab9b2d12015-10-14 18:33:11113static const char kStreams[][8] = {"stream1", "stream2"};
114static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
115static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
116
deadbeef5e97fb52015-10-15 19:49:08117static const char kRecvonly[] = "recvonly";
118static const char kSendrecv[] = "sendrecv";
119
deadbeefab9b2d12015-10-14 18:33:11120// Reference SDP with a MediaStream with label "stream1" and audio track with
121// id "audio_1" and a video track with id "video_1;
Steve Anton36da6ff2018-02-17 00:04:20122static const char kSdpStringWithStream1PlanB[] =
deadbeefab9b2d12015-10-14 18:33:11123 "v=0\r\n"
124 "o=- 0 0 IN IP4 127.0.0.1\r\n"
125 "s=-\r\n"
126 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 21:15:33127 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 18:33:11128 "a=ice-ufrag:e5785931\r\n"
129 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
130 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
131 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 18:33:11132 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 19:49:08133 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 18:30:12134 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 18:33:11135 "a=rtpmap:103 ISAC/16000\r\n"
136 "a=ssrc:1 cname:stream1\r\n"
137 "a=ssrc:1 mslabel:stream1\r\n"
138 "a=ssrc:1 label:audiotrack0\r\n"
139 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 21:15:33140 "a=ice-ufrag:e5785931\r\n"
141 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
142 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
143 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 18:33:11144 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 19:49:08145 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 18:30:12146 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 18:33:11147 "a=rtpmap:120 VP8/90000\r\n"
148 "a=ssrc:2 cname:stream1\r\n"
149 "a=ssrc:2 mslabel:stream1\r\n"
150 "a=ssrc:2 label:videotrack0\r\n";
Steve Anton36da6ff2018-02-17 00:04:20151// Same string as above but with the MID changed to the Unified Plan default.
152// This is needed so that this SDP can be used as an answer for a Unified Plan
153// offer.
154static const char kSdpStringWithStream1UnifiedPlan[] =
155 "v=0\r\n"
156 "o=- 0 0 IN IP4 127.0.0.1\r\n"
157 "s=-\r\n"
158 "t=0 0\r\n"
159 "m=audio 1 RTP/AVPF 103\r\n"
160 "a=ice-ufrag:e5785931\r\n"
161 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
162 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
163 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
164 "a=mid:0\r\n"
165 "a=sendrecv\r\n"
166 "a=rtcp-mux\r\n"
167 "a=rtpmap:103 ISAC/16000\r\n"
168 "a=ssrc:1 cname:stream1\r\n"
169 "a=ssrc:1 mslabel:stream1\r\n"
170 "a=ssrc:1 label:audiotrack0\r\n"
171 "m=video 1 RTP/AVPF 120\r\n"
172 "a=ice-ufrag:e5785931\r\n"
173 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
174 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
175 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
176 "a=mid:1\r\n"
177 "a=sendrecv\r\n"
178 "a=rtcp-mux\r\n"
179 "a=rtpmap:120 VP8/90000\r\n"
180 "a=ssrc:2 cname:stream1\r\n"
181 "a=ssrc:2 mslabel:stream1\r\n"
182 "a=ssrc:2 label:videotrack0\r\n";
deadbeefab9b2d12015-10-14 18:33:11183
zhihuang81c3a032016-11-17 20:06:24184// Reference SDP with a MediaStream with label "stream1" and audio track with
185// id "audio_1";
186static const char kSdpStringWithStream1AudioTrackOnly[] =
187 "v=0\r\n"
188 "o=- 0 0 IN IP4 127.0.0.1\r\n"
189 "s=-\r\n"
190 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 21:15:33191 "m=audio 1 RTP/AVPF 103\r\n"
zhihuang81c3a032016-11-17 20:06:24192 "a=ice-ufrag:e5785931\r\n"
193 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
194 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
195 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
zhihuang81c3a032016-11-17 20:06:24196 "a=mid:audio\r\n"
197 "a=sendrecv\r\n"
198 "a=rtpmap:103 ISAC/16000\r\n"
199 "a=ssrc:1 cname:stream1\r\n"
200 "a=ssrc:1 mslabel:stream1\r\n"
zhihuang4dfb8ce2016-11-23 18:30:12201 "a=ssrc:1 label:audiotrack0\r\n"
202 "a=rtcp-mux\r\n";
zhihuang81c3a032016-11-17 20:06:24203
deadbeefab9b2d12015-10-14 18:33:11204// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
205// MediaStreams have one audio track and one video track.
206// This uses MSID.
Steve Anton36da6ff2018-02-17 00:04:20207static const char kSdpStringWithStream1And2PlanB[] =
deadbeefab9b2d12015-10-14 18:33:11208 "v=0\r\n"
209 "o=- 0 0 IN IP4 127.0.0.1\r\n"
210 "s=-\r\n"
211 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 21:15:33212 "a=msid-semantic: WMS stream1 stream2\r\n"
213 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 18:33:11214 "a=ice-ufrag:e5785931\r\n"
215 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
216 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
217 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 18:33:11218 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 19:49:08219 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 18:30:12220 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 18:33:11221 "a=rtpmap:103 ISAC/16000\r\n"
222 "a=ssrc:1 cname:stream1\r\n"
223 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
224 "a=ssrc:3 cname:stream2\r\n"
225 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
226 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 21:15:33227 "a=ice-ufrag:e5785931\r\n"
228 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
229 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
230 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 18:33:11231 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 19:49:08232 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 18:30:12233 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 18:33:11234 "a=rtpmap:120 VP8/0\r\n"
235 "a=ssrc:2 cname:stream1\r\n"
236 "a=ssrc:2 msid:stream1 videotrack0\r\n"
237 "a=ssrc:4 cname:stream2\r\n"
238 "a=ssrc:4 msid:stream2 videotrack1\r\n";
Steve Anton36da6ff2018-02-17 00:04:20239static const char kSdpStringWithStream1And2UnifiedPlan[] =
240 "v=0\r\n"
241 "o=- 0 0 IN IP4 127.0.0.1\r\n"
242 "s=-\r\n"
243 "t=0 0\r\n"
244 "a=msid-semantic: WMS stream1 stream2\r\n"
245 "m=audio 1 RTP/AVPF 103\r\n"
246 "a=ice-ufrag:e5785931\r\n"
247 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
248 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
249 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
250 "a=mid:0\r\n"
251 "a=sendrecv\r\n"
252 "a=rtcp-mux\r\n"
253 "a=rtpmap:103 ISAC/16000\r\n"
254 "a=ssrc:1 cname:stream1\r\n"
255 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
256 "m=video 1 RTP/AVPF 120\r\n"
257 "a=ice-ufrag:e5785931\r\n"
258 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
259 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
260 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
261 "a=mid:1\r\n"
262 "a=sendrecv\r\n"
263 "a=rtcp-mux\r\n"
264 "a=rtpmap:120 VP8/0\r\n"
265 "a=ssrc:2 cname:stream1\r\n"
266 "a=ssrc:2 msid:stream1 videotrack0\r\n"
267 "m=audio 1 RTP/AVPF 103\r\n"
268 "a=ice-ufrag:e5785931\r\n"
269 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
270 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
271 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
272 "a=mid:2\r\n"
273 "a=sendrecv\r\n"
274 "a=rtcp-mux\r\n"
275 "a=rtpmap:103 ISAC/16000\r\n"
276 "a=ssrc:3 cname:stream2\r\n"
277 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
278 "m=video 1 RTP/AVPF 120\r\n"
279 "a=ice-ufrag:e5785931\r\n"
280 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
281 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
282 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
283 "a=mid:3\r\n"
284 "a=sendrecv\r\n"
285 "a=rtcp-mux\r\n"
286 "a=rtpmap:120 VP8/0\r\n"
287 "a=ssrc:4 cname:stream2\r\n"
288 "a=ssrc:4 msid:stream2 videotrack1\r\n";
deadbeefab9b2d12015-10-14 18:33:11289
290// Reference SDP without MediaStreams. Msid is not supported.
291static const char kSdpStringWithoutStreams[] =
292 "v=0\r\n"
293 "o=- 0 0 IN IP4 127.0.0.1\r\n"
294 "s=-\r\n"
295 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 21:15:33296 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 18:33:11297 "a=ice-ufrag:e5785931\r\n"
298 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
299 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
300 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 18:33:11301 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 19:49:08302 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 18:30:12303 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 18:33:11304 "a=rtpmap:103 ISAC/16000\r\n"
305 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 21:15:33306 "a=ice-ufrag:e5785931\r\n"
307 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
308 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
309 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 18:33:11310 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 19:49:08311 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 18:30:12312 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 18:33:11313 "a=rtpmap:120 VP8/90000\r\n";
314
315// Reference SDP without MediaStreams. Msid is supported.
316static const char kSdpStringWithMsidWithoutStreams[] =
317 "v=0\r\n"
318 "o=- 0 0 IN IP4 127.0.0.1\r\n"
319 "s=-\r\n"
320 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 21:15:33321 "a=msid-semantic: WMS\r\n"
322 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 18:33:11323 "a=ice-ufrag:e5785931\r\n"
324 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
325 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
326 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 18:33:11327 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 19:49:08328 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 18:30:12329 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 18:33:11330 "a=rtpmap:103 ISAC/16000\r\n"
331 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 21:15:33332 "a=ice-ufrag:e5785931\r\n"
333 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
334 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
335 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 18:33:11336 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 19:49:08337 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 18:30:12338 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 18:33:11339 "a=rtpmap:120 VP8/90000\r\n";
340
341// Reference SDP without MediaStreams and audio only.
342static const char kSdpStringWithoutStreamsAudioOnly[] =
343 "v=0\r\n"
344 "o=- 0 0 IN IP4 127.0.0.1\r\n"
345 "s=-\r\n"
346 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 21:15:33347 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 18:33:11348 "a=ice-ufrag:e5785931\r\n"
349 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
350 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
351 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 18:33:11352 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 19:49:08353 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 18:30:12354 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 18:33:11355 "a=rtpmap:103 ISAC/16000\r\n";
356
357// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
358static const char kSdpStringSendOnlyWithoutStreams[] =
359 "v=0\r\n"
360 "o=- 0 0 IN IP4 127.0.0.1\r\n"
361 "s=-\r\n"
362 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 21:15:33363 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 18:33:11364 "a=ice-ufrag:e5785931\r\n"
365 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
366 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
367 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 18:33:11368 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 19:49:08369 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 18:33:11370 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 18:30:12371 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 18:33:11372 "a=rtpmap:103 ISAC/16000\r\n"
373 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 21:15:33374 "a=ice-ufrag:e5785931\r\n"
375 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
376 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
377 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 18:33:11378 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 19:49:08379 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 18:33:11380 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 18:30:12381 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 18:33:11382 "a=rtpmap:120 VP8/90000\r\n";
383
384static const char kSdpStringInit[] =
385 "v=0\r\n"
386 "o=- 0 0 IN IP4 127.0.0.1\r\n"
387 "s=-\r\n"
388 "t=0 0\r\n"
deadbeefab9b2d12015-10-14 18:33:11389 "a=msid-semantic: WMS\r\n";
390
391static const char kSdpStringAudio[] =
392 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefd1a38b52016-12-10 21:15:33393 "a=ice-ufrag:e5785931\r\n"
394 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
395 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
396 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 18:33:11397 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 19:49:08398 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 18:30:12399 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 18:33:11400 "a=rtpmap:103 ISAC/16000\r\n";
401
402static const char kSdpStringVideo[] =
403 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 21:15:33404 "a=ice-ufrag:e5785931\r\n"
405 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
406 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
407 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 18:33:11408 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 19:49:08409 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 18:30:12410 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 18:33:11411 "a=rtpmap:120 VP8/90000\r\n";
412
413static const char kSdpStringMs1Audio0[] =
414 "a=ssrc:1 cname:stream1\r\n"
415 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
416
417static const char kSdpStringMs1Video0[] =
418 "a=ssrc:2 cname:stream1\r\n"
419 "a=ssrc:2 msid:stream1 videotrack0\r\n";
420
421static const char kSdpStringMs1Audio1[] =
422 "a=ssrc:3 cname:stream1\r\n"
423 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
424
425static const char kSdpStringMs1Video1[] =
426 "a=ssrc:4 cname:stream1\r\n"
427 "a=ssrc:4 msid:stream1 videotrack1\r\n";
428
deadbeef8662f942017-01-21 05:20:51429static const char kDtlsSdesFallbackSdp[] =
430 "v=0\r\n"
431 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
432 "s=-\r\n"
433 "c=IN IP4 0.0.0.0\r\n"
434 "t=0 0\r\n"
435 "a=group:BUNDLE audio\r\n"
436 "a=msid-semantic: WMS\r\n"
437 "m=audio 1 RTP/SAVPF 0\r\n"
438 "a=sendrecv\r\n"
439 "a=rtcp-mux\r\n"
440 "a=mid:audio\r\n"
441 "a=ssrc:1 cname:stream1\r\n"
442 "a=ssrc:1 mslabel:stream1\r\n"
443 "a=ssrc:1 label:audiotrack0\r\n"
444 "a=ice-ufrag:e5785931\r\n"
445 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
446 "a=rtpmap:0 pcmu/8000\r\n"
447 "a=fingerprint:sha-1 "
448 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
449 "a=setup:actpass\r\n"
Taylor Brandstetterfd350d72018-04-03 23:29:26450 "a=crypto:0 AES_CM_128_HMAC_SHA1_80 "
deadbeef8662f942017-01-21 05:20:51451 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
452 "dummy_session_params\r\n";
453
Mirko Bonadeiab64e8a2018-12-12 11:10:18454using ::cricket::StreamParams;
perkjd61bf802016-03-24 10:16:19455using ::testing::Exactly;
Steve Anton36da6ff2018-02-17 00:04:20456using ::testing::Values;
henrike@webrtc.org28e20752013-07-10 00:45:36457
Steve Anton36da6ff2018-02-17 00:04:20458using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
459using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
deadbeefab9b2d12015-10-14 18:33:11460
henrike@webrtc.org28e20752013-07-10 00:45:36461// Gets the first ssrc of given content type from the ContentInfo.
462bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
463 if (!content_info || !ssrc) {
464 return false;
465 }
466 const cricket::MediaContentDescription* media_desc =
Steve Antonb1c1de12017-12-21 23:14:30467 content_info->media_description();
henrike@webrtc.org28e20752013-07-10 00:45:36468 if (!media_desc || media_desc->streams().empty()) {
469 return false;
470 }
471 *ssrc = media_desc->streams().begin()->first_ssrc();
472 return true;
473}
474
deadbeefd1a38b52016-12-10 21:15:33475// Get the ufrags out of an SDP blob. Useful for testing ICE restart
476// behavior.
477std::vector<std::string> GetUfrags(
478 const webrtc::SessionDescriptionInterface* desc) {
479 std::vector<std::string> ufrags;
480 for (const cricket::TransportInfo& info :
481 desc->description()->transport_infos()) {
482 ufrags.push_back(info.description.ice_ufrag);
483 }
484 return ufrags;
485}
486
henrike@webrtc.org28e20752013-07-10 00:45:36487void SetSsrcToZero(std::string* sdp) {
488 const char kSdpSsrcAtribute[] = "a=ssrc:";
489 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
490 size_t ssrc_pos = 0;
491 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
Yves Gerey665174f2018-06-19 13:03:05492 std::string::npos) {
henrike@webrtc.org28e20752013-07-10 00:45:36493 size_t end_ssrc = sdp->find(" ", ssrc_pos);
494 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
495 ssrc_pos = end_ssrc;
496 }
497}
498
deadbeefab9b2d12015-10-14 18:33:11499// Check if |streams| contains the specified track.
500bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
Seth Hampson845e8782018-03-02 19:34:10501 const std::string& stream_id,
deadbeefab9b2d12015-10-14 18:33:11502 const std::string& track_id) {
503 for (const cricket::StreamParams& params : streams) {
Seth Hampson845e8782018-03-02 19:34:10504 if (params.first_stream_id() == stream_id && params.id == track_id) {
deadbeefab9b2d12015-10-14 18:33:11505 return true;
506 }
507 }
508 return false;
509}
510
511// Check if |senders| contains the specified sender, by id.
512bool ContainsSender(
513 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
514 const std::string& id) {
515 for (const auto& sender : senders) {
516 if (sender->id() == id) {
517 return true;
518 }
519 }
520 return false;
521}
522
Taylor Brandstetterdc4eb8c2016-05-12 15:14:50523// Check if |senders| contains the specified sender, by id and stream id.
524bool ContainsSender(
525 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
526 const std::string& id,
527 const std::string& stream_id) {
528 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 21:27:39529 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 15:14:50530 return true;
531 }
532 }
533 return false;
534}
535
deadbeefab9b2d12015-10-14 18:33:11536// Create a collection of streams.
537// CreateStreamCollection(1) creates a collection that
538// correspond to kSdpStringWithStream1.
539// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
540rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 15:14:50541 int number_of_streams,
542 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 18:33:11543 rtc::scoped_refptr<StreamCollection> local_collection(
544 StreamCollection::Create());
545
546 for (int i = 0; i < number_of_streams; ++i) {
547 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
548 webrtc::MediaStream::Create(kStreams[i]));
549
Taylor Brandstetterdc4eb8c2016-05-12 15:14:50550 for (int j = 0; j < tracks_per_stream; ++j) {
551 // Add a local audio track.
552 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
553 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
554 nullptr));
555 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 18:33:11556
Taylor Brandstetterdc4eb8c2016-05-12 15:14:50557 // Add a local video track.
558 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
559 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
perkj773be362017-08-01 06:22:01560 webrtc::FakeVideoTrackSource::Create(),
561 rtc::Thread::Current()));
Taylor Brandstetterdc4eb8c2016-05-12 15:14:50562 stream->AddTrack(video_track);
563 }
deadbeefab9b2d12015-10-14 18:33:11564
565 local_collection->AddStream(stream);
566 }
567 return local_collection;
568}
569
570// Check equality of StreamCollections.
571bool CompareStreamCollections(StreamCollectionInterface* s1,
572 StreamCollectionInterface* s2) {
573 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
574 return false;
575 }
576
577 for (size_t i = 0; i != s1->count(); ++i) {
Seth Hampson13b8bad2018-03-13 23:05:28578 if (s1->at(i)->id() != s2->at(i)->id()) {
deadbeefab9b2d12015-10-14 18:33:11579 return false;
580 }
581 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
582 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
583 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
584 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
585
586 if (audio_tracks1.size() != audio_tracks2.size()) {
587 return false;
588 }
589 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
590 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
591 return false;
592 }
593 }
594 if (video_tracks1.size() != video_tracks2.size()) {
595 return false;
596 }
597 for (size_t j = 0; j != video_tracks1.size(); ++j) {
598 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
599 return false;
600 }
601 }
602 }
603 return true;
604}
605
perkjd61bf802016-03-24 10:16:19606// Helper class to test Observer.
607class MockTrackObserver : public ObserverInterface {
608 public:
609 explicit MockTrackObserver(NotifierInterface* notifier)
610 : notifier_(notifier) {
611 notifier_->RegisterObserver(this);
612 }
613
614 ~MockTrackObserver() { Unregister(); }
615
616 void Unregister() {
617 if (notifier_) {
618 notifier_->UnregisterObserver(this);
619 notifier_ = nullptr;
620 }
621 }
622
623 MOCK_METHOD0(OnChanged, void());
624
625 private:
626 NotifierInterface* notifier_;
627};
628
nisse528b7932017-05-08 10:21:43629// The PeerConnectionMediaConfig tests below verify that configuration and
630// constraints are propagated into the PeerConnection's MediaConfig. These
631// settings are intended for MediaChannel constructors, but that is not
632// exercised by these unittest.
zhihuang29ff8442016-07-27 18:07:25633class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
634 public:
zhihuang38ede132017-06-15 19:52:32635 static rtc::scoped_refptr<PeerConnectionFactoryForTest>
636 CreatePeerConnectionFactoryForTest() {
637 auto audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
638 auto audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
Anders Carlssonb3306882018-05-14 08:11:42639 auto video_encoder_factory = webrtc::CreateBuiltinVideoEncoderFactory();
640 auto video_decoder_factory = webrtc::CreateBuiltinVideoDecoderFactory();
zhihuang38ede132017-06-15 19:52:32641
Danil Chapovalovf5258be2019-03-19 16:45:24642 PeerConnectionFactoryDependencies dependencies;
643 dependencies.worker_thread = rtc::Thread::Current();
644 dependencies.network_thread = rtc::Thread::Current();
645 dependencies.signaling_thread = rtc::Thread::Current();
646
henrika919dc2e2017-10-12 12:24:55647 // Use fake audio device module since we're only testing the interface
648 // level, and using a real one could make tests flaky when run in parallel.
Danil Chapovalovf5258be2019-03-19 16:45:24649 dependencies.media_engine = std::unique_ptr<cricket::MediaEngineInterface>(
zhihuang38ede132017-06-15 19:52:32650 cricket::WebRtcMediaEngineFactory::Create(
henrika919dc2e2017-10-12 12:24:55651 FakeAudioCaptureModule::Create(), audio_encoder_factory,
Anders Carlssonb3306882018-05-14 08:11:42652 audio_decoder_factory, std::move(video_encoder_factory),
Qingsi Wang59844ce2018-11-01 04:45:53653 std::move(video_decoder_factory), nullptr,
Ivo Creusen62337e52018-01-09 13:17:33654 webrtc::AudioProcessingBuilder().Create()));
zhihuang38ede132017-06-15 19:52:32655
Danil Chapovalovf5258be2019-03-19 16:45:24656 dependencies.call_factory = webrtc::CreateCallFactory();
657 dependencies.event_log_factory = webrtc::CreateRtcEventLogFactory();
zhihuang38ede132017-06-15 19:52:32658
659 return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
Danil Chapovalovf5258be2019-03-19 16:45:24660 std::move(dependencies));
zhihuang38ede132017-06-15 19:52:32661 }
662
Danil Chapovalovf5258be2019-03-19 16:45:24663 using PeerConnectionFactory::PeerConnectionFactory;
kwiberg1e4e8cb2017-01-31 09:48:08664
Danil Chapovalovf5258be2019-03-19 16:45:24665 private:
deadbeefd7850b22017-08-23 17:59:19666 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 18:07:25667};
668
Steve Anton36da6ff2018-02-17 00:04:20669// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
Mirko Bonadei6a489f22019-04-09 13:11:12670class PeerConnectionInterfaceBaseTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36671 protected:
Steve Anton36da6ff2018-02-17 00:04:20672 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
673 : vss_(new rtc::VirtualSocketServer()),
674 main_(vss_.get()),
675 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 13:04:57676#ifdef WEBRTC_ANDROID
677 webrtc::InitializeAndroidObjects();
678#endif
679 }
680
henrike@webrtc.org28e20752013-07-10 00:45:36681 virtual void SetUp() {
deadbeefd7850b22017-08-23 17:59:19682 // Use fake audio capture module since we're only testing the interface
683 // level, and using a real one could make tests flaky when run in parallel.
684 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36685 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 08:52:02686 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 09:28:29687 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
688 fake_audio_capture_module_),
689 webrtc::CreateBuiltinAudioEncoderFactory(),
690 webrtc::CreateBuiltinAudioDecoderFactory(),
691 webrtc::CreateBuiltinVideoEncoderFactory(),
692 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
693 nullptr /* audio_processing */);
danilchape9021a32016-05-17 08:52:02694 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 18:07:25695 pc_factory_for_test_ =
zhihuang38ede132017-06-15 19:52:32696 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
zhihuang29ff8442016-07-27 18:07:25697 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36698 }
699
700 void CreatePeerConnection() {
Niels Möllerf06f9232018-08-07 10:32:18701 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration());
henrike@webrtc.org28e20752013-07-10 00:45:36702 }
703
deadbeef293e9262017-01-11 20:28:30704 // DTLS does not work in a loopback call, so is disabled for most of the
705 // tests in this file.
706 void CreatePeerConnectionWithoutDtls() {
Niels Möllerf06f9232018-08-07 10:32:18707 RTCConfiguration config;
708 config.enable_dtls_srtp = false;
deadbeef293e9262017-01-11 20:28:30709
Niels Möllerf06f9232018-08-07 10:32:18710 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36711 }
712
Taylor Brandstettera1c30352016-05-13 15:15:11713 void CreatePeerConnectionWithIceTransportsType(
714 PeerConnectionInterface::IceTransportsType type) {
715 PeerConnectionInterface::RTCConfiguration config;
716 config.type = type;
Niels Möllerf06f9232018-08-07 10:32:18717 return CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 15:15:11718 }
719
720 void CreatePeerConnectionWithIceServer(const std::string& uri,
Niels Möllerdb4def92019-03-18 15:53:59721 const std::string& username,
Taylor Brandstettera1c30352016-05-13 15:15:11722 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 22:14:52723 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36724 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 15:15:11725 server.uri = uri;
Niels Möllerdb4def92019-03-18 15:53:59726 server.username = username;
Taylor Brandstettera1c30352016-05-13 15:15:11727 server.password = password;
728 config.servers.push_back(server);
Niels Möllerf06f9232018-08-07 10:32:18729 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 15:15:11730 }
henrike@webrtc.org28e20752013-07-10 00:45:36731
Niels Möllerf06f9232018-08-07 10:32:18732 void CreatePeerConnection(const RTCConfiguration& config) {
kwibergd1fe2812016-04-27 13:47:29733 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 22:14:52734 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
735 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53736
deadbeef1dcb1642017-03-30 04:08:16737 // Create certificate generator unless DTLS constraint is explicitly set to
738 // false.
Henrik Boströmd79599d2016-06-01 11:58:50739 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
Niels Möllerf06f9232018-08-07 10:32:18740
741 if (config.enable_dtls_srtp.value_or(true)) {
deadbeef8662f942017-01-21 05:20:51742 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
743 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53744 }
Steve Anton36da6ff2018-02-17 00:04:20745 RTCConfiguration modified_config = config;
746 modified_config.sdp_semantics = sdp_semantics_;
Henrik Boströmd79599d2016-06-01 11:58:50747 pc_ = pc_factory_->CreatePeerConnection(
Niels Möllerf06f9232018-08-07 10:32:18748 modified_config, std::move(port_allocator), std::move(cert_generator),
749 &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36750 ASSERT_TRUE(pc_.get() != NULL);
751 observer_.SetPeerConnectionInterface(pc_.get());
752 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
753 }
754
deadbeef0a6c4ca2015-10-06 18:38:28755 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 22:14:52756 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 18:38:28757 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 18:38:28758 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 22:14:52759 config.servers.push_back(server);
Steve Anton36da6ff2018-02-17 00:04:20760 config.sdp_semantics = sdp_semantics_;
761 rtc::scoped_refptr<PeerConnectionInterface> pc =
Niels Möllerf06f9232018-08-07 10:32:18762 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
Taylor Brandstetter0c7e9f52015-12-29 22:14:52763 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 18:38:28764 }
765
Steve Anton038834f2017-07-14 22:59:59766 void CreatePeerConnectionExpectFail(
767 PeerConnectionInterface::RTCConfiguration config) {
768 PeerConnectionInterface::IceServer server;
769 server.uri = kTurnIceServerUri;
770 server.password = kTurnPassword;
771 config.servers.push_back(server);
Steve Anton36da6ff2018-02-17 00:04:20772 config.sdp_semantics = sdp_semantics_;
Steve Anton038834f2017-07-14 22:59:59773 rtc::scoped_refptr<PeerConnectionInterface> pc =
774 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
775 EXPECT_EQ(nullptr, pc);
776 }
777
henrike@webrtc.org28e20752013-07-10 00:45:36778 void CreatePeerConnectionWithDifferentConfigurations() {
Niels Möllerdb4def92019-03-18 15:53:59779 CreatePeerConnectionWithIceServer(kStunAddressOnly, "", "");
Taylor Brandstetter0c7e9f52015-12-29 22:14:52780 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
781 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
782 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36783 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 22:14:52784 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36785
deadbeef0a6c4ca2015-10-06 18:38:28786 CreatePeerConnectionExpectFail(kStunInvalidPort);
787 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
788 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36789
Niels Möllerdb4def92019-03-18 15:53:59790 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnUsername,
791 kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 22:14:52792 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
793 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36794 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 22:14:52795 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36796 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 22:14:52797 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36798 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 22:14:52799 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36800 }
801
802 void ReleasePeerConnection() {
803 pc_ = NULL;
804 observer_.SetPeerConnectionInterface(NULL);
805 }
806
Steve Anton36da6ff2018-02-17 00:04:20807 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
808 const std::string& label) {
Niels Möller215ba602019-01-18 12:59:45809 return pc_factory_->CreateVideoTrack(label, FakeVideoTrackSource::Create());
Steve Anton36da6ff2018-02-17 00:04:20810 }
811
812 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 19:34:10813 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-17 00:04:20814 auto sender_or_error =
Seth Hampson845e8782018-03-02 19:34:10815 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-17 00:04:20816 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36817 }
818
Steve Anton36da6ff2018-02-17 00:04:20819 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 18:14:50820 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36821 pc_factory_->CreateLocalMediaStream(label));
Steve Anton36da6ff2018-02-17 00:04:20822 stream->AddTrack(CreateVideoTrack(label + "v0"));
823 ASSERT_TRUE(pc_->AddStream(stream));
Steve Anton36da6ff2018-02-17 00:04:20824 }
825
826 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
827 const std::string& label) {
828 return pc_factory_->CreateAudioTrack(label, nullptr);
829 }
830
831 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 19:34:10832 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-17 00:04:20833 auto sender_or_error =
Seth Hampson845e8782018-03-02 19:34:10834 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-17 00:04:20835 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
Steve Anton36da6ff2018-02-17 00:04:20836 }
837
838 void AddAudioStream(const std::string& label) {
839 rtc::scoped_refptr<MediaStreamInterface> stream(
840 pc_factory_->CreateLocalMediaStream(label));
841 stream->AddTrack(CreateAudioTrack(label + "a0"));
842 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36843 }
844
Seth Hampson845e8782018-03-02 19:34:10845 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36846 const std::string& audio_track_label,
847 const std::string& video_track_label) {
848 // Create a local stream.
zhihuang9763d562016-08-05 18:14:50849 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 19:34:10850 pc_factory_->CreateLocalMediaStream(stream_id));
Steve Anton36da6ff2018-02-17 00:04:20851 stream->AddTrack(CreateAudioTrack(audio_track_label));
852 stream->AddTrack(CreateVideoTrack(video_track_label));
853 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36854 }
855
Steve Anton36da6ff2018-02-17 00:04:20856 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
857 cricket::MediaType media_type) {
858 for (auto receiver : pc_->GetReceivers()) {
859 if (receiver->media_type() == media_type) {
860 return receiver;
861 }
862 }
863 return nullptr;
864 }
865
kwibergd1fe2812016-04-27 13:47:29866 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 10:32:18867 const RTCOfferAnswerOptions* options,
868 bool offer) {
Yves Gerey665174f2018-06-19 13:03:05869 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
870 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36871 if (offer) {
Niels Möllerf06f9232018-08-07 10:32:18872 pc_->CreateOffer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36873 } else {
Niels Möllerf06f9232018-08-07 10:32:18874 pc_->CreateAnswer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36875 }
876 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-30 04:08:16877 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36878 return observer->result();
879 }
880
kwibergd1fe2812016-04-27 13:47:29881 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 10:32:18882 const RTCOfferAnswerOptions* options) {
883 return DoCreateOfferAnswer(desc, options, true);
henrike@webrtc.org28e20752013-07-10 00:45:36884 }
885
kwibergd1fe2812016-04-27 13:47:29886 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 10:32:18887 const RTCOfferAnswerOptions* options) {
888 return DoCreateOfferAnswer(desc, options, false);
henrike@webrtc.org28e20752013-07-10 00:45:36889 }
890
Steve Antondb45ca82017-09-12 01:27:34891 bool DoSetSessionDescription(
892 std::unique_ptr<SessionDescriptionInterface> desc,
893 bool local) {
Yves Gerey665174f2018-06-19 13:03:05894 rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
895 new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36896 if (local) {
Steve Antondb45ca82017-09-12 01:27:34897 pc_->SetLocalDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36898 } else {
Steve Antondb45ca82017-09-12 01:27:34899 pc_->SetRemoteDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36900 }
zhihuang29ff8442016-07-27 18:07:25901 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
902 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
903 }
henrike@webrtc.org28e20752013-07-10 00:45:36904 return observer->result();
905 }
906
Steve Antondb45ca82017-09-12 01:27:34907 bool DoSetLocalDescription(
908 std::unique_ptr<SessionDescriptionInterface> desc) {
909 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36910 }
911
Steve Antondb45ca82017-09-12 01:27:34912 bool DoSetRemoteDescription(
913 std::unique_ptr<SessionDescriptionInterface> desc) {
914 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36915 }
916
917 // Calls PeerConnection::GetStats and check the return value.
918 // It does not verify the values in the StatReports since a RTCP packet might
919 // be required.
920 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52921 rtc::scoped_refptr<MockStatsObserver> observer(
922 new rtc::RefCountedObject<MockStatsObserver>());
Yves Gerey665174f2018-06-19 13:03:05923 if (!pc_->GetStats(observer, track,
924 PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36925 return false;
926 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
927 return observer->called();
928 }
929
Harald Alvestrand89061872018-01-02 13:08:34930 // Call the standards-compliant GetStats function.
931 bool DoGetRTCStats() {
932 rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback(
933 new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>());
934 pc_->GetStats(callback);
935 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
936 return callback->called();
937 }
938
henrike@webrtc.org28e20752013-07-10 00:45:36939 void InitiateCall() {
deadbeef293e9262017-01-11 20:28:30940 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36941 // Create a local stream with audio&video tracks.
Steve Anton36da6ff2018-02-17 00:04:20942 if (sdp_semantics_ == SdpSemantics::kPlanB) {
Seth Hampson845e8782018-03-02 19:34:10943 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-17 00:04:20944 } else {
945 // Unified Plan does not support AddStream, so just add an audio and video
946 // track.
Seth Hampson845e8782018-03-02 19:34:10947 AddAudioTrack(kAudioTracks[0], {kStreamId1});
948 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-17 00:04:20949 }
henrike@webrtc.org28e20752013-07-10 00:45:36950 CreateOfferReceiveAnswer();
951 }
952
953 // Verify that RTP Header extensions has been negotiated for audio and video.
954 void VerifyRemoteRtpHeaderExtensions() {
955 const cricket::MediaContentDescription* desc =
956 cricket::GetFirstAudioContentDescription(
957 pc_->remote_description()->description());
958 ASSERT_TRUE(desc != NULL);
959 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
960
961 desc = cricket::GetFirstVideoContentDescription(
962 pc_->remote_description()->description());
963 ASSERT_TRUE(desc != NULL);
964 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
965 }
966
967 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 13:47:29968 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 18:03:04969 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36970 std::string sdp;
971 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-12 01:27:34972 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 18:27:41973 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-12 01:27:34974 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36975 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
976 }
977
deadbeefab9b2d12015-10-14 18:33:11978 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-12 01:27:34979 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 18:27:41980 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-12 01:27:34981 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 18:33:11982 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
983 }
984
henrike@webrtc.org28e20752013-07-10 00:45:36985 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 13:47:29986 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 18:03:04987 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36988
989 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
990 // audio codec change, even if the parameter has nothing to do with
991 // receiving. Not all parameters are serialized to SDP.
992 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
993 // the SessionDescription, it is necessary to do that here to in order to
994 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
995 // https://code.google.com/p/webrtc/issues/detail?id=1356
996 std::string sdp;
997 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-12 01:27:34998 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 18:27:41999 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-12 01:27:341000 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:361001 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1002 }
1003
1004 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 13:47:291005 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 18:03:041006 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:361007
1008 std::string sdp;
1009 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-12 01:27:341010 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 18:27:411011 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-12 01:27:341012 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:361013 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1014 }
1015
1016 void CreateOfferReceiveAnswer() {
1017 CreateOfferAsLocalDescription();
1018 std::string sdp;
1019 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1020 CreateAnswerAsRemoteDescription(sdp);
1021 }
1022
1023 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 13:47:291024 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 18:03:041025 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:361026 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1027 // audio codec change, even if the parameter has nothing to do with
1028 // receiving. Not all parameters are serialized to SDP.
1029 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1030 // the SessionDescription, it is necessary to do that here to in order to
1031 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1032 // https://code.google.com/p/webrtc/issues/detail?id=1356
1033 std::string sdp;
1034 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-12 01:27:341035 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 18:27:411036 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:361037
Steve Antondb45ca82017-09-12 01:27:341038 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:361039 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:461040 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 16:39:201041 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:361042 }
1043
deadbeefab9b2d12015-10-14 18:33:111044 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-12 01:27:341045 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 18:27:411046 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-12 01:27:341047 ASSERT_TRUE(answer);
1048 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:361049 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1050 }
1051
deadbeefab9b2d12015-10-14 18:33:111052 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-12 01:27:341053 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 18:27:411054 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-12 01:27:341055 ASSERT_TRUE(pr_answer);
1056 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:361057 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-12 01:27:341058 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 18:27:411059 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-12 01:27:341060 ASSERT_TRUE(answer);
1061 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:361062 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1063 }
1064
Seth Hampson845e8782018-03-02 19:34:101065 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-17 00:04:201066 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 19:34:101067 // called with the given stream id and expected number of tracks.
1068 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-17 00:04:201069 int expected_num_tracks) {
1070 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 19:34:101071 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-17 00:04:201072 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 19:34:101073 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:361074 }
1075
1076 // Creates an offer and applies it as a local session description.
1077 // Creates an answer with the same SDP an the offer but removes all lines
1078 // that start with a:ssrc"
1079 void CreateOfferReceiveAnswerWithoutSsrc() {
1080 CreateOfferAsLocalDescription();
1081 std::string sdp;
1082 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1083 SetSsrcToZero(&sdp);
1084 CreateAnswerAsRemoteDescription(sdp);
1085 }
1086
deadbeefab9b2d12015-10-14 18:33:111087 // This function creates a MediaStream with label kStreams[0] and
1088 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1089 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 18:03:041090 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 18:33:111091 // |reference_collection_|
kwibergd1fe2812016-04-27 13:47:291092 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 18:03:041093 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1094 size_t number_of_video_tracks) {
1095 EXPECT_LE(number_of_audio_tracks, 2u);
1096 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 18:33:111097
1098 reference_collection_ = StreamCollection::Create();
1099 std::string sdp_ms1 = std::string(kSdpStringInit);
1100
Seth Hampson845e8782018-03-02 19:34:101101 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 18:33:111102
1103 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 19:34:101104 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 18:33:111105 reference_collection_->AddStream(stream);
1106
1107 if (number_of_audio_tracks > 0) {
1108 sdp_ms1 += std::string(kSdpStringAudio);
1109 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1110 AddAudioTrack(kAudioTracks[0], stream);
1111 }
1112 if (number_of_audio_tracks > 1) {
1113 sdp_ms1 += kSdpStringMs1Audio1;
1114 AddAudioTrack(kAudioTracks[1], stream);
1115 }
1116
1117 if (number_of_video_tracks > 0) {
1118 sdp_ms1 += std::string(kSdpStringVideo);
1119 sdp_ms1 += std::string(kSdpStringMs1Video0);
1120 AddVideoTrack(kVideoTracks[0], stream);
1121 }
1122 if (number_of_video_tracks > 1) {
1123 sdp_ms1 += kSdpStringMs1Video1;
1124 AddVideoTrack(kVideoTracks[1], stream);
1125 }
1126
kwibergd1fe2812016-04-27 13:47:291127 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 18:27:411128 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 18:33:111129 }
1130
1131 void AddAudioTrack(const std::string& track_id,
1132 MediaStreamInterface* stream) {
1133 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1134 webrtc::AudioTrack::Create(track_id, nullptr));
1135 ASSERT_TRUE(stream->AddTrack(audio_track));
1136 }
1137
1138 void AddVideoTrack(const std::string& track_id,
1139 MediaStreamInterface* stream) {
1140 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 15:20:421141 webrtc::VideoTrack::Create(track_id,
perkj773be362017-08-01 06:22:011142 webrtc::FakeVideoTrackSource::Create(),
1143 rtc::Thread::Current()));
deadbeefab9b2d12015-10-14 18:33:111144 ASSERT_TRUE(stream->AddTrack(video_track));
1145 }
1146
Steve Anton36da6ff2018-02-17 00:04:201147 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 20:28:301148 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-17 00:04:201149 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-15 02:44:111150 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-07 01:40:301151 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1152 return offer;
1153 }
1154
Steve Anton36da6ff2018-02-17 00:04:201155 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1156 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 19:34:101157 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-17 00:04:201158 std::unique_ptr<SessionDescriptionInterface> offer;
1159 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1160 return offer;
1161 }
1162
1163 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1164 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1165 std::unique_ptr<SessionDescriptionInterface> answer;
1166 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1167 return answer;
1168 }
1169
kwibergfd8be342016-05-15 02:44:111170 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-07 01:40:301171 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-12 01:27:341172 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-15 02:44:111173 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-07 01:40:301174 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1175 return answer;
1176 }
1177
1178 const std::string& GetFirstAudioStreamCname(
1179 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-07 01:40:301180 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 23:14:301181 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-07 01:40:301182 return audio_desc->streams()[0].cname;
1183 }
1184
zhihuang1c378ed2017-08-17 21:10:501185 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1186 const RTCOfferAnswerOptions& offer_answer_options) {
1187 RTC_DCHECK(pc_);
1188 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
1189 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
1190 pc_->CreateOffer(observer, offer_answer_options);
1191 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1192 return observer->MoveDescription();
1193 }
1194
1195 void CreateOfferWithOptionsAsRemoteDescription(
1196 std::unique_ptr<SessionDescriptionInterface>* desc,
1197 const RTCOfferAnswerOptions& offer_answer_options) {
1198 *desc = CreateOfferWithOptions(offer_answer_options);
1199 ASSERT_TRUE(desc != nullptr);
1200 std::string sdp;
1201 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-12 01:27:341202 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 18:27:411203 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-12 01:27:341204 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 21:10:501205 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1206 }
1207
1208 void CreateOfferWithOptionsAsLocalDescription(
1209 std::unique_ptr<SessionDescriptionInterface>* desc,
1210 const RTCOfferAnswerOptions& offer_answer_options) {
1211 *desc = CreateOfferWithOptions(offer_answer_options);
1212 ASSERT_TRUE(desc != nullptr);
1213 std::string sdp;
1214 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-12 01:27:341215 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 18:27:411216 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 21:10:501217
Steve Antondb45ca82017-09-12 01:27:341218 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 21:10:501219 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1220 }
1221
1222 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 23:14:301223 RTC_DCHECK(content);
1224 RTC_DCHECK(content->media_description());
1225 for (const cricket::AudioCodec& codec :
1226 content->media_description()->as_audio()->codecs()) {
1227 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 21:10:501228 return true;
Steve Antonb1c1de12017-12-21 23:14:301229 }
zhihuang1c378ed2017-08-17 21:10:501230 }
1231 return false;
1232 }
1233
Steve Anton36da6ff2018-02-17 00:04:201234 const char* GetSdpStringWithStream1() const {
1235 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1236 return kSdpStringWithStream1PlanB;
1237 } else {
1238 return kSdpStringWithStream1UnifiedPlan;
1239 }
1240 }
1241
1242 const char* GetSdpStringWithStream1And2() const {
1243 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1244 return kSdpStringWithStream1And2PlanB;
1245 } else {
1246 return kSdpStringWithStream1And2UnifiedPlan;
1247 }
1248 }
1249
deadbeef9a6f4d42017-05-16 02:43:331250 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1251 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 17:59:191252 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 22:14:521253 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-21 05:20:511254 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 18:14:501255 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1256 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1257 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:361258 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 18:33:111259 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-17 00:04:201260 const SdpSemantics sdp_semantics_;
1261};
1262
1263class PeerConnectionInterfaceTest
1264 : public PeerConnectionInterfaceBaseTest,
1265 public ::testing::WithParamInterface<SdpSemantics> {
1266 protected:
1267 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1268};
1269
1270class PeerConnectionInterfaceTestPlanB
1271 : public PeerConnectionInterfaceBaseTest {
1272 protected:
1273 PeerConnectionInterfaceTestPlanB()
1274 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB) {}
henrike@webrtc.org28e20752013-07-10 00:45:361275};
1276
zhihuang8f65cdf2016-05-07 01:40:301277// Generate different CNAMEs when PeerConnections are created.
1278// The CNAMEs are expected to be generated randomly. It is possible
1279// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-17 00:04:201280TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-15 02:44:111281 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-17 00:04:201282 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-15 02:44:111283 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-17 00:04:201284 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-07 01:40:301285 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1286 GetFirstAudioStreamCname(offer2.get()));
1287}
1288
Steve Anton36da6ff2018-02-17 00:04:201289TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-15 02:44:111290 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-17 00:04:201291 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-15 02:44:111292 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-17 00:04:201293 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-07 01:40:301294 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1295 GetFirstAudioStreamCname(answer2.get()));
1296}
1297
Steve Anton36da6ff2018-02-17 00:04:201298TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:361299 CreatePeerConnectionWithDifferentConfigurations) {
1300 CreatePeerConnectionWithDifferentConfigurations();
1301}
1302
Steve Anton36da6ff2018-02-17 00:04:201303TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 15:15:111304 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1305 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1306 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1307 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1308 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1309 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1310 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1311 port_allocator_->candidate_filter());
1312 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1313 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1314}
1315
1316// Test that when a PeerConnection is created with a nonzero candidate pool
1317// size, the pooled PortAllocatorSession is created with all the attributes
1318// in the RTCConfiguration.
Steve Anton36da6ff2018-02-17 00:04:201319TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 15:15:111320 PeerConnectionInterface::RTCConfiguration config;
1321 PeerConnectionInterface::IceServer server;
1322 server.uri = kStunAddressOnly;
1323 config.servers.push_back(server);
1324 config.type = PeerConnectionInterface::kRelay;
1325 config.disable_ipv6 = true;
1326 config.tcp_candidate_policy =
1327 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-06-01 01:29:121328 config.candidate_network_policy =
1329 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 15:15:111330 config.ice_candidate_pool_size = 1;
Niels Möllerf06f9232018-08-07 10:32:181331 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 15:15:111332
1333 const cricket::FakePortAllocatorSession* session =
1334 static_cast<const cricket::FakePortAllocatorSession*>(
1335 port_allocator_->GetPooledSession());
1336 ASSERT_NE(nullptr, session);
1337 EXPECT_EQ(1UL, session->stun_servers().size());
1338 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1339 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-06-01 01:29:121340 EXPECT_LT(0U,
1341 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 15:15:111342}
1343
deadbeefd21eab3e2017-07-26 23:50:111344// Test that network-related RTCConfiguration members are applied to the
1345// PortAllocator when CreatePeerConnection is called. Specifically:
1346// - disable_ipv6_on_wifi
1347// - max_ipv6_networks
1348// - tcp_candidate_policy
1349// - candidate_network_policy
1350// - prune_turn_ports
1351//
1352// Note that the candidate filter (RTCConfiguration::type) is already tested
1353// above.
Steve Anton36da6ff2018-02-17 00:04:201354TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab3e2017-07-26 23:50:111355 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1356 // Create fake port allocator.
1357 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1358 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1359 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1360
1361 // Create RTCConfiguration with some network-related fields relevant to
1362 // PortAllocator populated.
1363 PeerConnectionInterface::RTCConfiguration config;
1364 config.disable_ipv6_on_wifi = true;
1365 config.max_ipv6_networks = 10;
1366 config.tcp_candidate_policy =
1367 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1368 config.candidate_network_policy =
1369 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1370 config.prune_turn_ports = true;
1371
1372 // Create the PC factory and PC with the above config.
1373 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1374 webrtc::CreatePeerConnectionFactory(
1375 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 12:48:541376 rtc::Thread::Current(), fake_audio_capture_module_,
1377 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 09:28:291378 webrtc::CreateBuiltinAudioDecoderFactory(),
1379 webrtc::CreateBuiltinVideoEncoderFactory(),
1380 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1381 nullptr /* audio_processing */));
deadbeefd21eab3e2017-07-26 23:50:111382 rtc::scoped_refptr<PeerConnectionInterface> pc(
Niels Möllerf06f9232018-08-07 10:32:181383 pc_factory->CreatePeerConnection(config, std::move(port_allocator),
1384 nullptr, &observer_));
Yves Gerey4e933292018-10-31 14:36:051385 EXPECT_TRUE(pc.get());
1386 observer_.SetPeerConnectionInterface(pc.get());
deadbeefd21eab3e2017-07-26 23:50:111387
1388 // Now validate that the config fields set above were applied to the
1389 // PortAllocator, as flags or otherwise.
1390 EXPECT_FALSE(raw_port_allocator->flags() &
1391 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1392 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1393 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1394 EXPECT_TRUE(raw_port_allocator->flags() &
1395 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1396 EXPECT_TRUE(raw_port_allocator->prune_turn_ports());
1397}
1398
deadbeef46c73892016-11-17 03:42:041399// Check that GetConfiguration returns the configuration the PeerConnection was
1400// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-17 00:04:201401TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-17 03:42:041402 PeerConnectionInterface::RTCConfiguration config;
1403 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 10:32:181404 CreatePeerConnection(config);
deadbeef46c73892016-11-17 03:42:041405
1406 PeerConnectionInterface::RTCConfiguration returned_config =
1407 pc_->GetConfiguration();
1408 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1409}
1410
1411// Check that GetConfiguration returns the last configuration passed into
1412// SetConfiguration.
Steve Anton36da6ff2018-02-17 00:04:201413TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
Piotr (Peter) Slatala37227be2018-11-21 15:42:221414 PeerConnectionInterface::RTCConfiguration starting_config;
1415 starting_config.bundle_policy =
1416 webrtc::PeerConnection::kBundlePolicyMaxBundle;
1417 CreatePeerConnection(starting_config);
deadbeef46c73892016-11-17 03:42:041418
Steve Anton36da6ff2018-02-17 00:04:201419 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-17 03:42:041420 config.type = PeerConnectionInterface::kRelay;
Piotr (Peter) Slatalaaa1e7c22018-10-16 17:04:451421 config.use_media_transport = true;
Bjorn Mellema9bbd862018-11-02 16:07:481422 config.use_media_transport_for_data_channels = true;
deadbeef46c73892016-11-17 03:42:041423 EXPECT_TRUE(pc_->SetConfiguration(config));
1424
1425 PeerConnectionInterface::RTCConfiguration returned_config =
1426 pc_->GetConfiguration();
1427 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
Piotr (Peter) Slatalaaa1e7c22018-10-16 17:04:451428 EXPECT_TRUE(returned_config.use_media_transport);
Bjorn Mellema9bbd862018-11-02 16:07:481429 EXPECT_TRUE(returned_config.use_media_transport_for_data_channels);
deadbeef46c73892016-11-17 03:42:041430}
1431
Steve Antonc79268f2018-04-24 16:54:101432TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1433 CreatePeerConnection();
1434
1435 pc_->Close();
1436
1437 EXPECT_FALSE(
1438 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()));
1439}
1440
Steve Anton36da6ff2018-02-17 00:04:201441TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 20:28:301442 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 19:34:101443 AddVideoStream(kStreamId1);
1444 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:361445 ASSERT_EQ(2u, pc_->local_streams()->count());
1446
wu@webrtc.org9dba5252013-08-05 20:36:571447 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 18:14:501448 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 19:34:101449 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 18:14:501450 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Seth Hampson845e8782018-03-02 19:34:101451 pc_factory_->CreateAudioTrack(kStreamId3,
zhihuang9763d562016-08-05 18:14:501452 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:361453 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:291454 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:571455 EXPECT_EQ(3u, pc_->local_streams()->count());
1456
1457 // Remove the third stream.
1458 pc_->RemoveStream(pc_->local_streams()->at(2));
1459 EXPECT_EQ(2u, pc_->local_streams()->count());
1460
1461 // Remove the second stream.
1462 pc_->RemoveStream(pc_->local_streams()->at(1));
1463 EXPECT_EQ(1u, pc_->local_streams()->count());
1464
1465 // Remove the first stream.
1466 pc_->RemoveStream(pc_->local_streams()->at(0));
1467 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:361468}
1469
deadbeefab9b2d12015-10-14 18:33:111470// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-17 00:04:201471// Don't run under Unified Plan since the stream API is not available.
1472TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 20:28:301473 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 19:34:101474 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 13:47:291475 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 18:03:041476 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 18:33:111477
deadbeefab9b2d12015-10-14 18:33:111478 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 23:14:301479 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 19:34:101480 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 18:33:111481
deadbeefab9b2d12015-10-14 18:33:111482 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 23:14:301483 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 19:34:101484 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 18:33:111485
1486 // Add another stream and ensure the offer includes both the old and new
1487 // streams.
Seth Hampson845e8782018-03-02 19:34:101488 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 18:03:041489 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 18:33:111490
Steve Antonb1c1de12017-12-21 23:14:301491 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 19:34:101492 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1493 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 18:33:111494
Steve Antonb1c1de12017-12-21 23:14:301495 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 19:34:101496 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1497 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 18:33:111498}
1499
Steve Anton36da6ff2018-02-17 00:04:201500// Don't run under Unified Plan since the stream API is not available.
1501TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 20:28:301502 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 19:34:101503 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:361504 ASSERT_EQ(1u, pc_->local_streams()->count());
1505 pc_->RemoveStream(pc_->local_streams()->at(0));
1506 EXPECT_EQ(0u, pc_->local_streams()->count());
1507}
1508
deadbeefe1f9d832016-01-14 23:35:421509// Test for AddTrack and RemoveTrack methods.
1510// Tests that the created offer includes tracks we added,
1511// and that the RtpSenders are created correctly.
1512// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-17 00:04:201513// Only tested with Plan B since Unified Plan is covered in more detail by tests
1514// in peerconnection_jsep_unittests.cc
1515TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 20:28:301516 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 18:14:501517 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 12:59:451518 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 18:14:501519 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 12:59:451520 CreateVideoTrack("video_track"));
Seth Hampson845e8782018-03-02 19:34:101521 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1522 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 21:27:391523 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 19:34:101524 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 23:35:421525 EXPECT_EQ("audio_track", audio_sender->id());
1526 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 21:27:391527 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 19:34:101528 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 23:35:421529 EXPECT_EQ("video_track", video_sender->id());
1530 EXPECT_EQ(video_track, video_sender->track());
1531
1532 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 13:47:291533 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 18:03:041534 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 23:35:421535
1536 const cricket::ContentInfo* audio_content =
1537 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 23:14:301538 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 19:34:101539 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 23:35:421540
1541 const cricket::ContentInfo* video_content =
1542 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 23:14:301543 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 19:34:101544 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 23:35:421545
Steve Antondb45ca82017-09-12 01:27:341546 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 23:35:421547
1548 // Now try removing the tracks.
1549 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1550 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1551
1552 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 18:03:041553 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 23:35:421554
1555 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 23:14:301556 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 19:34:101557 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 23:35:421558
1559 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 23:14:301560 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 19:34:101561 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 23:35:421562
Steve Antondb45ca82017-09-12 01:27:341563 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 23:35:421564
1565 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1566 // should return false.
1567 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1568 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1569}
1570
1571// Test creating senders without a stream specified,
1572// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-17 00:04:201573TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 20:28:301574 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 18:14:501575 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 12:59:451576 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 18:14:501577 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 12:59:451578 CreateVideoTrack("video_track"));
deadbeefe1f9d832016-01-14 23:35:421579 auto audio_sender =
Steve Anton2d6c76a2018-01-06 01:10:521580 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 23:35:421581 auto video_sender =
Steve Anton2d6c76a2018-01-06 01:10:521582 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 23:35:421583 EXPECT_EQ("audio_track", audio_sender->id());
1584 EXPECT_EQ(audio_track, audio_sender->track());
1585 EXPECT_EQ("video_track", video_sender->id());
1586 EXPECT_EQ(video_track, video_sender->track());
Seth Hampson5b4f0752018-04-02 23:31:361587 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1588 // If the ID is truly a random GUID, it should be infinitely unlikely they
1589 // will be the same.
1590 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1591 } else {
1592 // We allows creating tracks without stream ids under Unified Plan
1593 // semantics.
1594 EXPECT_EQ(0u, video_sender->stream_ids().size());
1595 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1596 }
deadbeefe1f9d832016-01-14 23:35:421597}
1598
Harald Alvestrand89061872018-01-02 13:08:341599// Test that we can call GetStats() after AddTrack but before connecting
1600// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-17 00:04:201601TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 13:08:341602 CreatePeerConnectionWithoutDtls();
1603 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 12:59:451604 CreateAudioTrack("audio_track"));
Harald Alvestrand89061872018-01-02 13:08:341605 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 12:59:451606 CreateVideoTrack("video_track"));
Steve Anton2d6c76a2018-01-06 01:10:521607 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1608 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 13:08:341609 EXPECT_TRUE(DoGetStats(nullptr));
1610}
1611
Steve Anton36da6ff2018-02-17 00:04:201612TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 16:18:191613 CreatePeerConnectionWithoutDtls();
1614 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 12:59:451615 CreateAudioTrack("audio_track"));
Harald Alvestrandc72af932018-01-11 16:18:191616 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 12:59:451617 CreateVideoTrack("video_track"));
Harald Alvestrandc72af932018-01-11 16:18:191618 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 23:19:501619 ASSERT_TRUE(audio_sender.ok());
1620 auto* audio_sender_proxy =
1621 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1622 audio_sender.value().get());
1623 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1624
Harald Alvestrandc72af932018-01-11 16:18:191625 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 23:19:501626 ASSERT_TRUE(video_sender.ok());
1627 auto* video_sender_proxy =
1628 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1629 video_sender.value().get());
1630 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 16:18:191631}
1632
Steve Anton36da6ff2018-02-17 00:04:201633// Don't run under Unified Plan since the stream API is not available.
1634TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 16:18:191635 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 19:34:101636 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 16:18:191637 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 23:19:501638 ASSERT_EQ(1u, senders.size());
1639 auto* sender_proxy =
1640 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1641 senders[0].get());
1642 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 16:18:191643}
1644
Steve Anton36da6ff2018-02-17 00:04:201645TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:361646 InitiateCall();
Seth Hampson845e8782018-03-02 19:34:101647 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:361648 VerifyRemoteRtpHeaderExtensions();
1649}
1650
Steve Anton36da6ff2018-02-17 00:04:201651TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 20:28:301652 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 19:34:101653 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:361654 CreateOfferAsLocalDescription();
1655 std::string offer;
1656 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1657 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 19:34:101658 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:361659}
1660
Steve Anton36da6ff2018-02-17 00:04:201661TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 20:28:301662 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 19:34:101663 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:361664
1665 CreateOfferAsRemoteDescription();
1666 CreateAnswerAsLocalDescription();
1667
Seth Hampson845e8782018-03-02 19:34:101668 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:361669}
1670
Steve Anton36da6ff2018-02-17 00:04:201671TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 20:28:301672 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 19:34:101673 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:361674
1675 CreateOfferAsRemoteDescription();
1676 CreatePrAnswerAsLocalDescription();
1677 CreateAnswerAsLocalDescription();
1678
Seth Hampson845e8782018-03-02 19:34:101679 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:361680}
1681
Steve Anton36da6ff2018-02-17 00:04:201682// Don't run under Unified Plan since the stream API is not available.
1683TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:361684 InitiateCall();
1685 ASSERT_EQ(1u, pc_->remote_streams()->count());
1686 pc_->RemoveStream(pc_->local_streams()->at(0));
1687 CreateOfferReceiveAnswer();
1688 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 19:34:101689 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:361690 CreateOfferReceiveAnswer();
1691}
1692
1693// Tests that after negotiating an audio only call, the respondent can perform a
1694// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-17 00:04:201695TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 20:28:301696 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 19:34:101697 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:361698 CreateOfferAsRemoteDescription();
1699 CreateAnswerAsLocalDescription();
1700
1701 ASSERT_EQ(1u, pc_->remote_streams()->count());
1702 pc_->RemoveStream(pc_->local_streams()->at(0));
1703 CreateOfferReceiveAnswer();
1704 EXPECT_EQ(0u, pc_->remote_streams()->count());
1705}
1706
1707// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-17 00:04:201708TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 20:28:301709 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:361710
Steve Antonf1c6db12017-10-13 18:13:351711 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:361712 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 13:47:291713 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-17 00:04:201714 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 20:14:451715 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-12 01:27:341716 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:361717
1718 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 13:47:291719 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 20:14:451720 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-12 01:27:341721 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:361722
Steve Antonf1c6db12017-10-13 18:13:351723 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 16:39:201724 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:361725
Steve Antonf1c6db12017-10-13 18:13:351726 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:361727}
1728
deadbeefab9b2d12015-10-14 18:33:111729// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:361730// not unique.
Steve Anton07563732018-06-26 18:13:501731TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 20:28:301732 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:361733 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 13:47:291734 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 20:14:451735 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 18:03:041736 EXPECT_TRUE(offer);
1737 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:361738
1739 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 19:34:101740 AddAudioTrack("track_label", {kStreamId1});
1741 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:361742
1743 // Test CreateOffer
deadbeefc80741f2015-10-22 20:14:451744 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:361745
1746 // Test CreateAnswer
kwibergd1fe2812016-04-27 13:47:291747 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 20:14:451748 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:361749}
1750
1751// Test that we will get different SSRCs for each tracks in the offer and answer
1752// we created.
Steve Anton36da6ff2018-02-17 00:04:201753TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 20:28:301754 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:361755 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 19:34:101756 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1757 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:361758
1759 // Test CreateOffer
kwibergd1fe2812016-04-27 13:47:291760 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 18:03:041761 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:361762 int audio_ssrc = 0;
1763 int video_ssrc = 0;
Yves Gerey665174f2018-06-19 13:03:051764 EXPECT_TRUE(
1765 GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc));
1766 EXPECT_TRUE(
1767 GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:361768 EXPECT_NE(audio_ssrc, video_ssrc);
1769
1770 // Test CreateAnswer
Steve Antondb45ca82017-09-12 01:27:341771 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 13:47:291772 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 18:03:041773 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:361774 audio_ssrc = 0;
1775 video_ssrc = 0;
Yves Gerey665174f2018-06-19 13:03:051776 EXPECT_TRUE(
1777 GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc));
1778 EXPECT_TRUE(
1779 GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:361780 EXPECT_NE(audio_ssrc, video_ssrc);
1781}
1782
deadbeefeb459812015-12-16 03:24:431783// Test that it's possible to call AddTrack on a MediaStream after adding
1784// the stream to a PeerConnection.
1785// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-17 00:04:201786// Don't run under Unified Plan since the stream API is not available.
1787TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 20:28:301788 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-16 03:24:431789 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 19:34:101790 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-16 03:24:431791 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1792
1793 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 18:14:501794 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 12:59:451795 CreateVideoTrack("video_label"));
deadbeefeb459812015-12-16 03:24:431796 stream->AddTrack(video_track.get());
1797
kwibergd1fe2812016-04-27 13:47:291798 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 18:03:041799 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-16 03:24:431800
1801 const cricket::MediaContentDescription* video_desc =
1802 cricket::GetFirstVideoContentDescription(offer->description());
1803 EXPECT_TRUE(video_desc != nullptr);
1804}
1805
1806// Test that it's possible to call RemoveTrack on a MediaStream after adding
1807// the stream to a PeerConnection.
1808// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-17 00:04:201809// Don't run under Unified Plan since the stream API is not available.
1810TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 20:28:301811 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-16 03:24:431812 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 19:34:101813 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-16 03:24:431814 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1815
1816 // Remove the video track.
1817 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1818
kwibergd1fe2812016-04-27 13:47:291819 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 18:03:041820 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-16 03:24:431821
1822 const cricket::MediaContentDescription* video_desc =
1823 cricket::GetFirstVideoContentDescription(offer->description());
1824 EXPECT_TRUE(video_desc == nullptr);
1825}
1826
deadbeefbd7d8f72015-12-19 00:58:441827// Test creating a sender with a stream ID, and ensure the ID is populated
1828// in the offer.
Steve Anton36da6ff2018-02-17 00:04:201829// Don't run under Unified Plan since the stream API is not available.
1830TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 20:28:301831 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 19:34:101832 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-19 00:58:441833
kwibergd1fe2812016-04-27 13:47:291834 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 18:03:041835 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-19 00:58:441836
1837 const cricket::MediaContentDescription* video_desc =
1838 cricket::GetFirstVideoContentDescription(offer->description());
1839 ASSERT_TRUE(video_desc != nullptr);
1840 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 19:34:101841 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-19 00:58:441842}
1843
henrike@webrtc.org28e20752013-07-10 00:45:361844// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-17 00:04:201845TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:361846 InitiateCall();
Steve Anton36da6ff2018-02-17 00:04:201847 ASSERT_LT(0u, pc_->GetSenders().size());
1848 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 18:14:501849 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-17 00:04:201850 pc_->GetReceivers()[0]->track();
henrike@webrtc.org28e20752013-07-10 00:45:361851 EXPECT_TRUE(DoGetStats(remote_audio));
1852
1853 // Remove the stream. Since we are sending to our selves the local
1854 // and the remote stream is the same.
Steve Anton36da6ff2018-02-17 00:04:201855 pc_->RemoveTrack(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:361856 // Do a re-negotiation.
1857 CreateOfferReceiveAnswer();
1858
henrike@webrtc.org28e20752013-07-10 00:45:361859 // Test that we still can get statistics for the old track. Even if it is not
1860 // sent any longer.
1861 EXPECT_TRUE(DoGetStats(remote_audio));
1862}
1863
1864// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-17 00:04:201865TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:361866 InitiateCall();
Steve Anton36da6ff2018-02-17 00:04:201867 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1868 ASSERT_TRUE(video_receiver);
1869 EXPECT_TRUE(DoGetStats(video_receiver->track()));
henrike@webrtc.org28e20752013-07-10 00:45:361870}
1871
1872// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-17 00:04:201873TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:361874 InitiateCall();
zhihuang9763d562016-08-05 18:14:501875 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:361876 pc_factory_->CreateAudioTrack("unknown track", NULL));
1877 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1878}
1879
Steve Anton36da6ff2018-02-17 00:04:201880TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 13:08:341881 CreatePeerConnectionWithoutDtls();
1882 EXPECT_TRUE(DoGetRTCStats());
1883 // Clearing stats cache is needed now, but should be temporary.
1884 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1885 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 19:34:101886 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1887 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 13:08:341888 EXPECT_TRUE(DoGetRTCStats());
1889 pc_->ClearStatsCache();
1890 CreateOfferReceiveAnswer();
1891 EXPECT_TRUE(DoGetRTCStats());
1892}
1893
henrike@webrtc.org28e20752013-07-10 00:45:361894// This test setup two RTP data channels in loop back.
Steve Anton36da6ff2018-02-17 00:04:201895TEST_P(PeerConnectionInterfaceTest, TestDataChannel) {
Niels Möllerf06f9232018-08-07 10:32:181896 RTCConfiguration config;
1897 config.enable_rtp_data_channel = true;
1898 config.enable_dtls_srtp = false;
1899 CreatePeerConnection(config);
zhihuang9763d562016-08-05 18:14:501900 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:361901 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 18:14:501902 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:361903 pc_->CreateDataChannel("test2", NULL);
1904 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 13:47:291905 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:361906 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 13:47:291907 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:361908 new MockDataChannelObserver(data2));
1909
1910 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1911 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1912 std::string data_to_send1 = "testing testing";
1913 std::string data_to_send2 = "testing something else";
1914 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1915
1916 CreateOfferReceiveAnswer();
1917 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1918 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1919
1920 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1921 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1922 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1923 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1924
1925 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1926 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1927
1928 data1->Close();
1929 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1930 CreateOfferReceiveAnswer();
1931 EXPECT_FALSE(observer1->IsOpen());
1932 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1933 EXPECT_TRUE(observer2->IsOpen());
1934
1935 data_to_send2 = "testing something else again";
1936 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1937
1938 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1939}
1940
1941// This test verifies that sendnig binary data over RTP data channels should
1942// fail.
Steve Anton36da6ff2018-02-17 00:04:201943TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
Niels Möllerf06f9232018-08-07 10:32:181944 RTCConfiguration config;
1945 config.enable_rtp_data_channel = true;
1946 config.enable_dtls_srtp = false;
1947 CreatePeerConnection(config);
zhihuang9763d562016-08-05 18:14:501948 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:361949 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 18:14:501950 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:361951 pc_->CreateDataChannel("test2", NULL);
1952 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 13:47:291953 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:361954 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 13:47:291955 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:361956 new MockDataChannelObserver(data2));
1957
1958 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1959 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1960
1961 CreateOfferReceiveAnswer();
1962 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1963 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1964
1965 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1966 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1967
jbaucheec21bd2016-03-20 13:15:431968 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:361969 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
1970}
1971
1972// This test setup a RTP data channels in loop back and test that a channel is
1973// opened even if the remote end answer with a zero SSRC.
Steve Anton36da6ff2018-02-17 00:04:201974TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 10:32:181975 RTCConfiguration config;
1976 config.enable_rtp_data_channel = true;
1977 config.enable_dtls_srtp = false;
1978 CreatePeerConnection(config);
zhihuang9763d562016-08-05 18:14:501979 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:361980 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 13:47:291981 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:361982 new MockDataChannelObserver(data1));
1983
1984 CreateOfferReceiveAnswerWithoutSsrc();
1985
1986 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1987
1988 data1->Close();
1989 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1990 CreateOfferReceiveAnswerWithoutSsrc();
1991 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1992 EXPECT_FALSE(observer1->IsOpen());
1993}
1994
1995// This test that if a data channel is added in an answer a receive only channel
1996// channel is created.
Steve Anton36da6ff2018-02-17 00:04:201997TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 10:32:181998 RTCConfiguration config;
1999 config.enable_rtp_data_channel = true;
2000 config.enable_dtls_srtp = false;
2001
2002 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:362003
2004 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 18:14:502005 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:362006 pc_->CreateDataChannel(offer_label, NULL);
2007
2008 CreateOfferAsLocalDescription();
2009
2010 // Replace the data channel label in the offer and apply it as an answer.
2011 std::string receive_label = "answer_channel";
2012 std::string sdp;
2013 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Anton1c9c9fc2019-02-14 23:13:092014 absl::StrReplaceAll({{offer_label, receive_label}}, &sdp);
henrike@webrtc.org28e20752013-07-10 00:45:362015 CreateAnswerAsRemoteDescription(sdp);
2016
2017 // Verify that a new incoming data channel has been created and that
2018 // it is open but can't we written to.
2019 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
2020 DataChannelInterface* received_channel = observer_.last_datachannel_;
2021 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
2022 EXPECT_EQ(receive_label, received_channel->label());
2023 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
2024
2025 // Verify that the channel we initially offered has been rejected.
2026 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2027
2028 // Do another offer / answer exchange and verify that the data channel is
2029 // opened.
2030 CreateOfferReceiveAnswer();
2031 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
2032 kTimeout);
2033}
2034
2035// This test that no data channel is returned if a reliable channel is
2036// requested.
2037// TODO(perkj): Remove this test once reliable channels are implemented.
Steve Anton36da6ff2018-02-17 00:04:202038TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
Niels Möllerf06f9232018-08-07 10:32:182039 RTCConfiguration rtc_config;
2040 rtc_config.enable_rtp_data_channel = true;
2041 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:362042
2043 std::string label = "test";
2044 webrtc::DataChannelInit config;
2045 config.reliable = true;
zhihuang9763d562016-08-05 18:14:502046 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:362047 pc_->CreateDataChannel(label, &config);
2048 EXPECT_TRUE(channel == NULL);
2049}
2050
deadbeefab9b2d12015-10-14 18:33:112051// Verifies that duplicated label is not allowed for RTP data channel.
Steve Anton36da6ff2018-02-17 00:04:202052TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
Niels Möllerf06f9232018-08-07 10:32:182053 RTCConfiguration config;
2054 config.enable_rtp_data_channel = true;
2055 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 18:33:112056
2057 std::string label = "test";
zhihuang9763d562016-08-05 18:14:502058 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 18:33:112059 pc_->CreateDataChannel(label, nullptr);
2060 EXPECT_NE(channel, nullptr);
2061
zhihuang9763d562016-08-05 18:14:502062 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 18:33:112063 pc_->CreateDataChannel(label, nullptr);
2064 EXPECT_EQ(dup_channel, nullptr);
2065}
2066
henrike@webrtc.org28e20752013-07-10 00:45:362067// This tests that a SCTP data channel is returned using different
2068// DataChannelInit configurations.
Steve Anton36da6ff2018-02-17 00:04:202069TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
Niels Möllerf06f9232018-08-07 10:32:182070 RTCConfiguration rtc_config;
2071 rtc_config.enable_dtls_srtp = true;
2072 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:362073
2074 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 18:14:502075 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:362076 pc_->CreateDataChannel("1", &config);
2077 EXPECT_TRUE(channel != NULL);
2078 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:112079 EXPECT_TRUE(observer_.renegotiation_needed_);
2080 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:362081
2082 config.ordered = false;
2083 channel = pc_->CreateDataChannel("2", &config);
2084 EXPECT_TRUE(channel != NULL);
2085 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:112086 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:362087
2088 config.ordered = true;
2089 config.maxRetransmits = 0;
2090 channel = pc_->CreateDataChannel("3", &config);
2091 EXPECT_TRUE(channel != NULL);
2092 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:112093 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:362094
Harald Alvestrandf3736ed2019-04-08 11:09:302095 config.maxRetransmits = absl::nullopt;
henrike@webrtc.org28e20752013-07-10 00:45:362096 config.maxRetransmitTime = 0;
2097 channel = pc_->CreateDataChannel("4", &config);
2098 EXPECT_TRUE(channel != NULL);
2099 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:112100 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:362101}
2102
Harald Alvestrandf3736ed2019-04-08 11:09:302103// For backwards compatibility, we want people who "unset" maxRetransmits
2104// and maxRetransmitTime by setting them to -1 to get what they want.
2105TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannelWithMinusOne) {
2106 RTCConfiguration rtc_config;
2107 rtc_config.enable_dtls_srtp = true;
2108 CreatePeerConnection(rtc_config);
2109
2110 webrtc::DataChannelInit config;
2111 config.maxRetransmitTime = -1;
2112 config.maxRetransmits = -1;
2113 rtc::scoped_refptr<DataChannelInterface> channel =
2114 pc_->CreateDataChannel("1", &config);
2115 EXPECT_TRUE(channel != NULL);
2116}
2117
henrike@webrtc.org28e20752013-07-10 00:45:362118// This tests that no data channel is returned if both maxRetransmits and
2119// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-17 00:04:202120TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:362121 CreateSctpDataChannelShouldFailForInvalidConfig) {
Niels Möllerf06f9232018-08-07 10:32:182122 RTCConfiguration rtc_config;
2123 rtc_config.enable_dtls_srtp = true;
2124 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:362125
2126 std::string label = "test";
2127 webrtc::DataChannelInit config;
2128 config.maxRetransmits = 0;
2129 config.maxRetransmitTime = 0;
2130
zhihuang9763d562016-08-05 18:14:502131 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:362132 pc_->CreateDataChannel(label, &config);
2133 EXPECT_TRUE(channel == NULL);
2134}
2135
henrike@webrtc.org28e20752013-07-10 00:45:362136// The test verifies that creating a SCTP data channel with an id already in use
2137// or out of range should fail.
Steve Anton36da6ff2018-02-17 00:04:202138TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:362139 CreateSctpDataChannelWithInvalidIdShouldFail) {
Niels Möllerf06f9232018-08-07 10:32:182140 RTCConfiguration rtc_config;
2141 rtc_config.enable_dtls_srtp = true;
2142 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:362143
2144 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 18:14:502145 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:362146
wu@webrtc.orgcecfd182013-10-30 05:18:122147 config.id = 1;
Harald Alvestrand5c4d2ee2019-04-01 10:58:152148 config.negotiated = true;
wu@webrtc.orgcecfd182013-10-30 05:18:122149 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:362150 EXPECT_TRUE(channel != NULL);
2151 EXPECT_EQ(1, channel->id());
2152
henrike@webrtc.org28e20752013-07-10 00:45:362153 channel = pc_->CreateDataChannel("x", &config);
2154 EXPECT_TRUE(channel == NULL);
2155
2156 config.id = cricket::kMaxSctpSid;
Harald Alvestrand5c4d2ee2019-04-01 10:58:152157 config.negotiated = true;
henrike@webrtc.org28e20752013-07-10 00:45:362158 channel = pc_->CreateDataChannel("max", &config);
2159 EXPECT_TRUE(channel != NULL);
2160 EXPECT_EQ(config.id, channel->id());
2161
2162 config.id = cricket::kMaxSctpSid + 1;
Harald Alvestrand5c4d2ee2019-04-01 10:58:152163 config.negotiated = true;
henrike@webrtc.org28e20752013-07-10 00:45:362164 channel = pc_->CreateDataChannel("x", &config);
2165 EXPECT_TRUE(channel == NULL);
2166}
2167
deadbeefab9b2d12015-10-14 18:33:112168// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-17 00:04:202169TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
Niels Möllerf06f9232018-08-07 10:32:182170 RTCConfiguration rtc_config;
2171 rtc_config.enable_dtls_srtp = true;
2172 CreatePeerConnection(rtc_config);
deadbeefab9b2d12015-10-14 18:33:112173
2174 std::string label = "test";
zhihuang9763d562016-08-05 18:14:502175 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 18:33:112176 pc_->CreateDataChannel(label, nullptr);
2177 EXPECT_NE(channel, nullptr);
2178
zhihuang9763d562016-08-05 18:14:502179 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 18:33:112180 pc_->CreateDataChannel(label, nullptr);
2181 EXPECT_NE(dup_channel, nullptr);
2182}
2183
jiayl@webrtc.org001fd2d2014-05-29 15:31:112184// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2185// DataChannel.
Steve Anton36da6ff2018-02-17 00:04:202186TEST_P(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
Niels Möllerf06f9232018-08-07 10:32:182187 RTCConfiguration rtc_config;
2188 rtc_config.enable_rtp_data_channel = true;
2189 rtc_config.enable_dtls_srtp = false;
2190 CreatePeerConnection(rtc_config);
jiayl@webrtc.org001fd2d2014-05-29 15:31:112191
zhihuang9763d562016-08-05 18:14:502192 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:112193 pc_->CreateDataChannel("test1", NULL);
2194 EXPECT_TRUE(observer_.renegotiation_needed_);
2195 observer_.renegotiation_needed_ = false;
2196
Guido Urdaneta70c2db12019-04-16 10:24:142197 CreateOfferReceiveAnswer();
2198
zhihuang9763d562016-08-05 18:14:502199 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:112200 pc_->CreateDataChannel("test2", NULL);
Guido Urdaneta70c2db12019-04-16 10:24:142201 EXPECT_EQ(observer_.renegotiation_needed_,
2202 GetParam() == SdpSemantics::kPlanB);
jiayl@webrtc.org001fd2d2014-05-29 15:31:112203}
2204
henrike@webrtc.org28e20752013-07-10 00:45:362205// This test that a data channel closes when a PeerConnection is deleted/closed.
Steve Anton36da6ff2018-02-17 00:04:202206TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
Niels Möllerf06f9232018-08-07 10:32:182207 RTCConfiguration rtc_config;
2208 rtc_config.enable_rtp_data_channel = true;
2209 rtc_config.enable_dtls_srtp = false;
2210 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:362211
zhihuang9763d562016-08-05 18:14:502212 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:362213 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 18:14:502214 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:362215 pc_->CreateDataChannel("test2", NULL);
2216 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 13:47:292217 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:362218 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 13:47:292219 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:362220 new MockDataChannelObserver(data2));
2221
2222 CreateOfferReceiveAnswer();
2223 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2224 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2225
2226 ReleasePeerConnection();
2227 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2228 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2229}
2230
Zhi Huang644fde42018-04-03 02:16:262231// This tests that RTP data channels can be rejected in an answer.
2232TEST_P(PeerConnectionInterfaceTest, TestRejectRtpDataChannelInAnswer) {
Niels Möllerf06f9232018-08-07 10:32:182233 RTCConfiguration rtc_config;
2234 rtc_config.enable_rtp_data_channel = true;
2235 rtc_config.enable_dtls_srtp = false;
2236 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:362237
zhihuang9763d562016-08-05 18:14:502238 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:362239 pc_->CreateDataChannel("offer_channel", NULL));
2240
2241 CreateOfferAsLocalDescription();
2242
2243 // Create an answer where the m-line for data channels are rejected.
2244 std::string sdp;
2245 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-12 01:27:342246 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 18:27:412247 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-12 01:27:342248 ASSERT_TRUE(answer);
henrike@webrtc.org28e20752013-07-10 00:45:362249 cricket::ContentInfo* data_info =
Steve Anton36da6ff2018-02-17 00:04:202250 cricket::GetFirstDataContent(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:362251 data_info->rejected = true;
2252
Steve Antondb45ca82017-09-12 01:27:342253 DoSetRemoteDescription(std::move(answer));
henrike@webrtc.org28e20752013-07-10 00:45:362254 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2255}
2256
Zhi Huang644fde42018-04-03 02:16:262257#ifdef HAVE_SCTP
2258// This tests that SCTP data channels can be rejected in an answer.
2259TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2260#else
2261TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2262#endif
2263{
Niels Möllerf06f9232018-08-07 10:32:182264 RTCConfiguration rtc_config;
2265 CreatePeerConnection(rtc_config);
Zhi Huang644fde42018-04-03 02:16:262266
2267 rtc::scoped_refptr<DataChannelInterface> offer_channel(
2268 pc_->CreateDataChannel("offer_channel", NULL));
2269
2270 CreateOfferAsLocalDescription();
2271
2272 // Create an answer where the m-line for data channels are rejected.
2273 std::string sdp;
2274 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2275 std::unique_ptr<SessionDescriptionInterface> answer(
2276 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2277 ASSERT_TRUE(answer);
2278 cricket::ContentInfo* data_info =
2279 cricket::GetFirstDataContent(answer->description());
2280 data_info->rejected = true;
2281
2282 DoSetRemoteDescription(std::move(answer));
2283 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2284}
2285
henrike@webrtc.org28e20752013-07-10 00:45:362286// Test that we can create a session description from an SDP string from
2287// FireFox, use it as a remote session description, generate an answer and use
2288// the answer as a local description.
Steve Anton36da6ff2018-02-17 00:04:202289TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
Niels Möllerf06f9232018-08-07 10:32:182290 RTCConfiguration rtc_config;
2291 rtc_config.enable_dtls_srtp = true;
2292 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-17 00:04:202293 AddAudioTrack("audio_label");
2294 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-12 01:27:342295 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 18:27:412296 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-12 01:27:342297 webrtc::kFireFoxSdpOffer, nullptr));
2298 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:362299 CreateAnswerAsLocalDescription();
2300 ASSERT_TRUE(pc_->local_description() != NULL);
2301 ASSERT_TRUE(pc_->remote_description() != NULL);
2302
2303 const cricket::ContentInfo* content =
2304 cricket::GetFirstAudioContent(pc_->local_description()->description());
2305 ASSERT_TRUE(content != NULL);
2306 EXPECT_FALSE(content->rejected);
2307
2308 content =
2309 cricket::GetFirstVideoContent(pc_->local_description()->description());
2310 ASSERT_TRUE(content != NULL);
2311 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:522312#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:362313 content =
2314 cricket::GetFirstDataContent(pc_->local_description()->description());
2315 ASSERT_TRUE(content != NULL);
Zhi Huange830e682018-03-30 17:48:352316 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:522317#endif
henrike@webrtc.org28e20752013-07-10 00:45:362318}
2319
zhihuangb19012e2017-09-19 20:47:592320// Test that fallback from DTLS to SDES is not supported.
2321// The fallback was previously supported but was removed to simplify the code
2322// and because it's non-standard.
Steve Anton36da6ff2018-02-17 00:04:202323TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
Niels Möllerf06f9232018-08-07 10:32:182324 RTCConfiguration rtc_config;
2325 rtc_config.enable_dtls_srtp = true;
2326 CreatePeerConnection(rtc_config);
deadbeef8662f942017-01-21 05:20:512327 // Wait for fake certificate to be generated. Previously, this is what caused
2328 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-17 00:04:202329 AddAudioTrack("audio_label");
2330 AddVideoTrack("video_label");
deadbeef8662f942017-01-21 05:20:512331 ASSERT_NE(nullptr, fake_certificate_generator_);
2332 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2333 kTimeout);
Steve Antondb45ca82017-09-12 01:27:342334 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 18:27:412335 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2336 nullptr));
Zhi Huange830e682018-03-30 17:48:352337 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-21 05:20:512338}
2339
henrike@webrtc.org28e20752013-07-10 00:45:362340// Test that we can create an audio only offer and receive an answer with a
2341// limited set of audio codecs and receive an updated offer with more audio
2342// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-17 00:04:202343TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 20:28:302344 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-17 00:04:202345 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:362346 CreateOfferAsLocalDescription();
2347
Steve Anton36da6ff2018-02-17 00:04:202348 const char* answer_sdp =
2349 (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB
2350 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-12 01:27:342351 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-17 00:04:202352 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-12 01:27:342353 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:362354
Steve Anton36da6ff2018-02-17 00:04:202355 const char* reoffer_sdp =
2356 (sdp_semantics_ == SdpSemantics::kPlanB
2357 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2358 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-12 01:27:342359 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-17 00:04:202360 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-12 01:27:342361 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:362362 CreateAnswerAsLocalDescription();
2363}
2364
deadbeefc80741f2015-10-22 20:14:452365// Test that if we're receiving (but not sending) a track, subsequent offers
2366// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-17 00:04:202367TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
Niels Möllerf06f9232018-08-07 10:32:182368 RTCConfiguration rtc_config;
2369 rtc_config.enable_dtls_srtp = true;
2370 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-17 00:04:202371 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 20:14:452372 CreateAnswerAsLocalDescription();
2373
2374 // At this point we should be receiving stream 1, but not sending anything.
2375 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 13:47:292376 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 20:14:452377 DoCreateOffer(&offer, nullptr);
2378
2379 const cricket::ContentInfo* video_content =
2380 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 23:14:302381 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2382 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 20:14:452383
2384 const cricket::ContentInfo* audio_content =
2385 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 23:14:302386 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2387 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 20:14:452388}
2389
2390// Test that if we're receiving (but not sending) a track, and the
2391// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2392// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-17 00:04:202393TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
Niels Möllerf06f9232018-08-07 10:32:182394 RTCConfiguration rtc_config;
2395 rtc_config.enable_dtls_srtp = true;
2396 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-17 00:04:202397 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 20:14:452398 CreateAnswerAsLocalDescription();
2399
2400 // At this point we should be receiving stream 1, but not sending anything.
2401 // A new offer would be recvonly, but we'll set the "no receive" constraints
2402 // to make it inactive.
kwibergd1fe2812016-04-27 13:47:292403 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 10:32:182404 RTCOfferAnswerOptions options;
2405 options.offer_to_receive_audio = 0;
2406 options.offer_to_receive_video = 0;
2407 DoCreateOffer(&offer, &options);
deadbeefc80741f2015-10-22 20:14:452408
2409 const cricket::ContentInfo* video_content =
2410 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 23:14:302411 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2412 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 20:14:452413
2414 const cricket::ContentInfo* audio_content =
2415 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 23:14:302416 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2417 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 20:14:452418}
2419
deadbeef653b8e02015-11-11 20:55:102420// Test that we can use SetConfiguration to change the ICE servers of the
2421// PortAllocator.
Steve Anton36da6ff2018-02-17 00:04:202422TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 20:55:102423 CreatePeerConnection();
2424
Steve Anton36da6ff2018-02-17 00:04:202425 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 20:55:102426 PeerConnectionInterface::IceServer server;
2427 server.uri = "stun:test_hostname";
2428 config.servers.push_back(server);
2429 EXPECT_TRUE(pc_->SetConfiguration(config));
2430
Taylor Brandstetter0c7e9f52015-12-29 22:14:522431 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2432 EXPECT_EQ("test_hostname",
2433 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 20:55:102434}
2435
Steve Anton36da6ff2018-02-17 00:04:202436TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 15:15:112437 CreatePeerConnection();
Steve Anton36da6ff2018-02-17 00:04:202438 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 15:15:112439 config.type = PeerConnectionInterface::kRelay;
2440 EXPECT_TRUE(pc_->SetConfiguration(config));
2441 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2442}
2443
Steve Anton36da6ff2018-02-17 00:04:202444TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 20:28:302445 PeerConnectionInterface::RTCConfiguration config;
2446 config.prune_turn_ports = false;
Niels Möllerf06f9232018-08-07 10:32:182447 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-17 00:04:202448 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 20:28:302449 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2450
2451 config.prune_turn_ports = true;
2452 EXPECT_TRUE(pc_->SetConfiguration(config));
2453 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2454}
2455
skvladd1f5fda2017-02-04 00:54:052456// Test that the ice check interval can be changed. This does not verify that
2457// the setting makes it all the way to P2PTransportChannel, as that would
2458// require a very complex set of mocks.
Steve Anton36da6ff2018-02-17 00:04:202459TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-04 00:54:052460 PeerConnectionInterface::RTCConfiguration config;
Danil Chapovalov66cadcc2018-06-19 14:47:432461 config.ice_check_min_interval = absl::nullopt;
Niels Möllerf06f9232018-08-07 10:32:182462 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-17 00:04:202463 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 09:54:382464 config.ice_check_min_interval = 100;
skvladd1f5fda2017-02-04 00:54:052465 EXPECT_TRUE(pc_->SetConfiguration(config));
2466 PeerConnectionInterface::RTCConfiguration new_config =
2467 pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 09:54:382468 EXPECT_EQ(new_config.ice_check_min_interval, 100);
skvladd1f5fda2017-02-04 00:54:052469}
2470
Taylor Brandstettera1c30352016-05-13 15:15:112471// Test that when SetConfiguration changes both the pool size and other
2472// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-17 00:04:202473TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 15:15:112474 SetConfigurationCreatesPooledSessionCorrectly) {
2475 CreatePeerConnection();
Steve Anton36da6ff2018-02-17 00:04:202476 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 15:15:112477 config.ice_candidate_pool_size = 1;
2478 PeerConnectionInterface::IceServer server;
2479 server.uri = kStunAddressOnly;
2480 config.servers.push_back(server);
2481 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 23:02:192482 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 15:15:112483
2484 const cricket::FakePortAllocatorSession* session =
2485 static_cast<const cricket::FakePortAllocatorSession*>(
2486 port_allocator_->GetPooledSession());
2487 ASSERT_NE(nullptr, session);
2488 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 15:15:112489}
2490
deadbeef293e9262017-01-11 20:28:302491// Test that after SetLocalDescription, changing the pool size is not allowed,
2492// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-17 00:04:202493TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-13 02:49:322494 CantChangePoolSizeAfterSetLocalDescription) {
2495 CreatePeerConnection();
2496 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-17 00:04:202497 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-13 02:49:322498 config.ice_candidate_pool_size = 1;
2499 EXPECT_TRUE(pc_->SetConfiguration(config));
2500
2501 // Set remote offer; can still change pool size at this point.
2502 CreateOfferAsRemoteDescription();
2503 config.ice_candidate_pool_size = 2;
2504 EXPECT_TRUE(pc_->SetConfiguration(config));
2505
2506 // Set local answer; now it's too late.
2507 CreateAnswerAsLocalDescription();
2508 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 20:28:302509 RTCError error;
2510 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2511 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2512}
2513
deadbeef42a42632017-03-10 23:18:002514// Test that after setting an answer, extra pooled sessions are discarded. The
2515// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-17 00:04:202516TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 23:18:002517 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2518 CreatePeerConnection();
2519
2520 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-17 00:04:202521 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 23:18:002522 config.ice_candidate_pool_size = 4;
2523 EXPECT_TRUE(pc_->SetConfiguration(config));
2524
2525 // Do offer/answer.
2526 CreateOfferAsRemoteDescription();
2527 CreateAnswerAsLocalDescription();
2528
2529 // Expect no pooled sessions to be left.
2530 const cricket::PortAllocatorSession* session =
2531 port_allocator_->GetPooledSession();
2532 EXPECT_EQ(nullptr, session);
2533}
2534
2535// After Close is called, pooled candidates should be discarded so as to not
2536// waste network resources.
Steve Anton36da6ff2018-02-17 00:04:202537TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 23:18:002538 CreatePeerConnection();
2539
Steve Anton36da6ff2018-02-17 00:04:202540 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 23:18:002541 config.ice_candidate_pool_size = 3;
2542 EXPECT_TRUE(pc_->SetConfiguration(config));
2543 pc_->Close();
2544
2545 // Expect no pooled sessions to be left.
2546 const cricket::PortAllocatorSession* session =
2547 port_allocator_->GetPooledSession();
2548 EXPECT_EQ(nullptr, session);
2549}
2550
deadbeef293e9262017-01-11 20:28:302551// Test that SetConfiguration returns an invalid modification error if
2552// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-17 00:04:202553TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 20:28:302554 SetConfigurationReturnsInvalidModificationError) {
2555 PeerConnectionInterface::RTCConfiguration config;
2556 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2557 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2558 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
Niels Möllerf06f9232018-08-07 10:32:182559 CreatePeerConnection(config);
deadbeef293e9262017-01-11 20:28:302560
Steve Anton36da6ff2018-02-17 00:04:202561 PeerConnectionInterface::RTCConfiguration modified_config =
2562 pc_->GetConfiguration();
deadbeef293e9262017-01-11 20:28:302563 modified_config.bundle_policy =
2564 PeerConnectionInterface::kBundlePolicyMaxBundle;
2565 RTCError error;
2566 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2567 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2568
Steve Anton36da6ff2018-02-17 00:04:202569 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 20:28:302570 modified_config.rtcp_mux_policy =
2571 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2572 error.set_type(RTCErrorType::NONE);
2573 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2574 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2575
Steve Anton36da6ff2018-02-17 00:04:202576 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 20:28:302577 modified_config.continual_gathering_policy =
2578 PeerConnectionInterface::GATHER_CONTINUALLY;
2579 error.set_type(RTCErrorType::NONE);
2580 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2581 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2582}
2583
2584// Test that SetConfiguration returns a range error if the candidate pool size
2585// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-17 00:04:202586TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 20:28:302587 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2588 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 10:32:182589 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-17 00:04:202590 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 20:28:302591
2592 config.ice_candidate_pool_size = -1;
2593 RTCError error;
2594 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2595 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2596
2597 config.ice_candidate_pool_size = INT_MAX;
2598 error.set_type(RTCErrorType::NONE);
2599 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2600 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2601}
2602
2603// Test that SetConfiguration returns a syntax error if parsing an ICE server
2604// URL failed.
Steve Anton36da6ff2018-02-17 00:04:202605TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 20:28:302606 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2607 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 10:32:182608 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-17 00:04:202609 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 20:28:302610
2611 PeerConnectionInterface::IceServer bad_server;
2612 bad_server.uri = "stunn:www.example.com";
2613 config.servers.push_back(bad_server);
2614 RTCError error;
2615 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2616 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2617}
2618
2619// Test that SetConfiguration returns an invalid parameter error if a TURN
2620// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-17 00:04:202621TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 20:28:302622 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2623 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 10:32:182624 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-17 00:04:202625 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 20:28:302626
2627 PeerConnectionInterface::IceServer bad_server;
2628 bad_server.uri = "turn:www.example.com";
2629 // Missing password.
2630 bad_server.username = "foo";
2631 config.servers.push_back(bad_server);
2632 RTCError error;
2633 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2634 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-13 02:49:322635}
2636
henrike@webrtc.org28e20752013-07-10 00:45:362637// Test that PeerConnection::Close changes the states to closed and all remote
2638// tracks change state to ended.
Steve Anton36da6ff2018-02-17 00:04:202639TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:362640 // Initialize a PeerConnection and negotiate local and remote session
2641 // description.
2642 InitiateCall();
Steve Anton36da6ff2018-02-17 00:04:202643
2644 // With Plan B, verify the stream count. The analog with Unified Plan is the
2645 // RtpTransceiver count.
2646 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2647 ASSERT_EQ(1u, pc_->local_streams()->count());
2648 ASSERT_EQ(1u, pc_->remote_streams()->count());
2649 } else {
2650 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2651 }
henrike@webrtc.org28e20752013-07-10 00:45:362652
2653 pc_->Close();
2654
2655 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2656 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2657 pc_->ice_connection_state());
2658 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2659 pc_->ice_gathering_state());
2660
Steve Anton36da6ff2018-02-17 00:04:202661 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2662 EXPECT_EQ(1u, pc_->local_streams()->count());
2663 EXPECT_EQ(1u, pc_->remote_streams()->count());
2664 } else {
2665 // Verify that the RtpTransceivers are still present but all stopped.
2666 EXPECT_EQ(2u, pc_->GetTransceivers().size());
Mirko Bonadei739baf02019-01-27 16:29:422667 for (const auto& transceiver : pc_->GetTransceivers()) {
Steve Anton36da6ff2018-02-17 00:04:202668 EXPECT_TRUE(transceiver->stopped());
2669 }
2670 }
henrike@webrtc.org28e20752013-07-10 00:45:362671
Steve Anton36da6ff2018-02-17 00:04:202672 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2673 ASSERT_TRUE(audio_receiver);
2674 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2675 ASSERT_TRUE(video_receiver);
2676
Taylor Brandstetterd45b95c2016-03-29 20:16:522677 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 10:16:192678 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-17 00:04:202679 audio_receiver->track()->state(), kTimeout);
Taylor Brandstetterd45b95c2016-03-29 20:16:522680 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-17 00:04:202681 video_receiver->track()->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:362682}
2683
2684// Test that PeerConnection methods fails gracefully after
2685// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-17 00:04:202686// Don't run under Unified Plan since the stream API is not available.
2687TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 20:28:302688 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 19:34:102689 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:362690 CreateOfferAsRemoteDescription();
2691 CreateAnswerAsLocalDescription();
2692
2693 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 18:14:502694 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:362695 pc_->local_streams()->at(0);
2696
2697 pc_->Close();
2698
2699 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:292700 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:362701
henrike@webrtc.org28e20752013-07-10 00:45:362702 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2703
2704 EXPECT_TRUE(pc_->local_description() != NULL);
2705 EXPECT_TRUE(pc_->remote_description() != NULL);
2706
kwibergd1fe2812016-04-27 13:47:292707 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 22:30:512708 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 13:47:292709 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 22:30:512710 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:362711
2712 std::string sdp;
2713 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-12 01:27:342714 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 18:27:412715 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-12 01:27:342716 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:362717
2718 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-12 01:27:342719 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 18:27:412720 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-12 01:27:342721 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:362722}
2723
2724// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-17 00:04:202725TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:362726 InitiateCall();
2727 pc_->Close();
2728 DoGetStats(NULL);
2729}
deadbeefab9b2d12015-10-14 18:33:112730
2731// NOTE: The series of tests below come from what used to be
2732// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2733// setting a remote or local description has the expected effects.
2734
2735// This test verifies that the remote MediaStreams corresponding to a received
2736// SDP string is created. In this test the two separate MediaStreams are
2737// signaled.
Steve Anton36da6ff2018-02-17 00:04:202738TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
Niels Möllerf06f9232018-08-07 10:32:182739 RTCConfiguration config;
2740 config.enable_dtls_srtp = true;
2741 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-17 00:04:202742 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 18:33:112743
Taylor Brandstetterdc4eb8c2016-05-12 15:14:502744 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 18:33:112745 EXPECT_TRUE(
2746 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2747 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2748 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2749
2750 // Create a session description based on another SDP with another
2751 // MediaStream.
Steve Anton36da6ff2018-02-17 00:04:202752 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 18:33:112753
Taylor Brandstetterdc4eb8c2016-05-12 15:14:502754 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 18:33:112755 EXPECT_TRUE(
2756 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2757}
2758
2759// This test verifies that when remote tracks are added/removed from SDP, the
2760// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-17 00:04:202761// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2762// specific behavior.
2763TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 18:33:112764 AddRemoveTrackFromExistingRemoteMediaStream) {
Niels Möllerf06f9232018-08-07 10:32:182765 RTCConfiguration config;
2766 config.enable_dtls_srtp = true;
2767 CreatePeerConnection(config);
kwibergd1fe2812016-04-27 13:47:292768 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 18:03:042769 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-12 01:27:342770 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 18:33:112771 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2772 reference_collection_));
2773
2774 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 13:47:292775 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 18:03:042776 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-12 01:27:342777 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 18:33:112778 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2779 reference_collection_));
zhihuang9763d562016-08-05 18:14:502780 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 10:16:192781 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2782 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 18:14:502783 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 10:16:192784 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2785 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 18:33:112786
2787 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 13:47:292788 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 18:03:042789 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 10:16:192790 MockTrackObserver audio_track_observer(audio_track2);
2791 MockTrackObserver video_track_observer(video_track2);
2792
2793 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2794 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-12 01:27:342795 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 18:33:112796 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2797 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 20:16:522798 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 10:16:192799 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 20:16:522800 audio_track2->state(), kTimeout);
2801 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2802 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 18:33:112803}
2804
2805// This tests that remote tracks are ended if a local session description is set
2806// that rejects the media content type.
Steve Anton36da6ff2018-02-17 00:04:202807TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
Niels Möllerf06f9232018-08-07 10:32:182808 RTCConfiguration config;
2809 config.enable_dtls_srtp = true;
2810 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 18:33:112811 // First create and set a remote offer, then reject its video content in our
2812 // answer.
Steve Anton36da6ff2018-02-17 00:04:202813 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2814 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2815 ASSERT_TRUE(audio_receiver);
2816 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2817 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 18:33:112818
Steve Anton36da6ff2018-02-17 00:04:202819 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2820 audio_receiver->track();
deadbeefab9b2d12015-10-14 18:33:112821 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-17 00:04:202822 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2823 video_receiver->track();
2824 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 18:33:112825
kwibergd1fe2812016-04-27 13:47:292826 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 18:03:042827 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 18:33:112828 cricket::ContentInfo* video_info =
2829 local_answer->description()->GetContentByName("video");
2830 video_info->rejected = true;
Steve Antondb45ca82017-09-12 01:27:342831 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-17 00:04:202832 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2833 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 18:33:112834
2835 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 13:47:292836 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 18:03:042837 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 18:33:112838 video_info = local_offer->description()->GetContentByName("video");
2839 ASSERT_TRUE(video_info != nullptr);
2840 video_info->rejected = true;
2841 cricket::ContentInfo* audio_info =
2842 local_offer->description()->GetContentByName("audio");
2843 ASSERT_TRUE(audio_info != nullptr);
2844 audio_info->rejected = true;
Steve Antondb45ca82017-09-12 01:27:342845 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 20:16:522846 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-17 00:04:202847 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2848 kTimeout);
2849 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2850 kTimeout);
deadbeefab9b2d12015-10-14 18:33:112851}
2852
2853// This tests that we won't crash if the remote track has been removed outside
2854// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-17 00:04:202855// Don't run under Unified Plan since the stream API is not available.
2856TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
Niels Möllerf06f9232018-08-07 10:32:182857 RTCConfiguration config;
2858 config.enable_dtls_srtp = true;
2859 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-17 00:04:202860 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 18:33:112861 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2862 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2863 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2864
kwibergd1fe2812016-04-27 13:47:292865 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-17 00:04:202866 webrtc::CreateSessionDescription(SdpType::kAnswer,
2867 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 18:33:112868 cricket::ContentInfo* video_info =
2869 local_answer->description()->GetContentByName("video");
2870 video_info->rejected = true;
2871 cricket::ContentInfo* audio_info =
2872 local_answer->description()->GetContentByName("audio");
2873 audio_info->rejected = true;
Steve Antondb45ca82017-09-12 01:27:342874 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 18:33:112875
2876 // No crash is a pass.
2877}
2878
deadbeef5e97fb52015-10-15 19:49:082879// This tests that if a recvonly remote description is set, no remote streams
2880// will be created, even if the description contains SSRCs/MSIDs.
2881// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-17 00:04:202882TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
Niels Möllerf06f9232018-08-07 10:32:182883 RTCConfiguration config;
2884 config.enable_dtls_srtp = true;
2885 CreatePeerConnection(config);
deadbeef5e97fb52015-10-15 19:49:082886
Steve Anton36da6ff2018-02-17 00:04:202887 std::string recvonly_offer = GetSdpStringWithStream1();
Steve Anton1c9c9fc2019-02-14 23:13:092888 absl::StrReplaceAll({{kSendrecv, kRecvonly}}, &recvonly_offer);
deadbeef5e97fb52015-10-15 19:49:082889 CreateAndSetRemoteOffer(recvonly_offer);
2890
2891 EXPECT_EQ(0u, observer_.remote_streams()->count());
2892}
2893
deadbeefab9b2d12015-10-14 18:33:112894// This tests that a default MediaStream is created if a remote session
2895// description doesn't contain any streams and no MSID support.
2896// It also tests that the default stream is updated if a video m-line is added
2897// in a subsequent session description.
Steve Anton36da6ff2018-02-17 00:04:202898// Don't run under Unified Plan since this behavior is Plan B specific.
2899TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 10:32:182900 RTCConfiguration config;
2901 config.enable_dtls_srtp = true;
2902 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 18:33:112903 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2904
2905 ASSERT_EQ(1u, observer_.remote_streams()->count());
2906 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2907
2908 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2909 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 23:05:282910 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 18:33:112911
2912 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2913 ASSERT_EQ(1u, observer_.remote_streams()->count());
2914 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2915 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 17:20:042916 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2917 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 18:33:112918 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2919 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 17:20:042920 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2921 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 18:33:112922}
2923
2924// This tests that a default MediaStream is created if a remote session
2925// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-17 00:04:202926// Don't run under Unified Plan since this behavior is Plan B specific.
2927TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 18:50:392928 SendOnlySdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 10:32:182929 RTCConfiguration config;
2930 config.enable_dtls_srtp = true;
2931 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 18:33:112932 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2933
2934 ASSERT_EQ(1u, observer_.remote_streams()->count());
2935 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2936
2937 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2938 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 23:05:282939 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 18:33:112940}
2941
2942// This tests that it won't crash when PeerConnection tries to remove
2943// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-17 00:04:202944// Don't run under Unified Plan since this behavior is Plan B specific.
2945TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
Niels Möllerf06f9232018-08-07 10:32:182946 RTCConfiguration config;
2947 config.enable_dtls_srtp = true;
2948 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-17 00:04:202949 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 18:33:112950 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2951 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2952 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2953
2954 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2955
2956 // No crash is a pass.
2957}
2958
2959// This tests that a default MediaStream is created if the remote session
2960// description doesn't contain any streams and don't contain an indication if
2961// MSID is supported.
Steve Anton36da6ff2018-02-17 00:04:202962// Don't run under Unified Plan since this behavior is Plan B specific.
2963TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 18:50:392964 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 10:32:182965 RTCConfiguration config;
2966 config.enable_dtls_srtp = true;
2967 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 18:33:112968 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2969
2970 ASSERT_EQ(1u, observer_.remote_streams()->count());
2971 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2972 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2973 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2974}
2975
2976// This tests that a default MediaStream is not created if the remote session
2977// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-17 00:04:202978// Don't run under Unified Plan since this behavior is Plan B specific.
2979TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 10:32:182980 RTCConfiguration config;
2981 config.enable_dtls_srtp = true;
2982 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 18:33:112983 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2984 EXPECT_EQ(0u, observer_.remote_streams()->count());
2985}
2986
deadbeefbda7e0b2015-12-09 01:13:402987// This tests that when setting a new description, the old default tracks are
2988// not destroyed and recreated.
2989// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-17 00:04:202990// Don't run under Unified Plan since this behavior is Plan B specific.
2991TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 18:50:392992 DefaultTracksNotDestroyedAndRecreated) {
Niels Möllerf06f9232018-08-07 10:32:182993 RTCConfiguration config;
2994 config.enable_dtls_srtp = true;
2995 CreatePeerConnection(config);
deadbeefbda7e0b2015-12-09 01:13:402996 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2997
2998 ASSERT_EQ(1u, observer_.remote_streams()->count());
2999 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3000 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3001
3002 // Set the track to "disabled", then set a new description and ensure the
3003 // track is still disabled, which ensures it hasn't been recreated.
3004 remote_stream->GetAudioTracks()[0]->set_enabled(false);
3005 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3006 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3007 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
3008}
3009
deadbeefab9b2d12015-10-14 18:33:113010// This tests that a default MediaStream is not created if a remote session
3011// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-17 00:04:203012// Don't run under Unified Plan since this behavior is Plan B specific.
3013TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
Niels Möllerf06f9232018-08-07 10:32:183014 RTCConfiguration config;
3015 config.enable_dtls_srtp = true;
3016 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-17 00:04:203017 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 15:14:503018 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 18:33:113019 EXPECT_TRUE(
3020 CompareStreamCollections(observer_.remote_streams(), reference.get()));
3021
3022 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3023 EXPECT_EQ(0u, observer_.remote_streams()->count());
3024}
3025
Seth Hampson5897a6e2018-04-03 18:16:333026// This tests that a default MediaStream is created if a remote SDP comes from
3027// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
3028TEST_F(PeerConnectionInterfaceTestPlanB,
3029 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 10:32:183030 RTCConfiguration config;
3031 config.enable_dtls_srtp = true;
3032 CreatePeerConnection(config);
Seth Hampson5897a6e2018-04-03 18:16:333033 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
3034 // Add a=msid lines to simulate a Unified Plan endpoint that only
3035 // signals stream IDs with a=msid lines.
3036 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
3037
3038 CreateAndSetRemoteOffer(sdp_string);
3039
3040 ASSERT_EQ(1u, observer_.remote_streams()->count());
3041 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3042 EXPECT_EQ("default", remote_stream->id());
3043 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3044}
3045
Seth Hampson5b4f0752018-04-02 23:31:363046// This tests that when a Plan B endpoint receives an SDP that signals no media
3047// stream IDs indicated by the special character "-" in the a=msid line, that
3048// a default stream ID will be used for the MediaStream ID. This can occur
3049// when a Unified Plan endpoint signals no media stream IDs, but signals both
3050// a=ssrc msid and a=msid lines for interop signaling with Plan B.
3051TEST_F(PeerConnectionInterfaceTestPlanB,
3052 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
Niels Möllerf06f9232018-08-07 10:32:183053 RTCConfiguration config;
3054 config.enable_dtls_srtp = true;
3055 CreatePeerConnection(config);
Seth Hampson5b4f0752018-04-02 23:31:363056 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
3057 // the sender's stream ID will be interpreted as no stream IDs.
3058 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
3059 sdp_string.append("a=msid:- audiotrack0\n");
3060
3061 CreateAndSetRemoteOffer(sdp_string);
3062
3063 ASSERT_EQ(1u, observer_.remote_streams()->count());
3064 // Because SSRCs are signaled the track ID will be what was signaled in the
3065 // a=msid line.
3066 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3067 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3068 EXPECT_EQ("default", remote_stream->id());
3069 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-06 01:12:093070
3071 // Previously a bug ocurred when setting the remote description a second time.
3072 // This is because we checked equality of the remote StreamParams stream ID
3073 // (empty), and the previously set stream ID for the remote sender
3074 // ("default"). This cause a track to be removed, then added, when really
3075 // nothing should occur because it is the same track.
3076 CreateAndSetRemoteOffer(sdp_string);
3077 EXPECT_EQ(0u, observer_.remove_track_events_.size());
3078 EXPECT_EQ(1u, observer_.add_track_events_.size());
3079 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3080 remote_stream = observer_.remote_streams()->at(0);
3081 EXPECT_EQ("default", remote_stream->id());
3082 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 23:31:363083}
3084
deadbeefab9b2d12015-10-14 18:33:113085// This tests that an RtpSender is created when the local description is set
3086// after adding a local stream.
3087// TODO(deadbeef): This test and the one below it need to be updated when
3088// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-17 00:04:203089// Don't run under Unified Plan since this behavior is Plan B specific.
3090TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 10:32:183091 RTCConfiguration config;
3092 config.enable_dtls_srtp = true;
3093 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 18:33:113094
Taylor Brandstetterdc4eb8c2016-05-12 15:14:503095 // Create an offer with 1 stream with 2 tracks of each type.
3096 rtc::scoped_refptr<StreamCollection> stream_collection =
3097 CreateStreamCollection(1, 2);
3098 pc_->AddStream(stream_collection->at(0));
3099 std::unique_ptr<SessionDescriptionInterface> offer;
3100 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-12 01:27:343101 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 18:33:113102
deadbeefab9b2d12015-10-14 18:33:113103 auto senders = pc_->GetSenders();
3104 EXPECT_EQ(4u, senders.size());
3105 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3106 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3107 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3108 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3109
3110 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 15:14:503111 pc_->RemoveStream(stream_collection->at(0));
3112 stream_collection = CreateStreamCollection(1, 1);
3113 pc_->AddStream(stream_collection->at(0));
3114 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-12 01:27:343115 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 15:14:503116
deadbeefab9b2d12015-10-14 18:33:113117 senders = pc_->GetSenders();
3118 EXPECT_EQ(2u, senders.size());
3119 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3120 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3121 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
3122 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
3123}
3124
3125// This tests that an RtpSender is created when the local description is set
3126// before adding a local stream.
Steve Anton36da6ff2018-02-17 00:04:203127// Don't run under Unified Plan since this behavior is Plan B specific.
3128TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 18:50:393129 AddLocalStreamAfterLocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 10:32:183130 RTCConfiguration config;
3131 config.enable_dtls_srtp = true;
3132 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 18:33:113133
Taylor Brandstetterdc4eb8c2016-05-12 15:14:503134 rtc::scoped_refptr<StreamCollection> stream_collection =
3135 CreateStreamCollection(1, 2);
3136 // Add a stream to create the offer, but remove it afterwards.
3137 pc_->AddStream(stream_collection->at(0));
3138 std::unique_ptr<SessionDescriptionInterface> offer;
3139 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3140 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 18:33:113141
Steve Antondb45ca82017-09-12 01:27:343142 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 18:33:113143 auto senders = pc_->GetSenders();
3144 EXPECT_EQ(0u, senders.size());
3145
Taylor Brandstetterdc4eb8c2016-05-12 15:14:503146 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 18:33:113147 senders = pc_->GetSenders();
3148 EXPECT_EQ(4u, senders.size());
3149 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3150 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3151 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3152 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3153}
3154
3155// This tests that the expected behavior occurs if the SSRC on a local track is
3156// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-17 00:04:203157TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 18:50:393158 ChangeSsrcOnTrackInLocalSessionDescription) {
Niels Möllerf06f9232018-08-07 10:32:183159 RTCConfiguration config;
3160 config.enable_dtls_srtp = true;
3161 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 18:33:113162
Steve Anton36da6ff2018-02-17 00:04:203163 AddAudioTrack(kAudioTracks[0]);
3164 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 15:14:503165 std::unique_ptr<SessionDescriptionInterface> offer;
3166 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3167 // Grab a copy of the offer before it gets passed into the PC.
Steve Antond9e4a062018-07-25 01:23:333168 std::unique_ptr<SessionDescriptionInterface> modified_offer =
3169 webrtc::CreateSessionDescription(
3170 webrtc::SdpType::kOffer, offer->session_id(),
Harald Alvestrand4d7160e2019-04-12 05:01:293171 offer->session_version(), offer->description()->Clone());
Steve Antondb45ca82017-09-12 01:27:343172 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 18:33:113173
deadbeefab9b2d12015-10-14 18:33:113174 auto senders = pc_->GetSenders();
3175 EXPECT_EQ(2u, senders.size());
3176 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3177 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3178
3179 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 15:14:503180 cricket::MediaContentDescription* desc =
3181 cricket::GetFirstAudioContentDescription(modified_offer->description());
3182 ASSERT_TRUE(desc != NULL);
3183 for (StreamParams& stream : desc->mutable_streams()) {
3184 for (unsigned int& ssrc : stream.ssrcs) {
3185 ++ssrc;
3186 }
3187 }
deadbeefab9b2d12015-10-14 18:33:113188
Taylor Brandstetterdc4eb8c2016-05-12 15:14:503189 desc =
3190 cricket::GetFirstVideoContentDescription(modified_offer->description());
3191 ASSERT_TRUE(desc != NULL);
3192 for (StreamParams& stream : desc->mutable_streams()) {
3193 for (unsigned int& ssrc : stream.ssrcs) {
3194 ++ssrc;
3195 }
3196 }
3197
Steve Antondb45ca82017-09-12 01:27:343198 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 18:33:113199 senders = pc_->GetSenders();
3200 EXPECT_EQ(2u, senders.size());
3201 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3202 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3203 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
3204 // changed.
3205}
3206
3207// This tests that the expected behavior occurs if a new session description is
3208// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-17 00:04:203209// Don't run under Unified Plan since the stream API is not available.
3210TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 18:50:393211 SignalSameTracksInSeparateMediaStream) {
Niels Möllerf06f9232018-08-07 10:32:183212 RTCConfiguration config;
3213 config.enable_dtls_srtp = true;
3214 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 18:33:113215
Taylor Brandstetterdc4eb8c2016-05-12 15:14:503216 rtc::scoped_refptr<StreamCollection> stream_collection =
3217 CreateStreamCollection(2, 1);
3218 pc_->AddStream(stream_collection->at(0));
3219 std::unique_ptr<SessionDescriptionInterface> offer;
3220 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-12 01:27:343221 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 18:33:113222
deadbeefab9b2d12015-10-14 18:33:113223 auto senders = pc_->GetSenders();
3224 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 15:14:503225 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3226 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 18:33:113227
3228 // Add a new MediaStream but with the same tracks as in the first stream.
3229 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3230 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 15:14:503231 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3232 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 18:33:113233 pc_->AddStream(stream_1);
3234
Taylor Brandstetterdc4eb8c2016-05-12 15:14:503235 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-12 01:27:343236 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 18:33:113237
Taylor Brandstetterdc4eb8c2016-05-12 15:14:503238 auto new_senders = pc_->GetSenders();
3239 // Should be the same senders as before, but with updated stream id.
3240 // Note that this behavior is subject to change in the future.
3241 // We may decide the PC should ignore existing tracks in AddStream.
3242 EXPECT_EQ(senders, new_senders);
3243 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3244 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 18:33:113245}
3246
zhihuang81c3a032016-11-17 20:06:243247// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-17 00:04:203248TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
Niels Möllerf06f9232018-08-07 10:32:183249 RTCConfiguration config;
3250 config.enable_dtls_srtp = true;
3251 CreatePeerConnection(config);
zhihuang81c3a032016-11-17 20:06:243252 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3253 EXPECT_EQ(observer_.num_added_tracks_, 1);
3254 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3255
3256 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-17 00:04:203257 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
Steve Anton0f5400a2018-07-17 21:25:363258 EXPECT_EQ(observer_.num_added_tracks_, 2);
zhihuang81c3a032016-11-17 20:06:243259 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3260}
3261
deadbeefd1a38b52016-12-10 21:15:333262// Test that when SetConfiguration is called and the configuration is
3263// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-17 00:04:203264TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 21:15:333265 PeerConnectionInterface::RTCConfiguration config;
3266 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 10:32:183267 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-17 00:04:203268 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 19:34:103269 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3270 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 21:15:333271
3272 // Do initial offer/answer so there's something to restart.
3273 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-17 00:04:203274 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 21:15:333275
3276 // Grab the ufrags.
3277 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3278
3279 // Change ICE policy, which should trigger an ICE restart on the next offer.
3280 config.type = PeerConnectionInterface::kAll;
3281 EXPECT_TRUE(pc_->SetConfiguration(config));
3282 CreateOfferAsLocalDescription();
3283
3284 // Grab the new ufrags.
3285 std::vector<std::string> subsequent_ufrags =
3286 GetUfrags(pc_->local_description());
3287
3288 // Sanity check.
3289 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3290 // Check that each ufrag is different.
3291 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3292 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3293 }
3294}
3295
3296// Test that when SetConfiguration is called and the configuration *isn't*
3297// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-17 00:04:203298TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 21:15:333299 PeerConnectionInterface::RTCConfiguration config;
3300 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 10:32:183301 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-17 00:04:203302 config = pc_->GetConfiguration();
3303 AddAudioTrack(kAudioTracks[0]);
3304 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 21:15:333305
3306 // Do initial offer/answer so there's something to restart.
3307 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-17 00:04:203308 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 21:15:333309
3310 // Grab the ufrags.
3311 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3312
3313 // Call SetConfiguration with a config identical to what the PC was
3314 // constructed with.
3315 EXPECT_TRUE(pc_->SetConfiguration(config));
3316 CreateOfferAsLocalDescription();
3317
3318 // Grab the new ufrags.
3319 std::vector<std::string> subsequent_ufrags =
3320 GetUfrags(pc_->local_description());
3321
3322 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3323}
3324
3325// Test for a weird corner case scenario:
3326// 1. Audio/video session established.
3327// 2. SetConfiguration changes ICE config; ICE restart needed.
3328// 3. ICE restart initiated by remote peer, but only for one m= section.
3329// 4. Next createOffer should initiate an ICE restart, but only for the other
3330// m= section; it would be pointless to do an ICE restart for the m= section
3331// that was already restarted.
Steve Anton36da6ff2018-02-17 00:04:203332TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 21:15:333333 PeerConnectionInterface::RTCConfiguration config;
3334 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 10:32:183335 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-17 00:04:203336 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 19:34:103337 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3338 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 21:15:333339
3340 // Do initial offer/answer so there's something to restart.
3341 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-17 00:04:203342 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 21:15:333343
3344 // Change ICE policy, which should set the "needs-ice-restart" flag.
3345 config.type = PeerConnectionInterface::kAll;
3346 EXPECT_TRUE(pc_->SetConfiguration(config));
3347
3348 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-12 01:27:343349 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-17 00:04:203350 webrtc::CreateSessionDescription(SdpType::kOffer,
3351 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-12 01:27:343352 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 21:15:333353 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3354 "modified";
Steve Antondb45ca82017-09-12 01:27:343355 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 21:15:333356 CreateAnswerAsLocalDescription();
3357
3358 // Grab the ufrags.
3359 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 10:53:233360 ASSERT_EQ(2U, initial_ufrags.size());
deadbeefd1a38b52016-12-10 21:15:333361
3362 // Create offer and grab the new ufrags.
3363 CreateOfferAsLocalDescription();
3364 std::vector<std::string> subsequent_ufrags =
3365 GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 10:53:233366 ASSERT_EQ(2U, subsequent_ufrags.size());
deadbeefd1a38b52016-12-10 21:15:333367
3368 // Ensure that only the ufrag for the second m= section changed.
3369 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3370 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3371}
3372
deadbeeffe4a8a42016-12-21 01:56:173373// Tests that the methods to return current/pending descriptions work as
3374// expected at different points in the offer/answer exchange. This test does
3375// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-17 00:04:203376TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-21 01:56:173377 // This disables DTLS so we can apply an answer to ourselves.
3378 CreatePeerConnection();
3379
3380 // Create initial local offer and get SDP (which will also be used as
3381 // answer/pranswer);
Steve Antondb45ca82017-09-12 01:27:343382 std::unique_ptr<SessionDescriptionInterface> local_offer;
3383 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-21 01:56:173384 std::string sdp;
Steve Antondb45ca82017-09-12 01:27:343385 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-21 01:56:173386
3387 // Set local offer.
Steve Antondb45ca82017-09-12 01:27:343388 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3389 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3390 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-21 01:56:173391 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3392 EXPECT_EQ(nullptr, pc_->current_local_description());
3393 EXPECT_EQ(nullptr, pc_->current_remote_description());
3394
3395 // Set remote pranswer.
Steve Antondb45ca82017-09-12 01:27:343396 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 18:27:413397 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-12 01:27:343398 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3399 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3400 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3401 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-21 01:56:173402 EXPECT_EQ(nullptr, pc_->current_local_description());
3403 EXPECT_EQ(nullptr, pc_->current_remote_description());
3404
3405 // Set remote answer.
Steve Antondb45ca82017-09-12 01:27:343406 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 18:27:413407 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-12 01:27:343408 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3409 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-21 01:56:173410 EXPECT_EQ(nullptr, pc_->pending_local_description());
3411 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-12 01:27:343412 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3413 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-21 01:56:173414
3415 // Set remote offer.
Steve Antondb45ca82017-09-12 01:27:343416 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 18:27:413417 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-12 01:27:343418 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3419 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3420 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-21 01:56:173421 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-12 01:27:343422 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3423 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-21 01:56:173424
3425 // Set local pranswer.
Steve Antondb45ca82017-09-12 01:27:343426 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 18:27:413427 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-12 01:27:343428 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3429 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3430 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3431 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3432 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3433 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-21 01:56:173434
3435 // Set local answer.
Steve Antondb45ca82017-09-12 01:27:343436 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 18:27:413437 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-12 01:27:343438 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3439 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-21 01:56:173440 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3441 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-12 01:27:343442 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3443 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-21 01:56:173444}
3445
zhihuang77985012017-02-07 23:45:163446// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3447// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 14:29:403448// This version tests the StartRtcEventLog version that receives a file.
Steve Anton36da6ff2018-02-17 00:04:203449TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 14:29:403450 StartAndStopLoggingToFileAfterPeerConnectionClosed) {
zhihuang77985012017-02-07 23:45:163451 CreatePeerConnection();
3452 // The RtcEventLog will be reset when the PeerConnection is closed.
3453 pc_->Close();
3454
Elad Alon9e6565b2017-10-11 14:04:133455 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
3456 std::string filename = webrtc::test::OutputPath() +
3457 test_info->test_case_name() + test_info->name();
3458 rtc::PlatformFile file = rtc::CreatePlatformFile(filename);
3459
3460 constexpr int64_t max_size_bytes = 1024;
3461
zhihuang77985012017-02-07 23:45:163462 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes));
3463 pc_->StopRtcEventLog();
Elad Alon9e6565b2017-10-11 14:04:133464
3465 // Cleanup.
3466 rtc::ClosePlatformFile(file);
3467 rtc::RemoveFile(filename);
zhihuang77985012017-02-07 23:45:163468}
3469
Elad Alon99c3fe52017-10-13 14:29:403470// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3471// after the PeerConnection is closed.
3472// This version tests the StartRtcEventLog version that receives an object
3473// of type |RtcEventLogOutput|.
Steve Anton36da6ff2018-02-17 00:04:203474TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 14:29:403475 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3476 CreatePeerConnection();
3477 // The RtcEventLog will be reset when the PeerConnection is closed.
3478 pc_->Close();
3479
3480 rtc::PlatformFile file = 0;
3481 int64_t max_size_bytes = 1024;
3482 EXPECT_FALSE(pc_->StartRtcEventLog(
Karl Wiberg918f50c2018-07-05 09:40:333483 absl::make_unique<webrtc::RtcEventLogOutputFile>(file, max_size_bytes),
Bjorn Tereliusde939432017-11-20 16:38:143484 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 14:29:403485 pc_->StopRtcEventLog();
3486}
3487
deadbeef30952b42017-04-21 09:41:293488// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-17 00:04:203489TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 09:41:293490 CreatePeerConnection();
3491
3492 // First, create an offer with audio/video.
Niels Möllerf06f9232018-08-07 10:32:183493 RTCOfferAnswerOptions options;
3494 options.offer_to_receive_audio = 1;
3495 options.offer_to_receive_video = 1;
deadbeef30952b42017-04-21 09:41:293496 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 10:32:183497 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef30952b42017-04-21 09:41:293498 cricket::SessionDescription* desc = offer->description();
3499 ASSERT_EQ(2u, desc->transport_infos().size());
3500 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3501 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3502
3503 // Apply the offer as a remote description, then create an answer.
Steve Antondb45ca82017-09-12 01:27:343504 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef30952b42017-04-21 09:41:293505 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 10:32:183506 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef30952b42017-04-21 09:41:293507 desc = answer->description();
3508 ASSERT_EQ(2u, desc->transport_infos().size());
3509 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3510 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3511}
3512
deadbeef1dcb1642017-03-30 04:08:163513// Test that ICE renomination isn't offered if it's not enabled in the PC's
3514// RTCConfiguration.
Steve Anton36da6ff2018-02-17 00:04:203515TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-30 04:08:163516 PeerConnectionInterface::RTCConfiguration config;
3517 config.enable_ice_renomination = false;
Niels Möllerf06f9232018-08-07 10:32:183518 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-17 00:04:203519 AddAudioTrack("foo");
deadbeef1dcb1642017-03-30 04:08:163520
3521 std::unique_ptr<SessionDescriptionInterface> offer;
3522 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3523 cricket::SessionDescription* desc = offer->description();
3524 EXPECT_EQ(1u, desc->transport_infos().size());
3525 EXPECT_FALSE(
3526 desc->transport_infos()[0].description.GetIceParameters().renomination);
3527}
3528
3529// Test that the ICE renomination option is present in generated offers/answers
3530// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-17 00:04:203531TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-30 04:08:163532 PeerConnectionInterface::RTCConfiguration config;
3533 config.enable_ice_renomination = true;
Niels Möllerf06f9232018-08-07 10:32:183534 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-17 00:04:203535 AddAudioTrack("foo");
deadbeef1dcb1642017-03-30 04:08:163536
3537 std::unique_ptr<SessionDescriptionInterface> offer;
3538 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3539 cricket::SessionDescription* desc = offer->description();
3540 EXPECT_EQ(1u, desc->transport_infos().size());
3541 EXPECT_TRUE(
3542 desc->transport_infos()[0].description.GetIceParameters().renomination);
3543
3544 // Set the offer as a remote description, then create an answer and ensure it
3545 // has the renomination flag too.
Steve Antondb45ca82017-09-12 01:27:343546 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-30 04:08:163547 std::unique_ptr<SessionDescriptionInterface> answer;
3548 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3549 desc = answer->description();
3550 EXPECT_EQ(1u, desc->transport_infos().size());
3551 EXPECT_TRUE(
3552 desc->transport_infos()[0].description.GetIceParameters().renomination);
3553}
3554
3555// Test that if CreateOffer is called with the deprecated "offer to receive
3556// audio/video" constraints, they're processed and result in an offer with
3557// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-17 00:04:203558TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-30 04:08:163559 CreatePeerConnection();
3560
Niels Möllerf06f9232018-08-07 10:32:183561 RTCOfferAnswerOptions options;
3562 options.offer_to_receive_audio = 1;
3563 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-30 04:08:163564 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 10:32:183565 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef1dcb1642017-03-30 04:08:163566
3567 cricket::SessionDescription* desc = offer->description();
3568 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3569 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3570 ASSERT_NE(nullptr, audio);
3571 ASSERT_NE(nullptr, video);
3572 EXPECT_FALSE(audio->rejected);
3573 EXPECT_FALSE(video->rejected);
3574}
3575
3576// Test that if CreateAnswer is called with the deprecated "offer to receive
3577// audio/video" constraints, they're processed and can be used to reject an
3578// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-17 00:04:203579// Don't run under Unified Plan since this behavior is not supported.
3580TEST_F(PeerConnectionInterfaceTestPlanB,
3581 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-30 04:08:163582 CreatePeerConnection();
3583
3584 // First, create an offer with audio/video and apply it as a remote
3585 // description.
Niels Möllerf06f9232018-08-07 10:32:183586 RTCOfferAnswerOptions options;
3587 options.offer_to_receive_audio = 1;
3588 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-30 04:08:163589 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 10:32:183590 ASSERT_TRUE(DoCreateOffer(&offer, &options));
Steve Antondb45ca82017-09-12 01:27:343591 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-30 04:08:163592
3593 // Now create answer that rejects audio/video.
Niels Möllerf06f9232018-08-07 10:32:183594 options.offer_to_receive_audio = 0;
3595 options.offer_to_receive_video = 0;
deadbeef1dcb1642017-03-30 04:08:163596 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 10:32:183597 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef1dcb1642017-03-30 04:08:163598
3599 cricket::SessionDescription* desc = answer->description();
3600 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3601 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3602 ASSERT_NE(nullptr, audio);
3603 ASSERT_NE(nullptr, video);
3604 EXPECT_TRUE(audio->rejected);
3605 EXPECT_TRUE(video->rejected);
3606}
3607
deadbeef1dcb1642017-03-30 04:08:163608// Test that negotiation can succeed with a data channel only, and with the max
3609// bundle policy. Previously there was a bug that prevented this.
Steve Anton36da6ff2018-02-17 00:04:203610#ifdef HAVE_SCTP
3611TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3612#else
3613TEST_P(PeerConnectionInterfaceTest,
3614 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
3615#endif // HAVE_SCTP
deadbeef1dcb1642017-03-30 04:08:163616 PeerConnectionInterface::RTCConfiguration config;
3617 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möllerf06f9232018-08-07 10:32:183618 CreatePeerConnection(config);
deadbeef1dcb1642017-03-30 04:08:163619
3620 // First, create an offer with only a data channel and apply it as a remote
3621 // description.
3622 pc_->CreateDataChannel("test", nullptr);
3623 std::unique_ptr<SessionDescriptionInterface> offer;
3624 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-12 01:27:343625 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-30 04:08:163626
3627 // Create and set answer as well.
3628 std::unique_ptr<SessionDescriptionInterface> answer;
3629 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-12 01:27:343630 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-30 04:08:163631}
3632
Steve Anton36da6ff2018-02-17 00:04:203633TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 21:37:373634 CreatePeerConnection();
3635 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 09:54:383636 bitrate.current_bitrate_bps = 100000;
zstein4b979802017-06-02 21:37:373637 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3638}
3639
Steve Anton36da6ff2018-02-17 00:04:203640TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 21:37:373641 CreatePeerConnection();
3642 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 09:54:383643 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 21:37:373644 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3645}
3646
Steve Anton36da6ff2018-02-17 00:04:203647TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 21:37:373648 CreatePeerConnection();
3649 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 09:54:383650 bitrate.min_bitrate_bps = 5;
3651 bitrate.current_bitrate_bps = 3;
zstein4b979802017-06-02 21:37:373652 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3653}
3654
Steve Anton36da6ff2018-02-17 00:04:203655TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 21:37:373656 CreatePeerConnection();
3657 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 09:54:383658 bitrate.current_bitrate_bps = -1;
zstein4b979802017-06-02 21:37:373659 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3660}
3661
Steve Anton36da6ff2018-02-17 00:04:203662TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 21:37:373663 CreatePeerConnection();
3664 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 09:54:383665 bitrate.current_bitrate_bps = 10;
3666 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 21:37:373667 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3668}
3669
Steve Anton36da6ff2018-02-17 00:04:203670TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 21:37:373671 CreatePeerConnection();
3672 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 09:54:383673 bitrate.min_bitrate_bps = 10;
3674 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 21:37:373675 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3676}
3677
Steve Anton36da6ff2018-02-17 00:04:203678TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 21:37:373679 CreatePeerConnection();
3680 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 09:54:383681 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 21:37:373682 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3683}
3684
Steve Anton038834f2017-07-14 22:59:593685// ice_regather_interval_range requires WebRTC to be configured for continual
3686// gathering already.
Steve Anton36da6ff2018-02-17 00:04:203687TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 22:59:593688 SetIceRegatherIntervalRangeWithoutContinualGatheringFails) {
3689 PeerConnectionInterface::RTCConfiguration config;
3690 config.ice_regather_interval_range.emplace(1000, 2000);
3691 config.continual_gathering_policy =
3692 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE;
3693 CreatePeerConnectionExpectFail(config);
3694}
3695
3696// Ensures that there is no error when ice_regather_interval_range is set with
3697// continual gathering enabled.
Steve Anton36da6ff2018-02-17 00:04:203698TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 22:59:593699 SetIceRegatherIntervalRangeWithContinualGathering) {
3700 PeerConnectionInterface::RTCConfiguration config;
3701 config.ice_regather_interval_range.emplace(1000, 2000);
3702 config.continual_gathering_policy =
3703 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY;
Niels Möllerf06f9232018-08-07 10:32:183704 CreatePeerConnection(config);
Steve Anton038834f2017-07-14 22:59:593705}
3706
Niels Möller0c4f7be2018-05-07 12:01:373707// The current bitrate from BitrateSettings is currently clamped
Sebastian Janssonfc8d26b2018-02-21 08:52:063708// by Call's BitrateConstraints, which comes from the SDP or a default value.
3709// This test checks that a call to SetBitrate with a current bitrate that will
3710// be clamped succeeds.
Steve Anton36da6ff2018-02-17 00:04:203711TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 21:37:373712 CreatePeerConnection();
3713 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 09:54:383714 bitrate.current_bitrate_bps = 1;
zstein4b979802017-06-02 21:37:373715 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3716}
3717
zhihuang1c378ed2017-08-17 21:10:503718// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-17 00:04:203719TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 21:10:503720 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3721 RTCOfferAnswerOptions rtc_options;
3722
3723 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3724 // than kMaxOfferToReceiveMedia should be treated as invalid.
3725 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3726 CreatePeerConnection();
3727 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3728
3729 rtc_options.offer_to_receive_audio =
3730 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3731 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3732}
3733
Steve Anton36da6ff2018-02-17 00:04:203734TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 21:10:503735 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3736 RTCOfferAnswerOptions rtc_options;
3737
3738 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3739 // than kMaxOfferToReceiveMedia should be treated as invalid.
3740 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3741 CreatePeerConnection();
3742 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3743
3744 rtc_options.offer_to_receive_video =
3745 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3746 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3747}
3748
3749// Test that the audio and video content will be added to an offer if both
3750// |offer_to_receive_audio| and |offer_to_receive_video| options are 1.
Steve Anton36da6ff2018-02-17 00:04:203751TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 21:10:503752 RTCOfferAnswerOptions rtc_options;
3753 rtc_options.offer_to_receive_audio = 1;
3754 rtc_options.offer_to_receive_video = 1;
3755
3756 std::unique_ptr<SessionDescriptionInterface> offer;
3757 CreatePeerConnection();
3758 offer = CreateOfferWithOptions(rtc_options);
3759 ASSERT_TRUE(offer);
3760 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3761 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3762}
3763
3764// Test that only audio content will be added to the offer if only
3765// |offer_to_receive_audio| options is 1.
Steve Anton36da6ff2018-02-17 00:04:203766TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 21:10:503767 RTCOfferAnswerOptions rtc_options;
3768 rtc_options.offer_to_receive_audio = 1;
3769 rtc_options.offer_to_receive_video = 0;
3770
3771 std::unique_ptr<SessionDescriptionInterface> offer;
3772 CreatePeerConnection();
3773 offer = CreateOfferWithOptions(rtc_options);
3774 ASSERT_TRUE(offer);
3775 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3776 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3777}
3778
3779// Test that only video content will be added if only |offer_to_receive_video|
3780// options is 1.
Steve Anton36da6ff2018-02-17 00:04:203781TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 21:10:503782 RTCOfferAnswerOptions rtc_options;
3783 rtc_options.offer_to_receive_audio = 0;
3784 rtc_options.offer_to_receive_video = 1;
3785
3786 std::unique_ptr<SessionDescriptionInterface> offer;
3787 CreatePeerConnection();
3788 offer = CreateOfferWithOptions(rtc_options);
3789 ASSERT_TRUE(offer);
3790 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3791 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3792}
3793
zhihuang1c378ed2017-08-17 21:10:503794// Test that no media content will be added to the offer if using default
3795// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-17 00:04:203796TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 21:10:503797 RTCOfferAnswerOptions rtc_options;
3798
3799 std::unique_ptr<SessionDescriptionInterface> offer;
3800 CreatePeerConnection();
3801 offer = CreateOfferWithOptions(rtc_options);
3802 ASSERT_TRUE(offer);
3803 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3804 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3805}
3806
3807// Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise
3808// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-17 00:04:203809TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3810 CreatePeerConnection();
3811
zhihuang1c378ed2017-08-17 21:10:503812 RTCOfferAnswerOptions rtc_options;
3813 rtc_options.ice_restart = false;
3814 rtc_options.offer_to_receive_audio = 1;
3815
3816 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 21:10:503817 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-17 00:04:203818 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3819 auto ufrag1 =
3820 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3821 auto pwd1 =
3822 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 21:10:503823
3824 // |ice_restart| is false, the ufrag/pwd shouldn't change.
3825 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-17 00:04:203826 auto ufrag2 =
3827 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3828 auto pwd2 =
3829 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 21:10:503830
3831 // |ice_restart| is true, the ufrag/pwd should change.
3832 rtc_options.ice_restart = true;
3833 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-17 00:04:203834 auto ufrag3 =
3835 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3836 auto pwd3 =
3837 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 21:10:503838
3839 EXPECT_EQ(ufrag1, ufrag2);
3840 EXPECT_EQ(pwd1, pwd2);
3841 EXPECT_NE(ufrag2, ufrag3);
3842 EXPECT_NE(pwd2, pwd3);
3843}
3844
3845// Test that if |use_rtp_mux| is true, the bundling will be enabled in the
3846// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-17 00:04:203847TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 21:10:503848 RTCOfferAnswerOptions rtc_options;
3849 rtc_options.offer_to_receive_audio = 1;
3850 rtc_options.offer_to_receive_video = 1;
3851
3852 std::unique_ptr<SessionDescriptionInterface> offer;
3853 CreatePeerConnection();
3854
3855 rtc_options.use_rtp_mux = true;
3856 offer = CreateOfferWithOptions(rtc_options);
3857 ASSERT_TRUE(offer);
3858 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3859 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3860 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3861
3862 rtc_options.use_rtp_mux = false;
3863 offer = CreateOfferWithOptions(rtc_options);
3864 ASSERT_TRUE(offer);
3865 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3866 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3867 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3868}
3869
zhihuang141aacb2017-08-29 20:23:533870// This test ensures OnRenegotiationNeeded is called when we add track with
3871// MediaStream -> AddTrack in the same way it is called when we add track with
3872// PeerConnection -> AddTrack.
3873// The test can be removed once addStream is rewritten in terms of addTrack
3874// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-17 00:04:203875// Don't run under Unified Plan since the stream API is not available.
3876TEST_F(PeerConnectionInterfaceTestPlanB,
3877 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 20:23:533878 CreatePeerConnectionWithoutDtls();
3879 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 19:34:103880 pc_factory_->CreateLocalMediaStream(kStreamId1));
zhihuang141aacb2017-08-29 20:23:533881 pc_->AddStream(stream);
3882 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 12:59:453883 CreateAudioTrack("audio_track"));
zhihuang141aacb2017-08-29 20:23:533884 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 12:59:453885 CreateVideoTrack("video_track"));
zhihuang141aacb2017-08-29 20:23:533886 stream->AddTrack(audio_track);
3887 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3888 observer_.renegotiation_needed_ = false;
3889
Guido Urdaneta70c2db12019-04-16 10:24:143890 CreateOfferReceiveAnswer();
zhihuang141aacb2017-08-29 20:23:533891 stream->AddTrack(video_track);
3892 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3893 observer_.renegotiation_needed_ = false;
3894
Guido Urdaneta70c2db12019-04-16 10:24:143895 CreateOfferReceiveAnswer();
zhihuang141aacb2017-08-29 20:23:533896 stream->RemoveTrack(audio_track);
3897 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3898 observer_.renegotiation_needed_ = false;
3899
Guido Urdaneta70c2db12019-04-16 10:24:143900 CreateOfferReceiveAnswer();
zhihuang141aacb2017-08-29 20:23:533901 stream->RemoveTrack(video_track);
3902 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3903 observer_.renegotiation_needed_ = false;
3904}
3905
Zhi Huangb2d355e2017-10-27 00:26:373906// Tests that an error is returned if a description is applied that has fewer
3907// media sections than the existing description.
Steve Anton36da6ff2018-02-17 00:04:203908TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-27 00:26:373909 MediaSectionCountEnforcedForSubsequentOffer) {
3910 CreatePeerConnection();
Steve Anton36da6ff2018-02-17 00:04:203911 AddAudioTrack("audio_label");
3912 AddVideoTrack("video_label");
3913
Zhi Huangb2d355e2017-10-27 00:26:373914 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-17 00:04:203915 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-27 00:26:373916 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3917
3918 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-17 00:04:203919 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-27 00:26:373920 offer->description()->contents().pop_back();
3921 offer->description()->contents().pop_back();
3922 ASSERT_TRUE(offer->description()->contents().empty());
3923 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3924
3925 std::unique_ptr<SessionDescriptionInterface> answer;
3926 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3927 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3928
3929 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-17 00:04:203930 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-27 00:26:373931 offer->description()->contents().pop_back();
3932 offer->description()->contents().pop_back();
3933 ASSERT_TRUE(offer->description()->contents().empty());
3934 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3935}
3936
Johannes Kron89f874e2018-11-12 09:25:483937TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) {
3938 RTCConfiguration config;
3939 // Default behavior is false.
3940 CreatePeerConnection(config);
3941 std::unique_ptr<SessionDescriptionInterface> offer;
3942 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3943 EXPECT_FALSE(offer->description()->extmap_allow_mixed());
3944 // Possible to set to true.
3945 config.offer_extmap_allow_mixed = true;
3946 CreatePeerConnection(config);
3947 offer.release();
3948 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3949 EXPECT_TRUE(offer->description()->extmap_allow_mixed());
3950}
3951
Mirko Bonadeic84f6612019-01-31 11:20:573952INSTANTIATE_TEST_SUITE_P(PeerConnectionInterfaceTest,
3953 PeerConnectionInterfaceTest,
3954 Values(SdpSemantics::kPlanB,
3955 SdpSemantics::kUnifiedPlan));
Steve Anton36da6ff2018-02-17 00:04:203956
Mirko Bonadei6a489f22019-04-09 13:11:123957class PeerConnectionMediaConfigTest : public ::testing::Test {
nisse51542be2016-02-12 10:27:063958 protected:
3959 void SetUp() override {
zhihuang38ede132017-06-15 19:52:323960 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 10:27:063961 pcf_->Initialize();
3962 }
nisseeaabdf62017-05-05 09:23:023963 const cricket::MediaConfig TestCreatePeerConnection(
Niels Möllerf06f9232018-08-07 10:32:183964 const RTCConfiguration& config) {
3965 rtc::scoped_refptr<PeerConnectionInterface> pc(
3966 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 10:27:063967 EXPECT_TRUE(pc.get());
Yves Gereyf3ff14c2018-10-25 08:28:123968 observer_.SetPeerConnectionInterface(pc.get());
nisseeaabdf62017-05-05 09:23:023969 return pc->GetConfiguration().media_config;
nisse51542be2016-02-12 10:27:063970 }
3971
zhihuang9763d562016-08-05 18:14:503972 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 10:27:063973 MockPeerConnectionObserver observer_;
3974};
3975
Yves Gereyf3ff14c2018-10-25 08:28:123976// This sanity check validates the test infrastructure itself.
3977TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) {
3978 PeerConnectionInterface::RTCConfiguration config;
3979 rtc::scoped_refptr<PeerConnectionInterface> pc(
3980 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
3981 EXPECT_TRUE(pc.get());
3982 observer_.SetPeerConnectionInterface(pc.get()); // Required.
3983 pc->Close(); // No abort -> ok.
3984 SUCCEED();
3985}
3986
nisse51542be2016-02-12 10:27:063987// This test verifies the default behaviour with no constraints and a
3988// default RTCConfiguration.
3989TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
3990 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 10:27:063991
Niels Möllerf06f9232018-08-07 10:32:183992 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 10:27:063993
3994 EXPECT_FALSE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 14:25:123995 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
3996 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 12:29:593997 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 07:58:503998 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 10:27:063999}
4000
Niels Möller1d7ecd22018-01-18 14:25:124001// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 10:21:434002// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 10:27:064003TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
4004 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 10:27:064005
Niels Möller71bdda02016-03-31 10:59:594006 config.set_prerenderer_smoothing(false);
Niels Möllerf06f9232018-08-07 10:32:184007 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 10:27:064008
Niels Möller1d7ecd22018-01-18 14:25:124009 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 12:29:594010}
4011
Niels Möller6539f692018-01-18 07:58:504012// This test verifies that the experiment_cpu_load_estimator flag is
4013// propagated from RTCConfiguration to the PeerConnection.
4014TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
4015 PeerConnectionInterface::RTCConfiguration config;
Niels Möller6539f692018-01-18 07:58:504016
4017 config.set_experiment_cpu_load_estimator(true);
Niels Möllerf06f9232018-08-07 10:32:184018 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
Niels Möller6539f692018-01-18 07:58:504019
4020 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
4021}
4022
deadbeef293e9262017-01-11 20:28:304023// Tests a few random fields being different.
4024TEST(RTCConfigurationTest, ComparisonOperators) {
4025 PeerConnectionInterface::RTCConfiguration a;
4026 PeerConnectionInterface::RTCConfiguration b;
4027 EXPECT_EQ(a, b);
4028
4029 PeerConnectionInterface::RTCConfiguration c;
4030 c.servers.push_back(PeerConnectionInterface::IceServer());
4031 EXPECT_NE(a, c);
4032
4033 PeerConnectionInterface::RTCConfiguration d;
4034 d.type = PeerConnectionInterface::kRelay;
4035 EXPECT_NE(a, d);
4036
4037 PeerConnectionInterface::RTCConfiguration e;
4038 e.audio_jitter_buffer_max_packets = 5;
4039 EXPECT_NE(a, e);
4040
4041 PeerConnectionInterface::RTCConfiguration f;
4042 f.ice_connection_receiving_timeout = 1337;
4043 EXPECT_NE(a, f);
4044
4045 PeerConnectionInterface::RTCConfiguration g;
4046 g.disable_ipv6 = true;
4047 EXPECT_NE(a, g);
4048
4049 PeerConnectionInterface::RTCConfiguration h(
4050 PeerConnectionInterface::RTCConfigurationType::kAggressive);
4051 EXPECT_NE(a, h);
4052}
Mirko Bonadeiab64e8a2018-12-12 11:10:184053
4054} // namespace
4055} // namespace webrtc