blob: 565d89801bccdbf20ac4a43e9a7768d8e88791f0 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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:36 +00009 */
10
Jonas Olssona4d87372019-07-05 19:08:33 +020011#include "api/peer_connection_interface.h"
12
Yves Gerey3e707812018-11-28 16:47:49 +010013#include <limits.h>
14#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016#include <string>
kwiberg0eb15ed2015-12-17 03:04:15 -080017#include <utility>
Yves Gerey3e707812018-11-28 16:47:49 +010018#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000019
Steve Anton1c9c9fc2019-02-14 15:13:09 -080020#include "absl/strings/str_replace.h"
Yves Gerey3e707812018-11-28 16:47:49 +010021#include "absl/types/optional.h"
22#include "api/audio/audio_mixer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "api/audio_codecs/builtin_audio_decoder_factory.h"
24#include "api/audio_codecs/builtin_audio_encoder_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080025#include "api/call/call_factory_interface.h"
Mirko Bonadei2ff3f492018-11-22 09:00:13 +010026#include "api/create_peerconnection_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080027#include "api/data_channel_interface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010028#include "api/jsep.h"
Steve Anton10542f22019-01-11 09:11:00 -080029#include "api/media_stream_interface.h"
30#include "api/media_types.h"
Steve Anton10542f22019-01-11 09:11:00 -080031#include "api/rtc_error.h"
Danil Chapovalov9da25bd2019-06-20 10:19:42 +020032#include "api/rtc_event_log/rtc_event_log.h"
33#include "api/rtc_event_log/rtc_event_log_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080034#include "api/rtc_event_log_output.h"
35#include "api/rtp_receiver_interface.h"
36#include "api/rtp_sender_interface.h"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000037#include "api/rtp_transceiver_direction.h"
Mirko Bonadeid9708072019-01-25 20:26:48 +010038#include "api/scoped_refptr.h"
Danil Chapovalov9da25bd2019-06-20 10:19:42 +020039#include "api/task_queue/default_task_queue_factory.h"
Erik Språngceb44952020-09-22 11:36:35 +020040#include "api/transport/field_trial_based_config.h"
Anders Carlsson67537952018-05-03 11:28:29 +020041#include "api/video_codecs/builtin_video_decoder_factory.h"
42#include "api/video_codecs/builtin_video_encoder_factory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010043#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080044#include "media/base/media_config.h"
45#include "media/base/media_engine.h"
46#include "media/base/stream_params.h"
Steve Anton10542f22019-01-11 09:11:00 -080047#include "media/engine/webrtc_media_engine.h"
Danil Chapovalov9da25bd2019-06-20 10:19:42 +020048#include "media/engine/webrtc_media_engine_defaults.h"
Steve Anton10542f22019-01-11 09:11:00 -080049#include "media/sctp/sctp_transport_internal.h"
Yves Gerey3e707812018-11-28 16:47:49 +010050#include "modules/audio_device/include/audio_device.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020051#include "modules/audio_processing/include/audio_processing.h"
Steve Anton10542f22019-01-11 09:11:00 -080052#include "p2p/base/fake_port_allocator.h"
53#include "p2p/base/p2p_constants.h"
Yves Gerey3e707812018-11-28 16:47:49 +010054#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 09:11:00 -080055#include "p2p/base/port_allocator.h"
56#include "p2p/base/transport_description.h"
57#include "p2p/base/transport_info.h"
58#include "pc/audio_track.h"
59#include "pc/media_session.h"
60#include "pc/media_stream.h"
61#include "pc/peer_connection.h"
62#include "pc/peer_connection_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080063#include "pc/rtp_sender.h"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000064#include "pc/rtp_sender_proxy.h"
Steve Anton10542f22019-01-11 09:11:00 -080065#include "pc/session_description.h"
66#include "pc/stream_collection.h"
67#include "pc/test/fake_audio_capture_module.h"
68#include "pc/test/fake_rtc_certificate_generator.h"
69#include "pc/test/fake_video_track_source.h"
70#include "pc/test/mock_peer_connection_observers.h"
71#include "pc/test/test_sdp_strings.h"
72#include "pc/video_track.h"
Yves Gerey3e707812018-11-28 16:47:49 +010073#include "rtc_base/checks.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020074#include "rtc_base/gunit.h"
Steve Anton10542f22019-01-11 09:11:00 -080075#include "rtc_base/rtc_certificate_generator.h"
Steve Anton10542f22019-01-11 09:11:00 -080076#include "rtc_base/socket_address.h"
Yves Gerey3e707812018-11-28 16:47:49 +010077#include "rtc_base/thread.h"
Steve Anton10542f22019-01-11 09:11:00 -080078#include "rtc_base/virtual_socket_server.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020079#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010080#include "test/gtest.h"
kwibergac9f8762016-09-30 22:29:43 -070081
82#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080083#include "pc/test/android_test_initializer.h"
kwibergac9f8762016-09-30 22:29:43 -070084#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +010086namespace webrtc {
87namespace {
88
Seth Hampson845e8782018-03-02 11:34:10 -080089static const char kStreamId1[] = "local_stream_1";
90static const char kStreamId2[] = "local_stream_2";
91static const char kStreamId3[] = "local_stream_3";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092static const int kDefaultStunPort = 3478;
93static const char kStunAddressOnly[] = "stun:address";
94static const char kStunInvalidPort[] = "stun:address:-1";
95static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
96static const char kStunAddressPortAndMore2[] = "stun:address:port more";
Niels Möllerdb4def92019-03-18 16:53:59 +010097static const char kTurnIceServerUri[] = "turn:turn.example.org";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000098static const char kTurnUsername[] = "user";
99static const char kTurnPassword[] = "password";
100static const char kTurnHostname[] = "turn.example.org";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200101static const uint32_t kTimeout = 10000U;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102
deadbeefab9b2d12015-10-14 11:33:11 -0700103static const char kStreams[][8] = {"stream1", "stream2"};
104static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
105static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
106
deadbeef5e97fb52015-10-15 12:49:08 -0700107static const char kRecvonly[] = "recvonly";
108static const char kSendrecv[] = "sendrecv";
109
deadbeefab9b2d12015-10-14 11:33:11 -0700110// Reference SDP with a MediaStream with label "stream1" and audio track with
111// id "audio_1" and a video track with id "video_1;
Steve Anton36da6ff2018-02-16 16:04:20 -0800112static const char kSdpStringWithStream1PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700113 "v=0\r\n"
114 "o=- 0 0 IN IP4 127.0.0.1\r\n"
115 "s=-\r\n"
116 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800117 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700118 "a=ice-ufrag:e5785931\r\n"
119 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
120 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
121 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700122 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700123 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800124 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700125 "a=rtpmap:103 ISAC/16000\r\n"
126 "a=ssrc:1 cname:stream1\r\n"
Harald Alvestrand88b8dec2022-04-07 09:54:51 +0000127 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700128 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800129 "a=ice-ufrag:e5785931\r\n"
130 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
131 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
132 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700133 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700134 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800135 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700136 "a=rtpmap:120 VP8/90000\r\n"
137 "a=ssrc:2 cname:stream1\r\n"
Harald Alvestrand88b8dec2022-04-07 09:54:51 +0000138 "a=ssrc:2 msid:stream1 videotrack0\r\n";
139// Same string as above but with the MID changed to the Unified Plan default and
140// a=msid added. This is needed so that this SDP can be used as an answer for a
141// Unified Plan offer.
Steve Anton36da6ff2018-02-16 16:04:20 -0800142static const char kSdpStringWithStream1UnifiedPlan[] =
143 "v=0\r\n"
144 "o=- 0 0 IN IP4 127.0.0.1\r\n"
145 "s=-\r\n"
146 "t=0 0\r\n"
147 "m=audio 1 RTP/AVPF 103\r\n"
148 "a=ice-ufrag:e5785931\r\n"
149 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
150 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
151 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
152 "a=mid:0\r\n"
153 "a=sendrecv\r\n"
154 "a=rtcp-mux\r\n"
155 "a=rtpmap:103 ISAC/16000\r\n"
Harald Alvestrand88b8dec2022-04-07 09:54:51 +0000156 "a=msid:stream1 audiotrack0\r\n"
Steve Anton36da6ff2018-02-16 16:04:20 -0800157 "a=ssrc:1 cname:stream1\r\n"
Steve Anton36da6ff2018-02-16 16:04:20 -0800158 "m=video 1 RTP/AVPF 120\r\n"
159 "a=ice-ufrag:e5785931\r\n"
160 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
161 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
162 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
163 "a=mid:1\r\n"
164 "a=sendrecv\r\n"
165 "a=rtcp-mux\r\n"
166 "a=rtpmap:120 VP8/90000\r\n"
Harald Alvestrand88b8dec2022-04-07 09:54:51 +0000167 "a=msid:stream1 videotrack0\r\n"
168 "a=ssrc:2 cname:stream1\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700169
zhihuang81c3a032016-11-17 12:06:24 -0800170// Reference SDP with a MediaStream with label "stream1" and audio track with
171// id "audio_1";
172static const char kSdpStringWithStream1AudioTrackOnly[] =
173 "v=0\r\n"
174 "o=- 0 0 IN IP4 127.0.0.1\r\n"
175 "s=-\r\n"
176 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800177 "m=audio 1 RTP/AVPF 103\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800178 "a=ice-ufrag:e5785931\r\n"
179 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
180 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
181 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800182 "a=mid:audio\r\n"
183 "a=sendrecv\r\n"
184 "a=rtpmap:103 ISAC/16000\r\n"
185 "a=ssrc:1 cname:stream1\r\n"
Harald Alvestrand88b8dec2022-04-07 09:54:51 +0000186 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800187 "a=rtcp-mux\r\n";
zhihuang81c3a032016-11-17 12:06:24 -0800188
deadbeefab9b2d12015-10-14 11:33:11 -0700189// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
190// MediaStreams have one audio track and one video track.
191// This uses MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -0800192static const char kSdpStringWithStream1And2PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700193 "v=0\r\n"
194 "o=- 0 0 IN IP4 127.0.0.1\r\n"
195 "s=-\r\n"
196 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800197 "a=msid-semantic: WMS stream1 stream2\r\n"
198 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700199 "a=ice-ufrag:e5785931\r\n"
200 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
201 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
202 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700203 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700204 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800205 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700206 "a=rtpmap:103 ISAC/16000\r\n"
207 "a=ssrc:1 cname:stream1\r\n"
208 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
209 "a=ssrc:3 cname:stream2\r\n"
210 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
211 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800212 "a=ice-ufrag:e5785931\r\n"
213 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
214 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
215 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700216 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700217 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800218 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700219 "a=rtpmap:120 VP8/0\r\n"
220 "a=ssrc:2 cname:stream1\r\n"
221 "a=ssrc:2 msid:stream1 videotrack0\r\n"
222 "a=ssrc:4 cname:stream2\r\n"
223 "a=ssrc:4 msid:stream2 videotrack1\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800224static const char kSdpStringWithStream1And2UnifiedPlan[] =
225 "v=0\r\n"
226 "o=- 0 0 IN IP4 127.0.0.1\r\n"
227 "s=-\r\n"
228 "t=0 0\r\n"
229 "a=msid-semantic: WMS stream1 stream2\r\n"
230 "m=audio 1 RTP/AVPF 103\r\n"
231 "a=ice-ufrag:e5785931\r\n"
232 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
233 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
234 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
235 "a=mid:0\r\n"
236 "a=sendrecv\r\n"
237 "a=rtcp-mux\r\n"
238 "a=rtpmap:103 ISAC/16000\r\n"
239 "a=ssrc:1 cname:stream1\r\n"
240 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
241 "m=video 1 RTP/AVPF 120\r\n"
242 "a=ice-ufrag:e5785931\r\n"
243 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
244 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
245 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
246 "a=mid:1\r\n"
247 "a=sendrecv\r\n"
248 "a=rtcp-mux\r\n"
249 "a=rtpmap:120 VP8/0\r\n"
250 "a=ssrc:2 cname:stream1\r\n"
251 "a=ssrc:2 msid:stream1 videotrack0\r\n"
252 "m=audio 1 RTP/AVPF 103\r\n"
253 "a=ice-ufrag:e5785931\r\n"
254 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
255 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
256 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
257 "a=mid:2\r\n"
258 "a=sendrecv\r\n"
259 "a=rtcp-mux\r\n"
260 "a=rtpmap:103 ISAC/16000\r\n"
261 "a=ssrc:3 cname:stream2\r\n"
262 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
263 "m=video 1 RTP/AVPF 120\r\n"
264 "a=ice-ufrag:e5785931\r\n"
265 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
266 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
267 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
268 "a=mid:3\r\n"
269 "a=sendrecv\r\n"
270 "a=rtcp-mux\r\n"
271 "a=rtpmap:120 VP8/0\r\n"
272 "a=ssrc:4 cname:stream2\r\n"
273 "a=ssrc:4 msid:stream2 videotrack1\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700274
275// Reference SDP without MediaStreams. Msid is not supported.
276static const char kSdpStringWithoutStreams[] =
277 "v=0\r\n"
278 "o=- 0 0 IN IP4 127.0.0.1\r\n"
279 "s=-\r\n"
280 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800281 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700282 "a=ice-ufrag:e5785931\r\n"
283 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
284 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
285 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700286 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700287 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800288 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700289 "a=rtpmap:103 ISAC/16000\r\n"
290 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800291 "a=ice-ufrag:e5785931\r\n"
292 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
293 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
294 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700295 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700296 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800297 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700298 "a=rtpmap:120 VP8/90000\r\n";
299
300// Reference SDP without MediaStreams. Msid is supported.
301static const char kSdpStringWithMsidWithoutStreams[] =
302 "v=0\r\n"
303 "o=- 0 0 IN IP4 127.0.0.1\r\n"
304 "s=-\r\n"
305 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800306 "a=msid-semantic: WMS\r\n"
307 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700308 "a=ice-ufrag:e5785931\r\n"
309 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
310 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
311 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700312 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700313 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800314 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700315 "a=rtpmap:103 ISAC/16000\r\n"
316 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800317 "a=ice-ufrag:e5785931\r\n"
318 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
319 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
320 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700321 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700322 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800323 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700324 "a=rtpmap:120 VP8/90000\r\n";
325
326// Reference SDP without MediaStreams and audio only.
327static const char kSdpStringWithoutStreamsAudioOnly[] =
328 "v=0\r\n"
329 "o=- 0 0 IN IP4 127.0.0.1\r\n"
330 "s=-\r\n"
331 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800332 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700333 "a=ice-ufrag:e5785931\r\n"
334 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
335 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
336 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700337 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700338 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800339 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700340 "a=rtpmap:103 ISAC/16000\r\n";
341
342// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
343static const char kSdpStringSendOnlyWithoutStreams[] =
344 "v=0\r\n"
345 "o=- 0 0 IN IP4 127.0.0.1\r\n"
346 "s=-\r\n"
347 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800348 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700349 "a=ice-ufrag:e5785931\r\n"
350 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
351 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
352 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700353 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700354 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700355 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800356 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700357 "a=rtpmap:103 ISAC/16000\r\n"
358 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800359 "a=ice-ufrag:e5785931\r\n"
360 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
361 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
362 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700363 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700364 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700365 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800366 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700367 "a=rtpmap:120 VP8/90000\r\n";
368
369static const char kSdpStringInit[] =
370 "v=0\r\n"
371 "o=- 0 0 IN IP4 127.0.0.1\r\n"
372 "s=-\r\n"
373 "t=0 0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700374 "a=msid-semantic: WMS\r\n";
375
376static const char kSdpStringAudio[] =
377 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800378 "a=ice-ufrag:e5785931\r\n"
379 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
380 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
381 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700382 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700383 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800384 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700385 "a=rtpmap:103 ISAC/16000\r\n";
386
387static const char kSdpStringVideo[] =
388 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800389 "a=ice-ufrag:e5785931\r\n"
390 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
391 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
392 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700393 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700394 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800395 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700396 "a=rtpmap:120 VP8/90000\r\n";
397
398static const char kSdpStringMs1Audio0[] =
399 "a=ssrc:1 cname:stream1\r\n"
400 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
401
402static const char kSdpStringMs1Video0[] =
403 "a=ssrc:2 cname:stream1\r\n"
404 "a=ssrc:2 msid:stream1 videotrack0\r\n";
405
406static const char kSdpStringMs1Audio1[] =
407 "a=ssrc:3 cname:stream1\r\n"
408 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
409
410static const char kSdpStringMs1Video1[] =
411 "a=ssrc:4 cname:stream1\r\n"
412 "a=ssrc:4 msid:stream1 videotrack1\r\n";
413
deadbeef8662f942017-01-20 21:20:51 -0800414static const char kDtlsSdesFallbackSdp[] =
415 "v=0\r\n"
416 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
417 "s=-\r\n"
418 "c=IN IP4 0.0.0.0\r\n"
419 "t=0 0\r\n"
420 "a=group:BUNDLE audio\r\n"
421 "a=msid-semantic: WMS\r\n"
422 "m=audio 1 RTP/SAVPF 0\r\n"
423 "a=sendrecv\r\n"
424 "a=rtcp-mux\r\n"
425 "a=mid:audio\r\n"
426 "a=ssrc:1 cname:stream1\r\n"
deadbeef8662f942017-01-20 21:20:51 -0800427 "a=ice-ufrag:e5785931\r\n"
428 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
429 "a=rtpmap:0 pcmu/8000\r\n"
430 "a=fingerprint:sha-1 "
431 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
432 "a=setup:actpass\r\n"
Taylor Brandstetterfd350d72018-04-03 16:29:26 -0700433 "a=crypto:0 AES_CM_128_HMAC_SHA1_80 "
deadbeef8662f942017-01-20 21:20:51 -0800434 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
435 "dummy_session_params\r\n";
436
Niels Möllerdec9f742019-06-03 15:25:20 +0200437class RtcEventLogOutputNull final : public RtcEventLogOutput {
438 public:
439 bool IsActive() const override { return true; }
440 bool Write(const std::string& output) override { return true; }
441};
442
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +0100443using ::cricket::StreamParams;
perkjd61bf802016-03-24 03:16:19 -0700444using ::testing::Exactly;
Steve Anton36da6ff2018-02-16 16:04:20 -0800445using ::testing::Values;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000446
Steve Anton36da6ff2018-02-16 16:04:20 -0800447using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
448using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
deadbeefab9b2d12015-10-14 11:33:11 -0700449
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450// Gets the first ssrc of given content type from the ContentInfo.
451bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
452 if (!content_info || !ssrc) {
453 return false;
454 }
455 const cricket::MediaContentDescription* media_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -0800456 content_info->media_description();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000457 if (!media_desc || media_desc->streams().empty()) {
458 return false;
459 }
460 *ssrc = media_desc->streams().begin()->first_ssrc();
461 return true;
462}
463
deadbeefd1a38b52016-12-10 13:15:33 -0800464// Get the ufrags out of an SDP blob. Useful for testing ICE restart
465// behavior.
466std::vector<std::string> GetUfrags(
467 const webrtc::SessionDescriptionInterface* desc) {
468 std::vector<std::string> ufrags;
469 for (const cricket::TransportInfo& info :
470 desc->description()->transport_infos()) {
471 ufrags.push_back(info.description.ice_ufrag);
472 }
473 return ufrags;
474}
475
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000476void SetSsrcToZero(std::string* sdp) {
477 const char kSdpSsrcAtribute[] = "a=ssrc:";
478 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
479 size_t ssrc_pos = 0;
480 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
Yves Gerey665174f2018-06-19 15:03:05 +0200481 std::string::npos) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000482 size_t end_ssrc = sdp->find(" ", ssrc_pos);
483 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
484 ssrc_pos = end_ssrc;
485 }
486}
487
Artem Titov880fa812021-07-30 22:30:23 +0200488// Check if `streams` contains the specified track.
deadbeefab9b2d12015-10-14 11:33:11 -0700489bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
Seth Hampson845e8782018-03-02 11:34:10 -0800490 const std::string& stream_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700491 const std::string& track_id) {
492 for (const cricket::StreamParams& params : streams) {
Seth Hampson845e8782018-03-02 11:34:10 -0800493 if (params.first_stream_id() == stream_id && params.id == track_id) {
deadbeefab9b2d12015-10-14 11:33:11 -0700494 return true;
495 }
496 }
497 return false;
498}
499
Artem Titov880fa812021-07-30 22:30:23 +0200500// Check if `senders` contains the specified sender, by id.
deadbeefab9b2d12015-10-14 11:33:11 -0700501bool ContainsSender(
502 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
503 const std::string& id) {
504 for (const auto& sender : senders) {
505 if (sender->id() == id) {
506 return true;
507 }
508 }
509 return false;
510}
511
Artem Titov880fa812021-07-30 22:30:23 +0200512// Check if `senders` contains the specified sender, by id and stream id.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700513bool ContainsSender(
514 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
515 const std::string& id,
516 const std::string& stream_id) {
517 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700518 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700519 return true;
520 }
521 }
522 return false;
523}
524
deadbeefab9b2d12015-10-14 11:33:11 -0700525// Create a collection of streams.
526// CreateStreamCollection(1) creates a collection that
527// correspond to kSdpStringWithStream1.
528// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
529rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700530 int number_of_streams,
531 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700532 rtc::scoped_refptr<StreamCollection> local_collection(
533 StreamCollection::Create());
534
535 for (int i = 0; i < number_of_streams; ++i) {
536 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
537 webrtc::MediaStream::Create(kStreams[i]));
538
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700539 for (int j = 0; j < tracks_per_stream; ++j) {
540 // Add a local audio track.
541 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
542 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
543 nullptr));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +0000544 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700545
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700546 // Add a local video track.
547 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
548 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
perkj773be362017-07-31 23:22:01 -0700549 webrtc::FakeVideoTrackSource::Create(),
550 rtc::Thread::Current()));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +0000551 stream->AddTrack(video_track);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700552 }
deadbeefab9b2d12015-10-14 11:33:11 -0700553
554 local_collection->AddStream(stream);
555 }
556 return local_collection;
557}
558
559// Check equality of StreamCollections.
560bool CompareStreamCollections(StreamCollectionInterface* s1,
561 StreamCollectionInterface* s2) {
562 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
563 return false;
564 }
565
566 for (size_t i = 0; i != s1->count(); ++i) {
Seth Hampson13b8bad2018-03-13 16:05:28 -0700567 if (s1->at(i)->id() != s2->at(i)->id()) {
deadbeefab9b2d12015-10-14 11:33:11 -0700568 return false;
569 }
570 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
571 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
572 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
573 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
574
575 if (audio_tracks1.size() != audio_tracks2.size()) {
576 return false;
577 }
578 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
579 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
580 return false;
581 }
582 }
583 if (video_tracks1.size() != video_tracks2.size()) {
584 return false;
585 }
586 for (size_t j = 0; j != video_tracks1.size(); ++j) {
587 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
588 return false;
589 }
590 }
591 }
592 return true;
593}
594
perkjd61bf802016-03-24 03:16:19 -0700595// Helper class to test Observer.
596class MockTrackObserver : public ObserverInterface {
597 public:
598 explicit MockTrackObserver(NotifierInterface* notifier)
599 : notifier_(notifier) {
600 notifier_->RegisterObserver(this);
601 }
602
603 ~MockTrackObserver() { Unregister(); }
604
605 void Unregister() {
606 if (notifier_) {
607 notifier_->UnregisterObserver(this);
608 notifier_ = nullptr;
609 }
610 }
611
Danil Chapovalov3a353122020-05-15 11:16:53 +0200612 MOCK_METHOD(void, OnChanged, (), (override));
perkjd61bf802016-03-24 03:16:19 -0700613
614 private:
615 NotifierInterface* notifier_;
616};
617
nisse528b7932017-05-08 03:21:43 -0700618// The PeerConnectionMediaConfig tests below verify that configuration and
619// constraints are propagated into the PeerConnection's MediaConfig. These
620// settings are intended for MediaChannel constructors, but that is not
621// exercised by these unittest.
zhihuang29ff8442016-07-27 11:07:25 -0700622class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
623 public:
zhihuang38ede132017-06-15 12:52:32 -0700624 static rtc::scoped_refptr<PeerConnectionFactoryForTest>
625 CreatePeerConnectionFactoryForTest() {
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100626 PeerConnectionFactoryDependencies dependencies;
627 dependencies.worker_thread = rtc::Thread::Current();
628 dependencies.network_thread = rtc::Thread::Current();
629 dependencies.signaling_thread = rtc::Thread::Current();
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200630 dependencies.task_queue_factory = CreateDefaultTaskQueueFactory();
Erik Språngceb44952020-09-22 11:36:35 +0200631 dependencies.trials = std::make_unique<FieldTrialBasedConfig>();
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200632 cricket::MediaEngineDependencies media_deps;
633 media_deps.task_queue_factory = dependencies.task_queue_factory.get();
henrika919dc2e2017-10-12 14:24:55 +0200634 // Use fake audio device module since we're only testing the interface
635 // level, and using a real one could make tests flaky when run in parallel.
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200636 media_deps.adm = FakeAudioCaptureModule::Create();
637 SetMediaEngineDefaults(&media_deps);
Erik Språngceb44952020-09-22 11:36:35 +0200638 media_deps.trials = dependencies.trials.get();
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200639 dependencies.media_engine =
640 cricket::CreateMediaEngine(std::move(media_deps));
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100641 dependencies.call_factory = webrtc::CreateCallFactory();
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200642 dependencies.event_log_factory = std::make_unique<RtcEventLogFactory>(
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200643 dependencies.task_queue_factory.get());
zhihuang38ede132017-06-15 12:52:32 -0700644
Tommi87f70902021-04-27 14:43:08 +0200645 return rtc::make_ref_counted<PeerConnectionFactoryForTest>(
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100646 std::move(dependencies));
zhihuang38ede132017-06-15 12:52:32 -0700647 }
648
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100649 using PeerConnectionFactory::PeerConnectionFactory;
kwiberg1e4e8cb2017-01-31 01:48:08 -0800650
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100651 private:
deadbeefd7850b22017-08-23 10:59:19 -0700652 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700653};
654
Steve Anton36da6ff2018-02-16 16:04:20 -0800655// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200656class PeerConnectionInterfaceBaseTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000657 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800658 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
659 : vss_(new rtc::VirtualSocketServer()),
660 main_(vss_.get()),
661 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800662#ifdef WEBRTC_ANDROID
663 webrtc::InitializeAndroidObjects();
664#endif
665 }
666
Tomas Gunnarsson2efb8a52021-04-01 16:26:57 +0200667 void SetUp() override {
deadbeefd7850b22017-08-23 10:59:19 -0700668 // Use fake audio capture module since we're only testing the interface
669 // level, and using a real one could make tests flaky when run in parallel.
670 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000671 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700672 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200673 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
674 fake_audio_capture_module_),
675 webrtc::CreateBuiltinAudioEncoderFactory(),
676 webrtc::CreateBuiltinAudioDecoderFactory(),
677 webrtc::CreateBuiltinVideoEncoderFactory(),
678 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
679 nullptr /* audio_processing */);
danilchape9021a32016-05-17 01:52:02 -0700680 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700681 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700682 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000683 }
684
Tomas Gunnarsson2efb8a52021-04-01 16:26:57 +0200685 void TearDown() override {
686 if (pc_)
687 pc_->Close();
688 }
689
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000690 void CreatePeerConnection() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200691 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692 }
693
Harald Alvestrandf9e502d2021-10-13 15:26:26 +0000694 // DTLS does not work in a loopback call, so is disabled for many
deadbeef293e9262017-01-11 12:28:30 -0800695 // tests in this file.
696 void CreatePeerConnectionWithoutDtls() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200697 RTCConfiguration config;
Harald Alvestrandf9e502d2021-10-13 15:26:26 +0000698 PeerConnectionFactoryInterface::Options options;
699 options.disable_encryption = true;
700 pc_factory_->SetOptions(options);
Niels Möllerf06f9232018-08-07 12:32:18 +0200701 CreatePeerConnection(config);
Harald Alvestrandf9e502d2021-10-13 15:26:26 +0000702 options.disable_encryption = false;
703 pc_factory_->SetOptions(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 }
705
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700706 void CreatePeerConnectionWithIceTransportsType(
707 PeerConnectionInterface::IceTransportsType type) {
708 PeerConnectionInterface::RTCConfiguration config;
709 config.type = type;
Niels Möllerf06f9232018-08-07 12:32:18 +0200710 return CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700711 }
712
713 void CreatePeerConnectionWithIceServer(const std::string& uri,
Niels Möllerdb4def92019-03-18 16:53:59 +0100714 const std::string& username,
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700715 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800716 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700718 server.uri = uri;
Niels Möllerdb4def92019-03-18 16:53:59 +0100719 server.username = username;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700720 server.password = password;
721 config.servers.push_back(server);
Niels Möllerf06f9232018-08-07 12:32:18 +0200722 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700723 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724
Niels Möllerf06f9232018-08-07 12:32:18 +0200725 void CreatePeerConnection(const RTCConfiguration& config) {
Tomas Gunnarsson2efb8a52021-04-01 16:26:57 +0200726 if (pc_) {
727 pc_->Close();
728 pc_ = nullptr;
729 }
kwibergd1fe2812016-04-27 06:47:29 -0700730 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800731 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
732 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000733
deadbeef1dcb1642017-03-29 21:08:16 -0700734 // Create certificate generator unless DTLS constraint is explicitly set to
735 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200736 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
Niels Möllerf06f9232018-08-07 12:32:18 +0200737
Harald Alvestrandf9e502d2021-10-13 15:26:26 +0000738 // These won't be used if encryption is turned off, but that's harmless.
739 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
740 cert_generator.reset(fake_certificate_generator_);
741
Steve Anton36da6ff2018-02-16 16:04:20 -0800742 RTCConfiguration modified_config = config;
743 modified_config.sdp_semantics = sdp_semantics_;
Florent Castelli72424402022-04-06 03:45:10 +0200744 PeerConnectionDependencies pc_dependencies(&observer_);
745 pc_dependencies.cert_generator = std::move(cert_generator);
746 pc_dependencies.allocator = std::move(port_allocator);
747 auto result = pc_factory_->CreatePeerConnectionOrError(
748 modified_config, std::move(pc_dependencies));
749 ASSERT_TRUE(result.ok());
750 pc_ = result.MoveValue();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000751 observer_.SetPeerConnectionInterface(pc_.get());
752 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
753 }
754
deadbeef0a6c4ca2015-10-06 11:38:28 -0700755 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800756 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700757 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700758 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800759 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800760 config.sdp_semantics = sdp_semantics_;
Florent Castelli72424402022-04-06 03:45:10 +0200761 PeerConnectionDependencies pc_dependencies(&observer_);
762 auto result = pc_factory_->CreatePeerConnectionOrError(
763 config, std::move(pc_dependencies));
764 EXPECT_FALSE(result.ok());
deadbeef0a6c4ca2015-10-06 11:38:28 -0700765 }
766
Steve Anton038834f2017-07-14 15:59:59 -0700767 void CreatePeerConnectionExpectFail(
768 PeerConnectionInterface::RTCConfiguration config) {
769 PeerConnectionInterface::IceServer server;
770 server.uri = kTurnIceServerUri;
771 server.password = kTurnPassword;
772 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800773 config.sdp_semantics = sdp_semantics_;
Florent Castelli72424402022-04-06 03:45:10 +0200774 PeerConnectionDependencies pc_dependencies(&observer_);
775 auto result = pc_factory_->CreatePeerConnectionOrError(
776 config, std::move(pc_dependencies));
777 EXPECT_FALSE(result.ok());
Steve Anton038834f2017-07-14 15:59:59 -0700778 }
779
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780 void CreatePeerConnectionWithDifferentConfigurations() {
Niels Möllerdb4def92019-03-18 16:53:59 +0100781 CreatePeerConnectionWithIceServer(kStunAddressOnly, "", "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800782 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
783 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
784 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800786 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787
deadbeef0a6c4ca2015-10-06 11:38:28 -0700788 CreatePeerConnectionExpectFail(kStunInvalidPort);
789 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
790 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791
Niels Möllerdb4def92019-03-18 16:53:59 +0100792 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnUsername,
793 kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800794 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
795 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800797 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800799 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800801 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 }
803
804 void ReleasePeerConnection() {
Niels Möllerafb246b2022-04-20 14:26:50 +0200805 pc_ = nullptr;
806 observer_.SetPeerConnectionInterface(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807 }
808
Steve Anton36da6ff2018-02-16 16:04:20 -0800809 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
810 const std::string& label) {
Niels Möllerafb246b2022-04-20 14:26:50 +0200811 return pc_factory_->CreateVideoTrack(label,
812 FakeVideoTrackSource::Create().get());
Steve Anton36da6ff2018-02-16 16:04:20 -0800813 }
814
815 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800816 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800817 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800818 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800819 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820 }
821
Steve Anton36da6ff2018-02-16 16:04:20 -0800822 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700823 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 pc_factory_->CreateLocalMediaStream(label));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +0000825 stream->AddTrack(CreateVideoTrack(label + "v0"));
Niels Möllerafb246b2022-04-20 14:26:50 +0200826 ASSERT_TRUE(pc_->AddStream(stream.get()));
Steve Anton36da6ff2018-02-16 16:04:20 -0800827 }
828
829 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
830 const std::string& label) {
831 return pc_factory_->CreateAudioTrack(label, nullptr);
832 }
833
834 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800835 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800836 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800837 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800838 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
Steve Anton36da6ff2018-02-16 16:04:20 -0800839 }
840
841 void AddAudioStream(const std::string& label) {
842 rtc::scoped_refptr<MediaStreamInterface> stream(
843 pc_factory_->CreateLocalMediaStream(label));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +0000844 stream->AddTrack(CreateAudioTrack(label + "a0"));
Niels Möllerafb246b2022-04-20 14:26:50 +0200845 ASSERT_TRUE(pc_->AddStream(stream.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846 }
847
Seth Hampson845e8782018-03-02 11:34:10 -0800848 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 const std::string& audio_track_label,
850 const std::string& video_track_label) {
851 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700852 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800853 pc_factory_->CreateLocalMediaStream(stream_id));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +0000854 stream->AddTrack(CreateAudioTrack(audio_track_label));
855 stream->AddTrack(CreateVideoTrack(video_track_label));
Niels Möllerafb246b2022-04-20 14:26:50 +0200856 ASSERT_TRUE(pc_->AddStream(stream.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 }
858
Steve Anton36da6ff2018-02-16 16:04:20 -0800859 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
860 cricket::MediaType media_type) {
861 for (auto receiver : pc_->GetReceivers()) {
862 if (receiver->media_type() == media_type) {
863 return receiver;
864 }
865 }
866 return nullptr;
867 }
868
kwibergd1fe2812016-04-27 06:47:29 -0700869 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200870 const RTCOfferAnswerOptions* options,
871 bool offer) {
Tommi87f70902021-04-27 14:43:08 +0200872 auto observer =
873 rtc::make_ref_counted<MockCreateSessionDescriptionObserver>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 if (offer) {
Niels Möllerafb246b2022-04-20 14:26:50 +0200875 pc_->CreateOffer(observer.get(),
876 options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877 } else {
Niels Möllerafb246b2022-04-20 14:26:50 +0200878 pc_->CreateAnswer(observer.get(),
879 options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880 }
881 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700882 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 return observer->result();
884 }
885
kwibergd1fe2812016-04-27 06:47:29 -0700886 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200887 const RTCOfferAnswerOptions* options) {
888 return DoCreateOfferAnswer(desc, options, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 }
890
kwibergd1fe2812016-04-27 06:47:29 -0700891 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200892 const RTCOfferAnswerOptions* options) {
893 return DoCreateOfferAnswer(desc, options, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 }
895
Steve Antondb45ca82017-09-11 18:27:34 -0700896 bool DoSetSessionDescription(
897 std::unique_ptr<SessionDescriptionInterface> desc,
898 bool local) {
Tommi87f70902021-04-27 14:43:08 +0200899 auto observer = rtc::make_ref_counted<MockSetSessionDescriptionObserver>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900 if (local) {
Niels Möllerafb246b2022-04-20 14:26:50 +0200901 pc_->SetLocalDescription(observer.get(), desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 } else {
Niels Möllerafb246b2022-04-20 14:26:50 +0200903 pc_->SetRemoteDescription(observer.get(), desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904 }
zhihuang29ff8442016-07-27 11:07:25 -0700905 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
906 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
907 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908 return observer->result();
909 }
910
Steve Antondb45ca82017-09-11 18:27:34 -0700911 bool DoSetLocalDescription(
912 std::unique_ptr<SessionDescriptionInterface> desc) {
913 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000914 }
915
Steve Antondb45ca82017-09-11 18:27:34 -0700916 bool DoSetRemoteDescription(
917 std::unique_ptr<SessionDescriptionInterface> desc) {
918 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 }
920
921 // Calls PeerConnection::GetStats and check the return value.
922 // It does not verify the values in the StatReports since a RTCP packet might
923 // be required.
924 bool DoGetStats(MediaStreamTrackInterface* track) {
Tommi87f70902021-04-27 14:43:08 +0200925 auto observer = rtc::make_ref_counted<MockStatsObserver>();
Niels Möllerafb246b2022-04-20 14:26:50 +0200926 if (!pc_->GetStats(observer.get(), track,
Yves Gerey665174f2018-06-19 15:03:05 +0200927 PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928 return false;
929 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
930 return observer->called();
931 }
932
Harald Alvestrand89061872018-01-02 14:08:34 +0100933 // Call the standards-compliant GetStats function.
934 bool DoGetRTCStats() {
Tommi87f70902021-04-27 14:43:08 +0200935 auto callback =
936 rtc::make_ref_counted<webrtc::MockRTCStatsCollectorCallback>();
Niels Möllerafb246b2022-04-20 14:26:50 +0200937 pc_->GetStats(callback.get());
Harald Alvestrand89061872018-01-02 14:08:34 +0100938 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
939 return callback->called();
940 }
941
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800943 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 // Create a local stream with audio&video tracks.
Florent Castelli15a38de2022-04-06 00:38:21 +0200945 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Seth Hampson845e8782018-03-02 11:34:10 -0800946 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800947 } else {
948 // Unified Plan does not support AddStream, so just add an audio and video
949 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800950 AddAudioTrack(kAudioTracks[0], {kStreamId1});
951 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800952 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 CreateOfferReceiveAnswer();
954 }
955
956 // Verify that RTP Header extensions has been negotiated for audio and video.
957 void VerifyRemoteRtpHeaderExtensions() {
958 const cricket::MediaContentDescription* desc =
959 cricket::GetFirstAudioContentDescription(
960 pc_->remote_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +0200961 ASSERT_TRUE(desc != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
963
964 desc = cricket::GetFirstVideoContentDescription(
965 pc_->remote_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +0200966 ASSERT_TRUE(desc != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
968 }
969
970 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700971 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700972 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000973 std::string sdp;
974 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700975 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800976 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700977 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000978 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
979 }
980
deadbeefab9b2d12015-10-14 11:33:11 -0700981 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -0700982 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800983 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700984 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -0700985 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
986 }
987
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000988 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700989 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -0700990 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991
992 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
993 // audio codec change, even if the parameter has nothing to do with
994 // receiving. Not all parameters are serialized to SDP.
995 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
996 // the SessionDescription, it is necessary to do that here to in order to
997 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
998 // https://code.google.com/p/webrtc/issues/detail?id=1356
999 std::string sdp;
1000 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001001 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001002 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001003 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001004 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1005 }
1006
1007 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001008 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001009 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001010
1011 std::string sdp;
1012 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001013 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001014 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001015 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001016 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1017 }
1018
1019 void CreateOfferReceiveAnswer() {
1020 CreateOfferAsLocalDescription();
1021 std::string sdp;
1022 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1023 CreateAnswerAsRemoteDescription(sdp);
1024 }
1025
1026 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001027 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001028 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001029 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1030 // audio codec change, even if the parameter has nothing to do with
1031 // receiving. Not all parameters are serialized to SDP.
1032 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1033 // the SessionDescription, it is necessary to do that here to in order to
1034 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1035 // https://code.google.com/p/webrtc/issues/detail?id=1356
1036 std::string sdp;
1037 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001038 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001039 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001040
Steve Antondb45ca82017-09-11 18:27:34 -07001041 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001042 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001043 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001044 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001045 }
1046
deadbeefab9b2d12015-10-14 11:33:11 -07001047 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001048 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001049 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001050 ASSERT_TRUE(answer);
1051 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001052 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1053 }
1054
deadbeefab9b2d12015-10-14 11:33:11 -07001055 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001056 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001057 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001058 ASSERT_TRUE(pr_answer);
1059 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001060 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001061 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001062 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001063 ASSERT_TRUE(answer);
1064 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001065 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1066 }
1067
Seth Hampson845e8782018-03-02 11:34:10 -08001068 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001069 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001070 // called with the given stream id and expected number of tracks.
1071 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001072 int expected_num_tracks) {
1073 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001074 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001075 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001076 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001077 }
1078
1079 // Creates an offer and applies it as a local session description.
1080 // Creates an answer with the same SDP an the offer but removes all lines
1081 // that start with a:ssrc"
1082 void CreateOfferReceiveAnswerWithoutSsrc() {
1083 CreateOfferAsLocalDescription();
1084 std::string sdp;
1085 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1086 SetSsrcToZero(&sdp);
1087 CreateAnswerAsRemoteDescription(sdp);
1088 }
1089
deadbeefab9b2d12015-10-14 11:33:11 -07001090 // This function creates a MediaStream with label kStreams[0] and
Artem Titov880fa812021-07-30 22:30:23 +02001091 // `number_of_audio_tracks` and `number_of_video_tracks` tracks and the
deadbeefab9b2d12015-10-14 11:33:11 -07001092 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001093 // is returned and the MediaStream is stored in
Artem Titov880fa812021-07-30 22:30:23 +02001094 // `reference_collection_`
kwibergd1fe2812016-04-27 06:47:29 -07001095 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001096 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1097 size_t number_of_video_tracks) {
1098 EXPECT_LE(number_of_audio_tracks, 2u);
1099 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001100
1101 reference_collection_ = StreamCollection::Create();
1102 std::string sdp_ms1 = std::string(kSdpStringInit);
1103
Seth Hampson845e8782018-03-02 11:34:10 -08001104 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001105
1106 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001107 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001108 reference_collection_->AddStream(stream);
1109
1110 if (number_of_audio_tracks > 0) {
1111 sdp_ms1 += std::string(kSdpStringAudio);
1112 sdp_ms1 += std::string(kSdpStringMs1Audio0);
Niels Möllerafb246b2022-04-20 14:26:50 +02001113 AddAudioTrack(kAudioTracks[0], stream.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001114 }
1115 if (number_of_audio_tracks > 1) {
1116 sdp_ms1 += kSdpStringMs1Audio1;
Niels Möllerafb246b2022-04-20 14:26:50 +02001117 AddAudioTrack(kAudioTracks[1], stream.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001118 }
1119
1120 if (number_of_video_tracks > 0) {
1121 sdp_ms1 += std::string(kSdpStringVideo);
1122 sdp_ms1 += std::string(kSdpStringMs1Video0);
Niels Möllerafb246b2022-04-20 14:26:50 +02001123 AddVideoTrack(kVideoTracks[0], stream.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001124 }
1125 if (number_of_video_tracks > 1) {
1126 sdp_ms1 += kSdpStringMs1Video1;
Niels Möllerafb246b2022-04-20 14:26:50 +02001127 AddVideoTrack(kVideoTracks[1], stream.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001128 }
1129
kwibergd1fe2812016-04-27 06:47:29 -07001130 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001131 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001132 }
1133
1134 void AddAudioTrack(const std::string& track_id,
1135 MediaStreamInterface* stream) {
1136 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1137 webrtc::AudioTrack::Create(track_id, nullptr));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00001138 ASSERT_TRUE(stream->AddTrack(audio_track));
deadbeefab9b2d12015-10-14 11:33:11 -07001139 }
1140
1141 void AddVideoTrack(const std::string& track_id,
1142 MediaStreamInterface* stream) {
1143 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001144 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001145 webrtc::FakeVideoTrackSource::Create(),
1146 rtc::Thread::Current()));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00001147 ASSERT_TRUE(stream->AddTrack(video_track));
deadbeefab9b2d12015-10-14 11:33:11 -07001148 }
1149
Steve Anton36da6ff2018-02-16 16:04:20 -08001150 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001151 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001152 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001153 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001154 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1155 return offer;
1156 }
1157
Steve Anton36da6ff2018-02-16 16:04:20 -08001158 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1159 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001160 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001161 std::unique_ptr<SessionDescriptionInterface> offer;
1162 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1163 return offer;
1164 }
1165
1166 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1167 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1168 std::unique_ptr<SessionDescriptionInterface> answer;
1169 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1170 return answer;
1171 }
1172
kwibergfd8be342016-05-14 19:44:11 -07001173 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001174 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001175 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001176 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001177 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1178 return answer;
1179 }
1180
1181 const std::string& GetFirstAudioStreamCname(
1182 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001183 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001184 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001185 return audio_desc->streams()[0].cname;
1186 }
1187
zhihuang1c378ed2017-08-17 14:10:50 -07001188 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1189 const RTCOfferAnswerOptions& offer_answer_options) {
1190 RTC_DCHECK(pc_);
Tommi87f70902021-04-27 14:43:08 +02001191 auto observer =
1192 rtc::make_ref_counted<MockCreateSessionDescriptionObserver>();
Niels Möllerafb246b2022-04-20 14:26:50 +02001193 pc_->CreateOffer(observer.get(), offer_answer_options);
zhihuang1c378ed2017-08-17 14:10:50 -07001194 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1195 return observer->MoveDescription();
1196 }
1197
1198 void CreateOfferWithOptionsAsRemoteDescription(
1199 std::unique_ptr<SessionDescriptionInterface>* desc,
1200 const RTCOfferAnswerOptions& offer_answer_options) {
1201 *desc = CreateOfferWithOptions(offer_answer_options);
1202 ASSERT_TRUE(desc != nullptr);
1203 std::string sdp;
1204 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001205 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001206 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001207 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001208 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1209 }
1210
1211 void CreateOfferWithOptionsAsLocalDescription(
1212 std::unique_ptr<SessionDescriptionInterface>* desc,
1213 const RTCOfferAnswerOptions& offer_answer_options) {
1214 *desc = CreateOfferWithOptions(offer_answer_options);
1215 ASSERT_TRUE(desc != nullptr);
1216 std::string sdp;
1217 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001218 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001219 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001220
Steve Antondb45ca82017-09-11 18:27:34 -07001221 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001222 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1223 }
1224
1225 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001226 RTC_DCHECK(content);
1227 RTC_DCHECK(content->media_description());
1228 for (const cricket::AudioCodec& codec :
1229 content->media_description()->as_audio()->codecs()) {
1230 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001231 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001232 }
zhihuang1c378ed2017-08-17 14:10:50 -07001233 }
1234 return false;
1235 }
1236
Steve Anton36da6ff2018-02-16 16:04:20 -08001237 const char* GetSdpStringWithStream1() const {
Florent Castelli15a38de2022-04-06 00:38:21 +02001238 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Steve Anton36da6ff2018-02-16 16:04:20 -08001239 return kSdpStringWithStream1PlanB;
1240 } else {
1241 return kSdpStringWithStream1UnifiedPlan;
1242 }
1243 }
1244
1245 const char* GetSdpStringWithStream1And2() const {
Florent Castelli15a38de2022-04-06 00:38:21 +02001246 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Steve Anton36da6ff2018-02-16 16:04:20 -08001247 return kSdpStringWithStream1And2PlanB;
1248 } else {
1249 return kSdpStringWithStream1And2UnifiedPlan;
1250 }
1251 }
1252
deadbeef9a6f4d42017-05-15 19:43:33 -07001253 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1254 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001255 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001256 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001257 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001258 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1259 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1260 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001261 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001262 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001263 const SdpSemantics sdp_semantics_;
1264};
1265
1266class PeerConnectionInterfaceTest
1267 : public PeerConnectionInterfaceBaseTest,
1268 public ::testing::WithParamInterface<SdpSemantics> {
1269 protected:
1270 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1271};
1272
1273class PeerConnectionInterfaceTestPlanB
1274 : public PeerConnectionInterfaceBaseTest {
1275 protected:
1276 PeerConnectionInterfaceTestPlanB()
Florent Castelli15a38de2022-04-06 00:38:21 +02001277 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB_DEPRECATED) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001278};
1279
zhihuang8f65cdf2016-05-06 18:40:30 -07001280// Generate different CNAMEs when PeerConnections are created.
1281// The CNAMEs are expected to be generated randomly. It is possible
1282// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001283TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001284 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001285 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001286 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001287 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001288 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1289 GetFirstAudioStreamCname(offer2.get()));
1290}
1291
Steve Anton36da6ff2018-02-16 16:04:20 -08001292TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001293 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001294 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001295 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001296 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001297 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1298 GetFirstAudioStreamCname(answer2.get()));
1299}
1300
Steve Anton36da6ff2018-02-16 16:04:20 -08001301TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001302 CreatePeerConnectionWithDifferentConfigurations) {
1303 CreatePeerConnectionWithDifferentConfigurations();
1304}
1305
Steve Anton36da6ff2018-02-16 16:04:20 -08001306TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001307 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1308 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1309 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1310 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1311 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1312 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1313 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1314 port_allocator_->candidate_filter());
1315 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1316 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1317}
1318
1319// Test that when a PeerConnection is created with a nonzero candidate pool
1320// size, the pooled PortAllocatorSession is created with all the attributes
1321// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001322TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001323 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01001324 config.sdp_semantics = sdp_semantics_;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001325 PeerConnectionInterface::IceServer server;
1326 server.uri = kStunAddressOnly;
1327 config.servers.push_back(server);
1328 config.type = PeerConnectionInterface::kRelay;
1329 config.disable_ipv6 = true;
1330 config.tcp_candidate_policy =
1331 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001332 config.candidate_network_policy =
1333 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001334 config.ice_candidate_pool_size = 1;
Niels Möllerf06f9232018-08-07 12:32:18 +02001335 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001336
1337 const cricket::FakePortAllocatorSession* session =
1338 static_cast<const cricket::FakePortAllocatorSession*>(
1339 port_allocator_->GetPooledSession());
1340 ASSERT_NE(nullptr, session);
1341 EXPECT_EQ(1UL, session->stun_servers().size());
1342 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1343 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001344 EXPECT_LT(0U,
1345 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001346}
1347
deadbeefd21eab32017-07-26 16:50:11 -07001348// Test that network-related RTCConfiguration members are applied to the
1349// PortAllocator when CreatePeerConnection is called. Specifically:
1350// - disable_ipv6_on_wifi
1351// - max_ipv6_networks
1352// - tcp_candidate_policy
1353// - candidate_network_policy
1354// - prune_turn_ports
1355//
1356// Note that the candidate filter (RTCConfiguration::type) is already tested
1357// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001358TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001359 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1360 // Create fake port allocator.
1361 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1362 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1363 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1364
1365 // Create RTCConfiguration with some network-related fields relevant to
1366 // PortAllocator populated.
1367 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01001368 config.sdp_semantics = sdp_semantics_;
deadbeefd21eab32017-07-26 16:50:11 -07001369 config.disable_ipv6_on_wifi = true;
1370 config.max_ipv6_networks = 10;
1371 config.tcp_candidate_policy =
1372 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1373 config.candidate_network_policy =
1374 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1375 config.prune_turn_ports = true;
1376
1377 // Create the PC factory and PC with the above config.
1378 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1379 webrtc::CreatePeerConnectionFactory(
1380 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001381 rtc::Thread::Current(), fake_audio_capture_module_,
1382 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +02001383 webrtc::CreateBuiltinAudioDecoderFactory(),
1384 webrtc::CreateBuiltinVideoEncoderFactory(),
1385 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1386 nullptr /* audio_processing */));
Florent Castelli72424402022-04-06 03:45:10 +02001387 PeerConnectionDependencies pc_dependencies(&observer_);
1388 pc_dependencies.allocator = std::move(port_allocator);
1389 auto result = pc_factory_->CreatePeerConnectionOrError(
1390 config, std::move(pc_dependencies));
1391 EXPECT_TRUE(result.ok());
Niels Möllerafb246b2022-04-20 14:26:50 +02001392 observer_.SetPeerConnectionInterface(result.value().get());
deadbeefd21eab32017-07-26 16:50:11 -07001393
1394 // Now validate that the config fields set above were applied to the
1395 // PortAllocator, as flags or otherwise.
1396 EXPECT_FALSE(raw_port_allocator->flags() &
1397 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1398 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1399 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1400 EXPECT_TRUE(raw_port_allocator->flags() &
1401 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Honghai Zhangf8998cf2019-10-14 11:27:50 -07001402 EXPECT_EQ(webrtc::PRUNE_BASED_ON_PRIORITY,
1403 raw_port_allocator->turn_port_prune_policy());
deadbeefd21eab32017-07-26 16:50:11 -07001404}
1405
deadbeef46c73892016-11-16 19:42:04 -08001406// Check that GetConfiguration returns the configuration the PeerConnection was
1407// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001408TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001409 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01001410 config.sdp_semantics = sdp_semantics_;
deadbeef46c73892016-11-16 19:42:04 -08001411 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02001412 CreatePeerConnection(config);
deadbeef46c73892016-11-16 19:42:04 -08001413
1414 PeerConnectionInterface::RTCConfiguration returned_config =
1415 pc_->GetConfiguration();
1416 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1417}
1418
1419// Check that GetConfiguration returns the last configuration passed into
1420// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001421TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001422 PeerConnectionInterface::RTCConfiguration starting_config;
Henrik Boström62995db2022-01-03 09:58:10 +01001423 starting_config.sdp_semantics = sdp_semantics_;
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001424 starting_config.bundle_policy =
1425 webrtc::PeerConnection::kBundlePolicyMaxBundle;
1426 CreatePeerConnection(starting_config);
deadbeef46c73892016-11-16 19:42:04 -08001427
Steve Anton36da6ff2018-02-16 16:04:20 -08001428 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001429 config.type = PeerConnectionInterface::kRelay;
Niels Möller2579f0c2019-08-19 09:58:17 +02001430 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef46c73892016-11-16 19:42:04 -08001431
1432 PeerConnectionInterface::RTCConfiguration returned_config =
1433 pc_->GetConfiguration();
1434 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1435}
1436
Steve Antonc79268f2018-04-24 09:54:10 -07001437TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1438 CreatePeerConnection();
1439
1440 pc_->Close();
1441
1442 EXPECT_FALSE(
Niels Möller2579f0c2019-08-19 09:58:17 +02001443 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()).ok());
Steve Antonc79268f2018-04-24 09:54:10 -07001444}
1445
Steve Anton36da6ff2018-02-16 16:04:20 -08001446TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001447 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001448 AddVideoStream(kStreamId1);
1449 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001450 ASSERT_EQ(2u, pc_->local_streams()->count());
1451
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001452 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001453 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001454 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001455 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möllerafb246b2022-04-20 14:26:50 +02001456 pc_factory_->CreateAudioTrack(
1457 kStreamId3, static_cast<AudioSourceInterface*>(nullptr)));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00001458 stream->AddTrack(audio_track);
Niels Möllerafb246b2022-04-20 14:26:50 +02001459 EXPECT_TRUE(pc_->AddStream(stream.get()));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001460 EXPECT_EQ(3u, pc_->local_streams()->count());
1461
1462 // Remove the third stream.
1463 pc_->RemoveStream(pc_->local_streams()->at(2));
1464 EXPECT_EQ(2u, pc_->local_streams()->count());
1465
1466 // Remove the second stream.
1467 pc_->RemoveStream(pc_->local_streams()->at(1));
1468 EXPECT_EQ(1u, pc_->local_streams()->count());
1469
1470 // Remove the first stream.
1471 pc_->RemoveStream(pc_->local_streams()->at(0));
1472 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473}
1474
deadbeefab9b2d12015-10-14 11:33:11 -07001475// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001476// Don't run under Unified Plan since the stream API is not available.
1477TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001478 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001479 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001480 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001481 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001482
deadbeefab9b2d12015-10-14 11:33:11 -07001483 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001484 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001485 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001486
deadbeefab9b2d12015-10-14 11:33:11 -07001487 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001488 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001489 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001490
1491 // Add another stream and ensure the offer includes both the old and new
1492 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001493 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001494 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001495
Steve Antonb1c1de12017-12-21 15:14:30 -08001496 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001497 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1498 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001499
Steve Antonb1c1de12017-12-21 15:14:30 -08001500 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001501 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1502 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001503}
1504
Steve Anton36da6ff2018-02-16 16:04:20 -08001505// Don't run under Unified Plan since the stream API is not available.
1506TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001507 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001508 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001509 ASSERT_EQ(1u, pc_->local_streams()->count());
1510 pc_->RemoveStream(pc_->local_streams()->at(0));
1511 EXPECT_EQ(0u, pc_->local_streams()->count());
1512}
1513
deadbeefe1f9d832016-01-14 15:35:42 -08001514// Test for AddTrack and RemoveTrack methods.
1515// Tests that the created offer includes tracks we added,
1516// and that the RtpSenders are created correctly.
1517// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001518// Only tested with Plan B since Unified Plan is covered in more detail by tests
1519// in peerconnection_jsep_unittests.cc
1520TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001521 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001522 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001523 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001524 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001525 CreateVideoTrack("video_track"));
Seth Hampson845e8782018-03-02 11:34:10 -08001526 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1527 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001528 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001529 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001530 EXPECT_EQ("audio_track", audio_sender->id());
1531 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001532 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001533 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001534 EXPECT_EQ("video_track", video_sender->id());
1535 EXPECT_EQ(video_track, video_sender->track());
1536
1537 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001538 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001539 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001540
1541 const cricket::ContentInfo* audio_content =
1542 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001543 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001544 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001545
1546 const cricket::ContentInfo* video_content =
1547 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001548 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001549 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001550
Steve Antondb45ca82017-09-11 18:27:34 -07001551 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001552
1553 // Now try removing the tracks.
Harald Alvestrand93dd7632022-01-19 12:28:45 +00001554 EXPECT_TRUE(pc_->RemoveTrackOrError(audio_sender).ok());
1555 EXPECT_TRUE(pc_->RemoveTrackOrError(video_sender).ok());
deadbeefe1f9d832016-01-14 15:35:42 -08001556
1557 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001558 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001559
1560 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001561 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001562 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001563
1564 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001565 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001566 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001567
Steve Antondb45ca82017-09-11 18:27:34 -07001568 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001569
1570 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1571 // should return false.
Harald Alvestrand93dd7632022-01-19 12:28:45 +00001572 EXPECT_FALSE(pc_->RemoveTrackOrError(audio_sender).ok());
1573 EXPECT_FALSE(pc_->RemoveTrackOrError(video_sender).ok());
deadbeefe1f9d832016-01-14 15:35:42 -08001574}
1575
1576// Test creating senders without a stream specified,
1577// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001578TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001579 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001580 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001581 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001582 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001583 CreateVideoTrack("video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001584 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001585 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001586 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001587 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001588 EXPECT_EQ("audio_track", audio_sender->id());
1589 EXPECT_EQ(audio_track, audio_sender->track());
1590 EXPECT_EQ("video_track", video_sender->id());
1591 EXPECT_EQ(video_track, video_sender->track());
Florent Castelli15a38de2022-04-06 00:38:21 +02001592 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001593 // If the ID is truly a random GUID, it should be infinitely unlikely they
1594 // will be the same.
1595 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1596 } else {
1597 // We allows creating tracks without stream ids under Unified Plan
1598 // semantics.
1599 EXPECT_EQ(0u, video_sender->stream_ids().size());
1600 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1601 }
deadbeefe1f9d832016-01-14 15:35:42 -08001602}
1603
Harald Alvestrand89061872018-01-02 14:08:34 +01001604// Test that we can call GetStats() after AddTrack but before connecting
1605// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001606TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001607 CreatePeerConnectionWithoutDtls();
1608 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001609 CreateAudioTrack("audio_track"));
Harald Alvestrand89061872018-01-02 14:08:34 +01001610 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001611 CreateVideoTrack("video_track"));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001612 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1613 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001614 EXPECT_TRUE(DoGetStats(nullptr));
1615}
1616
Steve Anton36da6ff2018-02-16 16:04:20 -08001617TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001618 CreatePeerConnectionWithoutDtls();
1619 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001620 CreateAudioTrack("audio_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001621 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001622 CreateVideoTrack("video_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001623 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001624 ASSERT_TRUE(audio_sender.ok());
1625 auto* audio_sender_proxy =
1626 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1627 audio_sender.value().get());
1628 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1629
Harald Alvestrandc72af932018-01-11 17:18:19 +01001630 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001631 ASSERT_TRUE(video_sender.ok());
1632 auto* video_sender_proxy =
1633 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1634 video_sender.value().get());
1635 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001636}
1637
Steve Anton36da6ff2018-02-16 16:04:20 -08001638// Don't run under Unified Plan since the stream API is not available.
1639TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001640 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001641 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001642 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001643 ASSERT_EQ(1u, senders.size());
1644 auto* sender_proxy =
1645 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1646 senders[0].get());
1647 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001648}
1649
Steve Anton36da6ff2018-02-16 16:04:20 -08001650TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001651 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001652 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001653 VerifyRemoteRtpHeaderExtensions();
1654}
1655
Steve Anton36da6ff2018-02-16 16:04:20 -08001656TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001657 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001658 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659 CreateOfferAsLocalDescription();
1660 std::string offer;
1661 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1662 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001663 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001664}
1665
Steve Anton36da6ff2018-02-16 16:04:20 -08001666TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001667 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001668 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001669
1670 CreateOfferAsRemoteDescription();
1671 CreateAnswerAsLocalDescription();
1672
Seth Hampson845e8782018-03-02 11:34:10 -08001673 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001674}
1675
Steve Anton36da6ff2018-02-16 16:04:20 -08001676TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001677 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001678 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001679
1680 CreateOfferAsRemoteDescription();
1681 CreatePrAnswerAsLocalDescription();
1682 CreateAnswerAsLocalDescription();
1683
Seth Hampson845e8782018-03-02 11:34:10 -08001684 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001685}
1686
Steve Anton36da6ff2018-02-16 16:04:20 -08001687// Don't run under Unified Plan since the stream API is not available.
1688TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 InitiateCall();
1690 ASSERT_EQ(1u, pc_->remote_streams()->count());
1691 pc_->RemoveStream(pc_->local_streams()->at(0));
1692 CreateOfferReceiveAnswer();
1693 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001694 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001695 CreateOfferReceiveAnswer();
1696}
1697
1698// Tests that after negotiating an audio only call, the respondent can perform a
1699// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001700TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001701 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001702 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703 CreateOfferAsRemoteDescription();
1704 CreateAnswerAsLocalDescription();
1705
1706 ASSERT_EQ(1u, pc_->remote_streams()->count());
1707 pc_->RemoveStream(pc_->local_streams()->at(0));
1708 CreateOfferReceiveAnswer();
1709 EXPECT_EQ(0u, pc_->remote_streams()->count());
1710}
1711
1712// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001713TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001714 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001715
Steve Antonf1c6db12017-10-13 11:13:35 -07001716 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001718 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001719 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001720 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001721 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722
1723 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001724 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001725 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001726 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001727
Steve Antonf1c6db12017-10-13 11:13:35 -07001728 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001729 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001730
Steve Antonf1c6db12017-10-13 11:13:35 -07001731 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001732}
1733
deadbeefab9b2d12015-10-14 11:33:11 -07001734// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735// not unique.
Steve Anton07563732018-06-26 11:13:50 -07001736TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001737 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001738 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001739 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001740 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001741 EXPECT_TRUE(offer);
1742 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743
1744 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001745 AddAudioTrack("track_label", {kStreamId1});
1746 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001747
1748 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001749 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750
1751 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001752 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001753 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754}
1755
1756// Test that we will get different SSRCs for each tracks in the offer and answer
1757// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001758TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001759 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001761 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1762 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763
1764 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001765 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001766 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767 int audio_ssrc = 0;
1768 int video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001769 EXPECT_TRUE(
1770 GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc));
1771 EXPECT_TRUE(
1772 GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773 EXPECT_NE(audio_ssrc, video_ssrc);
1774
1775 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001776 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001777 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001778 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001779 audio_ssrc = 0;
1780 video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001781 EXPECT_TRUE(
1782 GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc));
1783 EXPECT_TRUE(
1784 GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785 EXPECT_NE(audio_ssrc, video_ssrc);
1786}
1787
deadbeefeb459812015-12-15 19:24:43 -08001788// Test that it's possible to call AddTrack on a MediaStream after adding
1789// the stream to a PeerConnection.
1790// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001791// Don't run under Unified Plan since the stream API is not available.
1792TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001793 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001794 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001795 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001796 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1797
1798 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001799 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001800 CreateVideoTrack("video_label"));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00001801 stream->AddTrack(video_track);
deadbeefeb459812015-12-15 19:24:43 -08001802
kwibergd1fe2812016-04-27 06:47:29 -07001803 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001804 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001805
1806 const cricket::MediaContentDescription* video_desc =
1807 cricket::GetFirstVideoContentDescription(offer->description());
1808 EXPECT_TRUE(video_desc != nullptr);
1809}
1810
1811// Test that it's possible to call RemoveTrack on a MediaStream after adding
1812// the stream to a PeerConnection.
1813// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001814// Don't run under Unified Plan since the stream API is not available.
1815TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001816 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001817 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001818 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001819 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1820
1821 // Remove the video track.
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00001822 stream->RemoveTrack(stream->GetVideoTracks()[0]);
deadbeefeb459812015-12-15 19:24:43 -08001823
kwibergd1fe2812016-04-27 06:47:29 -07001824 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001825 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001826
1827 const cricket::MediaContentDescription* video_desc =
1828 cricket::GetFirstVideoContentDescription(offer->description());
1829 EXPECT_TRUE(video_desc == nullptr);
1830}
1831
deadbeefbd7d8f72015-12-18 16:58:44 -08001832// Test creating a sender with a stream ID, and ensure the ID is populated
1833// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001834// Don't run under Unified Plan since the stream API is not available.
1835TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001836 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001837 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001838
kwibergd1fe2812016-04-27 06:47:29 -07001839 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001840 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001841
1842 const cricket::MediaContentDescription* video_desc =
1843 cricket::GetFirstVideoContentDescription(offer->description());
1844 ASSERT_TRUE(video_desc != nullptr);
1845 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001846 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001847}
1848
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001849// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001850TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001851 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001852 ASSERT_LT(0u, pc_->GetSenders().size());
1853 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001854 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001855 pc_->GetReceivers()[0]->track();
Niels Möllerafb246b2022-04-20 14:26:50 +02001856 EXPECT_TRUE(DoGetStats(remote_audio.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857
1858 // Remove the stream. Since we are sending to our selves the local
1859 // and the remote stream is the same.
Harald Alvestrand93dd7632022-01-19 12:28:45 +00001860 pc_->RemoveTrackOrError(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001861 // Do a re-negotiation.
1862 CreateOfferReceiveAnswer();
1863
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001864 // Test that we still can get statistics for the old track. Even if it is not
1865 // sent any longer.
Niels Möllerafb246b2022-04-20 14:26:50 +02001866 EXPECT_TRUE(DoGetStats(remote_audio.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001867}
1868
1869// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001870TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001871 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001872 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1873 ASSERT_TRUE(video_receiver);
Niels Möllerafb246b2022-04-20 14:26:50 +02001874 EXPECT_TRUE(DoGetStats(video_receiver->track().get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001875}
1876
1877// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001878TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001879 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001880 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
Niels Möllerafb246b2022-04-20 14:26:50 +02001881 pc_factory_->CreateAudioTrack("unknown track", nullptr));
1882 EXPECT_FALSE(DoGetStats(unknown_audio_track.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001883}
1884
Steve Anton36da6ff2018-02-16 16:04:20 -08001885TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001886 CreatePeerConnectionWithoutDtls();
1887 EXPECT_TRUE(DoGetRTCStats());
1888 // Clearing stats cache is needed now, but should be temporary.
1889 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1890 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001891 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1892 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001893 EXPECT_TRUE(DoGetRTCStats());
1894 pc_->ClearStatsCache();
1895 CreateOfferReceiveAnswer();
1896 EXPECT_TRUE(DoGetRTCStats());
1897}
1898
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001899// This tests that a SCTP data channel is returned using different
1900// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08001901TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001902 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02001903 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904
1905 webrtc::DataChannelInit config;
Florent Castelli72424402022-04-06 03:45:10 +02001906 auto channel = pc_->CreateDataChannelOrError("1", &config);
1907 EXPECT_TRUE(channel.ok());
1908 EXPECT_TRUE(channel.value()->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001909 EXPECT_TRUE(observer_.renegotiation_needed_);
1910 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001911
1912 config.ordered = false;
Florent Castelli72424402022-04-06 03:45:10 +02001913 channel = pc_->CreateDataChannelOrError("2", &config);
1914 EXPECT_TRUE(channel.ok());
1915 EXPECT_TRUE(channel.value()->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001916 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001917
1918 config.ordered = true;
1919 config.maxRetransmits = 0;
Florent Castelli72424402022-04-06 03:45:10 +02001920 channel = pc_->CreateDataChannelOrError("3", &config);
1921 EXPECT_TRUE(channel.ok());
1922 EXPECT_FALSE(channel.value()->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001923 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001924
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02001925 config.maxRetransmits = absl::nullopt;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001926 config.maxRetransmitTime = 0;
Florent Castelli72424402022-04-06 03:45:10 +02001927 channel = pc_->CreateDataChannelOrError("4", &config);
1928 EXPECT_TRUE(channel.ok());
1929 EXPECT_FALSE(channel.value()->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001930 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001931}
1932
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02001933// For backwards compatibility, we want people who "unset" maxRetransmits
1934// and maxRetransmitTime by setting them to -1 to get what they want.
1935TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannelWithMinusOne) {
1936 RTCConfiguration rtc_config;
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02001937 CreatePeerConnection(rtc_config);
1938
1939 webrtc::DataChannelInit config;
1940 config.maxRetransmitTime = -1;
1941 config.maxRetransmits = -1;
Florent Castelli72424402022-04-06 03:45:10 +02001942 auto channel = pc_->CreateDataChannelOrError("1", &config);
1943 EXPECT_TRUE(channel.ok());
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02001944}
1945
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001946// This tests that no data channel is returned if both maxRetransmits and
1947// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08001948TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001949 CreateSctpDataChannelShouldFailForInvalidConfig) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001950 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02001951 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001952
1953 std::string label = "test";
1954 webrtc::DataChannelInit config;
1955 config.maxRetransmits = 0;
1956 config.maxRetransmitTime = 0;
1957
Florent Castelli72424402022-04-06 03:45:10 +02001958 auto channel = pc_->CreateDataChannelOrError(label, &config);
1959 EXPECT_FALSE(channel.ok());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001960}
1961
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001962// The test verifies that creating a SCTP data channel with an id already in use
1963// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001964TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001965 CreateSctpDataChannelWithInvalidIdShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001966 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02001967 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001968
1969 webrtc::DataChannelInit config;
1970
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001971 config.id = 1;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02001972 config.negotiated = true;
Florent Castelli72424402022-04-06 03:45:10 +02001973 auto channel = pc_->CreateDataChannelOrError("1", &config);
1974 EXPECT_TRUE(channel.ok());
1975 EXPECT_EQ(1, channel.value()->id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001976
Florent Castelli72424402022-04-06 03:45:10 +02001977 channel = pc_->CreateDataChannelOrError("x", &config);
1978 EXPECT_FALSE(channel.ok());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001979
1980 config.id = cricket::kMaxSctpSid;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02001981 config.negotiated = true;
Florent Castelli72424402022-04-06 03:45:10 +02001982 channel = pc_->CreateDataChannelOrError("max", &config);
1983 EXPECT_TRUE(channel.ok());
1984 EXPECT_EQ(config.id, channel.value()->id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985
1986 config.id = cricket::kMaxSctpSid + 1;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02001987 config.negotiated = true;
Florent Castelli72424402022-04-06 03:45:10 +02001988 channel = pc_->CreateDataChannelOrError("x", &config);
1989 EXPECT_FALSE(channel.ok());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001990}
1991
deadbeefab9b2d12015-10-14 11:33:11 -07001992// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08001993TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001994 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02001995 CreatePeerConnection(rtc_config);
deadbeefab9b2d12015-10-14 11:33:11 -07001996
1997 std::string label = "test";
Florent Castelli72424402022-04-06 03:45:10 +02001998 auto channel = pc_->CreateDataChannelOrError(label, nullptr);
1999 EXPECT_TRUE(channel.ok());
deadbeefab9b2d12015-10-14 11:33:11 -07002000
Florent Castelli72424402022-04-06 03:45:10 +02002001 auto dup_channel = pc_->CreateDataChannelOrError(label, nullptr);
2002 EXPECT_TRUE(dup_channel.ok());
deadbeefab9b2d12015-10-14 11:33:11 -07002003}
2004
Mirko Bonadei5eb43b42021-01-18 13:24:40 +01002005#ifdef WEBRTC_HAVE_SCTP
Zhi Huang644fde42018-04-02 19:16:26 -07002006// This tests that SCTP data channels can be rejected in an answer.
2007TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2008#else
2009TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2010#endif
2011{
Niels Möllerf06f9232018-08-07 12:32:18 +02002012 RTCConfiguration rtc_config;
2013 CreatePeerConnection(rtc_config);
Zhi Huang644fde42018-04-02 19:16:26 -07002014
Florent Castelli72424402022-04-06 03:45:10 +02002015 auto offer_channel = pc_->CreateDataChannelOrError("offer_channel", NULL);
Zhi Huang644fde42018-04-02 19:16:26 -07002016
2017 CreateOfferAsLocalDescription();
2018
2019 // Create an answer where the m-line for data channels are rejected.
2020 std::string sdp;
2021 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2022 std::unique_ptr<SessionDescriptionInterface> answer(
2023 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2024 ASSERT_TRUE(answer);
2025 cricket::ContentInfo* data_info =
2026 cricket::GetFirstDataContent(answer->description());
2027 data_info->rejected = true;
2028
2029 DoSetRemoteDescription(std::move(answer));
Florent Castelli72424402022-04-06 03:45:10 +02002030 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel.value()->state());
Zhi Huang644fde42018-04-02 19:16:26 -07002031}
2032
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002033// Test that we can create a session description from an SDP string from
2034// FireFox, use it as a remote session description, generate an answer and use
2035// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002036TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002037 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002038 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002039 AddAudioTrack("audio_label");
2040 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002041 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002042 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002043 webrtc::kFireFoxSdpOffer, nullptr));
2044 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045 CreateAnswerAsLocalDescription();
Niels Möllerafb246b2022-04-20 14:26:50 +02002046 ASSERT_TRUE(pc_->local_description() != nullptr);
2047 ASSERT_TRUE(pc_->remote_description() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048
2049 const cricket::ContentInfo* content =
2050 cricket::GetFirstAudioContent(pc_->local_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002051 ASSERT_TRUE(content != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052 EXPECT_FALSE(content->rejected);
2053
2054 content =
2055 cricket::GetFirstVideoContent(pc_->local_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002056 ASSERT_TRUE(content != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057 EXPECT_FALSE(content->rejected);
Mirko Bonadei5eb43b42021-01-18 13:24:40 +01002058#ifdef WEBRTC_HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059 content =
2060 cricket::GetFirstDataContent(pc_->local_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002061 ASSERT_TRUE(content != nullptr);
Zhi Huange830e682018-03-30 10:48:35 -07002062 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002063#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002064}
2065
Harald Alvestrand0d018412021-11-04 13:52:31 +00002066// Test that fallback from DTLS to SDES is not supported.
2067// The fallback was previously supported but was removed to simplify the code
2068// and because it's non-standard.
2069TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002070 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002071 CreatePeerConnection(rtc_config);
deadbeef8662f942017-01-20 21:20:51 -08002072 // Wait for fake certificate to be generated. Previously, this is what caused
2073 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002074 AddAudioTrack("audio_label");
2075 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002076 ASSERT_NE(nullptr, fake_certificate_generator_);
2077 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2078 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002079 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002080 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2081 nullptr));
Harald Alvestrand0d018412021-11-04 13:52:31 +00002082 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002083}
2084
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002085// Test that we can create an audio only offer and receive an answer with a
2086// limited set of audio codecs and receive an updated offer with more audio
2087// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002088TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002089 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002090 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091 CreateOfferAsLocalDescription();
2092
Florent Castelli15a38de2022-04-06 00:38:21 +02002093 const char* answer_sdp = (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED
2094 ? webrtc::kAudioSdpPlanB
2095 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002096 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002097 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002098 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099
Steve Anton36da6ff2018-02-16 16:04:20 -08002100 const char* reoffer_sdp =
Florent Castelli15a38de2022-04-06 00:38:21 +02002101 (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED
Steve Anton36da6ff2018-02-16 16:04:20 -08002102 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2103 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002104 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002105 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002106 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107 CreateAnswerAsLocalDescription();
2108}
2109
deadbeefc80741f2015-10-22 13:14:45 -07002110// Test that if we're receiving (but not sending) a track, subsequent offers
2111// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002112TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002113 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002114 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002115 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002116 CreateAnswerAsLocalDescription();
2117
2118 // At this point we should be receiving stream 1, but not sending anything.
2119 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002120 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002121 DoCreateOffer(&offer, nullptr);
2122
2123 const cricket::ContentInfo* video_content =
2124 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002125 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2126 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002127
2128 const cricket::ContentInfo* audio_content =
2129 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002130 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2131 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002132}
2133
2134// Test that if we're receiving (but not sending) a track, and the
2135// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2136// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002137TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002138 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002139 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002140 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002141 CreateAnswerAsLocalDescription();
2142
2143 // At this point we should be receiving stream 1, but not sending anything.
2144 // A new offer would be recvonly, but we'll set the "no receive" constraints
2145 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002146 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02002147 RTCOfferAnswerOptions options;
2148 options.offer_to_receive_audio = 0;
2149 options.offer_to_receive_video = 0;
2150 DoCreateOffer(&offer, &options);
deadbeefc80741f2015-10-22 13:14:45 -07002151
2152 const cricket::ContentInfo* video_content =
2153 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002154 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2155 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002156
2157 const cricket::ContentInfo* audio_content =
2158 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002159 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2160 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002161}
2162
deadbeef653b8e02015-11-11 12:55:10 -08002163// Test that we can use SetConfiguration to change the ICE servers of the
2164// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002165TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002166 CreatePeerConnection();
2167
Steve Anton36da6ff2018-02-16 16:04:20 -08002168 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002169 PeerConnectionInterface::IceServer server;
2170 server.uri = "stun:test_hostname";
2171 config.servers.push_back(server);
Niels Möller2579f0c2019-08-19 09:58:17 +02002172 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef653b8e02015-11-11 12:55:10 -08002173
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002174 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2175 EXPECT_EQ("test_hostname",
2176 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002177}
2178
Steve Anton36da6ff2018-02-16 16:04:20 -08002179TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002180 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002181 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002182 config.type = PeerConnectionInterface::kRelay;
Niels Möller2579f0c2019-08-19 09:58:17 +02002183 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002184 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2185}
2186
Steve Anton36da6ff2018-02-16 16:04:20 -08002187TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002188 PeerConnectionInterface::RTCConfiguration config;
2189 config.prune_turn_ports = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02002190 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002191 config = pc_->GetConfiguration();
Honghai Zhangf8998cf2019-10-14 11:27:50 -07002192 EXPECT_EQ(webrtc::NO_PRUNE, port_allocator_->turn_port_prune_policy());
deadbeef293e9262017-01-11 12:28:30 -08002193
2194 config.prune_turn_ports = true;
Niels Möller2579f0c2019-08-19 09:58:17 +02002195 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Honghai Zhangf8998cf2019-10-14 11:27:50 -07002196 EXPECT_EQ(webrtc::PRUNE_BASED_ON_PRIORITY,
2197 port_allocator_->turn_port_prune_policy());
deadbeef293e9262017-01-11 12:28:30 -08002198}
2199
skvladd1f5fda2017-02-03 16:54:05 -08002200// Test that the ice check interval can be changed. This does not verify that
2201// the setting makes it all the way to P2PTransportChannel, as that would
2202// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002203TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002204 PeerConnectionInterface::RTCConfiguration config;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +02002205 config.ice_check_min_interval = absl::nullopt;
Niels Möllerf06f9232018-08-07 12:32:18 +02002206 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002207 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002208 config.ice_check_min_interval = 100;
Niels Möller2579f0c2019-08-19 09:58:17 +02002209 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Qingsi Wangbca14852019-06-26 14:56:02 -07002210 config = pc_->GetConfiguration();
2211 EXPECT_EQ(config.ice_check_min_interval, 100);
2212}
2213
2214TEST_P(PeerConnectionInterfaceTest,
2215 SetConfigurationChangesSurfaceIceCandidatesOnIceTransportTypeChanged) {
2216 PeerConnectionInterface::RTCConfiguration config;
2217 config.surface_ice_candidates_on_ice_transport_type_changed = false;
2218 CreatePeerConnection(config);
2219 config = pc_->GetConfiguration();
2220 EXPECT_FALSE(config.surface_ice_candidates_on_ice_transport_type_changed);
2221
2222 config.surface_ice_candidates_on_ice_transport_type_changed = true;
Niels Möller2579f0c2019-08-19 09:58:17 +02002223 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Qingsi Wangbca14852019-06-26 14:56:02 -07002224 config = pc_->GetConfiguration();
2225 EXPECT_TRUE(config.surface_ice_candidates_on_ice_transport_type_changed);
skvladd1f5fda2017-02-03 16:54:05 -08002226}
2227
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002228// Test that when SetConfiguration changes both the pool size and other
2229// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002230TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002231 SetConfigurationCreatesPooledSessionCorrectly) {
2232 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002233 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002234 config.ice_candidate_pool_size = 1;
2235 PeerConnectionInterface::IceServer server;
2236 server.uri = kStunAddressOnly;
2237 config.servers.push_back(server);
2238 config.type = PeerConnectionInterface::kRelay;
Niels Möller2579f0c2019-08-19 09:58:17 +02002239 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002240
2241 const cricket::FakePortAllocatorSession* session =
2242 static_cast<const cricket::FakePortAllocatorSession*>(
2243 port_allocator_->GetPooledSession());
2244 ASSERT_NE(nullptr, session);
2245 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002246}
2247
deadbeef293e9262017-01-11 12:28:30 -08002248// Test that after SetLocalDescription, changing the pool size is not allowed,
2249// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002250TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002251 CantChangePoolSizeAfterSetLocalDescription) {
2252 CreatePeerConnection();
2253 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002254 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002255 config.ice_candidate_pool_size = 1;
Niels Möller2579f0c2019-08-19 09:58:17 +02002256 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef6de92f92016-12-12 18:49:32 -08002257
2258 // Set remote offer; can still change pool size at this point.
2259 CreateOfferAsRemoteDescription();
2260 config.ice_candidate_pool_size = 2;
Niels Möller2579f0c2019-08-19 09:58:17 +02002261 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef6de92f92016-12-12 18:49:32 -08002262
2263 // Set local answer; now it's too late.
2264 CreateAnswerAsLocalDescription();
2265 config.ice_candidate_pool_size = 3;
Niels Möller2579f0c2019-08-19 09:58:17 +02002266 RTCError error = pc_->SetConfiguration(config);
deadbeef293e9262017-01-11 12:28:30 -08002267 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2268}
2269
deadbeef42a42632017-03-10 15:18:00 -08002270// Test that after setting an answer, extra pooled sessions are discarded. The
2271// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002272TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002273 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2274 CreatePeerConnection();
2275
2276 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002277 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002278 config.ice_candidate_pool_size = 4;
Niels Möller2579f0c2019-08-19 09:58:17 +02002279 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef42a42632017-03-10 15:18:00 -08002280
2281 // Do offer/answer.
2282 CreateOfferAsRemoteDescription();
2283 CreateAnswerAsLocalDescription();
2284
2285 // Expect no pooled sessions to be left.
2286 const cricket::PortAllocatorSession* session =
2287 port_allocator_->GetPooledSession();
2288 EXPECT_EQ(nullptr, session);
2289}
2290
2291// After Close is called, pooled candidates should be discarded so as to not
2292// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002293TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002294 CreatePeerConnection();
2295
Steve Anton36da6ff2018-02-16 16:04:20 -08002296 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002297 config.ice_candidate_pool_size = 3;
Niels Möller2579f0c2019-08-19 09:58:17 +02002298 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef42a42632017-03-10 15:18:00 -08002299 pc_->Close();
2300
2301 // Expect no pooled sessions to be left.
2302 const cricket::PortAllocatorSession* session =
2303 port_allocator_->GetPooledSession();
2304 EXPECT_EQ(nullptr, session);
2305}
2306
deadbeef293e9262017-01-11 12:28:30 -08002307// Test that SetConfiguration returns an invalid modification error if
2308// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002309TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002310 SetConfigurationReturnsInvalidModificationError) {
2311 PeerConnectionInterface::RTCConfiguration config;
2312 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2313 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2314 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
Niels Möllerf06f9232018-08-07 12:32:18 +02002315 CreatePeerConnection(config);
deadbeef293e9262017-01-11 12:28:30 -08002316
Steve Anton36da6ff2018-02-16 16:04:20 -08002317 PeerConnectionInterface::RTCConfiguration modified_config =
2318 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002319 modified_config.bundle_policy =
2320 PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möller2579f0c2019-08-19 09:58:17 +02002321 RTCError error = pc_->SetConfiguration(modified_config);
deadbeef293e9262017-01-11 12:28:30 -08002322 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2323
Steve Anton36da6ff2018-02-16 16:04:20 -08002324 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002325 modified_config.rtcp_mux_policy =
2326 PeerConnectionInterface::kRtcpMuxPolicyRequire;
Niels Möller2579f0c2019-08-19 09:58:17 +02002327 error = pc_->SetConfiguration(modified_config);
deadbeef293e9262017-01-11 12:28:30 -08002328 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2329
Steve Anton36da6ff2018-02-16 16:04:20 -08002330 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002331 modified_config.continual_gathering_policy =
2332 PeerConnectionInterface::GATHER_CONTINUALLY;
Niels Möller2579f0c2019-08-19 09:58:17 +02002333 error = pc_->SetConfiguration(modified_config);
deadbeef293e9262017-01-11 12:28:30 -08002334 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2335}
2336
2337// Test that SetConfiguration returns a range error if the candidate pool size
2338// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002339TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002340 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2341 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002342 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002343 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002344
2345 config.ice_candidate_pool_size = -1;
Niels Möller2579f0c2019-08-19 09:58:17 +02002346 RTCError error = pc_->SetConfiguration(config);
deadbeef293e9262017-01-11 12:28:30 -08002347 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2348
2349 config.ice_candidate_pool_size = INT_MAX;
Niels Möller2579f0c2019-08-19 09:58:17 +02002350 error = pc_->SetConfiguration(config);
deadbeef293e9262017-01-11 12:28:30 -08002351 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2352}
2353
2354// Test that SetConfiguration returns a syntax error if parsing an ICE server
2355// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002356TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002357 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2358 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002359 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002360 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002361
2362 PeerConnectionInterface::IceServer bad_server;
2363 bad_server.uri = "stunn:www.example.com";
2364 config.servers.push_back(bad_server);
Niels Möller2579f0c2019-08-19 09:58:17 +02002365 RTCError error = pc_->SetConfiguration(config);
deadbeef293e9262017-01-11 12:28:30 -08002366 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2367}
2368
2369// Test that SetConfiguration returns an invalid parameter error if a TURN
2370// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002371TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002372 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2373 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002374 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002375 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002376
2377 PeerConnectionInterface::IceServer bad_server;
2378 bad_server.uri = "turn:www.example.com";
2379 // Missing password.
2380 bad_server.username = "foo";
2381 config.servers.push_back(bad_server);
2382 RTCError error;
Niels Möller340e0c52019-08-26 11:03:47 +02002383 EXPECT_EQ(pc_->SetConfiguration(config).type(),
2384 RTCErrorType::INVALID_PARAMETER);
deadbeef6de92f92016-12-12 18:49:32 -08002385}
2386
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002387// Test that PeerConnection::Close changes the states to closed and all remote
2388// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002389TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002390 // Initialize a PeerConnection and negotiate local and remote session
2391 // description.
2392 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002393
2394 // With Plan B, verify the stream count. The analog with Unified Plan is the
2395 // RtpTransceiver count.
Florent Castelli15a38de2022-04-06 00:38:21 +02002396 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Steve Anton36da6ff2018-02-16 16:04:20 -08002397 ASSERT_EQ(1u, pc_->local_streams()->count());
2398 ASSERT_EQ(1u, pc_->remote_streams()->count());
2399 } else {
2400 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2401 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002402
2403 pc_->Close();
2404
2405 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2406 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2407 pc_->ice_connection_state());
2408 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2409 pc_->ice_gathering_state());
2410
Florent Castelli15a38de2022-04-06 00:38:21 +02002411 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Steve Anton36da6ff2018-02-16 16:04:20 -08002412 EXPECT_EQ(1u, pc_->local_streams()->count());
2413 EXPECT_EQ(1u, pc_->remote_streams()->count());
2414 } else {
Harald Alvestrand936f1af2020-09-22 07:41:50 +00002415 // Verify that the RtpTransceivers are still returned.
2416 EXPECT_EQ(2u, pc_->GetTransceivers().size());
Steve Anton36da6ff2018-02-16 16:04:20 -08002417 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002418
Steve Anton36da6ff2018-02-16 16:04:20 -08002419 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
Steve Anton36da6ff2018-02-16 16:04:20 -08002420 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
Florent Castelli15a38de2022-04-06 00:38:21 +02002421 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Harald Alvestrand6060df52020-08-11 09:54:02 +02002422 ASSERT_TRUE(audio_receiver);
2423 ASSERT_TRUE(video_receiver);
2424 // Track state may be updated asynchronously.
2425 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
2426 audio_receiver->track()->state(), kTimeout);
2427 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
2428 video_receiver->track()->state(), kTimeout);
2429 } else {
2430 ASSERT_FALSE(audio_receiver);
2431 ASSERT_FALSE(video_receiver);
2432 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433}
2434
2435// Test that PeerConnection methods fails gracefully after
2436// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002437// Don't run under Unified Plan since the stream API is not available.
2438TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002439 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002440 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002441 CreateOfferAsRemoteDescription();
2442 CreateAnswerAsLocalDescription();
2443
2444 ASSERT_EQ(1u, pc_->local_streams()->count());
Niels Möllere7cc8832022-01-04 15:20:03 +01002445 rtc::scoped_refptr<MediaStreamInterface> local_stream(
2446 pc_->local_streams()->at(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002447
2448 pc_->Close();
2449
Niels Möllerafb246b2022-04-20 14:26:50 +02002450 pc_->RemoveStream(local_stream.get());
2451 EXPECT_FALSE(pc_->AddStream(local_stream.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002452
Florent Castelli72424402022-04-06 03:45:10 +02002453 EXPECT_FALSE(pc_->CreateDataChannelOrError("test", NULL).ok());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002454
Niels Möllerafb246b2022-04-20 14:26:50 +02002455 EXPECT_TRUE(pc_->local_description() != nullptr);
2456 EXPECT_TRUE(pc_->remote_description() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002457
kwibergd1fe2812016-04-27 06:47:29 -07002458 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002459 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002460 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002461 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002462
2463 std::string sdp;
2464 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002465 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002466 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002467 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002468
2469 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002470 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002471 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002472 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002473}
2474
2475// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002476TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002477 InitiateCall();
2478 pc_->Close();
Niels Möllerafb246b2022-04-20 14:26:50 +02002479 DoGetStats(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480}
deadbeefab9b2d12015-10-14 11:33:11 -07002481
2482// NOTE: The series of tests below come from what used to be
2483// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2484// setting a remote or local description has the expected effects.
2485
2486// This test verifies that the remote MediaStreams corresponding to a received
2487// SDP string is created. In this test the two separate MediaStreams are
2488// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002489TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002490 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002491 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002492 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002493
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002494 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002495 EXPECT_TRUE(
2496 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2497 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2498 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2499
2500 // Create a session description based on another SDP with another
2501 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002502 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002503
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002504 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002505 EXPECT_TRUE(
2506 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2507}
2508
2509// This test verifies that when remote tracks are added/removed from SDP, the
2510// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002511// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2512// specific behavior.
2513TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002514 AddRemoveTrackFromExistingRemoteMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002515 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002516 CreatePeerConnection(config);
kwibergd1fe2812016-04-27 06:47:29 -07002517 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002518 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002519 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002520 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
Niels Möllerafb246b2022-04-20 14:26:50 +02002521 reference_collection_.get()));
deadbeefab9b2d12015-10-14 11:33:11 -07002522
2523 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002524 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002525 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002526 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002527 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
Niels Möllerafb246b2022-04-20 14:26:50 +02002528 reference_collection_.get()));
zhihuang9763d562016-08-05 11:14:50 -07002529 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002530 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2531 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002532 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002533 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2534 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002535
2536 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002537 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002538 CreateSessionDescriptionAndReference(1, 1);
Niels Möllerafb246b2022-04-20 14:26:50 +02002539 MockTrackObserver audio_track_observer(audio_track2.get());
2540 MockTrackObserver video_track_observer(video_track2.get());
perkjd61bf802016-03-24 03:16:19 -07002541
2542 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2543 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002544 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002545 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
Niels Möllerafb246b2022-04-20 14:26:50 +02002546 reference_collection_.get()));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002547 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002548 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002549 audio_track2->state(), kTimeout);
2550 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2551 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002552}
2553
2554// This tests that remote tracks are ended if a local session description is set
2555// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002556TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002557 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002558 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002559 // First create and set a remote offer, then reject its video content in our
2560 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002561 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2562 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2563 ASSERT_TRUE(audio_receiver);
2564 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2565 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002566
Steve Anton36da6ff2018-02-16 16:04:20 -08002567 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2568 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002569 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002570 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2571 video_receiver->track();
2572 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002573
kwibergd1fe2812016-04-27 06:47:29 -07002574 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002575 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002576 cricket::ContentInfo* video_info =
2577 local_answer->description()->GetContentByName("video");
2578 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002579 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002580 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2581 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002582
2583 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002584 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002585 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002586 video_info = local_offer->description()->GetContentByName("video");
2587 ASSERT_TRUE(video_info != nullptr);
2588 video_info->rejected = true;
2589 cricket::ContentInfo* audio_info =
2590 local_offer->description()->GetContentByName("audio");
2591 ASSERT_TRUE(audio_info != nullptr);
2592 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002593 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002594 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002595 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2596 kTimeout);
2597 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2598 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002599}
2600
2601// This tests that we won't crash if the remote track has been removed outside
2602// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002603// Don't run under Unified Plan since the stream API is not available.
2604TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002605 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002606 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002607 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002608 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00002609 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2610 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07002611
kwibergd1fe2812016-04-27 06:47:29 -07002612 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002613 webrtc::CreateSessionDescription(SdpType::kAnswer,
2614 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002615 cricket::ContentInfo* video_info =
2616 local_answer->description()->GetContentByName("video");
2617 video_info->rejected = true;
2618 cricket::ContentInfo* audio_info =
2619 local_answer->description()->GetContentByName("audio");
2620 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002621 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002622
2623 // No crash is a pass.
2624}
2625
deadbeef5e97fb52015-10-15 12:49:08 -07002626// This tests that if a recvonly remote description is set, no remote streams
2627// will be created, even if the description contains SSRCs/MSIDs.
2628// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002629TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002630 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002631 CreatePeerConnection(config);
deadbeef5e97fb52015-10-15 12:49:08 -07002632
Steve Anton36da6ff2018-02-16 16:04:20 -08002633 std::string recvonly_offer = GetSdpStringWithStream1();
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002634 absl::StrReplaceAll({{kSendrecv, kRecvonly}}, &recvonly_offer);
deadbeef5e97fb52015-10-15 12:49:08 -07002635 CreateAndSetRemoteOffer(recvonly_offer);
2636
2637 EXPECT_EQ(0u, observer_.remote_streams()->count());
2638}
2639
deadbeefab9b2d12015-10-14 11:33:11 -07002640// This tests that a default MediaStream is created if a remote session
2641// description doesn't contain any streams and no MSID support.
2642// It also tests that the default stream is updated if a video m-line is added
2643// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002644// Don't run under Unified Plan since this behavior is Plan B specific.
2645TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002646 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002647 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002648 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2649
2650 ASSERT_EQ(1u, observer_.remote_streams()->count());
2651 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2652
2653 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2654 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002655 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002656
2657 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2658 ASSERT_EQ(1u, observer_.remote_streams()->count());
2659 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2660 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002661 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2662 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002663 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2664 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002665 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2666 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002667}
2668
2669// This tests that a default MediaStream is created if a remote session
2670// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002671// Don't run under Unified Plan since this behavior is Plan B specific.
2672TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002673 SendOnlySdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002674 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002675 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002676 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2677
2678 ASSERT_EQ(1u, observer_.remote_streams()->count());
2679 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2680
2681 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2682 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002683 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002684}
2685
2686// This tests that it won't crash when PeerConnection tries to remove
2687// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002688// Don't run under Unified Plan since this behavior is Plan B specific.
2689TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002690 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002691 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002692 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002693 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00002694 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2695 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07002696
2697 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2698
2699 // No crash is a pass.
2700}
2701
2702// This tests that a default MediaStream is created if the remote session
2703// description doesn't contain any streams and don't contain an indication if
2704// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002705// Don't run under Unified Plan since this behavior is Plan B specific.
2706TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002707 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002708 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002709 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002710 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2711
2712 ASSERT_EQ(1u, observer_.remote_streams()->count());
2713 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2714 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2715 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2716}
2717
2718// This tests that a default MediaStream is not created if the remote session
2719// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08002720// Don't run under Unified Plan since this behavior is Plan B specific.
2721TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002722 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002723 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002724 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2725 EXPECT_EQ(0u, observer_.remote_streams()->count());
2726}
2727
deadbeefbda7e0b2015-12-08 17:13:40 -08002728// This tests that when setting a new description, the old default tracks are
2729// not destroyed and recreated.
2730// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08002731// Don't run under Unified Plan since this behavior is Plan B specific.
2732TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002733 DefaultTracksNotDestroyedAndRecreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002734 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002735 CreatePeerConnection(config);
deadbeefbda7e0b2015-12-08 17:13:40 -08002736 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2737
2738 ASSERT_EQ(1u, observer_.remote_streams()->count());
2739 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2740 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2741
2742 // Set the track to "disabled", then set a new description and ensure the
2743 // track is still disabled, which ensures it hasn't been recreated.
2744 remote_stream->GetAudioTracks()[0]->set_enabled(false);
2745 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2746 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2747 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
2748}
2749
deadbeefab9b2d12015-10-14 11:33:11 -07002750// This tests that a default MediaStream is not created if a remote session
2751// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08002752// Don't run under Unified Plan since this behavior is Plan B specific.
2753TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002754 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002755 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002756 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002757 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002758 EXPECT_TRUE(
2759 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2760
2761 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2762 EXPECT_EQ(0u, observer_.remote_streams()->count());
2763}
2764
Seth Hampson5897a6e2018-04-03 11:16:33 -07002765// This tests that a default MediaStream is created if a remote SDP comes from
2766// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
2767TEST_F(PeerConnectionInterfaceTestPlanB,
2768 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002769 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002770 CreatePeerConnection(config);
Seth Hampson5897a6e2018-04-03 11:16:33 -07002771 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
2772 // Add a=msid lines to simulate a Unified Plan endpoint that only
2773 // signals stream IDs with a=msid lines.
2774 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
2775
2776 CreateAndSetRemoteOffer(sdp_string);
2777
2778 ASSERT_EQ(1u, observer_.remote_streams()->count());
2779 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2780 EXPECT_EQ("default", remote_stream->id());
2781 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2782}
2783
Seth Hampson5b4f0752018-04-02 16:31:36 -07002784// This tests that when a Plan B endpoint receives an SDP that signals no media
2785// stream IDs indicated by the special character "-" in the a=msid line, that
2786// a default stream ID will be used for the MediaStream ID. This can occur
2787// when a Unified Plan endpoint signals no media stream IDs, but signals both
2788// a=ssrc msid and a=msid lines for interop signaling with Plan B.
2789TEST_F(PeerConnectionInterfaceTestPlanB,
2790 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002791 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002792 CreatePeerConnection(config);
Seth Hampson5b4f0752018-04-02 16:31:36 -07002793 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
2794 // the sender's stream ID will be interpreted as no stream IDs.
2795 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
2796 sdp_string.append("a=msid:- audiotrack0\n");
2797
2798 CreateAndSetRemoteOffer(sdp_string);
2799
2800 ASSERT_EQ(1u, observer_.remote_streams()->count());
2801 // Because SSRCs are signaled the track ID will be what was signaled in the
2802 // a=msid line.
2803 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
2804 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2805 EXPECT_EQ("default", remote_stream->id());
2806 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07002807
2808 // Previously a bug ocurred when setting the remote description a second time.
2809 // This is because we checked equality of the remote StreamParams stream ID
2810 // (empty), and the previously set stream ID for the remote sender
2811 // ("default"). This cause a track to be removed, then added, when really
2812 // nothing should occur because it is the same track.
2813 CreateAndSetRemoteOffer(sdp_string);
2814 EXPECT_EQ(0u, observer_.remove_track_events_.size());
2815 EXPECT_EQ(1u, observer_.add_track_events_.size());
2816 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
2817 remote_stream = observer_.remote_streams()->at(0);
2818 EXPECT_EQ("default", remote_stream->id());
2819 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07002820}
2821
deadbeefab9b2d12015-10-14 11:33:11 -07002822// This tests that an RtpSender is created when the local description is set
2823// after adding a local stream.
2824// TODO(deadbeef): This test and the one below it need to be updated when
2825// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08002826// Don't run under Unified Plan since this behavior is Plan B specific.
2827TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002828 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002829 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002830
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002831 // Create an offer with 1 stream with 2 tracks of each type.
2832 rtc::scoped_refptr<StreamCollection> stream_collection =
2833 CreateStreamCollection(1, 2);
2834 pc_->AddStream(stream_collection->at(0));
2835 std::unique_ptr<SessionDescriptionInterface> offer;
2836 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002837 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002838
deadbeefab9b2d12015-10-14 11:33:11 -07002839 auto senders = pc_->GetSenders();
2840 EXPECT_EQ(4u, senders.size());
2841 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2842 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2843 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2844 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2845
2846 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002847 pc_->RemoveStream(stream_collection->at(0));
2848 stream_collection = CreateStreamCollection(1, 1);
2849 pc_->AddStream(stream_collection->at(0));
2850 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002851 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002852
deadbeefab9b2d12015-10-14 11:33:11 -07002853 senders = pc_->GetSenders();
2854 EXPECT_EQ(2u, senders.size());
2855 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2856 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2857 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
2858 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
2859}
2860
2861// This tests that an RtpSender is created when the local description is set
2862// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002863// Don't run under Unified Plan since this behavior is Plan B specific.
2864TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002865 AddLocalStreamAfterLocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002866 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002867 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002868
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002869 rtc::scoped_refptr<StreamCollection> stream_collection =
2870 CreateStreamCollection(1, 2);
2871 // Add a stream to create the offer, but remove it afterwards.
2872 pc_->AddStream(stream_collection->at(0));
2873 std::unique_ptr<SessionDescriptionInterface> offer;
2874 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2875 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002876
Steve Antondb45ca82017-09-11 18:27:34 -07002877 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002878 auto senders = pc_->GetSenders();
2879 EXPECT_EQ(0u, senders.size());
2880
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002881 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002882 senders = pc_->GetSenders();
2883 EXPECT_EQ(4u, senders.size());
2884 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2885 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2886 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2887 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2888}
2889
2890// This tests that the expected behavior occurs if the SSRC on a local track is
2891// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002892TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002893 ChangeSsrcOnTrackInLocalSessionDescription) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002894 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002895 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002896
Steve Anton36da6ff2018-02-16 16:04:20 -08002897 AddAudioTrack(kAudioTracks[0]);
2898 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002899 std::unique_ptr<SessionDescriptionInterface> offer;
2900 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2901 // Grab a copy of the offer before it gets passed into the PC.
Steve Antond9e4a062018-07-24 18:23:33 -07002902 std::unique_ptr<SessionDescriptionInterface> modified_offer =
2903 webrtc::CreateSessionDescription(
2904 webrtc::SdpType::kOffer, offer->session_id(),
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002905 offer->session_version(), offer->description()->Clone());
Steve Antondb45ca82017-09-11 18:27:34 -07002906 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002907
deadbeefab9b2d12015-10-14 11:33:11 -07002908 auto senders = pc_->GetSenders();
2909 EXPECT_EQ(2u, senders.size());
2910 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2911 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2912
2913 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002914 cricket::MediaContentDescription* desc =
2915 cricket::GetFirstAudioContentDescription(modified_offer->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002916 ASSERT_TRUE(desc != nullptr);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002917 for (StreamParams& stream : desc->mutable_streams()) {
2918 for (unsigned int& ssrc : stream.ssrcs) {
2919 ++ssrc;
2920 }
2921 }
deadbeefab9b2d12015-10-14 11:33:11 -07002922
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002923 desc =
2924 cricket::GetFirstVideoContentDescription(modified_offer->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002925 ASSERT_TRUE(desc != nullptr);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002926 for (StreamParams& stream : desc->mutable_streams()) {
2927 for (unsigned int& ssrc : stream.ssrcs) {
2928 ++ssrc;
2929 }
2930 }
2931
Steve Antondb45ca82017-09-11 18:27:34 -07002932 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002933 senders = pc_->GetSenders();
2934 EXPECT_EQ(2u, senders.size());
2935 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2936 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2937 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
2938 // changed.
2939}
2940
2941// This tests that the expected behavior occurs if a new session description is
2942// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002943// Don't run under Unified Plan since the stream API is not available.
2944TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002945 SignalSameTracksInSeparateMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002946 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002947 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002948
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002949 rtc::scoped_refptr<StreamCollection> stream_collection =
2950 CreateStreamCollection(2, 1);
2951 pc_->AddStream(stream_collection->at(0));
2952 std::unique_ptr<SessionDescriptionInterface> offer;
2953 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002954 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002955
deadbeefab9b2d12015-10-14 11:33:11 -07002956 auto senders = pc_->GetSenders();
2957 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002958 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
2959 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07002960
2961 // Add a new MediaStream but with the same tracks as in the first stream.
2962 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
2963 webrtc::MediaStream::Create(kStreams[1]));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00002964 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
2965 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
Niels Möllerafb246b2022-04-20 14:26:50 +02002966 pc_->AddStream(stream_1.get());
deadbeefab9b2d12015-10-14 11:33:11 -07002967
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002968 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002969 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002970
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002971 auto new_senders = pc_->GetSenders();
2972 // Should be the same senders as before, but with updated stream id.
2973 // Note that this behavior is subject to change in the future.
2974 // We may decide the PC should ignore existing tracks in AddStream.
2975 EXPECT_EQ(senders, new_senders);
2976 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
2977 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07002978}
2979
zhihuang81c3a032016-11-17 12:06:24 -08002980// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002981TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002982 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002983 CreatePeerConnection(config);
zhihuang81c3a032016-11-17 12:06:24 -08002984 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
2985 EXPECT_EQ(observer_.num_added_tracks_, 1);
2986 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
2987
2988 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08002989 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
Steve Anton0f5400a2018-07-17 14:25:36 -07002990 EXPECT_EQ(observer_.num_added_tracks_, 2);
zhihuang81c3a032016-11-17 12:06:24 -08002991 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
2992}
2993
deadbeefd1a38b52016-12-10 13:15:33 -08002994// Test that when SetConfiguration is called and the configuration is
2995// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08002996TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08002997 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01002998 config.sdp_semantics = sdp_semantics_;
deadbeefd1a38b52016-12-10 13:15:33 -08002999 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003000 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003001 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003002 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3003 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003004
3005 // Do initial offer/answer so there's something to restart.
3006 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003007 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003008
3009 // Grab the ufrags.
3010 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3011
3012 // Change ICE policy, which should trigger an ICE restart on the next offer.
3013 config.type = PeerConnectionInterface::kAll;
Niels Möller2579f0c2019-08-19 09:58:17 +02003014 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeefd1a38b52016-12-10 13:15:33 -08003015 CreateOfferAsLocalDescription();
3016
3017 // Grab the new ufrags.
3018 std::vector<std::string> subsequent_ufrags =
3019 GetUfrags(pc_->local_description());
3020
3021 // Sanity check.
3022 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3023 // Check that each ufrag is different.
3024 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3025 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3026 }
3027}
3028
3029// Test that when SetConfiguration is called and the configuration *isn't*
3030// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003031TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003032 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003033 config.sdp_semantics = sdp_semantics_;
deadbeefd1a38b52016-12-10 13:15:33 -08003034 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003035 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003036 config = pc_->GetConfiguration();
3037 AddAudioTrack(kAudioTracks[0]);
3038 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003039
3040 // Do initial offer/answer so there's something to restart.
3041 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003042 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003043
3044 // Grab the ufrags.
3045 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3046
3047 // Call SetConfiguration with a config identical to what the PC was
3048 // constructed with.
Niels Möller2579f0c2019-08-19 09:58:17 +02003049 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeefd1a38b52016-12-10 13:15:33 -08003050 CreateOfferAsLocalDescription();
3051
3052 // Grab the new ufrags.
3053 std::vector<std::string> subsequent_ufrags =
3054 GetUfrags(pc_->local_description());
3055
3056 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3057}
3058
3059// Test for a weird corner case scenario:
3060// 1. Audio/video session established.
3061// 2. SetConfiguration changes ICE config; ICE restart needed.
3062// 3. ICE restart initiated by remote peer, but only for one m= section.
3063// 4. Next createOffer should initiate an ICE restart, but only for the other
3064// m= section; it would be pointless to do an ICE restart for the m= section
3065// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003066TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003067 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003068 config.sdp_semantics = sdp_semantics_;
deadbeefd1a38b52016-12-10 13:15:33 -08003069 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003070 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003071 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003072 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3073 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003074
3075 // Do initial offer/answer so there's something to restart.
3076 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003077 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003078
3079 // Change ICE policy, which should set the "needs-ice-restart" flag.
3080 config.type = PeerConnectionInterface::kAll;
Niels Möller2579f0c2019-08-19 09:58:17 +02003081 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeefd1a38b52016-12-10 13:15:33 -08003082
3083 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003084 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003085 webrtc::CreateSessionDescription(SdpType::kOffer,
3086 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003087 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003088 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3089 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003090 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003091 CreateAnswerAsLocalDescription();
3092
3093 // Grab the ufrags.
3094 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003095 ASSERT_EQ(2U, initial_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003096
3097 // Create offer and grab the new ufrags.
3098 CreateOfferAsLocalDescription();
3099 std::vector<std::string> subsequent_ufrags =
3100 GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003101 ASSERT_EQ(2U, subsequent_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003102
3103 // Ensure that only the ufrag for the second m= section changed.
3104 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3105 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3106}
3107
deadbeeffe4a8a42016-12-20 17:56:17 -08003108// Tests that the methods to return current/pending descriptions work as
3109// expected at different points in the offer/answer exchange. This test does
3110// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003111TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003112 // This disables DTLS so we can apply an answer to ourselves.
3113 CreatePeerConnection();
3114
3115 // Create initial local offer and get SDP (which will also be used as
3116 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003117 std::unique_ptr<SessionDescriptionInterface> local_offer;
3118 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003119 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003120 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003121
3122 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003123 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3124 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3125 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003126 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3127 EXPECT_EQ(nullptr, pc_->current_local_description());
3128 EXPECT_EQ(nullptr, pc_->current_remote_description());
3129
3130 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003131 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003132 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003133 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3134 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3135 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3136 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003137 EXPECT_EQ(nullptr, pc_->current_local_description());
3138 EXPECT_EQ(nullptr, pc_->current_remote_description());
3139
3140 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003141 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003142 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003143 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3144 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003145 EXPECT_EQ(nullptr, pc_->pending_local_description());
3146 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003147 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3148 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003149
3150 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003151 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003152 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003153 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3154 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3155 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003156 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003157 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3158 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003159
3160 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003161 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003162 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003163 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3164 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3165 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3166 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3167 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3168 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003169
3170 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003171 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003172 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003173 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3174 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003175 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3176 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003177 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3178 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003179}
3180
zhihuang77985012017-02-07 15:45:16 -08003181// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3182// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003183// This version tests the StartRtcEventLog version that receives an object
Artem Titov880fa812021-07-30 22:30:23 +02003184// of type `RtcEventLogOutput`.
Steve Anton36da6ff2018-02-16 16:04:20 -08003185TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003186 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3187 CreatePeerConnection();
3188 // The RtcEventLog will be reset when the PeerConnection is closed.
3189 pc_->Close();
3190
Niels Möllerdec9f742019-06-03 15:25:20 +02003191 EXPECT_FALSE(
Mirko Bonadei317a1f02019-09-17 17:06:18 +02003192 pc_->StartRtcEventLog(std::make_unique<webrtc::RtcEventLogOutputNull>(),
Niels Möllerdec9f742019-06-03 15:25:20 +02003193 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003194 pc_->StopRtcEventLog();
3195}
3196
deadbeef30952b42017-04-21 02:41:29 -07003197// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003198TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003199 CreatePeerConnection();
3200
3201 // First, create an offer with audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003202 RTCOfferAnswerOptions options;
3203 options.offer_to_receive_audio = 1;
3204 options.offer_to_receive_video = 1;
deadbeef30952b42017-04-21 02:41:29 -07003205 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003206 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003207 cricket::SessionDescription* desc = offer->description();
3208 ASSERT_EQ(2u, desc->transport_infos().size());
3209 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3210 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3211
3212 // Apply the offer as a remote description, then create an answer.
Harald Alvestrand61f74d92020-03-02 11:20:00 +01003213 EXPECT_FALSE(pc_->can_trickle_ice_candidates());
Steve Antondb45ca82017-09-11 18:27:34 -07003214 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
Harald Alvestrand61f74d92020-03-02 11:20:00 +01003215 ASSERT_TRUE(pc_->can_trickle_ice_candidates());
3216 EXPECT_TRUE(*(pc_->can_trickle_ice_candidates()));
deadbeef30952b42017-04-21 02:41:29 -07003217 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003218 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003219 desc = answer->description();
3220 ASSERT_EQ(2u, desc->transport_infos().size());
3221 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3222 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3223}
3224
deadbeef1dcb1642017-03-29 21:08:16 -07003225// Test that ICE renomination isn't offered if it's not enabled in the PC's
3226// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003227TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003228 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003229 config.sdp_semantics = sdp_semantics_;
deadbeef1dcb1642017-03-29 21:08:16 -07003230 config.enable_ice_renomination = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02003231 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003232 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003233
3234 std::unique_ptr<SessionDescriptionInterface> offer;
3235 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3236 cricket::SessionDescription* desc = offer->description();
3237 EXPECT_EQ(1u, desc->transport_infos().size());
3238 EXPECT_FALSE(
3239 desc->transport_infos()[0].description.GetIceParameters().renomination);
3240}
3241
3242// Test that the ICE renomination option is present in generated offers/answers
3243// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003244TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003245 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003246 config.sdp_semantics = sdp_semantics_;
deadbeef1dcb1642017-03-29 21:08:16 -07003247 config.enable_ice_renomination = true;
Niels Möllerf06f9232018-08-07 12:32:18 +02003248 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003249 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003250
3251 std::unique_ptr<SessionDescriptionInterface> offer;
3252 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3253 cricket::SessionDescription* desc = offer->description();
3254 EXPECT_EQ(1u, desc->transport_infos().size());
3255 EXPECT_TRUE(
3256 desc->transport_infos()[0].description.GetIceParameters().renomination);
3257
3258 // Set the offer as a remote description, then create an answer and ensure it
3259 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003260 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003261 std::unique_ptr<SessionDescriptionInterface> answer;
3262 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3263 desc = answer->description();
3264 EXPECT_EQ(1u, desc->transport_infos().size());
3265 EXPECT_TRUE(
3266 desc->transport_infos()[0].description.GetIceParameters().renomination);
3267}
3268
3269// Test that if CreateOffer is called with the deprecated "offer to receive
3270// audio/video" constraints, they're processed and result in an offer with
3271// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003272TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003273 CreatePeerConnection();
3274
Niels Möllerf06f9232018-08-07 12:32:18 +02003275 RTCOfferAnswerOptions options;
3276 options.offer_to_receive_audio = 1;
3277 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003278 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003279 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003280
3281 cricket::SessionDescription* desc = offer->description();
3282 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3283 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3284 ASSERT_NE(nullptr, audio);
3285 ASSERT_NE(nullptr, video);
3286 EXPECT_FALSE(audio->rejected);
3287 EXPECT_FALSE(video->rejected);
3288}
3289
3290// Test that if CreateAnswer is called with the deprecated "offer to receive
3291// audio/video" constraints, they're processed and can be used to reject an
3292// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003293// Don't run under Unified Plan since this behavior is not supported.
3294TEST_F(PeerConnectionInterfaceTestPlanB,
3295 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003296 CreatePeerConnection();
3297
3298 // First, create an offer with audio/video and apply it as a remote
3299 // description.
Niels Möllerf06f9232018-08-07 12:32:18 +02003300 RTCOfferAnswerOptions options;
3301 options.offer_to_receive_audio = 1;
3302 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003303 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003304 ASSERT_TRUE(DoCreateOffer(&offer, &options));
Steve Antondb45ca82017-09-11 18:27:34 -07003305 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003306
3307 // Now create answer that rejects audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003308 options.offer_to_receive_audio = 0;
3309 options.offer_to_receive_video = 0;
deadbeef1dcb1642017-03-29 21:08:16 -07003310 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003311 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003312
3313 cricket::SessionDescription* desc = answer->description();
3314 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3315 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3316 ASSERT_NE(nullptr, audio);
3317 ASSERT_NE(nullptr, video);
3318 EXPECT_TRUE(audio->rejected);
3319 EXPECT_TRUE(video->rejected);
3320}
3321
deadbeef1dcb1642017-03-29 21:08:16 -07003322// Test that negotiation can succeed with a data channel only, and with the max
3323// bundle policy. Previously there was a bug that prevented this.
Mirko Bonadei5eb43b42021-01-18 13:24:40 +01003324#ifdef WEBRTC_HAVE_SCTP
Steve Anton36da6ff2018-02-16 16:04:20 -08003325TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3326#else
3327TEST_P(PeerConnectionInterfaceTest,
3328 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
Mirko Bonadei5eb43b42021-01-18 13:24:40 +01003329#endif // WEBRTC_HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003330 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003331 config.sdp_semantics = sdp_semantics_;
deadbeef1dcb1642017-03-29 21:08:16 -07003332 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möllerf06f9232018-08-07 12:32:18 +02003333 CreatePeerConnection(config);
deadbeef1dcb1642017-03-29 21:08:16 -07003334
3335 // First, create an offer with only a data channel and apply it as a remote
3336 // description.
Florent Castelli72424402022-04-06 03:45:10 +02003337 pc_->CreateDataChannelOrError("test", nullptr);
deadbeef1dcb1642017-03-29 21:08:16 -07003338 std::unique_ptr<SessionDescriptionInterface> offer;
3339 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003340 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003341
3342 // Create and set answer as well.
3343 std::unique_ptr<SessionDescriptionInterface> answer;
3344 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003345 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003346}
3347
Steve Anton36da6ff2018-02-16 16:04:20 -08003348TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003349 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003350 BitrateSettings bitrate;
3351 bitrate.start_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003352 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3353}
3354
Steve Anton36da6ff2018-02-16 16:04:20 -08003355TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003356 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003357 BitrateSettings bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003358 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003359 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3360}
3361
Steve Anton36da6ff2018-02-16 16:04:20 -08003362TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003363 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003364 BitrateSettings bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003365 bitrate.min_bitrate_bps = 5;
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003366 bitrate.start_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003367 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3368}
3369
Steve Anton36da6ff2018-02-16 16:04:20 -08003370TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003371 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003372 BitrateSettings bitrate;
3373 bitrate.start_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003374 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3375}
3376
Steve Anton36da6ff2018-02-16 16:04:20 -08003377TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003378 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003379 BitrateSettings bitrate;
3380 bitrate.start_bitrate_bps = 10;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003381 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003382 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3383}
3384
Steve Anton36da6ff2018-02-16 16:04:20 -08003385TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003386 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003387 BitrateSettings bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003388 bitrate.min_bitrate_bps = 10;
3389 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003390 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3391}
3392
Steve Anton36da6ff2018-02-16 16:04:20 -08003393TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003394 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003395 BitrateSettings bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003396 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003397 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3398}
3399
Niels Möller0c4f7be2018-05-07 14:01:37 +02003400// The current bitrate from BitrateSettings is currently clamped
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003401// by Call's BitrateConstraints, which comes from the SDP or a default value.
3402// This test checks that a call to SetBitrate with a current bitrate that will
3403// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003404TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003405 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003406 BitrateSettings bitrate;
3407 bitrate.start_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003408 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3409}
3410
zhihuang1c378ed2017-08-17 14:10:50 -07003411// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003412TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003413 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3414 RTCOfferAnswerOptions rtc_options;
3415
3416 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3417 // than kMaxOfferToReceiveMedia should be treated as invalid.
3418 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3419 CreatePeerConnection();
3420 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3421
3422 rtc_options.offer_to_receive_audio =
3423 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3424 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3425}
3426
Steve Anton36da6ff2018-02-16 16:04:20 -08003427TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003428 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3429 RTCOfferAnswerOptions rtc_options;
3430
3431 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3432 // than kMaxOfferToReceiveMedia should be treated as invalid.
3433 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3434 CreatePeerConnection();
3435 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3436
3437 rtc_options.offer_to_receive_video =
3438 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3439 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3440}
3441
3442// Test that the audio and video content will be added to an offer if both
Artem Titov880fa812021-07-30 22:30:23 +02003443// `offer_to_receive_audio` and `offer_to_receive_video` options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003444TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003445 RTCOfferAnswerOptions rtc_options;
3446 rtc_options.offer_to_receive_audio = 1;
3447 rtc_options.offer_to_receive_video = 1;
3448
3449 std::unique_ptr<SessionDescriptionInterface> offer;
3450 CreatePeerConnection();
3451 offer = CreateOfferWithOptions(rtc_options);
3452 ASSERT_TRUE(offer);
3453 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3454 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3455}
3456
3457// Test that only audio content will be added to the offer if only
Artem Titov880fa812021-07-30 22:30:23 +02003458// `offer_to_receive_audio` options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003459TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003460 RTCOfferAnswerOptions rtc_options;
3461 rtc_options.offer_to_receive_audio = 1;
3462 rtc_options.offer_to_receive_video = 0;
3463
3464 std::unique_ptr<SessionDescriptionInterface> offer;
3465 CreatePeerConnection();
3466 offer = CreateOfferWithOptions(rtc_options);
3467 ASSERT_TRUE(offer);
3468 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3469 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3470}
3471
Artem Titov880fa812021-07-30 22:30:23 +02003472// Test that only video content will be added if only `offer_to_receive_video`
zhihuang1c378ed2017-08-17 14:10:50 -07003473// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003474TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003475 RTCOfferAnswerOptions rtc_options;
3476 rtc_options.offer_to_receive_audio = 0;
3477 rtc_options.offer_to_receive_video = 1;
3478
3479 std::unique_ptr<SessionDescriptionInterface> offer;
3480 CreatePeerConnection();
3481 offer = CreateOfferWithOptions(rtc_options);
3482 ASSERT_TRUE(offer);
3483 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3484 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3485}
3486
zhihuang1c378ed2017-08-17 14:10:50 -07003487// Test that no media content will be added to the offer if using default
3488// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003489TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003490 RTCOfferAnswerOptions rtc_options;
3491
3492 std::unique_ptr<SessionDescriptionInterface> offer;
3493 CreatePeerConnection();
3494 offer = CreateOfferWithOptions(rtc_options);
3495 ASSERT_TRUE(offer);
3496 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3497 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3498}
3499
Artem Titov880fa812021-07-30 22:30:23 +02003500// Test that if `ice_restart` is true, the ufrag/pwd will change, otherwise
zhihuang1c378ed2017-08-17 14:10:50 -07003501// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003502TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3503 CreatePeerConnection();
3504
zhihuang1c378ed2017-08-17 14:10:50 -07003505 RTCOfferAnswerOptions rtc_options;
3506 rtc_options.ice_restart = false;
3507 rtc_options.offer_to_receive_audio = 1;
3508
3509 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003510 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003511 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3512 auto ufrag1 =
3513 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3514 auto pwd1 =
3515 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003516
Artem Titov880fa812021-07-30 22:30:23 +02003517 // `ice_restart` is false, the ufrag/pwd shouldn't change.
zhihuang1c378ed2017-08-17 14:10:50 -07003518 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003519 auto ufrag2 =
3520 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3521 auto pwd2 =
3522 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003523
Artem Titov880fa812021-07-30 22:30:23 +02003524 // `ice_restart` is true, the ufrag/pwd should change.
zhihuang1c378ed2017-08-17 14:10:50 -07003525 rtc_options.ice_restart = true;
3526 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003527 auto ufrag3 =
3528 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3529 auto pwd3 =
3530 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003531
3532 EXPECT_EQ(ufrag1, ufrag2);
3533 EXPECT_EQ(pwd1, pwd2);
3534 EXPECT_NE(ufrag2, ufrag3);
3535 EXPECT_NE(pwd2, pwd3);
3536}
3537
Artem Titov880fa812021-07-30 22:30:23 +02003538// Test that if `use_rtp_mux` is true, the bundling will be enabled in the
zhihuang1c378ed2017-08-17 14:10:50 -07003539// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003540TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003541 RTCOfferAnswerOptions rtc_options;
3542 rtc_options.offer_to_receive_audio = 1;
3543 rtc_options.offer_to_receive_video = 1;
3544
3545 std::unique_ptr<SessionDescriptionInterface> offer;
3546 CreatePeerConnection();
3547
3548 rtc_options.use_rtp_mux = true;
3549 offer = CreateOfferWithOptions(rtc_options);
3550 ASSERT_TRUE(offer);
3551 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3552 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3553 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3554
3555 rtc_options.use_rtp_mux = false;
3556 offer = CreateOfferWithOptions(rtc_options);
3557 ASSERT_TRUE(offer);
3558 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3559 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3560 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3561}
3562
zhihuang141aacb2017-08-29 13:23:53 -07003563// This test ensures OnRenegotiationNeeded is called when we add track with
3564// MediaStream -> AddTrack in the same way it is called when we add track with
3565// PeerConnection -> AddTrack.
3566// The test can be removed once addStream is rewritten in terms of addTrack
3567// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003568// Don't run under Unified Plan since the stream API is not available.
3569TEST_F(PeerConnectionInterfaceTestPlanB,
3570 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003571 CreatePeerConnectionWithoutDtls();
3572 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003573 pc_factory_->CreateLocalMediaStream(kStreamId1));
Niels Möllerafb246b2022-04-20 14:26:50 +02003574 pc_->AddStream(stream.get());
zhihuang141aacb2017-08-29 13:23:53 -07003575 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01003576 CreateAudioTrack("audio_track"));
zhihuang141aacb2017-08-29 13:23:53 -07003577 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01003578 CreateVideoTrack("video_track"));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00003579 stream->AddTrack(audio_track);
zhihuang141aacb2017-08-29 13:23:53 -07003580 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3581 observer_.renegotiation_needed_ = false;
3582
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003583 CreateOfferReceiveAnswer();
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00003584 stream->AddTrack(video_track);
zhihuang141aacb2017-08-29 13:23:53 -07003585 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3586 observer_.renegotiation_needed_ = false;
3587
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003588 CreateOfferReceiveAnswer();
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00003589 stream->RemoveTrack(audio_track);
zhihuang141aacb2017-08-29 13:23:53 -07003590 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3591 observer_.renegotiation_needed_ = false;
3592
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003593 CreateOfferReceiveAnswer();
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00003594 stream->RemoveTrack(video_track);
zhihuang141aacb2017-08-29 13:23:53 -07003595 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3596 observer_.renegotiation_needed_ = false;
3597}
3598
Zhi Huangb2d355e2017-10-26 17:26:37 -07003599// Tests that an error is returned if a description is applied that has fewer
3600// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003601TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003602 MediaSectionCountEnforcedForSubsequentOffer) {
3603 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003604 AddAudioTrack("audio_label");
3605 AddVideoTrack("video_label");
3606
Zhi Huangb2d355e2017-10-26 17:26:37 -07003607 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003608 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003609 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3610
3611 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003612 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003613 offer->description()->contents().pop_back();
3614 offer->description()->contents().pop_back();
3615 ASSERT_TRUE(offer->description()->contents().empty());
3616 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3617
3618 std::unique_ptr<SessionDescriptionInterface> answer;
3619 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3620 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3621
3622 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003623 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003624 offer->description()->contents().pop_back();
3625 offer->description()->contents().pop_back();
3626 ASSERT_TRUE(offer->description()->contents().empty());
3627 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3628}
3629
Johannes Kron89f874e2018-11-12 10:25:48 +01003630TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) {
3631 RTCConfiguration config;
Emil Lundmark801c9992021-01-19 13:06:32 +01003632 // Default behavior is true.
Johannes Kron89f874e2018-11-12 10:25:48 +01003633 CreatePeerConnection(config);
3634 std::unique_ptr<SessionDescriptionInterface> offer;
3635 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Emil Lundmark801c9992021-01-19 13:06:32 +01003636 EXPECT_TRUE(offer->description()->extmap_allow_mixed());
3637 // Possible to set to false.
3638 config.offer_extmap_allow_mixed = false;
Johannes Kron89f874e2018-11-12 10:25:48 +01003639 CreatePeerConnection(config);
Artem Titov4f3a2eb2021-01-26 09:58:21 +01003640 offer = nullptr;
Johannes Kron89f874e2018-11-12 10:25:48 +01003641 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Emil Lundmark801c9992021-01-19 13:06:32 +01003642 EXPECT_FALSE(offer->description()->extmap_allow_mixed());
Johannes Kron89f874e2018-11-12 10:25:48 +01003643}
3644
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003645INSTANTIATE_TEST_SUITE_P(PeerConnectionInterfaceTest,
3646 PeerConnectionInterfaceTest,
Florent Castelli15a38de2022-04-06 00:38:21 +02003647 Values(SdpSemantics::kPlanB_DEPRECATED,
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003648 SdpSemantics::kUnifiedPlan));
Steve Anton36da6ff2018-02-16 16:04:20 -08003649
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003650class PeerConnectionMediaConfigTest : public ::testing::Test {
nisse51542be2016-02-12 02:27:06 -08003651 protected:
3652 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07003653 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08003654 }
nisseeaabdf62017-05-05 02:23:02 -07003655 const cricket::MediaConfig TestCreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +02003656 const RTCConfiguration& config) {
Florent Castelli72424402022-04-06 03:45:10 +02003657 PeerConnectionDependencies pc_dependencies(&observer_);
3658 auto result =
3659 pcf_->CreatePeerConnectionOrError(config, std::move(pc_dependencies));
3660 EXPECT_TRUE(result.ok());
Niels Möllerafb246b2022-04-20 14:26:50 +02003661 observer_.SetPeerConnectionInterface(result.value().get());
Florent Castelli72424402022-04-06 03:45:10 +02003662 return result.value()->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08003663 }
3664
zhihuang9763d562016-08-05 11:14:50 -07003665 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003666 MockPeerConnectionObserver observer_;
3667};
3668
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003669// This sanity check validates the test infrastructure itself.
3670TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) {
3671 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003672 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
Florent Castelli72424402022-04-06 03:45:10 +02003673 PeerConnectionDependencies pc_dependencies(&observer_);
3674 auto result =
3675 pcf_->CreatePeerConnectionOrError(config, std::move(pc_dependencies));
3676 EXPECT_TRUE(result.ok());
Niels Möllerafb246b2022-04-20 14:26:50 +02003677 observer_.SetPeerConnectionInterface(result.value().get());
Florent Castelli72424402022-04-06 03:45:10 +02003678 result.value()->Close(); // No abort -> ok.
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003679 SUCCEED();
3680}
3681
nisse51542be2016-02-12 02:27:06 -08003682// This test verifies the default behaviour with no constraints and a
3683// default RTCConfiguration.
3684TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
3685 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003686 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
nisse51542be2016-02-12 02:27:06 -08003687
Niels Möllerf06f9232018-08-07 12:32:18 +02003688 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003689
Henrik Boström35c5cc82022-04-14 09:23:20 +02003690 EXPECT_TRUE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01003691 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
3692 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003693 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01003694 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08003695}
3696
Niels Möller1d7ecd22018-01-18 15:25:12 +01003697// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07003698// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08003699TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
3700 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003701 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
nisse51542be2016-02-12 02:27:06 -08003702
Niels Möller71bdda02016-03-31 12:59:59 +02003703 config.set_prerenderer_smoothing(false);
Niels Möllerf06f9232018-08-07 12:32:18 +02003704 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003705
Niels Möller1d7ecd22018-01-18 15:25:12 +01003706 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003707}
3708
Niels Möller6539f692018-01-18 08:58:50 +01003709// This test verifies that the experiment_cpu_load_estimator flag is
3710// propagated from RTCConfiguration to the PeerConnection.
3711TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
3712 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003713 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
Niels Möller6539f692018-01-18 08:58:50 +01003714
3715 config.set_experiment_cpu_load_estimator(true);
Niels Möllerf06f9232018-08-07 12:32:18 +02003716 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
Niels Möller6539f692018-01-18 08:58:50 +01003717
3718 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
3719}
3720
deadbeef293e9262017-01-11 12:28:30 -08003721// Tests a few random fields being different.
3722TEST(RTCConfigurationTest, ComparisonOperators) {
3723 PeerConnectionInterface::RTCConfiguration a;
3724 PeerConnectionInterface::RTCConfiguration b;
3725 EXPECT_EQ(a, b);
3726
3727 PeerConnectionInterface::RTCConfiguration c;
3728 c.servers.push_back(PeerConnectionInterface::IceServer());
3729 EXPECT_NE(a, c);
3730
3731 PeerConnectionInterface::RTCConfiguration d;
3732 d.type = PeerConnectionInterface::kRelay;
3733 EXPECT_NE(a, d);
3734
3735 PeerConnectionInterface::RTCConfiguration e;
3736 e.audio_jitter_buffer_max_packets = 5;
3737 EXPECT_NE(a, e);
3738
3739 PeerConnectionInterface::RTCConfiguration f;
3740 f.ice_connection_receiving_timeout = 1337;
3741 EXPECT_NE(a, f);
3742
3743 PeerConnectionInterface::RTCConfiguration g;
3744 g.disable_ipv6 = true;
3745 EXPECT_NE(a, g);
3746
3747 PeerConnectionInterface::RTCConfiguration h(
3748 PeerConnectionInterface::RTCConfigurationType::kAggressive);
3749 EXPECT_NE(a, h);
3750}
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +01003751
3752} // namespace
3753} // namespace webrtc