blob: 7fa94527f1002b6a3d17b9aa45211e51a51d7544 [file] [log] [blame]
deadbeef1dcb1642017-03-29 21:08:16 -07001/*
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * 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.
9 */
10
Harald Alvestrandf8f7b702022-05-05 13:21:19 +000011// Integration tests for PeerConnection.
12// These tests exercise a full stack over a simulated network.
13//
14// NOTE: If your test takes a while (guideline: more than 5 seconds),
15// do NOT add it here, but instead add it to the file
16// slow_peer_connection_integrationtest.cc
17
Harald Alvestrand39993842021-02-17 09:05:31 +000018#include <stdint.h>
deadbeef1dcb1642017-03-29 21:08:16 -070019
Taylor Brandstetterd3ef4992020-10-15 18:22:57 -070020#include <algorithm>
deadbeef1dcb1642017-03-29 21:08:16 -070021#include <memory>
Harald Alvestrand39993842021-02-17 09:05:31 +000022#include <string>
23#include <tuple>
deadbeef1dcb1642017-03-29 21:08:16 -070024#include <utility>
25#include <vector>
26
Steve Anton64b626b2019-01-28 17:25:26 -080027#include "absl/algorithm/container.h"
Philipp Hanckea09b9212022-06-22 07:41:22 +020028#include "absl/memory/memory.h"
Harald Alvestrandf8f7b702022-05-05 13:21:19 +000029#include "absl/strings/string_view.h"
Harald Alvestrand39993842021-02-17 09:05:31 +000030#include "absl/types/optional.h"
31#include "api/async_resolver_factory.h"
32#include "api/candidate.h"
33#include "api/crypto/crypto_options.h"
34#include "api/dtmf_sender_interface.h"
35#include "api/ice_transport_interface.h"
36#include "api/jsep.h"
Steve Anton10542f22019-01-11 09:11:00 -080037#include "api/media_stream_interface.h"
Harald Alvestrand39993842021-02-17 09:05:31 +000038#include "api/media_types.h"
Steve Anton10542f22019-01-11 09:11:00 -080039#include "api/peer_connection_interface.h"
Harald Alvestrand39993842021-02-17 09:05:31 +000040#include "api/rtc_error.h"
41#include "api/rtc_event_log/rtc_event.h"
42#include "api/rtc_event_log/rtc_event_log.h"
43#include "api/rtc_event_log_output.h"
44#include "api/rtp_parameters.h"
Steve Anton10542f22019-01-11 09:11:00 -080045#include "api/rtp_receiver_interface.h"
Harald Alvestrand39993842021-02-17 09:05:31 +000046#include "api/rtp_sender_interface.h"
47#include "api/rtp_transceiver_direction.h"
48#include "api/rtp_transceiver_interface.h"
49#include "api/scoped_refptr.h"
50#include "api/stats/rtc_stats.h"
51#include "api/stats/rtc_stats_report.h"
52#include "api/stats/rtcstats_objects.h"
Jonas Oreland65455162022-06-08 11:25:46 +020053#include "api/test/mock_encoder_selector.h"
Harald Alvestrand39993842021-02-17 09:05:31 +000054#include "api/transport/rtp/rtp_source.h"
Steve Anton10542f22019-01-11 09:11:00 -080055#include "api/uma_metrics.h"
Harald Alvestrand39993842021-02-17 09:05:31 +000056#include "api/units/time_delta.h"
57#include "api/video/video_rotation.h"
58#include "logging/rtc_event_log/fake_rtc_event_log.h"
Qingsi Wang7685e862018-06-11 20:15:46 -070059#include "logging/rtc_event_log/fake_rtc_event_log_factory.h"
Harald Alvestrand39993842021-02-17 09:05:31 +000060#include "media/base/codec.h"
61#include "media/base/media_constants.h"
62#include "media/base/stream_params.h"
Steve Anton10542f22019-01-11 09:11:00 -080063#include "p2p/base/mock_async_resolver.h"
Harald Alvestrand39993842021-02-17 09:05:31 +000064#include "p2p/base/port.h"
65#include "p2p/base/port_allocator.h"
Steve Anton10542f22019-01-11 09:11:00 -080066#include "p2p/base/port_interface.h"
67#include "p2p/base/test_stun_server.h"
68#include "p2p/base/test_turn_customizer.h"
69#include "p2p/base/test_turn_server.h"
Harald Alvestrand39993842021-02-17 09:05:31 +000070#include "p2p/base/transport_description.h"
71#include "p2p/base/transport_info.h"
Steve Anton10542f22019-01-11 09:11:00 -080072#include "pc/media_session.h"
73#include "pc/peer_connection.h"
74#include "pc/peer_connection_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080075#include "pc/session_description.h"
Harald Alvestrand39993842021-02-17 09:05:31 +000076#include "pc/test/fake_periodic_video_source.h"
77#include "pc/test/integration_test_helpers.h"
Steve Anton10542f22019-01-11 09:11:00 -080078#include "pc/test/mock_peer_connection_observers.h"
Jonas Olssonb75d9e92019-02-22 10:33:29 +010079#include "rtc_base/fake_clock.h"
Qingsi Wangecd30542019-05-22 14:34:56 -070080#include "rtc_base/fake_mdns_responder.h"
Steve Anton10542f22019-01-11 09:11:00 -080081#include "rtc_base/fake_network.h"
82#include "rtc_base/firewall_socket_server.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020083#include "rtc_base/gunit.h"
Harald Alvestrand39993842021-02-17 09:05:31 +000084#include "rtc_base/helpers.h"
Harald Alvestrand39993842021-02-17 09:05:31 +000085#include "rtc_base/logging.h"
Harald Alvestrand39993842021-02-17 09:05:31 +000086#include "rtc_base/socket_address.h"
87#include "rtc_base/ssl_certificate.h"
88#include "rtc_base/ssl_fingerprint.h"
89#include "rtc_base/ssl_identity.h"
90#include "rtc_base/ssl_stream_adapter.h"
Danil Chapovalov2aaef452022-08-12 15:55:11 +020091#include "rtc_base/task_queue_for_test.h"
Steve Anton10542f22019-01-11 09:11:00 -080092#include "rtc_base/test_certificate_verifier.h"
Harald Alvestrand39993842021-02-17 09:05:31 +000093#include "rtc_base/thread.h"
Steve Anton10542f22019-01-11 09:11:00 -080094#include "rtc_base/time_utils.h"
95#include "rtc_base/virtual_socket_server.h"
Mirko Bonadei17f48782018-09-28 08:51:10 +020096#include "system_wrappers/include/metrics.h"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000097#include "test/gmock.h"
98#include "test/gtest.h"
deadbeef1dcb1642017-03-29 21:08:16 -070099
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +0100100namespace webrtc {
Harald Alvestrand39993842021-02-17 09:05:31 +0000101
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +0100102namespace {
103
Seth Hampson2f0d7022018-02-20 11:54:42 -0800104class PeerConnectionIntegrationTest
105 : public PeerConnectionIntegrationBaseTest,
Evan Shrubsole7619b7c2022-03-01 10:42:44 +0100106 public ::testing::WithParamInterface<
107 std::tuple<SdpSemantics, std::string>> {
Seth Hampson2f0d7022018-02-20 11:54:42 -0800108 protected:
109 PeerConnectionIntegrationTest()
Evan Shrubsole7619b7c2022-03-01 10:42:44 +0100110 : PeerConnectionIntegrationBaseTest(std::get<0>(GetParam()),
111 std::get<1>(GetParam())) {}
Seth Hampson2f0d7022018-02-20 11:54:42 -0800112};
113
Yves Gerey100fe632020-01-17 19:15:53 +0100114// Fake clock must be set before threads are started to prevent race on
115// Set/GetClockForTesting().
116// To achieve that, multiple inheritance is used as a mixin pattern
117// where order of construction is finely controlled.
118// This also ensures peerconnection is closed before switching back to non-fake
119// clock, avoiding other races and DCHECK failures such as in rtp_sender.cc.
120class FakeClockForTest : public rtc::ScopedFakeClock {
121 protected:
122 FakeClockForTest() {
123 // Some things use a time of "0" as a special value, so we need to start out
124 // the fake clock at a nonzero time.
125 // TODO(deadbeef): Fix this.
Danil Chapovalov0c626af2020-02-10 11:16:00 +0100126 AdvanceTime(webrtc::TimeDelta::Seconds(1));
Yves Gerey100fe632020-01-17 19:15:53 +0100127 }
128
129 // Explicit handle.
130 ScopedFakeClock& FakeClock() { return *this; }
131};
132
133// Ensure FakeClockForTest is constructed first (see class for rationale).
134class PeerConnectionIntegrationTestWithFakeClock
135 : public FakeClockForTest,
136 public PeerConnectionIntegrationTest {};
137
Seth Hampson2f0d7022018-02-20 11:54:42 -0800138class PeerConnectionIntegrationTestPlanB
139 : public PeerConnectionIntegrationBaseTest {
140 protected:
141 PeerConnectionIntegrationTestPlanB()
Florent Castelli15a38de2022-04-06 00:38:21 +0200142 : PeerConnectionIntegrationBaseTest(SdpSemantics::kPlanB_DEPRECATED) {}
Seth Hampson2f0d7022018-02-20 11:54:42 -0800143};
144
145class PeerConnectionIntegrationTestUnifiedPlan
146 : public PeerConnectionIntegrationBaseTest {
147 protected:
148 PeerConnectionIntegrationTestUnifiedPlan()
149 : PeerConnectionIntegrationBaseTest(SdpSemantics::kUnifiedPlan) {}
150};
151
deadbeef1dcb1642017-03-29 21:08:16 -0700152// Test the OnFirstPacketReceived callback from audio/video RtpReceivers. This
153// includes testing that the callback is invoked if an observer is connected
154// after the first packet has already been received.
Seth Hampson2f0d7022018-02-20 11:54:42 -0800155TEST_P(PeerConnectionIntegrationTest,
deadbeef1dcb1642017-03-29 21:08:16 -0700156 RtpReceiverObserverOnFirstPacketReceived) {
157 ASSERT_TRUE(CreatePeerConnectionWrappers());
158 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -0800159 caller()->AddAudioVideoTracks();
160 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -0700161 // Start offer/answer exchange and wait for it to complete.
162 caller()->CreateAndSetAndSignalOffer();
163 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
164 // Should be one receiver each for audio/video.
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +0200165 EXPECT_EQ(2U, caller()->rtp_receiver_observers().size());
166 EXPECT_EQ(2U, callee()->rtp_receiver_observers().size());
deadbeef1dcb1642017-03-29 21:08:16 -0700167 // Wait for all "first packet received" callbacks to be fired.
168 EXPECT_TRUE_WAIT(
Steve Anton64b626b2019-01-28 17:25:26 -0800169 absl::c_all_of(caller()->rtp_receiver_observers(),
170 [](const std::unique_ptr<MockRtpReceiverObserver>& o) {
171 return o->first_packet_received();
172 }),
deadbeef1dcb1642017-03-29 21:08:16 -0700173 kMaxWaitForFramesMs);
174 EXPECT_TRUE_WAIT(
Steve Anton64b626b2019-01-28 17:25:26 -0800175 absl::c_all_of(callee()->rtp_receiver_observers(),
176 [](const std::unique_ptr<MockRtpReceiverObserver>& o) {
177 return o->first_packet_received();
178 }),
deadbeef1dcb1642017-03-29 21:08:16 -0700179 kMaxWaitForFramesMs);
180 // If new observers are set after the first packet was already received, the
181 // callback should still be invoked.
182 caller()->ResetRtpReceiverObservers();
183 callee()->ResetRtpReceiverObservers();
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +0200184 EXPECT_EQ(2U, caller()->rtp_receiver_observers().size());
185 EXPECT_EQ(2U, callee()->rtp_receiver_observers().size());
deadbeef1dcb1642017-03-29 21:08:16 -0700186 EXPECT_TRUE(
Steve Anton64b626b2019-01-28 17:25:26 -0800187 absl::c_all_of(caller()->rtp_receiver_observers(),
188 [](const std::unique_ptr<MockRtpReceiverObserver>& o) {
189 return o->first_packet_received();
190 }));
deadbeef1dcb1642017-03-29 21:08:16 -0700191 EXPECT_TRUE(
Steve Anton64b626b2019-01-28 17:25:26 -0800192 absl::c_all_of(callee()->rtp_receiver_observers(),
193 [](const std::unique_ptr<MockRtpReceiverObserver>& o) {
194 return o->first_packet_received();
195 }));
deadbeef1dcb1642017-03-29 21:08:16 -0700196}
197
198class DummyDtmfObserver : public DtmfSenderObserverInterface {
199 public:
200 DummyDtmfObserver() : completed_(false) {}
201
202 // Implements DtmfSenderObserverInterface.
203 void OnToneChange(const std::string& tone) override {
204 tones_.push_back(tone);
205 if (tone.empty()) {
206 completed_ = true;
207 }
208 }
209
210 const std::vector<std::string>& tones() const { return tones_; }
211 bool completed() const { return completed_; }
212
213 private:
214 bool completed_;
215 std::vector<std::string> tones_;
216};
217
Artem Titov880fa812021-07-30 22:30:23 +0200218// Assumes `sender` already has an audio track added and the offer/answer
deadbeef1dcb1642017-03-29 21:08:16 -0700219// exchange is done.
Harald Alvestrand39993842021-02-17 09:05:31 +0000220void TestDtmfFromSenderToReceiver(PeerConnectionIntegrationWrapper* sender,
221 PeerConnectionIntegrationWrapper* receiver) {
Steve Anton15324772018-01-16 10:26:49 -0800222 // We should be able to get a DTMF sender from the local sender.
223 rtc::scoped_refptr<DtmfSenderInterface> dtmf_sender =
224 sender->pc()->GetSenders().at(0)->GetDtmfSender();
225 ASSERT_TRUE(dtmf_sender);
deadbeef1dcb1642017-03-29 21:08:16 -0700226 DummyDtmfObserver observer;
deadbeef1dcb1642017-03-29 21:08:16 -0700227 dtmf_sender->RegisterObserver(&observer);
228
229 // Test the DtmfSender object just created.
230 EXPECT_TRUE(dtmf_sender->CanInsertDtmf());
231 EXPECT_TRUE(dtmf_sender->InsertDtmf("1a", 100, 50));
232
233 EXPECT_TRUE_WAIT(observer.completed(), kDefaultTimeout);
234 std::vector<std::string> tones = {"1", "a", ""};
235 EXPECT_EQ(tones, observer.tones());
236 dtmf_sender->UnregisterObserver();
237 // TODO(deadbeef): Verify the tones were actually received end-to-end.
238}
239
240// Verifies the DtmfSenderObserver callbacks for a DtmfSender (one in each
241// direction).
Seth Hampson2f0d7022018-02-20 11:54:42 -0800242TEST_P(PeerConnectionIntegrationTest, DtmfSenderObserver) {
deadbeef1dcb1642017-03-29 21:08:16 -0700243 ASSERT_TRUE(CreatePeerConnectionWrappers());
244 ConnectFakeSignaling();
245 // Only need audio for DTMF.
Steve Anton15324772018-01-16 10:26:49 -0800246 caller()->AddAudioTrack();
247 callee()->AddAudioTrack();
deadbeef1dcb1642017-03-29 21:08:16 -0700248 caller()->CreateAndSetAndSignalOffer();
249 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
deadbeef71452802017-05-07 17:21:01 -0700250 // DTLS must finish before the DTMF sender can be used reliably.
251 ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700252 TestDtmfFromSenderToReceiver(caller(), callee());
253 TestDtmfFromSenderToReceiver(callee(), caller());
254}
255
256// Basic end-to-end test, verifying media can be encoded/transmitted/decoded
257// between two connections, using DTLS-SRTP.
Seth Hampson2f0d7022018-02-20 11:54:42 -0800258TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithDtls) {
deadbeef1dcb1642017-03-29 21:08:16 -0700259 ASSERT_TRUE(CreatePeerConnectionWrappers());
260 ConnectFakeSignaling();
Harald Alvestrand194939b2018-01-24 16:04:13 +0100261
deadbeef1dcb1642017-03-29 21:08:16 -0700262 // Do normal offer/answer and wait for some frames to be received in each
263 // direction.
Steve Anton15324772018-01-16 10:26:49 -0800264 caller()->AddAudioVideoTracks();
265 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -0700266 caller()->CreateAndSetAndSignalOffer();
267 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -0800268 MediaExpectations media_expectations;
269 media_expectations.ExpectBidirectionalAudioAndVideo();
270 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -0700271}
272
Harald Alvestrandca327932022-04-04 15:37:31 +0000273#if defined(WEBRTC_FUCHSIA)
Harald Alvestrand50b95522021-11-18 10:01:06 +0000274// Uses SDES instead of DTLS for key agreement.
275TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithSdes) {
276 PeerConnectionInterface::RTCConfiguration sdes_config;
277 sdes_config.enable_dtls_srtp.emplace(false);
278 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(sdes_config, sdes_config));
279 ConnectFakeSignaling();
280
281 // Do normal offer/answer and wait for some frames to be received in each
282 // direction.
283 caller()->AddAudioVideoTracks();
284 callee()->AddAudioVideoTracks();
285 caller()->CreateAndSetAndSignalOffer();
286 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
287 MediaExpectations media_expectations;
288 media_expectations.ExpectBidirectionalAudioAndVideo();
289 ASSERT_TRUE(ExpectNewFrames(media_expectations));
Harald Alvestrand50b95522021-11-18 10:01:06 +0000290}
Harald Alvestrandca327932022-04-04 15:37:31 +0000291#endif
Harald Alvestrand50b95522021-11-18 10:01:06 +0000292
Artem Titov880fa812021-07-30 22:30:23 +0200293// Basic end-to-end test specifying the `enable_encrypted_rtp_header_extensions`
Steve Anton9a44b2d2019-07-12 12:58:30 -0700294// option to offer encrypted versions of all header extensions alongside the
295// unencrypted versions.
296TEST_P(PeerConnectionIntegrationTest,
297 EndToEndCallWithEncryptedRtpHeaderExtensions) {
298 CryptoOptions crypto_options;
299 crypto_options.srtp.enable_encrypted_rtp_header_extensions = true;
300 PeerConnectionInterface::RTCConfiguration config;
301 config.crypto_options = crypto_options;
302 // Note: This allows offering >14 RTP header extensions.
303 config.offer_extmap_allow_mixed = true;
304 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config));
305 ConnectFakeSignaling();
306
307 // Do normal offer/answer and wait for some frames to be received in each
308 // direction.
309 caller()->AddAudioVideoTracks();
310 callee()->AddAudioVideoTracks();
311 caller()->CreateAndSetAndSignalOffer();
312 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
313 MediaExpectations media_expectations;
314 media_expectations.ExpectBidirectionalAudioAndVideo();
315 ASSERT_TRUE(ExpectNewFrames(media_expectations));
316}
317
deadbeef1dcb1642017-03-29 21:08:16 -0700318// This test sets up a call between two parties with a source resolution of
319// 1280x720 and verifies that a 16:9 aspect ratio is received.
Seth Hampson2f0d7022018-02-20 11:54:42 -0800320TEST_P(PeerConnectionIntegrationTest,
deadbeef1dcb1642017-03-29 21:08:16 -0700321 Send1280By720ResolutionAndReceive16To9AspectRatio) {
322 ASSERT_TRUE(CreatePeerConnectionWrappers());
323 ConnectFakeSignaling();
324
Niels Möller5c7efe72018-05-11 10:34:46 +0200325 // Add video tracks with 16:9 aspect ratio, size 1280 x 720.
326 webrtc::FakePeriodicVideoSource::Config config;
327 config.width = 1280;
328 config.height = 720;
Johannes Kron965e7942018-09-13 15:36:20 +0200329 config.timestamp_offset_ms = rtc::TimeMillis();
Niels Möller5c7efe72018-05-11 10:34:46 +0200330 caller()->AddTrack(caller()->CreateLocalVideoTrackWithConfig(config));
331 callee()->AddTrack(callee()->CreateLocalVideoTrackWithConfig(config));
deadbeef1dcb1642017-03-29 21:08:16 -0700332
333 // Do normal offer/answer and wait for at least one frame to be received in
334 // each direction.
335 caller()->CreateAndSetAndSignalOffer();
336 ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 &&
337 callee()->min_video_frames_received_per_track() > 0,
338 kMaxWaitForFramesMs);
339
340 // Check rendered aspect ratio.
341 EXPECT_EQ(16.0 / 9, caller()->local_rendered_aspect_ratio());
342 EXPECT_EQ(16.0 / 9, caller()->rendered_aspect_ratio());
343 EXPECT_EQ(16.0 / 9, callee()->local_rendered_aspect_ratio());
344 EXPECT_EQ(16.0 / 9, callee()->rendered_aspect_ratio());
345}
346
347// This test sets up an one-way call, with media only from caller to
348// callee.
Seth Hampson2f0d7022018-02-20 11:54:42 -0800349TEST_P(PeerConnectionIntegrationTest, OneWayMediaCall) {
deadbeef1dcb1642017-03-29 21:08:16 -0700350 ASSERT_TRUE(CreatePeerConnectionWrappers());
351 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -0800352 caller()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -0700353 caller()->CreateAndSetAndSignalOffer();
Seth Hampson2f0d7022018-02-20 11:54:42 -0800354 MediaExpectations media_expectations;
355 media_expectations.CalleeExpectsSomeAudioAndVideo();
356 media_expectations.CallerExpectsNoAudio();
357 media_expectations.CallerExpectsNoVideo();
358 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -0700359}
360
Johannes Kron3e983682020-03-29 22:17:00 +0200361// Tests that send only works without the caller having a decoder factory and
362// the callee having an encoder factory.
363TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithSendOnlyVideo) {
364 ASSERT_TRUE(
365 CreateOneDirectionalPeerConnectionWrappers(/*caller_to_callee=*/true));
366 ConnectFakeSignaling();
367 // Add one-directional video, from caller to callee.
368 rtc::scoped_refptr<webrtc::VideoTrackInterface> caller_track =
369 caller()->CreateLocalVideoTrack();
370 caller()->AddTrack(caller_track);
371 PeerConnectionInterface::RTCOfferAnswerOptions options;
372 options.offer_to_receive_video = 0;
373 caller()->SetOfferAnswerOptions(options);
374 caller()->CreateAndSetAndSignalOffer();
375 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
376 ASSERT_EQ(callee()->pc()->GetReceivers().size(), 1u);
377
378 // Expect video to be received in one direction.
379 MediaExpectations media_expectations;
380 media_expectations.CallerExpectsNoVideo();
381 media_expectations.CalleeExpectsSomeVideo();
382
383 EXPECT_TRUE(ExpectNewFrames(media_expectations));
384}
385
386// Tests that receive only works without the caller having an encoder factory
387// and the callee having a decoder factory.
388TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithReceiveOnlyVideo) {
389 ASSERT_TRUE(
390 CreateOneDirectionalPeerConnectionWrappers(/*caller_to_callee=*/false));
391 ConnectFakeSignaling();
392 // Add one-directional video, from callee to caller.
393 rtc::scoped_refptr<webrtc::VideoTrackInterface> callee_track =
394 callee()->CreateLocalVideoTrack();
395 callee()->AddTrack(callee_track);
396 PeerConnectionInterface::RTCOfferAnswerOptions options;
397 options.offer_to_receive_video = 1;
398 caller()->SetOfferAnswerOptions(options);
399 caller()->CreateAndSetAndSignalOffer();
400 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
401 ASSERT_EQ(caller()->pc()->GetReceivers().size(), 1u);
402
403 // Expect video to be received in one direction.
404 MediaExpectations media_expectations;
405 media_expectations.CallerExpectsSomeVideo();
406 media_expectations.CalleeExpectsNoVideo();
407
408 EXPECT_TRUE(ExpectNewFrames(media_expectations));
409}
410
411TEST_P(PeerConnectionIntegrationTest,
412 EndToEndCallAddReceiveVideoToSendOnlyCall) {
413 ASSERT_TRUE(CreatePeerConnectionWrappers());
414 ConnectFakeSignaling();
415 // Add one-directional video, from caller to callee.
416 rtc::scoped_refptr<webrtc::VideoTrackInterface> caller_track =
417 caller()->CreateLocalVideoTrack();
418 caller()->AddTrack(caller_track);
419 caller()->CreateAndSetAndSignalOffer();
420 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
421
422 // Add receive video.
423 rtc::scoped_refptr<webrtc::VideoTrackInterface> callee_track =
424 callee()->CreateLocalVideoTrack();
425 callee()->AddTrack(callee_track);
426 caller()->CreateAndSetAndSignalOffer();
427 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
428
429 // Ensure that video frames are received end-to-end.
430 MediaExpectations media_expectations;
431 media_expectations.ExpectBidirectionalVideo();
432 ASSERT_TRUE(ExpectNewFrames(media_expectations));
433}
434
435TEST_P(PeerConnectionIntegrationTest,
436 EndToEndCallAddSendVideoToReceiveOnlyCall) {
437 ASSERT_TRUE(CreatePeerConnectionWrappers());
438 ConnectFakeSignaling();
439 // Add one-directional video, from callee to caller.
440 rtc::scoped_refptr<webrtc::VideoTrackInterface> callee_track =
441 callee()->CreateLocalVideoTrack();
442 callee()->AddTrack(callee_track);
443 caller()->CreateAndSetAndSignalOffer();
444 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
445
446 // Add send video.
447 rtc::scoped_refptr<webrtc::VideoTrackInterface> caller_track =
448 caller()->CreateLocalVideoTrack();
449 caller()->AddTrack(caller_track);
450 caller()->CreateAndSetAndSignalOffer();
451 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
452
453 // Expect video to be received in one direction.
454 MediaExpectations media_expectations;
455 media_expectations.ExpectBidirectionalVideo();
456 ASSERT_TRUE(ExpectNewFrames(media_expectations));
457}
458
459TEST_P(PeerConnectionIntegrationTest,
460 EndToEndCallRemoveReceiveVideoFromSendReceiveCall) {
461 ASSERT_TRUE(CreatePeerConnectionWrappers());
462 ConnectFakeSignaling();
463 // Add send video, from caller to callee.
464 rtc::scoped_refptr<webrtc::VideoTrackInterface> caller_track =
465 caller()->CreateLocalVideoTrack();
466 rtc::scoped_refptr<webrtc::RtpSenderInterface> caller_sender =
467 caller()->AddTrack(caller_track);
468 // Add receive video, from callee to caller.
469 rtc::scoped_refptr<webrtc::VideoTrackInterface> callee_track =
470 callee()->CreateLocalVideoTrack();
471
472 rtc::scoped_refptr<webrtc::RtpSenderInterface> callee_sender =
473 callee()->AddTrack(callee_track);
474 caller()->CreateAndSetAndSignalOffer();
475 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
476
477 // Remove receive video (i.e., callee sender track).
Harald Alvestrand93dd7632022-01-19 12:28:45 +0000478 callee()->pc()->RemoveTrackOrError(callee_sender);
Johannes Kron3e983682020-03-29 22:17:00 +0200479
480 caller()->CreateAndSetAndSignalOffer();
481 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
482
483 // Expect one-directional video.
484 MediaExpectations media_expectations;
485 media_expectations.CallerExpectsNoVideo();
486 media_expectations.CalleeExpectsSomeVideo();
487
488 ASSERT_TRUE(ExpectNewFrames(media_expectations));
489}
490
491TEST_P(PeerConnectionIntegrationTest,
492 EndToEndCallRemoveSendVideoFromSendReceiveCall) {
493 ASSERT_TRUE(CreatePeerConnectionWrappers());
494 ConnectFakeSignaling();
495 // Add send video, from caller to callee.
496 rtc::scoped_refptr<webrtc::VideoTrackInterface> caller_track =
497 caller()->CreateLocalVideoTrack();
498 rtc::scoped_refptr<webrtc::RtpSenderInterface> caller_sender =
499 caller()->AddTrack(caller_track);
500 // Add receive video, from callee to caller.
501 rtc::scoped_refptr<webrtc::VideoTrackInterface> callee_track =
502 callee()->CreateLocalVideoTrack();
503
504 rtc::scoped_refptr<webrtc::RtpSenderInterface> callee_sender =
505 callee()->AddTrack(callee_track);
506 caller()->CreateAndSetAndSignalOffer();
507 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
508
509 // Remove send video (i.e., caller sender track).
Harald Alvestrand93dd7632022-01-19 12:28:45 +0000510 caller()->pc()->RemoveTrackOrError(caller_sender);
Johannes Kron3e983682020-03-29 22:17:00 +0200511
512 caller()->CreateAndSetAndSignalOffer();
513 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
514
515 // Expect one-directional video.
516 MediaExpectations media_expectations;
517 media_expectations.CalleeExpectsNoVideo();
518 media_expectations.CallerExpectsSomeVideo();
519
520 ASSERT_TRUE(ExpectNewFrames(media_expectations));
521}
522
deadbeef1dcb1642017-03-29 21:08:16 -0700523// This test sets up a audio call initially, with the callee rejecting video
524// initially. Then later the callee decides to upgrade to audio/video, and
525// initiates a new offer/answer exchange.
Seth Hampson2f0d7022018-02-20 11:54:42 -0800526TEST_P(PeerConnectionIntegrationTest, AudioToVideoUpgrade) {
deadbeef1dcb1642017-03-29 21:08:16 -0700527 ASSERT_TRUE(CreatePeerConnectionWrappers());
528 ConnectFakeSignaling();
529 // Initially, offer an audio/video stream from the caller, but refuse to
530 // send/receive video on the callee side.
Steve Anton15324772018-01-16 10:26:49 -0800531 caller()->AddAudioVideoTracks();
532 callee()->AddAudioTrack();
Florent Castelli15a38de2022-04-06 00:38:21 +0200533 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Seth Hampson2f0d7022018-02-20 11:54:42 -0800534 PeerConnectionInterface::RTCOfferAnswerOptions options;
535 options.offer_to_receive_video = 0;
536 callee()->SetOfferAnswerOptions(options);
537 } else {
538 callee()->SetRemoteOfferHandler([this] {
Harald Alvestrand6060df52020-08-11 09:54:02 +0200539 callee()
540 ->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)
541 ->StopInternal();
Seth Hampson2f0d7022018-02-20 11:54:42 -0800542 });
543 }
deadbeef1dcb1642017-03-29 21:08:16 -0700544 // Do offer/answer and make sure audio is still received end-to-end.
545 caller()->CreateAndSetAndSignalOffer();
546 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -0800547 {
548 MediaExpectations media_expectations;
549 media_expectations.ExpectBidirectionalAudio();
550 media_expectations.ExpectNoVideo();
551 ASSERT_TRUE(ExpectNewFrames(media_expectations));
552 }
deadbeef1dcb1642017-03-29 21:08:16 -0700553 // Sanity check that the callee's description has a rejected video section.
554 ASSERT_NE(nullptr, callee()->pc()->local_description());
555 const ContentInfo* callee_video_content =
556 GetFirstVideoContent(callee()->pc()->local_description()->description());
557 ASSERT_NE(nullptr, callee_video_content);
558 EXPECT_TRUE(callee_video_content->rejected);
Seth Hampson2f0d7022018-02-20 11:54:42 -0800559
deadbeef1dcb1642017-03-29 21:08:16 -0700560 // Now negotiate with video and ensure negotiation succeeds, with video
561 // frames and additional audio frames being received.
Steve Anton15324772018-01-16 10:26:49 -0800562 callee()->AddVideoTrack();
Florent Castelli15a38de2022-04-06 00:38:21 +0200563 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Seth Hampson2f0d7022018-02-20 11:54:42 -0800564 PeerConnectionInterface::RTCOfferAnswerOptions options;
565 options.offer_to_receive_video = 1;
566 callee()->SetOfferAnswerOptions(options);
567 } else {
568 callee()->SetRemoteOfferHandler(nullptr);
569 caller()->SetRemoteOfferHandler([this] {
570 // The caller creates a new transceiver to receive video on when receiving
571 // the offer, but by default it is send only.
572 auto transceivers = caller()->pc()->GetTransceivers();
Harald Alvestrand6060df52020-08-11 09:54:02 +0200573 ASSERT_EQ(2U, transceivers.size());
Seth Hampson2f0d7022018-02-20 11:54:42 -0800574 ASSERT_EQ(cricket::MEDIA_TYPE_VIDEO,
Harald Alvestrand6060df52020-08-11 09:54:02 +0200575 transceivers[1]->receiver()->media_type());
Niels Möllerafb246b2022-04-20 14:26:50 +0200576 transceivers[1]->sender()->SetTrack(
577 caller()->CreateLocalVideoTrack().get());
Harald Alvestrand6060df52020-08-11 09:54:02 +0200578 transceivers[1]->SetDirectionWithError(
579 RtpTransceiverDirection::kSendRecv);
Seth Hampson2f0d7022018-02-20 11:54:42 -0800580 });
581 }
deadbeef1dcb1642017-03-29 21:08:16 -0700582 callee()->CreateAndSetAndSignalOffer();
583 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -0800584 {
585 // Expect additional audio frames to be received after the upgrade.
586 MediaExpectations media_expectations;
587 media_expectations.ExpectBidirectionalAudioAndVideo();
588 ASSERT_TRUE(ExpectNewFrames(media_expectations));
589 }
deadbeef1dcb1642017-03-29 21:08:16 -0700590}
591
deadbeef4389b4d2017-09-07 09:07:36 -0700592// Simpler than the above test; just add an audio track to an established
593// video-only connection.
Seth Hampson2f0d7022018-02-20 11:54:42 -0800594TEST_P(PeerConnectionIntegrationTest, AddAudioToVideoOnlyCall) {
deadbeef4389b4d2017-09-07 09:07:36 -0700595 ASSERT_TRUE(CreatePeerConnectionWrappers());
596 ConnectFakeSignaling();
597 // Do initial offer/answer with just a video track.
Steve Anton15324772018-01-16 10:26:49 -0800598 caller()->AddVideoTrack();
599 callee()->AddVideoTrack();
deadbeef4389b4d2017-09-07 09:07:36 -0700600 caller()->CreateAndSetAndSignalOffer();
601 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
602 // Now add an audio track and do another offer/answer.
Steve Anton15324772018-01-16 10:26:49 -0800603 caller()->AddAudioTrack();
604 callee()->AddAudioTrack();
deadbeef4389b4d2017-09-07 09:07:36 -0700605 caller()->CreateAndSetAndSignalOffer();
606 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
607 // Ensure both audio and video frames are received end-to-end.
Seth Hampson2f0d7022018-02-20 11:54:42 -0800608 MediaExpectations media_expectations;
609 media_expectations.ExpectBidirectionalAudioAndVideo();
610 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef4389b4d2017-09-07 09:07:36 -0700611}
612
deadbeef1dcb1642017-03-29 21:08:16 -0700613// This test sets up a non-bundled call and negotiates bundling at the same
614// time as starting an ICE restart. When bundling is in effect in the restart,
615// the DTLS-SRTP context should be successfully reset.
Seth Hampson2f0d7022018-02-20 11:54:42 -0800616TEST_P(PeerConnectionIntegrationTest, BundlingEnabledWhileIceRestartOccurs) {
deadbeef1dcb1642017-03-29 21:08:16 -0700617 ASSERT_TRUE(CreatePeerConnectionWrappers());
618 ConnectFakeSignaling();
619
Steve Anton15324772018-01-16 10:26:49 -0800620 caller()->AddAudioVideoTracks();
621 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -0700622 // Remove the bundle group from the SDP received by the callee.
623 callee()->SetReceivedSdpMunger([](cricket::SessionDescription* desc) {
624 desc->RemoveGroupByName("BUNDLE");
625 });
626 caller()->CreateAndSetAndSignalOffer();
627 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -0800628 {
629 MediaExpectations media_expectations;
630 media_expectations.ExpectBidirectionalAudioAndVideo();
631 ASSERT_TRUE(ExpectNewFrames(media_expectations));
632 }
deadbeef1dcb1642017-03-29 21:08:16 -0700633 // Now stop removing the BUNDLE group, and trigger an ICE restart.
634 callee()->SetReceivedSdpMunger(nullptr);
635 caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions());
636 caller()->CreateAndSetAndSignalOffer();
637 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
638
639 // Expect additional frames to be received after the ICE restart.
Seth Hampson2f0d7022018-02-20 11:54:42 -0800640 {
641 MediaExpectations media_expectations;
642 media_expectations.ExpectBidirectionalAudioAndVideo();
643 ASSERT_TRUE(ExpectNewFrames(media_expectations));
644 }
deadbeef1dcb1642017-03-29 21:08:16 -0700645}
646
647// Test CVO (Coordination of Video Orientation). If a video source is rotated
648// and both peers support the CVO RTP header extension, the actual video frames
649// don't need to be encoded in different resolutions, since the rotation is
650// communicated through the RTP header extension.
Seth Hampson2f0d7022018-02-20 11:54:42 -0800651TEST_P(PeerConnectionIntegrationTest, RotatedVideoWithCVOExtension) {
deadbeef1dcb1642017-03-29 21:08:16 -0700652 ASSERT_TRUE(CreatePeerConnectionWrappers());
653 ConnectFakeSignaling();
654 // Add rotated video tracks.
Steve Anton15324772018-01-16 10:26:49 -0800655 caller()->AddTrack(
deadbeef1dcb1642017-03-29 21:08:16 -0700656 caller()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_90));
Steve Anton15324772018-01-16 10:26:49 -0800657 callee()->AddTrack(
deadbeef1dcb1642017-03-29 21:08:16 -0700658 callee()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_270));
659
660 // Wait for video frames to be received by both sides.
661 caller()->CreateAndSetAndSignalOffer();
662 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
663 ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 &&
664 callee()->min_video_frames_received_per_track() > 0,
665 kMaxWaitForFramesMs);
666
667 // Ensure that the aspect ratio is unmodified.
668 // TODO(deadbeef): Where does 4:3 come from? Should be explicit in the test,
669 // not just assumed.
670 EXPECT_EQ(4.0 / 3, caller()->local_rendered_aspect_ratio());
671 EXPECT_EQ(4.0 / 3, caller()->rendered_aspect_ratio());
672 EXPECT_EQ(4.0 / 3, callee()->local_rendered_aspect_ratio());
673 EXPECT_EQ(4.0 / 3, callee()->rendered_aspect_ratio());
674 // Ensure that the CVO bits were surfaced to the renderer.
675 EXPECT_EQ(webrtc::kVideoRotation_270, caller()->rendered_rotation());
676 EXPECT_EQ(webrtc::kVideoRotation_90, callee()->rendered_rotation());
677}
678
679// Test that when the CVO extension isn't supported, video is rotated the
680// old-fashioned way, by encoding rotated frames.
Seth Hampson2f0d7022018-02-20 11:54:42 -0800681TEST_P(PeerConnectionIntegrationTest, RotatedVideoWithoutCVOExtension) {
deadbeef1dcb1642017-03-29 21:08:16 -0700682 ASSERT_TRUE(CreatePeerConnectionWrappers());
683 ConnectFakeSignaling();
684 // Add rotated video tracks.
Steve Anton15324772018-01-16 10:26:49 -0800685 caller()->AddTrack(
deadbeef1dcb1642017-03-29 21:08:16 -0700686 caller()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_90));
Steve Anton15324772018-01-16 10:26:49 -0800687 callee()->AddTrack(
deadbeef1dcb1642017-03-29 21:08:16 -0700688 callee()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_270));
689
690 // Remove the CVO extension from the offered SDP.
691 callee()->SetReceivedSdpMunger([](cricket::SessionDescription* desc) {
692 cricket::VideoContentDescription* video =
693 GetFirstVideoContentDescription(desc);
694 video->ClearRtpHeaderExtensions();
695 });
696 // Wait for video frames to be received by both sides.
697 caller()->CreateAndSetAndSignalOffer();
698 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
699 ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 &&
700 callee()->min_video_frames_received_per_track() > 0,
701 kMaxWaitForFramesMs);
702
703 // Expect that the aspect ratio is inversed to account for the 90/270 degree
704 // rotation.
705 // TODO(deadbeef): Where does 4:3 come from? Should be explicit in the test,
706 // not just assumed.
707 EXPECT_EQ(3.0 / 4, caller()->local_rendered_aspect_ratio());
708 EXPECT_EQ(3.0 / 4, caller()->rendered_aspect_ratio());
709 EXPECT_EQ(3.0 / 4, callee()->local_rendered_aspect_ratio());
710 EXPECT_EQ(3.0 / 4, callee()->rendered_aspect_ratio());
711 // Expect that each endpoint is unaware of the rotation of the other endpoint.
712 EXPECT_EQ(webrtc::kVideoRotation_0, caller()->rendered_rotation());
713 EXPECT_EQ(webrtc::kVideoRotation_0, callee()->rendered_rotation());
714}
715
deadbeef1dcb1642017-03-29 21:08:16 -0700716// Test that if the answerer rejects the audio m= section, no audio is sent or
717// received, but video still can be.
Seth Hampson2f0d7022018-02-20 11:54:42 -0800718TEST_P(PeerConnectionIntegrationTest, AnswererRejectsAudioSection) {
deadbeef1dcb1642017-03-29 21:08:16 -0700719 ASSERT_TRUE(CreatePeerConnectionWrappers());
720 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -0800721 caller()->AddAudioVideoTracks();
Florent Castelli15a38de2022-04-06 00:38:21 +0200722 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Seth Hampson2f0d7022018-02-20 11:54:42 -0800723 // Only add video track for callee, and set offer_to_receive_audio to 0, so
724 // it will reject the audio m= section completely.
725 PeerConnectionInterface::RTCOfferAnswerOptions options;
726 options.offer_to_receive_audio = 0;
727 callee()->SetOfferAnswerOptions(options);
728 } else {
729 // Stopping the audio RtpTransceiver will cause the media section to be
730 // rejected in the answer.
731 callee()->SetRemoteOfferHandler([this] {
Harald Alvestrand6060df52020-08-11 09:54:02 +0200732 callee()
733 ->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_AUDIO)
734 ->StopInternal();
Seth Hampson2f0d7022018-02-20 11:54:42 -0800735 });
736 }
Steve Anton15324772018-01-16 10:26:49 -0800737 callee()->AddTrack(callee()->CreateLocalVideoTrack());
deadbeef1dcb1642017-03-29 21:08:16 -0700738 // Do offer/answer and wait for successful end-to-end video frames.
739 caller()->CreateAndSetAndSignalOffer();
740 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -0800741 MediaExpectations media_expectations;
742 media_expectations.ExpectBidirectionalVideo();
743 media_expectations.ExpectNoAudio();
744 ASSERT_TRUE(ExpectNewFrames(media_expectations));
745
deadbeef1dcb1642017-03-29 21:08:16 -0700746 // Sanity check that the callee's description has a rejected audio section.
747 ASSERT_NE(nullptr, callee()->pc()->local_description());
748 const ContentInfo* callee_audio_content =
749 GetFirstAudioContent(callee()->pc()->local_description()->description());
750 ASSERT_NE(nullptr, callee_audio_content);
751 EXPECT_TRUE(callee_audio_content->rejected);
Seth Hampson2f0d7022018-02-20 11:54:42 -0800752 if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) {
Harald Alvestrand6060df52020-08-11 09:54:02 +0200753 // The caller's transceiver should have stopped after receiving the answer,
754 // and thus no longer listed in transceivers.
755 EXPECT_EQ(nullptr,
756 caller()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_AUDIO));
Seth Hampson2f0d7022018-02-20 11:54:42 -0800757 }
deadbeef1dcb1642017-03-29 21:08:16 -0700758}
759
760// Test that if the answerer rejects the video m= section, no video is sent or
761// received, but audio still can be.
Seth Hampson2f0d7022018-02-20 11:54:42 -0800762TEST_P(PeerConnectionIntegrationTest, AnswererRejectsVideoSection) {
deadbeef1dcb1642017-03-29 21:08:16 -0700763 ASSERT_TRUE(CreatePeerConnectionWrappers());
764 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -0800765 caller()->AddAudioVideoTracks();
Florent Castelli15a38de2022-04-06 00:38:21 +0200766 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Seth Hampson2f0d7022018-02-20 11:54:42 -0800767 // Only add audio track for callee, and set offer_to_receive_video to 0, so
768 // it will reject the video m= section completely.
769 PeerConnectionInterface::RTCOfferAnswerOptions options;
770 options.offer_to_receive_video = 0;
771 callee()->SetOfferAnswerOptions(options);
772 } else {
773 // Stopping the video RtpTransceiver will cause the media section to be
774 // rejected in the answer.
775 callee()->SetRemoteOfferHandler([this] {
Harald Alvestrand6060df52020-08-11 09:54:02 +0200776 callee()
777 ->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)
778 ->StopInternal();
Seth Hampson2f0d7022018-02-20 11:54:42 -0800779 });
780 }
Steve Anton15324772018-01-16 10:26:49 -0800781 callee()->AddTrack(callee()->CreateLocalAudioTrack());
deadbeef1dcb1642017-03-29 21:08:16 -0700782 // Do offer/answer and wait for successful end-to-end audio frames.
783 caller()->CreateAndSetAndSignalOffer();
784 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -0800785 MediaExpectations media_expectations;
786 media_expectations.ExpectBidirectionalAudio();
787 media_expectations.ExpectNoVideo();
788 ASSERT_TRUE(ExpectNewFrames(media_expectations));
789
deadbeef1dcb1642017-03-29 21:08:16 -0700790 // Sanity check that the callee's description has a rejected video section.
791 ASSERT_NE(nullptr, callee()->pc()->local_description());
792 const ContentInfo* callee_video_content =
793 GetFirstVideoContent(callee()->pc()->local_description()->description());
794 ASSERT_NE(nullptr, callee_video_content);
795 EXPECT_TRUE(callee_video_content->rejected);
Seth Hampson2f0d7022018-02-20 11:54:42 -0800796 if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) {
Harald Alvestrand6060df52020-08-11 09:54:02 +0200797 // The caller's transceiver should have stopped after receiving the answer,
798 // and thus is no longer present.
799 EXPECT_EQ(nullptr,
800 caller()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO));
Seth Hampson2f0d7022018-02-20 11:54:42 -0800801 }
deadbeef1dcb1642017-03-29 21:08:16 -0700802}
803
804// Test that if the answerer rejects both audio and video m= sections, nothing
805// bad happens.
806// TODO(deadbeef): Test that a data channel still works. Currently this doesn't
807// test anything but the fact that negotiation succeeds, which doesn't mean
808// much.
Seth Hampson2f0d7022018-02-20 11:54:42 -0800809TEST_P(PeerConnectionIntegrationTest, AnswererRejectsAudioAndVideoSections) {
deadbeef1dcb1642017-03-29 21:08:16 -0700810 ASSERT_TRUE(CreatePeerConnectionWrappers());
811 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -0800812 caller()->AddAudioVideoTracks();
Florent Castelli15a38de2022-04-06 00:38:21 +0200813 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Seth Hampson2f0d7022018-02-20 11:54:42 -0800814 // Don't give the callee any tracks, and set offer_to_receive_X to 0, so it
815 // will reject both audio and video m= sections.
816 PeerConnectionInterface::RTCOfferAnswerOptions options;
817 options.offer_to_receive_audio = 0;
818 options.offer_to_receive_video = 0;
819 callee()->SetOfferAnswerOptions(options);
820 } else {
821 callee()->SetRemoteOfferHandler([this] {
822 // Stopping all transceivers will cause all media sections to be rejected.
Mirko Bonadei739baf02019-01-27 17:29:42 +0100823 for (const auto& transceiver : callee()->pc()->GetTransceivers()) {
Harald Alvestrand6060df52020-08-11 09:54:02 +0200824 transceiver->StopInternal();
Seth Hampson2f0d7022018-02-20 11:54:42 -0800825 }
826 });
827 }
deadbeef1dcb1642017-03-29 21:08:16 -0700828 // Do offer/answer and wait for stable signaling state.
829 caller()->CreateAndSetAndSignalOffer();
830 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -0800831
deadbeef1dcb1642017-03-29 21:08:16 -0700832 // Sanity check that the callee's description has rejected m= sections.
833 ASSERT_NE(nullptr, callee()->pc()->local_description());
834 const ContentInfo* callee_audio_content =
835 GetFirstAudioContent(callee()->pc()->local_description()->description());
836 ASSERT_NE(nullptr, callee_audio_content);
837 EXPECT_TRUE(callee_audio_content->rejected);
838 const ContentInfo* callee_video_content =
839 GetFirstVideoContent(callee()->pc()->local_description()->description());
840 ASSERT_NE(nullptr, callee_video_content);
841 EXPECT_TRUE(callee_video_content->rejected);
842}
843
844// This test sets up an audio and video call between two parties. After the
845// call runs for a while, the caller sends an updated offer with video being
846// rejected. Once the re-negotiation is done, the video flow should stop and
847// the audio flow should continue.
Seth Hampson2f0d7022018-02-20 11:54:42 -0800848TEST_P(PeerConnectionIntegrationTest, VideoRejectedInSubsequentOffer) {
deadbeef1dcb1642017-03-29 21:08:16 -0700849 ASSERT_TRUE(CreatePeerConnectionWrappers());
850 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -0800851 caller()->AddAudioVideoTracks();
852 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -0700853 caller()->CreateAndSetAndSignalOffer();
854 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -0800855 {
856 MediaExpectations media_expectations;
857 media_expectations.ExpectBidirectionalAudioAndVideo();
858 ASSERT_TRUE(ExpectNewFrames(media_expectations));
859 }
deadbeef1dcb1642017-03-29 21:08:16 -0700860 // Renegotiate, rejecting the video m= section.
Florent Castelli15a38de2022-04-06 00:38:21 +0200861 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Seth Hampson2f0d7022018-02-20 11:54:42 -0800862 caller()->SetGeneratedSdpMunger(
863 [](cricket::SessionDescription* description) {
864 for (cricket::ContentInfo& content : description->contents()) {
865 if (cricket::IsVideoContent(&content)) {
866 content.rejected = true;
867 }
868 }
869 });
870 } else {
Harald Alvestrand6060df52020-08-11 09:54:02 +0200871 caller()
872 ->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)
873 ->StopInternal();
Seth Hampson2f0d7022018-02-20 11:54:42 -0800874 }
deadbeef1dcb1642017-03-29 21:08:16 -0700875 caller()->CreateAndSetAndSignalOffer();
876 ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs);
877
878 // Sanity check that the caller's description has a rejected video section.
879 ASSERT_NE(nullptr, caller()->pc()->local_description());
880 const ContentInfo* caller_video_content =
881 GetFirstVideoContent(caller()->pc()->local_description()->description());
882 ASSERT_NE(nullptr, caller_video_content);
883 EXPECT_TRUE(caller_video_content->rejected);
deadbeef1dcb1642017-03-29 21:08:16 -0700884 // Wait for some additional audio frames to be received.
Seth Hampson2f0d7022018-02-20 11:54:42 -0800885 {
886 MediaExpectations media_expectations;
887 media_expectations.ExpectBidirectionalAudio();
888 media_expectations.ExpectNoVideo();
889 ASSERT_TRUE(ExpectNewFrames(media_expectations));
890 }
deadbeef1dcb1642017-03-29 21:08:16 -0700891}
892
Taylor Brandstetter60c8dc82018-04-11 15:20:27 -0700893// Do one offer/answer with audio, another that disables it (rejecting the m=
894// section), and another that re-enables it. Regression test for:
895// bugs.webrtc.org/6023
896TEST_F(PeerConnectionIntegrationTestPlanB, EnableAudioAfterRejecting) {
897 ASSERT_TRUE(CreatePeerConnectionWrappers());
898 ConnectFakeSignaling();
899
900 // Add audio track, do normal offer/answer.
901 rtc::scoped_refptr<webrtc::AudioTrackInterface> track =
902 caller()->CreateLocalAudioTrack();
903 rtc::scoped_refptr<webrtc::RtpSenderInterface> sender =
904 caller()->pc()->AddTrack(track, {"stream"}).MoveValue();
905 caller()->CreateAndSetAndSignalOffer();
906 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
907
908 // Remove audio track, and set offer_to_receive_audio to false to cause the
909 // m= section to be completely disabled, not just "recvonly".
Harald Alvestrand93dd7632022-01-19 12:28:45 +0000910 caller()->pc()->RemoveTrackOrError(sender);
Taylor Brandstetter60c8dc82018-04-11 15:20:27 -0700911 PeerConnectionInterface::RTCOfferAnswerOptions options;
912 options.offer_to_receive_audio = 0;
913 caller()->SetOfferAnswerOptions(options);
914 caller()->CreateAndSetAndSignalOffer();
915 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
916
917 // Add the audio track again, expecting negotiation to succeed and frames to
918 // flow.
919 sender = caller()->pc()->AddTrack(track, {"stream"}).MoveValue();
920 options.offer_to_receive_audio = 1;
921 caller()->SetOfferAnswerOptions(options);
922 caller()->CreateAndSetAndSignalOffer();
923 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
924
925 MediaExpectations media_expectations;
926 media_expectations.CalleeExpectsSomeAudio();
927 EXPECT_TRUE(ExpectNewFrames(media_expectations));
928}
929
deadbeef1dcb1642017-03-29 21:08:16 -0700930// Basic end-to-end test, but without SSRC/MSID signaling. This functionality
931// is needed to support legacy endpoints.
932// TODO(deadbeef): When we support the MID extension and demuxing on MID, also
933// add a test for an end-to-end test without MID signaling either (basically,
934// the minimum acceptable SDP).
Seth Hampson2f0d7022018-02-20 11:54:42 -0800935TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithoutSsrcOrMsidSignaling) {
deadbeef1dcb1642017-03-29 21:08:16 -0700936 ASSERT_TRUE(CreatePeerConnectionWrappers());
937 ConnectFakeSignaling();
938 // Add audio and video, testing that packets can be demuxed on payload type.
Steve Anton15324772018-01-16 10:26:49 -0800939 caller()->AddAudioVideoTracks();
940 callee()->AddAudioVideoTracks();
deadbeefd8ad7882017-04-18 16:01:17 -0700941 // Remove SSRCs and MSIDs from the received offer SDP.
942 callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids);
deadbeef1dcb1642017-03-29 21:08:16 -0700943 caller()->CreateAndSetAndSignalOffer();
944 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -0800945 MediaExpectations media_expectations;
946 media_expectations.ExpectBidirectionalAudioAndVideo();
947 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -0700948}
949
Seth Hampson5897a6e2018-04-03 11:16:33 -0700950// Basic end-to-end test, without SSRC signaling. This means that the track
951// was created properly and frames are delivered when the MSIDs are communicated
952// with a=msid lines and no a=ssrc lines.
953TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
954 EndToEndCallWithoutSsrcSignaling) {
955 const char kStreamId[] = "streamId";
956 ASSERT_TRUE(CreatePeerConnectionWrappers());
957 ConnectFakeSignaling();
958 // Add just audio tracks.
959 caller()->AddTrack(caller()->CreateLocalAudioTrack(), {kStreamId});
960 callee()->AddAudioTrack();
961
962 // Remove SSRCs from the received offer SDP.
963 callee()->SetReceivedSdpMunger(RemoveSsrcsAndKeepMsids);
964 caller()->CreateAndSetAndSignalOffer();
965 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
966 MediaExpectations media_expectations;
967 media_expectations.ExpectBidirectionalAudio();
968 ASSERT_TRUE(ExpectNewFrames(media_expectations));
969}
970
Johannes Kron3e983682020-03-29 22:17:00 +0200971TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
972 EndToEndCallAddReceiveVideoToSendOnlyCall) {
973 ASSERT_TRUE(CreatePeerConnectionWrappers());
974 ConnectFakeSignaling();
975 // Add one-directional video, from caller to callee.
976 rtc::scoped_refptr<webrtc::VideoTrackInterface> track =
977 caller()->CreateLocalVideoTrack();
978
979 RtpTransceiverInit video_transceiver_init;
980 video_transceiver_init.stream_ids = {"video1"};
981 video_transceiver_init.direction = RtpTransceiverDirection::kSendOnly;
982 auto video_sender =
983 caller()->pc()->AddTransceiver(track, video_transceiver_init).MoveValue();
984 caller()->CreateAndSetAndSignalOffer();
985 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
986
987 // Add receive direction.
Harald Alvestrand6060df52020-08-11 09:54:02 +0200988 video_sender->SetDirectionWithError(RtpTransceiverDirection::kSendRecv);
Johannes Kron3e983682020-03-29 22:17:00 +0200989
990 rtc::scoped_refptr<webrtc::VideoTrackInterface> callee_track =
991 callee()->CreateLocalVideoTrack();
992
993 callee()->AddTrack(callee_track);
994 caller()->CreateAndSetAndSignalOffer();
995 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
996 // Ensure that video frames are received end-to-end.
997 MediaExpectations media_expectations;
998 media_expectations.ExpectBidirectionalVideo();
999 ASSERT_TRUE(ExpectNewFrames(media_expectations));
1000}
1001
Steve Antondf527fd2018-04-27 15:52:03 -07001002// Tests that video flows between multiple video tracks when SSRCs are not
1003// signaled. This exercises the MID RTP header extension which is needed to
1004// demux the incoming video tracks.
1005TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
1006 EndToEndCallWithTwoVideoTracksAndNoSignaledSsrc) {
1007 ASSERT_TRUE(CreatePeerConnectionWrappers());
1008 ConnectFakeSignaling();
1009 caller()->AddVideoTrack();
1010 caller()->AddVideoTrack();
1011 callee()->AddVideoTrack();
1012 callee()->AddVideoTrack();
1013
1014 caller()->SetReceivedSdpMunger(&RemoveSsrcsAndKeepMsids);
1015 callee()->SetReceivedSdpMunger(&RemoveSsrcsAndKeepMsids);
1016 caller()->CreateAndSetAndSignalOffer();
1017 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1018 ASSERT_EQ(2u, caller()->pc()->GetReceivers().size());
1019 ASSERT_EQ(2u, callee()->pc()->GetReceivers().size());
1020
1021 // Expect video to be received in both directions on both tracks.
1022 MediaExpectations media_expectations;
1023 media_expectations.ExpectBidirectionalVideo();
1024 EXPECT_TRUE(ExpectNewFrames(media_expectations));
1025}
1026
Taylor Brandstetterd3ef4992020-10-15 18:22:57 -07001027// Used for the test below.
1028void RemoveBundleGroupSsrcsAndMidExtension(cricket::SessionDescription* desc) {
1029 RemoveSsrcsAndKeepMsids(desc);
1030 desc->RemoveGroupByName("BUNDLE");
1031 for (ContentInfo& content : desc->contents()) {
1032 cricket::MediaContentDescription* media = content.media_description();
1033 cricket::RtpHeaderExtensions extensions = media->rtp_header_extensions();
1034 extensions.erase(std::remove_if(extensions.begin(), extensions.end(),
1035 [](const RtpExtension& extension) {
1036 return extension.uri ==
1037 RtpExtension::kMidUri;
1038 }),
1039 extensions.end());
1040 media->set_rtp_header_extensions(extensions);
1041 }
1042}
1043
1044// Tests that video flows between multiple video tracks when BUNDLE is not used,
1045// SSRCs are not signaled and the MID RTP header extension is not used. This
1046// relies on demuxing by payload type, which normally doesn't work if you have
1047// multiple media sections using the same payload type, but which should work as
1048// long as the media sections aren't bundled.
1049// Regression test for: http://crbug.com/webrtc/12023
1050TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
1051 EndToEndCallWithTwoVideoTracksNoBundleNoSignaledSsrcAndNoMid) {
1052 ASSERT_TRUE(CreatePeerConnectionWrappers());
1053 ConnectFakeSignaling();
1054 caller()->AddVideoTrack();
1055 caller()->AddVideoTrack();
1056 callee()->AddVideoTrack();
1057 callee()->AddVideoTrack();
1058 caller()->SetReceivedSdpMunger(&RemoveBundleGroupSsrcsAndMidExtension);
1059 callee()->SetReceivedSdpMunger(&RemoveBundleGroupSsrcsAndMidExtension);
1060 caller()->CreateAndSetAndSignalOffer();
1061 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1062 ASSERT_EQ(2u, caller()->pc()->GetReceivers().size());
1063 ASSERT_EQ(2u, callee()->pc()->GetReceivers().size());
1064 // Make sure we are not bundled.
1065 ASSERT_NE(caller()->pc()->GetSenders()[0]->dtls_transport(),
1066 caller()->pc()->GetSenders()[1]->dtls_transport());
1067
1068 // Expect video to be received in both directions on both tracks.
1069 MediaExpectations media_expectations;
1070 media_expectations.ExpectBidirectionalVideo();
1071 EXPECT_TRUE(ExpectNewFrames(media_expectations));
1072}
1073
1074// Used for the test below.
1075void ModifyPayloadTypesAndRemoveMidExtension(
1076 cricket::SessionDescription* desc) {
1077 int pt = 96;
1078 for (ContentInfo& content : desc->contents()) {
1079 cricket::MediaContentDescription* media = content.media_description();
1080 cricket::RtpHeaderExtensions extensions = media->rtp_header_extensions();
1081 extensions.erase(std::remove_if(extensions.begin(), extensions.end(),
1082 [](const RtpExtension& extension) {
1083 return extension.uri ==
1084 RtpExtension::kMidUri;
1085 }),
1086 extensions.end());
1087 media->set_rtp_header_extensions(extensions);
1088 cricket::VideoContentDescription* video = media->as_video();
1089 ASSERT_TRUE(video != nullptr);
1090 std::vector<cricket::VideoCodec> codecs = {{pt++, "VP8"}};
1091 video->set_codecs(codecs);
1092 }
1093}
1094
1095// Tests that two video tracks can be demultiplexed by payload type alone, by
1096// using different payload types for the same codec in different m= sections.
1097// This practice is discouraged but historically has been supported.
1098// Regression test for: http://crbug.com/webrtc/12029
1099TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
1100 EndToEndCallWithTwoVideoTracksDemultiplexedByPayloadType) {
1101 ASSERT_TRUE(CreatePeerConnectionWrappers());
1102 ConnectFakeSignaling();
1103 caller()->AddVideoTrack();
1104 caller()->AddVideoTrack();
1105 callee()->AddVideoTrack();
1106 callee()->AddVideoTrack();
1107 caller()->SetGeneratedSdpMunger(&ModifyPayloadTypesAndRemoveMidExtension);
1108 callee()->SetGeneratedSdpMunger(&ModifyPayloadTypesAndRemoveMidExtension);
1109 // We can't remove SSRCs from the generated SDP because then no send streams
1110 // would be created.
1111 caller()->SetReceivedSdpMunger(&RemoveSsrcsAndKeepMsids);
1112 callee()->SetReceivedSdpMunger(&RemoveSsrcsAndKeepMsids);
1113 caller()->CreateAndSetAndSignalOffer();
1114 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1115 ASSERT_EQ(2u, caller()->pc()->GetReceivers().size());
1116 ASSERT_EQ(2u, callee()->pc()->GetReceivers().size());
1117 // Make sure we are bundled.
1118 ASSERT_EQ(caller()->pc()->GetSenders()[0]->dtls_transport(),
1119 caller()->pc()->GetSenders()[1]->dtls_transport());
1120
1121 // Expect video to be received in both directions on both tracks.
1122 MediaExpectations media_expectations;
1123 media_expectations.ExpectBidirectionalVideo();
1124 EXPECT_TRUE(ExpectNewFrames(media_expectations));
1125}
1126
Henrik Boström5b147782018-12-04 11:25:05 +01001127TEST_F(PeerConnectionIntegrationTestUnifiedPlan, NoStreamsMsidLinePresent) {
1128 ASSERT_TRUE(CreatePeerConnectionWrappers());
1129 ConnectFakeSignaling();
1130 caller()->AddAudioTrack();
1131 caller()->AddVideoTrack();
1132 caller()->CreateAndSetAndSignalOffer();
1133 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1134 auto callee_receivers = callee()->pc()->GetReceivers();
1135 ASSERT_EQ(2u, callee_receivers.size());
1136 EXPECT_TRUE(callee_receivers[0]->stream_ids().empty());
1137 EXPECT_TRUE(callee_receivers[1]->stream_ids().empty());
1138}
1139
1140TEST_F(PeerConnectionIntegrationTestUnifiedPlan, NoStreamsMsidLineMissing) {
1141 ASSERT_TRUE(CreatePeerConnectionWrappers());
1142 ConnectFakeSignaling();
1143 caller()->AddAudioTrack();
1144 caller()->AddVideoTrack();
1145 callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids);
1146 caller()->CreateAndSetAndSignalOffer();
1147 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1148 auto callee_receivers = callee()->pc()->GetReceivers();
1149 ASSERT_EQ(2u, callee_receivers.size());
1150 ASSERT_EQ(1u, callee_receivers[0]->stream_ids().size());
1151 ASSERT_EQ(1u, callee_receivers[1]->stream_ids().size());
1152 EXPECT_EQ(callee_receivers[0]->stream_ids()[0],
1153 callee_receivers[1]->stream_ids()[0]);
1154 EXPECT_EQ(callee_receivers[0]->streams()[0],
1155 callee_receivers[1]->streams()[0]);
1156}
1157
deadbeef1dcb1642017-03-29 21:08:16 -07001158// Test that if two video tracks are sent (from caller to callee, in this test),
1159// they're transmitted correctly end-to-end.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001160TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithTwoVideoTracks) {
deadbeef1dcb1642017-03-29 21:08:16 -07001161 ASSERT_TRUE(CreatePeerConnectionWrappers());
1162 ConnectFakeSignaling();
1163 // Add one audio/video stream, and one video-only stream.
Steve Anton15324772018-01-16 10:26:49 -08001164 caller()->AddAudioVideoTracks();
1165 caller()->AddVideoTrack();
deadbeef1dcb1642017-03-29 21:08:16 -07001166 caller()->CreateAndSetAndSignalOffer();
1167 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Steve Anton15324772018-01-16 10:26:49 -08001168 ASSERT_EQ(3u, callee()->pc()->GetReceivers().size());
Seth Hampson2f0d7022018-02-20 11:54:42 -08001169
1170 MediaExpectations media_expectations;
1171 media_expectations.CalleeExpectsSomeAudioAndVideo();
1172 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07001173}
1174
1175static void MakeSpecCompliantMaxBundleOffer(cricket::SessionDescription* desc) {
1176 bool first = true;
1177 for (cricket::ContentInfo& content : desc->contents()) {
1178 if (first) {
1179 first = false;
1180 continue;
1181 }
1182 content.bundle_only = true;
1183 }
1184 first = true;
1185 for (cricket::TransportInfo& transport : desc->transport_infos()) {
1186 if (first) {
1187 first = false;
1188 continue;
1189 }
1190 transport.description.ice_ufrag.clear();
1191 transport.description.ice_pwd.clear();
1192 transport.description.connection_role = cricket::CONNECTIONROLE_NONE;
1193 transport.description.identity_fingerprint.reset(nullptr);
1194 }
1195}
1196
1197// Test that if applying a true "max bundle" offer, which uses ports of 0,
1198// "a=bundle-only", omitting "a=fingerprint", "a=setup", "a=ice-ufrag" and
1199// "a=ice-pwd" for all but the audio "m=" section, negotiation still completes
1200// successfully and media flows.
1201// TODO(deadbeef): Update this test to also omit "a=rtcp-mux", once that works.
1202// TODO(deadbeef): Won't need this test once we start generating actual
1203// standards-compliant SDP.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001204TEST_P(PeerConnectionIntegrationTest,
deadbeef1dcb1642017-03-29 21:08:16 -07001205 EndToEndCallWithSpecCompliantMaxBundleOffer) {
1206 ASSERT_TRUE(CreatePeerConnectionWrappers());
1207 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08001208 caller()->AddAudioVideoTracks();
1209 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07001210 // Do the equivalent of setting the port to 0, adding a=bundle-only, and
1211 // removing a=ice-ufrag, a=ice-pwd, a=fingerprint and a=setup from all
1212 // but the first m= section.
1213 callee()->SetReceivedSdpMunger(MakeSpecCompliantMaxBundleOffer);
1214 caller()->CreateAndSetAndSignalOffer();
1215 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08001216 MediaExpectations media_expectations;
1217 media_expectations.ExpectBidirectionalAudioAndVideo();
1218 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07001219}
1220
1221// Test that we can receive the audio output level from a remote audio track.
1222// TODO(deadbeef): Use a fake audio source and verify that the output level is
1223// exactly what the source on the other side was configured with.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001224TEST_P(PeerConnectionIntegrationTest, GetAudioOutputLevelStatsWithOldStatsApi) {
deadbeef1dcb1642017-03-29 21:08:16 -07001225 ASSERT_TRUE(CreatePeerConnectionWrappers());
1226 ConnectFakeSignaling();
1227 // Just add an audio track.
Steve Anton15324772018-01-16 10:26:49 -08001228 caller()->AddAudioTrack();
deadbeef1dcb1642017-03-29 21:08:16 -07001229 caller()->CreateAndSetAndSignalOffer();
1230 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1231
1232 // Get the audio output level stats. Note that the level is not available
1233 // until an RTCP packet has been received.
deadbeefd8ad7882017-04-18 16:01:17 -07001234 EXPECT_TRUE_WAIT(callee()->OldGetStats()->AudioOutputLevel() > 0,
deadbeef1dcb1642017-03-29 21:08:16 -07001235 kMaxWaitForFramesMs);
1236}
1237
1238// Test that an audio input level is reported.
1239// TODO(deadbeef): Use a fake audio source and verify that the input level is
1240// exactly what the source was configured with.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001241TEST_P(PeerConnectionIntegrationTest, GetAudioInputLevelStatsWithOldStatsApi) {
deadbeef1dcb1642017-03-29 21:08:16 -07001242 ASSERT_TRUE(CreatePeerConnectionWrappers());
1243 ConnectFakeSignaling();
1244 // Just add an audio track.
Steve Anton15324772018-01-16 10:26:49 -08001245 caller()->AddAudioTrack();
deadbeef1dcb1642017-03-29 21:08:16 -07001246 caller()->CreateAndSetAndSignalOffer();
1247 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1248
1249 // Get the audio input level stats. The level should be available very
1250 // soon after the test starts.
deadbeefd8ad7882017-04-18 16:01:17 -07001251 EXPECT_TRUE_WAIT(caller()->OldGetStats()->AudioInputLevel() > 0,
deadbeef1dcb1642017-03-29 21:08:16 -07001252 kMaxWaitForStatsMs);
1253}
1254
1255// Test that we can get incoming byte counts from both audio and video tracks.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001256TEST_P(PeerConnectionIntegrationTest, GetBytesReceivedStatsWithOldStatsApi) {
deadbeef1dcb1642017-03-29 21:08:16 -07001257 ASSERT_TRUE(CreatePeerConnectionWrappers());
1258 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08001259 caller()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07001260 // Do offer/answer, wait for the callee to receive some frames.
1261 caller()->CreateAndSetAndSignalOffer();
1262 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08001263
1264 MediaExpectations media_expectations;
1265 media_expectations.CalleeExpectsSomeAudioAndVideo();
1266 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07001267
1268 // Get a handle to the remote tracks created, so they can be used as GetStats
1269 // filters.
Mirko Bonadei739baf02019-01-27 17:29:42 +01001270 for (const auto& receiver : callee()->pc()->GetReceivers()) {
Steve Anton15324772018-01-16 10:26:49 -08001271 // We received frames, so we definitely should have nonzero "received bytes"
1272 // stats at this point.
Niels Möllerafb246b2022-04-20 14:26:50 +02001273 EXPECT_GT(
1274 callee()->OldGetStatsForTrack(receiver->track().get())->BytesReceived(),
1275 0);
Steve Anton15324772018-01-16 10:26:49 -08001276 }
deadbeef1dcb1642017-03-29 21:08:16 -07001277}
1278
1279// Test that we can get outgoing byte counts from both audio and video tracks.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001280TEST_P(PeerConnectionIntegrationTest, GetBytesSentStatsWithOldStatsApi) {
deadbeef1dcb1642017-03-29 21:08:16 -07001281 ASSERT_TRUE(CreatePeerConnectionWrappers());
1282 ConnectFakeSignaling();
1283 auto audio_track = caller()->CreateLocalAudioTrack();
1284 auto video_track = caller()->CreateLocalVideoTrack();
Steve Anton15324772018-01-16 10:26:49 -08001285 caller()->AddTrack(audio_track);
1286 caller()->AddTrack(video_track);
deadbeef1dcb1642017-03-29 21:08:16 -07001287 // Do offer/answer, wait for the callee to receive some frames.
1288 caller()->CreateAndSetAndSignalOffer();
1289 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08001290 MediaExpectations media_expectations;
1291 media_expectations.CalleeExpectsSomeAudioAndVideo();
1292 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07001293
1294 // The callee received frames, so we definitely should have nonzero "sent
1295 // bytes" stats at this point.
Niels Möllerafb246b2022-04-20 14:26:50 +02001296 EXPECT_GT(caller()->OldGetStatsForTrack(audio_track.get())->BytesSent(), 0);
1297 EXPECT_GT(caller()->OldGetStatsForTrack(video_track.get())->BytesSent(), 0);
deadbeefd8ad7882017-04-18 16:01:17 -07001298}
1299
Steve Antona41959e2018-11-28 11:15:33 -08001300// Test that the track ID is associated with all local and remote SSRC stats
1301// using the old GetStats() and more than 1 audio and more than 1 video track.
1302// This is a regression test for crbug.com/906988
1303TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
1304 OldGetStatsAssociatesTrackIdForManyMediaSections) {
1305 ASSERT_TRUE(CreatePeerConnectionWrappers());
1306 ConnectFakeSignaling();
1307 auto audio_sender_1 = caller()->AddAudioTrack();
1308 auto video_sender_1 = caller()->AddVideoTrack();
1309 auto audio_sender_2 = caller()->AddAudioTrack();
1310 auto video_sender_2 = caller()->AddVideoTrack();
1311 caller()->CreateAndSetAndSignalOffer();
1312 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1313
1314 MediaExpectations media_expectations;
1315 media_expectations.CalleeExpectsSomeAudioAndVideo();
1316 ASSERT_TRUE_WAIT(ExpectNewFrames(media_expectations), kDefaultTimeout);
1317
1318 std::vector<std::string> track_ids = {
1319 audio_sender_1->track()->id(), video_sender_1->track()->id(),
1320 audio_sender_2->track()->id(), video_sender_2->track()->id()};
1321
1322 auto caller_stats = caller()->OldGetStats();
1323 EXPECT_THAT(caller_stats->TrackIds(), UnorderedElementsAreArray(track_ids));
1324 auto callee_stats = callee()->OldGetStats();
1325 EXPECT_THAT(callee_stats->TrackIds(), UnorderedElementsAreArray(track_ids));
1326}
1327
Steve Antonffa6ce42018-11-30 09:26:08 -08001328// Test that the new GetStats() returns stats for all outgoing/incoming streams
1329// with the correct track IDs if there are more than one audio and more than one
1330// video senders/receivers.
1331TEST_P(PeerConnectionIntegrationTest, NewGetStatsManyAudioAndManyVideoStreams) {
1332 ASSERT_TRUE(CreatePeerConnectionWrappers());
1333 ConnectFakeSignaling();
1334 auto audio_sender_1 = caller()->AddAudioTrack();
1335 auto video_sender_1 = caller()->AddVideoTrack();
1336 auto audio_sender_2 = caller()->AddAudioTrack();
1337 auto video_sender_2 = caller()->AddVideoTrack();
1338 caller()->CreateAndSetAndSignalOffer();
1339 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1340
1341 MediaExpectations media_expectations;
1342 media_expectations.CalleeExpectsSomeAudioAndVideo();
1343 ASSERT_TRUE_WAIT(ExpectNewFrames(media_expectations), kDefaultTimeout);
1344
1345 std::vector<std::string> track_ids = {
1346 audio_sender_1->track()->id(), video_sender_1->track()->id(),
1347 audio_sender_2->track()->id(), video_sender_2->track()->id()};
1348
1349 rtc::scoped_refptr<const webrtc::RTCStatsReport> caller_report =
1350 caller()->NewGetStats();
1351 ASSERT_TRUE(caller_report);
1352 auto outbound_stream_stats =
1353 caller_report->GetStatsOfType<webrtc::RTCOutboundRTPStreamStats>();
Henrik Boströma0ff50c2020-05-05 15:54:46 +02001354 ASSERT_EQ(outbound_stream_stats.size(), 4u);
Steve Antonffa6ce42018-11-30 09:26:08 -08001355 std::vector<std::string> outbound_track_ids;
1356 for (const auto& stat : outbound_stream_stats) {
1357 ASSERT_TRUE(stat->bytes_sent.is_defined());
1358 EXPECT_LT(0u, *stat->bytes_sent);
Rasmus Brandt2efae772019-06-27 14:29:34 +02001359 if (*stat->kind == "video") {
1360 ASSERT_TRUE(stat->key_frames_encoded.is_defined());
1361 EXPECT_GT(*stat->key_frames_encoded, 0u);
1362 ASSERT_TRUE(stat->frames_encoded.is_defined());
1363 EXPECT_GE(*stat->frames_encoded, *stat->key_frames_encoded);
1364 }
Steve Antonffa6ce42018-11-30 09:26:08 -08001365 ASSERT_TRUE(stat->track_id.is_defined());
1366 const auto* track_stat =
Henrik Boström15166b22022-10-19 11:06:58 +02001367 caller_report->GetAs<webrtc::DEPRECATED_RTCMediaStreamTrackStats>(
1368 *stat->track_id);
Steve Antonffa6ce42018-11-30 09:26:08 -08001369 ASSERT_TRUE(track_stat);
1370 outbound_track_ids.push_back(*track_stat->track_identifier);
1371 }
1372 EXPECT_THAT(outbound_track_ids, UnorderedElementsAreArray(track_ids));
1373
1374 rtc::scoped_refptr<const webrtc::RTCStatsReport> callee_report =
1375 callee()->NewGetStats();
1376 ASSERT_TRUE(callee_report);
1377 auto inbound_stream_stats =
1378 callee_report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>();
1379 ASSERT_EQ(4u, inbound_stream_stats.size());
1380 std::vector<std::string> inbound_track_ids;
1381 for (const auto& stat : inbound_stream_stats) {
1382 ASSERT_TRUE(stat->bytes_received.is_defined());
1383 EXPECT_LT(0u, *stat->bytes_received);
Rasmus Brandt2efae772019-06-27 14:29:34 +02001384 if (*stat->kind == "video") {
1385 ASSERT_TRUE(stat->key_frames_decoded.is_defined());
1386 EXPECT_GT(*stat->key_frames_decoded, 0u);
1387 ASSERT_TRUE(stat->frames_decoded.is_defined());
1388 EXPECT_GE(*stat->frames_decoded, *stat->key_frames_decoded);
1389 }
Steve Antonffa6ce42018-11-30 09:26:08 -08001390 ASSERT_TRUE(stat->track_id.is_defined());
1391 const auto* track_stat =
Henrik Boström15166b22022-10-19 11:06:58 +02001392 callee_report->GetAs<webrtc::DEPRECATED_RTCMediaStreamTrackStats>(
1393 *stat->track_id);
Steve Antonffa6ce42018-11-30 09:26:08 -08001394 ASSERT_TRUE(track_stat);
1395 inbound_track_ids.push_back(*track_stat->track_identifier);
1396 }
1397 EXPECT_THAT(inbound_track_ids, UnorderedElementsAreArray(track_ids));
1398}
1399
1400// Test that we can get stats (using the new stats implementation) for
deadbeefd8ad7882017-04-18 16:01:17 -07001401// unsignaled streams. Meaning when SSRCs/MSIDs aren't signaled explicitly in
1402// SDP.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001403TEST_P(PeerConnectionIntegrationTest,
deadbeefd8ad7882017-04-18 16:01:17 -07001404 GetStatsForUnsignaledStreamWithNewStatsApi) {
1405 ASSERT_TRUE(CreatePeerConnectionWrappers());
1406 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08001407 caller()->AddAudioTrack();
deadbeefd8ad7882017-04-18 16:01:17 -07001408 // Remove SSRCs and MSIDs from the received offer SDP.
1409 callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids);
1410 caller()->CreateAndSetAndSignalOffer();
1411 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08001412 MediaExpectations media_expectations;
1413 media_expectations.CalleeExpectsSomeAudio(1);
1414 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeefd8ad7882017-04-18 16:01:17 -07001415
1416 // We received a frame, so we should have nonzero "bytes received" stats for
1417 // the unsignaled stream, if stats are working for it.
1418 rtc::scoped_refptr<const webrtc::RTCStatsReport> report =
1419 callee()->NewGetStats();
1420 ASSERT_NE(nullptr, report);
1421 auto inbound_stream_stats =
1422 report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>();
1423 ASSERT_EQ(1U, inbound_stream_stats.size());
1424 ASSERT_TRUE(inbound_stream_stats[0]->bytes_received.is_defined());
1425 ASSERT_GT(*inbound_stream_stats[0]->bytes_received, 0U);
zhihuangf8164932017-05-19 13:09:47 -07001426 ASSERT_TRUE(inbound_stream_stats[0]->track_id.is_defined());
1427}
1428
Taylor Brandstettera4653442018-06-19 09:44:26 -07001429// Same as above but for the legacy stats implementation.
1430TEST_P(PeerConnectionIntegrationTest,
1431 GetStatsForUnsignaledStreamWithOldStatsApi) {
1432 ASSERT_TRUE(CreatePeerConnectionWrappers());
1433 ConnectFakeSignaling();
1434 caller()->AddAudioTrack();
1435 // Remove SSRCs and MSIDs from the received offer SDP.
1436 callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids);
1437 caller()->CreateAndSetAndSignalOffer();
1438 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1439
1440 // Note that, since the old stats implementation associates SSRCs with tracks
1441 // using SDP, when SSRCs aren't signaled in SDP these stats won't have an
1442 // associated track ID. So we can't use the track "selector" argument.
1443 //
1444 // Also, we use "EXPECT_TRUE_WAIT" because the stats collector may decide to
1445 // return cached stats if not enough time has passed since the last update.
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02001446 EXPECT_TRUE_WAIT(callee()->OldGetStats()->BytesReceived() > 0,
Taylor Brandstettera4653442018-06-19 09:44:26 -07001447 kDefaultTimeout);
1448}
1449
zhihuangf8164932017-05-19 13:09:47 -07001450// Test that we can successfully get the media related stats (audio level
1451// etc.) for the unsignaled stream.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001452TEST_P(PeerConnectionIntegrationTest,
zhihuangf8164932017-05-19 13:09:47 -07001453 GetMediaStatsForUnsignaledStreamWithNewStatsApi) {
1454 ASSERT_TRUE(CreatePeerConnectionWrappers());
1455 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08001456 caller()->AddAudioVideoTracks();
zhihuangf8164932017-05-19 13:09:47 -07001457 // Remove SSRCs and MSIDs from the received offer SDP.
1458 callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids);
1459 caller()->CreateAndSetAndSignalOffer();
1460 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08001461 MediaExpectations media_expectations;
1462 media_expectations.CalleeExpectsSomeAudio(1);
1463 media_expectations.CalleeExpectsSomeVideo(1);
1464 ASSERT_TRUE(ExpectNewFrames(media_expectations));
zhihuangf8164932017-05-19 13:09:47 -07001465
1466 rtc::scoped_refptr<const webrtc::RTCStatsReport> report =
1467 callee()->NewGetStats();
1468 ASSERT_NE(nullptr, report);
1469
Henrik Boström15166b22022-10-19 11:06:58 +02001470 auto media_stats =
1471 report->GetStatsOfType<webrtc::DEPRECATED_RTCMediaStreamTrackStats>();
zhihuangf8164932017-05-19 13:09:47 -07001472 auto audio_index = FindFirstMediaStatsIndexByKind("audio", media_stats);
1473 ASSERT_GE(audio_index, 0);
1474 EXPECT_TRUE(media_stats[audio_index]->audio_level.is_defined());
deadbeef1dcb1642017-03-29 21:08:16 -07001475}
1476
deadbeef4e2deab2017-09-20 13:56:21 -07001477// Helper for test below.
1478void ModifySsrcs(cricket::SessionDescription* desc) {
1479 for (ContentInfo& content : desc->contents()) {
Steve Antondf527fd2018-04-27 15:52:03 -07001480 for (StreamParams& stream :
Steve Antonb1c1de12017-12-21 15:14:30 -08001481 content.media_description()->mutable_streams()) {
deadbeef4e2deab2017-09-20 13:56:21 -07001482 for (uint32_t& ssrc : stream.ssrcs) {
1483 ssrc = rtc::CreateRandomId();
1484 }
1485 }
1486 }
1487}
1488
Henrik Boström15166b22022-10-19 11:06:58 +02001489// Test that the "DEPRECATED_RTCMediaStreamTrackStats" object is updated
1490// correctly when SSRCs are unsignaled, and the SSRC of the received (audio)
1491// stream changes. This should result in two "RTCInboundRTPStreamStats", but
1492// only one "DEPRECATED_RTCMediaStreamTrackStats", whose counters go up
1493// continuously rather than being reset to 0 once the SSRC change occurs.
deadbeef4e2deab2017-09-20 13:56:21 -07001494//
1495// Regression test for this bug:
1496// https://bugs.chromium.org/p/webrtc/issues/detail?id=8158
1497//
1498// The bug causes the track stats to only represent one of the two streams:
1499// whichever one has the higher SSRC. So with this bug, there was a 50% chance
1500// that the track stat counters would reset to 0 when the new stream is
1501// received, and a 50% chance that they'll stop updating (while
1502// "concealed_samples" continues increasing, due to silence being generated for
1503// the inactive stream).
Seth Hampson2f0d7022018-02-20 11:54:42 -08001504TEST_P(PeerConnectionIntegrationTest,
Steve Anton83119dd2017-11-10 16:19:52 -08001505 TrackStatsUpdatedCorrectlyWhenUnsignaledSsrcChanges) {
deadbeef4e2deab2017-09-20 13:56:21 -07001506 ASSERT_TRUE(CreatePeerConnectionWrappers());
1507 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08001508 caller()->AddAudioTrack();
deadbeef4e2deab2017-09-20 13:56:21 -07001509 // Remove SSRCs and MSIDs from the received offer SDP, simulating an endpoint
1510 // that doesn't signal SSRCs (from the callee's perspective).
1511 callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids);
1512 caller()->CreateAndSetAndSignalOffer();
1513 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1514 // Wait for 50 audio frames (500ms of audio) to be received by the callee.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001515 {
1516 MediaExpectations media_expectations;
1517 media_expectations.CalleeExpectsSomeAudio(50);
1518 ASSERT_TRUE(ExpectNewFrames(media_expectations));
1519 }
deadbeef4e2deab2017-09-20 13:56:21 -07001520 // Some audio frames were received, so we should have nonzero "samples
1521 // received" for the track.
1522 rtc::scoped_refptr<const webrtc::RTCStatsReport> report =
1523 callee()->NewGetStats();
1524 ASSERT_NE(nullptr, report);
Henrik Boström15166b22022-10-19 11:06:58 +02001525 auto track_stats =
1526 report->GetStatsOfType<webrtc::DEPRECATED_RTCMediaStreamTrackStats>();
deadbeef4e2deab2017-09-20 13:56:21 -07001527 ASSERT_EQ(1U, track_stats.size());
1528 ASSERT_TRUE(track_stats[0]->total_samples_received.is_defined());
1529 ASSERT_GT(*track_stats[0]->total_samples_received, 0U);
1530 // uint64_t prev_samples_received = *track_stats[0]->total_samples_received;
1531
1532 // Create a new offer and munge it to cause the caller to use a new SSRC.
1533 caller()->SetGeneratedSdpMunger(ModifySsrcs);
1534 caller()->CreateAndSetAndSignalOffer();
1535 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1536 // Wait for 25 more audio frames (250ms of audio) to be received, from the new
1537 // SSRC.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001538 {
1539 MediaExpectations media_expectations;
1540 media_expectations.CalleeExpectsSomeAudio(25);
1541 ASSERT_TRUE(ExpectNewFrames(media_expectations));
1542 }
deadbeef4e2deab2017-09-20 13:56:21 -07001543
1544 report = callee()->NewGetStats();
1545 ASSERT_NE(nullptr, report);
Henrik Boström15166b22022-10-19 11:06:58 +02001546 track_stats =
1547 report->GetStatsOfType<webrtc::DEPRECATED_RTCMediaStreamTrackStats>();
deadbeef4e2deab2017-09-20 13:56:21 -07001548 ASSERT_EQ(1U, track_stats.size());
1549 ASSERT_TRUE(track_stats[0]->total_samples_received.is_defined());
1550 // The "total samples received" stat should only be greater than it was
1551 // before.
1552 // TODO(deadbeef): Uncomment this assertion once the bug is completely fixed.
1553 // Right now, the new SSRC will cause the counters to reset to 0.
1554 // EXPECT_GT(*track_stats[0]->total_samples_received, prev_samples_received);
1555
1556 // Additionally, the percentage of concealed samples (samples generated to
Steve Anton83119dd2017-11-10 16:19:52 -08001557 // conceal packet loss) should be less than 50%. If it's greater, that's a
deadbeef4e2deab2017-09-20 13:56:21 -07001558 // good sign that we're seeing stats from the old stream that's no longer
1559 // receiving packets, and is generating concealed samples of silence.
Steve Anton83119dd2017-11-10 16:19:52 -08001560 constexpr double kAcceptableConcealedSamplesPercentage = 0.50;
deadbeef4e2deab2017-09-20 13:56:21 -07001561 ASSERT_TRUE(track_stats[0]->concealed_samples.is_defined());
1562 EXPECT_LT(*track_stats[0]->concealed_samples,
1563 *track_stats[0]->total_samples_received *
1564 kAcceptableConcealedSamplesPercentage);
1565
1566 // Also ensure that we have two "RTCInboundRTPStreamStats" as expected, as a
1567 // sanity check that the SSRC really changed.
1568 // TODO(deadbeef): This isn't working right now, because we're not returning
1569 // *any* stats for the inactive stream. Uncomment when the bug is completely
1570 // fixed.
1571 // auto inbound_stream_stats =
1572 // report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>();
1573 // ASSERT_EQ(2U, inbound_stream_stats.size());
1574}
1575
deadbeef1dcb1642017-03-29 21:08:16 -07001576// Test that DTLS 1.0 is used if both sides only support DTLS 1.0.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001577TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithDtls10) {
deadbeef1dcb1642017-03-29 21:08:16 -07001578 PeerConnectionFactory::Options dtls_10_options;
1579 dtls_10_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1580 ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_10_options,
1581 dtls_10_options));
1582 ConnectFakeSignaling();
1583 // Do normal offer/answer and wait for some frames to be received in each
1584 // direction.
Steve Anton15324772018-01-16 10:26:49 -08001585 caller()->AddAudioVideoTracks();
1586 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07001587 caller()->CreateAndSetAndSignalOffer();
1588 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08001589 MediaExpectations media_expectations;
1590 media_expectations.ExpectBidirectionalAudioAndVideo();
1591 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07001592}
1593
1594// Test getting cipher stats and UMA metrics when DTLS 1.0 is negotiated.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001595TEST_P(PeerConnectionIntegrationTest, Dtls10CipherStatsAndUmaMetrics) {
deadbeef1dcb1642017-03-29 21:08:16 -07001596 PeerConnectionFactory::Options dtls_10_options;
1597 dtls_10_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1598 ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_10_options,
1599 dtls_10_options));
1600 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08001601 caller()->AddAudioVideoTracks();
1602 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07001603 caller()->CreateAndSetAndSignalOffer();
Qingsi Wang7fc821d2018-07-12 12:54:53 -07001604 ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -07001605 EXPECT_TRUE_WAIT(rtc::SSLStreamAdapter::IsAcceptableCipher(
deadbeefd8ad7882017-04-18 16:01:17 -07001606 caller()->OldGetStats()->DtlsCipher(), rtc::KT_DEFAULT),
deadbeef1dcb1642017-03-29 21:08:16 -07001607 kDefaultTimeout);
1608 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
deadbeefd8ad7882017-04-18 16:01:17 -07001609 caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout);
Qingsi Wang7fc821d2018-07-12 12:54:53 -07001610 // TODO(bugs.webrtc.org/9456): Fix it.
Ying Wangef3998f2019-12-09 13:06:53 +01001611 EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(
1612 "WebRTC.PeerConnection.SrtpCryptoSuite.Audio",
1613 kDefaultSrtpCryptoSuite));
deadbeef1dcb1642017-03-29 21:08:16 -07001614}
1615
1616// Test getting cipher stats and UMA metrics when DTLS 1.2 is negotiated.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001617TEST_P(PeerConnectionIntegrationTest, Dtls12CipherStatsAndUmaMetrics) {
deadbeef1dcb1642017-03-29 21:08:16 -07001618 PeerConnectionFactory::Options dtls_12_options;
1619 dtls_12_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1620 ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_12_options,
1621 dtls_12_options));
1622 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08001623 caller()->AddAudioVideoTracks();
1624 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07001625 caller()->CreateAndSetAndSignalOffer();
Qingsi Wang7fc821d2018-07-12 12:54:53 -07001626 ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -07001627 EXPECT_TRUE_WAIT(rtc::SSLStreamAdapter::IsAcceptableCipher(
deadbeefd8ad7882017-04-18 16:01:17 -07001628 caller()->OldGetStats()->DtlsCipher(), rtc::KT_DEFAULT),
deadbeef1dcb1642017-03-29 21:08:16 -07001629 kDefaultTimeout);
1630 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
deadbeefd8ad7882017-04-18 16:01:17 -07001631 caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout);
Qingsi Wang7fc821d2018-07-12 12:54:53 -07001632 // TODO(bugs.webrtc.org/9456): Fix it.
Ying Wangef3998f2019-12-09 13:06:53 +01001633 EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(
1634 "WebRTC.PeerConnection.SrtpCryptoSuite.Audio",
1635 kDefaultSrtpCryptoSuite));
deadbeef1dcb1642017-03-29 21:08:16 -07001636}
1637
1638// Test that DTLS 1.0 can be used if the caller supports DTLS 1.2 and the
1639// callee only supports 1.0.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001640TEST_P(PeerConnectionIntegrationTest, CallerDtls12ToCalleeDtls10) {
deadbeef1dcb1642017-03-29 21:08:16 -07001641 PeerConnectionFactory::Options caller_options;
1642 caller_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1643 PeerConnectionFactory::Options callee_options;
1644 callee_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1645 ASSERT_TRUE(
1646 CreatePeerConnectionWrappersWithOptions(caller_options, callee_options));
1647 ConnectFakeSignaling();
1648 // Do normal offer/answer and wait for some frames to be received in each
1649 // direction.
Steve Anton15324772018-01-16 10:26:49 -08001650 caller()->AddAudioVideoTracks();
1651 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07001652 caller()->CreateAndSetAndSignalOffer();
1653 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08001654 MediaExpectations media_expectations;
1655 media_expectations.ExpectBidirectionalAudioAndVideo();
1656 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07001657}
1658
1659// Test that DTLS 1.0 can be used if the caller only supports DTLS 1.0 and the
1660// callee supports 1.2.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001661TEST_P(PeerConnectionIntegrationTest, CallerDtls10ToCalleeDtls12) {
deadbeef1dcb1642017-03-29 21:08:16 -07001662 PeerConnectionFactory::Options caller_options;
1663 caller_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
1664 PeerConnectionFactory::Options callee_options;
1665 callee_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
1666 ASSERT_TRUE(
1667 CreatePeerConnectionWrappersWithOptions(caller_options, callee_options));
1668 ConnectFakeSignaling();
1669 // Do normal offer/answer and wait for some frames to be received in each
1670 // direction.
Steve Anton15324772018-01-16 10:26:49 -08001671 caller()->AddAudioVideoTracks();
1672 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07001673 caller()->CreateAndSetAndSignalOffer();
1674 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08001675 MediaExpectations media_expectations;
1676 media_expectations.ExpectBidirectionalAudioAndVideo();
1677 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07001678}
1679
Taylor Brandstetter5e55fe82018-03-23 11:50:16 -07001680// The three tests below verify that "enable_aes128_sha1_32_crypto_cipher"
1681// works as expected; the cipher should only be used if enabled by both sides.
1682TEST_P(PeerConnectionIntegrationTest,
1683 Aes128Sha1_32_CipherNotUsedWhenOnlyCallerSupported) {
1684 PeerConnectionFactory::Options caller_options;
Benjamin Wrighta54daf12018-10-11 15:33:17 -07001685 caller_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true;
Taylor Brandstetter5e55fe82018-03-23 11:50:16 -07001686 PeerConnectionFactory::Options callee_options;
Benjamin Wrighta54daf12018-10-11 15:33:17 -07001687 callee_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher =
1688 false;
Mirko Bonadei7750d802021-07-26 17:27:42 +02001689 int expected_cipher_suite = rtc::kSrtpAes128CmSha1_80;
Taylor Brandstetter5e55fe82018-03-23 11:50:16 -07001690 TestNegotiatedCipherSuite(caller_options, callee_options,
1691 expected_cipher_suite);
1692}
1693
1694TEST_P(PeerConnectionIntegrationTest,
1695 Aes128Sha1_32_CipherNotUsedWhenOnlyCalleeSupported) {
1696 PeerConnectionFactory::Options caller_options;
Benjamin Wrighta54daf12018-10-11 15:33:17 -07001697 caller_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher =
1698 false;
Taylor Brandstetter5e55fe82018-03-23 11:50:16 -07001699 PeerConnectionFactory::Options callee_options;
Benjamin Wrighta54daf12018-10-11 15:33:17 -07001700 callee_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true;
Mirko Bonadei7750d802021-07-26 17:27:42 +02001701 int expected_cipher_suite = rtc::kSrtpAes128CmSha1_80;
Taylor Brandstetter5e55fe82018-03-23 11:50:16 -07001702 TestNegotiatedCipherSuite(caller_options, callee_options,
1703 expected_cipher_suite);
1704}
1705
1706TEST_P(PeerConnectionIntegrationTest, Aes128Sha1_32_CipherUsedWhenSupported) {
1707 PeerConnectionFactory::Options caller_options;
Benjamin Wrighta54daf12018-10-11 15:33:17 -07001708 caller_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true;
Taylor Brandstetter5e55fe82018-03-23 11:50:16 -07001709 PeerConnectionFactory::Options callee_options;
Benjamin Wrighta54daf12018-10-11 15:33:17 -07001710 callee_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true;
Mirko Bonadei7750d802021-07-26 17:27:42 +02001711 int expected_cipher_suite = rtc::kSrtpAes128CmSha1_32;
Taylor Brandstetter5e55fe82018-03-23 11:50:16 -07001712 TestNegotiatedCipherSuite(caller_options, callee_options,
1713 expected_cipher_suite);
1714}
1715
deadbeef1dcb1642017-03-29 21:08:16 -07001716// Test that a non-GCM cipher is used if both sides only support non-GCM.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001717TEST_P(PeerConnectionIntegrationTest, NonGcmCipherUsedWhenGcmNotSupported) {
deadbeef1dcb1642017-03-29 21:08:16 -07001718 bool local_gcm_enabled = false;
1719 bool remote_gcm_enabled = false;
Philipp Hancke2ebbff82019-10-26 06:12:55 +02001720 bool aes_ctr_enabled = true;
deadbeef1dcb1642017-03-29 21:08:16 -07001721 int expected_cipher_suite = kDefaultSrtpCryptoSuite;
1722 TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled,
Philipp Hancke2ebbff82019-10-26 06:12:55 +02001723 aes_ctr_enabled, expected_cipher_suite);
deadbeef1dcb1642017-03-29 21:08:16 -07001724}
1725
Philipp Hancke2ebbff82019-10-26 06:12:55 +02001726// Test that a GCM cipher is used if both ends support it and non-GCM is
1727// disabled.
1728TEST_P(PeerConnectionIntegrationTest, GcmCipherUsedWhenOnlyGcmSupported) {
deadbeef1dcb1642017-03-29 21:08:16 -07001729 bool local_gcm_enabled = true;
1730 bool remote_gcm_enabled = true;
Philipp Hancke2ebbff82019-10-26 06:12:55 +02001731 bool aes_ctr_enabled = false;
deadbeef1dcb1642017-03-29 21:08:16 -07001732 int expected_cipher_suite = kDefaultSrtpCryptoSuiteGcm;
1733 TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled,
Philipp Hancke2ebbff82019-10-26 06:12:55 +02001734 aes_ctr_enabled, expected_cipher_suite);
deadbeef1dcb1642017-03-29 21:08:16 -07001735}
1736
deadbeef7914b8c2017-04-21 03:23:33 -07001737// Verify that media can be transmitted end-to-end when GCM crypto suites are
1738// enabled. Note that the above tests, such as GcmCipherUsedWhenGcmSupported,
1739// only verify that a GCM cipher is negotiated, and not necessarily that SRTP
1740// works with it.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001741TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithGcmCipher) {
deadbeef7914b8c2017-04-21 03:23:33 -07001742 PeerConnectionFactory::Options gcm_options;
Benjamin Wrighta54daf12018-10-11 15:33:17 -07001743 gcm_options.crypto_options.srtp.enable_gcm_crypto_suites = true;
Philipp Hancke2ebbff82019-10-26 06:12:55 +02001744 gcm_options.crypto_options.srtp.enable_aes128_sha1_80_crypto_cipher = false;
deadbeef7914b8c2017-04-21 03:23:33 -07001745 ASSERT_TRUE(
1746 CreatePeerConnectionWrappersWithOptions(gcm_options, gcm_options));
1747 ConnectFakeSignaling();
1748 // Do normal offer/answer and wait for some frames to be received in each
1749 // direction.
Steve Anton15324772018-01-16 10:26:49 -08001750 caller()->AddAudioVideoTracks();
1751 callee()->AddAudioVideoTracks();
deadbeef7914b8c2017-04-21 03:23:33 -07001752 caller()->CreateAndSetAndSignalOffer();
1753 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08001754 MediaExpectations media_expectations;
1755 media_expectations.ExpectBidirectionalAudioAndVideo();
1756 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef7914b8c2017-04-21 03:23:33 -07001757}
1758
deadbeef1dcb1642017-03-29 21:08:16 -07001759// Test that the ICE connection and gathering states eventually reach
1760// "complete".
Seth Hampson2f0d7022018-02-20 11:54:42 -08001761TEST_P(PeerConnectionIntegrationTest, IceStatesReachCompletion) {
deadbeef1dcb1642017-03-29 21:08:16 -07001762 ASSERT_TRUE(CreatePeerConnectionWrappers());
1763 ConnectFakeSignaling();
1764 // Do normal offer/answer.
Steve Anton15324772018-01-16 10:26:49 -08001765 caller()->AddAudioVideoTracks();
1766 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07001767 caller()->CreateAndSetAndSignalOffer();
1768 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1769 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete,
1770 caller()->ice_gathering_state(), kMaxWaitForFramesMs);
1771 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete,
1772 callee()->ice_gathering_state(), kMaxWaitForFramesMs);
1773 // After the best candidate pair is selected and all candidates are signaled,
1774 // the ICE connection state should reach "complete".
1775 // TODO(deadbeef): Currently, the ICE "controlled" agent (the
1776 // answerer/"callee" by default) only reaches "connected". When this is
1777 // fixed, this test should be updated.
1778 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
1779 caller()->ice_connection_state(), kDefaultTimeout);
Alex Loiko9289eda2018-11-23 16:18:59 +00001780 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
1781 callee()->ice_connection_state(), kDefaultTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -07001782}
1783
Qingsi Wang1dac6d82018-12-12 15:28:47 -08001784constexpr int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN |
1785 cricket::PORTALLOCATOR_DISABLE_RELAY |
1786 cricket::PORTALLOCATOR_DISABLE_TCP;
Zach Stein6fcdc2f2018-08-23 16:25:55 -07001787
Qingsi Wang1dac6d82018-12-12 15:28:47 -08001788// Use a mock resolver to resolve the hostname back to the original IP on both
1789// sides and check that the ICE connection connects.
Zach Stein6fcdc2f2018-08-23 16:25:55 -07001790TEST_P(PeerConnectionIntegrationTest,
Harald Alvestrand099ff622022-06-02 13:24:32 +00001791 IceStatesReachCompletionWithRemoteHostname) {
Qingsi Wang1dac6d82018-12-12 15:28:47 -08001792 auto caller_resolver_factory =
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001793 std::make_unique<NiceMock<webrtc::MockAsyncResolverFactory>>();
Qingsi Wang1dac6d82018-12-12 15:28:47 -08001794 auto callee_resolver_factory =
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001795 std::make_unique<NiceMock<webrtc::MockAsyncResolverFactory>>();
Qingsi Wang1dac6d82018-12-12 15:28:47 -08001796 NiceMock<rtc::MockAsyncResolver> callee_async_resolver;
1797 NiceMock<rtc::MockAsyncResolver> caller_async_resolver;
Zach Stein6fcdc2f2018-08-23 16:25:55 -07001798
1799 // This also verifies that the injected AsyncResolverFactory is used by
1800 // P2PTransportChannel.
Qingsi Wang1dac6d82018-12-12 15:28:47 -08001801 EXPECT_CALL(*caller_resolver_factory, Create())
1802 .WillOnce(Return(&caller_async_resolver));
1803 webrtc::PeerConnectionDependencies caller_deps(nullptr);
1804 caller_deps.async_resolver_factory = std::move(caller_resolver_factory);
1805
1806 EXPECT_CALL(*callee_resolver_factory, Create())
1807 .WillOnce(Return(&callee_async_resolver));
1808 webrtc::PeerConnectionDependencies callee_deps(nullptr);
1809 callee_deps.async_resolver_factory = std::move(callee_resolver_factory);
1810
1811 PeerConnectionInterface::RTCConfiguration config;
1812 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
1813 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire;
1814
1815 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps(
1816 config, std::move(caller_deps), config, std::move(callee_deps)));
1817
1818 caller()->SetRemoteAsyncResolver(&callee_async_resolver);
1819 callee()->SetRemoteAsyncResolver(&caller_async_resolver);
1820
1821 // Enable hostname candidates with mDNS names.
Qingsi Wangecd30542019-05-22 14:34:56 -07001822 caller()->SetMdnsResponder(
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001823 std::make_unique<webrtc::FakeMdnsResponder>(network_thread()));
Qingsi Wangecd30542019-05-22 14:34:56 -07001824 callee()->SetMdnsResponder(
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001825 std::make_unique<webrtc::FakeMdnsResponder>(network_thread()));
Qingsi Wang1dac6d82018-12-12 15:28:47 -08001826
1827 SetPortAllocatorFlags(kOnlyLocalPorts, kOnlyLocalPorts);
Zach Stein6fcdc2f2018-08-23 16:25:55 -07001828
1829 ConnectFakeSignaling();
1830 caller()->AddAudioVideoTracks();
1831 callee()->AddAudioVideoTracks();
1832 caller()->CreateAndSetAndSignalOffer();
1833 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1834 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
1835 caller()->ice_connection_state(), kDefaultTimeout);
1836 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
1837 callee()->ice_connection_state(), kDefaultTimeout);
Jeroen de Borst833979f2018-12-13 08:25:54 -08001838
Ying Wangef3998f2019-12-09 13:06:53 +01001839 EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(
1840 "WebRTC.PeerConnection.CandidatePairType_UDP",
1841 webrtc::kIceCandidatePairHostNameHostName));
Harald Alvestrand4f7486a2022-06-02 11:35:49 +00001842 DestroyPeerConnections();
Zach Stein6fcdc2f2018-08-23 16:25:55 -07001843}
1844
Steve Antonede9ca52017-10-16 13:04:27 -07001845// Test that firewalling the ICE connection causes the clients to identify the
1846// disconnected state and then removing the firewall causes them to reconnect.
1847class PeerConnectionIntegrationIceStatesTest
Seth Hampson2f0d7022018-02-20 11:54:42 -08001848 : public PeerConnectionIntegrationBaseTest,
1849 public ::testing::WithParamInterface<
1850 std::tuple<SdpSemantics, std::tuple<std::string, uint32_t>>> {
Steve Antonede9ca52017-10-16 13:04:27 -07001851 protected:
Seth Hampson2f0d7022018-02-20 11:54:42 -08001852 PeerConnectionIntegrationIceStatesTest()
1853 : PeerConnectionIntegrationBaseTest(std::get<0>(GetParam())) {
1854 port_allocator_flags_ = std::get<1>(std::get<1>(GetParam()));
Steve Antonede9ca52017-10-16 13:04:27 -07001855 }
1856
1857 void StartStunServer(const SocketAddress& server_address) {
1858 stun_server_.reset(
Niels Möller091617d2020-12-02 15:32:08 +01001859 cricket::TestStunServer::Create(firewall(), server_address));
Steve Antonede9ca52017-10-16 13:04:27 -07001860 }
1861
1862 bool TestIPv6() {
1863 return (port_allocator_flags_ & cricket::PORTALLOCATOR_ENABLE_IPV6);
1864 }
1865
1866 void SetPortAllocatorFlags() {
Qingsi Wang1dac6d82018-12-12 15:28:47 -08001867 PeerConnectionIntegrationBaseTest::SetPortAllocatorFlags(
1868 port_allocator_flags_, port_allocator_flags_);
Steve Antonede9ca52017-10-16 13:04:27 -07001869 }
1870
1871 std::vector<SocketAddress> CallerAddresses() {
1872 std::vector<SocketAddress> addresses;
1873 addresses.push_back(SocketAddress("1.1.1.1", 0));
1874 if (TestIPv6()) {
1875 addresses.push_back(SocketAddress("1111:0:a:b:c:d:e:f", 0));
1876 }
1877 return addresses;
1878 }
1879
1880 std::vector<SocketAddress> CalleeAddresses() {
1881 std::vector<SocketAddress> addresses;
1882 addresses.push_back(SocketAddress("2.2.2.2", 0));
1883 if (TestIPv6()) {
1884 addresses.push_back(SocketAddress("2222:0:a:b:c:d:e:f", 0));
1885 }
1886 return addresses;
1887 }
1888
1889 void SetUpNetworkInterfaces() {
1890 // Remove the default interfaces added by the test infrastructure.
Qingsi Wangecd30542019-05-22 14:34:56 -07001891 caller()->network_manager()->RemoveInterface(kDefaultLocalAddress);
1892 callee()->network_manager()->RemoveInterface(kDefaultLocalAddress);
Steve Antonede9ca52017-10-16 13:04:27 -07001893
1894 // Add network addresses for test.
1895 for (const auto& caller_address : CallerAddresses()) {
Qingsi Wangecd30542019-05-22 14:34:56 -07001896 caller()->network_manager()->AddInterface(caller_address);
Steve Antonede9ca52017-10-16 13:04:27 -07001897 }
1898 for (const auto& callee_address : CalleeAddresses()) {
Qingsi Wangecd30542019-05-22 14:34:56 -07001899 callee()->network_manager()->AddInterface(callee_address);
Steve Antonede9ca52017-10-16 13:04:27 -07001900 }
1901 }
1902
1903 private:
1904 uint32_t port_allocator_flags_;
1905 std::unique_ptr<cricket::TestStunServer> stun_server_;
1906};
1907
Yves Gerey100fe632020-01-17 19:15:53 +01001908// Ensure FakeClockForTest is constructed first (see class for rationale).
1909class PeerConnectionIntegrationIceStatesTestWithFakeClock
1910 : public FakeClockForTest,
1911 public PeerConnectionIntegrationIceStatesTest {};
1912
Harald Alvestrandec23d6d2021-02-11 10:47:22 +00001913#if !defined(THREAD_SANITIZER)
1914// This test provokes TSAN errors. bugs.webrtc.org/11282
1915
Jonas Olssonb75d9e92019-02-22 10:33:29 +01001916// Tests that if the connection doesn't get set up properly we eventually reach
1917// the "failed" iceConnectionState.
Yves Gerey100fe632020-01-17 19:15:53 +01001918TEST_P(PeerConnectionIntegrationIceStatesTestWithFakeClock,
1919 IceStateSetupFailure) {
Jonas Olssonb75d9e92019-02-22 10:33:29 +01001920 // Block connections to/from the caller and wait for ICE to become
1921 // disconnected.
1922 for (const auto& caller_address : CallerAddresses()) {
1923 firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address);
1924 }
1925
1926 ASSERT_TRUE(CreatePeerConnectionWrappers());
1927 ConnectFakeSignaling();
1928 SetPortAllocatorFlags();
1929 SetUpNetworkInterfaces();
1930 caller()->AddAudioVideoTracks();
1931 caller()->CreateAndSetAndSignalOffer();
1932
1933 // According to RFC7675, if there is no response within 30 seconds then the
1934 // peer should consider the other side to have rejected the connection. This
1935 // is signaled by the state transitioning to "failed".
1936 constexpr int kConsentTimeout = 30000;
1937 ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionFailed,
1938 caller()->standardized_ice_connection_state(),
Yves Gerey100fe632020-01-17 19:15:53 +01001939 kConsentTimeout, FakeClock());
Steve Antonede9ca52017-10-16 13:04:27 -07001940}
1941
Harald Alvestrandec23d6d2021-02-11 10:47:22 +00001942#endif // !defined(THREAD_SANITIZER)
1943
Steve Antonede9ca52017-10-16 13:04:27 -07001944// Tests that the best connection is set to the appropriate IPv4/IPv6 connection
1945// and that the statistics in the metric observers are updated correctly.
Rasmus Brandt32af25b2021-03-17 13:40:21 +01001946// TODO(bugs.webrtc.org/12591): Flaky on Windows.
1947#if defined(WEBRTC_WIN)
1948#define MAYBE_VerifyBestConnection DISABLED_VerifyBestConnection
1949#else
1950#define MAYBE_VerifyBestConnection VerifyBestConnection
1951#endif
1952TEST_P(PeerConnectionIntegrationIceStatesTest, MAYBE_VerifyBestConnection) {
Steve Antonede9ca52017-10-16 13:04:27 -07001953 ASSERT_TRUE(CreatePeerConnectionWrappers());
1954 ConnectFakeSignaling();
1955 SetPortAllocatorFlags();
1956 SetUpNetworkInterfaces();
Steve Anton15324772018-01-16 10:26:49 -08001957 caller()->AddAudioVideoTracks();
1958 callee()->AddAudioVideoTracks();
Steve Antonede9ca52017-10-16 13:04:27 -07001959 caller()->CreateAndSetAndSignalOffer();
1960
1961 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Steve Anton692f3c72020-01-16 14:12:31 -08001962 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
1963 caller()->ice_connection_state(), kDefaultTimeout);
1964 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
1965 callee()->ice_connection_state(), kDefaultTimeout);
Steve Antonede9ca52017-10-16 13:04:27 -07001966
Qingsi Wang7fc821d2018-07-12 12:54:53 -07001967 // TODO(bugs.webrtc.org/9456): Fix it.
1968 const int num_best_ipv4 = webrtc::metrics::NumEvents(
1969 "WebRTC.PeerConnection.IPMetrics", webrtc::kBestConnections_IPv4);
1970 const int num_best_ipv6 = webrtc::metrics::NumEvents(
1971 "WebRTC.PeerConnection.IPMetrics", webrtc::kBestConnections_IPv6);
Steve Antonede9ca52017-10-16 13:04:27 -07001972 if (TestIPv6()) {
1973 // When IPv6 is enabled, we should prefer an IPv6 connection over an IPv4
1974 // connection.
Ying Wangef3998f2019-12-09 13:06:53 +01001975 EXPECT_METRIC_EQ(0, num_best_ipv4);
1976 EXPECT_METRIC_EQ(1, num_best_ipv6);
Steve Antonede9ca52017-10-16 13:04:27 -07001977 } else {
Ying Wangef3998f2019-12-09 13:06:53 +01001978 EXPECT_METRIC_EQ(1, num_best_ipv4);
1979 EXPECT_METRIC_EQ(0, num_best_ipv6);
Steve Antonede9ca52017-10-16 13:04:27 -07001980 }
1981
Ying Wangef3998f2019-12-09 13:06:53 +01001982 EXPECT_METRIC_EQ(0, webrtc::metrics::NumEvents(
1983 "WebRTC.PeerConnection.CandidatePairType_UDP",
1984 webrtc::kIceCandidatePairHostHost));
1985 EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(
1986 "WebRTC.PeerConnection.CandidatePairType_UDP",
1987 webrtc::kIceCandidatePairHostPublicHostPublic));
Steve Antonede9ca52017-10-16 13:04:27 -07001988}
1989
1990constexpr uint32_t kFlagsIPv4NoStun = cricket::PORTALLOCATOR_DISABLE_TCP |
1991 cricket::PORTALLOCATOR_DISABLE_STUN |
1992 cricket::PORTALLOCATOR_DISABLE_RELAY;
1993constexpr uint32_t kFlagsIPv6NoStun =
1994 cricket::PORTALLOCATOR_DISABLE_TCP | cricket::PORTALLOCATOR_DISABLE_STUN |
1995 cricket::PORTALLOCATOR_ENABLE_IPV6 | cricket::PORTALLOCATOR_DISABLE_RELAY;
1996constexpr uint32_t kFlagsIPv4Stun =
1997 cricket::PORTALLOCATOR_DISABLE_TCP | cricket::PORTALLOCATOR_DISABLE_RELAY;
1998
Mirko Bonadeic84f6612019-01-31 12:20:57 +01001999INSTANTIATE_TEST_SUITE_P(
Seth Hampson2f0d7022018-02-20 11:54:42 -08002000 PeerConnectionIntegrationTest,
2001 PeerConnectionIntegrationIceStatesTest,
Florent Castelli15a38de2022-04-06 00:38:21 +02002002 Combine(Values(SdpSemantics::kPlanB_DEPRECATED, SdpSemantics::kUnifiedPlan),
Seth Hampson2f0d7022018-02-20 11:54:42 -08002003 Values(std::make_pair("IPv4 no STUN", kFlagsIPv4NoStun),
2004 std::make_pair("IPv6 no STUN", kFlagsIPv6NoStun),
2005 std::make_pair("IPv4 with STUN", kFlagsIPv4Stun))));
Steve Antonede9ca52017-10-16 13:04:27 -07002006
Yves Gerey100fe632020-01-17 19:15:53 +01002007INSTANTIATE_TEST_SUITE_P(
2008 PeerConnectionIntegrationTest,
2009 PeerConnectionIntegrationIceStatesTestWithFakeClock,
Florent Castelli15a38de2022-04-06 00:38:21 +02002010 Combine(Values(SdpSemantics::kPlanB_DEPRECATED, SdpSemantics::kUnifiedPlan),
Yves Gerey100fe632020-01-17 19:15:53 +01002011 Values(std::make_pair("IPv4 no STUN", kFlagsIPv4NoStun),
2012 std::make_pair("IPv6 no STUN", kFlagsIPv6NoStun),
2013 std::make_pair("IPv4 with STUN", kFlagsIPv4Stun))));
2014
deadbeef1dcb1642017-03-29 21:08:16 -07002015// This test sets up a call between two parties with audio and video.
2016// During the call, the caller restarts ICE and the test verifies that
2017// new ICE candidates are generated and audio and video still can flow, and the
2018// ICE state reaches completed again.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002019TEST_P(PeerConnectionIntegrationTest, MediaContinuesFlowingAfterIceRestart) {
deadbeef1dcb1642017-03-29 21:08:16 -07002020 ASSERT_TRUE(CreatePeerConnectionWrappers());
2021 ConnectFakeSignaling();
2022 // Do normal offer/answer and wait for ICE to complete.
Steve Anton15324772018-01-16 10:26:49 -08002023 caller()->AddAudioVideoTracks();
2024 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07002025 caller()->CreateAndSetAndSignalOffer();
2026 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2027 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
2028 caller()->ice_connection_state(), kMaxWaitForFramesMs);
Alex Loiko9289eda2018-11-23 16:18:59 +00002029 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
2030 callee()->ice_connection_state(), kMaxWaitForFramesMs);
deadbeef1dcb1642017-03-29 21:08:16 -07002031
2032 // To verify that the ICE restart actually occurs, get
2033 // ufrag/password/candidates before and after restart.
2034 // Create an SDP string of the first audio candidate for both clients.
2035 const webrtc::IceCandidateCollection* audio_candidates_caller =
2036 caller()->pc()->local_description()->candidates(0);
2037 const webrtc::IceCandidateCollection* audio_candidates_callee =
2038 callee()->pc()->local_description()->candidates(0);
2039 ASSERT_GT(audio_candidates_caller->count(), 0u);
2040 ASSERT_GT(audio_candidates_callee->count(), 0u);
2041 std::string caller_candidate_pre_restart;
2042 ASSERT_TRUE(
2043 audio_candidates_caller->at(0)->ToString(&caller_candidate_pre_restart));
2044 std::string callee_candidate_pre_restart;
2045 ASSERT_TRUE(
2046 audio_candidates_callee->at(0)->ToString(&callee_candidate_pre_restart));
2047 const cricket::SessionDescription* desc =
2048 caller()->pc()->local_description()->description();
2049 std::string caller_ufrag_pre_restart =
2050 desc->transport_infos()[0].description.ice_ufrag;
2051 desc = callee()->pc()->local_description()->description();
2052 std::string callee_ufrag_pre_restart =
2053 desc->transport_infos()[0].description.ice_ufrag;
2054
Alex Drake00c7ecf2019-08-06 10:54:47 -07002055 EXPECT_EQ(caller()->ice_candidate_pair_change_history().size(), 1u);
deadbeef1dcb1642017-03-29 21:08:16 -07002056 // Have the caller initiate an ICE restart.
2057 caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions());
2058 caller()->CreateAndSetAndSignalOffer();
2059 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2060 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
2061 caller()->ice_connection_state(), kMaxWaitForFramesMs);
Alex Loiko9289eda2018-11-23 16:18:59 +00002062 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
deadbeef1dcb1642017-03-29 21:08:16 -07002063 callee()->ice_connection_state(), kMaxWaitForFramesMs);
2064
2065 // Grab the ufrags/candidates again.
2066 audio_candidates_caller = caller()->pc()->local_description()->candidates(0);
2067 audio_candidates_callee = callee()->pc()->local_description()->candidates(0);
2068 ASSERT_GT(audio_candidates_caller->count(), 0u);
2069 ASSERT_GT(audio_candidates_callee->count(), 0u);
2070 std::string caller_candidate_post_restart;
2071 ASSERT_TRUE(
2072 audio_candidates_caller->at(0)->ToString(&caller_candidate_post_restart));
2073 std::string callee_candidate_post_restart;
2074 ASSERT_TRUE(
2075 audio_candidates_callee->at(0)->ToString(&callee_candidate_post_restart));
2076 desc = caller()->pc()->local_description()->description();
2077 std::string caller_ufrag_post_restart =
2078 desc->transport_infos()[0].description.ice_ufrag;
2079 desc = callee()->pc()->local_description()->description();
2080 std::string callee_ufrag_post_restart =
2081 desc->transport_infos()[0].description.ice_ufrag;
2082 // Sanity check that an ICE restart was actually negotiated in SDP.
2083 ASSERT_NE(caller_candidate_pre_restart, caller_candidate_post_restart);
2084 ASSERT_NE(callee_candidate_pre_restart, callee_candidate_post_restart);
2085 ASSERT_NE(caller_ufrag_pre_restart, caller_ufrag_post_restart);
2086 ASSERT_NE(callee_ufrag_pre_restart, callee_ufrag_post_restart);
Alex Drake00c7ecf2019-08-06 10:54:47 -07002087 EXPECT_GT(caller()->ice_candidate_pair_change_history().size(), 1u);
deadbeef1dcb1642017-03-29 21:08:16 -07002088
2089 // Ensure that additional frames are received after the ICE restart.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002090 MediaExpectations media_expectations;
2091 media_expectations.ExpectBidirectionalAudioAndVideo();
2092 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07002093}
2094
2095// Verify that audio/video can be received end-to-end when ICE renomination is
2096// enabled.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002097TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithIceRenomination) {
deadbeef1dcb1642017-03-29 21:08:16 -07002098 PeerConnectionInterface::RTCConfiguration config;
2099 config.enable_ice_renomination = true;
2100 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config));
2101 ConnectFakeSignaling();
2102 // Do normal offer/answer and wait for some frames to be received in each
2103 // direction.
Steve Anton15324772018-01-16 10:26:49 -08002104 caller()->AddAudioVideoTracks();
2105 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07002106 caller()->CreateAndSetAndSignalOffer();
2107 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2108 // Sanity check that ICE renomination was actually negotiated.
2109 const cricket::SessionDescription* desc =
2110 caller()->pc()->local_description()->description();
2111 for (const cricket::TransportInfo& info : desc->transport_infos()) {
Steve Anton64b626b2019-01-28 17:25:26 -08002112 ASSERT_THAT(info.description.transport_options, Contains("renomination"));
deadbeef1dcb1642017-03-29 21:08:16 -07002113 }
2114 desc = callee()->pc()->local_description()->description();
2115 for (const cricket::TransportInfo& info : desc->transport_infos()) {
Steve Anton64b626b2019-01-28 17:25:26 -08002116 ASSERT_THAT(info.description.transport_options, Contains("renomination"));
deadbeef1dcb1642017-03-29 21:08:16 -07002117 }
Seth Hampson2f0d7022018-02-20 11:54:42 -08002118 MediaExpectations media_expectations;
2119 media_expectations.ExpectBidirectionalAudioAndVideo();
2120 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07002121}
2122
Steve Anton6f25b092017-10-23 09:39:20 -07002123// With a max bundle policy and RTCP muxing, adding a new media description to
2124// the connection should not affect ICE at all because the new media will use
2125// the existing connection.
Rasmus Brandt685be142021-03-15 14:03:38 +01002126// TODO(bugs.webrtc.org/12538): Fails on tsan.
2127#if defined(THREAD_SANITIZER)
2128#define MAYBE_AddMediaToConnectedBundleDoesNotRestartIce \
2129 DISABLED_AddMediaToConnectedBundleDoesNotRestartIce
2130#else
2131#define MAYBE_AddMediaToConnectedBundleDoesNotRestartIce \
2132 AddMediaToConnectedBundleDoesNotRestartIce
2133#endif
Seth Hampson2f0d7022018-02-20 11:54:42 -08002134TEST_P(PeerConnectionIntegrationTest,
Rasmus Brandt685be142021-03-15 14:03:38 +01002135 MAYBE_AddMediaToConnectedBundleDoesNotRestartIce) {
Steve Anton6f25b092017-10-23 09:39:20 -07002136 PeerConnectionInterface::RTCConfiguration config;
2137 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
2138 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire;
2139 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(
2140 config, PeerConnectionInterface::RTCConfiguration()));
2141 ConnectFakeSignaling();
2142
Steve Anton15324772018-01-16 10:26:49 -08002143 caller()->AddAudioTrack();
Steve Anton6f25b092017-10-23 09:39:20 -07002144 caller()->CreateAndSetAndSignalOffer();
2145 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Steve Antonff52f1b2017-10-26 12:24:50 -07002146 ASSERT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
2147 caller()->ice_connection_state(), kDefaultTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07002148
2149 caller()->clear_ice_connection_state_history();
2150
Steve Anton15324772018-01-16 10:26:49 -08002151 caller()->AddVideoTrack();
Steve Anton6f25b092017-10-23 09:39:20 -07002152 caller()->CreateAndSetAndSignalOffer();
2153 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2154
2155 EXPECT_EQ(0u, caller()->ice_connection_state_history().size());
2156}
2157
deadbeef1dcb1642017-03-29 21:08:16 -07002158// This test sets up a call between two parties with audio and video. It then
2159// renegotiates setting the video m-line to "port 0", then later renegotiates
2160// again, enabling video.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002161TEST_P(PeerConnectionIntegrationTest,
deadbeef1dcb1642017-03-29 21:08:16 -07002162 VideoFlowsAfterMediaSectionIsRejectedAndRecycled) {
2163 ASSERT_TRUE(CreatePeerConnectionWrappers());
2164 ConnectFakeSignaling();
2165
2166 // Do initial negotiation, only sending media from the caller. Will result in
2167 // video and audio recvonly "m=" sections.
Steve Anton15324772018-01-16 10:26:49 -08002168 caller()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07002169 caller()->CreateAndSetAndSignalOffer();
2170 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2171
2172 // Negotiate again, disabling the video "m=" section (the callee will set the
2173 // port to 0 due to offer_to_receive_video = 0).
Florent Castelli15a38de2022-04-06 00:38:21 +02002174 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Seth Hampson2f0d7022018-02-20 11:54:42 -08002175 PeerConnectionInterface::RTCOfferAnswerOptions options;
2176 options.offer_to_receive_video = 0;
2177 callee()->SetOfferAnswerOptions(options);
2178 } else {
2179 callee()->SetRemoteOfferHandler([this] {
Harald Alvestrand6060df52020-08-11 09:54:02 +02002180 callee()
2181 ->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)
2182 ->StopInternal();
Seth Hampson2f0d7022018-02-20 11:54:42 -08002183 });
2184 }
deadbeef1dcb1642017-03-29 21:08:16 -07002185 caller()->CreateAndSetAndSignalOffer();
2186 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2187 // Sanity check that video "m=" section was actually rejected.
2188 const ContentInfo* answer_video_content = cricket::GetFirstVideoContent(
2189 callee()->pc()->local_description()->description());
2190 ASSERT_NE(nullptr, answer_video_content);
2191 ASSERT_TRUE(answer_video_content->rejected);
2192
2193 // Enable video and do negotiation again, making sure video is received
2194 // end-to-end, also adding media stream to callee.
Florent Castelli15a38de2022-04-06 00:38:21 +02002195 if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
Seth Hampson2f0d7022018-02-20 11:54:42 -08002196 PeerConnectionInterface::RTCOfferAnswerOptions options;
2197 options.offer_to_receive_video = 1;
2198 callee()->SetOfferAnswerOptions(options);
2199 } else {
2200 // The caller's transceiver is stopped, so we need to add another track.
2201 auto caller_transceiver =
2202 caller()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO);
Harald Alvestrand6060df52020-08-11 09:54:02 +02002203 EXPECT_EQ(nullptr, caller_transceiver.get());
Seth Hampson2f0d7022018-02-20 11:54:42 -08002204 caller()->AddVideoTrack();
2205 }
2206 callee()->AddVideoTrack();
2207 callee()->SetRemoteOfferHandler(nullptr);
deadbeef1dcb1642017-03-29 21:08:16 -07002208 caller()->CreateAndSetAndSignalOffer();
2209 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002210
deadbeef1dcb1642017-03-29 21:08:16 -07002211 // Verify the caller receives frames from the newly added stream, and the
2212 // callee receives additional frames from the re-enabled video m= section.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002213 MediaExpectations media_expectations;
2214 media_expectations.CalleeExpectsSomeAudio();
2215 media_expectations.ExpectBidirectionalVideo();
2216 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07002217}
2218
deadbeef1dcb1642017-03-29 21:08:16 -07002219// This tests that if we negotiate after calling CreateSender but before we
2220// have a track, then set a track later, frames from the newly-set track are
2221// received end-to-end.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002222TEST_F(PeerConnectionIntegrationTestPlanB,
deadbeef1dcb1642017-03-29 21:08:16 -07002223 MediaFlowsAfterEarlyWarmupWithCreateSender) {
2224 ASSERT_TRUE(CreatePeerConnectionWrappers());
2225 ConnectFakeSignaling();
2226 auto caller_audio_sender =
2227 caller()->pc()->CreateSender("audio", "caller_stream");
2228 auto caller_video_sender =
2229 caller()->pc()->CreateSender("video", "caller_stream");
2230 auto callee_audio_sender =
2231 callee()->pc()->CreateSender("audio", "callee_stream");
2232 auto callee_video_sender =
2233 callee()->pc()->CreateSender("video", "callee_stream");
2234 caller()->CreateAndSetAndSignalOffer();
2235 ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs);
2236 // Wait for ICE to complete, without any tracks being set.
2237 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
2238 caller()->ice_connection_state(), kMaxWaitForFramesMs);
2239 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
2240 callee()->ice_connection_state(), kMaxWaitForFramesMs);
2241 // Now set the tracks, and expect frames to immediately start flowing.
Niels Möllerafb246b2022-04-20 14:26:50 +02002242 EXPECT_TRUE(
2243 caller_audio_sender->SetTrack(caller()->CreateLocalAudioTrack().get()));
2244 EXPECT_TRUE(
2245 caller_video_sender->SetTrack(caller()->CreateLocalVideoTrack().get()));
2246 EXPECT_TRUE(
2247 callee_audio_sender->SetTrack(callee()->CreateLocalAudioTrack().get()));
2248 EXPECT_TRUE(
2249 callee_video_sender->SetTrack(callee()->CreateLocalVideoTrack().get()));
Seth Hampson2f0d7022018-02-20 11:54:42 -08002250 MediaExpectations media_expectations;
2251 media_expectations.ExpectBidirectionalAudioAndVideo();
2252 ASSERT_TRUE(ExpectNewFrames(media_expectations));
2253}
2254
2255// This tests that if we negotiate after calling AddTransceiver but before we
2256// have a track, then set a track later, frames from the newly-set tracks are
2257// received end-to-end.
2258TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
2259 MediaFlowsAfterEarlyWarmupWithAddTransceiver) {
2260 ASSERT_TRUE(CreatePeerConnectionWrappers());
2261 ConnectFakeSignaling();
2262 auto audio_result = caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_AUDIO);
2263 ASSERT_EQ(RTCErrorType::NONE, audio_result.error().type());
2264 auto caller_audio_sender = audio_result.MoveValue()->sender();
2265 auto video_result = caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_VIDEO);
2266 ASSERT_EQ(RTCErrorType::NONE, video_result.error().type());
2267 auto caller_video_sender = video_result.MoveValue()->sender();
2268 callee()->SetRemoteOfferHandler([this] {
2269 ASSERT_EQ(2u, callee()->pc()->GetTransceivers().size());
Harald Alvestrand6060df52020-08-11 09:54:02 +02002270 callee()->pc()->GetTransceivers()[0]->SetDirectionWithError(
Seth Hampson2f0d7022018-02-20 11:54:42 -08002271 RtpTransceiverDirection::kSendRecv);
Harald Alvestrand6060df52020-08-11 09:54:02 +02002272 callee()->pc()->GetTransceivers()[1]->SetDirectionWithError(
Seth Hampson2f0d7022018-02-20 11:54:42 -08002273 RtpTransceiverDirection::kSendRecv);
2274 });
2275 caller()->CreateAndSetAndSignalOffer();
2276 ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs);
2277 // Wait for ICE to complete, without any tracks being set.
2278 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
2279 caller()->ice_connection_state(), kMaxWaitForFramesMs);
2280 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
2281 callee()->ice_connection_state(), kMaxWaitForFramesMs);
2282 // Now set the tracks, and expect frames to immediately start flowing.
2283 auto callee_audio_sender = callee()->pc()->GetSenders()[0];
2284 auto callee_video_sender = callee()->pc()->GetSenders()[1];
Niels Möllerafb246b2022-04-20 14:26:50 +02002285 ASSERT_TRUE(
2286 caller_audio_sender->SetTrack(caller()->CreateLocalAudioTrack().get()));
2287 ASSERT_TRUE(
2288 caller_video_sender->SetTrack(caller()->CreateLocalVideoTrack().get()));
2289 ASSERT_TRUE(
2290 callee_audio_sender->SetTrack(callee()->CreateLocalAudioTrack().get()));
2291 ASSERT_TRUE(
2292 callee_video_sender->SetTrack(callee()->CreateLocalVideoTrack().get()));
Seth Hampson2f0d7022018-02-20 11:54:42 -08002293 MediaExpectations media_expectations;
2294 media_expectations.ExpectBidirectionalAudioAndVideo();
2295 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07002296}
2297
2298// This test verifies that a remote video track can be added via AddStream,
2299// and sent end-to-end. For this particular test, it's simply echoed back
2300// from the caller to the callee, rather than being forwarded to a third
2301// PeerConnection.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002302TEST_F(PeerConnectionIntegrationTestPlanB, CanSendRemoteVideoTrack) {
deadbeef1dcb1642017-03-29 21:08:16 -07002303 ASSERT_TRUE(CreatePeerConnectionWrappers());
2304 ConnectFakeSignaling();
2305 // Just send a video track from the caller.
Steve Anton15324772018-01-16 10:26:49 -08002306 caller()->AddVideoTrack();
deadbeef1dcb1642017-03-29 21:08:16 -07002307 caller()->CreateAndSetAndSignalOffer();
2308 ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02002309 ASSERT_EQ(1U, callee()->remote_streams()->count());
deadbeef1dcb1642017-03-29 21:08:16 -07002310
2311 // Echo the stream back, and do a new offer/anwer (initiated by callee this
2312 // time).
2313 callee()->pc()->AddStream(callee()->remote_streams()->at(0));
2314 callee()->CreateAndSetAndSignalOffer();
2315 ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs);
2316
Seth Hampson2f0d7022018-02-20 11:54:42 -08002317 MediaExpectations media_expectations;
2318 media_expectations.ExpectBidirectionalVideo();
2319 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07002320}
2321
Harald Alvestrandec23d6d2021-02-11 10:47:22 +00002322#if !defined(THREAD_SANITIZER)
2323// This test provokes TSAN errors. bugs.webrtc.org/11282
2324
deadbeef1dcb1642017-03-29 21:08:16 -07002325// Test that we achieve the expected end-to-end connection time, using a
2326// fake clock and simulated latency on the media and signaling paths.
2327// We use a TURN<->TURN connection because this is usually the quickest to
2328// set up initially, especially when we're confident the connection will work
2329// and can start sending media before we get a STUN response.
2330//
2331// With various optimizations enabled, here are the network delays we expect to
2332// be on the critical path:
2333// 1. 2 signaling trips: Signaling offer and offerer's TURN candidate, then
2334// signaling answer (with DTLS fingerprint).
2335// 2. 9 media hops: Rest of the DTLS handshake. 3 hops in each direction when
2336// using TURN<->TURN pair, and DTLS exchange is 4 packets,
2337// the first of which should have arrived before the answer.
Yves Gerey100fe632020-01-17 19:15:53 +01002338TEST_P(PeerConnectionIntegrationTestWithFakeClock,
2339 EndToEndConnectionTimeWithTurnTurnPair) {
deadbeef1dcb1642017-03-29 21:08:16 -07002340 static constexpr int media_hop_delay_ms = 50;
2341 static constexpr int signaling_trip_delay_ms = 500;
2342 // For explanation of these values, see comment above.
2343 static constexpr int required_media_hops = 9;
2344 static constexpr int required_signaling_trips = 2;
2345 // For internal delays (such as posting an event asychronously).
2346 static constexpr int allowed_internal_delay_ms = 20;
2347 static constexpr int total_connection_time_ms =
2348 media_hop_delay_ms * required_media_hops +
2349 signaling_trip_delay_ms * required_signaling_trips +
2350 allowed_internal_delay_ms;
2351
2352 static const rtc::SocketAddress turn_server_1_internal_address{"88.88.88.0",
2353 3478};
2354 static const rtc::SocketAddress turn_server_1_external_address{"88.88.88.1",
2355 0};
2356 static const rtc::SocketAddress turn_server_2_internal_address{"99.99.99.0",
2357 3478};
2358 static const rtc::SocketAddress turn_server_2_external_address{"99.99.99.1",
2359 0};
Seth Hampsonaed71642018-06-11 07:41:32 -07002360 cricket::TestTurnServer* turn_server_1 = CreateTurnServer(
2361 turn_server_1_internal_address, turn_server_1_external_address);
Jonas Orelandbdcee282017-10-10 14:01:40 +02002362
Seth Hampsonaed71642018-06-11 07:41:32 -07002363 cricket::TestTurnServer* turn_server_2 = CreateTurnServer(
2364 turn_server_2_internal_address, turn_server_2_external_address);
deadbeef1dcb1642017-03-29 21:08:16 -07002365 // Bypass permission check on received packets so media can be sent before
2366 // the candidate is signaled.
Danil Chapovalov2aaef452022-08-12 15:55:11 +02002367 SendTask(network_thread(), [turn_server_1] {
Seth Hampsonaed71642018-06-11 07:41:32 -07002368 turn_server_1->set_enable_permission_checks(false);
2369 });
Danil Chapovalov2aaef452022-08-12 15:55:11 +02002370 SendTask(network_thread(), [turn_server_2] {
Seth Hampsonaed71642018-06-11 07:41:32 -07002371 turn_server_2->set_enable_permission_checks(false);
2372 });
deadbeef1dcb1642017-03-29 21:08:16 -07002373
2374 PeerConnectionInterface::RTCConfiguration client_1_config;
2375 webrtc::PeerConnectionInterface::IceServer ice_server_1;
2376 ice_server_1.urls.push_back("turn:88.88.88.0:3478");
2377 ice_server_1.username = "test";
2378 ice_server_1.password = "test";
2379 client_1_config.servers.push_back(ice_server_1);
2380 client_1_config.type = webrtc::PeerConnectionInterface::kRelay;
2381 client_1_config.presume_writable_when_fully_relayed = true;
2382
2383 PeerConnectionInterface::RTCConfiguration client_2_config;
2384 webrtc::PeerConnectionInterface::IceServer ice_server_2;
2385 ice_server_2.urls.push_back("turn:99.99.99.0:3478");
2386 ice_server_2.username = "test";
2387 ice_server_2.password = "test";
2388 client_2_config.servers.push_back(ice_server_2);
2389 client_2_config.type = webrtc::PeerConnectionInterface::kRelay;
2390 client_2_config.presume_writable_when_fully_relayed = true;
2391
2392 ASSERT_TRUE(
2393 CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config));
2394 // Set up the simulated delays.
2395 SetSignalingDelayMs(signaling_trip_delay_ms);
2396 ConnectFakeSignaling();
2397 virtual_socket_server()->set_delay_mean(media_hop_delay_ms);
2398 virtual_socket_server()->UpdateDelayDistribution();
2399
2400 // Set "offer to receive audio/video" without adding any tracks, so we just
2401 // set up ICE/DTLS with no media.
2402 PeerConnectionInterface::RTCOfferAnswerOptions options;
2403 options.offer_to_receive_audio = 1;
2404 options.offer_to_receive_video = 1;
2405 caller()->SetOfferAnswerOptions(options);
2406 caller()->CreateAndSetAndSignalOffer();
deadbeef71452802017-05-07 17:21:01 -07002407 EXPECT_TRUE_SIMULATED_WAIT(DtlsConnected(), total_connection_time_ms,
Yves Gerey100fe632020-01-17 19:15:53 +01002408 FakeClock());
Seth Hampson1d4a76d2018-06-19 14:31:41 -07002409 // Closing the PeerConnections destroys the ports before the ScopedFakeClock.
2410 // If this is not done a DCHECK can be hit in ports.cc, because a large
2411 // negative number is calculated for the rtt due to the global clock changing.
Steve Antond91969e2019-05-30 12:27:03 -07002412 ClosePeerConnections();
deadbeef1dcb1642017-03-29 21:08:16 -07002413}
2414
Philipp Hancke1fe14f22022-06-17 11:34:31 +02002415TEST_P(PeerConnectionIntegrationTestWithFakeClock,
2416 OnIceCandidateFlushesGetStatsCache) {
2417 ASSERT_TRUE(CreatePeerConnectionWrappers());
2418 ConnectFakeSignaling();
2419 caller()->AddAudioTrack();
2420
2421 // Call getStats, assert there are no candidates.
2422 rtc::scoped_refptr<const webrtc::RTCStatsReport> first_report =
2423 caller()->NewGetStats();
2424 ASSERT_TRUE(first_report);
2425 auto first_candidate_stats =
2426 first_report->GetStatsOfType<webrtc::RTCLocalIceCandidateStats>();
2427 ASSERT_EQ(first_candidate_stats.size(), 0u);
2428
Philipp Hanckea09b9212022-06-22 07:41:22 +02002429 // Create an offer at the caller and set it as remote description on the
2430 // callee.
Philipp Hancke1fe14f22022-06-17 11:34:31 +02002431 caller()->CreateAndSetAndSignalOffer();
Philipp Hancke1fe14f22022-06-17 11:34:31 +02002432 // Call getStats again, assert there are candidates now.
2433 rtc::scoped_refptr<const webrtc::RTCStatsReport> second_report =
2434 caller()->NewGetStats();
2435 ASSERT_TRUE(second_report);
2436 auto second_candidate_stats =
2437 second_report->GetStatsOfType<webrtc::RTCLocalIceCandidateStats>();
2438 ASSERT_NE(second_candidate_stats.size(), 0u);
2439
2440 // The fake clock ensures that no time has passed so the cache must have been
2441 // explicitly invalidated.
2442 EXPECT_EQ(first_report->timestamp_us(), second_report->timestamp_us());
2443}
2444
Philipp Hanckea09b9212022-06-22 07:41:22 +02002445TEST_P(PeerConnectionIntegrationTestWithFakeClock,
2446 AddIceCandidateFlushesGetStatsCache) {
2447 ASSERT_TRUE(CreatePeerConnectionWrappers());
2448 ConnectFakeSignalingForSdpOnly();
2449 caller()->AddAudioTrack();
2450
2451 // Start candidate gathering and wait for it to complete. Candidates are not
2452 // signalled.
2453 caller()->CreateAndSetAndSignalOffer();
2454 ASSERT_TRUE_SIMULATED_WAIT(caller()->IceGatheringStateComplete(),
2455 kDefaultTimeout, FakeClock());
2456
2457 // Call getStats, assert there are no candidates.
2458 rtc::scoped_refptr<const webrtc::RTCStatsReport> first_report =
2459 caller()->NewGetStats();
2460 ASSERT_TRUE(first_report);
2461 auto first_candidate_stats =
2462 first_report->GetStatsOfType<webrtc::RTCRemoteIceCandidateStats>();
2463 ASSERT_EQ(first_candidate_stats.size(), 0u);
2464
2465 // Add a "fake" candidate.
2466 absl::optional<RTCError> result;
2467 caller()->pc()->AddIceCandidate(
2468 absl::WrapUnique(webrtc::CreateIceCandidate(
2469 "", 0,
2470 "candidate:2214029314 1 udp 2122260223 127.0.0.1 49152 typ host",
2471 nullptr)),
2472 [&result](RTCError r) { result = r; });
2473 ASSERT_TRUE_WAIT(result.has_value(), kDefaultTimeout);
2474 ASSERT_TRUE(result.value().ok());
2475
2476 // Call getStats again, assert there is a remote candidate now.
2477 rtc::scoped_refptr<const webrtc::RTCStatsReport> second_report =
2478 caller()->NewGetStats();
2479 ASSERT_TRUE(second_report);
2480 auto second_candidate_stats =
2481 second_report->GetStatsOfType<webrtc::RTCRemoteIceCandidateStats>();
2482 ASSERT_EQ(second_candidate_stats.size(), 1u);
2483
2484 // The fake clock ensures that no time has passed so the cache must have been
2485 // explicitly invalidated.
2486 EXPECT_EQ(first_report->timestamp_us(), second_report->timestamp_us());
2487}
2488
Harald Alvestrandec23d6d2021-02-11 10:47:22 +00002489#endif // !defined(THREAD_SANITIZER)
2490
Jonas Orelandbdcee282017-10-10 14:01:40 +02002491// Verify that a TurnCustomizer passed in through RTCConfiguration
2492// is actually used by the underlying TURN candidate pair.
2493// Note that turnport_unittest.cc contains more detailed, lower-level tests.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002494TEST_P(PeerConnectionIntegrationTest, TurnCustomizerUsedForTurnConnections) {
Jonas Orelandbdcee282017-10-10 14:01:40 +02002495 static const rtc::SocketAddress turn_server_1_internal_address{"88.88.88.0",
2496 3478};
2497 static const rtc::SocketAddress turn_server_1_external_address{"88.88.88.1",
2498 0};
2499 static const rtc::SocketAddress turn_server_2_internal_address{"99.99.99.0",
2500 3478};
2501 static const rtc::SocketAddress turn_server_2_external_address{"99.99.99.1",
2502 0};
Seth Hampsonaed71642018-06-11 07:41:32 -07002503 CreateTurnServer(turn_server_1_internal_address,
2504 turn_server_1_external_address);
2505 CreateTurnServer(turn_server_2_internal_address,
2506 turn_server_2_external_address);
Jonas Orelandbdcee282017-10-10 14:01:40 +02002507
2508 PeerConnectionInterface::RTCConfiguration client_1_config;
2509 webrtc::PeerConnectionInterface::IceServer ice_server_1;
2510 ice_server_1.urls.push_back("turn:88.88.88.0:3478");
2511 ice_server_1.username = "test";
2512 ice_server_1.password = "test";
2513 client_1_config.servers.push_back(ice_server_1);
2514 client_1_config.type = webrtc::PeerConnectionInterface::kRelay;
Seth Hampsonaed71642018-06-11 07:41:32 -07002515 auto* customizer1 = CreateTurnCustomizer();
2516 client_1_config.turn_customizer = customizer1;
Jonas Orelandbdcee282017-10-10 14:01:40 +02002517
2518 PeerConnectionInterface::RTCConfiguration client_2_config;
2519 webrtc::PeerConnectionInterface::IceServer ice_server_2;
2520 ice_server_2.urls.push_back("turn:99.99.99.0:3478");
2521 ice_server_2.username = "test";
2522 ice_server_2.password = "test";
2523 client_2_config.servers.push_back(ice_server_2);
2524 client_2_config.type = webrtc::PeerConnectionInterface::kRelay;
Seth Hampsonaed71642018-06-11 07:41:32 -07002525 auto* customizer2 = CreateTurnCustomizer();
2526 client_2_config.turn_customizer = customizer2;
Jonas Orelandbdcee282017-10-10 14:01:40 +02002527
2528 ASSERT_TRUE(
2529 CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config));
2530 ConnectFakeSignaling();
2531
2532 // Set "offer to receive audio/video" without adding any tracks, so we just
2533 // set up ICE/DTLS with no media.
2534 PeerConnectionInterface::RTCOfferAnswerOptions options;
2535 options.offer_to_receive_audio = 1;
2536 options.offer_to_receive_video = 1;
2537 caller()->SetOfferAnswerOptions(options);
2538 caller()->CreateAndSetAndSignalOffer();
2539 ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout);
2540
Seth Hampsonaed71642018-06-11 07:41:32 -07002541 ExpectTurnCustomizerCountersIncremented(customizer1);
2542 ExpectTurnCustomizerCountersIncremented(customizer2);
Jonas Orelandbdcee282017-10-10 14:01:40 +02002543}
2544
Benjamin Wright2d5f3cb2018-05-22 14:46:06 -07002545// Verifies that you can use TCP instead of UDP to connect to a TURN server and
2546// send media between the caller and the callee.
2547TEST_P(PeerConnectionIntegrationTest, TCPUsedForTurnConnections) {
2548 static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0",
2549 3478};
2550 static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0};
2551
2552 // Enable TCP for the fake turn server.
Seth Hampsonaed71642018-06-11 07:41:32 -07002553 CreateTurnServer(turn_server_internal_address, turn_server_external_address,
2554 cricket::PROTO_TCP);
Benjamin Wright2d5f3cb2018-05-22 14:46:06 -07002555
2556 webrtc::PeerConnectionInterface::IceServer ice_server;
2557 ice_server.urls.push_back("turn:88.88.88.0:3478?transport=tcp");
2558 ice_server.username = "test";
2559 ice_server.password = "test";
2560
2561 PeerConnectionInterface::RTCConfiguration client_1_config;
2562 client_1_config.servers.push_back(ice_server);
2563 client_1_config.type = webrtc::PeerConnectionInterface::kRelay;
2564
2565 PeerConnectionInterface::RTCConfiguration client_2_config;
2566 client_2_config.servers.push_back(ice_server);
2567 client_2_config.type = webrtc::PeerConnectionInterface::kRelay;
2568
2569 ASSERT_TRUE(
2570 CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config));
2571
2572 // Do normal offer/answer and wait for ICE to complete.
2573 ConnectFakeSignaling();
2574 caller()->AddAudioVideoTracks();
2575 callee()->AddAudioVideoTracks();
2576 caller()->CreateAndSetAndSignalOffer();
2577 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2578 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
2579 callee()->ice_connection_state(), kMaxWaitForFramesMs);
2580
2581 MediaExpectations media_expectations;
2582 media_expectations.ExpectBidirectionalAudioAndVideo();
2583 EXPECT_TRUE(ExpectNewFrames(media_expectations));
2584}
2585
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07002586// Verify that a SSLCertificateVerifier passed in through
2587// PeerConnectionDependencies is actually used by the underlying SSL
2588// implementation to determine whether a certificate presented by the TURN
2589// server is accepted by the client. Note that openssladapter_unittest.cc
2590// contains more detailed, lower-level tests.
2591TEST_P(PeerConnectionIntegrationTest,
2592 SSLCertificateVerifierUsedForTurnConnections) {
2593 static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0",
2594 3478};
2595 static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0};
2596
2597 // Enable TCP-TLS for the fake turn server. We need to pass in 88.88.88.0 so
2598 // that host name verification passes on the fake certificate.
Seth Hampsonaed71642018-06-11 07:41:32 -07002599 CreateTurnServer(turn_server_internal_address, turn_server_external_address,
2600 cricket::PROTO_TLS, "88.88.88.0");
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07002601
2602 webrtc::PeerConnectionInterface::IceServer ice_server;
2603 ice_server.urls.push_back("turns:88.88.88.0:3478?transport=tcp");
2604 ice_server.username = "test";
2605 ice_server.password = "test";
2606
2607 PeerConnectionInterface::RTCConfiguration client_1_config;
2608 client_1_config.servers.push_back(ice_server);
2609 client_1_config.type = webrtc::PeerConnectionInterface::kRelay;
2610
2611 PeerConnectionInterface::RTCConfiguration client_2_config;
2612 client_2_config.servers.push_back(ice_server);
2613 // Setting the type to kRelay forces the connection to go through a TURN
2614 // server.
2615 client_2_config.type = webrtc::PeerConnectionInterface::kRelay;
2616
2617 // Get a copy to the pointer so we can verify calls later.
2618 rtc::TestCertificateVerifier* client_1_cert_verifier =
2619 new rtc::TestCertificateVerifier();
2620 client_1_cert_verifier->verify_certificate_ = true;
2621 rtc::TestCertificateVerifier* client_2_cert_verifier =
2622 new rtc::TestCertificateVerifier();
2623 client_2_cert_verifier->verify_certificate_ = true;
2624
2625 // Create the dependencies with the test certificate verifier.
2626 webrtc::PeerConnectionDependencies client_1_deps(nullptr);
2627 client_1_deps.tls_cert_verifier =
2628 std::unique_ptr<rtc::TestCertificateVerifier>(client_1_cert_verifier);
2629 webrtc::PeerConnectionDependencies client_2_deps(nullptr);
2630 client_2_deps.tls_cert_verifier =
2631 std::unique_ptr<rtc::TestCertificateVerifier>(client_2_cert_verifier);
2632
2633 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps(
2634 client_1_config, std::move(client_1_deps), client_2_config,
2635 std::move(client_2_deps)));
2636 ConnectFakeSignaling();
2637
2638 // Set "offer to receive audio/video" without adding any tracks, so we just
2639 // set up ICE/DTLS with no media.
2640 PeerConnectionInterface::RTCOfferAnswerOptions options;
2641 options.offer_to_receive_audio = 1;
2642 options.offer_to_receive_video = 1;
2643 caller()->SetOfferAnswerOptions(options);
2644 caller()->CreateAndSetAndSignalOffer();
2645 ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout);
2646
2647 EXPECT_GT(client_1_cert_verifier->call_count_, 0u);
2648 EXPECT_GT(client_2_cert_verifier->call_count_, 0u);
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07002649}
2650
Qingsi Wang25ec8882019-11-15 12:33:05 -08002651// Test that the injected ICE transport factory is used to create ICE transports
2652// for WebRTC connections.
2653TEST_P(PeerConnectionIntegrationTest, IceTransportFactoryUsedForConnections) {
2654 PeerConnectionInterface::RTCConfiguration default_config;
2655 PeerConnectionDependencies dependencies(nullptr);
2656 auto ice_transport_factory = std::make_unique<MockIceTransportFactory>();
2657 EXPECT_CALL(*ice_transport_factory, RecordIceTransportCreated()).Times(1);
2658 dependencies.ice_transport_factory = std::move(ice_transport_factory);
Niels Möller2a707032020-06-16 16:39:13 +02002659 auto wrapper = CreatePeerConnectionWrapper("Caller", nullptr, &default_config,
2660 std::move(dependencies), nullptr,
2661 /*reset_encoder_factory=*/false,
2662 /*reset_decoder_factory=*/false);
Qingsi Wang25ec8882019-11-15 12:33:05 -08002663 ASSERT_TRUE(wrapper);
2664 wrapper->CreateDataChannel();
Tommi87f70902021-04-27 14:43:08 +02002665 auto observer = rtc::make_ref_counted<MockSetSessionDescriptionObserver>();
Niels Möllerafb246b2022-04-20 14:26:50 +02002666 wrapper->pc()->SetLocalDescription(observer.get(),
Qingsi Wang25ec8882019-11-15 12:33:05 -08002667 wrapper->CreateOfferAndWait().release());
2668}
2669
deadbeefc964d0b2017-04-03 10:03:35 -07002670// Test that audio and video flow end-to-end when codec names don't use the
2671// expected casing, given that they're supposed to be case insensitive. To test
2672// this, all but one codec is removed from each media description, and its
2673// casing is changed.
2674//
2675// In the past, this has regressed and caused crashes/black video, due to the
2676// fact that code at some layers was doing case-insensitive comparisons and
2677// code at other layers was not.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002678TEST_P(PeerConnectionIntegrationTest, CodecNamesAreCaseInsensitive) {
deadbeefc964d0b2017-04-03 10:03:35 -07002679 ASSERT_TRUE(CreatePeerConnectionWrappers());
2680 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08002681 caller()->AddAudioVideoTracks();
2682 callee()->AddAudioVideoTracks();
deadbeefc964d0b2017-04-03 10:03:35 -07002683
2684 // Remove all but one audio/video codec (opus and VP8), and change the
2685 // casing of the caller's generated offer.
2686 caller()->SetGeneratedSdpMunger([](cricket::SessionDescription* description) {
2687 cricket::AudioContentDescription* audio =
2688 GetFirstAudioContentDescription(description);
2689 ASSERT_NE(nullptr, audio);
2690 auto audio_codecs = audio->codecs();
2691 audio_codecs.erase(std::remove_if(audio_codecs.begin(), audio_codecs.end(),
2692 [](const cricket::AudioCodec& codec) {
2693 return codec.name != "opus";
2694 }),
2695 audio_codecs.end());
2696 ASSERT_EQ(1u, audio_codecs.size());
2697 audio_codecs[0].name = "OpUs";
2698 audio->set_codecs(audio_codecs);
2699
2700 cricket::VideoContentDescription* video =
2701 GetFirstVideoContentDescription(description);
2702 ASSERT_NE(nullptr, video);
2703 auto video_codecs = video->codecs();
2704 video_codecs.erase(std::remove_if(video_codecs.begin(), video_codecs.end(),
2705 [](const cricket::VideoCodec& codec) {
2706 return codec.name != "VP8";
2707 }),
2708 video_codecs.end());
2709 ASSERT_EQ(1u, video_codecs.size());
2710 video_codecs[0].name = "vP8";
2711 video->set_codecs(video_codecs);
2712 });
2713
2714 caller()->CreateAndSetAndSignalOffer();
2715 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2716
2717 // Verify frames are still received end-to-end.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002718 MediaExpectations media_expectations;
2719 media_expectations.ExpectBidirectionalAudioAndVideo();
2720 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeefc964d0b2017-04-03 10:03:35 -07002721}
2722
Jonas Oreland49ac5952018-09-26 16:04:32 +02002723TEST_P(PeerConnectionIntegrationTest, GetSourcesAudio) {
hbos8d609f62017-04-10 07:39:05 -07002724 ASSERT_TRUE(CreatePeerConnectionWrappers());
2725 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08002726 caller()->AddAudioTrack();
hbos8d609f62017-04-10 07:39:05 -07002727 caller()->CreateAndSetAndSignalOffer();
2728 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
deadbeefd8ad7882017-04-18 16:01:17 -07002729 // Wait for one audio frame to be received by the callee.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002730 MediaExpectations media_expectations;
2731 media_expectations.CalleeExpectsSomeAudio(1);
2732 ASSERT_TRUE(ExpectNewFrames(media_expectations));
Jonas Oreland49ac5952018-09-26 16:04:32 +02002733 ASSERT_EQ(callee()->pc()->GetReceivers().size(), 1u);
hbos8d609f62017-04-10 07:39:05 -07002734 auto receiver = callee()->pc()->GetReceivers()[0];
2735 ASSERT_EQ(receiver->media_type(), cricket::MEDIA_TYPE_AUDIO);
Jonas Oreland49ac5952018-09-26 16:04:32 +02002736 auto sources = receiver->GetSources();
hbos8d609f62017-04-10 07:39:05 -07002737 ASSERT_GT(receiver->GetParameters().encodings.size(), 0u);
2738 EXPECT_EQ(receiver->GetParameters().encodings[0].ssrc,
Jonas Oreland49ac5952018-09-26 16:04:32 +02002739 sources[0].source_id());
2740 EXPECT_EQ(webrtc::RtpSourceType::SSRC, sources[0].source_type());
2741}
2742
2743TEST_P(PeerConnectionIntegrationTest, GetSourcesVideo) {
2744 ASSERT_TRUE(CreatePeerConnectionWrappers());
2745 ConnectFakeSignaling();
2746 caller()->AddVideoTrack();
2747 caller()->CreateAndSetAndSignalOffer();
2748 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2749 // Wait for one video frame to be received by the callee.
2750 MediaExpectations media_expectations;
2751 media_expectations.CalleeExpectsSomeVideo(1);
2752 ASSERT_TRUE(ExpectNewFrames(media_expectations));
2753 ASSERT_EQ(callee()->pc()->GetReceivers().size(), 1u);
2754 auto receiver = callee()->pc()->GetReceivers()[0];
2755 ASSERT_EQ(receiver->media_type(), cricket::MEDIA_TYPE_VIDEO);
2756 auto sources = receiver->GetSources();
2757 ASSERT_GT(receiver->GetParameters().encodings.size(), 0u);
Yves Gereyf781bb52019-07-23 19:15:39 +02002758 ASSERT_GT(sources.size(), 0u);
Jonas Oreland49ac5952018-09-26 16:04:32 +02002759 EXPECT_EQ(receiver->GetParameters().encodings[0].ssrc,
2760 sources[0].source_id());
2761 EXPECT_EQ(webrtc::RtpSourceType::SSRC, sources[0].source_type());
hbos8d609f62017-04-10 07:39:05 -07002762}
2763
deadbeef2f425aa2017-04-14 10:41:32 -07002764// Test that if a track is removed and added again with a different stream ID,
2765// the new stream ID is successfully communicated in SDP and media continues to
2766// flow end-to-end.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002767// TODO(webrtc.bugs.org/8734): This test does not work for Unified Plan because
2768// it will not reuse a transceiver that has already been sending. After creating
2769// a new transceiver it tries to create an offer with two senders of the same
2770// track ids and it fails.
2771TEST_F(PeerConnectionIntegrationTestPlanB, RemoveAndAddTrackWithNewStreamId) {
deadbeef2f425aa2017-04-14 10:41:32 -07002772 ASSERT_TRUE(CreatePeerConnectionWrappers());
2773 ConnectFakeSignaling();
2774
deadbeef2f425aa2017-04-14 10:41:32 -07002775 // Add track using stream 1, do offer/answer.
2776 rtc::scoped_refptr<webrtc::AudioTrackInterface> track =
2777 caller()->CreateLocalAudioTrack();
2778 rtc::scoped_refptr<webrtc::RtpSenderInterface> sender =
Steve Antond78323f2018-07-11 11:13:44 -07002779 caller()->AddTrack(track, {"stream_1"});
deadbeef2f425aa2017-04-14 10:41:32 -07002780 caller()->CreateAndSetAndSignalOffer();
2781 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002782 {
2783 MediaExpectations media_expectations;
2784 media_expectations.CalleeExpectsSomeAudio(1);
2785 ASSERT_TRUE(ExpectNewFrames(media_expectations));
2786 }
deadbeef2f425aa2017-04-14 10:41:32 -07002787 // Remove the sender, and create a new one with the new stream.
Harald Alvestrand93dd7632022-01-19 12:28:45 +00002788 caller()->pc()->RemoveTrackOrError(sender);
Steve Antond78323f2018-07-11 11:13:44 -07002789 sender = caller()->AddTrack(track, {"stream_2"});
deadbeef2f425aa2017-04-14 10:41:32 -07002790 caller()->CreateAndSetAndSignalOffer();
2791 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2792 // Wait for additional audio frames to be received by the callee.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002793 {
2794 MediaExpectations media_expectations;
2795 media_expectations.CalleeExpectsSomeAudio();
2796 ASSERT_TRUE(ExpectNewFrames(media_expectations));
2797 }
deadbeef2f425aa2017-04-14 10:41:32 -07002798}
2799
Seth Hampson2f0d7022018-02-20 11:54:42 -08002800TEST_P(PeerConnectionIntegrationTest, RtcEventLogOutputWriteCalled) {
Elad Alon99c3fe52017-10-13 16:29:40 +02002801 ASSERT_TRUE(CreatePeerConnectionWrappers());
2802 ConnectFakeSignaling();
2803
Mirko Bonadei317a1f02019-09-17 17:06:18 +02002804 auto output = std::make_unique<testing::NiceMock<MockRtcEventLogOutput>>();
Mirko Bonadei6a489f22019-04-09 15:11:12 +02002805 ON_CALL(*output, IsActive()).WillByDefault(::testing::Return(true));
Ali Tofighb7821ce2022-07-12 16:08:13 +02002806 ON_CALL(*output, Write(::testing::A<absl::string_view>()))
Björn Terelius63299a32022-07-05 10:58:52 +02002807 .WillByDefault(::testing::Return(true));
Ali Tofighb7821ce2022-07-12 16:08:13 +02002808 EXPECT_CALL(*output, Write(::testing::A<absl::string_view>()))
Björn Terelius63299a32022-07-05 10:58:52 +02002809 .Times(::testing::AtLeast(1));
Bjorn Tereliusde939432017-11-20 17:38:14 +01002810 EXPECT_TRUE(caller()->pc()->StartRtcEventLog(
2811 std::move(output), webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02002812
Steve Anton15324772018-01-16 10:26:49 -08002813 caller()->AddAudioVideoTracks();
Elad Alon99c3fe52017-10-13 16:29:40 +02002814 caller()->CreateAndSetAndSignalOffer();
2815 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2816}
2817
Steve Antonede9ca52017-10-16 13:04:27 -07002818// Test that if candidates are only signaled by applying full session
2819// descriptions (instead of using AddIceCandidate), the peers can connect to
2820// each other and exchange media.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002821TEST_P(PeerConnectionIntegrationTest, MediaFlowsWhenCandidatesSetOnlyInSdp) {
Steve Antonede9ca52017-10-16 13:04:27 -07002822 ASSERT_TRUE(CreatePeerConnectionWrappers());
2823 // Each side will signal the session descriptions but not candidates.
2824 ConnectFakeSignalingForSdpOnly();
2825
2826 // Add audio video track and exchange the initial offer/answer with media
2827 // information only. This will start ICE gathering on each side.
Steve Anton15324772018-01-16 10:26:49 -08002828 caller()->AddAudioVideoTracks();
2829 callee()->AddAudioVideoTracks();
Steve Antonede9ca52017-10-16 13:04:27 -07002830 caller()->CreateAndSetAndSignalOffer();
2831
2832 // Wait for all candidates to be gathered on both the caller and callee.
2833 ASSERT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
2834 caller()->ice_gathering_state(), kDefaultTimeout);
2835 ASSERT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
2836 callee()->ice_gathering_state(), kDefaultTimeout);
2837
2838 // The candidates will now be included in the session description, so
2839 // signaling them will start the ICE connection.
2840 caller()->CreateAndSetAndSignalOffer();
2841 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2842
2843 // Ensure that media flows in both directions.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002844 MediaExpectations media_expectations;
2845 media_expectations.ExpectBidirectionalAudioAndVideo();
2846 ASSERT_TRUE(ExpectNewFrames(media_expectations));
Steve Antonede9ca52017-10-16 13:04:27 -07002847}
2848
Harald Alvestrandec23d6d2021-02-11 10:47:22 +00002849#if !defined(THREAD_SANITIZER)
2850// These tests provokes TSAN errors. See bugs.webrtc.org/11305.
2851
henrika5f6bf242017-11-01 11:06:56 +01002852// Test that SetAudioPlayout can be used to disable audio playout from the
2853// start, then later enable it. This may be useful, for example, if the caller
2854// needs to play a local ringtone until some event occurs, after which it
2855// switches to playing the received audio.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002856TEST_P(PeerConnectionIntegrationTest, DisableAndEnableAudioPlayout) {
henrika5f6bf242017-11-01 11:06:56 +01002857 ASSERT_TRUE(CreatePeerConnectionWrappers());
2858 ConnectFakeSignaling();
2859
2860 // Set up audio-only call where audio playout is disabled on caller's side.
2861 caller()->pc()->SetAudioPlayout(false);
Steve Anton15324772018-01-16 10:26:49 -08002862 caller()->AddAudioTrack();
2863 callee()->AddAudioTrack();
henrika5f6bf242017-11-01 11:06:56 +01002864 caller()->CreateAndSetAndSignalOffer();
2865 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2866
2867 // Pump messages for a second.
2868 WAIT(false, 1000);
2869 // Since audio playout is disabled, the caller shouldn't have received
2870 // anything (at the playout level, at least).
2871 EXPECT_EQ(0, caller()->audio_frames_received());
2872 // As a sanity check, make sure the callee (for which playout isn't disabled)
2873 // did still see frames on its audio level.
2874 ASSERT_GT(callee()->audio_frames_received(), 0);
2875
2876 // Enable playout again, and ensure audio starts flowing.
2877 caller()->pc()->SetAudioPlayout(true);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002878 MediaExpectations media_expectations;
2879 media_expectations.ExpectBidirectionalAudio();
2880 ASSERT_TRUE(ExpectNewFrames(media_expectations));
henrika5f6bf242017-11-01 11:06:56 +01002881}
2882
Harald Alvestrand39993842021-02-17 09:05:31 +00002883double GetAudioEnergyStat(PeerConnectionIntegrationWrapper* pc) {
henrika5f6bf242017-11-01 11:06:56 +01002884 auto report = pc->NewGetStats();
2885 auto track_stats_list =
Henrik Boström15166b22022-10-19 11:06:58 +02002886 report->GetStatsOfType<webrtc::DEPRECATED_RTCMediaStreamTrackStats>();
2887 const webrtc::DEPRECATED_RTCMediaStreamTrackStats* remote_track_stats =
2888 nullptr;
henrika5f6bf242017-11-01 11:06:56 +01002889 for (const auto* track_stats : track_stats_list) {
2890 if (track_stats->remote_source.is_defined() &&
2891 *track_stats->remote_source) {
2892 remote_track_stats = track_stats;
2893 break;
2894 }
2895 }
2896
2897 if (!remote_track_stats->total_audio_energy.is_defined()) {
2898 return 0.0;
2899 }
2900 return *remote_track_stats->total_audio_energy;
2901}
2902
2903// Test that if audio playout is disabled via the SetAudioPlayout() method, then
2904// incoming audio is still processed and statistics are generated.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002905TEST_P(PeerConnectionIntegrationTest,
henrika5f6bf242017-11-01 11:06:56 +01002906 DisableAudioPlayoutStillGeneratesAudioStats) {
2907 ASSERT_TRUE(CreatePeerConnectionWrappers());
2908 ConnectFakeSignaling();
2909
2910 // Set up audio-only call where playout is disabled but audio-processing is
2911 // still active.
Steve Anton15324772018-01-16 10:26:49 -08002912 caller()->AddAudioTrack();
2913 callee()->AddAudioTrack();
henrika5f6bf242017-11-01 11:06:56 +01002914 caller()->pc()->SetAudioPlayout(false);
2915
2916 caller()->CreateAndSetAndSignalOffer();
2917 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2918
2919 // Wait for the callee to receive audio stats.
2920 EXPECT_TRUE_WAIT(GetAudioEnergyStat(caller()) > 0, kMaxWaitForFramesMs);
2921}
2922
Harald Alvestrandec23d6d2021-02-11 10:47:22 +00002923#endif // !defined(THREAD_SANITIZER)
2924
henrika4f167df2017-11-01 14:45:55 +01002925// Test that SetAudioRecording can be used to disable audio recording from the
2926// start, then later enable it. This may be useful, for example, if the caller
2927// wants to ensure that no audio resources are active before a certain state
2928// is reached.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002929TEST_P(PeerConnectionIntegrationTest, DisableAndEnableAudioRecording) {
henrika4f167df2017-11-01 14:45:55 +01002930 ASSERT_TRUE(CreatePeerConnectionWrappers());
2931 ConnectFakeSignaling();
2932
2933 // Set up audio-only call where audio recording is disabled on caller's side.
2934 caller()->pc()->SetAudioRecording(false);
Steve Anton15324772018-01-16 10:26:49 -08002935 caller()->AddAudioTrack();
2936 callee()->AddAudioTrack();
henrika4f167df2017-11-01 14:45:55 +01002937 caller()->CreateAndSetAndSignalOffer();
2938 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2939
2940 // Pump messages for a second.
2941 WAIT(false, 1000);
2942 // Since caller has disabled audio recording, the callee shouldn't have
2943 // received anything.
2944 EXPECT_EQ(0, callee()->audio_frames_received());
2945 // As a sanity check, make sure the caller did still see frames on its
2946 // audio level since audio recording is enabled on the calle side.
2947 ASSERT_GT(caller()->audio_frames_received(), 0);
2948
2949 // Enable audio recording again, and ensure audio starts flowing.
2950 caller()->pc()->SetAudioRecording(true);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002951 MediaExpectations media_expectations;
2952 media_expectations.ExpectBidirectionalAudio();
2953 ASSERT_TRUE(ExpectNewFrames(media_expectations));
henrika4f167df2017-11-01 14:45:55 +01002954}
2955
Qingsi Wang7685e862018-06-11 20:15:46 -07002956TEST_P(PeerConnectionIntegrationTest,
2957 IceEventsGeneratedAndLoggedInRtcEventLog) {
2958 ASSERT_TRUE(CreatePeerConnectionWrappersWithFakeRtcEventLog());
2959 ConnectFakeSignaling();
2960 PeerConnectionInterface::RTCOfferAnswerOptions options;
2961 options.offer_to_receive_audio = 1;
2962 caller()->SetOfferAnswerOptions(options);
2963 caller()->CreateAndSetAndSignalOffer();
2964 ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout);
2965 ASSERT_NE(nullptr, caller()->event_log_factory());
2966 ASSERT_NE(nullptr, callee()->event_log_factory());
2967 webrtc::FakeRtcEventLog* caller_event_log =
Danil Chapovalov4f281f12021-01-18 13:29:00 +01002968 caller()->event_log_factory()->last_log_created();
Qingsi Wang7685e862018-06-11 20:15:46 -07002969 webrtc::FakeRtcEventLog* callee_event_log =
Danil Chapovalov4f281f12021-01-18 13:29:00 +01002970 callee()->event_log_factory()->last_log_created();
Qingsi Wang7685e862018-06-11 20:15:46 -07002971 ASSERT_NE(nullptr, caller_event_log);
2972 ASSERT_NE(nullptr, callee_event_log);
2973 int caller_ice_config_count = caller_event_log->GetEventCount(
2974 webrtc::RtcEvent::Type::IceCandidatePairConfig);
2975 int caller_ice_event_count = caller_event_log->GetEventCount(
2976 webrtc::RtcEvent::Type::IceCandidatePairEvent);
2977 int callee_ice_config_count = callee_event_log->GetEventCount(
2978 webrtc::RtcEvent::Type::IceCandidatePairConfig);
2979 int callee_ice_event_count = callee_event_log->GetEventCount(
2980 webrtc::RtcEvent::Type::IceCandidatePairEvent);
2981 EXPECT_LT(0, caller_ice_config_count);
2982 EXPECT_LT(0, caller_ice_event_count);
2983 EXPECT_LT(0, callee_ice_config_count);
2984 EXPECT_LT(0, callee_ice_event_count);
2985}
2986
Qingsi Wangc129c352019-04-18 10:41:58 -07002987TEST_P(PeerConnectionIntegrationTest, RegatherAfterChangingIceTransportType) {
Qingsi Wangc129c352019-04-18 10:41:58 -07002988 static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0",
2989 3478};
2990 static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0};
2991
2992 CreateTurnServer(turn_server_internal_address, turn_server_external_address);
2993
2994 webrtc::PeerConnectionInterface::IceServer ice_server;
2995 ice_server.urls.push_back("turn:88.88.88.0:3478");
2996 ice_server.username = "test";
2997 ice_server.password = "test";
2998
2999 PeerConnectionInterface::RTCConfiguration caller_config;
3000 caller_config.servers.push_back(ice_server);
3001 caller_config.type = webrtc::PeerConnectionInterface::kRelay;
3002 caller_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY;
Qingsi Wang1fe119f2019-05-31 16:55:33 -07003003 caller_config.surface_ice_candidates_on_ice_transport_type_changed = true;
Qingsi Wangc129c352019-04-18 10:41:58 -07003004
3005 PeerConnectionInterface::RTCConfiguration callee_config;
3006 callee_config.servers.push_back(ice_server);
3007 callee_config.type = webrtc::PeerConnectionInterface::kRelay;
3008 callee_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY;
Qingsi Wang1fe119f2019-05-31 16:55:33 -07003009 callee_config.surface_ice_candidates_on_ice_transport_type_changed = true;
Qingsi Wangc129c352019-04-18 10:41:58 -07003010
3011 ASSERT_TRUE(
3012 CreatePeerConnectionWrappersWithConfig(caller_config, callee_config));
3013
3014 // Do normal offer/answer and wait for ICE to complete.
3015 ConnectFakeSignaling();
3016 caller()->AddAudioVideoTracks();
3017 callee()->AddAudioVideoTracks();
3018 caller()->CreateAndSetAndSignalOffer();
3019 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3020 // Since we are doing continual gathering, the ICE transport does not reach
3021 // kIceGatheringComplete (see
3022 // P2PTransportChannel::OnCandidatesAllocationDone), and consequently not
3023 // kIceConnectionComplete.
3024 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
3025 caller()->ice_connection_state(), kDefaultTimeout);
3026 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
3027 callee()->ice_connection_state(), kDefaultTimeout);
3028 // Note that we cannot use the metric
Artem Titovcfea2182021-08-10 01:22:31 +02003029 // `WebRTC.PeerConnection.CandidatePairType_UDP` in this test since this
Qingsi Wangc129c352019-04-18 10:41:58 -07003030 // metric is only populated when we reach kIceConnectionComplete in the
3031 // current implementation.
3032 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
3033 caller()->last_candidate_gathered().type());
3034 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
3035 callee()->last_candidate_gathered().type());
3036
3037 // Loosen the caller's candidate filter.
3038 caller_config = caller()->pc()->GetConfiguration();
3039 caller_config.type = webrtc::PeerConnectionInterface::kAll;
3040 caller()->pc()->SetConfiguration(caller_config);
3041 // We should have gathered a new host candidate.
3042 EXPECT_EQ_WAIT(cricket::LOCAL_PORT_TYPE,
3043 caller()->last_candidate_gathered().type(), kDefaultTimeout);
3044
3045 // Loosen the callee's candidate filter.
3046 callee_config = callee()->pc()->GetConfiguration();
3047 callee_config.type = webrtc::PeerConnectionInterface::kAll;
3048 callee()->pc()->SetConfiguration(callee_config);
3049 EXPECT_EQ_WAIT(cricket::LOCAL_PORT_TYPE,
3050 callee()->last_candidate_gathered().type(), kDefaultTimeout);
Jonas Orelande3096512020-05-27 09:01:05 +02003051
3052 // Create an offer and verify that it does not contain an ICE restart (i.e new
3053 // ice credentials).
3054 std::string caller_ufrag_pre_offer = caller()
3055 ->pc()
3056 ->local_description()
3057 ->description()
3058 ->transport_infos()[0]
3059 .description.ice_ufrag;
3060 caller()->CreateAndSetAndSignalOffer();
3061 std::string caller_ufrag_post_offer = caller()
3062 ->pc()
3063 ->local_description()
3064 ->description()
3065 ->transport_infos()[0]
3066 .description.ice_ufrag;
3067 EXPECT_EQ(caller_ufrag_pre_offer, caller_ufrag_post_offer);
Qingsi Wangc129c352019-04-18 10:41:58 -07003068}
3069
Eldar Relloda13ea22019-06-01 12:23:43 +03003070TEST_P(PeerConnectionIntegrationTest, OnIceCandidateError) {
Eldar Relloda13ea22019-06-01 12:23:43 +03003071 static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0",
3072 3478};
3073 static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0};
3074
3075 CreateTurnServer(turn_server_internal_address, turn_server_external_address);
3076
3077 webrtc::PeerConnectionInterface::IceServer ice_server;
3078 ice_server.urls.push_back("turn:88.88.88.0:3478");
3079 ice_server.username = "test";
3080 ice_server.password = "123";
3081
3082 PeerConnectionInterface::RTCConfiguration caller_config;
3083 caller_config.servers.push_back(ice_server);
3084 caller_config.type = webrtc::PeerConnectionInterface::kRelay;
3085 caller_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY;
3086
3087 PeerConnectionInterface::RTCConfiguration callee_config;
3088 callee_config.servers.push_back(ice_server);
3089 callee_config.type = webrtc::PeerConnectionInterface::kRelay;
3090 callee_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY;
3091
3092 ASSERT_TRUE(
3093 CreatePeerConnectionWrappersWithConfig(caller_config, callee_config));
3094
3095 // Do normal offer/answer and wait for ICE to complete.
3096 ConnectFakeSignaling();
3097 caller()->AddAudioVideoTracks();
3098 callee()->AddAudioVideoTracks();
3099 caller()->CreateAndSetAndSignalOffer();
3100 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3101 EXPECT_EQ_WAIT(401, caller()->error_event().error_code, kDefaultTimeout);
3102 EXPECT_EQ("Unauthorized", caller()->error_event().error_text);
3103 EXPECT_EQ("turn:88.88.88.0:3478?transport=udp", caller()->error_event().url);
Eldar Rello0095d372019-12-02 22:22:07 +02003104 EXPECT_NE(caller()->error_event().address, "");
Eldar Relloda13ea22019-06-01 12:23:43 +03003105}
3106
Eldar Rellofa8019c2020-05-14 11:59:33 +03003107TEST_P(PeerConnectionIntegrationTest, OnIceCandidateErrorWithEmptyAddress) {
3108 webrtc::PeerConnectionInterface::IceServer ice_server;
3109 ice_server.urls.push_back("turn:127.0.0.1:3478?transport=tcp");
3110 ice_server.username = "test";
3111 ice_server.password = "test";
3112
3113 PeerConnectionInterface::RTCConfiguration caller_config;
3114 caller_config.servers.push_back(ice_server);
3115 caller_config.type = webrtc::PeerConnectionInterface::kRelay;
3116 caller_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY;
3117
3118 PeerConnectionInterface::RTCConfiguration callee_config;
3119 callee_config.servers.push_back(ice_server);
3120 callee_config.type = webrtc::PeerConnectionInterface::kRelay;
3121 callee_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY;
3122
3123 ASSERT_TRUE(
3124 CreatePeerConnectionWrappersWithConfig(caller_config, callee_config));
3125
3126 // Do normal offer/answer and wait for ICE to complete.
3127 ConnectFakeSignaling();
3128 caller()->AddAudioVideoTracks();
3129 callee()->AddAudioVideoTracks();
3130 caller()->CreateAndSetAndSignalOffer();
3131 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3132 EXPECT_EQ_WAIT(701, caller()->error_event().error_code, kDefaultTimeout);
3133 EXPECT_EQ(caller()->error_event().address, "");
3134}
3135
Eldar Rello5ab79e62019-10-09 18:29:44 +03003136TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
3137 AudioKeepsFlowingAfterImplicitRollback) {
3138 PeerConnectionInterface::RTCConfiguration config;
3139 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
3140 config.enable_implicit_rollback = true;
3141 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config));
3142 ConnectFakeSignaling();
3143 caller()->AddAudioTrack();
3144 callee()->AddAudioTrack();
3145 caller()->CreateAndSetAndSignalOffer();
3146 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3147 MediaExpectations media_expectations;
3148 media_expectations.ExpectBidirectionalAudio();
3149 ASSERT_TRUE(ExpectNewFrames(media_expectations));
3150 SetSignalIceCandidates(false); // Workaround candidate outrace sdp.
3151 caller()->AddVideoTrack();
3152 callee()->AddVideoTrack();
Tommi87f70902021-04-27 14:43:08 +02003153 auto observer = rtc::make_ref_counted<MockSetSessionDescriptionObserver>();
Niels Möllerafb246b2022-04-20 14:26:50 +02003154 callee()->pc()->SetLocalDescription(observer.get(),
Eldar Rello5ab79e62019-10-09 18:29:44 +03003155 callee()->CreateOfferAndWait().release());
3156 EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout);
3157 caller()->CreateAndSetAndSignalOffer(); // Implicit rollback.
3158 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3159 ASSERT_TRUE(ExpectNewFrames(media_expectations));
3160}
3161
3162TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
3163 ImplicitRollbackVisitsStableState) {
3164 RTCConfiguration config;
3165 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
3166 config.enable_implicit_rollback = true;
3167
3168 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config));
3169
Tommi87f70902021-04-27 14:43:08 +02003170 auto sld_observer =
3171 rtc::make_ref_counted<MockSetSessionDescriptionObserver>();
Niels Möllerafb246b2022-04-20 14:26:50 +02003172 callee()->pc()->SetLocalDescription(sld_observer.get(),
Eldar Rello5ab79e62019-10-09 18:29:44 +03003173 callee()->CreateOfferAndWait().release());
3174 EXPECT_TRUE_WAIT(sld_observer->called(), kDefaultTimeout);
3175 EXPECT_EQ(sld_observer->error(), "");
3176
Tommi87f70902021-04-27 14:43:08 +02003177 auto srd_observer =
3178 rtc::make_ref_counted<MockSetSessionDescriptionObserver>();
Eldar Rello5ab79e62019-10-09 18:29:44 +03003179 callee()->pc()->SetRemoteDescription(
Niels Möllerafb246b2022-04-20 14:26:50 +02003180 srd_observer.get(), caller()->CreateOfferAndWait().release());
Eldar Rello5ab79e62019-10-09 18:29:44 +03003181 EXPECT_TRUE_WAIT(srd_observer->called(), kDefaultTimeout);
3182 EXPECT_EQ(srd_observer->error(), "");
3183
3184 EXPECT_THAT(callee()->peer_connection_signaling_state_history(),
3185 ElementsAre(PeerConnectionInterface::kHaveLocalOffer,
3186 PeerConnectionInterface::kStable,
3187 PeerConnectionInterface::kHaveRemoteOffer));
3188}
3189
Eldar Rellobd9c33a2020-10-01 17:52:45 +03003190TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
3191 H264FmtpSpsPpsIdrInKeyframeParameterUsage) {
3192 ASSERT_TRUE(CreatePeerConnectionWrappers());
3193 ConnectFakeSignaling();
3194 caller()->AddVideoTrack();
3195 callee()->AddVideoTrack();
3196 auto munger = [](cricket::SessionDescription* desc) {
3197 cricket::VideoContentDescription* video =
3198 GetFirstVideoContentDescription(desc);
3199 auto codecs = video->codecs();
3200 for (auto&& codec : codecs) {
3201 if (codec.name == "H264") {
3202 std::string value;
3203 // The parameter is not supposed to be present in SDP by default.
3204 EXPECT_FALSE(
3205 codec.GetParam(cricket::kH264FmtpSpsPpsIdrInKeyframe, &value));
3206 codec.SetParam(std::string(cricket::kH264FmtpSpsPpsIdrInKeyframe),
3207 std::string(""));
3208 }
3209 }
3210 video->set_codecs(codecs);
3211 };
3212 // Munge local offer for SLD.
3213 caller()->SetGeneratedSdpMunger(munger);
3214 // Munge remote answer for SRD.
3215 caller()->SetReceivedSdpMunger(munger);
3216 caller()->CreateAndSetAndSignalOffer();
3217 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3218 // Observe that after munging the parameter is present in generated SDP.
3219 caller()->SetGeneratedSdpMunger([](cricket::SessionDescription* desc) {
3220 cricket::VideoContentDescription* video =
3221 GetFirstVideoContentDescription(desc);
3222 for (auto&& codec : video->codecs()) {
3223 if (codec.name == "H264") {
3224 std::string value;
3225 EXPECT_TRUE(
3226 codec.GetParam(cricket::kH264FmtpSpsPpsIdrInKeyframe, &value));
3227 }
3228 }
3229 });
3230 caller()->CreateOfferAndWait();
3231}
3232
Harald Alvestrand1a9be302020-12-11 14:53:59 +00003233TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
Harald Alvestrand94324f22021-01-13 12:31:53 +00003234 RenegotiateManyAudioTransceivers) {
Harald Alvestrand1a9be302020-12-11 14:53:59 +00003235 PeerConnectionInterface::RTCConfiguration config;
3236 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
3237 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config));
3238 ConnectFakeSignaling();
3239 caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_AUDIO);
3240
3241 caller()->CreateAndSetAndSignalOffer();
3242 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3243 int current_size = caller()->pc()->GetTransceivers().size();
3244 // Add more tracks until we get close to having issues.
3245 // Issues have been seen at:
3246 // - 32 tracks on android_arm64_rel and android_arm_dbg bots
Harald Alvestrandcc6ae442021-01-18 08:06:23 +00003247 // - 16 tracks on android_arm_dbg (flaky)
3248 while (current_size < 8) {
Harald Alvestrand1a9be302020-12-11 14:53:59 +00003249 // Double the number of tracks
3250 for (int i = 0; i < current_size; i++) {
3251 caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_AUDIO);
3252 }
3253 current_size = caller()->pc()->GetTransceivers().size();
3254 RTC_LOG(LS_INFO) << "Renegotiating with " << current_size << " tracks";
3255 auto start_time_ms = rtc::TimeMillis();
3256 caller()->CreateAndSetAndSignalOffer();
3257 // We want to stop when the time exceeds one second.
3258 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3259 auto elapsed_time_ms = rtc::TimeMillis() - start_time_ms;
3260 RTC_LOG(LS_INFO) << "Renegotiating took " << elapsed_time_ms << " ms";
3261 ASSERT_GT(1000, elapsed_time_ms)
3262 << "Audio transceivers: Negotiation took too long after "
3263 << current_size << " tracks added";
3264 }
3265}
3266
3267TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
3268 RenegotiateManyVideoTransceivers) {
3269 PeerConnectionInterface::RTCConfiguration config;
3270 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
3271 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config));
3272 ConnectFakeSignaling();
3273 caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_VIDEO);
3274
3275 caller()->CreateAndSetAndSignalOffer();
3276 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3277 int current_size = caller()->pc()->GetTransceivers().size();
3278 // Add more tracks until we get close to having issues.
3279 // Issues have been seen at:
3280 // - 96 on a Linux workstation
3281 // - 64 at win_x86_more_configs and win_x64_msvc_dbg
3282 // - 32 on android_arm64_rel and linux_dbg bots
Harald Alvestrand785e23b2021-03-15 21:26:27 +00003283 // - 16 on Android 64 (Nexus 5x)
3284 while (current_size < 8) {
Harald Alvestrand1a9be302020-12-11 14:53:59 +00003285 // Double the number of tracks
3286 for (int i = 0; i < current_size; i++) {
3287 caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_VIDEO);
3288 }
3289 current_size = caller()->pc()->GetTransceivers().size();
3290 RTC_LOG(LS_INFO) << "Renegotiating with " << current_size << " tracks";
3291 auto start_time_ms = rtc::TimeMillis();
3292 caller()->CreateAndSetAndSignalOffer();
3293 // We want to stop when the time exceeds one second.
3294 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3295 auto elapsed_time_ms = rtc::TimeMillis() - start_time_ms;
3296 RTC_LOG(LS_INFO) << "Renegotiating took " << elapsed_time_ms << " ms";
3297 ASSERT_GT(1000, elapsed_time_ms)
3298 << "Video transceivers: Negotiation took too long after "
3299 << current_size << " tracks added";
3300 }
3301}
3302
Harald Alvestrand94324f22021-01-13 12:31:53 +00003303TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
3304 RenegotiateManyVideoTransceiversAndWatchAudioDelay) {
3305 PeerConnectionInterface::RTCConfiguration config;
3306 config.sdp_semantics = SdpSemantics::kUnifiedPlan;
3307 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config));
3308 ConnectFakeSignaling();
3309 caller()->AddAudioTrack();
Harald Alvestrandcc6ae442021-01-18 08:06:23 +00003310 callee()->AddAudioTrack();
Harald Alvestrand94324f22021-01-13 12:31:53 +00003311 caller()->CreateAndSetAndSignalOffer();
3312 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3313 // Wait until we can see the audio flowing.
3314 MediaExpectations media_expectations;
3315 media_expectations.CalleeExpectsSomeAudio();
3316 ASSERT_TRUE(ExpectNewFrames(media_expectations));
3317
Harald Alvestrandcc6ae442021-01-18 08:06:23 +00003318 // Get the baseline numbers for audio_packets and audio_delay
3319 // in both directions.
3320 caller()->StartWatchingDelayStats();
3321 callee()->StartWatchingDelayStats();
Harald Alvestrand94324f22021-01-13 12:31:53 +00003322
3323 int current_size = caller()->pc()->GetTransceivers().size();
3324 // Add more tracks until we get close to having issues.
3325 // Making this number very large makes the test very slow.
Harald Alvestrandcc6ae442021-01-18 08:06:23 +00003326 while (current_size < 16) {
Harald Alvestrand94324f22021-01-13 12:31:53 +00003327 // Double the number of tracks
3328 for (int i = 0; i < current_size; i++) {
3329 caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_VIDEO);
3330 }
3331 current_size = caller()->pc()->GetTransceivers().size();
3332 RTC_LOG(LS_INFO) << "Renegotiating with " << current_size << " tracks";
3333 auto start_time_ms = rtc::TimeMillis();
3334 caller()->CreateAndSetAndSignalOffer();
3335 // We want to stop when the time exceeds one second.
3336 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3337 auto elapsed_time_ms = rtc::TimeMillis() - start_time_ms;
3338 RTC_LOG(LS_INFO) << "Renegotiating took " << elapsed_time_ms << " ms";
3339 // This is a guard against the test using excessive amounts of time.
3340 ASSERT_GT(5000, elapsed_time_ms)
3341 << "Video transceivers: Negotiation took too long after "
3342 << current_size << " tracks added";
Harald Alvestrandcc6ae442021-01-18 08:06:23 +00003343 caller()->UpdateDelayStats("caller reception", current_size);
3344 callee()->UpdateDelayStats("callee reception", current_size);
Harald Alvestrand94324f22021-01-13 12:31:53 +00003345 }
3346}
3347
Evan Shrubsole7619b7c2022-03-01 10:42:44 +01003348INSTANTIATE_TEST_SUITE_P(
3349 PeerConnectionIntegrationTest,
3350 PeerConnectionIntegrationTest,
Florent Castelli15a38de2022-04-06 00:38:21 +02003351 Combine(Values(SdpSemantics::kPlanB_DEPRECATED, SdpSemantics::kUnifiedPlan),
Evan Shrubsole7619b7c2022-03-01 10:42:44 +01003352 Values("WebRTC-FrameBuffer3/arm:FrameBuffer2/",
3353 "WebRTC-FrameBuffer3/arm:FrameBuffer3/",
3354 "WebRTC-FrameBuffer3/arm:SyncDecoding/")));
Steve Antond3679212018-01-17 17:41:02 -08003355
Evan Shrubsole7619b7c2022-03-01 10:42:44 +01003356INSTANTIATE_TEST_SUITE_P(
3357 PeerConnectionIntegrationTest,
3358 PeerConnectionIntegrationTestWithFakeClock,
Florent Castelli15a38de2022-04-06 00:38:21 +02003359 Combine(Values(SdpSemantics::kPlanB_DEPRECATED, SdpSemantics::kUnifiedPlan),
Evan Shrubsole7619b7c2022-03-01 10:42:44 +01003360 Values("WebRTC-FrameBuffer3/arm:FrameBuffer2/",
3361 "WebRTC-FrameBuffer3/arm:FrameBuffer3/",
3362 "WebRTC-FrameBuffer3/arm:SyncDecoding/")));
Yves Gerey100fe632020-01-17 19:15:53 +01003363
Steve Anton74255ff2018-01-24 18:32:57 -08003364// Tests that verify interoperability between Plan B and Unified Plan
3365// PeerConnections.
3366class PeerConnectionIntegrationInteropTest
Seth Hampson2f0d7022018-02-20 11:54:42 -08003367 : public PeerConnectionIntegrationBaseTest,
Steve Anton74255ff2018-01-24 18:32:57 -08003368 public ::testing::WithParamInterface<
3369 std::tuple<SdpSemantics, SdpSemantics>> {
3370 protected:
Seth Hampson2f0d7022018-02-20 11:54:42 -08003371 // Setting the SdpSemantics for the base test to kDefault does not matter
3372 // because we specify not to use the test semantics when creating
Harald Alvestrand39993842021-02-17 09:05:31 +00003373 // PeerConnectionIntegrationWrappers.
Steve Anton74255ff2018-01-24 18:32:57 -08003374 PeerConnectionIntegrationInteropTest()
Florent Castelli15a38de2022-04-06 00:38:21 +02003375 : PeerConnectionIntegrationBaseTest(SdpSemantics::kPlanB_DEPRECATED),
Seth Hampson2f0d7022018-02-20 11:54:42 -08003376 caller_semantics_(std::get<0>(GetParam())),
Steve Anton74255ff2018-01-24 18:32:57 -08003377 callee_semantics_(std::get<1>(GetParam())) {}
3378
3379 bool CreatePeerConnectionWrappersWithSemantics() {
Steve Anton3acffc32018-04-12 17:21:03 -07003380 return CreatePeerConnectionWrappersWithSdpSemantics(caller_semantics_,
3381 callee_semantics_);
Steve Anton74255ff2018-01-24 18:32:57 -08003382 }
3383
3384 const SdpSemantics caller_semantics_;
3385 const SdpSemantics callee_semantics_;
3386};
3387
3388TEST_P(PeerConnectionIntegrationInteropTest, NoMediaLocalToNoMediaRemote) {
3389 ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics());
3390 ConnectFakeSignaling();
3391
3392 caller()->CreateAndSetAndSignalOffer();
3393 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3394}
3395
3396TEST_P(PeerConnectionIntegrationInteropTest, OneAudioLocalToNoMediaRemote) {
3397 ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics());
3398 ConnectFakeSignaling();
3399 auto audio_sender = caller()->AddAudioTrack();
3400
3401 caller()->CreateAndSetAndSignalOffer();
3402 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3403
3404 // Verify that one audio receiver has been created on the remote and that it
3405 // has the same track ID as the sending track.
3406 auto receivers = callee()->pc()->GetReceivers();
3407 ASSERT_EQ(1u, receivers.size());
3408 EXPECT_EQ(cricket::MEDIA_TYPE_AUDIO, receivers[0]->media_type());
3409 EXPECT_EQ(receivers[0]->track()->id(), audio_sender->track()->id());
3410
Seth Hampson2f0d7022018-02-20 11:54:42 -08003411 MediaExpectations media_expectations;
3412 media_expectations.CalleeExpectsSomeAudio();
3413 ASSERT_TRUE(ExpectNewFrames(media_expectations));
Steve Anton74255ff2018-01-24 18:32:57 -08003414}
3415
3416TEST_P(PeerConnectionIntegrationInteropTest, OneAudioOneVideoToNoMediaRemote) {
3417 ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics());
3418 ConnectFakeSignaling();
3419 auto video_sender = caller()->AddVideoTrack();
3420 auto audio_sender = caller()->AddAudioTrack();
3421
3422 caller()->CreateAndSetAndSignalOffer();
3423 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3424
3425 // Verify that one audio and one video receiver have been created on the
3426 // remote and that they have the same track IDs as the sending tracks.
3427 auto audio_receivers =
3428 callee()->GetReceiversOfType(cricket::MEDIA_TYPE_AUDIO);
3429 ASSERT_EQ(1u, audio_receivers.size());
3430 EXPECT_EQ(audio_receivers[0]->track()->id(), audio_sender->track()->id());
3431 auto video_receivers =
3432 callee()->GetReceiversOfType(cricket::MEDIA_TYPE_VIDEO);
3433 ASSERT_EQ(1u, video_receivers.size());
3434 EXPECT_EQ(video_receivers[0]->track()->id(), video_sender->track()->id());
3435
Seth Hampson2f0d7022018-02-20 11:54:42 -08003436 MediaExpectations media_expectations;
3437 media_expectations.CalleeExpectsSomeAudioAndVideo();
3438 ASSERT_TRUE(ExpectNewFrames(media_expectations));
Steve Anton74255ff2018-01-24 18:32:57 -08003439}
3440
3441TEST_P(PeerConnectionIntegrationInteropTest,
3442 OneAudioOneVideoLocalToOneAudioOneVideoRemote) {
3443 ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics());
3444 ConnectFakeSignaling();
3445 caller()->AddAudioVideoTracks();
3446 callee()->AddAudioVideoTracks();
3447
3448 caller()->CreateAndSetAndSignalOffer();
3449 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3450
Seth Hampson2f0d7022018-02-20 11:54:42 -08003451 MediaExpectations media_expectations;
3452 media_expectations.ExpectBidirectionalAudioAndVideo();
3453 ASSERT_TRUE(ExpectNewFrames(media_expectations));
Steve Anton74255ff2018-01-24 18:32:57 -08003454}
3455
3456TEST_P(PeerConnectionIntegrationInteropTest,
3457 ReverseRolesOneAudioLocalToOneVideoRemote) {
3458 ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics());
3459 ConnectFakeSignaling();
3460 caller()->AddAudioTrack();
3461 callee()->AddVideoTrack();
3462
3463 caller()->CreateAndSetAndSignalOffer();
3464 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3465
3466 // Verify that only the audio track has been negotiated.
3467 EXPECT_EQ(0u, caller()->GetReceiversOfType(cricket::MEDIA_TYPE_VIDEO).size());
3468 // Might also check that the callee's NegotiationNeeded flag is set.
3469
3470 // Reverse roles.
3471 callee()->CreateAndSetAndSignalOffer();
3472 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3473
Seth Hampson2f0d7022018-02-20 11:54:42 -08003474 MediaExpectations media_expectations;
3475 media_expectations.CallerExpectsSomeVideo();
3476 media_expectations.CalleeExpectsSomeAudio();
3477 ASSERT_TRUE(ExpectNewFrames(media_expectations));
Steve Anton74255ff2018-01-24 18:32:57 -08003478}
3479
Taylor Brandstetter1c7ecef2021-08-11 12:38:35 -07003480TEST_P(PeerConnectionIntegrationTest, NewTracksDoNotCauseNewCandidates) {
3481 ASSERT_TRUE(CreatePeerConnectionWrappers());
3482 ConnectFakeSignaling();
3483 caller()->AddAudioVideoTracks();
3484 caller()->CreateAndSetAndSignalOffer();
3485 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3486 ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout);
3487 caller()->ExpectCandidates(0);
3488 callee()->ExpectCandidates(0);
3489 caller()->AddAudioTrack();
3490 caller()->CreateAndSetAndSignalOffer();
3491 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3492}
3493
Harald Alvestrand35ba0c52022-05-05 07:37:41 +00003494TEST_P(PeerConnectionIntegrationTest, MediaCallWithoutMediaEngineFails) {
3495 ASSERT_TRUE(CreatePeerConnectionWrappersWithoutMediaEngine());
3496 // AddTrack should fail.
3497 EXPECT_FALSE(
3498 caller()->pc()->AddTrack(caller()->CreateLocalAudioTrack(), {}).ok());
3499}
3500
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003501INSTANTIATE_TEST_SUITE_P(
Steve Antonba42e992018-04-09 14:10:01 -07003502 PeerConnectionIntegrationTest,
3503 PeerConnectionIntegrationInteropTest,
Florent Castelli15a38de2022-04-06 00:38:21 +02003504 Values(std::make_tuple(SdpSemantics::kPlanB_DEPRECATED,
3505 SdpSemantics::kUnifiedPlan),
3506 std::make_tuple(SdpSemantics::kUnifiedPlan,
3507 SdpSemantics::kPlanB_DEPRECATED)));
Steve Antonba42e992018-04-09 14:10:01 -07003508
3509// Test that if the Unified Plan side offers two video tracks then the Plan B
3510// side will only see the first one and ignore the second.
3511TEST_F(PeerConnectionIntegrationTestPlanB, TwoVideoUnifiedPlanToNoMediaPlanB) {
Steve Anton3acffc32018-04-12 17:21:03 -07003512 ASSERT_TRUE(CreatePeerConnectionWrappersWithSdpSemantics(
Florent Castelli15a38de2022-04-06 00:38:21 +02003513 SdpSemantics::kUnifiedPlan, SdpSemantics::kPlanB_DEPRECATED));
Steve Anton74255ff2018-01-24 18:32:57 -08003514 ConnectFakeSignaling();
3515 auto first_sender = caller()->AddVideoTrack();
3516 caller()->AddVideoTrack();
3517
3518 caller()->CreateAndSetAndSignalOffer();
3519 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3520
3521 // Verify that there is only one receiver and it corresponds to the first
3522 // added track.
3523 auto receivers = callee()->pc()->GetReceivers();
3524 ASSERT_EQ(1u, receivers.size());
3525 EXPECT_TRUE(receivers[0]->track()->enabled());
3526 EXPECT_EQ(first_sender->track()->id(), receivers[0]->track()->id());
3527
Seth Hampson2f0d7022018-02-20 11:54:42 -08003528 MediaExpectations media_expectations;
3529 media_expectations.CalleeExpectsSomeVideo();
3530 ASSERT_TRUE(ExpectNewFrames(media_expectations));
Steve Anton74255ff2018-01-24 18:32:57 -08003531}
3532
Steve Anton2bed3972019-01-04 17:04:30 -08003533// Test that if the initial offer tagged BUNDLE section is rejected due to its
3534// associated RtpTransceiver being stopped and another transceiver is added,
3535// then renegotiation causes the callee to receive the new video track without
3536// error.
3537// This is a regression test for bugs.webrtc.org/9954
3538TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
3539 ReOfferWithStoppedBundleTaggedTransceiver) {
3540 RTCConfiguration config;
3541 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
3542 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config));
3543 ConnectFakeSignaling();
3544 auto audio_transceiver_or_error =
3545 caller()->pc()->AddTransceiver(caller()->CreateLocalAudioTrack());
3546 ASSERT_TRUE(audio_transceiver_or_error.ok());
3547 auto audio_transceiver = audio_transceiver_or_error.MoveValue();
3548
3549 caller()->CreateAndSetAndSignalOffer();
3550 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3551 {
3552 MediaExpectations media_expectations;
3553 media_expectations.CalleeExpectsSomeAudio();
3554 ASSERT_TRUE(ExpectNewFrames(media_expectations));
3555 }
3556
Harald Alvestrand6060df52020-08-11 09:54:02 +02003557 audio_transceiver->StopInternal();
Steve Anton2bed3972019-01-04 17:04:30 -08003558 caller()->pc()->AddTransceiver(caller()->CreateLocalVideoTrack());
3559
3560 caller()->CreateAndSetAndSignalOffer();
3561 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3562 {
3563 MediaExpectations media_expectations;
3564 media_expectations.CalleeExpectsSomeVideo();
3565 ASSERT_TRUE(ExpectNewFrames(media_expectations));
3566 }
3567}
3568
Harald Alvestrandbedb6052020-08-20 14:50:10 +02003569TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
3570 StopTransceiverRemovesDtlsTransports) {
3571 RTCConfiguration config;
3572 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config));
3573 ConnectFakeSignaling();
3574 auto audio_transceiver_or_error =
3575 caller()->pc()->AddTransceiver(caller()->CreateLocalAudioTrack());
3576 ASSERT_TRUE(audio_transceiver_or_error.ok());
3577 auto audio_transceiver = audio_transceiver_or_error.MoveValue();
3578
3579 caller()->CreateAndSetAndSignalOffer();
3580 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3581
3582 audio_transceiver->StopStandard();
3583 caller()->CreateAndSetAndSignalOffer();
3584 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3585 ASSERT_EQ(0U, caller()->pc()->GetTransceivers().size());
3586 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
3587 caller()->pc()->ice_gathering_state());
3588 EXPECT_THAT(caller()->ice_gathering_state_history(),
3589 ElementsAre(PeerConnectionInterface::kIceGatheringGathering,
3590 PeerConnectionInterface::kIceGatheringComplete,
3591 PeerConnectionInterface::kIceGatheringNew));
3592}
3593
Harald Alvestrand1ee33252020-09-24 13:31:15 +00003594TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
Harald Alvestrand45be0a92020-09-30 06:55:23 +00003595 StopTransceiverStopsAndRemovesTransceivers) {
3596 RTCConfiguration config;
3597 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config));
3598 ConnectFakeSignaling();
3599 auto audio_transceiver_or_error =
3600 caller()->pc()->AddTransceiver(caller()->CreateLocalAudioTrack());
3601 ASSERT_TRUE(audio_transceiver_or_error.ok());
3602 auto caller_transceiver = audio_transceiver_or_error.MoveValue();
3603
3604 caller()->CreateAndSetAndSignalOffer();
3605 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3606 caller_transceiver->StopStandard();
3607
3608 auto callee_transceiver = callee()->pc()->GetTransceivers()[0];
3609 caller()->CreateAndSetAndSignalOffer();
3610 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3611 EXPECT_EQ(0U, caller()->pc()->GetTransceivers().size());
3612 EXPECT_EQ(0U, callee()->pc()->GetTransceivers().size());
3613 EXPECT_EQ(0U, caller()->pc()->GetSenders().size());
3614 EXPECT_EQ(0U, callee()->pc()->GetSenders().size());
3615 EXPECT_EQ(0U, caller()->pc()->GetReceivers().size());
3616 EXPECT_EQ(0U, callee()->pc()->GetReceivers().size());
3617 EXPECT_TRUE(caller_transceiver->stopped());
3618 EXPECT_TRUE(callee_transceiver->stopped());
3619}
3620
3621TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
Harald Alvestrand1ee33252020-09-24 13:31:15 +00003622 StopTransceiverEndsIncomingAudioTrack) {
3623 RTCConfiguration config;
3624 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config));
3625 ConnectFakeSignaling();
3626 auto audio_transceiver_or_error =
3627 caller()->pc()->AddTransceiver(caller()->CreateLocalAudioTrack());
3628 ASSERT_TRUE(audio_transceiver_or_error.ok());
3629 auto audio_transceiver = audio_transceiver_or_error.MoveValue();
3630
3631 caller()->CreateAndSetAndSignalOffer();
3632 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3633 auto caller_track = audio_transceiver->receiver()->track();
3634 auto callee_track = callee()->pc()->GetReceivers()[0]->track();
3635 audio_transceiver->StopStandard();
3636 EXPECT_EQ(MediaStreamTrackInterface::TrackState::kEnded,
3637 caller_track->state());
3638 caller()->CreateAndSetAndSignalOffer();
3639 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3640 EXPECT_EQ(MediaStreamTrackInterface::TrackState::kEnded,
3641 callee_track->state());
3642}
3643
3644TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
3645 StopTransceiverEndsIncomingVideoTrack) {
3646 RTCConfiguration config;
3647 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config));
3648 ConnectFakeSignaling();
3649 auto audio_transceiver_or_error =
3650 caller()->pc()->AddTransceiver(caller()->CreateLocalVideoTrack());
3651 ASSERT_TRUE(audio_transceiver_or_error.ok());
3652 auto audio_transceiver = audio_transceiver_or_error.MoveValue();
3653
3654 caller()->CreateAndSetAndSignalOffer();
3655 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3656 auto caller_track = audio_transceiver->receiver()->track();
3657 auto callee_track = callee()->pc()->GetReceivers()[0]->track();
3658 audio_transceiver->StopStandard();
3659 EXPECT_EQ(MediaStreamTrackInterface::TrackState::kEnded,
3660 caller_track->state());
3661 caller()->CreateAndSetAndSignalOffer();
3662 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3663 EXPECT_EQ(MediaStreamTrackInterface::TrackState::kEnded,
3664 callee_track->state());
3665}
3666
Jonas Oreland65455162022-06-08 11:25:46 +02003667TEST_P(PeerConnectionIntegrationTest, EndToEndRtpSenderVideoEncoderSelector) {
3668 ASSERT_TRUE(
3669 CreateOneDirectionalPeerConnectionWrappers(/*caller_to_callee=*/true));
3670 ConnectFakeSignaling();
3671 // Add one-directional video, from caller to callee.
3672 rtc::scoped_refptr<webrtc::VideoTrackInterface> caller_track =
3673 caller()->CreateLocalVideoTrack();
3674 auto sender = caller()->AddTrack(caller_track);
3675 PeerConnectionInterface::RTCOfferAnswerOptions options;
3676 options.offer_to_receive_video = 0;
3677 caller()->SetOfferAnswerOptions(options);
3678 caller()->CreateAndSetAndSignalOffer();
3679 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3680 ASSERT_EQ(callee()->pc()->GetReceivers().size(), 1u);
3681
3682 std::unique_ptr<MockEncoderSelector> encoder_selector =
3683 std::make_unique<MockEncoderSelector>();
3684 EXPECT_CALL(*encoder_selector, OnCurrentEncoder);
3685
3686 sender->SetEncoderSelector(std::move(encoder_selector));
3687
3688 // Expect video to be received in one direction.
3689 MediaExpectations media_expectations;
3690 media_expectations.CallerExpectsNoVideo();
3691 media_expectations.CalleeExpectsSomeVideo();
3692
3693 EXPECT_TRUE(ExpectNewFrames(media_expectations));
3694}
3695
Harald Alvestrand89c40e22021-02-17 08:58:35 +00003696} // namespace
Harald Alvestrand39993842021-02-17 09:05:31 +00003697
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +01003698} // namespace webrtc