blob: 2991fac588b23e2ac8745f934ffe27b78f50515e [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; }
Björn Terelius63299a32022-07-05 10:58:52 +0200440 bool Write(const std::string& /*output*/) override { return true; }
441 bool Write(const absl::string_view /*output*/) override { return true; }
Niels Möllerdec9f742019-06-03 15:25:20 +0200442};
443
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +0100444using ::cricket::StreamParams;
perkjd61bf802016-03-24 03:16:19 -0700445using ::testing::Exactly;
Steve Anton36da6ff2018-02-16 16:04:20 -0800446using ::testing::Values;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000447
Steve Anton36da6ff2018-02-16 16:04:20 -0800448using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
449using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
deadbeefab9b2d12015-10-14 11:33:11 -0700450
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000451// Gets the first ssrc of given content type from the ContentInfo.
452bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
453 if (!content_info || !ssrc) {
454 return false;
455 }
456 const cricket::MediaContentDescription* media_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -0800457 content_info->media_description();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000458 if (!media_desc || media_desc->streams().empty()) {
459 return false;
460 }
461 *ssrc = media_desc->streams().begin()->first_ssrc();
462 return true;
463}
464
deadbeefd1a38b52016-12-10 13:15:33 -0800465// Get the ufrags out of an SDP blob. Useful for testing ICE restart
466// behavior.
467std::vector<std::string> GetUfrags(
468 const webrtc::SessionDescriptionInterface* desc) {
469 std::vector<std::string> ufrags;
470 for (const cricket::TransportInfo& info :
471 desc->description()->transport_infos()) {
472 ufrags.push_back(info.description.ice_ufrag);
473 }
474 return ufrags;
475}
476
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000477void SetSsrcToZero(std::string* sdp) {
478 const char kSdpSsrcAtribute[] = "a=ssrc:";
479 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
480 size_t ssrc_pos = 0;
481 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
Yves Gerey665174f2018-06-19 15:03:05 +0200482 std::string::npos) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000483 size_t end_ssrc = sdp->find(" ", ssrc_pos);
484 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
485 ssrc_pos = end_ssrc;
486 }
487}
488
Artem Titov880fa812021-07-30 22:30:23 +0200489// Check if `streams` contains the specified track.
deadbeefab9b2d12015-10-14 11:33:11 -0700490bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
Seth Hampson845e8782018-03-02 11:34:10 -0800491 const std::string& stream_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700492 const std::string& track_id) {
493 for (const cricket::StreamParams& params : streams) {
Seth Hampson845e8782018-03-02 11:34:10 -0800494 if (params.first_stream_id() == stream_id && params.id == track_id) {
deadbeefab9b2d12015-10-14 11:33:11 -0700495 return true;
496 }
497 }
498 return false;
499}
500
Artem Titov880fa812021-07-30 22:30:23 +0200501// Check if `senders` contains the specified sender, by id.
deadbeefab9b2d12015-10-14 11:33:11 -0700502bool ContainsSender(
503 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
504 const std::string& id) {
505 for (const auto& sender : senders) {
506 if (sender->id() == id) {
507 return true;
508 }
509 }
510 return false;
511}
512
Artem Titov880fa812021-07-30 22:30:23 +0200513// Check if `senders` contains the specified sender, by id and stream id.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700514bool ContainsSender(
515 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
516 const std::string& id,
517 const std::string& stream_id) {
518 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700519 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700520 return true;
521 }
522 }
523 return false;
524}
525
deadbeefab9b2d12015-10-14 11:33:11 -0700526// Create a collection of streams.
527// CreateStreamCollection(1) creates a collection that
528// correspond to kSdpStringWithStream1.
529// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
530rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700531 int number_of_streams,
532 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700533 rtc::scoped_refptr<StreamCollection> local_collection(
534 StreamCollection::Create());
535
536 for (int i = 0; i < number_of_streams; ++i) {
537 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
538 webrtc::MediaStream::Create(kStreams[i]));
539
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700540 for (int j = 0; j < tracks_per_stream; ++j) {
541 // Add a local audio track.
542 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
543 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
544 nullptr));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +0000545 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700546
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700547 // Add a local video track.
548 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
549 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
perkj773be362017-07-31 23:22:01 -0700550 webrtc::FakeVideoTrackSource::Create(),
551 rtc::Thread::Current()));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +0000552 stream->AddTrack(video_track);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700553 }
deadbeefab9b2d12015-10-14 11:33:11 -0700554
555 local_collection->AddStream(stream);
556 }
557 return local_collection;
558}
559
560// Check equality of StreamCollections.
561bool CompareStreamCollections(StreamCollectionInterface* s1,
562 StreamCollectionInterface* s2) {
563 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
564 return false;
565 }
566
567 for (size_t i = 0; i != s1->count(); ++i) {
Seth Hampson13b8bad2018-03-13 16:05:28 -0700568 if (s1->at(i)->id() != s2->at(i)->id()) {
deadbeefab9b2d12015-10-14 11:33:11 -0700569 return false;
570 }
571 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
572 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
573 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
574 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
575
576 if (audio_tracks1.size() != audio_tracks2.size()) {
577 return false;
578 }
579 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
580 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
581 return false;
582 }
583 }
584 if (video_tracks1.size() != video_tracks2.size()) {
585 return false;
586 }
587 for (size_t j = 0; j != video_tracks1.size(); ++j) {
588 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
589 return false;
590 }
591 }
592 }
593 return true;
594}
595
perkjd61bf802016-03-24 03:16:19 -0700596// Helper class to test Observer.
597class MockTrackObserver : public ObserverInterface {
598 public:
599 explicit MockTrackObserver(NotifierInterface* notifier)
600 : notifier_(notifier) {
601 notifier_->RegisterObserver(this);
602 }
603
604 ~MockTrackObserver() { Unregister(); }
605
606 void Unregister() {
607 if (notifier_) {
608 notifier_->UnregisterObserver(this);
609 notifier_ = nullptr;
610 }
611 }
612
Danil Chapovalov3a353122020-05-15 11:16:53 +0200613 MOCK_METHOD(void, OnChanged, (), (override));
perkjd61bf802016-03-24 03:16:19 -0700614
615 private:
616 NotifierInterface* notifier_;
617};
618
nisse528b7932017-05-08 03:21:43 -0700619// The PeerConnectionMediaConfig tests below verify that configuration and
620// constraints are propagated into the PeerConnection's MediaConfig. These
621// settings are intended for MediaChannel constructors, but that is not
622// exercised by these unittest.
zhihuang29ff8442016-07-27 11:07:25 -0700623class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
624 public:
zhihuang38ede132017-06-15 12:52:32 -0700625 static rtc::scoped_refptr<PeerConnectionFactoryForTest>
626 CreatePeerConnectionFactoryForTest() {
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100627 PeerConnectionFactoryDependencies dependencies;
628 dependencies.worker_thread = rtc::Thread::Current();
629 dependencies.network_thread = rtc::Thread::Current();
630 dependencies.signaling_thread = rtc::Thread::Current();
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200631 dependencies.task_queue_factory = CreateDefaultTaskQueueFactory();
Erik Språngceb44952020-09-22 11:36:35 +0200632 dependencies.trials = std::make_unique<FieldTrialBasedConfig>();
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200633 cricket::MediaEngineDependencies media_deps;
634 media_deps.task_queue_factory = dependencies.task_queue_factory.get();
henrika919dc2e2017-10-12 14:24:55 +0200635 // Use fake audio device module since we're only testing the interface
636 // level, and using a real one could make tests flaky when run in parallel.
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200637 media_deps.adm = FakeAudioCaptureModule::Create();
638 SetMediaEngineDefaults(&media_deps);
Erik Språngceb44952020-09-22 11:36:35 +0200639 media_deps.trials = dependencies.trials.get();
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200640 dependencies.media_engine =
641 cricket::CreateMediaEngine(std::move(media_deps));
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100642 dependencies.call_factory = webrtc::CreateCallFactory();
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200643 dependencies.event_log_factory = std::make_unique<RtcEventLogFactory>(
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200644 dependencies.task_queue_factory.get());
zhihuang38ede132017-06-15 12:52:32 -0700645
Tommi87f70902021-04-27 14:43:08 +0200646 return rtc::make_ref_counted<PeerConnectionFactoryForTest>(
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100647 std::move(dependencies));
zhihuang38ede132017-06-15 12:52:32 -0700648 }
649
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100650 using PeerConnectionFactory::PeerConnectionFactory;
kwiberg1e4e8cb2017-01-31 01:48:08 -0800651
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100652 private:
deadbeefd7850b22017-08-23 10:59:19 -0700653 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700654};
655
Steve Anton36da6ff2018-02-16 16:04:20 -0800656// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200657class PeerConnectionInterfaceBaseTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000658 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800659 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
660 : vss_(new rtc::VirtualSocketServer()),
661 main_(vss_.get()),
662 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800663#ifdef WEBRTC_ANDROID
664 webrtc::InitializeAndroidObjects();
665#endif
666 }
667
Tomas Gunnarsson2efb8a52021-04-01 16:26:57 +0200668 void SetUp() override {
deadbeefd7850b22017-08-23 10:59:19 -0700669 // Use fake audio capture module since we're only testing the interface
670 // level, and using a real one could make tests flaky when run in parallel.
671 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000672 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700673 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200674 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
675 fake_audio_capture_module_),
676 webrtc::CreateBuiltinAudioEncoderFactory(),
677 webrtc::CreateBuiltinAudioDecoderFactory(),
678 webrtc::CreateBuiltinVideoEncoderFactory(),
679 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
680 nullptr /* audio_processing */);
danilchape9021a32016-05-17 01:52:02 -0700681 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700682 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700683 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000684 }
685
Tomas Gunnarsson2efb8a52021-04-01 16:26:57 +0200686 void TearDown() override {
687 if (pc_)
688 pc_->Close();
689 }
690
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000691 void CreatePeerConnection() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200692 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 }
694
Harald Alvestrandf9e502d2021-10-13 15:26:26 +0000695 // DTLS does not work in a loopback call, so is disabled for many
deadbeef293e9262017-01-11 12:28:30 -0800696 // tests in this file.
697 void CreatePeerConnectionWithoutDtls() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200698 RTCConfiguration config;
Harald Alvestrandf9e502d2021-10-13 15:26:26 +0000699 PeerConnectionFactoryInterface::Options options;
700 options.disable_encryption = true;
701 pc_factory_->SetOptions(options);
Niels Möllerf06f9232018-08-07 12:32:18 +0200702 CreatePeerConnection(config);
Harald Alvestrandf9e502d2021-10-13 15:26:26 +0000703 options.disable_encryption = false;
704 pc_factory_->SetOptions(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705 }
706
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700707 void CreatePeerConnectionWithIceTransportsType(
708 PeerConnectionInterface::IceTransportsType type) {
709 PeerConnectionInterface::RTCConfiguration config;
710 config.type = type;
Niels Möllerf06f9232018-08-07 12:32:18 +0200711 return CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700712 }
713
714 void CreatePeerConnectionWithIceServer(const std::string& uri,
Niels Möllerdb4def92019-03-18 16:53:59 +0100715 const std::string& username,
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700716 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800717 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700719 server.uri = uri;
Niels Möllerdb4def92019-03-18 16:53:59 +0100720 server.username = username;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700721 server.password = password;
722 config.servers.push_back(server);
Niels Möllerf06f9232018-08-07 12:32:18 +0200723 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700724 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725
Niels Möllerf06f9232018-08-07 12:32:18 +0200726 void CreatePeerConnection(const RTCConfiguration& config) {
Tomas Gunnarsson2efb8a52021-04-01 16:26:57 +0200727 if (pc_) {
728 pc_->Close();
729 pc_ = nullptr;
730 }
kwibergd1fe2812016-04-27 06:47:29 -0700731 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Byoungchan Leed58f5262022-06-27 18:05:22 +0900732 new cricket::FakePortAllocator(
733 rtc::Thread::Current(),
734 std::make_unique<rtc::BasicPacketSocketFactory>(vss_.get())));
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800735 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000736
deadbeef1dcb1642017-03-29 21:08:16 -0700737 // Create certificate generator unless DTLS constraint is explicitly set to
738 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200739 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
Niels Möllerf06f9232018-08-07 12:32:18 +0200740
Harald Alvestrandf9e502d2021-10-13 15:26:26 +0000741 // These won't be used if encryption is turned off, but that's harmless.
742 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
743 cert_generator.reset(fake_certificate_generator_);
744
Steve Anton36da6ff2018-02-16 16:04:20 -0800745 RTCConfiguration modified_config = config;
746 modified_config.sdp_semantics = sdp_semantics_;
Florent Castelli72424402022-04-06 03:45:10 +0200747 PeerConnectionDependencies pc_dependencies(&observer_);
748 pc_dependencies.cert_generator = std::move(cert_generator);
749 pc_dependencies.allocator = std::move(port_allocator);
750 auto result = pc_factory_->CreatePeerConnectionOrError(
751 modified_config, std::move(pc_dependencies));
752 ASSERT_TRUE(result.ok());
753 pc_ = result.MoveValue();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754 observer_.SetPeerConnectionInterface(pc_.get());
755 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
756 }
757
deadbeef0a6c4ca2015-10-06 11:38:28 -0700758 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800759 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700760 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700761 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800762 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800763 config.sdp_semantics = sdp_semantics_;
Florent Castelli72424402022-04-06 03:45:10 +0200764 PeerConnectionDependencies pc_dependencies(&observer_);
765 auto result = pc_factory_->CreatePeerConnectionOrError(
766 config, std::move(pc_dependencies));
767 EXPECT_FALSE(result.ok());
deadbeef0a6c4ca2015-10-06 11:38:28 -0700768 }
769
Steve Anton038834f2017-07-14 15:59:59 -0700770 void CreatePeerConnectionExpectFail(
771 PeerConnectionInterface::RTCConfiguration config) {
772 PeerConnectionInterface::IceServer server;
773 server.uri = kTurnIceServerUri;
774 server.password = kTurnPassword;
775 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800776 config.sdp_semantics = sdp_semantics_;
Florent Castelli72424402022-04-06 03:45:10 +0200777 PeerConnectionDependencies pc_dependencies(&observer_);
778 auto result = pc_factory_->CreatePeerConnectionOrError(
779 config, std::move(pc_dependencies));
780 EXPECT_FALSE(result.ok());
Steve Anton038834f2017-07-14 15:59:59 -0700781 }
782
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783 void CreatePeerConnectionWithDifferentConfigurations() {
Niels Möllerdb4def92019-03-18 16:53:59 +0100784 CreatePeerConnectionWithIceServer(kStunAddressOnly, "", "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800785 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
786 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
787 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800789 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790
deadbeef0a6c4ca2015-10-06 11:38:28 -0700791 CreatePeerConnectionExpectFail(kStunInvalidPort);
792 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
793 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794
Niels Möllerdb4def92019-03-18 16:53:59 +0100795 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnUsername,
796 kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800797 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
798 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800800 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800802 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800804 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 }
806
807 void ReleasePeerConnection() {
Niels Möllerafb246b2022-04-20 14:26:50 +0200808 pc_ = nullptr;
809 observer_.SetPeerConnectionInterface(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810 }
811
Steve Anton36da6ff2018-02-16 16:04:20 -0800812 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
813 const std::string& label) {
Niels Möllerafb246b2022-04-20 14:26:50 +0200814 return pc_factory_->CreateVideoTrack(label,
815 FakeVideoTrackSource::Create().get());
Steve Anton36da6ff2018-02-16 16:04:20 -0800816 }
817
818 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800819 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800820 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800821 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800822 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 }
824
Steve Anton36da6ff2018-02-16 16:04:20 -0800825 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700826 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827 pc_factory_->CreateLocalMediaStream(label));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +0000828 stream->AddTrack(CreateVideoTrack(label + "v0"));
Niels Möllerafb246b2022-04-20 14:26:50 +0200829 ASSERT_TRUE(pc_->AddStream(stream.get()));
Steve Anton36da6ff2018-02-16 16:04:20 -0800830 }
831
832 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
833 const std::string& label) {
834 return pc_factory_->CreateAudioTrack(label, nullptr);
835 }
836
837 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800838 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800839 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800840 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800841 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
Steve Anton36da6ff2018-02-16 16:04:20 -0800842 }
843
844 void AddAudioStream(const std::string& label) {
845 rtc::scoped_refptr<MediaStreamInterface> stream(
846 pc_factory_->CreateLocalMediaStream(label));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +0000847 stream->AddTrack(CreateAudioTrack(label + "a0"));
Niels Möllerafb246b2022-04-20 14:26:50 +0200848 ASSERT_TRUE(pc_->AddStream(stream.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 }
850
Seth Hampson845e8782018-03-02 11:34:10 -0800851 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000852 const std::string& audio_track_label,
853 const std::string& video_track_label) {
854 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700855 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800856 pc_factory_->CreateLocalMediaStream(stream_id));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +0000857 stream->AddTrack(CreateAudioTrack(audio_track_label));
858 stream->AddTrack(CreateVideoTrack(video_track_label));
Niels Möllerafb246b2022-04-20 14:26:50 +0200859 ASSERT_TRUE(pc_->AddStream(stream.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 }
861
Steve Anton36da6ff2018-02-16 16:04:20 -0800862 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
863 cricket::MediaType media_type) {
864 for (auto receiver : pc_->GetReceivers()) {
865 if (receiver->media_type() == media_type) {
866 return receiver;
867 }
868 }
869 return nullptr;
870 }
871
kwibergd1fe2812016-04-27 06:47:29 -0700872 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200873 const RTCOfferAnswerOptions* options,
874 bool offer) {
Tommi87f70902021-04-27 14:43:08 +0200875 auto observer =
876 rtc::make_ref_counted<MockCreateSessionDescriptionObserver>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877 if (offer) {
Niels Möllerafb246b2022-04-20 14:26:50 +0200878 pc_->CreateOffer(observer.get(),
879 options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880 } else {
Niels Möllerafb246b2022-04-20 14:26:50 +0200881 pc_->CreateAnswer(observer.get(),
882 options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 }
884 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700885 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886 return observer->result();
887 }
888
kwibergd1fe2812016-04-27 06:47:29 -0700889 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200890 const RTCOfferAnswerOptions* options) {
891 return DoCreateOfferAnswer(desc, options, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892 }
893
kwibergd1fe2812016-04-27 06:47:29 -0700894 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200895 const RTCOfferAnswerOptions* options) {
896 return DoCreateOfferAnswer(desc, options, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897 }
898
Steve Antondb45ca82017-09-11 18:27:34 -0700899 bool DoSetSessionDescription(
900 std::unique_ptr<SessionDescriptionInterface> desc,
901 bool local) {
Tommi87f70902021-04-27 14:43:08 +0200902 auto observer = rtc::make_ref_counted<MockSetSessionDescriptionObserver>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903 if (local) {
Niels Möllerafb246b2022-04-20 14:26:50 +0200904 pc_->SetLocalDescription(observer.get(), desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905 } else {
Niels Möllerafb246b2022-04-20 14:26:50 +0200906 pc_->SetRemoteDescription(observer.get(), desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907 }
zhihuang29ff8442016-07-27 11:07:25 -0700908 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
909 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
910 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911 return observer->result();
912 }
913
Steve Antondb45ca82017-09-11 18:27:34 -0700914 bool DoSetLocalDescription(
915 std::unique_ptr<SessionDescriptionInterface> desc) {
916 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917 }
918
Steve Antondb45ca82017-09-11 18:27:34 -0700919 bool DoSetRemoteDescription(
920 std::unique_ptr<SessionDescriptionInterface> desc) {
921 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 }
923
924 // Calls PeerConnection::GetStats and check the return value.
925 // It does not verify the values in the StatReports since a RTCP packet might
926 // be required.
927 bool DoGetStats(MediaStreamTrackInterface* track) {
Tommi87f70902021-04-27 14:43:08 +0200928 auto observer = rtc::make_ref_counted<MockStatsObserver>();
Niels Möllerafb246b2022-04-20 14:26:50 +0200929 if (!pc_->GetStats(observer.get(), track,
Yves Gerey665174f2018-06-19 15:03:05 +0200930 PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 return false;
932 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
933 return observer->called();
934 }
935
Harald Alvestrand89061872018-01-02 14:08:34 +0100936 // Call the standards-compliant GetStats function.
937 bool DoGetRTCStats() {
Tommi87f70902021-04-27 14:43:08 +0200938 auto callback =
939 rtc::make_ref_counted<webrtc::MockRTCStatsCollectorCallback>();
Niels Möllerafb246b2022-04-20 14:26:50 +0200940 pc_->GetStats(callback.get());
Harald Alvestrand89061872018-01-02 14:08:34 +0100941 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
942 return callback->called();
943 }
944
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800946 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 // Create a local stream with audio&video tracks.
Florent Castelli15a38de2022-04-06 00:38:21 +0200948 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Seth Hampson845e8782018-03-02 11:34:10 -0800949 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800950 } else {
951 // Unified Plan does not support AddStream, so just add an audio and video
952 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800953 AddAudioTrack(kAudioTracks[0], {kStreamId1});
954 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800955 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000956 CreateOfferReceiveAnswer();
957 }
958
959 // Verify that RTP Header extensions has been negotiated for audio and video.
960 void VerifyRemoteRtpHeaderExtensions() {
961 const cricket::MediaContentDescription* desc =
962 cricket::GetFirstAudioContentDescription(
963 pc_->remote_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +0200964 ASSERT_TRUE(desc != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000965 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
966
967 desc = cricket::GetFirstVideoContentDescription(
968 pc_->remote_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +0200969 ASSERT_TRUE(desc != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
971 }
972
973 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700974 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700975 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976 std::string sdp;
977 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700978 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800979 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700980 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000981 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
982 }
983
deadbeefab9b2d12015-10-14 11:33:11 -0700984 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -0700985 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800986 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700987 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -0700988 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
989 }
990
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700992 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -0700993 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000994
995 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
996 // audio codec change, even if the parameter has nothing to do with
997 // receiving. Not all parameters are serialized to SDP.
998 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
999 // the SessionDescription, it is necessary to do that here to in order to
1000 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1001 // https://code.google.com/p/webrtc/issues/detail?id=1356
1002 std::string sdp;
1003 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001004 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001005 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001006 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001007 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1008 }
1009
1010 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001011 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001012 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001013
1014 std::string sdp;
1015 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001016 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001017 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001018 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001019 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1020 }
1021
1022 void CreateOfferReceiveAnswer() {
1023 CreateOfferAsLocalDescription();
1024 std::string sdp;
1025 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1026 CreateAnswerAsRemoteDescription(sdp);
1027 }
1028
1029 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001030 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001031 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1033 // audio codec change, even if the parameter has nothing to do with
1034 // receiving. Not all parameters are serialized to SDP.
1035 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1036 // the SessionDescription, it is necessary to do that here to in order to
1037 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1038 // https://code.google.com/p/webrtc/issues/detail?id=1356
1039 std::string sdp;
1040 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001041 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001042 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001043
Steve Antondb45ca82017-09-11 18:27:34 -07001044 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001045 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001046 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001047 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001048 }
1049
deadbeefab9b2d12015-10-14 11:33:11 -07001050 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001051 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001052 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001053 ASSERT_TRUE(answer);
1054 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001055 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1056 }
1057
deadbeefab9b2d12015-10-14 11:33:11 -07001058 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001059 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001060 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001061 ASSERT_TRUE(pr_answer);
1062 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001064 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001065 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001066 ASSERT_TRUE(answer);
1067 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1069 }
1070
Seth Hampson845e8782018-03-02 11:34:10 -08001071 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001072 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001073 // called with the given stream id and expected number of tracks.
1074 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001075 int expected_num_tracks) {
1076 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001077 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001078 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001079 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080 }
1081
1082 // Creates an offer and applies it as a local session description.
1083 // Creates an answer with the same SDP an the offer but removes all lines
1084 // that start with a:ssrc"
1085 void CreateOfferReceiveAnswerWithoutSsrc() {
1086 CreateOfferAsLocalDescription();
1087 std::string sdp;
1088 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1089 SetSsrcToZero(&sdp);
1090 CreateAnswerAsRemoteDescription(sdp);
1091 }
1092
deadbeefab9b2d12015-10-14 11:33:11 -07001093 // This function creates a MediaStream with label kStreams[0] and
Artem Titov880fa812021-07-30 22:30:23 +02001094 // `number_of_audio_tracks` and `number_of_video_tracks` tracks and the
deadbeefab9b2d12015-10-14 11:33:11 -07001095 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001096 // is returned and the MediaStream is stored in
Artem Titov880fa812021-07-30 22:30:23 +02001097 // `reference_collection_`
kwibergd1fe2812016-04-27 06:47:29 -07001098 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001099 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1100 size_t number_of_video_tracks) {
1101 EXPECT_LE(number_of_audio_tracks, 2u);
1102 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001103
1104 reference_collection_ = StreamCollection::Create();
1105 std::string sdp_ms1 = std::string(kSdpStringInit);
1106
Seth Hampson845e8782018-03-02 11:34:10 -08001107 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001108
1109 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001110 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001111 reference_collection_->AddStream(stream);
1112
1113 if (number_of_audio_tracks > 0) {
1114 sdp_ms1 += std::string(kSdpStringAudio);
1115 sdp_ms1 += std::string(kSdpStringMs1Audio0);
Niels Möllerafb246b2022-04-20 14:26:50 +02001116 AddAudioTrack(kAudioTracks[0], stream.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001117 }
1118 if (number_of_audio_tracks > 1) {
1119 sdp_ms1 += kSdpStringMs1Audio1;
Niels Möllerafb246b2022-04-20 14:26:50 +02001120 AddAudioTrack(kAudioTracks[1], stream.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001121 }
1122
1123 if (number_of_video_tracks > 0) {
1124 sdp_ms1 += std::string(kSdpStringVideo);
1125 sdp_ms1 += std::string(kSdpStringMs1Video0);
Niels Möllerafb246b2022-04-20 14:26:50 +02001126 AddVideoTrack(kVideoTracks[0], stream.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001127 }
1128 if (number_of_video_tracks > 1) {
1129 sdp_ms1 += kSdpStringMs1Video1;
Niels Möllerafb246b2022-04-20 14:26:50 +02001130 AddVideoTrack(kVideoTracks[1], stream.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001131 }
1132
kwibergd1fe2812016-04-27 06:47:29 -07001133 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001134 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001135 }
1136
1137 void AddAudioTrack(const std::string& track_id,
1138 MediaStreamInterface* stream) {
1139 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1140 webrtc::AudioTrack::Create(track_id, nullptr));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00001141 ASSERT_TRUE(stream->AddTrack(audio_track));
deadbeefab9b2d12015-10-14 11:33:11 -07001142 }
1143
1144 void AddVideoTrack(const std::string& track_id,
1145 MediaStreamInterface* stream) {
1146 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001147 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001148 webrtc::FakeVideoTrackSource::Create(),
1149 rtc::Thread::Current()));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00001150 ASSERT_TRUE(stream->AddTrack(video_track));
deadbeefab9b2d12015-10-14 11:33:11 -07001151 }
1152
Steve Anton36da6ff2018-02-16 16:04:20 -08001153 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001154 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001155 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001156 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001157 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1158 return offer;
1159 }
1160
Steve Anton36da6ff2018-02-16 16:04:20 -08001161 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1162 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001163 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001164 std::unique_ptr<SessionDescriptionInterface> offer;
1165 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1166 return offer;
1167 }
1168
1169 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1170 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1171 std::unique_ptr<SessionDescriptionInterface> answer;
1172 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1173 return answer;
1174 }
1175
kwibergfd8be342016-05-14 19:44:11 -07001176 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001177 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001178 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001179 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001180 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1181 return answer;
1182 }
1183
1184 const std::string& GetFirstAudioStreamCname(
1185 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001186 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001187 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001188 return audio_desc->streams()[0].cname;
1189 }
1190
zhihuang1c378ed2017-08-17 14:10:50 -07001191 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1192 const RTCOfferAnswerOptions& offer_answer_options) {
1193 RTC_DCHECK(pc_);
Tommi87f70902021-04-27 14:43:08 +02001194 auto observer =
1195 rtc::make_ref_counted<MockCreateSessionDescriptionObserver>();
Niels Möllerafb246b2022-04-20 14:26:50 +02001196 pc_->CreateOffer(observer.get(), offer_answer_options);
zhihuang1c378ed2017-08-17 14:10:50 -07001197 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1198 return observer->MoveDescription();
1199 }
1200
1201 void CreateOfferWithOptionsAsRemoteDescription(
1202 std::unique_ptr<SessionDescriptionInterface>* desc,
1203 const RTCOfferAnswerOptions& offer_answer_options) {
1204 *desc = CreateOfferWithOptions(offer_answer_options);
1205 ASSERT_TRUE(desc != nullptr);
1206 std::string sdp;
1207 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001208 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001209 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001210 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001211 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1212 }
1213
1214 void CreateOfferWithOptionsAsLocalDescription(
1215 std::unique_ptr<SessionDescriptionInterface>* desc,
1216 const RTCOfferAnswerOptions& offer_answer_options) {
1217 *desc = CreateOfferWithOptions(offer_answer_options);
1218 ASSERT_TRUE(desc != nullptr);
1219 std::string sdp;
1220 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001221 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001222 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001223
Steve Antondb45ca82017-09-11 18:27:34 -07001224 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001225 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1226 }
1227
1228 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001229 RTC_DCHECK(content);
1230 RTC_DCHECK(content->media_description());
1231 for (const cricket::AudioCodec& codec :
1232 content->media_description()->as_audio()->codecs()) {
1233 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001234 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001235 }
zhihuang1c378ed2017-08-17 14:10:50 -07001236 }
1237 return false;
1238 }
1239
Steve Anton36da6ff2018-02-16 16:04:20 -08001240 const char* GetSdpStringWithStream1() const {
Florent Castelli15a38de2022-04-06 00:38:21 +02001241 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Steve Anton36da6ff2018-02-16 16:04:20 -08001242 return kSdpStringWithStream1PlanB;
1243 } else {
1244 return kSdpStringWithStream1UnifiedPlan;
1245 }
1246 }
1247
1248 const char* GetSdpStringWithStream1And2() const {
Florent Castelli15a38de2022-04-06 00:38:21 +02001249 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Steve Anton36da6ff2018-02-16 16:04:20 -08001250 return kSdpStringWithStream1And2PlanB;
1251 } else {
1252 return kSdpStringWithStream1And2UnifiedPlan;
1253 }
1254 }
1255
Byoungchan Leed58f5262022-06-27 18:05:22 +09001256 rtc::SocketServer* socket_server() const { return vss_.get(); }
1257
deadbeef9a6f4d42017-05-15 19:43:33 -07001258 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1259 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001260 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001261 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001262 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001263 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1264 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1265 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001266 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001267 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001268 const SdpSemantics sdp_semantics_;
1269};
1270
1271class PeerConnectionInterfaceTest
1272 : public PeerConnectionInterfaceBaseTest,
1273 public ::testing::WithParamInterface<SdpSemantics> {
1274 protected:
1275 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1276};
1277
1278class PeerConnectionInterfaceTestPlanB
1279 : public PeerConnectionInterfaceBaseTest {
1280 protected:
1281 PeerConnectionInterfaceTestPlanB()
Florent Castelli15a38de2022-04-06 00:38:21 +02001282 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB_DEPRECATED) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001283};
1284
zhihuang8f65cdf2016-05-06 18:40:30 -07001285// Generate different CNAMEs when PeerConnections are created.
1286// The CNAMEs are expected to be generated randomly. It is possible
1287// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001288TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001289 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001290 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001291 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001292 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001293 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1294 GetFirstAudioStreamCname(offer2.get()));
1295}
1296
Steve Anton36da6ff2018-02-16 16:04:20 -08001297TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001298 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001299 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001300 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001301 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001302 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1303 GetFirstAudioStreamCname(answer2.get()));
1304}
1305
Steve Anton36da6ff2018-02-16 16:04:20 -08001306TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001307 CreatePeerConnectionWithDifferentConfigurations) {
1308 CreatePeerConnectionWithDifferentConfigurations();
1309}
1310
Steve Anton36da6ff2018-02-16 16:04:20 -08001311TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001312 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1313 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1314 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1315 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1316 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1317 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1318 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1319 port_allocator_->candidate_filter());
1320 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1321 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1322}
1323
1324// Test that when a PeerConnection is created with a nonzero candidate pool
1325// size, the pooled PortAllocatorSession is created with all the attributes
1326// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001327TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001328 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01001329 config.sdp_semantics = sdp_semantics_;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001330 PeerConnectionInterface::IceServer server;
1331 server.uri = kStunAddressOnly;
1332 config.servers.push_back(server);
1333 config.type = PeerConnectionInterface::kRelay;
1334 config.disable_ipv6 = true;
1335 config.tcp_candidate_policy =
1336 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001337 config.candidate_network_policy =
1338 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001339 config.ice_candidate_pool_size = 1;
Niels Möllerf06f9232018-08-07 12:32:18 +02001340 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001341
1342 const cricket::FakePortAllocatorSession* session =
1343 static_cast<const cricket::FakePortAllocatorSession*>(
1344 port_allocator_->GetPooledSession());
1345 ASSERT_NE(nullptr, session);
1346 EXPECT_EQ(1UL, session->stun_servers().size());
1347 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1348 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001349 EXPECT_LT(0U,
1350 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001351}
1352
deadbeefd21eab32017-07-26 16:50:11 -07001353// Test that network-related RTCConfiguration members are applied to the
1354// PortAllocator when CreatePeerConnection is called. Specifically:
1355// - disable_ipv6_on_wifi
1356// - max_ipv6_networks
1357// - tcp_candidate_policy
1358// - candidate_network_policy
1359// - prune_turn_ports
1360//
1361// Note that the candidate filter (RTCConfiguration::type) is already tested
1362// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001363TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001364 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1365 // Create fake port allocator.
Byoungchan Leed58f5262022-06-27 18:05:22 +09001366 std::unique_ptr<rtc::PacketSocketFactory> packet_socket_factory(
1367 new rtc::BasicPacketSocketFactory(socket_server()));
deadbeefd21eab32017-07-26 16:50:11 -07001368 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Byoungchan Leed58f5262022-06-27 18:05:22 +09001369 new cricket::FakePortAllocator(rtc::Thread::Current(),
1370 packet_socket_factory.get()));
deadbeefd21eab32017-07-26 16:50:11 -07001371 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1372
1373 // Create RTCConfiguration with some network-related fields relevant to
1374 // PortAllocator populated.
1375 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01001376 config.sdp_semantics = sdp_semantics_;
deadbeefd21eab32017-07-26 16:50:11 -07001377 config.disable_ipv6_on_wifi = true;
1378 config.max_ipv6_networks = 10;
1379 config.tcp_candidate_policy =
1380 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1381 config.candidate_network_policy =
1382 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1383 config.prune_turn_ports = true;
1384
1385 // Create the PC factory and PC with the above config.
1386 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1387 webrtc::CreatePeerConnectionFactory(
1388 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001389 rtc::Thread::Current(), fake_audio_capture_module_,
1390 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +02001391 webrtc::CreateBuiltinAudioDecoderFactory(),
1392 webrtc::CreateBuiltinVideoEncoderFactory(),
1393 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1394 nullptr /* audio_processing */));
Florent Castelli72424402022-04-06 03:45:10 +02001395 PeerConnectionDependencies pc_dependencies(&observer_);
1396 pc_dependencies.allocator = std::move(port_allocator);
1397 auto result = pc_factory_->CreatePeerConnectionOrError(
1398 config, std::move(pc_dependencies));
1399 EXPECT_TRUE(result.ok());
Niels Möllerafb246b2022-04-20 14:26:50 +02001400 observer_.SetPeerConnectionInterface(result.value().get());
deadbeefd21eab32017-07-26 16:50:11 -07001401
1402 // Now validate that the config fields set above were applied to the
1403 // PortAllocator, as flags or otherwise.
1404 EXPECT_FALSE(raw_port_allocator->flags() &
1405 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1406 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1407 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1408 EXPECT_TRUE(raw_port_allocator->flags() &
1409 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Honghai Zhangf8998cf2019-10-14 11:27:50 -07001410 EXPECT_EQ(webrtc::PRUNE_BASED_ON_PRIORITY,
1411 raw_port_allocator->turn_port_prune_policy());
deadbeefd21eab32017-07-26 16:50:11 -07001412}
1413
deadbeef46c73892016-11-16 19:42:04 -08001414// Check that GetConfiguration returns the configuration the PeerConnection was
1415// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001416TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001417 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01001418 config.sdp_semantics = sdp_semantics_;
deadbeef46c73892016-11-16 19:42:04 -08001419 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02001420 CreatePeerConnection(config);
deadbeef46c73892016-11-16 19:42:04 -08001421
1422 PeerConnectionInterface::RTCConfiguration returned_config =
1423 pc_->GetConfiguration();
1424 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1425}
1426
1427// Check that GetConfiguration returns the last configuration passed into
1428// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001429TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001430 PeerConnectionInterface::RTCConfiguration starting_config;
Henrik Boström62995db2022-01-03 09:58:10 +01001431 starting_config.sdp_semantics = sdp_semantics_;
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001432 starting_config.bundle_policy =
1433 webrtc::PeerConnection::kBundlePolicyMaxBundle;
1434 CreatePeerConnection(starting_config);
deadbeef46c73892016-11-16 19:42:04 -08001435
Steve Anton36da6ff2018-02-16 16:04:20 -08001436 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001437 config.type = PeerConnectionInterface::kRelay;
Niels Möller2579f0c2019-08-19 09:58:17 +02001438 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef46c73892016-11-16 19:42:04 -08001439
1440 PeerConnectionInterface::RTCConfiguration returned_config =
1441 pc_->GetConfiguration();
1442 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1443}
1444
Steve Antonc79268f2018-04-24 09:54:10 -07001445TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1446 CreatePeerConnection();
1447
1448 pc_->Close();
1449
1450 EXPECT_FALSE(
Niels Möller2579f0c2019-08-19 09:58:17 +02001451 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()).ok());
Steve Antonc79268f2018-04-24 09:54:10 -07001452}
1453
Steve Anton36da6ff2018-02-16 16:04:20 -08001454TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001455 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001456 AddVideoStream(kStreamId1);
1457 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001458 ASSERT_EQ(2u, pc_->local_streams()->count());
1459
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001460 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001461 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001462 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001463 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möllerafb246b2022-04-20 14:26:50 +02001464 pc_factory_->CreateAudioTrack(
1465 kStreamId3, static_cast<AudioSourceInterface*>(nullptr)));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00001466 stream->AddTrack(audio_track);
Niels Möllerafb246b2022-04-20 14:26:50 +02001467 EXPECT_TRUE(pc_->AddStream(stream.get()));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001468 EXPECT_EQ(3u, pc_->local_streams()->count());
1469
1470 // Remove the third stream.
1471 pc_->RemoveStream(pc_->local_streams()->at(2));
1472 EXPECT_EQ(2u, pc_->local_streams()->count());
1473
1474 // Remove the second stream.
1475 pc_->RemoveStream(pc_->local_streams()->at(1));
1476 EXPECT_EQ(1u, pc_->local_streams()->count());
1477
1478 // Remove the first stream.
1479 pc_->RemoveStream(pc_->local_streams()->at(0));
1480 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001481}
1482
deadbeefab9b2d12015-10-14 11:33:11 -07001483// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001484// Don't run under Unified Plan since the stream API is not available.
1485TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001486 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001487 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001488 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001489 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001490
deadbeefab9b2d12015-10-14 11:33:11 -07001491 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001492 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001493 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001494
deadbeefab9b2d12015-10-14 11:33:11 -07001495 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001496 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001497 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001498
1499 // Add another stream and ensure the offer includes both the old and new
1500 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001501 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001502 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001503
Steve Antonb1c1de12017-12-21 15:14:30 -08001504 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001505 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1506 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001507
Steve Antonb1c1de12017-12-21 15:14:30 -08001508 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001509 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1510 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001511}
1512
Steve Anton36da6ff2018-02-16 16:04:20 -08001513// Don't run under Unified Plan since the stream API is not available.
1514TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001515 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001516 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001517 ASSERT_EQ(1u, pc_->local_streams()->count());
1518 pc_->RemoveStream(pc_->local_streams()->at(0));
1519 EXPECT_EQ(0u, pc_->local_streams()->count());
1520}
1521
deadbeefe1f9d832016-01-14 15:35:42 -08001522// Test for AddTrack and RemoveTrack methods.
1523// Tests that the created offer includes tracks we added,
1524// and that the RtpSenders are created correctly.
1525// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001526// Only tested with Plan B since Unified Plan is covered in more detail by tests
1527// in peerconnection_jsep_unittests.cc
1528TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001529 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001530 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001531 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001532 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001533 CreateVideoTrack("video_track"));
Seth Hampson845e8782018-03-02 11:34:10 -08001534 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1535 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001536 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001537 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001538 EXPECT_EQ("audio_track", audio_sender->id());
1539 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001540 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001541 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001542 EXPECT_EQ("video_track", video_sender->id());
1543 EXPECT_EQ(video_track, video_sender->track());
1544
1545 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001546 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001547 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001548
1549 const cricket::ContentInfo* audio_content =
1550 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001551 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001552 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001553
1554 const cricket::ContentInfo* video_content =
1555 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001556 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001557 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001558
Steve Antondb45ca82017-09-11 18:27:34 -07001559 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001560
1561 // Now try removing the tracks.
Harald Alvestrand93dd7632022-01-19 12:28:45 +00001562 EXPECT_TRUE(pc_->RemoveTrackOrError(audio_sender).ok());
1563 EXPECT_TRUE(pc_->RemoveTrackOrError(video_sender).ok());
deadbeefe1f9d832016-01-14 15:35:42 -08001564
1565 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001566 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001567
1568 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001569 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001570 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001571
1572 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001573 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001574 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001575
Steve Antondb45ca82017-09-11 18:27:34 -07001576 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001577
1578 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1579 // should return false.
Harald Alvestrand93dd7632022-01-19 12:28:45 +00001580 EXPECT_FALSE(pc_->RemoveTrackOrError(audio_sender).ok());
1581 EXPECT_FALSE(pc_->RemoveTrackOrError(video_sender).ok());
deadbeefe1f9d832016-01-14 15:35:42 -08001582}
1583
1584// Test creating senders without a stream specified,
1585// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001586TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001587 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001588 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001589 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001590 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001591 CreateVideoTrack("video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001592 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001593 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001594 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001595 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001596 EXPECT_EQ("audio_track", audio_sender->id());
1597 EXPECT_EQ(audio_track, audio_sender->track());
1598 EXPECT_EQ("video_track", video_sender->id());
1599 EXPECT_EQ(video_track, video_sender->track());
Florent Castelli15a38de2022-04-06 00:38:21 +02001600 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Seth Hampson5b4f0752018-04-02 16:31:36 -07001601 // If the ID is truly a random GUID, it should be infinitely unlikely they
1602 // will be the same.
1603 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1604 } else {
1605 // We allows creating tracks without stream ids under Unified Plan
1606 // semantics.
1607 EXPECT_EQ(0u, video_sender->stream_ids().size());
1608 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1609 }
deadbeefe1f9d832016-01-14 15:35:42 -08001610}
1611
Harald Alvestrand89061872018-01-02 14:08:34 +01001612// Test that we can call GetStats() after AddTrack but before connecting
1613// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001614TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001615 CreatePeerConnectionWithoutDtls();
1616 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001617 CreateAudioTrack("audio_track"));
Harald Alvestrand89061872018-01-02 14:08:34 +01001618 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001619 CreateVideoTrack("video_track"));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001620 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1621 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001622 EXPECT_TRUE(DoGetStats(nullptr));
1623}
1624
Steve Anton36da6ff2018-02-16 16:04:20 -08001625TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001626 CreatePeerConnectionWithoutDtls();
1627 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001628 CreateAudioTrack("audio_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001629 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001630 CreateVideoTrack("video_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001631 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001632 ASSERT_TRUE(audio_sender.ok());
1633 auto* audio_sender_proxy =
1634 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1635 audio_sender.value().get());
1636 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1637
Harald Alvestrandc72af932018-01-11 17:18:19 +01001638 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001639 ASSERT_TRUE(video_sender.ok());
1640 auto* video_sender_proxy =
1641 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1642 video_sender.value().get());
1643 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001644}
1645
Steve Anton36da6ff2018-02-16 16:04:20 -08001646// Don't run under Unified Plan since the stream API is not available.
1647TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001648 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001649 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001650 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001651 ASSERT_EQ(1u, senders.size());
1652 auto* sender_proxy =
1653 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1654 senders[0].get());
1655 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001656}
1657
Steve Anton36da6ff2018-02-16 16:04:20 -08001658TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001660 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001661 VerifyRemoteRtpHeaderExtensions();
1662}
1663
Steve Anton36da6ff2018-02-16 16:04:20 -08001664TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001665 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001666 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667 CreateOfferAsLocalDescription();
1668 std::string offer;
1669 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1670 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001671 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001672}
1673
Steve Anton36da6ff2018-02-16 16:04:20 -08001674TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001675 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001676 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001677
1678 CreateOfferAsRemoteDescription();
1679 CreateAnswerAsLocalDescription();
1680
Seth Hampson845e8782018-03-02 11:34:10 -08001681 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682}
1683
Steve Anton36da6ff2018-02-16 16:04:20 -08001684TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001685 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001686 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687
1688 CreateOfferAsRemoteDescription();
1689 CreatePrAnswerAsLocalDescription();
1690 CreateAnswerAsLocalDescription();
1691
Seth Hampson845e8782018-03-02 11:34:10 -08001692 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693}
1694
Steve Anton36da6ff2018-02-16 16:04:20 -08001695// Don't run under Unified Plan since the stream API is not available.
1696TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001697 InitiateCall();
1698 ASSERT_EQ(1u, pc_->remote_streams()->count());
1699 pc_->RemoveStream(pc_->local_streams()->at(0));
1700 CreateOfferReceiveAnswer();
1701 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001702 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703 CreateOfferReceiveAnswer();
1704}
1705
1706// Tests that after negotiating an audio only call, the respondent can perform a
1707// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001708TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001709 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001710 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711 CreateOfferAsRemoteDescription();
1712 CreateAnswerAsLocalDescription();
1713
1714 ASSERT_EQ(1u, pc_->remote_streams()->count());
1715 pc_->RemoveStream(pc_->local_streams()->at(0));
1716 CreateOfferReceiveAnswer();
1717 EXPECT_EQ(0u, pc_->remote_streams()->count());
1718}
1719
1720// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001721TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001722 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001723
Steve Antonf1c6db12017-10-13 11:13:35 -07001724 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001726 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001727 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001728 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001729 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001730
1731 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001732 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001733 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001734 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735
Steve Antonf1c6db12017-10-13 11:13:35 -07001736 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001737 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001738
Steve Antonf1c6db12017-10-13 11:13:35 -07001739 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740}
1741
deadbeefab9b2d12015-10-14 11:33:11 -07001742// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743// not unique.
Steve Anton07563732018-06-26 11:13:50 -07001744TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001745 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001747 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001748 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001749 EXPECT_TRUE(offer);
1750 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751
1752 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001753 AddAudioTrack("track_label", {kStreamId1});
1754 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755
1756 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001757 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758
1759 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001760 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001761 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001762}
1763
1764// Test that we will get different SSRCs for each tracks in the offer and answer
1765// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001766TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001767 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001769 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1770 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001771
1772 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001773 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001774 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775 int audio_ssrc = 0;
1776 int video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001777 EXPECT_TRUE(
1778 GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc));
1779 EXPECT_TRUE(
1780 GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781 EXPECT_NE(audio_ssrc, video_ssrc);
1782
1783 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001784 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001785 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001786 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787 audio_ssrc = 0;
1788 video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001789 EXPECT_TRUE(
1790 GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc));
1791 EXPECT_TRUE(
1792 GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793 EXPECT_NE(audio_ssrc, video_ssrc);
1794}
1795
deadbeefeb459812015-12-15 19:24:43 -08001796// Test that it's possible to call AddTrack on a MediaStream after adding
1797// the stream to a PeerConnection.
1798// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001799// Don't run under Unified Plan since the stream API is not available.
1800TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001801 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001802 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001803 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001804 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1805
1806 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001807 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001808 CreateVideoTrack("video_label"));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00001809 stream->AddTrack(video_track);
deadbeefeb459812015-12-15 19:24:43 -08001810
kwibergd1fe2812016-04-27 06:47:29 -07001811 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001812 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001813
1814 const cricket::MediaContentDescription* video_desc =
1815 cricket::GetFirstVideoContentDescription(offer->description());
1816 EXPECT_TRUE(video_desc != nullptr);
1817}
1818
1819// Test that it's possible to call RemoveTrack on a MediaStream after adding
1820// the stream to a PeerConnection.
1821// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001822// Don't run under Unified Plan since the stream API is not available.
1823TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001824 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001825 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001826 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001827 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1828
1829 // Remove the video track.
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00001830 stream->RemoveTrack(stream->GetVideoTracks()[0]);
deadbeefeb459812015-12-15 19:24:43 -08001831
kwibergd1fe2812016-04-27 06:47:29 -07001832 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001833 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001834
1835 const cricket::MediaContentDescription* video_desc =
1836 cricket::GetFirstVideoContentDescription(offer->description());
1837 EXPECT_TRUE(video_desc == nullptr);
1838}
1839
deadbeefbd7d8f72015-12-18 16:58:44 -08001840// Test creating a sender with a stream ID, and ensure the ID is populated
1841// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001842// Don't run under Unified Plan since the stream API is not available.
1843TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001844 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001845 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001846
kwibergd1fe2812016-04-27 06:47:29 -07001847 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001848 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001849
1850 const cricket::MediaContentDescription* video_desc =
1851 cricket::GetFirstVideoContentDescription(offer->description());
1852 ASSERT_TRUE(video_desc != nullptr);
1853 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001854 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001855}
1856
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001858TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001860 ASSERT_LT(0u, pc_->GetSenders().size());
1861 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001862 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001863 pc_->GetReceivers()[0]->track();
Niels Möllerafb246b2022-04-20 14:26:50 +02001864 EXPECT_TRUE(DoGetStats(remote_audio.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001865
1866 // Remove the stream. Since we are sending to our selves the local
1867 // and the remote stream is the same.
Harald Alvestrand93dd7632022-01-19 12:28:45 +00001868 pc_->RemoveTrackOrError(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001869 // Do a re-negotiation.
1870 CreateOfferReceiveAnswer();
1871
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001872 // Test that we still can get statistics for the old track. Even if it is not
1873 // sent any longer.
Niels Möllerafb246b2022-04-20 14:26:50 +02001874 EXPECT_TRUE(DoGetStats(remote_audio.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001875}
1876
1877// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001878TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001879 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001880 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1881 ASSERT_TRUE(video_receiver);
Niels Möllerafb246b2022-04-20 14:26:50 +02001882 EXPECT_TRUE(DoGetStats(video_receiver->track().get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001883}
1884
1885// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001886TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001887 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001888 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
Niels Möllerafb246b2022-04-20 14:26:50 +02001889 pc_factory_->CreateAudioTrack("unknown track", nullptr));
1890 EXPECT_FALSE(DoGetStats(unknown_audio_track.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001891}
1892
Steve Anton36da6ff2018-02-16 16:04:20 -08001893TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001894 CreatePeerConnectionWithoutDtls();
1895 EXPECT_TRUE(DoGetRTCStats());
1896 // Clearing stats cache is needed now, but should be temporary.
1897 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1898 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001899 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1900 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001901 EXPECT_TRUE(DoGetRTCStats());
1902 pc_->ClearStatsCache();
1903 CreateOfferReceiveAnswer();
1904 EXPECT_TRUE(DoGetRTCStats());
1905}
1906
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907// This tests that a SCTP data channel is returned using different
1908// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08001909TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001910 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02001911 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001912
1913 webrtc::DataChannelInit config;
Florent Castelli72424402022-04-06 03:45:10 +02001914 auto channel = pc_->CreateDataChannelOrError("1", &config);
1915 EXPECT_TRUE(channel.ok());
1916 EXPECT_TRUE(channel.value()->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001917 EXPECT_TRUE(observer_.renegotiation_needed_);
1918 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001919
1920 config.ordered = false;
Florent Castelli72424402022-04-06 03:45:10 +02001921 channel = pc_->CreateDataChannelOrError("2", &config);
1922 EXPECT_TRUE(channel.ok());
1923 EXPECT_TRUE(channel.value()->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001924 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001925
1926 config.ordered = true;
1927 config.maxRetransmits = 0;
Florent Castelli72424402022-04-06 03:45:10 +02001928 channel = pc_->CreateDataChannelOrError("3", &config);
1929 EXPECT_TRUE(channel.ok());
1930 EXPECT_FALSE(channel.value()->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001931 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001932
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02001933 config.maxRetransmits = absl::nullopt;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001934 config.maxRetransmitTime = 0;
Florent Castelli72424402022-04-06 03:45:10 +02001935 channel = pc_->CreateDataChannelOrError("4", &config);
1936 EXPECT_TRUE(channel.ok());
1937 EXPECT_FALSE(channel.value()->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00001938 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001939}
1940
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02001941// For backwards compatibility, we want people who "unset" maxRetransmits
1942// and maxRetransmitTime by setting them to -1 to get what they want.
1943TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannelWithMinusOne) {
1944 RTCConfiguration rtc_config;
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02001945 CreatePeerConnection(rtc_config);
1946
1947 webrtc::DataChannelInit config;
1948 config.maxRetransmitTime = -1;
1949 config.maxRetransmits = -1;
Florent Castelli72424402022-04-06 03:45:10 +02001950 auto channel = pc_->CreateDataChannelOrError("1", &config);
1951 EXPECT_TRUE(channel.ok());
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02001952}
1953
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001954// This tests that no data channel is returned if both maxRetransmits and
1955// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08001956TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001957 CreateSctpDataChannelShouldFailForInvalidConfig) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001958 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02001959 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001960
1961 std::string label = "test";
1962 webrtc::DataChannelInit config;
1963 config.maxRetransmits = 0;
1964 config.maxRetransmitTime = 0;
1965
Florent Castelli72424402022-04-06 03:45:10 +02001966 auto channel = pc_->CreateDataChannelOrError(label, &config);
1967 EXPECT_FALSE(channel.ok());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001968}
1969
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001970// The test verifies that creating a SCTP data channel with an id already in use
1971// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001972TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001973 CreateSctpDataChannelWithInvalidIdShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001974 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02001975 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001976
1977 webrtc::DataChannelInit config;
1978
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00001979 config.id = 1;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02001980 config.negotiated = true;
Florent Castelli72424402022-04-06 03:45:10 +02001981 auto channel = pc_->CreateDataChannelOrError("1", &config);
1982 EXPECT_TRUE(channel.ok());
1983 EXPECT_EQ(1, channel.value()->id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001984
Florent Castelli72424402022-04-06 03:45:10 +02001985 channel = pc_->CreateDataChannelOrError("x", &config);
1986 EXPECT_FALSE(channel.ok());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001987
1988 config.id = cricket::kMaxSctpSid;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02001989 config.negotiated = true;
Florent Castelli72424402022-04-06 03:45:10 +02001990 channel = pc_->CreateDataChannelOrError("max", &config);
1991 EXPECT_TRUE(channel.ok());
1992 EXPECT_EQ(config.id, channel.value()->id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001993
1994 config.id = cricket::kMaxSctpSid + 1;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02001995 config.negotiated = true;
Florent Castelli72424402022-04-06 03:45:10 +02001996 channel = pc_->CreateDataChannelOrError("x", &config);
1997 EXPECT_FALSE(channel.ok());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998}
1999
deadbeefab9b2d12015-10-14 11:33:11 -07002000// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002001TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002002 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002003 CreatePeerConnection(rtc_config);
deadbeefab9b2d12015-10-14 11:33:11 -07002004
2005 std::string label = "test";
Florent Castelli72424402022-04-06 03:45:10 +02002006 auto channel = pc_->CreateDataChannelOrError(label, nullptr);
2007 EXPECT_TRUE(channel.ok());
deadbeefab9b2d12015-10-14 11:33:11 -07002008
Florent Castelli72424402022-04-06 03:45:10 +02002009 auto dup_channel = pc_->CreateDataChannelOrError(label, nullptr);
2010 EXPECT_TRUE(dup_channel.ok());
deadbeefab9b2d12015-10-14 11:33:11 -07002011}
2012
Mirko Bonadei5eb43b42021-01-18 13:24:40 +01002013#ifdef WEBRTC_HAVE_SCTP
Zhi Huang644fde42018-04-02 19:16:26 -07002014// This tests that SCTP data channels can be rejected in an answer.
2015TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2016#else
2017TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2018#endif
2019{
Niels Möllerf06f9232018-08-07 12:32:18 +02002020 RTCConfiguration rtc_config;
2021 CreatePeerConnection(rtc_config);
Zhi Huang644fde42018-04-02 19:16:26 -07002022
Florent Castelli72424402022-04-06 03:45:10 +02002023 auto offer_channel = pc_->CreateDataChannelOrError("offer_channel", NULL);
Zhi Huang644fde42018-04-02 19:16:26 -07002024
2025 CreateOfferAsLocalDescription();
2026
2027 // Create an answer where the m-line for data channels are rejected.
2028 std::string sdp;
2029 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2030 std::unique_ptr<SessionDescriptionInterface> answer(
2031 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2032 ASSERT_TRUE(answer);
2033 cricket::ContentInfo* data_info =
2034 cricket::GetFirstDataContent(answer->description());
2035 data_info->rejected = true;
2036
2037 DoSetRemoteDescription(std::move(answer));
Florent Castelli72424402022-04-06 03:45:10 +02002038 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel.value()->state());
Zhi Huang644fde42018-04-02 19:16:26 -07002039}
2040
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041// Test that we can create a session description from an SDP string from
2042// FireFox, use it as a remote session description, generate an answer and use
2043// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002044TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002045 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002046 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002047 AddAudioTrack("audio_label");
2048 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002049 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002050 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002051 webrtc::kFireFoxSdpOffer, nullptr));
2052 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 CreateAnswerAsLocalDescription();
Niels Möllerafb246b2022-04-20 14:26:50 +02002054 ASSERT_TRUE(pc_->local_description() != nullptr);
2055 ASSERT_TRUE(pc_->remote_description() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056
2057 const cricket::ContentInfo* content =
2058 cricket::GetFirstAudioContent(pc_->local_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002059 ASSERT_TRUE(content != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060 EXPECT_FALSE(content->rejected);
2061
2062 content =
2063 cricket::GetFirstVideoContent(pc_->local_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002064 ASSERT_TRUE(content != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065 EXPECT_FALSE(content->rejected);
Mirko Bonadei5eb43b42021-01-18 13:24:40 +01002066#ifdef WEBRTC_HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067 content =
2068 cricket::GetFirstDataContent(pc_->local_description()->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002069 ASSERT_TRUE(content != nullptr);
Zhi Huange830e682018-03-30 10:48:35 -07002070 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002071#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072}
2073
Harald Alvestrand0d018412021-11-04 13:52:31 +00002074// Test that fallback from DTLS to SDES is not supported.
2075// The fallback was previously supported but was removed to simplify the code
2076// and because it's non-standard.
2077TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002078 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002079 CreatePeerConnection(rtc_config);
deadbeef8662f942017-01-20 21:20:51 -08002080 // Wait for fake certificate to be generated. Previously, this is what caused
2081 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002082 AddAudioTrack("audio_label");
2083 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002084 ASSERT_NE(nullptr, fake_certificate_generator_);
2085 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2086 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002087 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002088 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2089 nullptr));
Harald Alvestrand0d018412021-11-04 13:52:31 +00002090 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002091}
2092
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093// Test that we can create an audio only offer and receive an answer with a
2094// limited set of audio codecs and receive an updated offer with more audio
2095// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002096TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002097 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002098 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099 CreateOfferAsLocalDescription();
2100
Florent Castelli15a38de2022-04-06 00:38:21 +02002101 const char* answer_sdp = (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED
2102 ? webrtc::kAudioSdpPlanB
2103 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002104 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002105 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002106 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107
Steve Anton36da6ff2018-02-16 16:04:20 -08002108 const char* reoffer_sdp =
Florent Castelli15a38de2022-04-06 00:38:21 +02002109 (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED
Steve Anton36da6ff2018-02-16 16:04:20 -08002110 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2111 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002112 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002113 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002114 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115 CreateAnswerAsLocalDescription();
2116}
2117
deadbeefc80741f2015-10-22 13:14:45 -07002118// Test that if we're receiving (but not sending) a track, subsequent offers
2119// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002120TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002121 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002122 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002123 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002124 CreateAnswerAsLocalDescription();
2125
2126 // At this point we should be receiving stream 1, but not sending anything.
2127 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002128 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002129 DoCreateOffer(&offer, nullptr);
2130
2131 const cricket::ContentInfo* video_content =
2132 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002133 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2134 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002135
2136 const cricket::ContentInfo* audio_content =
2137 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002138 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2139 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002140}
2141
2142// Test that if we're receiving (but not sending) a track, and the
2143// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2144// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002145TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002146 RTCConfiguration rtc_config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002147 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002148 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002149 CreateAnswerAsLocalDescription();
2150
2151 // At this point we should be receiving stream 1, but not sending anything.
2152 // A new offer would be recvonly, but we'll set the "no receive" constraints
2153 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002154 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02002155 RTCOfferAnswerOptions options;
2156 options.offer_to_receive_audio = 0;
2157 options.offer_to_receive_video = 0;
2158 DoCreateOffer(&offer, &options);
deadbeefc80741f2015-10-22 13:14:45 -07002159
2160 const cricket::ContentInfo* video_content =
2161 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002162 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2163 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002164
2165 const cricket::ContentInfo* audio_content =
2166 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002167 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2168 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002169}
2170
deadbeef653b8e02015-11-11 12:55:10 -08002171// Test that we can use SetConfiguration to change the ICE servers of the
2172// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002173TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002174 CreatePeerConnection();
2175
Steve Anton36da6ff2018-02-16 16:04:20 -08002176 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002177 PeerConnectionInterface::IceServer server;
2178 server.uri = "stun:test_hostname";
2179 config.servers.push_back(server);
Niels Möller2579f0c2019-08-19 09:58:17 +02002180 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef653b8e02015-11-11 12:55:10 -08002181
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002182 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2183 EXPECT_EQ("test_hostname",
2184 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002185}
2186
Steve Anton36da6ff2018-02-16 16:04:20 -08002187TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002188 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002189 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002190 config.type = PeerConnectionInterface::kRelay;
Niels Möller2579f0c2019-08-19 09:58:17 +02002191 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002192 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2193}
2194
Steve Anton36da6ff2018-02-16 16:04:20 -08002195TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002196 PeerConnectionInterface::RTCConfiguration config;
2197 config.prune_turn_ports = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02002198 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002199 config = pc_->GetConfiguration();
Honghai Zhangf8998cf2019-10-14 11:27:50 -07002200 EXPECT_EQ(webrtc::NO_PRUNE, port_allocator_->turn_port_prune_policy());
deadbeef293e9262017-01-11 12:28:30 -08002201
2202 config.prune_turn_ports = true;
Niels Möller2579f0c2019-08-19 09:58:17 +02002203 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Honghai Zhangf8998cf2019-10-14 11:27:50 -07002204 EXPECT_EQ(webrtc::PRUNE_BASED_ON_PRIORITY,
2205 port_allocator_->turn_port_prune_policy());
deadbeef293e9262017-01-11 12:28:30 -08002206}
2207
skvladd1f5fda2017-02-03 16:54:05 -08002208// Test that the ice check interval can be changed. This does not verify that
2209// the setting makes it all the way to P2PTransportChannel, as that would
2210// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002211TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002212 PeerConnectionInterface::RTCConfiguration config;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +02002213 config.ice_check_min_interval = absl::nullopt;
Niels Möllerf06f9232018-08-07 12:32:18 +02002214 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002215 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002216 config.ice_check_min_interval = 100;
Niels Möller2579f0c2019-08-19 09:58:17 +02002217 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Qingsi Wangbca14852019-06-26 14:56:02 -07002218 config = pc_->GetConfiguration();
2219 EXPECT_EQ(config.ice_check_min_interval, 100);
2220}
2221
2222TEST_P(PeerConnectionInterfaceTest,
2223 SetConfigurationChangesSurfaceIceCandidatesOnIceTransportTypeChanged) {
2224 PeerConnectionInterface::RTCConfiguration config;
2225 config.surface_ice_candidates_on_ice_transport_type_changed = false;
2226 CreatePeerConnection(config);
2227 config = pc_->GetConfiguration();
2228 EXPECT_FALSE(config.surface_ice_candidates_on_ice_transport_type_changed);
2229
2230 config.surface_ice_candidates_on_ice_transport_type_changed = true;
Niels Möller2579f0c2019-08-19 09:58:17 +02002231 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Qingsi Wangbca14852019-06-26 14:56:02 -07002232 config = pc_->GetConfiguration();
2233 EXPECT_TRUE(config.surface_ice_candidates_on_ice_transport_type_changed);
skvladd1f5fda2017-02-03 16:54:05 -08002234}
2235
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002236// Test that when SetConfiguration changes both the pool size and other
2237// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002238TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002239 SetConfigurationCreatesPooledSessionCorrectly) {
2240 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002241 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002242 config.ice_candidate_pool_size = 1;
2243 PeerConnectionInterface::IceServer server;
2244 server.uri = kStunAddressOnly;
2245 config.servers.push_back(server);
2246 config.type = PeerConnectionInterface::kRelay;
Niels Möller2579f0c2019-08-19 09:58:17 +02002247 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002248
2249 const cricket::FakePortAllocatorSession* session =
2250 static_cast<const cricket::FakePortAllocatorSession*>(
2251 port_allocator_->GetPooledSession());
2252 ASSERT_NE(nullptr, session);
2253 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002254}
2255
deadbeef293e9262017-01-11 12:28:30 -08002256// Test that after SetLocalDescription, changing the pool size is not allowed,
2257// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002258TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002259 CantChangePoolSizeAfterSetLocalDescription) {
2260 CreatePeerConnection();
2261 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002262 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002263 config.ice_candidate_pool_size = 1;
Niels Möller2579f0c2019-08-19 09:58:17 +02002264 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef6de92f92016-12-12 18:49:32 -08002265
2266 // Set remote offer; can still change pool size at this point.
2267 CreateOfferAsRemoteDescription();
2268 config.ice_candidate_pool_size = 2;
Niels Möller2579f0c2019-08-19 09:58:17 +02002269 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef6de92f92016-12-12 18:49:32 -08002270
2271 // Set local answer; now it's too late.
2272 CreateAnswerAsLocalDescription();
2273 config.ice_candidate_pool_size = 3;
Niels Möller2579f0c2019-08-19 09:58:17 +02002274 RTCError error = pc_->SetConfiguration(config);
deadbeef293e9262017-01-11 12:28:30 -08002275 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2276}
2277
deadbeef42a42632017-03-10 15:18:00 -08002278// Test that after setting an answer, extra pooled sessions are discarded. The
2279// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002280TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002281 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2282 CreatePeerConnection();
2283
2284 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002285 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002286 config.ice_candidate_pool_size = 4;
Niels Möller2579f0c2019-08-19 09:58:17 +02002287 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef42a42632017-03-10 15:18:00 -08002288
2289 // Do offer/answer.
2290 CreateOfferAsRemoteDescription();
2291 CreateAnswerAsLocalDescription();
2292
2293 // Expect no pooled sessions to be left.
2294 const cricket::PortAllocatorSession* session =
2295 port_allocator_->GetPooledSession();
2296 EXPECT_EQ(nullptr, session);
2297}
2298
2299// After Close is called, pooled candidates should be discarded so as to not
2300// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002301TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002302 CreatePeerConnection();
2303
Steve Anton36da6ff2018-02-16 16:04:20 -08002304 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002305 config.ice_candidate_pool_size = 3;
Niels Möller2579f0c2019-08-19 09:58:17 +02002306 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeef42a42632017-03-10 15:18:00 -08002307 pc_->Close();
2308
2309 // Expect no pooled sessions to be left.
2310 const cricket::PortAllocatorSession* session =
2311 port_allocator_->GetPooledSession();
2312 EXPECT_EQ(nullptr, session);
2313}
2314
deadbeef293e9262017-01-11 12:28:30 -08002315// Test that SetConfiguration returns an invalid modification error if
2316// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002317TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002318 SetConfigurationReturnsInvalidModificationError) {
2319 PeerConnectionInterface::RTCConfiguration config;
2320 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2321 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2322 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
Niels Möllerf06f9232018-08-07 12:32:18 +02002323 CreatePeerConnection(config);
deadbeef293e9262017-01-11 12:28:30 -08002324
Steve Anton36da6ff2018-02-16 16:04:20 -08002325 PeerConnectionInterface::RTCConfiguration modified_config =
2326 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002327 modified_config.bundle_policy =
2328 PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möller2579f0c2019-08-19 09:58:17 +02002329 RTCError error = pc_->SetConfiguration(modified_config);
deadbeef293e9262017-01-11 12:28:30 -08002330 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2331
Steve Anton36da6ff2018-02-16 16:04:20 -08002332 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002333 modified_config.rtcp_mux_policy =
2334 PeerConnectionInterface::kRtcpMuxPolicyRequire;
Niels Möller2579f0c2019-08-19 09:58:17 +02002335 error = pc_->SetConfiguration(modified_config);
deadbeef293e9262017-01-11 12:28:30 -08002336 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2337
Steve Anton36da6ff2018-02-16 16:04:20 -08002338 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002339 modified_config.continual_gathering_policy =
2340 PeerConnectionInterface::GATHER_CONTINUALLY;
Niels Möller2579f0c2019-08-19 09:58:17 +02002341 error = pc_->SetConfiguration(modified_config);
deadbeef293e9262017-01-11 12:28:30 -08002342 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2343}
2344
2345// Test that SetConfiguration returns a range error if the candidate pool size
2346// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002347TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002348 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2349 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002350 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002351 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002352
2353 config.ice_candidate_pool_size = -1;
Niels Möller2579f0c2019-08-19 09:58:17 +02002354 RTCError error = pc_->SetConfiguration(config);
deadbeef293e9262017-01-11 12:28:30 -08002355 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2356
2357 config.ice_candidate_pool_size = INT_MAX;
Niels Möller2579f0c2019-08-19 09:58:17 +02002358 error = pc_->SetConfiguration(config);
deadbeef293e9262017-01-11 12:28:30 -08002359 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2360}
2361
2362// Test that SetConfiguration returns a syntax error if parsing an ICE server
2363// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002364TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002365 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2366 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002367 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002368 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002369
2370 PeerConnectionInterface::IceServer bad_server;
2371 bad_server.uri = "stunn:www.example.com";
2372 config.servers.push_back(bad_server);
Niels Möller2579f0c2019-08-19 09:58:17 +02002373 RTCError error = pc_->SetConfiguration(config);
deadbeef293e9262017-01-11 12:28:30 -08002374 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2375}
2376
2377// Test that SetConfiguration returns an invalid parameter error if a TURN
2378// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002379TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002380 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2381 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002382 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002383 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002384
2385 PeerConnectionInterface::IceServer bad_server;
2386 bad_server.uri = "turn:www.example.com";
2387 // Missing password.
2388 bad_server.username = "foo";
2389 config.servers.push_back(bad_server);
2390 RTCError error;
Niels Möller340e0c52019-08-26 11:03:47 +02002391 EXPECT_EQ(pc_->SetConfiguration(config).type(),
2392 RTCErrorType::INVALID_PARAMETER);
deadbeef6de92f92016-12-12 18:49:32 -08002393}
2394
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002395// Test that PeerConnection::Close changes the states to closed and all remote
2396// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002397TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398 // Initialize a PeerConnection and negotiate local and remote session
2399 // description.
2400 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002401
2402 // With Plan B, verify the stream count. The analog with Unified Plan is the
2403 // RtpTransceiver count.
Florent Castelli15a38de2022-04-06 00:38:21 +02002404 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Steve Anton36da6ff2018-02-16 16:04:20 -08002405 ASSERT_EQ(1u, pc_->local_streams()->count());
2406 ASSERT_EQ(1u, pc_->remote_streams()->count());
2407 } else {
2408 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2409 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002410
2411 pc_->Close();
2412
2413 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2414 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2415 pc_->ice_connection_state());
2416 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2417 pc_->ice_gathering_state());
2418
Florent Castelli15a38de2022-04-06 00:38:21 +02002419 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Steve Anton36da6ff2018-02-16 16:04:20 -08002420 EXPECT_EQ(1u, pc_->local_streams()->count());
2421 EXPECT_EQ(1u, pc_->remote_streams()->count());
2422 } else {
Harald Alvestrand936f1af2020-09-22 07:41:50 +00002423 // Verify that the RtpTransceivers are still returned.
2424 EXPECT_EQ(2u, pc_->GetTransceivers().size());
Steve Anton36da6ff2018-02-16 16:04:20 -08002425 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002426
Steve Anton36da6ff2018-02-16 16:04:20 -08002427 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
Steve Anton36da6ff2018-02-16 16:04:20 -08002428 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
Florent Castelli15a38de2022-04-06 00:38:21 +02002429 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Harald Alvestrand6060df52020-08-11 09:54:02 +02002430 ASSERT_TRUE(audio_receiver);
2431 ASSERT_TRUE(video_receiver);
2432 // Track state may be updated asynchronously.
2433 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
2434 audio_receiver->track()->state(), kTimeout);
2435 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
2436 video_receiver->track()->state(), kTimeout);
2437 } else {
2438 ASSERT_FALSE(audio_receiver);
2439 ASSERT_FALSE(video_receiver);
2440 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002441}
2442
2443// Test that PeerConnection methods fails gracefully after
2444// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002445// Don't run under Unified Plan since the stream API is not available.
2446TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002447 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002448 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002449 CreateOfferAsRemoteDescription();
2450 CreateAnswerAsLocalDescription();
2451
2452 ASSERT_EQ(1u, pc_->local_streams()->count());
Niels Möllere7cc8832022-01-04 15:20:03 +01002453 rtc::scoped_refptr<MediaStreamInterface> local_stream(
2454 pc_->local_streams()->at(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002455
2456 pc_->Close();
2457
Niels Möllerafb246b2022-04-20 14:26:50 +02002458 pc_->RemoveStream(local_stream.get());
2459 EXPECT_FALSE(pc_->AddStream(local_stream.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002460
Florent Castelli72424402022-04-06 03:45:10 +02002461 EXPECT_FALSE(pc_->CreateDataChannelOrError("test", NULL).ok());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002462
Niels Möllerafb246b2022-04-20 14:26:50 +02002463 EXPECT_TRUE(pc_->local_description() != nullptr);
2464 EXPECT_TRUE(pc_->remote_description() != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002465
kwibergd1fe2812016-04-27 06:47:29 -07002466 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002467 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002468 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002469 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002470
2471 std::string sdp;
2472 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002473 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002474 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002475 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002476
2477 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002478 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002479 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002480 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002481}
2482
2483// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002484TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002485 InitiateCall();
2486 pc_->Close();
Niels Möllerafb246b2022-04-20 14:26:50 +02002487 DoGetStats(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002488}
deadbeefab9b2d12015-10-14 11:33:11 -07002489
2490// NOTE: The series of tests below come from what used to be
2491// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2492// setting a remote or local description has the expected effects.
2493
2494// This test verifies that the remote MediaStreams corresponding to a received
2495// SDP string is created. In this test the two separate MediaStreams are
2496// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002497TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002498 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002499 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002500 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002501
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002502 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002503 EXPECT_TRUE(
2504 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2505 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2506 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2507
2508 // Create a session description based on another SDP with another
2509 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002510 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002511
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002512 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002513 EXPECT_TRUE(
2514 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2515}
2516
2517// This test verifies that when remote tracks are added/removed from SDP, the
2518// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002519// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2520// specific behavior.
2521TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002522 AddRemoveTrackFromExistingRemoteMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002523 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002524 CreatePeerConnection(config);
kwibergd1fe2812016-04-27 06:47:29 -07002525 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002526 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002527 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002528 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
Niels Möllerafb246b2022-04-20 14:26:50 +02002529 reference_collection_.get()));
deadbeefab9b2d12015-10-14 11:33:11 -07002530
2531 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002532 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002533 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002534 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002535 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
Niels Möllerafb246b2022-04-20 14:26:50 +02002536 reference_collection_.get()));
zhihuang9763d562016-08-05 11:14:50 -07002537 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002538 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2539 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002540 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002541 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2542 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002543
2544 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002545 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002546 CreateSessionDescriptionAndReference(1, 1);
Niels Möllerafb246b2022-04-20 14:26:50 +02002547 MockTrackObserver audio_track_observer(audio_track2.get());
2548 MockTrackObserver video_track_observer(video_track2.get());
perkjd61bf802016-03-24 03:16:19 -07002549
2550 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2551 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002552 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002553 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
Niels Möllerafb246b2022-04-20 14:26:50 +02002554 reference_collection_.get()));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002555 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002556 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002557 audio_track2->state(), kTimeout);
2558 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2559 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002560}
2561
2562// This tests that remote tracks are ended if a local session description is set
2563// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002564TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002565 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002566 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002567 // First create and set a remote offer, then reject its video content in our
2568 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002569 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2570 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2571 ASSERT_TRUE(audio_receiver);
2572 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2573 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002574
Steve Anton36da6ff2018-02-16 16:04:20 -08002575 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2576 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002577 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002578 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2579 video_receiver->track();
2580 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002581
kwibergd1fe2812016-04-27 06:47:29 -07002582 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002583 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002584 cricket::ContentInfo* video_info =
2585 local_answer->description()->GetContentByName("video");
2586 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002587 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002588 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2589 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002590
2591 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002592 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002593 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002594 video_info = local_offer->description()->GetContentByName("video");
2595 ASSERT_TRUE(video_info != nullptr);
2596 video_info->rejected = true;
2597 cricket::ContentInfo* audio_info =
2598 local_offer->description()->GetContentByName("audio");
2599 ASSERT_TRUE(audio_info != nullptr);
2600 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002601 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002602 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002603 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2604 kTimeout);
2605 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2606 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002607}
2608
2609// This tests that we won't crash if the remote track has been removed outside
2610// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002611// Don't run under Unified Plan since the stream API is not available.
2612TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002613 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002614 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002615 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002616 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00002617 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2618 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07002619
kwibergd1fe2812016-04-27 06:47:29 -07002620 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002621 webrtc::CreateSessionDescription(SdpType::kAnswer,
2622 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002623 cricket::ContentInfo* video_info =
2624 local_answer->description()->GetContentByName("video");
2625 video_info->rejected = true;
2626 cricket::ContentInfo* audio_info =
2627 local_answer->description()->GetContentByName("audio");
2628 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002629 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002630
2631 // No crash is a pass.
2632}
2633
deadbeef5e97fb52015-10-15 12:49:08 -07002634// This tests that if a recvonly remote description is set, no remote streams
2635// will be created, even if the description contains SSRCs/MSIDs.
2636// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002637TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002638 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002639 CreatePeerConnection(config);
deadbeef5e97fb52015-10-15 12:49:08 -07002640
Steve Anton36da6ff2018-02-16 16:04:20 -08002641 std::string recvonly_offer = GetSdpStringWithStream1();
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002642 absl::StrReplaceAll({{kSendrecv, kRecvonly}}, &recvonly_offer);
deadbeef5e97fb52015-10-15 12:49:08 -07002643 CreateAndSetRemoteOffer(recvonly_offer);
2644
2645 EXPECT_EQ(0u, observer_.remote_streams()->count());
2646}
2647
deadbeefab9b2d12015-10-14 11:33:11 -07002648// This tests that a default MediaStream is created if a remote session
2649// description doesn't contain any streams and no MSID support.
2650// It also tests that the default stream is updated if a video m-line is added
2651// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002652// Don't run under Unified Plan since this behavior is Plan B specific.
2653TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002654 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002655 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002656 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2657
2658 ASSERT_EQ(1u, observer_.remote_streams()->count());
2659 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2660
2661 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2662 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002663 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002664
2665 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2666 ASSERT_EQ(1u, observer_.remote_streams()->count());
2667 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2668 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002669 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2670 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002671 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2672 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002673 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2674 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002675}
2676
2677// This tests that a default MediaStream is created if a remote session
2678// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002679// Don't run under Unified Plan since this behavior is Plan B specific.
2680TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002681 SendOnlySdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002682 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002683 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002684 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2685
2686 ASSERT_EQ(1u, observer_.remote_streams()->count());
2687 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2688
2689 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2690 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002691 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002692}
2693
2694// This tests that it won't crash when PeerConnection tries to remove
2695// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002696// Don't run under Unified Plan since this behavior is Plan B specific.
2697TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002698 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002699 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002700 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002701 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00002702 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2703 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07002704
2705 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2706
2707 // No crash is a pass.
2708}
2709
2710// This tests that a default MediaStream is created if the remote session
2711// description doesn't contain any streams and don't contain an indication if
2712// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002713// Don't run under Unified Plan since this behavior is Plan B specific.
2714TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002715 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002716 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002717 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002718 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2719
2720 ASSERT_EQ(1u, observer_.remote_streams()->count());
2721 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2722 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2723 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2724}
2725
2726// This tests that a default MediaStream is not created if the remote session
2727// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08002728// Don't run under Unified Plan since this behavior is Plan B specific.
2729TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002730 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002731 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002732 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2733 EXPECT_EQ(0u, observer_.remote_streams()->count());
2734}
2735
deadbeefbda7e0b2015-12-08 17:13:40 -08002736// This tests that when setting a new description, the old default tracks are
2737// not destroyed and recreated.
2738// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08002739// Don't run under Unified Plan since this behavior is Plan B specific.
2740TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002741 DefaultTracksNotDestroyedAndRecreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002742 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002743 CreatePeerConnection(config);
deadbeefbda7e0b2015-12-08 17:13:40 -08002744 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2745
2746 ASSERT_EQ(1u, observer_.remote_streams()->count());
2747 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2748 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2749
2750 // Set the track to "disabled", then set a new description and ensure the
2751 // track is still disabled, which ensures it hasn't been recreated.
2752 remote_stream->GetAudioTracks()[0]->set_enabled(false);
2753 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2754 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2755 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
2756}
2757
deadbeefab9b2d12015-10-14 11:33:11 -07002758// This tests that a default MediaStream is not created if a remote session
2759// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08002760// Don't run under Unified Plan since this behavior is Plan B specific.
2761TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002762 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002763 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002764 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002765 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002766 EXPECT_TRUE(
2767 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2768
2769 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2770 EXPECT_EQ(0u, observer_.remote_streams()->count());
2771}
2772
Seth Hampson5897a6e2018-04-03 11:16:33 -07002773// This tests that a default MediaStream is created if a remote SDP comes from
2774// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
2775TEST_F(PeerConnectionInterfaceTestPlanB,
2776 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002777 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002778 CreatePeerConnection(config);
Seth Hampson5897a6e2018-04-03 11:16:33 -07002779 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
2780 // Add a=msid lines to simulate a Unified Plan endpoint that only
2781 // signals stream IDs with a=msid lines.
2782 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
2783
2784 CreateAndSetRemoteOffer(sdp_string);
2785
2786 ASSERT_EQ(1u, observer_.remote_streams()->count());
2787 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2788 EXPECT_EQ("default", remote_stream->id());
2789 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2790}
2791
Seth Hampson5b4f0752018-04-02 16:31:36 -07002792// This tests that when a Plan B endpoint receives an SDP that signals no media
2793// stream IDs indicated by the special character "-" in the a=msid line, that
2794// a default stream ID will be used for the MediaStream ID. This can occur
2795// when a Unified Plan endpoint signals no media stream IDs, but signals both
2796// a=ssrc msid and a=msid lines for interop signaling with Plan B.
2797TEST_F(PeerConnectionInterfaceTestPlanB,
2798 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002799 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002800 CreatePeerConnection(config);
Seth Hampson5b4f0752018-04-02 16:31:36 -07002801 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
2802 // the sender's stream ID will be interpreted as no stream IDs.
2803 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
2804 sdp_string.append("a=msid:- audiotrack0\n");
2805
2806 CreateAndSetRemoteOffer(sdp_string);
2807
2808 ASSERT_EQ(1u, observer_.remote_streams()->count());
2809 // Because SSRCs are signaled the track ID will be what was signaled in the
2810 // a=msid line.
2811 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
2812 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2813 EXPECT_EQ("default", remote_stream->id());
2814 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07002815
2816 // Previously a bug ocurred when setting the remote description a second time.
2817 // This is because we checked equality of the remote StreamParams stream ID
2818 // (empty), and the previously set stream ID for the remote sender
2819 // ("default"). This cause a track to be removed, then added, when really
2820 // nothing should occur because it is the same track.
2821 CreateAndSetRemoteOffer(sdp_string);
2822 EXPECT_EQ(0u, observer_.remove_track_events_.size());
2823 EXPECT_EQ(1u, observer_.add_track_events_.size());
2824 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
2825 remote_stream = observer_.remote_streams()->at(0);
2826 EXPECT_EQ("default", remote_stream->id());
2827 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07002828}
2829
deadbeefab9b2d12015-10-14 11:33:11 -07002830// This tests that an RtpSender is created when the local description is set
2831// after adding a local stream.
2832// TODO(deadbeef): This test and the one below it need to be updated when
2833// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08002834// Don't run under Unified Plan since this behavior is Plan B specific.
2835TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002836 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002837 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002838
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002839 // Create an offer with 1 stream with 2 tracks of each type.
2840 rtc::scoped_refptr<StreamCollection> stream_collection =
2841 CreateStreamCollection(1, 2);
2842 pc_->AddStream(stream_collection->at(0));
2843 std::unique_ptr<SessionDescriptionInterface> offer;
2844 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002845 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002846
deadbeefab9b2d12015-10-14 11:33:11 -07002847 auto senders = pc_->GetSenders();
2848 EXPECT_EQ(4u, senders.size());
2849 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2850 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2851 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2852 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2853
2854 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002855 pc_->RemoveStream(stream_collection->at(0));
2856 stream_collection = CreateStreamCollection(1, 1);
2857 pc_->AddStream(stream_collection->at(0));
2858 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002859 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002860
deadbeefab9b2d12015-10-14 11:33:11 -07002861 senders = pc_->GetSenders();
2862 EXPECT_EQ(2u, senders.size());
2863 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2864 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2865 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
2866 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
2867}
2868
2869// This tests that an RtpSender is created when the local description is set
2870// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002871// Don't run under Unified Plan since this behavior is Plan B specific.
2872TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002873 AddLocalStreamAfterLocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002874 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002875 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002876
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002877 rtc::scoped_refptr<StreamCollection> stream_collection =
2878 CreateStreamCollection(1, 2);
2879 // Add a stream to create the offer, but remove it afterwards.
2880 pc_->AddStream(stream_collection->at(0));
2881 std::unique_ptr<SessionDescriptionInterface> offer;
2882 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2883 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002884
Steve Antondb45ca82017-09-11 18:27:34 -07002885 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002886 auto senders = pc_->GetSenders();
2887 EXPECT_EQ(0u, senders.size());
2888
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002889 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002890 senders = pc_->GetSenders();
2891 EXPECT_EQ(4u, senders.size());
2892 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2893 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2894 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2895 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2896}
2897
2898// This tests that the expected behavior occurs if the SSRC on a local track is
2899// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002900TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002901 ChangeSsrcOnTrackInLocalSessionDescription) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002902 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002903 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002904
Steve Anton36da6ff2018-02-16 16:04:20 -08002905 AddAudioTrack(kAudioTracks[0]);
2906 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002907 std::unique_ptr<SessionDescriptionInterface> offer;
2908 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2909 // Grab a copy of the offer before it gets passed into the PC.
Steve Antond9e4a062018-07-24 18:23:33 -07002910 std::unique_ptr<SessionDescriptionInterface> modified_offer =
2911 webrtc::CreateSessionDescription(
2912 webrtc::SdpType::kOffer, offer->session_id(),
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02002913 offer->session_version(), offer->description()->Clone());
Steve Antondb45ca82017-09-11 18:27:34 -07002914 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002915
deadbeefab9b2d12015-10-14 11:33:11 -07002916 auto senders = pc_->GetSenders();
2917 EXPECT_EQ(2u, senders.size());
2918 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2919 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2920
2921 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002922 cricket::MediaContentDescription* desc =
2923 cricket::GetFirstAudioContentDescription(modified_offer->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002924 ASSERT_TRUE(desc != nullptr);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002925 for (StreamParams& stream : desc->mutable_streams()) {
2926 for (unsigned int& ssrc : stream.ssrcs) {
2927 ++ssrc;
2928 }
2929 }
deadbeefab9b2d12015-10-14 11:33:11 -07002930
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002931 desc =
2932 cricket::GetFirstVideoContentDescription(modified_offer->description());
Niels Möllerafb246b2022-04-20 14:26:50 +02002933 ASSERT_TRUE(desc != nullptr);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002934 for (StreamParams& stream : desc->mutable_streams()) {
2935 for (unsigned int& ssrc : stream.ssrcs) {
2936 ++ssrc;
2937 }
2938 }
2939
Steve Antondb45ca82017-09-11 18:27:34 -07002940 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002941 senders = pc_->GetSenders();
2942 EXPECT_EQ(2u, senders.size());
2943 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2944 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2945 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
2946 // changed.
2947}
2948
2949// This tests that the expected behavior occurs if a new session description is
2950// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002951// Don't run under Unified Plan since the stream API is not available.
2952TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002953 SignalSameTracksInSeparateMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002954 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002955 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002956
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002957 rtc::scoped_refptr<StreamCollection> stream_collection =
2958 CreateStreamCollection(2, 1);
2959 pc_->AddStream(stream_collection->at(0));
2960 std::unique_ptr<SessionDescriptionInterface> offer;
2961 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002962 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002963
deadbeefab9b2d12015-10-14 11:33:11 -07002964 auto senders = pc_->GetSenders();
2965 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002966 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
2967 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07002968
2969 // Add a new MediaStream but with the same tracks as in the first stream.
2970 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
2971 webrtc::MediaStream::Create(kStreams[1]));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00002972 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
2973 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
Niels Möllerafb246b2022-04-20 14:26:50 +02002974 pc_->AddStream(stream_1.get());
deadbeefab9b2d12015-10-14 11:33:11 -07002975
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002976 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002977 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002978
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002979 auto new_senders = pc_->GetSenders();
2980 // Should be the same senders as before, but with updated stream id.
2981 // Note that this behavior is subject to change in the future.
2982 // We may decide the PC should ignore existing tracks in AddStream.
2983 EXPECT_EQ(senders, new_senders);
2984 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
2985 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07002986}
2987
zhihuang81c3a032016-11-17 12:06:24 -08002988// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002989TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002990 RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002991 CreatePeerConnection(config);
zhihuang81c3a032016-11-17 12:06:24 -08002992 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
2993 EXPECT_EQ(observer_.num_added_tracks_, 1);
2994 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
2995
2996 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08002997 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
Steve Anton0f5400a2018-07-17 14:25:36 -07002998 EXPECT_EQ(observer_.num_added_tracks_, 2);
zhihuang81c3a032016-11-17 12:06:24 -08002999 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3000}
3001
deadbeefd1a38b52016-12-10 13:15:33 -08003002// Test that when SetConfiguration is called and the configuration is
3003// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003004TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003005 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003006 config.sdp_semantics = sdp_semantics_;
deadbeefd1a38b52016-12-10 13:15:33 -08003007 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003008 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003009 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003010 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3011 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003012
3013 // Do initial offer/answer so there's something to restart.
3014 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003015 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003016
3017 // Grab the ufrags.
3018 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3019
3020 // Change ICE policy, which should trigger an ICE restart on the next offer.
3021 config.type = PeerConnectionInterface::kAll;
Niels Möller2579f0c2019-08-19 09:58:17 +02003022 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeefd1a38b52016-12-10 13:15:33 -08003023 CreateOfferAsLocalDescription();
3024
3025 // Grab the new ufrags.
3026 std::vector<std::string> subsequent_ufrags =
3027 GetUfrags(pc_->local_description());
3028
3029 // Sanity check.
3030 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3031 // Check that each ufrag is different.
3032 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3033 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3034 }
3035}
3036
3037// Test that when SetConfiguration is called and the configuration *isn't*
3038// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003039TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003040 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003041 config.sdp_semantics = sdp_semantics_;
deadbeefd1a38b52016-12-10 13:15:33 -08003042 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003043 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003044 config = pc_->GetConfiguration();
3045 AddAudioTrack(kAudioTracks[0]);
3046 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003047
3048 // Do initial offer/answer so there's something to restart.
3049 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003050 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003051
3052 // Grab the ufrags.
3053 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3054
3055 // Call SetConfiguration with a config identical to what the PC was
3056 // constructed with.
Niels Möller2579f0c2019-08-19 09:58:17 +02003057 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeefd1a38b52016-12-10 13:15:33 -08003058 CreateOfferAsLocalDescription();
3059
3060 // Grab the new ufrags.
3061 std::vector<std::string> subsequent_ufrags =
3062 GetUfrags(pc_->local_description());
3063
3064 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3065}
3066
3067// Test for a weird corner case scenario:
3068// 1. Audio/video session established.
3069// 2. SetConfiguration changes ICE config; ICE restart needed.
3070// 3. ICE restart initiated by remote peer, but only for one m= section.
3071// 4. Next createOffer should initiate an ICE restart, but only for the other
3072// m= section; it would be pointless to do an ICE restart for the m= section
3073// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003074TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003075 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003076 config.sdp_semantics = sdp_semantics_;
deadbeefd1a38b52016-12-10 13:15:33 -08003077 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003078 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003079 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003080 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3081 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003082
3083 // Do initial offer/answer so there's something to restart.
3084 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003085 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003086
3087 // Change ICE policy, which should set the "needs-ice-restart" flag.
3088 config.type = PeerConnectionInterface::kAll;
Niels Möller2579f0c2019-08-19 09:58:17 +02003089 EXPECT_TRUE(pc_->SetConfiguration(config).ok());
deadbeefd1a38b52016-12-10 13:15:33 -08003090
3091 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003092 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003093 webrtc::CreateSessionDescription(SdpType::kOffer,
3094 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003095 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003096 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3097 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003098 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003099 CreateAnswerAsLocalDescription();
3100
3101 // Grab the ufrags.
3102 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003103 ASSERT_EQ(2U, initial_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003104
3105 // Create offer and grab the new ufrags.
3106 CreateOfferAsLocalDescription();
3107 std::vector<std::string> subsequent_ufrags =
3108 GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003109 ASSERT_EQ(2U, subsequent_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003110
3111 // Ensure that only the ufrag for the second m= section changed.
3112 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3113 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3114}
3115
deadbeeffe4a8a42016-12-20 17:56:17 -08003116// Tests that the methods to return current/pending descriptions work as
3117// expected at different points in the offer/answer exchange. This test does
3118// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003119TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003120 // This disables DTLS so we can apply an answer to ourselves.
3121 CreatePeerConnection();
3122
3123 // Create initial local offer and get SDP (which will also be used as
3124 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003125 std::unique_ptr<SessionDescriptionInterface> local_offer;
3126 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003127 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003128 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003129
3130 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003131 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3132 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3133 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003134 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3135 EXPECT_EQ(nullptr, pc_->current_local_description());
3136 EXPECT_EQ(nullptr, pc_->current_remote_description());
3137
3138 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003139 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003140 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003141 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3142 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3143 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3144 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003145 EXPECT_EQ(nullptr, pc_->current_local_description());
3146 EXPECT_EQ(nullptr, pc_->current_remote_description());
3147
3148 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003149 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003150 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003151 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3152 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003153 EXPECT_EQ(nullptr, pc_->pending_local_description());
3154 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003155 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3156 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003157
3158 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003159 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003160 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003161 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3162 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3163 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003164 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003165 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3166 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003167
3168 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003169 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003170 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003171 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3172 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3173 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3174 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3175 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3176 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003177
3178 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003179 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003180 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003181 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3182 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003183 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3184 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003185 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3186 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003187}
3188
zhihuang77985012017-02-07 15:45:16 -08003189// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3190// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003191// This version tests the StartRtcEventLog version that receives an object
Artem Titov880fa812021-07-30 22:30:23 +02003192// of type `RtcEventLogOutput`.
Steve Anton36da6ff2018-02-16 16:04:20 -08003193TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003194 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3195 CreatePeerConnection();
3196 // The RtcEventLog will be reset when the PeerConnection is closed.
3197 pc_->Close();
3198
Niels Möllerdec9f742019-06-03 15:25:20 +02003199 EXPECT_FALSE(
Mirko Bonadei317a1f02019-09-17 17:06:18 +02003200 pc_->StartRtcEventLog(std::make_unique<webrtc::RtcEventLogOutputNull>(),
Niels Möllerdec9f742019-06-03 15:25:20 +02003201 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003202 pc_->StopRtcEventLog();
3203}
3204
deadbeef30952b42017-04-21 02:41:29 -07003205// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003206TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003207 CreatePeerConnection();
3208
3209 // First, create an offer with audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003210 RTCOfferAnswerOptions options;
3211 options.offer_to_receive_audio = 1;
3212 options.offer_to_receive_video = 1;
deadbeef30952b42017-04-21 02:41:29 -07003213 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003214 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003215 cricket::SessionDescription* desc = offer->description();
3216 ASSERT_EQ(2u, desc->transport_infos().size());
3217 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3218 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3219
3220 // Apply the offer as a remote description, then create an answer.
Harald Alvestrand61f74d92020-03-02 11:20:00 +01003221 EXPECT_FALSE(pc_->can_trickle_ice_candidates());
Steve Antondb45ca82017-09-11 18:27:34 -07003222 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
Harald Alvestrand61f74d92020-03-02 11:20:00 +01003223 ASSERT_TRUE(pc_->can_trickle_ice_candidates());
3224 EXPECT_TRUE(*(pc_->can_trickle_ice_candidates()));
deadbeef30952b42017-04-21 02:41:29 -07003225 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003226 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003227 desc = answer->description();
3228 ASSERT_EQ(2u, desc->transport_infos().size());
3229 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3230 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3231}
3232
deadbeef1dcb1642017-03-29 21:08:16 -07003233// Test that ICE renomination isn't offered if it's not enabled in the PC's
3234// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003235TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003236 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003237 config.sdp_semantics = sdp_semantics_;
deadbeef1dcb1642017-03-29 21:08:16 -07003238 config.enable_ice_renomination = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02003239 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003240 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003241
3242 std::unique_ptr<SessionDescriptionInterface> offer;
3243 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3244 cricket::SessionDescription* desc = offer->description();
3245 EXPECT_EQ(1u, desc->transport_infos().size());
3246 EXPECT_FALSE(
3247 desc->transport_infos()[0].description.GetIceParameters().renomination);
3248}
3249
3250// Test that the ICE renomination option is present in generated offers/answers
3251// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003252TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003253 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003254 config.sdp_semantics = sdp_semantics_;
deadbeef1dcb1642017-03-29 21:08:16 -07003255 config.enable_ice_renomination = true;
Niels Möllerf06f9232018-08-07 12:32:18 +02003256 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003257 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003258
3259 std::unique_ptr<SessionDescriptionInterface> offer;
3260 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3261 cricket::SessionDescription* desc = offer->description();
3262 EXPECT_EQ(1u, desc->transport_infos().size());
3263 EXPECT_TRUE(
3264 desc->transport_infos()[0].description.GetIceParameters().renomination);
3265
3266 // Set the offer as a remote description, then create an answer and ensure it
3267 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003268 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003269 std::unique_ptr<SessionDescriptionInterface> answer;
3270 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3271 desc = answer->description();
3272 EXPECT_EQ(1u, desc->transport_infos().size());
3273 EXPECT_TRUE(
3274 desc->transport_infos()[0].description.GetIceParameters().renomination);
3275}
3276
3277// Test that if CreateOffer is called with the deprecated "offer to receive
3278// audio/video" constraints, they're processed and result in an offer with
3279// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003280TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003281 CreatePeerConnection();
3282
Niels Möllerf06f9232018-08-07 12:32:18 +02003283 RTCOfferAnswerOptions options;
3284 options.offer_to_receive_audio = 1;
3285 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003286 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003287 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003288
3289 cricket::SessionDescription* desc = offer->description();
3290 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3291 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3292 ASSERT_NE(nullptr, audio);
3293 ASSERT_NE(nullptr, video);
3294 EXPECT_FALSE(audio->rejected);
3295 EXPECT_FALSE(video->rejected);
3296}
3297
3298// Test that if CreateAnswer is called with the deprecated "offer to receive
3299// audio/video" constraints, they're processed and can be used to reject an
3300// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003301// Don't run under Unified Plan since this behavior is not supported.
3302TEST_F(PeerConnectionInterfaceTestPlanB,
3303 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003304 CreatePeerConnection();
3305
3306 // First, create an offer with audio/video and apply it as a remote
3307 // description.
Niels Möllerf06f9232018-08-07 12:32:18 +02003308 RTCOfferAnswerOptions options;
3309 options.offer_to_receive_audio = 1;
3310 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003311 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003312 ASSERT_TRUE(DoCreateOffer(&offer, &options));
Steve Antondb45ca82017-09-11 18:27:34 -07003313 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003314
3315 // Now create answer that rejects audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003316 options.offer_to_receive_audio = 0;
3317 options.offer_to_receive_video = 0;
deadbeef1dcb1642017-03-29 21:08:16 -07003318 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003319 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003320
3321 cricket::SessionDescription* desc = answer->description();
3322 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3323 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3324 ASSERT_NE(nullptr, audio);
3325 ASSERT_NE(nullptr, video);
3326 EXPECT_TRUE(audio->rejected);
3327 EXPECT_TRUE(video->rejected);
3328}
3329
deadbeef1dcb1642017-03-29 21:08:16 -07003330// Test that negotiation can succeed with a data channel only, and with the max
3331// bundle policy. Previously there was a bug that prevented this.
Mirko Bonadei5eb43b42021-01-18 13:24:40 +01003332#ifdef WEBRTC_HAVE_SCTP
Steve Anton36da6ff2018-02-16 16:04:20 -08003333TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3334#else
3335TEST_P(PeerConnectionInterfaceTest,
3336 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
Mirko Bonadei5eb43b42021-01-18 13:24:40 +01003337#endif // WEBRTC_HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003338 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003339 config.sdp_semantics = sdp_semantics_;
deadbeef1dcb1642017-03-29 21:08:16 -07003340 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möllerf06f9232018-08-07 12:32:18 +02003341 CreatePeerConnection(config);
deadbeef1dcb1642017-03-29 21:08:16 -07003342
3343 // First, create an offer with only a data channel and apply it as a remote
3344 // description.
Florent Castelli72424402022-04-06 03:45:10 +02003345 pc_->CreateDataChannelOrError("test", nullptr);
deadbeef1dcb1642017-03-29 21:08:16 -07003346 std::unique_ptr<SessionDescriptionInterface> offer;
3347 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003348 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003349
3350 // Create and set answer as well.
3351 std::unique_ptr<SessionDescriptionInterface> answer;
3352 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003353 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003354}
3355
Steve Anton36da6ff2018-02-16 16:04:20 -08003356TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003357 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003358 BitrateSettings bitrate;
3359 bitrate.start_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003360 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3361}
3362
Steve Anton36da6ff2018-02-16 16:04:20 -08003363TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003364 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003365 BitrateSettings bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003366 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003367 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3368}
3369
Steve Anton36da6ff2018-02-16 16:04:20 -08003370TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003371 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003372 BitrateSettings bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003373 bitrate.min_bitrate_bps = 5;
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003374 bitrate.start_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003375 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3376}
3377
Steve Anton36da6ff2018-02-16 16:04:20 -08003378TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003379 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003380 BitrateSettings bitrate;
3381 bitrate.start_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003382 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3383}
3384
Steve Anton36da6ff2018-02-16 16:04:20 -08003385TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003386 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003387 BitrateSettings bitrate;
3388 bitrate.start_bitrate_bps = 10;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003389 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003390 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3391}
3392
Steve Anton36da6ff2018-02-16 16:04:20 -08003393TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003394 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003395 BitrateSettings bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003396 bitrate.min_bitrate_bps = 10;
3397 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003398 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3399}
3400
Steve Anton36da6ff2018-02-16 16:04:20 -08003401TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003402 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003403 BitrateSettings bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003404 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003405 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3406}
3407
Niels Möller0c4f7be2018-05-07 14:01:37 +02003408// The current bitrate from BitrateSettings is currently clamped
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003409// by Call's BitrateConstraints, which comes from the SDP or a default value.
3410// This test checks that a call to SetBitrate with a current bitrate that will
3411// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003412TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003413 CreatePeerConnection();
Niels Möller9ad1f6f2020-07-13 10:25:41 +02003414 BitrateSettings bitrate;
3415 bitrate.start_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003416 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3417}
3418
zhihuang1c378ed2017-08-17 14:10:50 -07003419// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003420TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003421 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3422 RTCOfferAnswerOptions rtc_options;
3423
3424 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3425 // than kMaxOfferToReceiveMedia should be treated as invalid.
3426 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3427 CreatePeerConnection();
3428 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3429
3430 rtc_options.offer_to_receive_audio =
3431 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3432 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3433}
3434
Steve Anton36da6ff2018-02-16 16:04:20 -08003435TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003436 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3437 RTCOfferAnswerOptions rtc_options;
3438
3439 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3440 // than kMaxOfferToReceiveMedia should be treated as invalid.
3441 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3442 CreatePeerConnection();
3443 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3444
3445 rtc_options.offer_to_receive_video =
3446 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3447 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3448}
3449
3450// Test that the audio and video content will be added to an offer if both
Artem Titov880fa812021-07-30 22:30:23 +02003451// `offer_to_receive_audio` and `offer_to_receive_video` options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003452TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003453 RTCOfferAnswerOptions rtc_options;
3454 rtc_options.offer_to_receive_audio = 1;
3455 rtc_options.offer_to_receive_video = 1;
3456
3457 std::unique_ptr<SessionDescriptionInterface> offer;
3458 CreatePeerConnection();
3459 offer = CreateOfferWithOptions(rtc_options);
3460 ASSERT_TRUE(offer);
3461 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3462 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3463}
3464
3465// Test that only audio content will be added to the offer if only
Artem Titov880fa812021-07-30 22:30:23 +02003466// `offer_to_receive_audio` options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003467TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003468 RTCOfferAnswerOptions rtc_options;
3469 rtc_options.offer_to_receive_audio = 1;
3470 rtc_options.offer_to_receive_video = 0;
3471
3472 std::unique_ptr<SessionDescriptionInterface> offer;
3473 CreatePeerConnection();
3474 offer = CreateOfferWithOptions(rtc_options);
3475 ASSERT_TRUE(offer);
3476 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3477 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3478}
3479
Artem Titov880fa812021-07-30 22:30:23 +02003480// Test that only video content will be added if only `offer_to_receive_video`
zhihuang1c378ed2017-08-17 14:10:50 -07003481// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003482TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003483 RTCOfferAnswerOptions rtc_options;
3484 rtc_options.offer_to_receive_audio = 0;
3485 rtc_options.offer_to_receive_video = 1;
3486
3487 std::unique_ptr<SessionDescriptionInterface> offer;
3488 CreatePeerConnection();
3489 offer = CreateOfferWithOptions(rtc_options);
3490 ASSERT_TRUE(offer);
3491 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3492 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3493}
3494
zhihuang1c378ed2017-08-17 14:10:50 -07003495// Test that no media content will be added to the offer if using default
3496// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003497TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003498 RTCOfferAnswerOptions rtc_options;
3499
3500 std::unique_ptr<SessionDescriptionInterface> offer;
3501 CreatePeerConnection();
3502 offer = CreateOfferWithOptions(rtc_options);
3503 ASSERT_TRUE(offer);
3504 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3505 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3506}
3507
Artem Titov880fa812021-07-30 22:30:23 +02003508// Test that if `ice_restart` is true, the ufrag/pwd will change, otherwise
zhihuang1c378ed2017-08-17 14:10:50 -07003509// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003510TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3511 CreatePeerConnection();
3512
zhihuang1c378ed2017-08-17 14:10:50 -07003513 RTCOfferAnswerOptions rtc_options;
3514 rtc_options.ice_restart = false;
3515 rtc_options.offer_to_receive_audio = 1;
3516
3517 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003518 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003519 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3520 auto ufrag1 =
3521 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3522 auto pwd1 =
3523 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003524
Artem Titov880fa812021-07-30 22:30:23 +02003525 // `ice_restart` is false, the ufrag/pwd shouldn't change.
zhihuang1c378ed2017-08-17 14:10:50 -07003526 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003527 auto ufrag2 =
3528 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3529 auto pwd2 =
3530 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003531
Artem Titov880fa812021-07-30 22:30:23 +02003532 // `ice_restart` is true, the ufrag/pwd should change.
zhihuang1c378ed2017-08-17 14:10:50 -07003533 rtc_options.ice_restart = true;
3534 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003535 auto ufrag3 =
3536 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3537 auto pwd3 =
3538 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003539
3540 EXPECT_EQ(ufrag1, ufrag2);
3541 EXPECT_EQ(pwd1, pwd2);
3542 EXPECT_NE(ufrag2, ufrag3);
3543 EXPECT_NE(pwd2, pwd3);
3544}
3545
Artem Titov880fa812021-07-30 22:30:23 +02003546// Test that if `use_rtp_mux` is true, the bundling will be enabled in the
zhihuang1c378ed2017-08-17 14:10:50 -07003547// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003548TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003549 RTCOfferAnswerOptions rtc_options;
3550 rtc_options.offer_to_receive_audio = 1;
3551 rtc_options.offer_to_receive_video = 1;
3552
3553 std::unique_ptr<SessionDescriptionInterface> offer;
3554 CreatePeerConnection();
3555
3556 rtc_options.use_rtp_mux = true;
3557 offer = CreateOfferWithOptions(rtc_options);
3558 ASSERT_TRUE(offer);
3559 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3560 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3561 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3562
3563 rtc_options.use_rtp_mux = false;
3564 offer = CreateOfferWithOptions(rtc_options);
3565 ASSERT_TRUE(offer);
3566 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3567 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3568 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3569}
3570
zhihuang141aacb2017-08-29 13:23:53 -07003571// This test ensures OnRenegotiationNeeded is called when we add track with
3572// MediaStream -> AddTrack in the same way it is called when we add track with
3573// PeerConnection -> AddTrack.
3574// The test can be removed once addStream is rewritten in terms of addTrack
3575// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003576// Don't run under Unified Plan since the stream API is not available.
3577TEST_F(PeerConnectionInterfaceTestPlanB,
3578 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003579 CreatePeerConnectionWithoutDtls();
3580 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003581 pc_factory_->CreateLocalMediaStream(kStreamId1));
Niels Möllerafb246b2022-04-20 14:26:50 +02003582 pc_->AddStream(stream.get());
zhihuang141aacb2017-08-29 13:23:53 -07003583 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01003584 CreateAudioTrack("audio_track"));
zhihuang141aacb2017-08-29 13:23:53 -07003585 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01003586 CreateVideoTrack("video_track"));
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00003587 stream->AddTrack(audio_track);
zhihuang141aacb2017-08-29 13:23:53 -07003588 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3589 observer_.renegotiation_needed_ = false;
3590
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003591 CreateOfferReceiveAnswer();
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00003592 stream->AddTrack(video_track);
zhihuang141aacb2017-08-29 13:23:53 -07003593 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3594 observer_.renegotiation_needed_ = false;
3595
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003596 CreateOfferReceiveAnswer();
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00003597 stream->RemoveTrack(audio_track);
zhihuang141aacb2017-08-29 13:23:53 -07003598 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3599 observer_.renegotiation_needed_ = false;
3600
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003601 CreateOfferReceiveAnswer();
Harald Alvestrand2f7ad282022-04-21 11:35:43 +00003602 stream->RemoveTrack(video_track);
zhihuang141aacb2017-08-29 13:23:53 -07003603 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3604 observer_.renegotiation_needed_ = false;
3605}
3606
Zhi Huangb2d355e2017-10-26 17:26:37 -07003607// Tests that an error is returned if a description is applied that has fewer
3608// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003609TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003610 MediaSectionCountEnforcedForSubsequentOffer) {
3611 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003612 AddAudioTrack("audio_label");
3613 AddVideoTrack("video_label");
3614
Zhi Huangb2d355e2017-10-26 17:26:37 -07003615 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003616 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003617 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3618
3619 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003620 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003621 offer->description()->contents().pop_back();
3622 offer->description()->contents().pop_back();
3623 ASSERT_TRUE(offer->description()->contents().empty());
3624 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3625
3626 std::unique_ptr<SessionDescriptionInterface> answer;
3627 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3628 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3629
3630 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003631 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003632 offer->description()->contents().pop_back();
3633 offer->description()->contents().pop_back();
3634 ASSERT_TRUE(offer->description()->contents().empty());
3635 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3636}
3637
Johannes Kron89f874e2018-11-12 10:25:48 +01003638TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) {
3639 RTCConfiguration config;
Emil Lundmark801c9992021-01-19 13:06:32 +01003640 // Default behavior is true.
Johannes Kron89f874e2018-11-12 10:25:48 +01003641 CreatePeerConnection(config);
3642 std::unique_ptr<SessionDescriptionInterface> offer;
3643 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Emil Lundmark801c9992021-01-19 13:06:32 +01003644 EXPECT_TRUE(offer->description()->extmap_allow_mixed());
3645 // Possible to set to false.
3646 config.offer_extmap_allow_mixed = false;
Johannes Kron89f874e2018-11-12 10:25:48 +01003647 CreatePeerConnection(config);
Artem Titov4f3a2eb2021-01-26 09:58:21 +01003648 offer = nullptr;
Johannes Kron89f874e2018-11-12 10:25:48 +01003649 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Emil Lundmark801c9992021-01-19 13:06:32 +01003650 EXPECT_FALSE(offer->description()->extmap_allow_mixed());
Johannes Kron89f874e2018-11-12 10:25:48 +01003651}
3652
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003653INSTANTIATE_TEST_SUITE_P(PeerConnectionInterfaceTest,
3654 PeerConnectionInterfaceTest,
Florent Castelli15a38de2022-04-06 00:38:21 +02003655 Values(SdpSemantics::kPlanB_DEPRECATED,
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003656 SdpSemantics::kUnifiedPlan));
Steve Anton36da6ff2018-02-16 16:04:20 -08003657
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003658class PeerConnectionMediaConfigTest : public ::testing::Test {
nisse51542be2016-02-12 02:27:06 -08003659 protected:
3660 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07003661 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08003662 }
nisseeaabdf62017-05-05 02:23:02 -07003663 const cricket::MediaConfig TestCreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +02003664 const RTCConfiguration& config) {
Florent Castelli72424402022-04-06 03:45:10 +02003665 PeerConnectionDependencies pc_dependencies(&observer_);
3666 auto result =
3667 pcf_->CreatePeerConnectionOrError(config, std::move(pc_dependencies));
3668 EXPECT_TRUE(result.ok());
Niels Möllerafb246b2022-04-20 14:26:50 +02003669 observer_.SetPeerConnectionInterface(result.value().get());
Florent Castelli72424402022-04-06 03:45:10 +02003670 return result.value()->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08003671 }
3672
zhihuang9763d562016-08-05 11:14:50 -07003673 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003674 MockPeerConnectionObserver observer_;
3675};
3676
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003677// This sanity check validates the test infrastructure itself.
3678TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) {
3679 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003680 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
Florent Castelli72424402022-04-06 03:45:10 +02003681 PeerConnectionDependencies pc_dependencies(&observer_);
3682 auto result =
3683 pcf_->CreatePeerConnectionOrError(config, std::move(pc_dependencies));
3684 EXPECT_TRUE(result.ok());
Niels Möllerafb246b2022-04-20 14:26:50 +02003685 observer_.SetPeerConnectionInterface(result.value().get());
Florent Castelli72424402022-04-06 03:45:10 +02003686 result.value()->Close(); // No abort -> ok.
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003687 SUCCEED();
3688}
3689
nisse51542be2016-02-12 02:27:06 -08003690// This test verifies the default behaviour with no constraints and a
3691// default RTCConfiguration.
3692TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
3693 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003694 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
nisse51542be2016-02-12 02:27:06 -08003695
Niels Möllerf06f9232018-08-07 12:32:18 +02003696 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003697
Henrik Boström35c5cc82022-04-14 09:23:20 +02003698 EXPECT_TRUE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01003699 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
3700 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003701 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01003702 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08003703}
3704
Niels Möller1d7ecd22018-01-18 15:25:12 +01003705// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07003706// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08003707TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
3708 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003709 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
nisse51542be2016-02-12 02:27:06 -08003710
Niels Möller71bdda02016-03-31 12:59:59 +02003711 config.set_prerenderer_smoothing(false);
Niels Möllerf06f9232018-08-07 12:32:18 +02003712 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003713
Niels Möller1d7ecd22018-01-18 15:25:12 +01003714 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003715}
3716
Niels Möller6539f692018-01-18 08:58:50 +01003717// This test verifies that the experiment_cpu_load_estimator flag is
3718// propagated from RTCConfiguration to the PeerConnection.
3719TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
3720 PeerConnectionInterface::RTCConfiguration config;
Henrik Boström62995db2022-01-03 09:58:10 +01003721 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
Niels Möller6539f692018-01-18 08:58:50 +01003722
3723 config.set_experiment_cpu_load_estimator(true);
Niels Möllerf06f9232018-08-07 12:32:18 +02003724 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
Niels Möller6539f692018-01-18 08:58:50 +01003725
3726 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
3727}
3728
deadbeef293e9262017-01-11 12:28:30 -08003729// Tests a few random fields being different.
3730TEST(RTCConfigurationTest, ComparisonOperators) {
3731 PeerConnectionInterface::RTCConfiguration a;
3732 PeerConnectionInterface::RTCConfiguration b;
3733 EXPECT_EQ(a, b);
3734
3735 PeerConnectionInterface::RTCConfiguration c;
3736 c.servers.push_back(PeerConnectionInterface::IceServer());
3737 EXPECT_NE(a, c);
3738
3739 PeerConnectionInterface::RTCConfiguration d;
3740 d.type = PeerConnectionInterface::kRelay;
3741 EXPECT_NE(a, d);
3742
3743 PeerConnectionInterface::RTCConfiguration e;
3744 e.audio_jitter_buffer_max_packets = 5;
3745 EXPECT_NE(a, e);
3746
3747 PeerConnectionInterface::RTCConfiguration f;
3748 f.ice_connection_receiving_timeout = 1337;
3749 EXPECT_NE(a, f);
3750
3751 PeerConnectionInterface::RTCConfiguration g;
3752 g.disable_ipv6 = true;
3753 EXPECT_NE(a, g);
3754
3755 PeerConnectionInterface::RTCConfiguration h(
3756 PeerConnectionInterface::RTCConfigurationType::kAggressive);
3757 EXPECT_NE(a, h);
3758}
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +01003759
3760} // namespace
3761} // namespace webrtc