blob: f195b784c9ccfd957526a5094fd47a018fdd5814 [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(
Byoungchan Leed58f5262022-06-27 18:05:22 +0900731 new cricket::FakePortAllocator(
732 rtc::Thread::Current(),
733 std::make_unique<rtc::BasicPacketSocketFactory>(vss_.get())));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800734 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000735
deadbeef1dcb1642017-03-29 21:08:16 -0700736 // Create certificate generator unless DTLS constraint is explicitly set to
737 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200738 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
Niels Möllerf06f9232018-08-07 12:32:18 +0200739
Harald Alvestrandf9e502d2021-10-13 15:26:26 +0000740 // These won't be used if encryption is turned off, but that's harmless.
741 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
742 cert_generator.reset(fake_certificate_generator_);
743
Steve Anton36da6ff2018-02-16 16:04:20 -0800744 RTCConfiguration modified_config = config;
745 modified_config.sdp_semantics = sdp_semantics_;
Florent Castelli72424402022-04-06 03:45:10 +0200746 PeerConnectionDependencies pc_dependencies(&observer_);
747 pc_dependencies.cert_generator = std::move(cert_generator);
748 pc_dependencies.allocator = std::move(port_allocator);
749 auto result = pc_factory_->CreatePeerConnectionOrError(
750 modified_config, std::move(pc_dependencies));
751 ASSERT_TRUE(result.ok());
752 pc_ = result.MoveValue();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000753 observer_.SetPeerConnectionInterface(pc_.get());
754 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
755 }
756
deadbeef0a6c4ca2015-10-06 11:38:28 -0700757 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800758 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700759 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700760 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800761 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800762 config.sdp_semantics = sdp_semantics_;
Florent Castelli72424402022-04-06 03:45:10 +0200763 PeerConnectionDependencies pc_dependencies(&observer_);
764 auto result = pc_factory_->CreatePeerConnectionOrError(
765 config, std::move(pc_dependencies));
766 EXPECT_FALSE(result.ok());
deadbeef0a6c4ca2015-10-06 11:38:28 -0700767 }
768
Steve Anton038834f2017-07-14 15:59:59 -0700769 void CreatePeerConnectionExpectFail(
770 PeerConnectionInterface::RTCConfiguration config) {
771 PeerConnectionInterface::IceServer server;
772 server.uri = kTurnIceServerUri;
773 server.password = kTurnPassword;
774 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800775 config.sdp_semantics = sdp_semantics_;
Florent Castelli72424402022-04-06 03:45:10 +0200776 PeerConnectionDependencies pc_dependencies(&observer_);
777 auto result = pc_factory_->CreatePeerConnectionOrError(
778 config, std::move(pc_dependencies));
779 EXPECT_FALSE(result.ok());
Steve Anton038834f2017-07-14 15:59:59 -0700780 }
781
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000782 void CreatePeerConnectionWithDifferentConfigurations() {
Niels Möllerdb4def92019-03-18 16:53:59 +0100783 CreatePeerConnectionWithIceServer(kStunAddressOnly, "", "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800784 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
785 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
786 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800788 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789
deadbeef0a6c4ca2015-10-06 11:38:28 -0700790 CreatePeerConnectionExpectFail(kStunInvalidPort);
791 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
792 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793
Niels Möllerdb4def92019-03-18 16:53:59 +0100794 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnUsername,
795 kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800796 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
797 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800799 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800801 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800803 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 }
805
806 void ReleasePeerConnection() {
Niels Möllerafb246b2022-04-20 14:26:50 +0200807 pc_ = nullptr;
808 observer_.SetPeerConnectionInterface(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 }
810
Steve Anton36da6ff2018-02-16 16:04:20 -0800811 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
812 const std::string& label) {
Niels Möllerafb246b2022-04-20 14:26:50 +0200813 return pc_factory_->CreateVideoTrack(label,
814 FakeVideoTrackSource::Create().get());
Steve Anton36da6ff2018-02-16 16:04:20 -0800815 }
816
817 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800818 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800819 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800820 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800821 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 }
823
Steve Anton36da6ff2018-02-16 16:04:20 -0800824 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700825 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000826 pc_factory_->CreateLocalMediaStream(label));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +0000827 stream->AddTrack(CreateVideoTrack(label + "v0"));
Niels Möllerafb246b2022-04-20 14:26:50 +0200828 ASSERT_TRUE(pc_->AddStream(stream.get()));
Steve Anton36da6ff2018-02-16 16:04:20 -0800829 }
830
831 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
832 const std::string& label) {
833 return pc_factory_->CreateAudioTrack(label, nullptr);
834 }
835
836 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800837 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800838 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800839 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800840 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
Steve Anton36da6ff2018-02-16 16:04:20 -0800841 }
842
843 void AddAudioStream(const std::string& label) {
844 rtc::scoped_refptr<MediaStreamInterface> stream(
845 pc_factory_->CreateLocalMediaStream(label));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +0000846 stream->AddTrack(CreateAudioTrack(label + "a0"));
Niels Möllerafb246b2022-04-20 14:26:50 +0200847 ASSERT_TRUE(pc_->AddStream(stream.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848 }
849
Seth Hampson845e8782018-03-02 11:34:10 -0800850 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 const std::string& audio_track_label,
852 const std::string& video_track_label) {
853 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700854 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800855 pc_factory_->CreateLocalMediaStream(stream_id));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +0000856 stream->AddTrack(CreateAudioTrack(audio_track_label));
857 stream->AddTrack(CreateVideoTrack(video_track_label));
Niels Möllerafb246b2022-04-20 14:26:50 +0200858 ASSERT_TRUE(pc_->AddStream(stream.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859 }
860
Steve Anton36da6ff2018-02-16 16:04:20 -0800861 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
862 cricket::MediaType media_type) {
863 for (auto receiver : pc_->GetReceivers()) {
864 if (receiver->media_type() == media_type) {
865 return receiver;
866 }
867 }
868 return nullptr;
869 }
870
kwibergd1fe2812016-04-27 06:47:29 -0700871 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200872 const RTCOfferAnswerOptions* options,
873 bool offer) {
Tommi87f70902021-04-27 14:43:08 +0200874 auto observer =
875 rtc::make_ref_counted<MockCreateSessionDescriptionObserver>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 if (offer) {
Niels Möllerafb246b2022-04-20 14:26:50 +0200877 pc_->CreateOffer(observer.get(),
878 options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 } else {
Niels Möllerafb246b2022-04-20 14:26:50 +0200880 pc_->CreateAnswer(observer.get(),
881 options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882 }
883 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700884 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 return observer->result();
886 }
887
kwibergd1fe2812016-04-27 06:47:29 -0700888 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200889 const RTCOfferAnswerOptions* options) {
890 return DoCreateOfferAnswer(desc, options, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891 }
892
kwibergd1fe2812016-04-27 06:47:29 -0700893 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200894 const RTCOfferAnswerOptions* options) {
895 return DoCreateOfferAnswer(desc, options, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896 }
897
Steve Antondb45ca82017-09-11 18:27:34 -0700898 bool DoSetSessionDescription(
899 std::unique_ptr<SessionDescriptionInterface> desc,
900 bool local) {
Tommi87f70902021-04-27 14:43:08 +0200901 auto observer = rtc::make_ref_counted<MockSetSessionDescriptionObserver>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 if (local) {
Niels Möllerafb246b2022-04-20 14:26:50 +0200903 pc_->SetLocalDescription(observer.get(), desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904 } else {
Niels Möllerafb246b2022-04-20 14:26:50 +0200905 pc_->SetRemoteDescription(observer.get(), desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906 }
zhihuang29ff8442016-07-27 11:07:25 -0700907 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
908 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
909 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910 return observer->result();
911 }
912
Steve Antondb45ca82017-09-11 18:27:34 -0700913 bool DoSetLocalDescription(
914 std::unique_ptr<SessionDescriptionInterface> desc) {
915 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 }
917
Steve Antondb45ca82017-09-11 18:27:34 -0700918 bool DoSetRemoteDescription(
919 std::unique_ptr<SessionDescriptionInterface> desc) {
920 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921 }
922
923 // Calls PeerConnection::GetStats and check the return value.
924 // It does not verify the values in the StatReports since a RTCP packet might
925 // be required.
926 bool DoGetStats(MediaStreamTrackInterface* track) {
Tommi87f70902021-04-27 14:43:08 +0200927 auto observer = rtc::make_ref_counted<MockStatsObserver>();
Niels Möllerafb246b2022-04-20 14:26:50 +0200928 if (!pc_->GetStats(observer.get(), track,
Yves Gerey665174f2018-06-19 15:03:05 +0200929 PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930 return false;
931 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
932 return observer->called();
933 }
934
Harald Alvestrand89061872018-01-02 14:08:34 +0100935 // Call the standards-compliant GetStats function.
936 bool DoGetRTCStats() {
Tommi87f70902021-04-27 14:43:08 +0200937 auto callback =
938 rtc::make_ref_counted<webrtc::MockRTCStatsCollectorCallback>();
Niels Möllerafb246b2022-04-20 14:26:50 +0200939 pc_->GetStats(callback.get());
Harald Alvestrand89061872018-01-02 14:08:34 +0100940 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
941 return callback->called();
942 }
943
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800945 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000946 // Create a local stream with audio&video tracks.
Florent Castelli15a38de2022-04-06 00:38:21 +0200947 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Seth Hampson845e8782018-03-02 11:34:10 -0800948 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800949 } else {
950 // Unified Plan does not support AddStream, so just add an audio and video
951 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800952 AddAudioTrack(kAudioTracks[0], {kStreamId1});
953 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800954 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 CreateOfferReceiveAnswer();
956 }
957
958 // Verify that RTP Header extensions has been negotiated for audio and video.
959 void VerifyRemoteRtpHeaderExtensions() {
960 const cricket::MediaContentDescription* desc =
961 cricket::GetFirstAudioContentDescription(
962 pc_->remote_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +0200963 ASSERT_TRUE(desc != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
965
966 desc = cricket::GetFirstVideoContentDescription(
967 pc_->remote_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +0200968 ASSERT_TRUE(desc != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
970 }
971
972 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700973 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700974 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 std::string sdp;
976 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700977 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800978 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700979 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000980 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
981 }
982
deadbeefab9b2d12015-10-14 11:33:11 -0700983 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -0700984 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800985 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700986 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -0700987 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
988 }
989
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700991 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -0700992 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000993
994 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
995 // audio codec change, even if the parameter has nothing to do with
996 // receiving. Not all parameters are serialized to SDP.
997 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
998 // the SessionDescription, it is necessary to do that here to in order to
999 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1000 // https://code.google.com/p/webrtc/issues/detail?id=1356
1001 std::string sdp;
1002 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001003 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001004 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001005 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001006 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1007 }
1008
1009 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001010 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001011 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001012
1013 std::string sdp;
1014 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001015 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001016 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001017 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001018 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1019 }
1020
1021 void CreateOfferReceiveAnswer() {
1022 CreateOfferAsLocalDescription();
1023 std::string sdp;
1024 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1025 CreateAnswerAsRemoteDescription(sdp);
1026 }
1027
1028 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001029 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001030 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001031 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1032 // audio codec change, even if the parameter has nothing to do with
1033 // receiving. Not all parameters are serialized to SDP.
1034 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1035 // the SessionDescription, it is necessary to do that here to in order to
1036 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1037 // https://code.google.com/p/webrtc/issues/detail?id=1356
1038 std::string sdp;
1039 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001040 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001041 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001042
Steve Antondb45ca82017-09-11 18:27:34 -07001043 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001044 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001045 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001046 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001047 }
1048
deadbeefab9b2d12015-10-14 11:33:11 -07001049 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001050 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001051 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001052 ASSERT_TRUE(answer);
1053 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001054 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1055 }
1056
deadbeefab9b2d12015-10-14 11:33:11 -07001057 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001058 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001059 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001060 ASSERT_TRUE(pr_answer);
1061 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001062 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001063 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001064 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001065 ASSERT_TRUE(answer);
1066 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001067 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1068 }
1069
Seth Hampson845e8782018-03-02 11:34:10 -08001070 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001071 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001072 // called with the given stream id and expected number of tracks.
1073 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001074 int expected_num_tracks) {
1075 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001076 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001077 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001078 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001079 }
1080
1081 // Creates an offer and applies it as a local session description.
1082 // Creates an answer with the same SDP an the offer but removes all lines
1083 // that start with a:ssrc"
1084 void CreateOfferReceiveAnswerWithoutSsrc() {
1085 CreateOfferAsLocalDescription();
1086 std::string sdp;
1087 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1088 SetSsrcToZero(&sdp);
1089 CreateAnswerAsRemoteDescription(sdp);
1090 }
1091
deadbeefab9b2d12015-10-14 11:33:11 -07001092 // This function creates a MediaStream with label kStreams[0] and
Artem Titov880fa812021-07-30 22:30:23 +02001093 // `number_of_audio_tracks` and `number_of_video_tracks` tracks and the
deadbeefab9b2d12015-10-14 11:33:11 -07001094 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001095 // is returned and the MediaStream is stored in
Artem Titov880fa812021-07-30 22:30:23 +02001096 // `reference_collection_`
kwibergd1fe2812016-04-27 06:47:29 -07001097 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001098 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1099 size_t number_of_video_tracks) {
1100 EXPECT_LE(number_of_audio_tracks, 2u);
1101 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001102
1103 reference_collection_ = StreamCollection::Create();
1104 std::string sdp_ms1 = std::string(kSdpStringInit);
1105
Seth Hampson845e8782018-03-02 11:34:10 -08001106 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001107
1108 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001109 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001110 reference_collection_->AddStream(stream);
1111
1112 if (number_of_audio_tracks > 0) {
1113 sdp_ms1 += std::string(kSdpStringAudio);
1114 sdp_ms1 += std::string(kSdpStringMs1Audio0);
Niels Möllerafb246b2022-04-20 14:26:50 +02001115 AddAudioTrack(kAudioTracks[0], stream.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001116 }
1117 if (number_of_audio_tracks > 1) {
1118 sdp_ms1 += kSdpStringMs1Audio1;
Niels Möllerafb246b2022-04-20 14:26:50 +02001119 AddAudioTrack(kAudioTracks[1], stream.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001120 }
1121
1122 if (number_of_video_tracks > 0) {
1123 sdp_ms1 += std::string(kSdpStringVideo);
1124 sdp_ms1 += std::string(kSdpStringMs1Video0);
Niels Möllerafb246b2022-04-20 14:26:50 +02001125 AddVideoTrack(kVideoTracks[0], stream.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001126 }
1127 if (number_of_video_tracks > 1) {
1128 sdp_ms1 += kSdpStringMs1Video1;
Niels Möllerafb246b2022-04-20 14:26:50 +02001129 AddVideoTrack(kVideoTracks[1], stream.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001130 }
1131
kwibergd1fe2812016-04-27 06:47:29 -07001132 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001133 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001134 }
1135
1136 void AddAudioTrack(const std::string& track_id,
1137 MediaStreamInterface* stream) {
1138 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1139 webrtc::AudioTrack::Create(track_id, nullptr));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00001140 ASSERT_TRUE(stream->AddTrack(audio_track));
deadbeefab9b2d12015-10-14 11:33:11 -07001141 }
1142
1143 void AddVideoTrack(const std::string& track_id,
1144 MediaStreamInterface* stream) {
1145 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001146 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001147 webrtc::FakeVideoTrackSource::Create(),
1148 rtc::Thread::Current()));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00001149 ASSERT_TRUE(stream->AddTrack(video_track));
deadbeefab9b2d12015-10-14 11:33:11 -07001150 }
1151
Steve Anton36da6ff2018-02-16 16:04:20 -08001152 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001153 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001154 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001155 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001156 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1157 return offer;
1158 }
1159
Steve Anton36da6ff2018-02-16 16:04:20 -08001160 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1161 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001162 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001163 std::unique_ptr<SessionDescriptionInterface> offer;
1164 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1165 return offer;
1166 }
1167
1168 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1169 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1170 std::unique_ptr<SessionDescriptionInterface> answer;
1171 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1172 return answer;
1173 }
1174
kwibergfd8be342016-05-14 19:44:11 -07001175 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001176 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001177 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001178 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001179 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1180 return answer;
1181 }
1182
1183 const std::string& GetFirstAudioStreamCname(
1184 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001185 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001186 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001187 return audio_desc->streams()[0].cname;
1188 }
1189
zhihuang1c378ed2017-08-17 14:10:50 -07001190 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1191 const RTCOfferAnswerOptions& offer_answer_options) {
1192 RTC_DCHECK(pc_);
Tommi87f70902021-04-27 14:43:08 +02001193 auto observer =
1194 rtc::make_ref_counted<MockCreateSessionDescriptionObserver>();
Niels Möllerafb246b2022-04-20 14:26:50 +02001195 pc_->CreateOffer(observer.get(), offer_answer_options);
zhihuang1c378ed2017-08-17 14:10:50 -07001196 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1197 return observer->MoveDescription();
1198 }
1199
1200 void CreateOfferWithOptionsAsRemoteDescription(
1201 std::unique_ptr<SessionDescriptionInterface>* desc,
1202 const RTCOfferAnswerOptions& offer_answer_options) {
1203 *desc = CreateOfferWithOptions(offer_answer_options);
1204 ASSERT_TRUE(desc != nullptr);
1205 std::string sdp;
1206 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001207 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001208 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001209 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001210 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1211 }
1212
1213 void CreateOfferWithOptionsAsLocalDescription(
1214 std::unique_ptr<SessionDescriptionInterface>* desc,
1215 const RTCOfferAnswerOptions& offer_answer_options) {
1216 *desc = CreateOfferWithOptions(offer_answer_options);
1217 ASSERT_TRUE(desc != nullptr);
1218 std::string sdp;
1219 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001220 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001221 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001222
Steve Antondb45ca82017-09-11 18:27:34 -07001223 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001224 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1225 }
1226
1227 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001228 RTC_DCHECK(content);
1229 RTC_DCHECK(content->media_description());
1230 for (const cricket::AudioCodec& codec :
1231 content->media_description()->as_audio()->codecs()) {
1232 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001233 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001234 }
zhihuang1c378ed2017-08-17 14:10:50 -07001235 }
1236 return false;
1237 }
1238
Steve Anton36da6ff2018-02-16 16:04:20 -08001239 const char* GetSdpStringWithStream1() const {
Florent Castelli15a38de2022-04-06 00:38:21 +02001240 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Steve Anton36da6ff2018-02-16 16:04:20 -08001241 return kSdpStringWithStream1PlanB;
1242 } else {
1243 return kSdpStringWithStream1UnifiedPlan;
1244 }
1245 }
1246
1247 const char* GetSdpStringWithStream1And2() const {
Florent Castelli15a38de2022-04-06 00:38:21 +02001248 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Steve Anton36da6ff2018-02-16 16:04:20 -08001249 return kSdpStringWithStream1And2PlanB;
1250 } else {
1251 return kSdpStringWithStream1And2UnifiedPlan;
1252 }
1253 }
1254
Byoungchan Leed58f5262022-06-27 18:05:22 +09001255 rtc::SocketServer* socket_server() const { return vss_.get(); }
1256
deadbeef9a6f4d42017-05-15 19:43:33 -07001257 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1258 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001259 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001260 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001261 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001262 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1263 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1264 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001265 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001266 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001267 const SdpSemantics sdp_semantics_;
1268};
1269
1270class PeerConnectionInterfaceTest
1271 : public PeerConnectionInterfaceBaseTest,
1272 public ::testing::WithParamInterface<SdpSemantics> {
1273 protected:
1274 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1275};
1276
1277class PeerConnectionInterfaceTestPlanB
1278 : public PeerConnectionInterfaceBaseTest {
1279 protected:
1280 PeerConnectionInterfaceTestPlanB()
Florent Castelli15a38de2022-04-06 00:38:21 +02001281 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB_DEPRECATED) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001282};
1283
zhihuang8f65cdf2016-05-06 18:40:30 -07001284// Generate different CNAMEs when PeerConnections are created.
1285// The CNAMEs are expected to be generated randomly. It is possible
1286// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001287TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001288 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001289 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001290 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001291 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001292 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1293 GetFirstAudioStreamCname(offer2.get()));
1294}
1295
Steve Anton36da6ff2018-02-16 16:04:20 -08001296TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001297 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001298 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001299 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001300 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001301 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1302 GetFirstAudioStreamCname(answer2.get()));
1303}
1304
Steve Anton36da6ff2018-02-16 16:04:20 -08001305TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001306 CreatePeerConnectionWithDifferentConfigurations) {
1307 CreatePeerConnectionWithDifferentConfigurations();
1308}
1309
Steve Anton36da6ff2018-02-16 16:04:20 -08001310TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001311 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1312 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1313 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1314 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1315 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1316 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1317 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1318 port_allocator_->candidate_filter());
1319 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1320 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1321}
1322
1323// Test that when a PeerConnection is created with a nonzero candidate pool
1324// size, the pooled PortAllocatorSession is created with all the attributes
1325// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001326TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001327 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01001328 config.sdp_semantics = sdp_semantics_;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001329 PeerConnectionInterface::IceServer server;
1330 server.uri = kStunAddressOnly;
1331 config.servers.push_back(server);
1332 config.type = PeerConnectionInterface::kRelay;
1333 config.disable_ipv6 = true;
1334 config.tcp_candidate_policy =
1335 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001336 config.candidate_network_policy =
1337 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001338 config.ice_candidate_pool_size = 1;
Niels Möllerf06f9232018-08-07 12:32:18 +02001339 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001340
1341 const cricket::FakePortAllocatorSession* session =
1342 static_cast<const cricket::FakePortAllocatorSession*>(
1343 port_allocator_->GetPooledSession());
1344 ASSERT_NE(nullptr, session);
1345 EXPECT_EQ(1UL, session->stun_servers().size());
1346 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1347 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001348 EXPECT_LT(0U,
1349 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001350}
1351
deadbeefd21eab32017-07-26 16:50:11 -07001352// Test that network-related RTCConfiguration members are applied to the
1353// PortAllocator when CreatePeerConnection is called. Specifically:
1354// - disable_ipv6_on_wifi
1355// - max_ipv6_networks
1356// - tcp_candidate_policy
1357// - candidate_network_policy
1358// - prune_turn_ports
1359//
1360// Note that the candidate filter (RTCConfiguration::type) is already tested
1361// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001362TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001363 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1364 // Create fake port allocator.
Byoungchan Leed58f5262022-06-27 18:05:22 +09001365 std::unique_ptr<rtc::PacketSocketFactory> packet_socket_factory(
1366 new rtc::BasicPacketSocketFactory(socket_server()));
deadbeefd21eab32017-07-26 16:50:11 -07001367 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Byoungchan Leed58f5262022-06-27 18:05:22 +09001368 new cricket::FakePortAllocator(rtc::Thread::Current(),
1369 packet_socket_factory.get()));
deadbeefd21eab32017-07-26 16:50:11 -07001370 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1371
1372 // Create RTCConfiguration with some network-related fields relevant to
1373 // PortAllocator populated.
1374 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01001375 config.sdp_semantics = sdp_semantics_;
deadbeefd21eab32017-07-26 16:50:11 -07001376 config.disable_ipv6_on_wifi = true;
1377 config.max_ipv6_networks = 10;
1378 config.tcp_candidate_policy =
1379 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1380 config.candidate_network_policy =
1381 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1382 config.prune_turn_ports = true;
1383
1384 // Create the PC factory and PC with the above config.
1385 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1386 webrtc::CreatePeerConnectionFactory(
1387 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001388 rtc::Thread::Current(), fake_audio_capture_module_,
1389 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +02001390 webrtc::CreateBuiltinAudioDecoderFactory(),
1391 webrtc::CreateBuiltinVideoEncoderFactory(),
1392 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1393 nullptr /* audio_processing */));
Florent Castelli72424402022-04-06 03:45:10 +02001394 PeerConnectionDependencies pc_dependencies(&observer_);
1395 pc_dependencies.allocator = std::move(port_allocator);
1396 auto result = pc_factory_->CreatePeerConnectionOrError(
1397 config, std::move(pc_dependencies));
1398 EXPECT_TRUE(result.ok());
Niels Möllerafb246b2022-04-20 14:26:50 +02001399 observer_.SetPeerConnectionInterface(result.value().get());
deadbeefd21eab32017-07-26 16:50:11 -07001400
1401 // Now validate that the config fields set above were applied to the
1402 // PortAllocator, as flags or otherwise.
1403 EXPECT_FALSE(raw_port_allocator->flags() &
1404 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1405 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1406 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1407 EXPECT_TRUE(raw_port_allocator->flags() &
1408 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Honghai Zhangf8998cf2019-10-14 11:27:50 -07001409 EXPECT_EQ(webrtc::PRUNE_BASED_ON_PRIORITY,
1410 raw_port_allocator->turn_port_prune_policy());
deadbeefd21eab32017-07-26 16:50:11 -07001411}
1412
deadbeef46c73892016-11-16 19:42:04 -08001413// Check that GetConfiguration returns the configuration the PeerConnection was
1414// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001415TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001416 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01001417 config.sdp_semantics = sdp_semantics_;
deadbeef46c73892016-11-16 19:42:04 -08001418 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02001419 CreatePeerConnection(config);
deadbeef46c73892016-11-16 19:42:04 -08001420
1421 PeerConnectionInterface::RTCConfiguration returned_config =
1422 pc_->GetConfiguration();
1423 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1424}
1425
1426// Check that GetConfiguration returns the last configuration passed into
1427// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001428TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001429 PeerConnectionInterface::RTCConfiguration starting_config;
Henrik Boström62995db2022-01-03 09:58:10 +01001430 starting_config.sdp_semantics = sdp_semantics_;
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001431 starting_config.bundle_policy =
1432 webrtc::PeerConnection::kBundlePolicyMaxBundle;
1433 CreatePeerConnection(starting_config);
deadbeef46c73892016-11-16 19:42:04 -08001434
Steve Anton36da6ff2018-02-16 16:04:20 -08001435 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001436 config.type = PeerConnectionInterface::kRelay;
Niels Möller2579f0c2019-08-19 09:58:17 +02001437 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef46c73892016-11-16 19:42:04 -08001438
1439 PeerConnectionInterface::RTCConfiguration returned_config =
1440 pc_->GetConfiguration();
1441 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1442}
1443
Steve Antonc79268f2018-04-24 09:54:10 -07001444TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1445 CreatePeerConnection();
1446
1447 pc_->Close();
1448
1449 EXPECT_FALSE(
Niels Möller2579f0c2019-08-19 09:58:17 +02001450 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()).ok());
Steve Antonc79268f2018-04-24 09:54:10 -07001451}
1452
Steve Anton36da6ff2018-02-16 16:04:20 -08001453TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001454 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001455 AddVideoStream(kStreamId1);
1456 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001457 ASSERT_EQ(2u, pc_->local_streams()->count());
1458
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001459 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001460 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001461 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001462 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möllerafb246b2022-04-20 14:26:50 +02001463 pc_factory_->CreateAudioTrack(
1464 kStreamId3, static_cast<AudioSourceInterface*>(nullptr)));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00001465 stream->AddTrack(audio_track);
Niels Möllerafb246b2022-04-20 14:26:50 +02001466 EXPECT_TRUE(pc_->AddStream(stream.get()));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001467 EXPECT_EQ(3u, pc_->local_streams()->count());
1468
1469 // Remove the third stream.
1470 pc_->RemoveStream(pc_->local_streams()->at(2));
1471 EXPECT_EQ(2u, pc_->local_streams()->count());
1472
1473 // Remove the second stream.
1474 pc_->RemoveStream(pc_->local_streams()->at(1));
1475 EXPECT_EQ(1u, pc_->local_streams()->count());
1476
1477 // Remove the first stream.
1478 pc_->RemoveStream(pc_->local_streams()->at(0));
1479 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001480}
1481
deadbeefab9b2d12015-10-14 11:33:11 -07001482// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001483// Don't run under Unified Plan since the stream API is not available.
1484TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001485 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001486 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001487 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001488 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001489
deadbeefab9b2d12015-10-14 11:33:11 -07001490 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001491 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001492 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001493
deadbeefab9b2d12015-10-14 11:33:11 -07001494 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001495 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001496 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001497
1498 // Add another stream and ensure the offer includes both the old and new
1499 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001500 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001501 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001502
Steve Antonb1c1de12017-12-21 15:14:30 -08001503 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001504 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1505 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001506
Steve Antonb1c1de12017-12-21 15:14:30 -08001507 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001508 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1509 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001510}
1511
Steve Anton36da6ff2018-02-16 16:04:20 -08001512// Don't run under Unified Plan since the stream API is not available.
1513TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001514 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001515 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001516 ASSERT_EQ(1u, pc_->local_streams()->count());
1517 pc_->RemoveStream(pc_->local_streams()->at(0));
1518 EXPECT_EQ(0u, pc_->local_streams()->count());
1519}
1520
deadbeefe1f9d832016-01-14 15:35:42 -08001521// Test for AddTrack and RemoveTrack methods.
1522// Tests that the created offer includes tracks we added,
1523// and that the RtpSenders are created correctly.
1524// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001525// Only tested with Plan B since Unified Plan is covered in more detail by tests
1526// in peerconnection_jsep_unittests.cc
1527TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001528 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001529 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001530 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001531 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001532 CreateVideoTrack("video_track"));
Seth Hampson845e8782018-03-02 11:34:10 -08001533 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1534 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001535 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001536 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001537 EXPECT_EQ("audio_track", audio_sender->id());
1538 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001539 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001540 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001541 EXPECT_EQ("video_track", video_sender->id());
1542 EXPECT_EQ(video_track, video_sender->track());
1543
1544 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001545 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001546 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001547
1548 const cricket::ContentInfo* audio_content =
1549 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001550 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001551 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001552
1553 const cricket::ContentInfo* video_content =
1554 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001555 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001556 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001557
Steve Antondb45ca82017-09-11 18:27:34 -07001558 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001559
1560 // Now try removing the tracks.
Harald Alvestrand93dd7632022-01-19 12:28:45 +00001561 EXPECT_TRUE(pc_->RemoveTrackOrError(audio_sender).ok());
1562 EXPECT_TRUE(pc_->RemoveTrackOrError(video_sender).ok());
deadbeefe1f9d832016-01-14 15:35:42 -08001563
1564 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001565 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001566
1567 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001568 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001569 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001570
1571 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001572 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001573 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001574
Steve Antondb45ca82017-09-11 18:27:34 -07001575 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001576
1577 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1578 // should return false.
Harald Alvestrand93dd7632022-01-19 12:28:45 +00001579 EXPECT_FALSE(pc_->RemoveTrackOrError(audio_sender).ok());
1580 EXPECT_FALSE(pc_->RemoveTrackOrError(video_sender).ok());
deadbeefe1f9d832016-01-14 15:35:42 -08001581}
1582
1583// Test creating senders without a stream specified,
1584// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001585TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001586 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001587 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001588 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001589 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001590 CreateVideoTrack("video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001591 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001592 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001593 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001594 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001595 EXPECT_EQ("audio_track", audio_sender->id());
1596 EXPECT_EQ(audio_track, audio_sender->track());
1597 EXPECT_EQ("video_track", video_sender->id());
1598 EXPECT_EQ(video_track, video_sender->track());
Florent Castelli15a38de2022-04-06 00:38:21 +02001599 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001600 // If the ID is truly a random GUID, it should be infinitely unlikely they
1601 // will be the same.
1602 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1603 } else {
1604 // We allows creating tracks without stream ids under Unified Plan
1605 // semantics.
1606 EXPECT_EQ(0u, video_sender->stream_ids().size());
1607 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1608 }
deadbeefe1f9d832016-01-14 15:35:42 -08001609}
1610
Harald Alvestrand89061872018-01-02 14:08:34 +01001611// Test that we can call GetStats() after AddTrack but before connecting
1612// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001613TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001614 CreatePeerConnectionWithoutDtls();
1615 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001616 CreateAudioTrack("audio_track"));
Harald Alvestrand89061872018-01-02 14:08:34 +01001617 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001618 CreateVideoTrack("video_track"));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001619 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1620 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001621 EXPECT_TRUE(DoGetStats(nullptr));
1622}
1623
Steve Anton36da6ff2018-02-16 16:04:20 -08001624TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001625 CreatePeerConnectionWithoutDtls();
1626 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001627 CreateAudioTrack("audio_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001628 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001629 CreateVideoTrack("video_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001630 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001631 ASSERT_TRUE(audio_sender.ok());
1632 auto* audio_sender_proxy =
1633 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1634 audio_sender.value().get());
1635 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1636
Harald Alvestrandc72af932018-01-11 17:18:19 +01001637 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001638 ASSERT_TRUE(video_sender.ok());
1639 auto* video_sender_proxy =
1640 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1641 video_sender.value().get());
1642 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001643}
1644
Steve Anton36da6ff2018-02-16 16:04:20 -08001645// Don't run under Unified Plan since the stream API is not available.
1646TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001647 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001648 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001649 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001650 ASSERT_EQ(1u, senders.size());
1651 auto* sender_proxy =
1652 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1653 senders[0].get());
1654 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001655}
1656
Steve Anton36da6ff2018-02-16 16:04:20 -08001657TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001658 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001659 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001660 VerifyRemoteRtpHeaderExtensions();
1661}
1662
Steve Anton36da6ff2018-02-16 16:04:20 -08001663TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001664 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001665 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001666 CreateOfferAsLocalDescription();
1667 std::string offer;
1668 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1669 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001670 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001671}
1672
Steve Anton36da6ff2018-02-16 16:04:20 -08001673TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001674 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001675 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001676
1677 CreateOfferAsRemoteDescription();
1678 CreateAnswerAsLocalDescription();
1679
Seth Hampson845e8782018-03-02 11:34:10 -08001680 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001681}
1682
Steve Anton36da6ff2018-02-16 16:04:20 -08001683TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001684 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001685 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686
1687 CreateOfferAsRemoteDescription();
1688 CreatePrAnswerAsLocalDescription();
1689 CreateAnswerAsLocalDescription();
1690
Seth Hampson845e8782018-03-02 11:34:10 -08001691 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001692}
1693
Steve Anton36da6ff2018-02-16 16:04:20 -08001694// Don't run under Unified Plan since the stream API is not available.
1695TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696 InitiateCall();
1697 ASSERT_EQ(1u, pc_->remote_streams()->count());
1698 pc_->RemoveStream(pc_->local_streams()->at(0));
1699 CreateOfferReceiveAnswer();
1700 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001701 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001702 CreateOfferReceiveAnswer();
1703}
1704
1705// Tests that after negotiating an audio only call, the respondent can perform a
1706// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001707TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001708 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001709 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001710 CreateOfferAsRemoteDescription();
1711 CreateAnswerAsLocalDescription();
1712
1713 ASSERT_EQ(1u, pc_->remote_streams()->count());
1714 pc_->RemoveStream(pc_->local_streams()->at(0));
1715 CreateOfferReceiveAnswer();
1716 EXPECT_EQ(0u, pc_->remote_streams()->count());
1717}
1718
1719// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001720TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001721 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722
Steve Antonf1c6db12017-10-13 11:13:35 -07001723 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001724 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001725 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001726 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001727 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001728 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729
1730 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001731 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001732 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001733 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001734
Steve Antonf1c6db12017-10-13 11:13:35 -07001735 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001736 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737
Steve Antonf1c6db12017-10-13 11:13:35 -07001738 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001739}
1740
deadbeefab9b2d12015-10-14 11:33:11 -07001741// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001742// not unique.
Steve Anton07563732018-06-26 11:13:50 -07001743TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001744 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001746 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001747 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001748 EXPECT_TRUE(offer);
1749 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750
1751 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001752 AddAudioTrack("track_label", {kStreamId1});
1753 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754
1755 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001756 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757
1758 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001759 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001760 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761}
1762
1763// Test that we will get different SSRCs for each tracks in the offer and answer
1764// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001765TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001766 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001768 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1769 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001770
1771 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001772 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001773 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001774 int audio_ssrc = 0;
1775 int video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001776 EXPECT_TRUE(
1777 GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc));
1778 EXPECT_TRUE(
1779 GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001780 EXPECT_NE(audio_ssrc, video_ssrc);
1781
1782 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001783 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001784 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001785 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 audio_ssrc = 0;
1787 video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001788 EXPECT_TRUE(
1789 GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc));
1790 EXPECT_TRUE(
1791 GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792 EXPECT_NE(audio_ssrc, video_ssrc);
1793}
1794
deadbeefeb459812015-12-15 19:24:43 -08001795// Test that it's possible to call AddTrack on a MediaStream after adding
1796// the stream to a PeerConnection.
1797// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001798// Don't run under Unified Plan since the stream API is not available.
1799TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001800 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001801 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001802 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001803 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1804
1805 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001806 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001807 CreateVideoTrack("video_label"));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00001808 stream->AddTrack(video_track);
deadbeefeb459812015-12-15 19:24:43 -08001809
kwibergd1fe2812016-04-27 06:47:29 -07001810 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001811 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001812
1813 const cricket::MediaContentDescription* video_desc =
1814 cricket::GetFirstVideoContentDescription(offer->description());
1815 EXPECT_TRUE(video_desc != nullptr);
1816}
1817
1818// Test that it's possible to call RemoveTrack on a MediaStream after adding
1819// the stream to a PeerConnection.
1820// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001821// Don't run under Unified Plan since the stream API is not available.
1822TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001823 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001824 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001825 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001826 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1827
1828 // Remove the video track.
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00001829 stream->RemoveTrack(stream->GetVideoTracks()[0]);
deadbeefeb459812015-12-15 19:24:43 -08001830
kwibergd1fe2812016-04-27 06:47:29 -07001831 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001832 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001833
1834 const cricket::MediaContentDescription* video_desc =
1835 cricket::GetFirstVideoContentDescription(offer->description());
1836 EXPECT_TRUE(video_desc == nullptr);
1837}
1838
deadbeefbd7d8f72015-12-18 16:58:44 -08001839// Test creating a sender with a stream ID, and ensure the ID is populated
1840// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001841// Don't run under Unified Plan since the stream API is not available.
1842TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001843 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001844 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001845
kwibergd1fe2812016-04-27 06:47:29 -07001846 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001847 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001848
1849 const cricket::MediaContentDescription* video_desc =
1850 cricket::GetFirstVideoContentDescription(offer->description());
1851 ASSERT_TRUE(video_desc != nullptr);
1852 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001853 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001854}
1855
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001856// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001857TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001858 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001859 ASSERT_LT(0u, pc_->GetSenders().size());
1860 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001861 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001862 pc_->GetReceivers()[0]->track();
Niels Möllerafb246b2022-04-20 14:26:50 +02001863 EXPECT_TRUE(DoGetStats(remote_audio.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001864
1865 // Remove the stream. Since we are sending to our selves the local
1866 // and the remote stream is the same.
Harald Alvestrand93dd7632022-01-19 12:28:45 +00001867 pc_->RemoveTrackOrError(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001868 // Do a re-negotiation.
1869 CreateOfferReceiveAnswer();
1870
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001871 // Test that we still can get statistics for the old track. Even if it is not
1872 // sent any longer.
Niels Möllerafb246b2022-04-20 14:26:50 +02001873 EXPECT_TRUE(DoGetStats(remote_audio.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001874}
1875
1876// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001877TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001878 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001879 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1880 ASSERT_TRUE(video_receiver);
Niels Möllerafb246b2022-04-20 14:26:50 +02001881 EXPECT_TRUE(DoGetStats(video_receiver->track().get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001882}
1883
1884// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001885TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001886 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001887 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
Niels Möllerafb246b2022-04-20 14:26:50 +02001888 pc_factory_->CreateAudioTrack("unknown track", nullptr));
1889 EXPECT_FALSE(DoGetStats(unknown_audio_track.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001890}
1891
Steve Anton36da6ff2018-02-16 16:04:20 -08001892TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001893 CreatePeerConnectionWithoutDtls();
1894 EXPECT_TRUE(DoGetRTCStats());
1895 // Clearing stats cache is needed now, but should be temporary.
1896 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1897 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001898 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1899 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001900 EXPECT_TRUE(DoGetRTCStats());
1901 pc_->ClearStatsCache();
1902 CreateOfferReceiveAnswer();
1903 EXPECT_TRUE(DoGetRTCStats());
1904}
1905
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906// This tests that a SCTP data channel is returned using different
1907// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08001908TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001909 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02001910 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001911
1912 webrtc::DataChannelInit config;
Florent Castelli72424402022-04-06 03:45:10 +02001913 auto channel = pc_->CreateDataChannelOrError("1", &config);
1914 EXPECT_TRUE(channel.ok());
1915 EXPECT_TRUE(channel.value()->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001916 EXPECT_TRUE(observer_.renegotiation_needed_);
1917 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001918
1919 config.ordered = false;
Florent Castelli72424402022-04-06 03:45:10 +02001920 channel = pc_->CreateDataChannelOrError("2", &config);
1921 EXPECT_TRUE(channel.ok());
1922 EXPECT_TRUE(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
1925 config.ordered = true;
1926 config.maxRetransmits = 0;
Florent Castelli72424402022-04-06 03:45:10 +02001927 channel = pc_->CreateDataChannelOrError("3", &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
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02001932 config.maxRetransmits = absl::nullopt;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001933 config.maxRetransmitTime = 0;
Florent Castelli72424402022-04-06 03:45:10 +02001934 channel = pc_->CreateDataChannelOrError("4", &config);
1935 EXPECT_TRUE(channel.ok());
1936 EXPECT_FALSE(channel.value()->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001937 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001938}
1939
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02001940// For backwards compatibility, we want people who "unset" maxRetransmits
1941// and maxRetransmitTime by setting them to -1 to get what they want.
1942TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannelWithMinusOne) {
1943 RTCConfiguration rtc_config;
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02001944 CreatePeerConnection(rtc_config);
1945
1946 webrtc::DataChannelInit config;
1947 config.maxRetransmitTime = -1;
1948 config.maxRetransmits = -1;
Florent Castelli72424402022-04-06 03:45:10 +02001949 auto channel = pc_->CreateDataChannelOrError("1", &config);
1950 EXPECT_TRUE(channel.ok());
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02001951}
1952
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001953// This tests that no data channel is returned if both maxRetransmits and
1954// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08001955TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001956 CreateSctpDataChannelShouldFailForInvalidConfig) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001957 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02001958 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001959
1960 std::string label = "test";
1961 webrtc::DataChannelInit config;
1962 config.maxRetransmits = 0;
1963 config.maxRetransmitTime = 0;
1964
Florent Castelli72424402022-04-06 03:45:10 +02001965 auto channel = pc_->CreateDataChannelOrError(label, &config);
1966 EXPECT_FALSE(channel.ok());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001967}
1968
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001969// The test verifies that creating a SCTP data channel with an id already in use
1970// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001971TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001972 CreateSctpDataChannelWithInvalidIdShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001973 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02001974 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001975
1976 webrtc::DataChannelInit config;
1977
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001978 config.id = 1;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02001979 config.negotiated = true;
Florent Castelli72424402022-04-06 03:45:10 +02001980 auto channel = pc_->CreateDataChannelOrError("1", &config);
1981 EXPECT_TRUE(channel.ok());
1982 EXPECT_EQ(1, channel.value()->id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983
Florent Castelli72424402022-04-06 03:45:10 +02001984 channel = pc_->CreateDataChannelOrError("x", &config);
1985 EXPECT_FALSE(channel.ok());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986
1987 config.id = cricket::kMaxSctpSid;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02001988 config.negotiated = true;
Florent Castelli72424402022-04-06 03:45:10 +02001989 channel = pc_->CreateDataChannelOrError("max", &config);
1990 EXPECT_TRUE(channel.ok());
1991 EXPECT_EQ(config.id, channel.value()->id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001992
1993 config.id = cricket::kMaxSctpSid + 1;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02001994 config.negotiated = true;
Florent Castelli72424402022-04-06 03:45:10 +02001995 channel = pc_->CreateDataChannelOrError("x", &config);
1996 EXPECT_FALSE(channel.ok());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997}
1998
deadbeefab9b2d12015-10-14 11:33:11 -07001999// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002000TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002001 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002002 CreatePeerConnection(rtc_config);
deadbeefab9b2d12015-10-14 11:33:11 -07002003
2004 std::string label = "test";
Florent Castelli72424402022-04-06 03:45:10 +02002005 auto channel = pc_->CreateDataChannelOrError(label, nullptr);
2006 EXPECT_TRUE(channel.ok());
deadbeefab9b2d12015-10-14 11:33:11 -07002007
Florent Castelli72424402022-04-06 03:45:10 +02002008 auto dup_channel = pc_->CreateDataChannelOrError(label, nullptr);
2009 EXPECT_TRUE(dup_channel.ok());
deadbeefab9b2d12015-10-14 11:33:11 -07002010}
2011
Mirko Bonadei5eb43b42021-01-18 13:24:40 +01002012#ifdef WEBRTC_HAVE_SCTP
Zhi Huang644fde42018-04-02 19:16:26 -07002013// This tests that SCTP data channels can be rejected in an answer.
2014TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2015#else
2016TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2017#endif
2018{
Niels Möllerf06f9232018-08-07 12:32:18 +02002019 RTCConfiguration rtc_config;
2020 CreatePeerConnection(rtc_config);
Zhi Huang644fde42018-04-02 19:16:26 -07002021
Florent Castelli72424402022-04-06 03:45:10 +02002022 auto offer_channel = pc_->CreateDataChannelOrError("offer_channel", NULL);
Zhi Huang644fde42018-04-02 19:16:26 -07002023
2024 CreateOfferAsLocalDescription();
2025
2026 // Create an answer where the m-line for data channels are rejected.
2027 std::string sdp;
2028 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2029 std::unique_ptr<SessionDescriptionInterface> answer(
2030 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2031 ASSERT_TRUE(answer);
2032 cricket::ContentInfo* data_info =
2033 cricket::GetFirstDataContent(answer->description());
2034 data_info->rejected = true;
2035
2036 DoSetRemoteDescription(std::move(answer));
Florent Castelli72424402022-04-06 03:45:10 +02002037 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel.value()->state());
Zhi Huang644fde42018-04-02 19:16:26 -07002038}
2039
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002040// Test that we can create a session description from an SDP string from
2041// FireFox, use it as a remote session description, generate an answer and use
2042// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002043TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002044 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002045 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002046 AddAudioTrack("audio_label");
2047 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002048 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002049 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002050 webrtc::kFireFoxSdpOffer, nullptr));
2051 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052 CreateAnswerAsLocalDescription();
Niels Möllerafb246b2022-04-20 14:26:50 +02002053 ASSERT_TRUE(pc_->local_description() != nullptr);
2054 ASSERT_TRUE(pc_->remote_description() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055
2056 const cricket::ContentInfo* content =
2057 cricket::GetFirstAudioContent(pc_->local_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002058 ASSERT_TRUE(content != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059 EXPECT_FALSE(content->rejected);
2060
2061 content =
2062 cricket::GetFirstVideoContent(pc_->local_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002063 ASSERT_TRUE(content != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002064 EXPECT_FALSE(content->rejected);
Mirko Bonadei5eb43b42021-01-18 13:24:40 +01002065#ifdef WEBRTC_HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002066 content =
2067 cricket::GetFirstDataContent(pc_->local_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002068 ASSERT_TRUE(content != nullptr);
Zhi Huange830e682018-03-30 10:48:35 -07002069 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002070#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002071}
2072
Harald Alvestrand0d018412021-11-04 13:52:31 +00002073// Test that fallback from DTLS to SDES is not supported.
2074// The fallback was previously supported but was removed to simplify the code
2075// and because it's non-standard.
2076TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002077 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002078 CreatePeerConnection(rtc_config);
deadbeef8662f942017-01-20 21:20:51 -08002079 // Wait for fake certificate to be generated. Previously, this is what caused
2080 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002081 AddAudioTrack("audio_label");
2082 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002083 ASSERT_NE(nullptr, fake_certificate_generator_);
2084 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2085 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002086 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002087 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2088 nullptr));
Harald Alvestrand0d018412021-11-04 13:52:31 +00002089 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002090}
2091
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092// Test that we can create an audio only offer and receive an answer with a
2093// limited set of audio codecs and receive an updated offer with more audio
2094// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002095TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002096 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002097 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098 CreateOfferAsLocalDescription();
2099
Florent Castelli15a38de2022-04-06 00:38:21 +02002100 const char* answer_sdp = (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED
2101 ? webrtc::kAudioSdpPlanB
2102 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002103 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002104 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002105 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002106
Steve Anton36da6ff2018-02-16 16:04:20 -08002107 const char* reoffer_sdp =
Florent Castelli15a38de2022-04-06 00:38:21 +02002108 (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED
Steve Anton36da6ff2018-02-16 16:04:20 -08002109 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2110 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002111 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002112 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002113 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114 CreateAnswerAsLocalDescription();
2115}
2116
deadbeefc80741f2015-10-22 13:14:45 -07002117// Test that if we're receiving (but not sending) a track, subsequent offers
2118// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002119TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002120 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002121 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002122 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002123 CreateAnswerAsLocalDescription();
2124
2125 // At this point we should be receiving stream 1, but not sending anything.
2126 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002127 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002128 DoCreateOffer(&offer, nullptr);
2129
2130 const cricket::ContentInfo* video_content =
2131 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002132 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2133 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002134
2135 const cricket::ContentInfo* audio_content =
2136 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002137 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2138 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002139}
2140
2141// Test that if we're receiving (but not sending) a track, and the
2142// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2143// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002144TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002145 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002146 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002147 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002148 CreateAnswerAsLocalDescription();
2149
2150 // At this point we should be receiving stream 1, but not sending anything.
2151 // A new offer would be recvonly, but we'll set the "no receive" constraints
2152 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002153 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02002154 RTCOfferAnswerOptions options;
2155 options.offer_to_receive_audio = 0;
2156 options.offer_to_receive_video = 0;
2157 DoCreateOffer(&offer, &options);
deadbeefc80741f2015-10-22 13:14:45 -07002158
2159 const cricket::ContentInfo* video_content =
2160 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002161 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2162 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002163
2164 const cricket::ContentInfo* audio_content =
2165 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002166 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2167 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002168}
2169
deadbeef653b8e02015-11-11 12:55:10 -08002170// Test that we can use SetConfiguration to change the ICE servers of the
2171// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002172TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002173 CreatePeerConnection();
2174
Steve Anton36da6ff2018-02-16 16:04:20 -08002175 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002176 PeerConnectionInterface::IceServer server;
2177 server.uri = "stun:test_hostname";
2178 config.servers.push_back(server);
Niels Möller2579f0c2019-08-19 09:58:17 +02002179 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef653b8e02015-11-11 12:55:10 -08002180
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002181 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2182 EXPECT_EQ("test_hostname",
2183 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002184}
2185
Steve Anton36da6ff2018-02-16 16:04:20 -08002186TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002187 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002188 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002189 config.type = PeerConnectionInterface::kRelay;
Niels Möller2579f0c2019-08-19 09:58:17 +02002190 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002191 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2192}
2193
Steve Anton36da6ff2018-02-16 16:04:20 -08002194TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002195 PeerConnectionInterface::RTCConfiguration config;
2196 config.prune_turn_ports = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02002197 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002198 config = pc_->GetConfiguration();
Honghai Zhangf8998cf2019-10-14 11:27:50 -07002199 EXPECT_EQ(webrtc::NO_PRUNE, port_allocator_->turn_port_prune_policy());
deadbeef293e9262017-01-11 12:28:30 -08002200
2201 config.prune_turn_ports = true;
Niels Möller2579f0c2019-08-19 09:58:17 +02002202 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Honghai Zhangf8998cf2019-10-14 11:27:50 -07002203 EXPECT_EQ(webrtc::PRUNE_BASED_ON_PRIORITY,
2204 port_allocator_->turn_port_prune_policy());
deadbeef293e9262017-01-11 12:28:30 -08002205}
2206
skvladd1f5fda2017-02-03 16:54:05 -08002207// Test that the ice check interval can be changed. This does not verify that
2208// the setting makes it all the way to P2PTransportChannel, as that would
2209// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002210TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002211 PeerConnectionInterface::RTCConfiguration config;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +02002212 config.ice_check_min_interval = absl::nullopt;
Niels Möllerf06f9232018-08-07 12:32:18 +02002213 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002214 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002215 config.ice_check_min_interval = 100;
Niels Möller2579f0c2019-08-19 09:58:17 +02002216 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Qingsi Wangbca14852019-06-26 14:56:02 -07002217 config = pc_->GetConfiguration();
2218 EXPECT_EQ(config.ice_check_min_interval, 100);
2219}
2220
2221TEST_P(PeerConnectionInterfaceTest,
2222 SetConfigurationChangesSurfaceIceCandidatesOnIceTransportTypeChanged) {
2223 PeerConnectionInterface::RTCConfiguration config;
2224 config.surface_ice_candidates_on_ice_transport_type_changed = false;
2225 CreatePeerConnection(config);
2226 config = pc_->GetConfiguration();
2227 EXPECT_FALSE(config.surface_ice_candidates_on_ice_transport_type_changed);
2228
2229 config.surface_ice_candidates_on_ice_transport_type_changed = true;
Niels Möller2579f0c2019-08-19 09:58:17 +02002230 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Qingsi Wangbca14852019-06-26 14:56:02 -07002231 config = pc_->GetConfiguration();
2232 EXPECT_TRUE(config.surface_ice_candidates_on_ice_transport_type_changed);
skvladd1f5fda2017-02-03 16:54:05 -08002233}
2234
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002235// Test that when SetConfiguration changes both the pool size and other
2236// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002237TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002238 SetConfigurationCreatesPooledSessionCorrectly) {
2239 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002240 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002241 config.ice_candidate_pool_size = 1;
2242 PeerConnectionInterface::IceServer server;
2243 server.uri = kStunAddressOnly;
2244 config.servers.push_back(server);
2245 config.type = PeerConnectionInterface::kRelay;
Niels Möller2579f0c2019-08-19 09:58:17 +02002246 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002247
2248 const cricket::FakePortAllocatorSession* session =
2249 static_cast<const cricket::FakePortAllocatorSession*>(
2250 port_allocator_->GetPooledSession());
2251 ASSERT_NE(nullptr, session);
2252 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002253}
2254
deadbeef293e9262017-01-11 12:28:30 -08002255// Test that after SetLocalDescription, changing the pool size is not allowed,
2256// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002257TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002258 CantChangePoolSizeAfterSetLocalDescription) {
2259 CreatePeerConnection();
2260 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002261 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002262 config.ice_candidate_pool_size = 1;
Niels Möller2579f0c2019-08-19 09:58:17 +02002263 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef6de92f92016-12-12 18:49:32 -08002264
2265 // Set remote offer; can still change pool size at this point.
2266 CreateOfferAsRemoteDescription();
2267 config.ice_candidate_pool_size = 2;
Niels Möller2579f0c2019-08-19 09:58:17 +02002268 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef6de92f92016-12-12 18:49:32 -08002269
2270 // Set local answer; now it's too late.
2271 CreateAnswerAsLocalDescription();
2272 config.ice_candidate_pool_size = 3;
Niels Möller2579f0c2019-08-19 09:58:17 +02002273 RTCError error = pc_->SetConfiguration(config);
deadbeef293e9262017-01-11 12:28:30 -08002274 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2275}
2276
deadbeef42a42632017-03-10 15:18:00 -08002277// Test that after setting an answer, extra pooled sessions are discarded. The
2278// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002279TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002280 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2281 CreatePeerConnection();
2282
2283 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002284 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002285 config.ice_candidate_pool_size = 4;
Niels Möller2579f0c2019-08-19 09:58:17 +02002286 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef42a42632017-03-10 15:18:00 -08002287
2288 // Do offer/answer.
2289 CreateOfferAsRemoteDescription();
2290 CreateAnswerAsLocalDescription();
2291
2292 // Expect no pooled sessions to be left.
2293 const cricket::PortAllocatorSession* session =
2294 port_allocator_->GetPooledSession();
2295 EXPECT_EQ(nullptr, session);
2296}
2297
2298// After Close is called, pooled candidates should be discarded so as to not
2299// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002300TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002301 CreatePeerConnection();
2302
Steve Anton36da6ff2018-02-16 16:04:20 -08002303 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002304 config.ice_candidate_pool_size = 3;
Niels Möller2579f0c2019-08-19 09:58:17 +02002305 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef42a42632017-03-10 15:18:00 -08002306 pc_->Close();
2307
2308 // Expect no pooled sessions to be left.
2309 const cricket::PortAllocatorSession* session =
2310 port_allocator_->GetPooledSession();
2311 EXPECT_EQ(nullptr, session);
2312}
2313
deadbeef293e9262017-01-11 12:28:30 -08002314// Test that SetConfiguration returns an invalid modification error if
2315// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002316TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002317 SetConfigurationReturnsInvalidModificationError) {
2318 PeerConnectionInterface::RTCConfiguration config;
2319 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2320 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2321 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
Niels Möllerf06f9232018-08-07 12:32:18 +02002322 CreatePeerConnection(config);
deadbeef293e9262017-01-11 12:28:30 -08002323
Steve Anton36da6ff2018-02-16 16:04:20 -08002324 PeerConnectionInterface::RTCConfiguration modified_config =
2325 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002326 modified_config.bundle_policy =
2327 PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möller2579f0c2019-08-19 09:58:17 +02002328 RTCError error = pc_->SetConfiguration(modified_config);
deadbeef293e9262017-01-11 12:28:30 -08002329 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2330
Steve Anton36da6ff2018-02-16 16:04:20 -08002331 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002332 modified_config.rtcp_mux_policy =
2333 PeerConnectionInterface::kRtcpMuxPolicyRequire;
Niels Möller2579f0c2019-08-19 09:58:17 +02002334 error = pc_->SetConfiguration(modified_config);
deadbeef293e9262017-01-11 12:28:30 -08002335 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2336
Steve Anton36da6ff2018-02-16 16:04:20 -08002337 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002338 modified_config.continual_gathering_policy =
2339 PeerConnectionInterface::GATHER_CONTINUALLY;
Niels Möller2579f0c2019-08-19 09:58:17 +02002340 error = pc_->SetConfiguration(modified_config);
deadbeef293e9262017-01-11 12:28:30 -08002341 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2342}
2343
2344// Test that SetConfiguration returns a range error if the candidate pool size
2345// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002346TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002347 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2348 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002349 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002350 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002351
2352 config.ice_candidate_pool_size = -1;
Niels Möller2579f0c2019-08-19 09:58:17 +02002353 RTCError error = pc_->SetConfiguration(config);
deadbeef293e9262017-01-11 12:28:30 -08002354 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2355
2356 config.ice_candidate_pool_size = INT_MAX;
Niels Möller2579f0c2019-08-19 09:58:17 +02002357 error = pc_->SetConfiguration(config);
deadbeef293e9262017-01-11 12:28:30 -08002358 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2359}
2360
2361// Test that SetConfiguration returns a syntax error if parsing an ICE server
2362// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002363TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002364 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2365 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002366 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002367 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002368
2369 PeerConnectionInterface::IceServer bad_server;
2370 bad_server.uri = "stunn:www.example.com";
2371 config.servers.push_back(bad_server);
Niels Möller2579f0c2019-08-19 09:58:17 +02002372 RTCError error = pc_->SetConfiguration(config);
deadbeef293e9262017-01-11 12:28:30 -08002373 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2374}
2375
2376// Test that SetConfiguration returns an invalid parameter error if a TURN
2377// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002378TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002379 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2380 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002381 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002382 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002383
2384 PeerConnectionInterface::IceServer bad_server;
2385 bad_server.uri = "turn:www.example.com";
2386 // Missing password.
2387 bad_server.username = "foo";
2388 config.servers.push_back(bad_server);
2389 RTCError error;
Niels Möller340e0c52019-08-26 11:03:47 +02002390 EXPECT_EQ(pc_->SetConfiguration(config).type(),
2391 RTCErrorType::INVALID_PARAMETER);
deadbeef6de92f92016-12-12 18:49:32 -08002392}
2393
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002394// Test that PeerConnection::Close changes the states to closed and all remote
2395// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002396TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002397 // Initialize a PeerConnection and negotiate local and remote session
2398 // description.
2399 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002400
2401 // With Plan B, verify the stream count. The analog with Unified Plan is the
2402 // RtpTransceiver count.
Florent Castelli15a38de2022-04-06 00:38:21 +02002403 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Steve Anton36da6ff2018-02-16 16:04:20 -08002404 ASSERT_EQ(1u, pc_->local_streams()->count());
2405 ASSERT_EQ(1u, pc_->remote_streams()->count());
2406 } else {
2407 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2408 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409
2410 pc_->Close();
2411
2412 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2413 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2414 pc_->ice_connection_state());
2415 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2416 pc_->ice_gathering_state());
2417
Florent Castelli15a38de2022-04-06 00:38:21 +02002418 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Steve Anton36da6ff2018-02-16 16:04:20 -08002419 EXPECT_EQ(1u, pc_->local_streams()->count());
2420 EXPECT_EQ(1u, pc_->remote_streams()->count());
2421 } else {
Harald Alvestrand936f1af2020-09-22 07:41:50 +00002422 // Verify that the RtpTransceivers are still returned.
2423 EXPECT_EQ(2u, pc_->GetTransceivers().size());
Steve Anton36da6ff2018-02-16 16:04:20 -08002424 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002425
Steve Anton36da6ff2018-02-16 16:04:20 -08002426 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
Steve Anton36da6ff2018-02-16 16:04:20 -08002427 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
Florent Castelli15a38de2022-04-06 00:38:21 +02002428 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Harald Alvestrand6060df52020-08-11 09:54:02 +02002429 ASSERT_TRUE(audio_receiver);
2430 ASSERT_TRUE(video_receiver);
2431 // Track state may be updated asynchronously.
2432 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
2433 audio_receiver->track()->state(), kTimeout);
2434 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
2435 video_receiver->track()->state(), kTimeout);
2436 } else {
2437 ASSERT_FALSE(audio_receiver);
2438 ASSERT_FALSE(video_receiver);
2439 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002440}
2441
2442// Test that PeerConnection methods fails gracefully after
2443// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002444// Don't run under Unified Plan since the stream API is not available.
2445TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002446 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002447 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002448 CreateOfferAsRemoteDescription();
2449 CreateAnswerAsLocalDescription();
2450
2451 ASSERT_EQ(1u, pc_->local_streams()->count());
Niels Möllere7cc8832022-01-04 15:20:03 +01002452 rtc::scoped_refptr<MediaStreamInterface> local_stream(
2453 pc_->local_streams()->at(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002454
2455 pc_->Close();
2456
Niels Möllerafb246b2022-04-20 14:26:50 +02002457 pc_->RemoveStream(local_stream.get());
2458 EXPECT_FALSE(pc_->AddStream(local_stream.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002459
Florent Castelli72424402022-04-06 03:45:10 +02002460 EXPECT_FALSE(pc_->CreateDataChannelOrError("test", NULL).ok());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002461
Niels Möllerafb246b2022-04-20 14:26:50 +02002462 EXPECT_TRUE(pc_->local_description() != nullptr);
2463 EXPECT_TRUE(pc_->remote_description() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002464
kwibergd1fe2812016-04-27 06:47:29 -07002465 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002466 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002467 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002468 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469
2470 std::string sdp;
2471 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002472 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002473 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002474 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475
2476 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002477 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002478 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002479 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480}
2481
2482// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002483TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002484 InitiateCall();
2485 pc_->Close();
Niels Möllerafb246b2022-04-20 14:26:50 +02002486 DoGetStats(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002487}
deadbeefab9b2d12015-10-14 11:33:11 -07002488
2489// NOTE: The series of tests below come from what used to be
2490// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2491// setting a remote or local description has the expected effects.
2492
2493// This test verifies that the remote MediaStreams corresponding to a received
2494// SDP string is created. In this test the two separate MediaStreams are
2495// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002496TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002497 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002498 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002499 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002500
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002501 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002502 EXPECT_TRUE(
2503 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2504 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2505 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2506
2507 // Create a session description based on another SDP with another
2508 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002509 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002510
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002511 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002512 EXPECT_TRUE(
2513 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2514}
2515
2516// This test verifies that when remote tracks are added/removed from SDP, the
2517// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002518// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2519// specific behavior.
2520TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002521 AddRemoveTrackFromExistingRemoteMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002522 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002523 CreatePeerConnection(config);
kwibergd1fe2812016-04-27 06:47:29 -07002524 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002525 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002526 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
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()));
deadbeefab9b2d12015-10-14 11:33:11 -07002529
2530 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002531 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002532 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002533 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002534 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
Niels Möllerafb246b2022-04-20 14:26:50 +02002535 reference_collection_.get()));
zhihuang9763d562016-08-05 11:14:50 -07002536 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002537 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2538 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002539 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002540 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2541 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002542
2543 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002544 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002545 CreateSessionDescriptionAndReference(1, 1);
Niels Möllerafb246b2022-04-20 14:26:50 +02002546 MockTrackObserver audio_track_observer(audio_track2.get());
2547 MockTrackObserver video_track_observer(video_track2.get());
perkjd61bf802016-03-24 03:16:19 -07002548
2549 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2550 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002551 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002552 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
Niels Möllerafb246b2022-04-20 14:26:50 +02002553 reference_collection_.get()));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002554 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002555 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002556 audio_track2->state(), kTimeout);
2557 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2558 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002559}
2560
2561// This tests that remote tracks are ended if a local session description is set
2562// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002563TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002564 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002565 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002566 // First create and set a remote offer, then reject its video content in our
2567 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002568 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2569 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2570 ASSERT_TRUE(audio_receiver);
2571 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2572 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002573
Steve Anton36da6ff2018-02-16 16:04:20 -08002574 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2575 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002576 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002577 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2578 video_receiver->track();
2579 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002580
kwibergd1fe2812016-04-27 06:47:29 -07002581 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002582 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002583 cricket::ContentInfo* video_info =
2584 local_answer->description()->GetContentByName("video");
2585 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002586 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002587 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2588 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002589
2590 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002591 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002592 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002593 video_info = local_offer->description()->GetContentByName("video");
2594 ASSERT_TRUE(video_info != nullptr);
2595 video_info->rejected = true;
2596 cricket::ContentInfo* audio_info =
2597 local_offer->description()->GetContentByName("audio");
2598 ASSERT_TRUE(audio_info != nullptr);
2599 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002600 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002601 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002602 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2603 kTimeout);
2604 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2605 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002606}
2607
2608// This tests that we won't crash if the remote track has been removed outside
2609// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002610// Don't run under Unified Plan since the stream API is not available.
2611TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002612 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002613 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002614 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002615 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00002616 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2617 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07002618
kwibergd1fe2812016-04-27 06:47:29 -07002619 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002620 webrtc::CreateSessionDescription(SdpType::kAnswer,
2621 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002622 cricket::ContentInfo* video_info =
2623 local_answer->description()->GetContentByName("video");
2624 video_info->rejected = true;
2625 cricket::ContentInfo* audio_info =
2626 local_answer->description()->GetContentByName("audio");
2627 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002628 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002629
2630 // No crash is a pass.
2631}
2632
deadbeef5e97fb52015-10-15 12:49:08 -07002633// This tests that if a recvonly remote description is set, no remote streams
2634// will be created, even if the description contains SSRCs/MSIDs.
2635// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002636TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002637 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002638 CreatePeerConnection(config);
deadbeef5e97fb52015-10-15 12:49:08 -07002639
Steve Anton36da6ff2018-02-16 16:04:20 -08002640 std::string recvonly_offer = GetSdpStringWithStream1();
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002641 absl::StrReplaceAll({{kSendrecv, kRecvonly}}, &recvonly_offer);
deadbeef5e97fb52015-10-15 12:49:08 -07002642 CreateAndSetRemoteOffer(recvonly_offer);
2643
2644 EXPECT_EQ(0u, observer_.remote_streams()->count());
2645}
2646
deadbeefab9b2d12015-10-14 11:33:11 -07002647// This tests that a default MediaStream is created if a remote session
2648// description doesn't contain any streams and no MSID support.
2649// It also tests that the default stream is updated if a video m-line is added
2650// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002651// Don't run under Unified Plan since this behavior is Plan B specific.
2652TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002653 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002654 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002655 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2656
2657 ASSERT_EQ(1u, observer_.remote_streams()->count());
2658 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2659
2660 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2661 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002662 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002663
2664 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2665 ASSERT_EQ(1u, observer_.remote_streams()->count());
2666 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2667 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002668 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2669 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002670 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2671 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002672 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2673 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002674}
2675
2676// This tests that a default MediaStream is created if a remote session
2677// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002678// Don't run under Unified Plan since this behavior is Plan B specific.
2679TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002680 SendOnlySdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002681 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002682 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002683 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2684
2685 ASSERT_EQ(1u, observer_.remote_streams()->count());
2686 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2687
2688 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2689 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002690 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002691}
2692
2693// This tests that it won't crash when PeerConnection tries to remove
2694// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002695// Don't run under Unified Plan since this behavior is Plan B specific.
2696TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002697 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002698 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002699 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002700 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00002701 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2702 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07002703
2704 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2705
2706 // No crash is a pass.
2707}
2708
2709// This tests that a default MediaStream is created if the remote session
2710// description doesn't contain any streams and don't contain an indication if
2711// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002712// Don't run under Unified Plan since this behavior is Plan B specific.
2713TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002714 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002715 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002716 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002717 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2718
2719 ASSERT_EQ(1u, observer_.remote_streams()->count());
2720 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2721 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2722 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2723}
2724
2725// This tests that a default MediaStream is not created if the remote session
2726// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08002727// Don't run under Unified Plan since this behavior is Plan B specific.
2728TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002729 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002730 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002731 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2732 EXPECT_EQ(0u, observer_.remote_streams()->count());
2733}
2734
deadbeefbda7e0b2015-12-08 17:13:40 -08002735// This tests that when setting a new description, the old default tracks are
2736// not destroyed and recreated.
2737// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08002738// Don't run under Unified Plan since this behavior is Plan B specific.
2739TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002740 DefaultTracksNotDestroyedAndRecreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002741 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002742 CreatePeerConnection(config);
deadbeefbda7e0b2015-12-08 17:13:40 -08002743 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2744
2745 ASSERT_EQ(1u, observer_.remote_streams()->count());
2746 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2747 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2748
2749 // Set the track to "disabled", then set a new description and ensure the
2750 // track is still disabled, which ensures it hasn't been recreated.
2751 remote_stream->GetAudioTracks()[0]->set_enabled(false);
2752 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2753 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2754 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
2755}
2756
deadbeefab9b2d12015-10-14 11:33:11 -07002757// This tests that a default MediaStream is not created if a remote session
2758// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08002759// Don't run under Unified Plan since this behavior is Plan B specific.
2760TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002761 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002762 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002763 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002764 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002765 EXPECT_TRUE(
2766 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2767
2768 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2769 EXPECT_EQ(0u, observer_.remote_streams()->count());
2770}
2771
Seth Hampson5897a6e2018-04-03 11:16:33 -07002772// This tests that a default MediaStream is created if a remote SDP comes from
2773// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
2774TEST_F(PeerConnectionInterfaceTestPlanB,
2775 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002776 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002777 CreatePeerConnection(config);
Seth Hampson5897a6e2018-04-03 11:16:33 -07002778 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
2779 // Add a=msid lines to simulate a Unified Plan endpoint that only
2780 // signals stream IDs with a=msid lines.
2781 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
2782
2783 CreateAndSetRemoteOffer(sdp_string);
2784
2785 ASSERT_EQ(1u, observer_.remote_streams()->count());
2786 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2787 EXPECT_EQ("default", remote_stream->id());
2788 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2789}
2790
Seth Hampson5b4f0752018-04-02 16:31:36 -07002791// This tests that when a Plan B endpoint receives an SDP that signals no media
2792// stream IDs indicated by the special character "-" in the a=msid line, that
2793// a default stream ID will be used for the MediaStream ID. This can occur
2794// when a Unified Plan endpoint signals no media stream IDs, but signals both
2795// a=ssrc msid and a=msid lines for interop signaling with Plan B.
2796TEST_F(PeerConnectionInterfaceTestPlanB,
2797 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002798 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002799 CreatePeerConnection(config);
Seth Hampson5b4f0752018-04-02 16:31:36 -07002800 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
2801 // the sender's stream ID will be interpreted as no stream IDs.
2802 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
2803 sdp_string.append("a=msid:- audiotrack0\n");
2804
2805 CreateAndSetRemoteOffer(sdp_string);
2806
2807 ASSERT_EQ(1u, observer_.remote_streams()->count());
2808 // Because SSRCs are signaled the track ID will be what was signaled in the
2809 // a=msid line.
2810 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
2811 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2812 EXPECT_EQ("default", remote_stream->id());
2813 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07002814
2815 // Previously a bug ocurred when setting the remote description a second time.
2816 // This is because we checked equality of the remote StreamParams stream ID
2817 // (empty), and the previously set stream ID for the remote sender
2818 // ("default"). This cause a track to be removed, then added, when really
2819 // nothing should occur because it is the same track.
2820 CreateAndSetRemoteOffer(sdp_string);
2821 EXPECT_EQ(0u, observer_.remove_track_events_.size());
2822 EXPECT_EQ(1u, observer_.add_track_events_.size());
2823 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
2824 remote_stream = observer_.remote_streams()->at(0);
2825 EXPECT_EQ("default", remote_stream->id());
2826 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07002827}
2828
deadbeefab9b2d12015-10-14 11:33:11 -07002829// This tests that an RtpSender is created when the local description is set
2830// after adding a local stream.
2831// TODO(deadbeef): This test and the one below it need to be updated when
2832// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08002833// Don't run under Unified Plan since this behavior is Plan B specific.
2834TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002835 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002836 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002837
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002838 // Create an offer with 1 stream with 2 tracks of each type.
2839 rtc::scoped_refptr<StreamCollection> stream_collection =
2840 CreateStreamCollection(1, 2);
2841 pc_->AddStream(stream_collection->at(0));
2842 std::unique_ptr<SessionDescriptionInterface> offer;
2843 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002844 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002845
deadbeefab9b2d12015-10-14 11:33:11 -07002846 auto senders = pc_->GetSenders();
2847 EXPECT_EQ(4u, senders.size());
2848 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2849 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2850 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2851 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2852
2853 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002854 pc_->RemoveStream(stream_collection->at(0));
2855 stream_collection = CreateStreamCollection(1, 1);
2856 pc_->AddStream(stream_collection->at(0));
2857 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002858 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002859
deadbeefab9b2d12015-10-14 11:33:11 -07002860 senders = pc_->GetSenders();
2861 EXPECT_EQ(2u, senders.size());
2862 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2863 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2864 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
2865 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
2866}
2867
2868// This tests that an RtpSender is created when the local description is set
2869// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002870// Don't run under Unified Plan since this behavior is Plan B specific.
2871TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002872 AddLocalStreamAfterLocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002873 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002874 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002875
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002876 rtc::scoped_refptr<StreamCollection> stream_collection =
2877 CreateStreamCollection(1, 2);
2878 // Add a stream to create the offer, but remove it afterwards.
2879 pc_->AddStream(stream_collection->at(0));
2880 std::unique_ptr<SessionDescriptionInterface> offer;
2881 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2882 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002883
Steve Antondb45ca82017-09-11 18:27:34 -07002884 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002885 auto senders = pc_->GetSenders();
2886 EXPECT_EQ(0u, senders.size());
2887
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002888 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002889 senders = pc_->GetSenders();
2890 EXPECT_EQ(4u, senders.size());
2891 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2892 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2893 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2894 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2895}
2896
2897// This tests that the expected behavior occurs if the SSRC on a local track is
2898// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002899TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002900 ChangeSsrcOnTrackInLocalSessionDescription) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002901 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002902 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002903
Steve Anton36da6ff2018-02-16 16:04:20 -08002904 AddAudioTrack(kAudioTracks[0]);
2905 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002906 std::unique_ptr<SessionDescriptionInterface> offer;
2907 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2908 // Grab a copy of the offer before it gets passed into the PC.
Steve Antond9e4a062018-07-24 18:23:33 -07002909 std::unique_ptr<SessionDescriptionInterface> modified_offer =
2910 webrtc::CreateSessionDescription(
2911 webrtc::SdpType::kOffer, offer->session_id(),
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002912 offer->session_version(), offer->description()->Clone());
Steve Antondb45ca82017-09-11 18:27:34 -07002913 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002914
deadbeefab9b2d12015-10-14 11:33:11 -07002915 auto senders = pc_->GetSenders();
2916 EXPECT_EQ(2u, senders.size());
2917 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2918 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2919
2920 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002921 cricket::MediaContentDescription* desc =
2922 cricket::GetFirstAudioContentDescription(modified_offer->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002923 ASSERT_TRUE(desc != nullptr);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002924 for (StreamParams& stream : desc->mutable_streams()) {
2925 for (unsigned int& ssrc : stream.ssrcs) {
2926 ++ssrc;
2927 }
2928 }
deadbeefab9b2d12015-10-14 11:33:11 -07002929
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002930 desc =
2931 cricket::GetFirstVideoContentDescription(modified_offer->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002932 ASSERT_TRUE(desc != nullptr);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002933 for (StreamParams& stream : desc->mutable_streams()) {
2934 for (unsigned int& ssrc : stream.ssrcs) {
2935 ++ssrc;
2936 }
2937 }
2938
Steve Antondb45ca82017-09-11 18:27:34 -07002939 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002940 senders = pc_->GetSenders();
2941 EXPECT_EQ(2u, senders.size());
2942 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2943 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2944 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
2945 // changed.
2946}
2947
2948// This tests that the expected behavior occurs if a new session description is
2949// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002950// Don't run under Unified Plan since the stream API is not available.
2951TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002952 SignalSameTracksInSeparateMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002953 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002954 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002955
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002956 rtc::scoped_refptr<StreamCollection> stream_collection =
2957 CreateStreamCollection(2, 1);
2958 pc_->AddStream(stream_collection->at(0));
2959 std::unique_ptr<SessionDescriptionInterface> offer;
2960 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002961 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002962
deadbeefab9b2d12015-10-14 11:33:11 -07002963 auto senders = pc_->GetSenders();
2964 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002965 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
2966 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07002967
2968 // Add a new MediaStream but with the same tracks as in the first stream.
2969 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
2970 webrtc::MediaStream::Create(kStreams[1]));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00002971 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
2972 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
Niels Möllerafb246b2022-04-20 14:26:50 +02002973 pc_->AddStream(stream_1.get());
deadbeefab9b2d12015-10-14 11:33:11 -07002974
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002975 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002976 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002977
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002978 auto new_senders = pc_->GetSenders();
2979 // Should be the same senders as before, but with updated stream id.
2980 // Note that this behavior is subject to change in the future.
2981 // We may decide the PC should ignore existing tracks in AddStream.
2982 EXPECT_EQ(senders, new_senders);
2983 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
2984 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07002985}
2986
zhihuang81c3a032016-11-17 12:06:24 -08002987// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002988TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002989 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002990 CreatePeerConnection(config);
zhihuang81c3a032016-11-17 12:06:24 -08002991 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
2992 EXPECT_EQ(observer_.num_added_tracks_, 1);
2993 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
2994
2995 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08002996 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
Steve Anton0f5400a2018-07-17 14:25:36 -07002997 EXPECT_EQ(observer_.num_added_tracks_, 2);
zhihuang81c3a032016-11-17 12:06:24 -08002998 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
2999}
3000
deadbeefd1a38b52016-12-10 13:15:33 -08003001// Test that when SetConfiguration is called and the configuration is
3002// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003003TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003004 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003005 config.sdp_semantics = sdp_semantics_;
deadbeefd1a38b52016-12-10 13:15:33 -08003006 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003007 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003008 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003009 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3010 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003011
3012 // Do initial offer/answer so there's something to restart.
3013 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003014 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003015
3016 // Grab the ufrags.
3017 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3018
3019 // Change ICE policy, which should trigger an ICE restart on the next offer.
3020 config.type = PeerConnectionInterface::kAll;
Niels Möller2579f0c2019-08-19 09:58:17 +02003021 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeefd1a38b52016-12-10 13:15:33 -08003022 CreateOfferAsLocalDescription();
3023
3024 // Grab the new ufrags.
3025 std::vector<std::string> subsequent_ufrags =
3026 GetUfrags(pc_->local_description());
3027
3028 // Sanity check.
3029 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3030 // Check that each ufrag is different.
3031 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3032 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3033 }
3034}
3035
3036// Test that when SetConfiguration is called and the configuration *isn't*
3037// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003038TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003039 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003040 config.sdp_semantics = sdp_semantics_;
deadbeefd1a38b52016-12-10 13:15:33 -08003041 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003042 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003043 config = pc_->GetConfiguration();
3044 AddAudioTrack(kAudioTracks[0]);
3045 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003046
3047 // Do initial offer/answer so there's something to restart.
3048 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003049 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003050
3051 // Grab the ufrags.
3052 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3053
3054 // Call SetConfiguration with a config identical to what the PC was
3055 // constructed with.
Niels Möller2579f0c2019-08-19 09:58:17 +02003056 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeefd1a38b52016-12-10 13:15:33 -08003057 CreateOfferAsLocalDescription();
3058
3059 // Grab the new ufrags.
3060 std::vector<std::string> subsequent_ufrags =
3061 GetUfrags(pc_->local_description());
3062
3063 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3064}
3065
3066// Test for a weird corner case scenario:
3067// 1. Audio/video session established.
3068// 2. SetConfiguration changes ICE config; ICE restart needed.
3069// 3. ICE restart initiated by remote peer, but only for one m= section.
3070// 4. Next createOffer should initiate an ICE restart, but only for the other
3071// m= section; it would be pointless to do an ICE restart for the m= section
3072// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003073TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003074 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003075 config.sdp_semantics = sdp_semantics_;
deadbeefd1a38b52016-12-10 13:15:33 -08003076 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003077 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003078 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003079 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3080 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003081
3082 // Do initial offer/answer so there's something to restart.
3083 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003084 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003085
3086 // Change ICE policy, which should set the "needs-ice-restart" flag.
3087 config.type = PeerConnectionInterface::kAll;
Niels Möller2579f0c2019-08-19 09:58:17 +02003088 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeefd1a38b52016-12-10 13:15:33 -08003089
3090 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003091 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003092 webrtc::CreateSessionDescription(SdpType::kOffer,
3093 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003094 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003095 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3096 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003097 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003098 CreateAnswerAsLocalDescription();
3099
3100 // Grab the ufrags.
3101 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003102 ASSERT_EQ(2U, initial_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003103
3104 // Create offer and grab the new ufrags.
3105 CreateOfferAsLocalDescription();
3106 std::vector<std::string> subsequent_ufrags =
3107 GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003108 ASSERT_EQ(2U, subsequent_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003109
3110 // Ensure that only the ufrag for the second m= section changed.
3111 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3112 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3113}
3114
deadbeeffe4a8a42016-12-20 17:56:17 -08003115// Tests that the methods to return current/pending descriptions work as
3116// expected at different points in the offer/answer exchange. This test does
3117// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003118TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003119 // This disables DTLS so we can apply an answer to ourselves.
3120 CreatePeerConnection();
3121
3122 // Create initial local offer and get SDP (which will also be used as
3123 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003124 std::unique_ptr<SessionDescriptionInterface> local_offer;
3125 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003126 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003127 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003128
3129 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003130 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3131 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3132 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003133 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3134 EXPECT_EQ(nullptr, pc_->current_local_description());
3135 EXPECT_EQ(nullptr, pc_->current_remote_description());
3136
3137 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003138 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003139 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003140 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3141 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3142 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3143 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003144 EXPECT_EQ(nullptr, pc_->current_local_description());
3145 EXPECT_EQ(nullptr, pc_->current_remote_description());
3146
3147 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003148 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003149 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003150 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3151 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003152 EXPECT_EQ(nullptr, pc_->pending_local_description());
3153 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003154 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3155 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003156
3157 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003158 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003159 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003160 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3161 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3162 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003163 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003164 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3165 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003166
3167 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003168 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003169 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003170 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3171 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3172 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3173 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3174 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3175 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003176
3177 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003178 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003179 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003180 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3181 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003182 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3183 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003184 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3185 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003186}
3187
zhihuang77985012017-02-07 15:45:16 -08003188// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3189// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003190// This version tests the StartRtcEventLog version that receives an object
Artem Titov880fa812021-07-30 22:30:23 +02003191// of type `RtcEventLogOutput`.
Steve Anton36da6ff2018-02-16 16:04:20 -08003192TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003193 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3194 CreatePeerConnection();
3195 // The RtcEventLog will be reset when the PeerConnection is closed.
3196 pc_->Close();
3197
Niels Möllerdec9f742019-06-03 15:25:20 +02003198 EXPECT_FALSE(
Mirko Bonadei317a1f02019-09-17 17:06:18 +02003199 pc_->StartRtcEventLog(std::make_unique<webrtc::RtcEventLogOutputNull>(),
Niels Möllerdec9f742019-06-03 15:25:20 +02003200 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003201 pc_->StopRtcEventLog();
3202}
3203
deadbeef30952b42017-04-21 02:41:29 -07003204// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003205TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003206 CreatePeerConnection();
3207
3208 // First, create an offer with audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003209 RTCOfferAnswerOptions options;
3210 options.offer_to_receive_audio = 1;
3211 options.offer_to_receive_video = 1;
deadbeef30952b42017-04-21 02:41:29 -07003212 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003213 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003214 cricket::SessionDescription* desc = offer->description();
3215 ASSERT_EQ(2u, desc->transport_infos().size());
3216 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3217 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3218
3219 // Apply the offer as a remote description, then create an answer.
Harald Alvestrand61f74d92020-03-02 11:20:00 +01003220 EXPECT_FALSE(pc_->can_trickle_ice_candidates());
Steve Antondb45ca82017-09-11 18:27:34 -07003221 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
Harald Alvestrand61f74d92020-03-02 11:20:00 +01003222 ASSERT_TRUE(pc_->can_trickle_ice_candidates());
3223 EXPECT_TRUE(*(pc_->can_trickle_ice_candidates()));
deadbeef30952b42017-04-21 02:41:29 -07003224 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003225 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003226 desc = answer->description();
3227 ASSERT_EQ(2u, desc->transport_infos().size());
3228 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3229 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3230}
3231
deadbeef1dcb1642017-03-29 21:08:16 -07003232// Test that ICE renomination isn't offered if it's not enabled in the PC's
3233// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003234TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003235 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003236 config.sdp_semantics = sdp_semantics_;
deadbeef1dcb1642017-03-29 21:08:16 -07003237 config.enable_ice_renomination = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02003238 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003239 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003240
3241 std::unique_ptr<SessionDescriptionInterface> offer;
3242 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3243 cricket::SessionDescription* desc = offer->description();
3244 EXPECT_EQ(1u, desc->transport_infos().size());
3245 EXPECT_FALSE(
3246 desc->transport_infos()[0].description.GetIceParameters().renomination);
3247}
3248
3249// Test that the ICE renomination option is present in generated offers/answers
3250// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003251TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003252 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003253 config.sdp_semantics = sdp_semantics_;
deadbeef1dcb1642017-03-29 21:08:16 -07003254 config.enable_ice_renomination = true;
Niels Möllerf06f9232018-08-07 12:32:18 +02003255 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003256 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003257
3258 std::unique_ptr<SessionDescriptionInterface> offer;
3259 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3260 cricket::SessionDescription* desc = offer->description();
3261 EXPECT_EQ(1u, desc->transport_infos().size());
3262 EXPECT_TRUE(
3263 desc->transport_infos()[0].description.GetIceParameters().renomination);
3264
3265 // Set the offer as a remote description, then create an answer and ensure it
3266 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003267 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003268 std::unique_ptr<SessionDescriptionInterface> answer;
3269 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3270 desc = answer->description();
3271 EXPECT_EQ(1u, desc->transport_infos().size());
3272 EXPECT_TRUE(
3273 desc->transport_infos()[0].description.GetIceParameters().renomination);
3274}
3275
3276// Test that if CreateOffer is called with the deprecated "offer to receive
3277// audio/video" constraints, they're processed and result in an offer with
3278// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003279TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003280 CreatePeerConnection();
3281
Niels Möllerf06f9232018-08-07 12:32:18 +02003282 RTCOfferAnswerOptions options;
3283 options.offer_to_receive_audio = 1;
3284 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003285 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003286 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003287
3288 cricket::SessionDescription* desc = offer->description();
3289 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3290 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3291 ASSERT_NE(nullptr, audio);
3292 ASSERT_NE(nullptr, video);
3293 EXPECT_FALSE(audio->rejected);
3294 EXPECT_FALSE(video->rejected);
3295}
3296
3297// Test that if CreateAnswer is called with the deprecated "offer to receive
3298// audio/video" constraints, they're processed and can be used to reject an
3299// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003300// Don't run under Unified Plan since this behavior is not supported.
3301TEST_F(PeerConnectionInterfaceTestPlanB,
3302 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003303 CreatePeerConnection();
3304
3305 // First, create an offer with audio/video and apply it as a remote
3306 // description.
Niels Möllerf06f9232018-08-07 12:32:18 +02003307 RTCOfferAnswerOptions options;
3308 options.offer_to_receive_audio = 1;
3309 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003310 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003311 ASSERT_TRUE(DoCreateOffer(&offer, &options));
Steve Antondb45ca82017-09-11 18:27:34 -07003312 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003313
3314 // Now create answer that rejects audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003315 options.offer_to_receive_audio = 0;
3316 options.offer_to_receive_video = 0;
deadbeef1dcb1642017-03-29 21:08:16 -07003317 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003318 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003319
3320 cricket::SessionDescription* desc = answer->description();
3321 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3322 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3323 ASSERT_NE(nullptr, audio);
3324 ASSERT_NE(nullptr, video);
3325 EXPECT_TRUE(audio->rejected);
3326 EXPECT_TRUE(video->rejected);
3327}
3328
deadbeef1dcb1642017-03-29 21:08:16 -07003329// Test that negotiation can succeed with a data channel only, and with the max
3330// bundle policy. Previously there was a bug that prevented this.
Mirko Bonadei5eb43b42021-01-18 13:24:40 +01003331#ifdef WEBRTC_HAVE_SCTP
Steve Anton36da6ff2018-02-16 16:04:20 -08003332TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3333#else
3334TEST_P(PeerConnectionInterfaceTest,
3335 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
Mirko Bonadei5eb43b42021-01-18 13:24:40 +01003336#endif // WEBRTC_HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003337 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003338 config.sdp_semantics = sdp_semantics_;
deadbeef1dcb1642017-03-29 21:08:16 -07003339 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möllerf06f9232018-08-07 12:32:18 +02003340 CreatePeerConnection(config);
deadbeef1dcb1642017-03-29 21:08:16 -07003341
3342 // First, create an offer with only a data channel and apply it as a remote
3343 // description.
Florent Castelli72424402022-04-06 03:45:10 +02003344 pc_->CreateDataChannelOrError("test", nullptr);
deadbeef1dcb1642017-03-29 21:08:16 -07003345 std::unique_ptr<SessionDescriptionInterface> offer;
3346 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003347 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003348
3349 // Create and set answer as well.
3350 std::unique_ptr<SessionDescriptionInterface> answer;
3351 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003352 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003353}
3354
Steve Anton36da6ff2018-02-16 16:04:20 -08003355TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003356 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003357 BitrateSettings bitrate;
3358 bitrate.start_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003359 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3360}
3361
Steve Anton36da6ff2018-02-16 16:04:20 -08003362TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
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 = -1;
zstein4b979802017-06-02 14:37:37 -07003366 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3367}
3368
Steve Anton36da6ff2018-02-16 16:04:20 -08003369TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003370 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003371 BitrateSettings bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003372 bitrate.min_bitrate_bps = 5;
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003373 bitrate.start_bitrate_bps = 3;
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, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003378 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003379 BitrateSettings bitrate;
3380 bitrate.start_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003381 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3382}
3383
Steve Anton36da6ff2018-02-16 16:04:20 -08003384TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003385 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003386 BitrateSettings bitrate;
3387 bitrate.start_bitrate_bps = 10;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003388 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003389 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3390}
3391
Steve Anton36da6ff2018-02-16 16:04:20 -08003392TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003393 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003394 BitrateSettings bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003395 bitrate.min_bitrate_bps = 10;
3396 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003397 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3398}
3399
Steve Anton36da6ff2018-02-16 16:04:20 -08003400TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003401 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003402 BitrateSettings bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003403 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003404 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3405}
3406
Niels Möller0c4f7be2018-05-07 14:01:37 +02003407// The current bitrate from BitrateSettings is currently clamped
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003408// by Call's BitrateConstraints, which comes from the SDP or a default value.
3409// This test checks that a call to SetBitrate with a current bitrate that will
3410// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003411TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003412 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003413 BitrateSettings bitrate;
3414 bitrate.start_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003415 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3416}
3417
zhihuang1c378ed2017-08-17 14:10:50 -07003418// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003419TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003420 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3421 RTCOfferAnswerOptions rtc_options;
3422
3423 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3424 // than kMaxOfferToReceiveMedia should be treated as invalid.
3425 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3426 CreatePeerConnection();
3427 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3428
3429 rtc_options.offer_to_receive_audio =
3430 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3431 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3432}
3433
Steve Anton36da6ff2018-02-16 16:04:20 -08003434TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003435 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3436 RTCOfferAnswerOptions rtc_options;
3437
3438 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3439 // than kMaxOfferToReceiveMedia should be treated as invalid.
3440 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3441 CreatePeerConnection();
3442 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3443
3444 rtc_options.offer_to_receive_video =
3445 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3446 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3447}
3448
3449// Test that the audio and video content will be added to an offer if both
Artem Titov880fa812021-07-30 22:30:23 +02003450// `offer_to_receive_audio` and `offer_to_receive_video` options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003451TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003452 RTCOfferAnswerOptions rtc_options;
3453 rtc_options.offer_to_receive_audio = 1;
3454 rtc_options.offer_to_receive_video = 1;
3455
3456 std::unique_ptr<SessionDescriptionInterface> offer;
3457 CreatePeerConnection();
3458 offer = CreateOfferWithOptions(rtc_options);
3459 ASSERT_TRUE(offer);
3460 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3461 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3462}
3463
3464// Test that only audio content will be added to the offer if only
Artem Titov880fa812021-07-30 22:30:23 +02003465// `offer_to_receive_audio` options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003466TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003467 RTCOfferAnswerOptions rtc_options;
3468 rtc_options.offer_to_receive_audio = 1;
3469 rtc_options.offer_to_receive_video = 0;
3470
3471 std::unique_ptr<SessionDescriptionInterface> offer;
3472 CreatePeerConnection();
3473 offer = CreateOfferWithOptions(rtc_options);
3474 ASSERT_TRUE(offer);
3475 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3476 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3477}
3478
Artem Titov880fa812021-07-30 22:30:23 +02003479// Test that only video content will be added if only `offer_to_receive_video`
zhihuang1c378ed2017-08-17 14:10:50 -07003480// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003481TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003482 RTCOfferAnswerOptions rtc_options;
3483 rtc_options.offer_to_receive_audio = 0;
3484 rtc_options.offer_to_receive_video = 1;
3485
3486 std::unique_ptr<SessionDescriptionInterface> offer;
3487 CreatePeerConnection();
3488 offer = CreateOfferWithOptions(rtc_options);
3489 ASSERT_TRUE(offer);
3490 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3491 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3492}
3493
zhihuang1c378ed2017-08-17 14:10:50 -07003494// Test that no media content will be added to the offer if using default
3495// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003496TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003497 RTCOfferAnswerOptions rtc_options;
3498
3499 std::unique_ptr<SessionDescriptionInterface> offer;
3500 CreatePeerConnection();
3501 offer = CreateOfferWithOptions(rtc_options);
3502 ASSERT_TRUE(offer);
3503 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3504 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3505}
3506
Artem Titov880fa812021-07-30 22:30:23 +02003507// Test that if `ice_restart` is true, the ufrag/pwd will change, otherwise
zhihuang1c378ed2017-08-17 14:10:50 -07003508// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003509TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3510 CreatePeerConnection();
3511
zhihuang1c378ed2017-08-17 14:10:50 -07003512 RTCOfferAnswerOptions rtc_options;
3513 rtc_options.ice_restart = false;
3514 rtc_options.offer_to_receive_audio = 1;
3515
3516 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003517 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003518 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3519 auto ufrag1 =
3520 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3521 auto pwd1 =
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 false, the ufrag/pwd shouldn't change.
zhihuang1c378ed2017-08-17 14:10:50 -07003525 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003526 auto ufrag2 =
3527 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3528 auto pwd2 =
3529 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003530
Artem Titov880fa812021-07-30 22:30:23 +02003531 // `ice_restart` is true, the ufrag/pwd should change.
zhihuang1c378ed2017-08-17 14:10:50 -07003532 rtc_options.ice_restart = true;
3533 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003534 auto ufrag3 =
3535 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3536 auto pwd3 =
3537 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003538
3539 EXPECT_EQ(ufrag1, ufrag2);
3540 EXPECT_EQ(pwd1, pwd2);
3541 EXPECT_NE(ufrag2, ufrag3);
3542 EXPECT_NE(pwd2, pwd3);
3543}
3544
Artem Titov880fa812021-07-30 22:30:23 +02003545// Test that if `use_rtp_mux` is true, the bundling will be enabled in the
zhihuang1c378ed2017-08-17 14:10:50 -07003546// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003547TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003548 RTCOfferAnswerOptions rtc_options;
3549 rtc_options.offer_to_receive_audio = 1;
3550 rtc_options.offer_to_receive_video = 1;
3551
3552 std::unique_ptr<SessionDescriptionInterface> offer;
3553 CreatePeerConnection();
3554
3555 rtc_options.use_rtp_mux = true;
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_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3561
3562 rtc_options.use_rtp_mux = false;
3563 offer = CreateOfferWithOptions(rtc_options);
3564 ASSERT_TRUE(offer);
3565 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3566 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3567 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3568}
3569
zhihuang141aacb2017-08-29 13:23:53 -07003570// This test ensures OnRenegotiationNeeded is called when we add track with
3571// MediaStream -> AddTrack in the same way it is called when we add track with
3572// PeerConnection -> AddTrack.
3573// The test can be removed once addStream is rewritten in terms of addTrack
3574// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003575// Don't run under Unified Plan since the stream API is not available.
3576TEST_F(PeerConnectionInterfaceTestPlanB,
3577 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003578 CreatePeerConnectionWithoutDtls();
3579 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003580 pc_factory_->CreateLocalMediaStream(kStreamId1));
Niels Möllerafb246b2022-04-20 14:26:50 +02003581 pc_->AddStream(stream.get());
zhihuang141aacb2017-08-29 13:23:53 -07003582 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01003583 CreateAudioTrack("audio_track"));
zhihuang141aacb2017-08-29 13:23:53 -07003584 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01003585 CreateVideoTrack("video_track"));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00003586 stream->AddTrack(audio_track);
zhihuang141aacb2017-08-29 13:23:53 -07003587 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3588 observer_.renegotiation_needed_ = false;
3589
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003590 CreateOfferReceiveAnswer();
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00003591 stream->AddTrack(video_track);
zhihuang141aacb2017-08-29 13:23:53 -07003592 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3593 observer_.renegotiation_needed_ = false;
3594
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003595 CreateOfferReceiveAnswer();
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00003596 stream->RemoveTrack(audio_track);
zhihuang141aacb2017-08-29 13:23:53 -07003597 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3598 observer_.renegotiation_needed_ = false;
3599
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003600 CreateOfferReceiveAnswer();
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00003601 stream->RemoveTrack(video_track);
zhihuang141aacb2017-08-29 13:23:53 -07003602 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3603 observer_.renegotiation_needed_ = false;
3604}
3605
Zhi Huangb2d355e2017-10-26 17:26:37 -07003606// Tests that an error is returned if a description is applied that has fewer
3607// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003608TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003609 MediaSectionCountEnforcedForSubsequentOffer) {
3610 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003611 AddAudioTrack("audio_label");
3612 AddVideoTrack("video_label");
3613
Zhi Huangb2d355e2017-10-26 17:26:37 -07003614 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003615 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003616 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3617
3618 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003619 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003620 offer->description()->contents().pop_back();
3621 offer->description()->contents().pop_back();
3622 ASSERT_TRUE(offer->description()->contents().empty());
3623 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3624
3625 std::unique_ptr<SessionDescriptionInterface> answer;
3626 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3627 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3628
3629 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003630 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003631 offer->description()->contents().pop_back();
3632 offer->description()->contents().pop_back();
3633 ASSERT_TRUE(offer->description()->contents().empty());
3634 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3635}
3636
Johannes Kron89f874e2018-11-12 10:25:48 +01003637TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) {
3638 RTCConfiguration config;
Emil Lundmark801c9992021-01-19 13:06:32 +01003639 // Default behavior is true.
Johannes Kron89f874e2018-11-12 10:25:48 +01003640 CreatePeerConnection(config);
3641 std::unique_ptr<SessionDescriptionInterface> offer;
3642 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Emil Lundmark801c9992021-01-19 13:06:32 +01003643 EXPECT_TRUE(offer->description()->extmap_allow_mixed());
3644 // Possible to set to false.
3645 config.offer_extmap_allow_mixed = false;
Johannes Kron89f874e2018-11-12 10:25:48 +01003646 CreatePeerConnection(config);
Artem Titov4f3a2eb2021-01-26 09:58:21 +01003647 offer = nullptr;
Johannes Kron89f874e2018-11-12 10:25:48 +01003648 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Emil Lundmark801c9992021-01-19 13:06:32 +01003649 EXPECT_FALSE(offer->description()->extmap_allow_mixed());
Johannes Kron89f874e2018-11-12 10:25:48 +01003650}
3651
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003652INSTANTIATE_TEST_SUITE_P(PeerConnectionInterfaceTest,
3653 PeerConnectionInterfaceTest,
Florent Castelli15a38de2022-04-06 00:38:21 +02003654 Values(SdpSemantics::kPlanB_DEPRECATED,
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003655 SdpSemantics::kUnifiedPlan));
Steve Anton36da6ff2018-02-16 16:04:20 -08003656
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003657class PeerConnectionMediaConfigTest : public ::testing::Test {
nisse51542be2016-02-12 02:27:06 -08003658 protected:
3659 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07003660 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08003661 }
nisseeaabdf62017-05-05 02:23:02 -07003662 const cricket::MediaConfig TestCreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +02003663 const RTCConfiguration& config) {
Florent Castelli72424402022-04-06 03:45:10 +02003664 PeerConnectionDependencies pc_dependencies(&observer_);
3665 auto result =
3666 pcf_->CreatePeerConnectionOrError(config, std::move(pc_dependencies));
3667 EXPECT_TRUE(result.ok());
Niels Möllerafb246b2022-04-20 14:26:50 +02003668 observer_.SetPeerConnectionInterface(result.value().get());
Florent Castelli72424402022-04-06 03:45:10 +02003669 return result.value()->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08003670 }
3671
zhihuang9763d562016-08-05 11:14:50 -07003672 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003673 MockPeerConnectionObserver observer_;
3674};
3675
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003676// This sanity check validates the test infrastructure itself.
3677TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) {
3678 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003679 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
Florent Castelli72424402022-04-06 03:45:10 +02003680 PeerConnectionDependencies pc_dependencies(&observer_);
3681 auto result =
3682 pcf_->CreatePeerConnectionOrError(config, std::move(pc_dependencies));
3683 EXPECT_TRUE(result.ok());
Niels Möllerafb246b2022-04-20 14:26:50 +02003684 observer_.SetPeerConnectionInterface(result.value().get());
Florent Castelli72424402022-04-06 03:45:10 +02003685 result.value()->Close(); // No abort -> ok.
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003686 SUCCEED();
3687}
3688
nisse51542be2016-02-12 02:27:06 -08003689// This test verifies the default behaviour with no constraints and a
3690// default RTCConfiguration.
3691TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
3692 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003693 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
nisse51542be2016-02-12 02:27:06 -08003694
Niels Möllerf06f9232018-08-07 12:32:18 +02003695 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003696
Henrik Boström35c5cc82022-04-14 09:23:20 +02003697 EXPECT_TRUE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01003698 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
3699 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003700 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01003701 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08003702}
3703
Niels Möller1d7ecd22018-01-18 15:25:12 +01003704// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07003705// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08003706TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
3707 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003708 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
nisse51542be2016-02-12 02:27:06 -08003709
Niels Möller71bdda02016-03-31 12:59:59 +02003710 config.set_prerenderer_smoothing(false);
Niels Möllerf06f9232018-08-07 12:32:18 +02003711 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003712
Niels Möller1d7ecd22018-01-18 15:25:12 +01003713 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003714}
3715
Niels Möller6539f692018-01-18 08:58:50 +01003716// This test verifies that the experiment_cpu_load_estimator flag is
3717// propagated from RTCConfiguration to the PeerConnection.
3718TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
3719 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003720 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
Niels Möller6539f692018-01-18 08:58:50 +01003721
3722 config.set_experiment_cpu_load_estimator(true);
Niels Möllerf06f9232018-08-07 12:32:18 +02003723 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
Niels Möller6539f692018-01-18 08:58:50 +01003724
3725 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
3726}
3727
deadbeef293e9262017-01-11 12:28:30 -08003728// Tests a few random fields being different.
3729TEST(RTCConfigurationTest, ComparisonOperators) {
3730 PeerConnectionInterface::RTCConfiguration a;
3731 PeerConnectionInterface::RTCConfiguration b;
3732 EXPECT_EQ(a, b);
3733
3734 PeerConnectionInterface::RTCConfiguration c;
3735 c.servers.push_back(PeerConnectionInterface::IceServer());
3736 EXPECT_NE(a, c);
3737
3738 PeerConnectionInterface::RTCConfiguration d;
3739 d.type = PeerConnectionInterface::kRelay;
3740 EXPECT_NE(a, d);
3741
3742 PeerConnectionInterface::RTCConfiguration e;
3743 e.audio_jitter_buffer_max_packets = 5;
3744 EXPECT_NE(a, e);
3745
3746 PeerConnectionInterface::RTCConfiguration f;
3747 f.ice_connection_receiving_timeout = 1337;
3748 EXPECT_NE(a, f);
3749
3750 PeerConnectionInterface::RTCConfiguration g;
3751 g.disable_ipv6 = true;
3752 EXPECT_NE(a, g);
3753
3754 PeerConnectionInterface::RTCConfiguration h(
3755 PeerConnectionInterface::RTCConfigurationType::kAggressive);
3756 EXPECT_NE(a, h);
3757}
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +01003758
3759} // namespace
3760} // namespace webrtc