deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1 | /* |
| 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 Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 11 | #include <stdint.h> |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 12 | |
Taylor Brandstetter | d3ef499 | 2020-10-15 18:22:57 -0700 | [diff] [blame] | 13 | #include <algorithm> |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 14 | #include <memory> |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <tuple> |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 17 | #include <utility> |
| 18 | #include <vector> |
| 19 | |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 20 | #include "absl/algorithm/container.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 21 | #include "absl/types/optional.h" |
| 22 | #include "api/async_resolver_factory.h" |
| 23 | #include "api/candidate.h" |
| 24 | #include "api/crypto/crypto_options.h" |
| 25 | #include "api/dtmf_sender_interface.h" |
| 26 | #include "api/ice_transport_interface.h" |
| 27 | #include "api/jsep.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 28 | #include "api/media_stream_interface.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 29 | #include "api/media_types.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 30 | #include "api/peer_connection_interface.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 31 | #include "api/rtc_error.h" |
| 32 | #include "api/rtc_event_log/rtc_event.h" |
| 33 | #include "api/rtc_event_log/rtc_event_log.h" |
| 34 | #include "api/rtc_event_log_output.h" |
| 35 | #include "api/rtp_parameters.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 36 | #include "api/rtp_receiver_interface.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 37 | #include "api/rtp_sender_interface.h" |
| 38 | #include "api/rtp_transceiver_direction.h" |
| 39 | #include "api/rtp_transceiver_interface.h" |
| 40 | #include "api/scoped_refptr.h" |
| 41 | #include "api/stats/rtc_stats.h" |
| 42 | #include "api/stats/rtc_stats_report.h" |
| 43 | #include "api/stats/rtcstats_objects.h" |
| 44 | #include "api/transport/rtp/rtp_source.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 45 | #include "api/uma_metrics.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 46 | #include "api/units/time_delta.h" |
| 47 | #include "api/video/video_rotation.h" |
| 48 | #include "logging/rtc_event_log/fake_rtc_event_log.h" |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 49 | #include "logging/rtc_event_log/fake_rtc_event_log_factory.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 50 | #include "media/base/codec.h" |
| 51 | #include "media/base/media_constants.h" |
| 52 | #include "media/base/stream_params.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 53 | #include "p2p/base/mock_async_resolver.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 54 | #include "p2p/base/port.h" |
| 55 | #include "p2p/base/port_allocator.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 56 | #include "p2p/base/port_interface.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 57 | #include "p2p/base/stun_server.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 58 | #include "p2p/base/test_stun_server.h" |
| 59 | #include "p2p/base/test_turn_customizer.h" |
| 60 | #include "p2p/base/test_turn_server.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 61 | #include "p2p/base/transport_description.h" |
| 62 | #include "p2p/base/transport_info.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 63 | #include "pc/media_session.h" |
| 64 | #include "pc/peer_connection.h" |
| 65 | #include "pc/peer_connection_factory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 66 | #include "pc/session_description.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 67 | #include "pc/test/fake_periodic_video_source.h" |
| 68 | #include "pc/test/integration_test_helpers.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 69 | #include "pc/test/mock_peer_connection_observers.h" |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 70 | #include "rtc_base/fake_clock.h" |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 71 | #include "rtc_base/fake_mdns_responder.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 72 | #include "rtc_base/fake_network.h" |
| 73 | #include "rtc_base/firewall_socket_server.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 74 | #include "rtc_base/gunit.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 75 | #include "rtc_base/helpers.h" |
| 76 | #include "rtc_base/location.h" |
| 77 | #include "rtc_base/logging.h" |
| 78 | #include "rtc_base/ref_counted_object.h" |
| 79 | #include "rtc_base/socket_address.h" |
| 80 | #include "rtc_base/ssl_certificate.h" |
| 81 | #include "rtc_base/ssl_fingerprint.h" |
| 82 | #include "rtc_base/ssl_identity.h" |
| 83 | #include "rtc_base/ssl_stream_adapter.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 84 | #include "rtc_base/test_certificate_verifier.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 85 | #include "rtc_base/thread.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 86 | #include "rtc_base/time_utils.h" |
| 87 | #include "rtc_base/virtual_socket_server.h" |
Mirko Bonadei | 17f4878 | 2018-09-28 08:51:10 +0200 | [diff] [blame] | 88 | #include "system_wrappers/include/metrics.h" |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 89 | |
Mirko Bonadei | ab64e8a | 2018-12-12 12:10:18 +0100 | [diff] [blame] | 90 | namespace webrtc { |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 91 | |
Mirko Bonadei | ab64e8a | 2018-12-12 12:10:18 +0100 | [diff] [blame] | 92 | namespace { |
| 93 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 94 | class PeerConnectionIntegrationTest |
| 95 | : public PeerConnectionIntegrationBaseTest, |
| 96 | public ::testing::WithParamInterface<SdpSemantics> { |
| 97 | protected: |
| 98 | PeerConnectionIntegrationTest() |
| 99 | : PeerConnectionIntegrationBaseTest(GetParam()) {} |
| 100 | }; |
| 101 | |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 102 | // Fake clock must be set before threads are started to prevent race on |
| 103 | // Set/GetClockForTesting(). |
| 104 | // To achieve that, multiple inheritance is used as a mixin pattern |
| 105 | // where order of construction is finely controlled. |
| 106 | // This also ensures peerconnection is closed before switching back to non-fake |
| 107 | // clock, avoiding other races and DCHECK failures such as in rtp_sender.cc. |
| 108 | class FakeClockForTest : public rtc::ScopedFakeClock { |
| 109 | protected: |
| 110 | FakeClockForTest() { |
| 111 | // Some things use a time of "0" as a special value, so we need to start out |
| 112 | // the fake clock at a nonzero time. |
| 113 | // TODO(deadbeef): Fix this. |
Danil Chapovalov | 0c626af | 2020-02-10 11:16:00 +0100 | [diff] [blame] | 114 | AdvanceTime(webrtc::TimeDelta::Seconds(1)); |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | // Explicit handle. |
| 118 | ScopedFakeClock& FakeClock() { return *this; } |
| 119 | }; |
| 120 | |
| 121 | // Ensure FakeClockForTest is constructed first (see class for rationale). |
| 122 | class PeerConnectionIntegrationTestWithFakeClock |
| 123 | : public FakeClockForTest, |
| 124 | public PeerConnectionIntegrationTest {}; |
| 125 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 126 | class PeerConnectionIntegrationTestPlanB |
| 127 | : public PeerConnectionIntegrationBaseTest { |
| 128 | protected: |
| 129 | PeerConnectionIntegrationTestPlanB() |
| 130 | : PeerConnectionIntegrationBaseTest(SdpSemantics::kPlanB) {} |
| 131 | }; |
| 132 | |
| 133 | class PeerConnectionIntegrationTestUnifiedPlan |
| 134 | : public PeerConnectionIntegrationBaseTest { |
| 135 | protected: |
| 136 | PeerConnectionIntegrationTestUnifiedPlan() |
| 137 | : PeerConnectionIntegrationBaseTest(SdpSemantics::kUnifiedPlan) {} |
| 138 | }; |
| 139 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 140 | // Test the OnFirstPacketReceived callback from audio/video RtpReceivers. This |
| 141 | // includes testing that the callback is invoked if an observer is connected |
| 142 | // after the first packet has already been received. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 143 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 144 | RtpReceiverObserverOnFirstPacketReceived) { |
| 145 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 146 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 147 | caller()->AddAudioVideoTracks(); |
| 148 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 149 | // Start offer/answer exchange and wait for it to complete. |
| 150 | caller()->CreateAndSetAndSignalOffer(); |
| 151 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 152 | // Should be one receiver each for audio/video. |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 153 | EXPECT_EQ(2U, caller()->rtp_receiver_observers().size()); |
| 154 | EXPECT_EQ(2U, callee()->rtp_receiver_observers().size()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 155 | // Wait for all "first packet received" callbacks to be fired. |
| 156 | EXPECT_TRUE_WAIT( |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 157 | absl::c_all_of(caller()->rtp_receiver_observers(), |
| 158 | [](const std::unique_ptr<MockRtpReceiverObserver>& o) { |
| 159 | return o->first_packet_received(); |
| 160 | }), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 161 | kMaxWaitForFramesMs); |
| 162 | EXPECT_TRUE_WAIT( |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 163 | absl::c_all_of(callee()->rtp_receiver_observers(), |
| 164 | [](const std::unique_ptr<MockRtpReceiverObserver>& o) { |
| 165 | return o->first_packet_received(); |
| 166 | }), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 167 | kMaxWaitForFramesMs); |
| 168 | // If new observers are set after the first packet was already received, the |
| 169 | // callback should still be invoked. |
| 170 | caller()->ResetRtpReceiverObservers(); |
| 171 | callee()->ResetRtpReceiverObservers(); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 172 | EXPECT_EQ(2U, caller()->rtp_receiver_observers().size()); |
| 173 | EXPECT_EQ(2U, callee()->rtp_receiver_observers().size()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 174 | EXPECT_TRUE( |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 175 | absl::c_all_of(caller()->rtp_receiver_observers(), |
| 176 | [](const std::unique_ptr<MockRtpReceiverObserver>& o) { |
| 177 | return o->first_packet_received(); |
| 178 | })); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 179 | EXPECT_TRUE( |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 180 | absl::c_all_of(callee()->rtp_receiver_observers(), |
| 181 | [](const std::unique_ptr<MockRtpReceiverObserver>& o) { |
| 182 | return o->first_packet_received(); |
| 183 | })); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | class DummyDtmfObserver : public DtmfSenderObserverInterface { |
| 187 | public: |
| 188 | DummyDtmfObserver() : completed_(false) {} |
| 189 | |
| 190 | // Implements DtmfSenderObserverInterface. |
| 191 | void OnToneChange(const std::string& tone) override { |
| 192 | tones_.push_back(tone); |
| 193 | if (tone.empty()) { |
| 194 | completed_ = true; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | const std::vector<std::string>& tones() const { return tones_; } |
| 199 | bool completed() const { return completed_; } |
| 200 | |
| 201 | private: |
| 202 | bool completed_; |
| 203 | std::vector<std::string> tones_; |
| 204 | }; |
| 205 | |
| 206 | // Assumes |sender| already has an audio track added and the offer/answer |
| 207 | // exchange is done. |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 208 | void TestDtmfFromSenderToReceiver(PeerConnectionIntegrationWrapper* sender, |
| 209 | PeerConnectionIntegrationWrapper* receiver) { |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 210 | // We should be able to get a DTMF sender from the local sender. |
| 211 | rtc::scoped_refptr<DtmfSenderInterface> dtmf_sender = |
| 212 | sender->pc()->GetSenders().at(0)->GetDtmfSender(); |
| 213 | ASSERT_TRUE(dtmf_sender); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 214 | DummyDtmfObserver observer; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 215 | dtmf_sender->RegisterObserver(&observer); |
| 216 | |
| 217 | // Test the DtmfSender object just created. |
| 218 | EXPECT_TRUE(dtmf_sender->CanInsertDtmf()); |
| 219 | EXPECT_TRUE(dtmf_sender->InsertDtmf("1a", 100, 50)); |
| 220 | |
| 221 | EXPECT_TRUE_WAIT(observer.completed(), kDefaultTimeout); |
| 222 | std::vector<std::string> tones = {"1", "a", ""}; |
| 223 | EXPECT_EQ(tones, observer.tones()); |
| 224 | dtmf_sender->UnregisterObserver(); |
| 225 | // TODO(deadbeef): Verify the tones were actually received end-to-end. |
| 226 | } |
| 227 | |
| 228 | // Verifies the DtmfSenderObserver callbacks for a DtmfSender (one in each |
| 229 | // direction). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 230 | TEST_P(PeerConnectionIntegrationTest, DtmfSenderObserver) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 231 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 232 | ConnectFakeSignaling(); |
| 233 | // Only need audio for DTMF. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 234 | caller()->AddAudioTrack(); |
| 235 | callee()->AddAudioTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 236 | caller()->CreateAndSetAndSignalOffer(); |
| 237 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
deadbeef | 7145280 | 2017-05-07 17:21:01 -0700 | [diff] [blame] | 238 | // DTLS must finish before the DTMF sender can be used reliably. |
| 239 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 240 | TestDtmfFromSenderToReceiver(caller(), callee()); |
| 241 | TestDtmfFromSenderToReceiver(callee(), caller()); |
| 242 | } |
| 243 | |
| 244 | // Basic end-to-end test, verifying media can be encoded/transmitted/decoded |
| 245 | // between two connections, using DTLS-SRTP. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 246 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithDtls) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 247 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 248 | ConnectFakeSignaling(); |
Harald Alvestrand | 194939b | 2018-01-24 16:04:13 +0100 | [diff] [blame] | 249 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 250 | // Do normal offer/answer and wait for some frames to be received in each |
| 251 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 252 | caller()->AddAudioVideoTracks(); |
| 253 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 254 | caller()->CreateAndSetAndSignalOffer(); |
| 255 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 256 | MediaExpectations media_expectations; |
| 257 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 258 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 259 | EXPECT_METRIC_LE( |
| 260 | 2, webrtc::metrics::NumEvents("WebRTC.PeerConnection.KeyProtocol", |
| 261 | webrtc::kEnumCounterKeyProtocolDtls)); |
| 262 | EXPECT_METRIC_EQ( |
| 263 | 0, webrtc::metrics::NumEvents("WebRTC.PeerConnection.KeyProtocol", |
| 264 | webrtc::kEnumCounterKeyProtocolSdes)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | // Uses SDES instead of DTLS for key agreement. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 268 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithSdes) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 269 | PeerConnectionInterface::RTCConfiguration sdes_config; |
| 270 | sdes_config.enable_dtls_srtp.emplace(false); |
| 271 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(sdes_config, sdes_config)); |
| 272 | ConnectFakeSignaling(); |
| 273 | |
| 274 | // Do normal offer/answer and wait for some frames to be received in each |
| 275 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 276 | caller()->AddAudioVideoTracks(); |
| 277 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 278 | caller()->CreateAndSetAndSignalOffer(); |
| 279 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 280 | MediaExpectations media_expectations; |
| 281 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 282 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 283 | EXPECT_METRIC_LE( |
| 284 | 2, webrtc::metrics::NumEvents("WebRTC.PeerConnection.KeyProtocol", |
| 285 | webrtc::kEnumCounterKeyProtocolSdes)); |
| 286 | EXPECT_METRIC_EQ( |
| 287 | 0, webrtc::metrics::NumEvents("WebRTC.PeerConnection.KeyProtocol", |
| 288 | webrtc::kEnumCounterKeyProtocolDtls)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Steve Anton | 9a44b2d | 2019-07-12 12:58:30 -0700 | [diff] [blame] | 291 | // Basic end-to-end test specifying the |enable_encrypted_rtp_header_extensions| |
| 292 | // option to offer encrypted versions of all header extensions alongside the |
| 293 | // unencrypted versions. |
| 294 | TEST_P(PeerConnectionIntegrationTest, |
| 295 | EndToEndCallWithEncryptedRtpHeaderExtensions) { |
| 296 | CryptoOptions crypto_options; |
| 297 | crypto_options.srtp.enable_encrypted_rtp_header_extensions = true; |
| 298 | PeerConnectionInterface::RTCConfiguration config; |
| 299 | config.crypto_options = crypto_options; |
| 300 | // Note: This allows offering >14 RTP header extensions. |
| 301 | config.offer_extmap_allow_mixed = true; |
| 302 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 303 | ConnectFakeSignaling(); |
| 304 | |
| 305 | // Do normal offer/answer and wait for some frames to be received in each |
| 306 | // direction. |
| 307 | caller()->AddAudioVideoTracks(); |
| 308 | callee()->AddAudioVideoTracks(); |
| 309 | caller()->CreateAndSetAndSignalOffer(); |
| 310 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 311 | MediaExpectations media_expectations; |
| 312 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 313 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 314 | } |
| 315 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 316 | // This test sets up a call between two parties with a source resolution of |
| 317 | // 1280x720 and verifies that a 16:9 aspect ratio is received. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 318 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 319 | Send1280By720ResolutionAndReceive16To9AspectRatio) { |
| 320 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 321 | ConnectFakeSignaling(); |
| 322 | |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 323 | // Add video tracks with 16:9 aspect ratio, size 1280 x 720. |
| 324 | webrtc::FakePeriodicVideoSource::Config config; |
| 325 | config.width = 1280; |
| 326 | config.height = 720; |
Johannes Kron | 965e794 | 2018-09-13 15:36:20 +0200 | [diff] [blame] | 327 | config.timestamp_offset_ms = rtc::TimeMillis(); |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 328 | caller()->AddTrack(caller()->CreateLocalVideoTrackWithConfig(config)); |
| 329 | callee()->AddTrack(callee()->CreateLocalVideoTrackWithConfig(config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 330 | |
| 331 | // Do normal offer/answer and wait for at least one frame to be received in |
| 332 | // each direction. |
| 333 | caller()->CreateAndSetAndSignalOffer(); |
| 334 | ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 && |
| 335 | callee()->min_video_frames_received_per_track() > 0, |
| 336 | kMaxWaitForFramesMs); |
| 337 | |
| 338 | // Check rendered aspect ratio. |
| 339 | EXPECT_EQ(16.0 / 9, caller()->local_rendered_aspect_ratio()); |
| 340 | EXPECT_EQ(16.0 / 9, caller()->rendered_aspect_ratio()); |
| 341 | EXPECT_EQ(16.0 / 9, callee()->local_rendered_aspect_ratio()); |
| 342 | EXPECT_EQ(16.0 / 9, callee()->rendered_aspect_ratio()); |
| 343 | } |
| 344 | |
| 345 | // This test sets up an one-way call, with media only from caller to |
| 346 | // callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 347 | TEST_P(PeerConnectionIntegrationTest, OneWayMediaCall) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 348 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 349 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 350 | caller()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 351 | caller()->CreateAndSetAndSignalOffer(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 352 | MediaExpectations media_expectations; |
| 353 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 354 | media_expectations.CallerExpectsNoAudio(); |
| 355 | media_expectations.CallerExpectsNoVideo(); |
| 356 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 359 | // Tests that send only works without the caller having a decoder factory and |
| 360 | // the callee having an encoder factory. |
| 361 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithSendOnlyVideo) { |
| 362 | ASSERT_TRUE( |
| 363 | CreateOneDirectionalPeerConnectionWrappers(/*caller_to_callee=*/true)); |
| 364 | ConnectFakeSignaling(); |
| 365 | // Add one-directional video, from caller to callee. |
| 366 | rtc::scoped_refptr<webrtc::VideoTrackInterface> caller_track = |
| 367 | caller()->CreateLocalVideoTrack(); |
| 368 | caller()->AddTrack(caller_track); |
| 369 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 370 | options.offer_to_receive_video = 0; |
| 371 | caller()->SetOfferAnswerOptions(options); |
| 372 | caller()->CreateAndSetAndSignalOffer(); |
| 373 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 374 | ASSERT_EQ(callee()->pc()->GetReceivers().size(), 1u); |
| 375 | |
| 376 | // Expect video to be received in one direction. |
| 377 | MediaExpectations media_expectations; |
| 378 | media_expectations.CallerExpectsNoVideo(); |
| 379 | media_expectations.CalleeExpectsSomeVideo(); |
| 380 | |
| 381 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 382 | } |
| 383 | |
| 384 | // Tests that receive only works without the caller having an encoder factory |
| 385 | // and the callee having a decoder factory. |
| 386 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithReceiveOnlyVideo) { |
| 387 | ASSERT_TRUE( |
| 388 | CreateOneDirectionalPeerConnectionWrappers(/*caller_to_callee=*/false)); |
| 389 | ConnectFakeSignaling(); |
| 390 | // Add one-directional video, from callee to caller. |
| 391 | rtc::scoped_refptr<webrtc::VideoTrackInterface> callee_track = |
| 392 | callee()->CreateLocalVideoTrack(); |
| 393 | callee()->AddTrack(callee_track); |
| 394 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 395 | options.offer_to_receive_video = 1; |
| 396 | caller()->SetOfferAnswerOptions(options); |
| 397 | caller()->CreateAndSetAndSignalOffer(); |
| 398 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 399 | ASSERT_EQ(caller()->pc()->GetReceivers().size(), 1u); |
| 400 | |
| 401 | // Expect video to be received in one direction. |
| 402 | MediaExpectations media_expectations; |
| 403 | media_expectations.CallerExpectsSomeVideo(); |
| 404 | media_expectations.CalleeExpectsNoVideo(); |
| 405 | |
| 406 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 407 | } |
| 408 | |
| 409 | TEST_P(PeerConnectionIntegrationTest, |
| 410 | EndToEndCallAddReceiveVideoToSendOnlyCall) { |
| 411 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 412 | ConnectFakeSignaling(); |
| 413 | // Add one-directional video, from caller to callee. |
| 414 | rtc::scoped_refptr<webrtc::VideoTrackInterface> caller_track = |
| 415 | caller()->CreateLocalVideoTrack(); |
| 416 | caller()->AddTrack(caller_track); |
| 417 | caller()->CreateAndSetAndSignalOffer(); |
| 418 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 419 | |
| 420 | // Add receive video. |
| 421 | rtc::scoped_refptr<webrtc::VideoTrackInterface> callee_track = |
| 422 | callee()->CreateLocalVideoTrack(); |
| 423 | callee()->AddTrack(callee_track); |
| 424 | caller()->CreateAndSetAndSignalOffer(); |
| 425 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 426 | |
| 427 | // Ensure that video frames are received end-to-end. |
| 428 | MediaExpectations media_expectations; |
| 429 | media_expectations.ExpectBidirectionalVideo(); |
| 430 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 431 | } |
| 432 | |
| 433 | TEST_P(PeerConnectionIntegrationTest, |
| 434 | EndToEndCallAddSendVideoToReceiveOnlyCall) { |
| 435 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 436 | ConnectFakeSignaling(); |
| 437 | // Add one-directional video, from callee to caller. |
| 438 | rtc::scoped_refptr<webrtc::VideoTrackInterface> callee_track = |
| 439 | callee()->CreateLocalVideoTrack(); |
| 440 | callee()->AddTrack(callee_track); |
| 441 | caller()->CreateAndSetAndSignalOffer(); |
| 442 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 443 | |
| 444 | // Add send video. |
| 445 | rtc::scoped_refptr<webrtc::VideoTrackInterface> caller_track = |
| 446 | caller()->CreateLocalVideoTrack(); |
| 447 | caller()->AddTrack(caller_track); |
| 448 | caller()->CreateAndSetAndSignalOffer(); |
| 449 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 450 | |
| 451 | // Expect video to be received in one direction. |
| 452 | MediaExpectations media_expectations; |
| 453 | media_expectations.ExpectBidirectionalVideo(); |
| 454 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 455 | } |
| 456 | |
| 457 | TEST_P(PeerConnectionIntegrationTest, |
| 458 | EndToEndCallRemoveReceiveVideoFromSendReceiveCall) { |
| 459 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 460 | ConnectFakeSignaling(); |
| 461 | // Add send video, from caller to callee. |
| 462 | rtc::scoped_refptr<webrtc::VideoTrackInterface> caller_track = |
| 463 | caller()->CreateLocalVideoTrack(); |
| 464 | rtc::scoped_refptr<webrtc::RtpSenderInterface> caller_sender = |
| 465 | caller()->AddTrack(caller_track); |
| 466 | // Add receive video, from callee to caller. |
| 467 | rtc::scoped_refptr<webrtc::VideoTrackInterface> callee_track = |
| 468 | callee()->CreateLocalVideoTrack(); |
| 469 | |
| 470 | rtc::scoped_refptr<webrtc::RtpSenderInterface> callee_sender = |
| 471 | callee()->AddTrack(callee_track); |
| 472 | caller()->CreateAndSetAndSignalOffer(); |
| 473 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 474 | |
| 475 | // Remove receive video (i.e., callee sender track). |
| 476 | callee()->pc()->RemoveTrack(callee_sender); |
| 477 | |
| 478 | caller()->CreateAndSetAndSignalOffer(); |
| 479 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 480 | |
| 481 | // Expect one-directional video. |
| 482 | MediaExpectations media_expectations; |
| 483 | media_expectations.CallerExpectsNoVideo(); |
| 484 | media_expectations.CalleeExpectsSomeVideo(); |
| 485 | |
| 486 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 487 | } |
| 488 | |
| 489 | TEST_P(PeerConnectionIntegrationTest, |
| 490 | EndToEndCallRemoveSendVideoFromSendReceiveCall) { |
| 491 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 492 | ConnectFakeSignaling(); |
| 493 | // Add send video, from caller to callee. |
| 494 | rtc::scoped_refptr<webrtc::VideoTrackInterface> caller_track = |
| 495 | caller()->CreateLocalVideoTrack(); |
| 496 | rtc::scoped_refptr<webrtc::RtpSenderInterface> caller_sender = |
| 497 | caller()->AddTrack(caller_track); |
| 498 | // Add receive video, from callee to caller. |
| 499 | rtc::scoped_refptr<webrtc::VideoTrackInterface> callee_track = |
| 500 | callee()->CreateLocalVideoTrack(); |
| 501 | |
| 502 | rtc::scoped_refptr<webrtc::RtpSenderInterface> callee_sender = |
| 503 | callee()->AddTrack(callee_track); |
| 504 | caller()->CreateAndSetAndSignalOffer(); |
| 505 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 506 | |
| 507 | // Remove send video (i.e., caller sender track). |
| 508 | caller()->pc()->RemoveTrack(caller_sender); |
| 509 | |
| 510 | caller()->CreateAndSetAndSignalOffer(); |
| 511 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 512 | |
| 513 | // Expect one-directional video. |
| 514 | MediaExpectations media_expectations; |
| 515 | media_expectations.CalleeExpectsNoVideo(); |
| 516 | media_expectations.CallerExpectsSomeVideo(); |
| 517 | |
| 518 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 519 | } |
| 520 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 521 | // This test sets up a audio call initially, with the callee rejecting video |
| 522 | // initially. Then later the callee decides to upgrade to audio/video, and |
| 523 | // initiates a new offer/answer exchange. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 524 | TEST_P(PeerConnectionIntegrationTest, AudioToVideoUpgrade) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 525 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 526 | ConnectFakeSignaling(); |
| 527 | // Initially, offer an audio/video stream from the caller, but refuse to |
| 528 | // send/receive video on the callee side. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 529 | caller()->AddAudioVideoTracks(); |
| 530 | callee()->AddAudioTrack(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 531 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 532 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 533 | options.offer_to_receive_video = 0; |
| 534 | callee()->SetOfferAnswerOptions(options); |
| 535 | } else { |
| 536 | callee()->SetRemoteOfferHandler([this] { |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 537 | callee() |
| 538 | ->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO) |
| 539 | ->StopInternal(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 540 | }); |
| 541 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 542 | // Do offer/answer and make sure audio is still received end-to-end. |
| 543 | caller()->CreateAndSetAndSignalOffer(); |
| 544 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 545 | { |
| 546 | MediaExpectations media_expectations; |
| 547 | media_expectations.ExpectBidirectionalAudio(); |
| 548 | media_expectations.ExpectNoVideo(); |
| 549 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 550 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 551 | // Sanity check that the callee's description has a rejected video section. |
| 552 | ASSERT_NE(nullptr, callee()->pc()->local_description()); |
| 553 | const ContentInfo* callee_video_content = |
| 554 | GetFirstVideoContent(callee()->pc()->local_description()->description()); |
| 555 | ASSERT_NE(nullptr, callee_video_content); |
| 556 | EXPECT_TRUE(callee_video_content->rejected); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 557 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 558 | // Now negotiate with video and ensure negotiation succeeds, with video |
| 559 | // frames and additional audio frames being received. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 560 | callee()->AddVideoTrack(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 561 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 562 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 563 | options.offer_to_receive_video = 1; |
| 564 | callee()->SetOfferAnswerOptions(options); |
| 565 | } else { |
| 566 | callee()->SetRemoteOfferHandler(nullptr); |
| 567 | caller()->SetRemoteOfferHandler([this] { |
| 568 | // The caller creates a new transceiver to receive video on when receiving |
| 569 | // the offer, but by default it is send only. |
| 570 | auto transceivers = caller()->pc()->GetTransceivers(); |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 571 | ASSERT_EQ(2U, transceivers.size()); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 572 | ASSERT_EQ(cricket::MEDIA_TYPE_VIDEO, |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 573 | transceivers[1]->receiver()->media_type()); |
| 574 | transceivers[1]->sender()->SetTrack(caller()->CreateLocalVideoTrack()); |
| 575 | transceivers[1]->SetDirectionWithError( |
| 576 | RtpTransceiverDirection::kSendRecv); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 577 | }); |
| 578 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 579 | callee()->CreateAndSetAndSignalOffer(); |
| 580 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 581 | { |
| 582 | // Expect additional audio frames to be received after the upgrade. |
| 583 | MediaExpectations media_expectations; |
| 584 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 585 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 586 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 587 | } |
| 588 | |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 589 | // Simpler than the above test; just add an audio track to an established |
| 590 | // video-only connection. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 591 | TEST_P(PeerConnectionIntegrationTest, AddAudioToVideoOnlyCall) { |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 592 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 593 | ConnectFakeSignaling(); |
| 594 | // Do initial offer/answer with just a video track. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 595 | caller()->AddVideoTrack(); |
| 596 | callee()->AddVideoTrack(); |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 597 | caller()->CreateAndSetAndSignalOffer(); |
| 598 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 599 | // Now add an audio track and do another offer/answer. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 600 | caller()->AddAudioTrack(); |
| 601 | callee()->AddAudioTrack(); |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 602 | caller()->CreateAndSetAndSignalOffer(); |
| 603 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 604 | // Ensure both audio and video frames are received end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 605 | MediaExpectations media_expectations; |
| 606 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 607 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 608 | } |
| 609 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 610 | // This test sets up a call that's transferred to a new caller with a different |
| 611 | // DTLS fingerprint. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 612 | TEST_P(PeerConnectionIntegrationTest, CallTransferredForCallee) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 613 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 614 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 615 | caller()->AddAudioVideoTracks(); |
| 616 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 617 | caller()->CreateAndSetAndSignalOffer(); |
| 618 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 619 | |
| 620 | // Keep the original peer around which will still send packets to the |
| 621 | // receiving client. These SRTP packets will be dropped. |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 622 | std::unique_ptr<PeerConnectionIntegrationWrapper> original_peer( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 623 | SetCallerPcWrapperAndReturnCurrent( |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 624 | CreatePeerConnectionWrapperWithAlternateKey().release())); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 625 | // TODO(deadbeef): Why do we call Close here? That goes against the comment |
| 626 | // directly above. |
| 627 | original_peer->pc()->Close(); |
| 628 | |
| 629 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 630 | caller()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 631 | caller()->CreateAndSetAndSignalOffer(); |
| 632 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 633 | // Wait for some additional frames to be transmitted end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 634 | MediaExpectations media_expectations; |
| 635 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 636 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | // This test sets up a call that's transferred to a new callee with a different |
| 640 | // DTLS fingerprint. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 641 | TEST_P(PeerConnectionIntegrationTest, CallTransferredForCaller) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 642 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 643 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 644 | caller()->AddAudioVideoTracks(); |
| 645 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 646 | caller()->CreateAndSetAndSignalOffer(); |
| 647 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 648 | |
| 649 | // Keep the original peer around which will still send packets to the |
| 650 | // receiving client. These SRTP packets will be dropped. |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 651 | std::unique_ptr<PeerConnectionIntegrationWrapper> original_peer( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 652 | SetCalleePcWrapperAndReturnCurrent( |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 653 | CreatePeerConnectionWrapperWithAlternateKey().release())); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 654 | // TODO(deadbeef): Why do we call Close here? That goes against the comment |
| 655 | // directly above. |
| 656 | original_peer->pc()->Close(); |
| 657 | |
| 658 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 659 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 660 | caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions()); |
| 661 | caller()->CreateAndSetAndSignalOffer(); |
| 662 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 663 | // Wait for some additional frames to be transmitted end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 664 | MediaExpectations media_expectations; |
| 665 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 666 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | // This test sets up a non-bundled call and negotiates bundling at the same |
| 670 | // time as starting an ICE restart. When bundling is in effect in the restart, |
| 671 | // the DTLS-SRTP context should be successfully reset. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 672 | TEST_P(PeerConnectionIntegrationTest, BundlingEnabledWhileIceRestartOccurs) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 673 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 674 | ConnectFakeSignaling(); |
| 675 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 676 | caller()->AddAudioVideoTracks(); |
| 677 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 678 | // Remove the bundle group from the SDP received by the callee. |
| 679 | callee()->SetReceivedSdpMunger([](cricket::SessionDescription* desc) { |
| 680 | desc->RemoveGroupByName("BUNDLE"); |
| 681 | }); |
| 682 | caller()->CreateAndSetAndSignalOffer(); |
| 683 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 684 | { |
| 685 | MediaExpectations media_expectations; |
| 686 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 687 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 688 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 689 | // Now stop removing the BUNDLE group, and trigger an ICE restart. |
| 690 | callee()->SetReceivedSdpMunger(nullptr); |
| 691 | caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions()); |
| 692 | caller()->CreateAndSetAndSignalOffer(); |
| 693 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 694 | |
| 695 | // Expect additional frames to be received after the ICE restart. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 696 | { |
| 697 | MediaExpectations media_expectations; |
| 698 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 699 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 700 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | // Test CVO (Coordination of Video Orientation). If a video source is rotated |
| 704 | // and both peers support the CVO RTP header extension, the actual video frames |
| 705 | // don't need to be encoded in different resolutions, since the rotation is |
| 706 | // communicated through the RTP header extension. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 707 | TEST_P(PeerConnectionIntegrationTest, RotatedVideoWithCVOExtension) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 708 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 709 | ConnectFakeSignaling(); |
| 710 | // Add rotated video tracks. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 711 | caller()->AddTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 712 | caller()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_90)); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 713 | callee()->AddTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 714 | callee()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_270)); |
| 715 | |
| 716 | // Wait for video frames to be received by both sides. |
| 717 | caller()->CreateAndSetAndSignalOffer(); |
| 718 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 719 | ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 && |
| 720 | callee()->min_video_frames_received_per_track() > 0, |
| 721 | kMaxWaitForFramesMs); |
| 722 | |
| 723 | // Ensure that the aspect ratio is unmodified. |
| 724 | // TODO(deadbeef): Where does 4:3 come from? Should be explicit in the test, |
| 725 | // not just assumed. |
| 726 | EXPECT_EQ(4.0 / 3, caller()->local_rendered_aspect_ratio()); |
| 727 | EXPECT_EQ(4.0 / 3, caller()->rendered_aspect_ratio()); |
| 728 | EXPECT_EQ(4.0 / 3, callee()->local_rendered_aspect_ratio()); |
| 729 | EXPECT_EQ(4.0 / 3, callee()->rendered_aspect_ratio()); |
| 730 | // Ensure that the CVO bits were surfaced to the renderer. |
| 731 | EXPECT_EQ(webrtc::kVideoRotation_270, caller()->rendered_rotation()); |
| 732 | EXPECT_EQ(webrtc::kVideoRotation_90, callee()->rendered_rotation()); |
| 733 | } |
| 734 | |
| 735 | // Test that when the CVO extension isn't supported, video is rotated the |
| 736 | // old-fashioned way, by encoding rotated frames. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 737 | TEST_P(PeerConnectionIntegrationTest, RotatedVideoWithoutCVOExtension) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 738 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 739 | ConnectFakeSignaling(); |
| 740 | // Add rotated video tracks. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 741 | caller()->AddTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 742 | caller()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_90)); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 743 | callee()->AddTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 744 | callee()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_270)); |
| 745 | |
| 746 | // Remove the CVO extension from the offered SDP. |
| 747 | callee()->SetReceivedSdpMunger([](cricket::SessionDescription* desc) { |
| 748 | cricket::VideoContentDescription* video = |
| 749 | GetFirstVideoContentDescription(desc); |
| 750 | video->ClearRtpHeaderExtensions(); |
| 751 | }); |
| 752 | // Wait for video frames to be received by both sides. |
| 753 | caller()->CreateAndSetAndSignalOffer(); |
| 754 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 755 | ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 && |
| 756 | callee()->min_video_frames_received_per_track() > 0, |
| 757 | kMaxWaitForFramesMs); |
| 758 | |
| 759 | // Expect that the aspect ratio is inversed to account for the 90/270 degree |
| 760 | // rotation. |
| 761 | // TODO(deadbeef): Where does 4:3 come from? Should be explicit in the test, |
| 762 | // not just assumed. |
| 763 | EXPECT_EQ(3.0 / 4, caller()->local_rendered_aspect_ratio()); |
| 764 | EXPECT_EQ(3.0 / 4, caller()->rendered_aspect_ratio()); |
| 765 | EXPECT_EQ(3.0 / 4, callee()->local_rendered_aspect_ratio()); |
| 766 | EXPECT_EQ(3.0 / 4, callee()->rendered_aspect_ratio()); |
| 767 | // Expect that each endpoint is unaware of the rotation of the other endpoint. |
| 768 | EXPECT_EQ(webrtc::kVideoRotation_0, caller()->rendered_rotation()); |
| 769 | EXPECT_EQ(webrtc::kVideoRotation_0, callee()->rendered_rotation()); |
| 770 | } |
| 771 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 772 | // Test that if the answerer rejects the audio m= section, no audio is sent or |
| 773 | // received, but video still can be. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 774 | TEST_P(PeerConnectionIntegrationTest, AnswererRejectsAudioSection) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 775 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 776 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 777 | caller()->AddAudioVideoTracks(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 778 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 779 | // Only add video track for callee, and set offer_to_receive_audio to 0, so |
| 780 | // it will reject the audio m= section completely. |
| 781 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 782 | options.offer_to_receive_audio = 0; |
| 783 | callee()->SetOfferAnswerOptions(options); |
| 784 | } else { |
| 785 | // Stopping the audio RtpTransceiver will cause the media section to be |
| 786 | // rejected in the answer. |
| 787 | callee()->SetRemoteOfferHandler([this] { |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 788 | callee() |
| 789 | ->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_AUDIO) |
| 790 | ->StopInternal(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 791 | }); |
| 792 | } |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 793 | callee()->AddTrack(callee()->CreateLocalVideoTrack()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 794 | // Do offer/answer and wait for successful end-to-end video frames. |
| 795 | caller()->CreateAndSetAndSignalOffer(); |
| 796 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 797 | MediaExpectations media_expectations; |
| 798 | media_expectations.ExpectBidirectionalVideo(); |
| 799 | media_expectations.ExpectNoAudio(); |
| 800 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 801 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 802 | // Sanity check that the callee's description has a rejected audio section. |
| 803 | ASSERT_NE(nullptr, callee()->pc()->local_description()); |
| 804 | const ContentInfo* callee_audio_content = |
| 805 | GetFirstAudioContent(callee()->pc()->local_description()->description()); |
| 806 | ASSERT_NE(nullptr, callee_audio_content); |
| 807 | EXPECT_TRUE(callee_audio_content->rejected); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 808 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 809 | // The caller's transceiver should have stopped after receiving the answer, |
| 810 | // and thus no longer listed in transceivers. |
| 811 | EXPECT_EQ(nullptr, |
| 812 | caller()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_AUDIO)); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 813 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | // Test that if the answerer rejects the video m= section, no video is sent or |
| 817 | // received, but audio still can be. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 818 | TEST_P(PeerConnectionIntegrationTest, AnswererRejectsVideoSection) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 819 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 820 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 821 | caller()->AddAudioVideoTracks(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 822 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 823 | // Only add audio track for callee, and set offer_to_receive_video to 0, so |
| 824 | // it will reject the video m= section completely. |
| 825 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 826 | options.offer_to_receive_video = 0; |
| 827 | callee()->SetOfferAnswerOptions(options); |
| 828 | } else { |
| 829 | // Stopping the video RtpTransceiver will cause the media section to be |
| 830 | // rejected in the answer. |
| 831 | callee()->SetRemoteOfferHandler([this] { |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 832 | callee() |
| 833 | ->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO) |
| 834 | ->StopInternal(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 835 | }); |
| 836 | } |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 837 | callee()->AddTrack(callee()->CreateLocalAudioTrack()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 838 | // Do offer/answer and wait for successful end-to-end audio frames. |
| 839 | caller()->CreateAndSetAndSignalOffer(); |
| 840 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 841 | MediaExpectations media_expectations; |
| 842 | media_expectations.ExpectBidirectionalAudio(); |
| 843 | media_expectations.ExpectNoVideo(); |
| 844 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 845 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 846 | // Sanity check that the callee's description has a rejected video section. |
| 847 | ASSERT_NE(nullptr, callee()->pc()->local_description()); |
| 848 | const ContentInfo* callee_video_content = |
| 849 | GetFirstVideoContent(callee()->pc()->local_description()->description()); |
| 850 | ASSERT_NE(nullptr, callee_video_content); |
| 851 | EXPECT_TRUE(callee_video_content->rejected); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 852 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 853 | // The caller's transceiver should have stopped after receiving the answer, |
| 854 | // and thus is no longer present. |
| 855 | EXPECT_EQ(nullptr, |
| 856 | caller()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 857 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | // Test that if the answerer rejects both audio and video m= sections, nothing |
| 861 | // bad happens. |
| 862 | // TODO(deadbeef): Test that a data channel still works. Currently this doesn't |
| 863 | // test anything but the fact that negotiation succeeds, which doesn't mean |
| 864 | // much. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 865 | TEST_P(PeerConnectionIntegrationTest, AnswererRejectsAudioAndVideoSections) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 866 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 867 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 868 | caller()->AddAudioVideoTracks(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 869 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 870 | // Don't give the callee any tracks, and set offer_to_receive_X to 0, so it |
| 871 | // will reject both audio and video m= sections. |
| 872 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 873 | options.offer_to_receive_audio = 0; |
| 874 | options.offer_to_receive_video = 0; |
| 875 | callee()->SetOfferAnswerOptions(options); |
| 876 | } else { |
| 877 | callee()->SetRemoteOfferHandler([this] { |
| 878 | // Stopping all transceivers will cause all media sections to be rejected. |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 879 | for (const auto& transceiver : callee()->pc()->GetTransceivers()) { |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 880 | transceiver->StopInternal(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 881 | } |
| 882 | }); |
| 883 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 884 | // Do offer/answer and wait for stable signaling state. |
| 885 | caller()->CreateAndSetAndSignalOffer(); |
| 886 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 887 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 888 | // Sanity check that the callee's description has rejected m= sections. |
| 889 | ASSERT_NE(nullptr, callee()->pc()->local_description()); |
| 890 | const ContentInfo* callee_audio_content = |
| 891 | GetFirstAudioContent(callee()->pc()->local_description()->description()); |
| 892 | ASSERT_NE(nullptr, callee_audio_content); |
| 893 | EXPECT_TRUE(callee_audio_content->rejected); |
| 894 | const ContentInfo* callee_video_content = |
| 895 | GetFirstVideoContent(callee()->pc()->local_description()->description()); |
| 896 | ASSERT_NE(nullptr, callee_video_content); |
| 897 | EXPECT_TRUE(callee_video_content->rejected); |
| 898 | } |
| 899 | |
| 900 | // This test sets up an audio and video call between two parties. After the |
| 901 | // call runs for a while, the caller sends an updated offer with video being |
| 902 | // rejected. Once the re-negotiation is done, the video flow should stop and |
| 903 | // the audio flow should continue. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 904 | TEST_P(PeerConnectionIntegrationTest, VideoRejectedInSubsequentOffer) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 905 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 906 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 907 | caller()->AddAudioVideoTracks(); |
| 908 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 909 | caller()->CreateAndSetAndSignalOffer(); |
| 910 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 911 | { |
| 912 | MediaExpectations media_expectations; |
| 913 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 914 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 915 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 916 | // Renegotiate, rejecting the video m= section. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 917 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 918 | caller()->SetGeneratedSdpMunger( |
| 919 | [](cricket::SessionDescription* description) { |
| 920 | for (cricket::ContentInfo& content : description->contents()) { |
| 921 | if (cricket::IsVideoContent(&content)) { |
| 922 | content.rejected = true; |
| 923 | } |
| 924 | } |
| 925 | }); |
| 926 | } else { |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 927 | caller() |
| 928 | ->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO) |
| 929 | ->StopInternal(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 930 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 931 | caller()->CreateAndSetAndSignalOffer(); |
| 932 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
| 933 | |
| 934 | // Sanity check that the caller's description has a rejected video section. |
| 935 | ASSERT_NE(nullptr, caller()->pc()->local_description()); |
| 936 | const ContentInfo* caller_video_content = |
| 937 | GetFirstVideoContent(caller()->pc()->local_description()->description()); |
| 938 | ASSERT_NE(nullptr, caller_video_content); |
| 939 | EXPECT_TRUE(caller_video_content->rejected); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 940 | // Wait for some additional audio frames to be received. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 941 | { |
| 942 | MediaExpectations media_expectations; |
| 943 | media_expectations.ExpectBidirectionalAudio(); |
| 944 | media_expectations.ExpectNoVideo(); |
| 945 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 946 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 947 | } |
| 948 | |
Taylor Brandstetter | 60c8dc8 | 2018-04-11 15:20:27 -0700 | [diff] [blame] | 949 | // Do one offer/answer with audio, another that disables it (rejecting the m= |
| 950 | // section), and another that re-enables it. Regression test for: |
| 951 | // bugs.webrtc.org/6023 |
| 952 | TEST_F(PeerConnectionIntegrationTestPlanB, EnableAudioAfterRejecting) { |
| 953 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 954 | ConnectFakeSignaling(); |
| 955 | |
| 956 | // Add audio track, do normal offer/answer. |
| 957 | rtc::scoped_refptr<webrtc::AudioTrackInterface> track = |
| 958 | caller()->CreateLocalAudioTrack(); |
| 959 | rtc::scoped_refptr<webrtc::RtpSenderInterface> sender = |
| 960 | caller()->pc()->AddTrack(track, {"stream"}).MoveValue(); |
| 961 | caller()->CreateAndSetAndSignalOffer(); |
| 962 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 963 | |
| 964 | // Remove audio track, and set offer_to_receive_audio to false to cause the |
| 965 | // m= section to be completely disabled, not just "recvonly". |
| 966 | caller()->pc()->RemoveTrack(sender); |
| 967 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 968 | options.offer_to_receive_audio = 0; |
| 969 | caller()->SetOfferAnswerOptions(options); |
| 970 | caller()->CreateAndSetAndSignalOffer(); |
| 971 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 972 | |
| 973 | // Add the audio track again, expecting negotiation to succeed and frames to |
| 974 | // flow. |
| 975 | sender = caller()->pc()->AddTrack(track, {"stream"}).MoveValue(); |
| 976 | options.offer_to_receive_audio = 1; |
| 977 | caller()->SetOfferAnswerOptions(options); |
| 978 | caller()->CreateAndSetAndSignalOffer(); |
| 979 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 980 | |
| 981 | MediaExpectations media_expectations; |
| 982 | media_expectations.CalleeExpectsSomeAudio(); |
| 983 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 984 | } |
| 985 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 986 | // Basic end-to-end test, but without SSRC/MSID signaling. This functionality |
| 987 | // is needed to support legacy endpoints. |
| 988 | // TODO(deadbeef): When we support the MID extension and demuxing on MID, also |
| 989 | // add a test for an end-to-end test without MID signaling either (basically, |
| 990 | // the minimum acceptable SDP). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 991 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithoutSsrcOrMsidSignaling) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 992 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 993 | ConnectFakeSignaling(); |
| 994 | // Add audio and video, testing that packets can be demuxed on payload type. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 995 | caller()->AddAudioVideoTracks(); |
| 996 | callee()->AddAudioVideoTracks(); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 997 | // Remove SSRCs and MSIDs from the received offer SDP. |
| 998 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 999 | caller()->CreateAndSetAndSignalOffer(); |
| 1000 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1001 | MediaExpectations media_expectations; |
| 1002 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 1003 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 1006 | // Basic end-to-end test, without SSRC signaling. This means that the track |
| 1007 | // was created properly and frames are delivered when the MSIDs are communicated |
| 1008 | // with a=msid lines and no a=ssrc lines. |
| 1009 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 1010 | EndToEndCallWithoutSsrcSignaling) { |
| 1011 | const char kStreamId[] = "streamId"; |
| 1012 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1013 | ConnectFakeSignaling(); |
| 1014 | // Add just audio tracks. |
| 1015 | caller()->AddTrack(caller()->CreateLocalAudioTrack(), {kStreamId}); |
| 1016 | callee()->AddAudioTrack(); |
| 1017 | |
| 1018 | // Remove SSRCs from the received offer SDP. |
| 1019 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndKeepMsids); |
| 1020 | caller()->CreateAndSetAndSignalOffer(); |
| 1021 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1022 | MediaExpectations media_expectations; |
| 1023 | media_expectations.ExpectBidirectionalAudio(); |
| 1024 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 1025 | } |
| 1026 | |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 1027 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 1028 | EndToEndCallAddReceiveVideoToSendOnlyCall) { |
| 1029 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1030 | ConnectFakeSignaling(); |
| 1031 | // Add one-directional video, from caller to callee. |
| 1032 | rtc::scoped_refptr<webrtc::VideoTrackInterface> track = |
| 1033 | caller()->CreateLocalVideoTrack(); |
| 1034 | |
| 1035 | RtpTransceiverInit video_transceiver_init; |
| 1036 | video_transceiver_init.stream_ids = {"video1"}; |
| 1037 | video_transceiver_init.direction = RtpTransceiverDirection::kSendOnly; |
| 1038 | auto video_sender = |
| 1039 | caller()->pc()->AddTransceiver(track, video_transceiver_init).MoveValue(); |
| 1040 | caller()->CreateAndSetAndSignalOffer(); |
| 1041 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1042 | |
| 1043 | // Add receive direction. |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 1044 | video_sender->SetDirectionWithError(RtpTransceiverDirection::kSendRecv); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 1045 | |
| 1046 | rtc::scoped_refptr<webrtc::VideoTrackInterface> callee_track = |
| 1047 | callee()->CreateLocalVideoTrack(); |
| 1048 | |
| 1049 | callee()->AddTrack(callee_track); |
| 1050 | caller()->CreateAndSetAndSignalOffer(); |
| 1051 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1052 | // Ensure that video frames are received end-to-end. |
| 1053 | MediaExpectations media_expectations; |
| 1054 | media_expectations.ExpectBidirectionalVideo(); |
| 1055 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 1056 | } |
| 1057 | |
Steve Anton | df527fd | 2018-04-27 15:52:03 -0700 | [diff] [blame] | 1058 | // Tests that video flows between multiple video tracks when SSRCs are not |
| 1059 | // signaled. This exercises the MID RTP header extension which is needed to |
| 1060 | // demux the incoming video tracks. |
| 1061 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 1062 | EndToEndCallWithTwoVideoTracksAndNoSignaledSsrc) { |
| 1063 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1064 | ConnectFakeSignaling(); |
| 1065 | caller()->AddVideoTrack(); |
| 1066 | caller()->AddVideoTrack(); |
| 1067 | callee()->AddVideoTrack(); |
| 1068 | callee()->AddVideoTrack(); |
| 1069 | |
| 1070 | caller()->SetReceivedSdpMunger(&RemoveSsrcsAndKeepMsids); |
| 1071 | callee()->SetReceivedSdpMunger(&RemoveSsrcsAndKeepMsids); |
| 1072 | caller()->CreateAndSetAndSignalOffer(); |
| 1073 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1074 | ASSERT_EQ(2u, caller()->pc()->GetReceivers().size()); |
| 1075 | ASSERT_EQ(2u, callee()->pc()->GetReceivers().size()); |
| 1076 | |
| 1077 | // Expect video to be received in both directions on both tracks. |
| 1078 | MediaExpectations media_expectations; |
| 1079 | media_expectations.ExpectBidirectionalVideo(); |
| 1080 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 1081 | } |
| 1082 | |
Taylor Brandstetter | d3ef499 | 2020-10-15 18:22:57 -0700 | [diff] [blame] | 1083 | // Used for the test below. |
| 1084 | void RemoveBundleGroupSsrcsAndMidExtension(cricket::SessionDescription* desc) { |
| 1085 | RemoveSsrcsAndKeepMsids(desc); |
| 1086 | desc->RemoveGroupByName("BUNDLE"); |
| 1087 | for (ContentInfo& content : desc->contents()) { |
| 1088 | cricket::MediaContentDescription* media = content.media_description(); |
| 1089 | cricket::RtpHeaderExtensions extensions = media->rtp_header_extensions(); |
| 1090 | extensions.erase(std::remove_if(extensions.begin(), extensions.end(), |
| 1091 | [](const RtpExtension& extension) { |
| 1092 | return extension.uri == |
| 1093 | RtpExtension::kMidUri; |
| 1094 | }), |
| 1095 | extensions.end()); |
| 1096 | media->set_rtp_header_extensions(extensions); |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | // Tests that video flows between multiple video tracks when BUNDLE is not used, |
| 1101 | // SSRCs are not signaled and the MID RTP header extension is not used. This |
| 1102 | // relies on demuxing by payload type, which normally doesn't work if you have |
| 1103 | // multiple media sections using the same payload type, but which should work as |
| 1104 | // long as the media sections aren't bundled. |
| 1105 | // Regression test for: http://crbug.com/webrtc/12023 |
| 1106 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 1107 | EndToEndCallWithTwoVideoTracksNoBundleNoSignaledSsrcAndNoMid) { |
| 1108 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1109 | ConnectFakeSignaling(); |
| 1110 | caller()->AddVideoTrack(); |
| 1111 | caller()->AddVideoTrack(); |
| 1112 | callee()->AddVideoTrack(); |
| 1113 | callee()->AddVideoTrack(); |
| 1114 | caller()->SetReceivedSdpMunger(&RemoveBundleGroupSsrcsAndMidExtension); |
| 1115 | callee()->SetReceivedSdpMunger(&RemoveBundleGroupSsrcsAndMidExtension); |
| 1116 | caller()->CreateAndSetAndSignalOffer(); |
| 1117 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1118 | ASSERT_EQ(2u, caller()->pc()->GetReceivers().size()); |
| 1119 | ASSERT_EQ(2u, callee()->pc()->GetReceivers().size()); |
| 1120 | // Make sure we are not bundled. |
| 1121 | ASSERT_NE(caller()->pc()->GetSenders()[0]->dtls_transport(), |
| 1122 | caller()->pc()->GetSenders()[1]->dtls_transport()); |
| 1123 | |
| 1124 | // Expect video to be received in both directions on both tracks. |
| 1125 | MediaExpectations media_expectations; |
| 1126 | media_expectations.ExpectBidirectionalVideo(); |
| 1127 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 1128 | } |
| 1129 | |
| 1130 | // Used for the test below. |
| 1131 | void ModifyPayloadTypesAndRemoveMidExtension( |
| 1132 | cricket::SessionDescription* desc) { |
| 1133 | int pt = 96; |
| 1134 | for (ContentInfo& content : desc->contents()) { |
| 1135 | cricket::MediaContentDescription* media = content.media_description(); |
| 1136 | cricket::RtpHeaderExtensions extensions = media->rtp_header_extensions(); |
| 1137 | extensions.erase(std::remove_if(extensions.begin(), extensions.end(), |
| 1138 | [](const RtpExtension& extension) { |
| 1139 | return extension.uri == |
| 1140 | RtpExtension::kMidUri; |
| 1141 | }), |
| 1142 | extensions.end()); |
| 1143 | media->set_rtp_header_extensions(extensions); |
| 1144 | cricket::VideoContentDescription* video = media->as_video(); |
| 1145 | ASSERT_TRUE(video != nullptr); |
| 1146 | std::vector<cricket::VideoCodec> codecs = {{pt++, "VP8"}}; |
| 1147 | video->set_codecs(codecs); |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | // Tests that two video tracks can be demultiplexed by payload type alone, by |
| 1152 | // using different payload types for the same codec in different m= sections. |
| 1153 | // This practice is discouraged but historically has been supported. |
| 1154 | // Regression test for: http://crbug.com/webrtc/12029 |
| 1155 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 1156 | EndToEndCallWithTwoVideoTracksDemultiplexedByPayloadType) { |
| 1157 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1158 | ConnectFakeSignaling(); |
| 1159 | caller()->AddVideoTrack(); |
| 1160 | caller()->AddVideoTrack(); |
| 1161 | callee()->AddVideoTrack(); |
| 1162 | callee()->AddVideoTrack(); |
| 1163 | caller()->SetGeneratedSdpMunger(&ModifyPayloadTypesAndRemoveMidExtension); |
| 1164 | callee()->SetGeneratedSdpMunger(&ModifyPayloadTypesAndRemoveMidExtension); |
| 1165 | // We can't remove SSRCs from the generated SDP because then no send streams |
| 1166 | // would be created. |
| 1167 | caller()->SetReceivedSdpMunger(&RemoveSsrcsAndKeepMsids); |
| 1168 | callee()->SetReceivedSdpMunger(&RemoveSsrcsAndKeepMsids); |
| 1169 | caller()->CreateAndSetAndSignalOffer(); |
| 1170 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1171 | ASSERT_EQ(2u, caller()->pc()->GetReceivers().size()); |
| 1172 | ASSERT_EQ(2u, callee()->pc()->GetReceivers().size()); |
| 1173 | // Make sure we are bundled. |
| 1174 | ASSERT_EQ(caller()->pc()->GetSenders()[0]->dtls_transport(), |
| 1175 | caller()->pc()->GetSenders()[1]->dtls_transport()); |
| 1176 | |
| 1177 | // Expect video to be received in both directions on both tracks. |
| 1178 | MediaExpectations media_expectations; |
| 1179 | media_expectations.ExpectBidirectionalVideo(); |
| 1180 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 1181 | } |
| 1182 | |
Henrik Boström | 5b14778 | 2018-12-04 11:25:05 +0100 | [diff] [blame] | 1183 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, NoStreamsMsidLinePresent) { |
| 1184 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1185 | ConnectFakeSignaling(); |
| 1186 | caller()->AddAudioTrack(); |
| 1187 | caller()->AddVideoTrack(); |
| 1188 | caller()->CreateAndSetAndSignalOffer(); |
| 1189 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1190 | auto callee_receivers = callee()->pc()->GetReceivers(); |
| 1191 | ASSERT_EQ(2u, callee_receivers.size()); |
| 1192 | EXPECT_TRUE(callee_receivers[0]->stream_ids().empty()); |
| 1193 | EXPECT_TRUE(callee_receivers[1]->stream_ids().empty()); |
| 1194 | } |
| 1195 | |
| 1196 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, NoStreamsMsidLineMissing) { |
| 1197 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1198 | ConnectFakeSignaling(); |
| 1199 | caller()->AddAudioTrack(); |
| 1200 | caller()->AddVideoTrack(); |
| 1201 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 1202 | caller()->CreateAndSetAndSignalOffer(); |
| 1203 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1204 | auto callee_receivers = callee()->pc()->GetReceivers(); |
| 1205 | ASSERT_EQ(2u, callee_receivers.size()); |
| 1206 | ASSERT_EQ(1u, callee_receivers[0]->stream_ids().size()); |
| 1207 | ASSERT_EQ(1u, callee_receivers[1]->stream_ids().size()); |
| 1208 | EXPECT_EQ(callee_receivers[0]->stream_ids()[0], |
| 1209 | callee_receivers[1]->stream_ids()[0]); |
| 1210 | EXPECT_EQ(callee_receivers[0]->streams()[0], |
| 1211 | callee_receivers[1]->streams()[0]); |
| 1212 | } |
| 1213 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1214 | // Test that if two video tracks are sent (from caller to callee, in this test), |
| 1215 | // they're transmitted correctly end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1216 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithTwoVideoTracks) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1217 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1218 | ConnectFakeSignaling(); |
| 1219 | // Add one audio/video stream, and one video-only stream. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1220 | caller()->AddAudioVideoTracks(); |
| 1221 | caller()->AddVideoTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1222 | caller()->CreateAndSetAndSignalOffer(); |
| 1223 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1224 | ASSERT_EQ(3u, callee()->pc()->GetReceivers().size()); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1225 | |
| 1226 | MediaExpectations media_expectations; |
| 1227 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 1228 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | static void MakeSpecCompliantMaxBundleOffer(cricket::SessionDescription* desc) { |
| 1232 | bool first = true; |
| 1233 | for (cricket::ContentInfo& content : desc->contents()) { |
| 1234 | if (first) { |
| 1235 | first = false; |
| 1236 | continue; |
| 1237 | } |
| 1238 | content.bundle_only = true; |
| 1239 | } |
| 1240 | first = true; |
| 1241 | for (cricket::TransportInfo& transport : desc->transport_infos()) { |
| 1242 | if (first) { |
| 1243 | first = false; |
| 1244 | continue; |
| 1245 | } |
| 1246 | transport.description.ice_ufrag.clear(); |
| 1247 | transport.description.ice_pwd.clear(); |
| 1248 | transport.description.connection_role = cricket::CONNECTIONROLE_NONE; |
| 1249 | transport.description.identity_fingerprint.reset(nullptr); |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | // Test that if applying a true "max bundle" offer, which uses ports of 0, |
| 1254 | // "a=bundle-only", omitting "a=fingerprint", "a=setup", "a=ice-ufrag" and |
| 1255 | // "a=ice-pwd" for all but the audio "m=" section, negotiation still completes |
| 1256 | // successfully and media flows. |
| 1257 | // TODO(deadbeef): Update this test to also omit "a=rtcp-mux", once that works. |
| 1258 | // TODO(deadbeef): Won't need this test once we start generating actual |
| 1259 | // standards-compliant SDP. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1260 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1261 | EndToEndCallWithSpecCompliantMaxBundleOffer) { |
| 1262 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1263 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1264 | caller()->AddAudioVideoTracks(); |
| 1265 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1266 | // Do the equivalent of setting the port to 0, adding a=bundle-only, and |
| 1267 | // removing a=ice-ufrag, a=ice-pwd, a=fingerprint and a=setup from all |
| 1268 | // but the first m= section. |
| 1269 | callee()->SetReceivedSdpMunger(MakeSpecCompliantMaxBundleOffer); |
| 1270 | caller()->CreateAndSetAndSignalOffer(); |
| 1271 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1272 | MediaExpectations media_expectations; |
| 1273 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 1274 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | // Test that we can receive the audio output level from a remote audio track. |
| 1278 | // TODO(deadbeef): Use a fake audio source and verify that the output level is |
| 1279 | // exactly what the source on the other side was configured with. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1280 | TEST_P(PeerConnectionIntegrationTest, GetAudioOutputLevelStatsWithOldStatsApi) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1281 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1282 | ConnectFakeSignaling(); |
| 1283 | // Just add an audio track. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1284 | caller()->AddAudioTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1285 | caller()->CreateAndSetAndSignalOffer(); |
| 1286 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1287 | |
| 1288 | // Get the audio output level stats. Note that the level is not available |
| 1289 | // until an RTCP packet has been received. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 1290 | EXPECT_TRUE_WAIT(callee()->OldGetStats()->AudioOutputLevel() > 0, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1291 | kMaxWaitForFramesMs); |
| 1292 | } |
| 1293 | |
| 1294 | // Test that an audio input level is reported. |
| 1295 | // TODO(deadbeef): Use a fake audio source and verify that the input level is |
| 1296 | // exactly what the source was configured with. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1297 | TEST_P(PeerConnectionIntegrationTest, GetAudioInputLevelStatsWithOldStatsApi) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1298 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1299 | ConnectFakeSignaling(); |
| 1300 | // Just add an audio track. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1301 | caller()->AddAudioTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1302 | caller()->CreateAndSetAndSignalOffer(); |
| 1303 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1304 | |
| 1305 | // Get the audio input level stats. The level should be available very |
| 1306 | // soon after the test starts. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 1307 | EXPECT_TRUE_WAIT(caller()->OldGetStats()->AudioInputLevel() > 0, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1308 | kMaxWaitForStatsMs); |
| 1309 | } |
| 1310 | |
| 1311 | // Test that we can get incoming byte counts from both audio and video tracks. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1312 | TEST_P(PeerConnectionIntegrationTest, GetBytesReceivedStatsWithOldStatsApi) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1313 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1314 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1315 | caller()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1316 | // Do offer/answer, wait for the callee to receive some frames. |
| 1317 | caller()->CreateAndSetAndSignalOffer(); |
| 1318 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1319 | |
| 1320 | MediaExpectations media_expectations; |
| 1321 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 1322 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1323 | |
| 1324 | // Get a handle to the remote tracks created, so they can be used as GetStats |
| 1325 | // filters. |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 1326 | for (const auto& receiver : callee()->pc()->GetReceivers()) { |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1327 | // We received frames, so we definitely should have nonzero "received bytes" |
| 1328 | // stats at this point. |
| 1329 | EXPECT_GT(callee()->OldGetStatsForTrack(receiver->track())->BytesReceived(), |
| 1330 | 0); |
| 1331 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | // Test that we can get outgoing byte counts from both audio and video tracks. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1335 | TEST_P(PeerConnectionIntegrationTest, GetBytesSentStatsWithOldStatsApi) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1336 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1337 | ConnectFakeSignaling(); |
| 1338 | auto audio_track = caller()->CreateLocalAudioTrack(); |
| 1339 | auto video_track = caller()->CreateLocalVideoTrack(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1340 | caller()->AddTrack(audio_track); |
| 1341 | caller()->AddTrack(video_track); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1342 | // Do offer/answer, wait for the callee to receive some frames. |
| 1343 | caller()->CreateAndSetAndSignalOffer(); |
| 1344 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1345 | MediaExpectations media_expectations; |
| 1346 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 1347 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1348 | |
| 1349 | // The callee received frames, so we definitely should have nonzero "sent |
| 1350 | // bytes" stats at this point. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 1351 | EXPECT_GT(caller()->OldGetStatsForTrack(audio_track)->BytesSent(), 0); |
| 1352 | EXPECT_GT(caller()->OldGetStatsForTrack(video_track)->BytesSent(), 0); |
| 1353 | } |
| 1354 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 1355 | // Test that we can get capture start ntp time. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1356 | TEST_P(PeerConnectionIntegrationTest, GetCaptureStartNtpTimeWithOldStatsApi) { |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 1357 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1358 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1359 | caller()->AddAudioTrack(); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 1360 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1361 | callee()->AddAudioTrack(); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 1362 | |
| 1363 | // Do offer/answer, wait for the callee to receive some frames. |
| 1364 | caller()->CreateAndSetAndSignalOffer(); |
| 1365 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1366 | |
| 1367 | // Get the remote audio track created on the receiver, so they can be used as |
| 1368 | // GetStats filters. |
Steve Anton | fc85371 | 2018-03-01 13:48:58 -0800 | [diff] [blame] | 1369 | auto receivers = callee()->pc()->GetReceivers(); |
| 1370 | ASSERT_EQ(1u, receivers.size()); |
| 1371 | auto remote_audio_track = receivers[0]->track(); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 1372 | |
| 1373 | // Get the audio output level stats. Note that the level is not available |
| 1374 | // until an RTCP packet has been received. |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 1375 | EXPECT_TRUE_WAIT( |
| 1376 | callee()->OldGetStatsForTrack(remote_audio_track)->CaptureStartNtpTime() > |
| 1377 | 0, |
| 1378 | 2 * kMaxWaitForFramesMs); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 1379 | } |
| 1380 | |
Steve Anton | a41959e | 2018-11-28 11:15:33 -0800 | [diff] [blame] | 1381 | // Test that the track ID is associated with all local and remote SSRC stats |
| 1382 | // using the old GetStats() and more than 1 audio and more than 1 video track. |
| 1383 | // This is a regression test for crbug.com/906988 |
| 1384 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 1385 | OldGetStatsAssociatesTrackIdForManyMediaSections) { |
| 1386 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1387 | ConnectFakeSignaling(); |
| 1388 | auto audio_sender_1 = caller()->AddAudioTrack(); |
| 1389 | auto video_sender_1 = caller()->AddVideoTrack(); |
| 1390 | auto audio_sender_2 = caller()->AddAudioTrack(); |
| 1391 | auto video_sender_2 = caller()->AddVideoTrack(); |
| 1392 | caller()->CreateAndSetAndSignalOffer(); |
| 1393 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1394 | |
| 1395 | MediaExpectations media_expectations; |
| 1396 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 1397 | ASSERT_TRUE_WAIT(ExpectNewFrames(media_expectations), kDefaultTimeout); |
| 1398 | |
| 1399 | std::vector<std::string> track_ids = { |
| 1400 | audio_sender_1->track()->id(), video_sender_1->track()->id(), |
| 1401 | audio_sender_2->track()->id(), video_sender_2->track()->id()}; |
| 1402 | |
| 1403 | auto caller_stats = caller()->OldGetStats(); |
| 1404 | EXPECT_THAT(caller_stats->TrackIds(), UnorderedElementsAreArray(track_ids)); |
| 1405 | auto callee_stats = callee()->OldGetStats(); |
| 1406 | EXPECT_THAT(callee_stats->TrackIds(), UnorderedElementsAreArray(track_ids)); |
| 1407 | } |
| 1408 | |
Steve Anton | ffa6ce4 | 2018-11-30 09:26:08 -0800 | [diff] [blame] | 1409 | // Test that the new GetStats() returns stats for all outgoing/incoming streams |
| 1410 | // with the correct track IDs if there are more than one audio and more than one |
| 1411 | // video senders/receivers. |
| 1412 | TEST_P(PeerConnectionIntegrationTest, NewGetStatsManyAudioAndManyVideoStreams) { |
| 1413 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1414 | ConnectFakeSignaling(); |
| 1415 | auto audio_sender_1 = caller()->AddAudioTrack(); |
| 1416 | auto video_sender_1 = caller()->AddVideoTrack(); |
| 1417 | auto audio_sender_2 = caller()->AddAudioTrack(); |
| 1418 | auto video_sender_2 = caller()->AddVideoTrack(); |
| 1419 | caller()->CreateAndSetAndSignalOffer(); |
| 1420 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1421 | |
| 1422 | MediaExpectations media_expectations; |
| 1423 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 1424 | ASSERT_TRUE_WAIT(ExpectNewFrames(media_expectations), kDefaultTimeout); |
| 1425 | |
| 1426 | std::vector<std::string> track_ids = { |
| 1427 | audio_sender_1->track()->id(), video_sender_1->track()->id(), |
| 1428 | audio_sender_2->track()->id(), video_sender_2->track()->id()}; |
| 1429 | |
| 1430 | rtc::scoped_refptr<const webrtc::RTCStatsReport> caller_report = |
| 1431 | caller()->NewGetStats(); |
| 1432 | ASSERT_TRUE(caller_report); |
| 1433 | auto outbound_stream_stats = |
| 1434 | caller_report->GetStatsOfType<webrtc::RTCOutboundRTPStreamStats>(); |
Henrik Boström | a0ff50c | 2020-05-05 15:54:46 +0200 | [diff] [blame] | 1435 | ASSERT_EQ(outbound_stream_stats.size(), 4u); |
Steve Anton | ffa6ce4 | 2018-11-30 09:26:08 -0800 | [diff] [blame] | 1436 | std::vector<std::string> outbound_track_ids; |
| 1437 | for (const auto& stat : outbound_stream_stats) { |
| 1438 | ASSERT_TRUE(stat->bytes_sent.is_defined()); |
| 1439 | EXPECT_LT(0u, *stat->bytes_sent); |
Rasmus Brandt | 2efae77 | 2019-06-27 14:29:34 +0200 | [diff] [blame] | 1440 | if (*stat->kind == "video") { |
| 1441 | ASSERT_TRUE(stat->key_frames_encoded.is_defined()); |
| 1442 | EXPECT_GT(*stat->key_frames_encoded, 0u); |
| 1443 | ASSERT_TRUE(stat->frames_encoded.is_defined()); |
| 1444 | EXPECT_GE(*stat->frames_encoded, *stat->key_frames_encoded); |
| 1445 | } |
Steve Anton | ffa6ce4 | 2018-11-30 09:26:08 -0800 | [diff] [blame] | 1446 | ASSERT_TRUE(stat->track_id.is_defined()); |
| 1447 | const auto* track_stat = |
| 1448 | caller_report->GetAs<webrtc::RTCMediaStreamTrackStats>(*stat->track_id); |
| 1449 | ASSERT_TRUE(track_stat); |
| 1450 | outbound_track_ids.push_back(*track_stat->track_identifier); |
| 1451 | } |
| 1452 | EXPECT_THAT(outbound_track_ids, UnorderedElementsAreArray(track_ids)); |
| 1453 | |
| 1454 | rtc::scoped_refptr<const webrtc::RTCStatsReport> callee_report = |
| 1455 | callee()->NewGetStats(); |
| 1456 | ASSERT_TRUE(callee_report); |
| 1457 | auto inbound_stream_stats = |
| 1458 | callee_report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>(); |
| 1459 | ASSERT_EQ(4u, inbound_stream_stats.size()); |
| 1460 | std::vector<std::string> inbound_track_ids; |
| 1461 | for (const auto& stat : inbound_stream_stats) { |
| 1462 | ASSERT_TRUE(stat->bytes_received.is_defined()); |
| 1463 | EXPECT_LT(0u, *stat->bytes_received); |
Rasmus Brandt | 2efae77 | 2019-06-27 14:29:34 +0200 | [diff] [blame] | 1464 | if (*stat->kind == "video") { |
| 1465 | ASSERT_TRUE(stat->key_frames_decoded.is_defined()); |
| 1466 | EXPECT_GT(*stat->key_frames_decoded, 0u); |
| 1467 | ASSERT_TRUE(stat->frames_decoded.is_defined()); |
| 1468 | EXPECT_GE(*stat->frames_decoded, *stat->key_frames_decoded); |
| 1469 | } |
Steve Anton | ffa6ce4 | 2018-11-30 09:26:08 -0800 | [diff] [blame] | 1470 | ASSERT_TRUE(stat->track_id.is_defined()); |
| 1471 | const auto* track_stat = |
| 1472 | callee_report->GetAs<webrtc::RTCMediaStreamTrackStats>(*stat->track_id); |
| 1473 | ASSERT_TRUE(track_stat); |
| 1474 | inbound_track_ids.push_back(*track_stat->track_identifier); |
| 1475 | } |
| 1476 | EXPECT_THAT(inbound_track_ids, UnorderedElementsAreArray(track_ids)); |
| 1477 | } |
| 1478 | |
| 1479 | // Test that we can get stats (using the new stats implementation) for |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 1480 | // unsignaled streams. Meaning when SSRCs/MSIDs aren't signaled explicitly in |
| 1481 | // SDP. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1482 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 1483 | GetStatsForUnsignaledStreamWithNewStatsApi) { |
| 1484 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1485 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1486 | caller()->AddAudioTrack(); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 1487 | // Remove SSRCs and MSIDs from the received offer SDP. |
| 1488 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 1489 | caller()->CreateAndSetAndSignalOffer(); |
| 1490 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1491 | MediaExpectations media_expectations; |
| 1492 | media_expectations.CalleeExpectsSomeAudio(1); |
| 1493 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 1494 | |
| 1495 | // We received a frame, so we should have nonzero "bytes received" stats for |
| 1496 | // the unsignaled stream, if stats are working for it. |
| 1497 | rtc::scoped_refptr<const webrtc::RTCStatsReport> report = |
| 1498 | callee()->NewGetStats(); |
| 1499 | ASSERT_NE(nullptr, report); |
| 1500 | auto inbound_stream_stats = |
| 1501 | report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>(); |
| 1502 | ASSERT_EQ(1U, inbound_stream_stats.size()); |
| 1503 | ASSERT_TRUE(inbound_stream_stats[0]->bytes_received.is_defined()); |
| 1504 | ASSERT_GT(*inbound_stream_stats[0]->bytes_received, 0U); |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 1505 | ASSERT_TRUE(inbound_stream_stats[0]->track_id.is_defined()); |
| 1506 | } |
| 1507 | |
Taylor Brandstetter | a465344 | 2018-06-19 09:44:26 -0700 | [diff] [blame] | 1508 | // Same as above but for the legacy stats implementation. |
| 1509 | TEST_P(PeerConnectionIntegrationTest, |
| 1510 | GetStatsForUnsignaledStreamWithOldStatsApi) { |
| 1511 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1512 | ConnectFakeSignaling(); |
| 1513 | caller()->AddAudioTrack(); |
| 1514 | // Remove SSRCs and MSIDs from the received offer SDP. |
| 1515 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 1516 | caller()->CreateAndSetAndSignalOffer(); |
| 1517 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1518 | |
| 1519 | // Note that, since the old stats implementation associates SSRCs with tracks |
| 1520 | // using SDP, when SSRCs aren't signaled in SDP these stats won't have an |
| 1521 | // associated track ID. So we can't use the track "selector" argument. |
| 1522 | // |
| 1523 | // Also, we use "EXPECT_TRUE_WAIT" because the stats collector may decide to |
| 1524 | // return cached stats if not enough time has passed since the last update. |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 1525 | EXPECT_TRUE_WAIT(callee()->OldGetStats()->BytesReceived() > 0, |
Taylor Brandstetter | a465344 | 2018-06-19 09:44:26 -0700 | [diff] [blame] | 1526 | kDefaultTimeout); |
| 1527 | } |
| 1528 | |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 1529 | // Test that we can successfully get the media related stats (audio level |
| 1530 | // etc.) for the unsignaled stream. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1531 | TEST_P(PeerConnectionIntegrationTest, |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 1532 | GetMediaStatsForUnsignaledStreamWithNewStatsApi) { |
| 1533 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1534 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1535 | caller()->AddAudioVideoTracks(); |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 1536 | // Remove SSRCs and MSIDs from the received offer SDP. |
| 1537 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 1538 | caller()->CreateAndSetAndSignalOffer(); |
| 1539 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1540 | MediaExpectations media_expectations; |
| 1541 | media_expectations.CalleeExpectsSomeAudio(1); |
| 1542 | media_expectations.CalleeExpectsSomeVideo(1); |
| 1543 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 1544 | |
| 1545 | rtc::scoped_refptr<const webrtc::RTCStatsReport> report = |
| 1546 | callee()->NewGetStats(); |
| 1547 | ASSERT_NE(nullptr, report); |
| 1548 | |
| 1549 | auto media_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>(); |
| 1550 | auto audio_index = FindFirstMediaStatsIndexByKind("audio", media_stats); |
| 1551 | ASSERT_GE(audio_index, 0); |
| 1552 | EXPECT_TRUE(media_stats[audio_index]->audio_level.is_defined()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1553 | } |
| 1554 | |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 1555 | // Helper for test below. |
| 1556 | void ModifySsrcs(cricket::SessionDescription* desc) { |
| 1557 | for (ContentInfo& content : desc->contents()) { |
Steve Anton | df527fd | 2018-04-27 15:52:03 -0700 | [diff] [blame] | 1558 | for (StreamParams& stream : |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1559 | content.media_description()->mutable_streams()) { |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 1560 | for (uint32_t& ssrc : stream.ssrcs) { |
| 1561 | ssrc = rtc::CreateRandomId(); |
| 1562 | } |
| 1563 | } |
| 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | // Test that the "RTCMediaSteamTrackStats" object is updated correctly when |
| 1568 | // SSRCs are unsignaled, and the SSRC of the received (audio) stream changes. |
| 1569 | // This should result in two "RTCInboundRTPStreamStats", but only one |
| 1570 | // "RTCMediaStreamTrackStats", whose counters go up continuously rather than |
| 1571 | // being reset to 0 once the SSRC change occurs. |
| 1572 | // |
| 1573 | // Regression test for this bug: |
| 1574 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=8158 |
| 1575 | // |
| 1576 | // The bug causes the track stats to only represent one of the two streams: |
| 1577 | // whichever one has the higher SSRC. So with this bug, there was a 50% chance |
| 1578 | // that the track stat counters would reset to 0 when the new stream is |
| 1579 | // received, and a 50% chance that they'll stop updating (while |
| 1580 | // "concealed_samples" continues increasing, due to silence being generated for |
| 1581 | // the inactive stream). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1582 | TEST_P(PeerConnectionIntegrationTest, |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 1583 | TrackStatsUpdatedCorrectlyWhenUnsignaledSsrcChanges) { |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 1584 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1585 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1586 | caller()->AddAudioTrack(); |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 1587 | // Remove SSRCs and MSIDs from the received offer SDP, simulating an endpoint |
| 1588 | // that doesn't signal SSRCs (from the callee's perspective). |
| 1589 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 1590 | caller()->CreateAndSetAndSignalOffer(); |
| 1591 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1592 | // Wait for 50 audio frames (500ms of audio) to be received by the callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1593 | { |
| 1594 | MediaExpectations media_expectations; |
| 1595 | media_expectations.CalleeExpectsSomeAudio(50); |
| 1596 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 1597 | } |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 1598 | // Some audio frames were received, so we should have nonzero "samples |
| 1599 | // received" for the track. |
| 1600 | rtc::scoped_refptr<const webrtc::RTCStatsReport> report = |
| 1601 | callee()->NewGetStats(); |
| 1602 | ASSERT_NE(nullptr, report); |
| 1603 | auto track_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>(); |
| 1604 | ASSERT_EQ(1U, track_stats.size()); |
| 1605 | ASSERT_TRUE(track_stats[0]->total_samples_received.is_defined()); |
| 1606 | ASSERT_GT(*track_stats[0]->total_samples_received, 0U); |
| 1607 | // uint64_t prev_samples_received = *track_stats[0]->total_samples_received; |
| 1608 | |
| 1609 | // Create a new offer and munge it to cause the caller to use a new SSRC. |
| 1610 | caller()->SetGeneratedSdpMunger(ModifySsrcs); |
| 1611 | caller()->CreateAndSetAndSignalOffer(); |
| 1612 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1613 | // Wait for 25 more audio frames (250ms of audio) to be received, from the new |
| 1614 | // SSRC. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1615 | { |
| 1616 | MediaExpectations media_expectations; |
| 1617 | media_expectations.CalleeExpectsSomeAudio(25); |
| 1618 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 1619 | } |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 1620 | |
| 1621 | report = callee()->NewGetStats(); |
| 1622 | ASSERT_NE(nullptr, report); |
| 1623 | track_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>(); |
| 1624 | ASSERT_EQ(1U, track_stats.size()); |
| 1625 | ASSERT_TRUE(track_stats[0]->total_samples_received.is_defined()); |
| 1626 | // The "total samples received" stat should only be greater than it was |
| 1627 | // before. |
| 1628 | // TODO(deadbeef): Uncomment this assertion once the bug is completely fixed. |
| 1629 | // Right now, the new SSRC will cause the counters to reset to 0. |
| 1630 | // EXPECT_GT(*track_stats[0]->total_samples_received, prev_samples_received); |
| 1631 | |
| 1632 | // Additionally, the percentage of concealed samples (samples generated to |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 1633 | // conceal packet loss) should be less than 50%. If it's greater, that's a |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 1634 | // good sign that we're seeing stats from the old stream that's no longer |
| 1635 | // receiving packets, and is generating concealed samples of silence. |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 1636 | constexpr double kAcceptableConcealedSamplesPercentage = 0.50; |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 1637 | ASSERT_TRUE(track_stats[0]->concealed_samples.is_defined()); |
| 1638 | EXPECT_LT(*track_stats[0]->concealed_samples, |
| 1639 | *track_stats[0]->total_samples_received * |
| 1640 | kAcceptableConcealedSamplesPercentage); |
| 1641 | |
| 1642 | // Also ensure that we have two "RTCInboundRTPStreamStats" as expected, as a |
| 1643 | // sanity check that the SSRC really changed. |
| 1644 | // TODO(deadbeef): This isn't working right now, because we're not returning |
| 1645 | // *any* stats for the inactive stream. Uncomment when the bug is completely |
| 1646 | // fixed. |
| 1647 | // auto inbound_stream_stats = |
| 1648 | // report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>(); |
| 1649 | // ASSERT_EQ(2U, inbound_stream_stats.size()); |
| 1650 | } |
| 1651 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1652 | // Test that DTLS 1.0 is used if both sides only support DTLS 1.0. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1653 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithDtls10) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1654 | PeerConnectionFactory::Options dtls_10_options; |
| 1655 | dtls_10_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 1656 | ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_10_options, |
| 1657 | dtls_10_options)); |
| 1658 | ConnectFakeSignaling(); |
| 1659 | // Do normal offer/answer and wait for some frames to be received in each |
| 1660 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1661 | caller()->AddAudioVideoTracks(); |
| 1662 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1663 | caller()->CreateAndSetAndSignalOffer(); |
| 1664 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1665 | MediaExpectations media_expectations; |
| 1666 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 1667 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | // Test getting cipher stats and UMA metrics when DTLS 1.0 is negotiated. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1671 | TEST_P(PeerConnectionIntegrationTest, Dtls10CipherStatsAndUmaMetrics) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1672 | PeerConnectionFactory::Options dtls_10_options; |
| 1673 | dtls_10_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 1674 | ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_10_options, |
| 1675 | dtls_10_options)); |
| 1676 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1677 | caller()->AddAudioVideoTracks(); |
| 1678 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1679 | caller()->CreateAndSetAndSignalOffer(); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1680 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1681 | EXPECT_TRUE_WAIT(rtc::SSLStreamAdapter::IsAcceptableCipher( |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 1682 | caller()->OldGetStats()->DtlsCipher(), rtc::KT_DEFAULT), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1683 | kDefaultTimeout); |
| 1684 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 1685 | caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1686 | // TODO(bugs.webrtc.org/9456): Fix it. |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 1687 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents( |
| 1688 | "WebRTC.PeerConnection.SrtpCryptoSuite.Audio", |
| 1689 | kDefaultSrtpCryptoSuite)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1690 | } |
| 1691 | |
| 1692 | // Test getting cipher stats and UMA metrics when DTLS 1.2 is negotiated. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1693 | TEST_P(PeerConnectionIntegrationTest, Dtls12CipherStatsAndUmaMetrics) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1694 | PeerConnectionFactory::Options dtls_12_options; |
| 1695 | dtls_12_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 1696 | ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_12_options, |
| 1697 | dtls_12_options)); |
| 1698 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1699 | caller()->AddAudioVideoTracks(); |
| 1700 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1701 | caller()->CreateAndSetAndSignalOffer(); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1702 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1703 | EXPECT_TRUE_WAIT(rtc::SSLStreamAdapter::IsAcceptableCipher( |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 1704 | caller()->OldGetStats()->DtlsCipher(), rtc::KT_DEFAULT), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1705 | kDefaultTimeout); |
| 1706 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 1707 | caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1708 | // TODO(bugs.webrtc.org/9456): Fix it. |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 1709 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents( |
| 1710 | "WebRTC.PeerConnection.SrtpCryptoSuite.Audio", |
| 1711 | kDefaultSrtpCryptoSuite)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | // Test that DTLS 1.0 can be used if the caller supports DTLS 1.2 and the |
| 1715 | // callee only supports 1.0. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1716 | TEST_P(PeerConnectionIntegrationTest, CallerDtls12ToCalleeDtls10) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1717 | PeerConnectionFactory::Options caller_options; |
| 1718 | caller_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 1719 | PeerConnectionFactory::Options callee_options; |
| 1720 | callee_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 1721 | ASSERT_TRUE( |
| 1722 | CreatePeerConnectionWrappersWithOptions(caller_options, callee_options)); |
| 1723 | ConnectFakeSignaling(); |
| 1724 | // Do normal offer/answer and wait for some frames to be received in each |
| 1725 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1726 | caller()->AddAudioVideoTracks(); |
| 1727 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1728 | caller()->CreateAndSetAndSignalOffer(); |
| 1729 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1730 | MediaExpectations media_expectations; |
| 1731 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 1732 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | // Test that DTLS 1.0 can be used if the caller only supports DTLS 1.0 and the |
| 1736 | // callee supports 1.2. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1737 | TEST_P(PeerConnectionIntegrationTest, CallerDtls10ToCalleeDtls12) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1738 | PeerConnectionFactory::Options caller_options; |
| 1739 | caller_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 1740 | PeerConnectionFactory::Options callee_options; |
| 1741 | callee_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 1742 | ASSERT_TRUE( |
| 1743 | CreatePeerConnectionWrappersWithOptions(caller_options, callee_options)); |
| 1744 | ConnectFakeSignaling(); |
| 1745 | // Do normal offer/answer and wait for some frames to be received in each |
| 1746 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1747 | caller()->AddAudioVideoTracks(); |
| 1748 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1749 | caller()->CreateAndSetAndSignalOffer(); |
| 1750 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1751 | MediaExpectations media_expectations; |
| 1752 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 1753 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1754 | } |
| 1755 | |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1756 | // The three tests below verify that "enable_aes128_sha1_32_crypto_cipher" |
| 1757 | // works as expected; the cipher should only be used if enabled by both sides. |
| 1758 | TEST_P(PeerConnectionIntegrationTest, |
| 1759 | Aes128Sha1_32_CipherNotUsedWhenOnlyCallerSupported) { |
| 1760 | PeerConnectionFactory::Options caller_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1761 | caller_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1762 | PeerConnectionFactory::Options callee_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1763 | callee_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = |
| 1764 | false; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1765 | int expected_cipher_suite = rtc::SRTP_AES128_CM_SHA1_80; |
| 1766 | TestNegotiatedCipherSuite(caller_options, callee_options, |
| 1767 | expected_cipher_suite); |
| 1768 | } |
| 1769 | |
| 1770 | TEST_P(PeerConnectionIntegrationTest, |
| 1771 | Aes128Sha1_32_CipherNotUsedWhenOnlyCalleeSupported) { |
| 1772 | PeerConnectionFactory::Options caller_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1773 | caller_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = |
| 1774 | false; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1775 | PeerConnectionFactory::Options callee_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1776 | callee_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1777 | int expected_cipher_suite = rtc::SRTP_AES128_CM_SHA1_80; |
| 1778 | TestNegotiatedCipherSuite(caller_options, callee_options, |
| 1779 | expected_cipher_suite); |
| 1780 | } |
| 1781 | |
| 1782 | TEST_P(PeerConnectionIntegrationTest, Aes128Sha1_32_CipherUsedWhenSupported) { |
| 1783 | PeerConnectionFactory::Options caller_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1784 | caller_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1785 | PeerConnectionFactory::Options callee_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1786 | callee_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1787 | int expected_cipher_suite = rtc::SRTP_AES128_CM_SHA1_32; |
| 1788 | TestNegotiatedCipherSuite(caller_options, callee_options, |
| 1789 | expected_cipher_suite); |
| 1790 | } |
| 1791 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1792 | // Test that a non-GCM cipher is used if both sides only support non-GCM. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1793 | TEST_P(PeerConnectionIntegrationTest, NonGcmCipherUsedWhenGcmNotSupported) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1794 | bool local_gcm_enabled = false; |
| 1795 | bool remote_gcm_enabled = false; |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 1796 | bool aes_ctr_enabled = true; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1797 | int expected_cipher_suite = kDefaultSrtpCryptoSuite; |
| 1798 | TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled, |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 1799 | aes_ctr_enabled, expected_cipher_suite); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 1802 | // Test that a GCM cipher is used if both ends support it and non-GCM is |
| 1803 | // disabled. |
| 1804 | TEST_P(PeerConnectionIntegrationTest, GcmCipherUsedWhenOnlyGcmSupported) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1805 | bool local_gcm_enabled = true; |
| 1806 | bool remote_gcm_enabled = true; |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 1807 | bool aes_ctr_enabled = false; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1808 | int expected_cipher_suite = kDefaultSrtpCryptoSuiteGcm; |
| 1809 | TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled, |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 1810 | aes_ctr_enabled, expected_cipher_suite); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 1813 | // Verify that media can be transmitted end-to-end when GCM crypto suites are |
| 1814 | // enabled. Note that the above tests, such as GcmCipherUsedWhenGcmSupported, |
| 1815 | // only verify that a GCM cipher is negotiated, and not necessarily that SRTP |
| 1816 | // works with it. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1817 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithGcmCipher) { |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 1818 | PeerConnectionFactory::Options gcm_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1819 | gcm_options.crypto_options.srtp.enable_gcm_crypto_suites = true; |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 1820 | gcm_options.crypto_options.srtp.enable_aes128_sha1_80_crypto_cipher = false; |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 1821 | ASSERT_TRUE( |
| 1822 | CreatePeerConnectionWrappersWithOptions(gcm_options, gcm_options)); |
| 1823 | ConnectFakeSignaling(); |
| 1824 | // Do normal offer/answer and wait for some frames to be received in each |
| 1825 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1826 | caller()->AddAudioVideoTracks(); |
| 1827 | callee()->AddAudioVideoTracks(); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 1828 | caller()->CreateAndSetAndSignalOffer(); |
| 1829 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1830 | MediaExpectations media_expectations; |
| 1831 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 1832 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1835 | // Test that the ICE connection and gathering states eventually reach |
| 1836 | // "complete". |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1837 | TEST_P(PeerConnectionIntegrationTest, IceStatesReachCompletion) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1838 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1839 | ConnectFakeSignaling(); |
| 1840 | // Do normal offer/answer. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1841 | caller()->AddAudioVideoTracks(); |
| 1842 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1843 | caller()->CreateAndSetAndSignalOffer(); |
| 1844 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1845 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete, |
| 1846 | caller()->ice_gathering_state(), kMaxWaitForFramesMs); |
| 1847 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete, |
| 1848 | callee()->ice_gathering_state(), kMaxWaitForFramesMs); |
| 1849 | // After the best candidate pair is selected and all candidates are signaled, |
| 1850 | // the ICE connection state should reach "complete". |
| 1851 | // TODO(deadbeef): Currently, the ICE "controlled" agent (the |
| 1852 | // answerer/"callee" by default) only reaches "connected". When this is |
| 1853 | // fixed, this test should be updated. |
| 1854 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 1855 | caller()->ice_connection_state(), kDefaultTimeout); |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 1856 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 1857 | callee()->ice_connection_state(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1858 | } |
| 1859 | |
Harald Alvestrand | ec23d6d | 2021-02-11 10:47:22 +0000 | [diff] [blame] | 1860 | #if !defined(THREAD_SANITIZER) |
| 1861 | // This test provokes TSAN errors. See bugs.webrtc.org/3608 |
| 1862 | |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 1863 | constexpr int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN | |
| 1864 | cricket::PORTALLOCATOR_DISABLE_RELAY | |
| 1865 | cricket::PORTALLOCATOR_DISABLE_TCP; |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 1866 | |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 1867 | // Use a mock resolver to resolve the hostname back to the original IP on both |
| 1868 | // sides and check that the ICE connection connects. |
Markus Handell | 5691053 | 2021-04-10 11:23:14 +0000 | [diff] [blame] | 1869 | // TODO(bugs.webrtc.org/12590): Flaky on Windows and on Linux MSAN. |
| 1870 | #if defined(WEBRTC_WIN) || defined(WEBRTC_LINUX) |
Rasmus Brandt | 32af25b | 2021-03-17 13:40:21 +0100 | [diff] [blame] | 1871 | #define MAYBE_IceStatesReachCompletionWithRemoteHostname \ |
| 1872 | DISABLED_IceStatesReachCompletionWithRemoteHostname |
| 1873 | #else |
| 1874 | #define MAYBE_IceStatesReachCompletionWithRemoteHostname \ |
| 1875 | IceStatesReachCompletionWithRemoteHostname |
| 1876 | #endif |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 1877 | TEST_P(PeerConnectionIntegrationTest, |
Rasmus Brandt | 32af25b | 2021-03-17 13:40:21 +0100 | [diff] [blame] | 1878 | MAYBE_IceStatesReachCompletionWithRemoteHostname) { |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 1879 | auto caller_resolver_factory = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1880 | std::make_unique<NiceMock<webrtc::MockAsyncResolverFactory>>(); |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 1881 | auto callee_resolver_factory = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1882 | std::make_unique<NiceMock<webrtc::MockAsyncResolverFactory>>(); |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 1883 | NiceMock<rtc::MockAsyncResolver> callee_async_resolver; |
| 1884 | NiceMock<rtc::MockAsyncResolver> caller_async_resolver; |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 1885 | |
| 1886 | // This also verifies that the injected AsyncResolverFactory is used by |
| 1887 | // P2PTransportChannel. |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 1888 | EXPECT_CALL(*caller_resolver_factory, Create()) |
| 1889 | .WillOnce(Return(&caller_async_resolver)); |
| 1890 | webrtc::PeerConnectionDependencies caller_deps(nullptr); |
| 1891 | caller_deps.async_resolver_factory = std::move(caller_resolver_factory); |
| 1892 | |
| 1893 | EXPECT_CALL(*callee_resolver_factory, Create()) |
| 1894 | .WillOnce(Return(&callee_async_resolver)); |
| 1895 | webrtc::PeerConnectionDependencies callee_deps(nullptr); |
| 1896 | callee_deps.async_resolver_factory = std::move(callee_resolver_factory); |
| 1897 | |
| 1898 | PeerConnectionInterface::RTCConfiguration config; |
| 1899 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 1900 | config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 1901 | |
| 1902 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps( |
| 1903 | config, std::move(caller_deps), config, std::move(callee_deps))); |
| 1904 | |
| 1905 | caller()->SetRemoteAsyncResolver(&callee_async_resolver); |
| 1906 | callee()->SetRemoteAsyncResolver(&caller_async_resolver); |
| 1907 | |
| 1908 | // Enable hostname candidates with mDNS names. |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 1909 | caller()->SetMdnsResponder( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1910 | std::make_unique<webrtc::FakeMdnsResponder>(network_thread())); |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 1911 | callee()->SetMdnsResponder( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1912 | std::make_unique<webrtc::FakeMdnsResponder>(network_thread())); |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 1913 | |
| 1914 | SetPortAllocatorFlags(kOnlyLocalPorts, kOnlyLocalPorts); |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 1915 | |
| 1916 | ConnectFakeSignaling(); |
| 1917 | caller()->AddAudioVideoTracks(); |
| 1918 | callee()->AddAudioVideoTracks(); |
| 1919 | caller()->CreateAndSetAndSignalOffer(); |
| 1920 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1921 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 1922 | caller()->ice_connection_state(), kDefaultTimeout); |
| 1923 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 1924 | callee()->ice_connection_state(), kDefaultTimeout); |
Jeroen de Borst | 833979f | 2018-12-13 08:25:54 -0800 | [diff] [blame] | 1925 | |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 1926 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents( |
| 1927 | "WebRTC.PeerConnection.CandidatePairType_UDP", |
| 1928 | webrtc::kIceCandidatePairHostNameHostName)); |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 1929 | } |
| 1930 | |
Harald Alvestrand | ec23d6d | 2021-02-11 10:47:22 +0000 | [diff] [blame] | 1931 | #endif // !defined(THREAD_SANITIZER) |
| 1932 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1933 | // Test that firewalling the ICE connection causes the clients to identify the |
| 1934 | // disconnected state and then removing the firewall causes them to reconnect. |
| 1935 | class PeerConnectionIntegrationIceStatesTest |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1936 | : public PeerConnectionIntegrationBaseTest, |
| 1937 | public ::testing::WithParamInterface< |
| 1938 | std::tuple<SdpSemantics, std::tuple<std::string, uint32_t>>> { |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1939 | protected: |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1940 | PeerConnectionIntegrationIceStatesTest() |
| 1941 | : PeerConnectionIntegrationBaseTest(std::get<0>(GetParam())) { |
| 1942 | port_allocator_flags_ = std::get<1>(std::get<1>(GetParam())); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | void StartStunServer(const SocketAddress& server_address) { |
| 1946 | stun_server_.reset( |
Niels Möller | 091617d | 2020-12-02 15:32:08 +0100 | [diff] [blame] | 1947 | cricket::TestStunServer::Create(firewall(), server_address)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | bool TestIPv6() { |
| 1951 | return (port_allocator_flags_ & cricket::PORTALLOCATOR_ENABLE_IPV6); |
| 1952 | } |
| 1953 | |
| 1954 | void SetPortAllocatorFlags() { |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 1955 | PeerConnectionIntegrationBaseTest::SetPortAllocatorFlags( |
| 1956 | port_allocator_flags_, port_allocator_flags_); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | std::vector<SocketAddress> CallerAddresses() { |
| 1960 | std::vector<SocketAddress> addresses; |
| 1961 | addresses.push_back(SocketAddress("1.1.1.1", 0)); |
| 1962 | if (TestIPv6()) { |
| 1963 | addresses.push_back(SocketAddress("1111:0:a:b:c:d:e:f", 0)); |
| 1964 | } |
| 1965 | return addresses; |
| 1966 | } |
| 1967 | |
| 1968 | std::vector<SocketAddress> CalleeAddresses() { |
| 1969 | std::vector<SocketAddress> addresses; |
| 1970 | addresses.push_back(SocketAddress("2.2.2.2", 0)); |
| 1971 | if (TestIPv6()) { |
| 1972 | addresses.push_back(SocketAddress("2222:0:a:b:c:d:e:f", 0)); |
| 1973 | } |
| 1974 | return addresses; |
| 1975 | } |
| 1976 | |
| 1977 | void SetUpNetworkInterfaces() { |
| 1978 | // Remove the default interfaces added by the test infrastructure. |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 1979 | caller()->network_manager()->RemoveInterface(kDefaultLocalAddress); |
| 1980 | callee()->network_manager()->RemoveInterface(kDefaultLocalAddress); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1981 | |
| 1982 | // Add network addresses for test. |
| 1983 | for (const auto& caller_address : CallerAddresses()) { |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 1984 | caller()->network_manager()->AddInterface(caller_address); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1985 | } |
| 1986 | for (const auto& callee_address : CalleeAddresses()) { |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 1987 | callee()->network_manager()->AddInterface(callee_address); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1988 | } |
| 1989 | } |
| 1990 | |
| 1991 | private: |
| 1992 | uint32_t port_allocator_flags_; |
| 1993 | std::unique_ptr<cricket::TestStunServer> stun_server_; |
| 1994 | }; |
| 1995 | |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 1996 | // Ensure FakeClockForTest is constructed first (see class for rationale). |
| 1997 | class PeerConnectionIntegrationIceStatesTestWithFakeClock |
| 1998 | : public FakeClockForTest, |
| 1999 | public PeerConnectionIntegrationIceStatesTest {}; |
| 2000 | |
Harald Alvestrand | ec23d6d | 2021-02-11 10:47:22 +0000 | [diff] [blame] | 2001 | #if !defined(THREAD_SANITIZER) |
| 2002 | // This test provokes TSAN errors. bugs.webrtc.org/11282 |
| 2003 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2004 | // Tests that the PeerConnection goes through all the ICE gathering/connection |
| 2005 | // states over the duration of the call. This includes Disconnected and Failed |
| 2006 | // states, induced by putting a firewall between the peers and waiting for them |
| 2007 | // to time out. |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 2008 | TEST_P(PeerConnectionIntegrationIceStatesTestWithFakeClock, VerifyIceStates) { |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2009 | const SocketAddress kStunServerAddress = |
| 2010 | SocketAddress("99.99.99.1", cricket::STUN_SERVER_PORT); |
| 2011 | StartStunServer(kStunServerAddress); |
| 2012 | |
| 2013 | PeerConnectionInterface::RTCConfiguration config; |
| 2014 | PeerConnectionInterface::IceServer ice_stun_server; |
| 2015 | ice_stun_server.urls.push_back( |
| 2016 | "stun:" + kStunServerAddress.HostAsURIString() + ":" + |
| 2017 | kStunServerAddress.PortAsString()); |
| 2018 | config.servers.push_back(ice_stun_server); |
| 2019 | |
| 2020 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 2021 | ConnectFakeSignaling(); |
| 2022 | SetPortAllocatorFlags(); |
| 2023 | SetUpNetworkInterfaces(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2024 | caller()->AddAudioVideoTracks(); |
| 2025 | callee()->AddAudioVideoTracks(); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2026 | |
| 2027 | // Initial state before anything happens. |
| 2028 | ASSERT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 2029 | caller()->ice_gathering_state()); |
| 2030 | ASSERT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 2031 | caller()->ice_connection_state()); |
Jonas Olsson | 7a6739e | 2019-01-15 16:31:55 +0100 | [diff] [blame] | 2032 | ASSERT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 2033 | caller()->standardized_ice_connection_state()); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2034 | |
| 2035 | // Start the call by creating the offer, setting it as the local description, |
| 2036 | // then sending it to the peer who will respond with an answer. This happens |
| 2037 | // asynchronously so that we can watch the states as it runs in the |
| 2038 | // background. |
| 2039 | caller()->CreateAndSetAndSignalOffer(); |
| 2040 | |
Steve Anton | a9b67ce | 2020-01-16 14:00:44 -0800 | [diff] [blame] | 2041 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 2042 | caller()->ice_connection_state(), kDefaultTimeout, |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 2043 | FakeClock()); |
Steve Anton | a9b67ce | 2020-01-16 14:00:44 -0800 | [diff] [blame] | 2044 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 2045 | caller()->standardized_ice_connection_state(), |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 2046 | kDefaultTimeout, FakeClock()); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2047 | |
| 2048 | // Verify that the observer was notified of the intermediate transitions. |
| 2049 | EXPECT_THAT(caller()->ice_connection_state_history(), |
| 2050 | ElementsAre(PeerConnectionInterface::kIceConnectionChecking, |
| 2051 | PeerConnectionInterface::kIceConnectionConnected, |
| 2052 | PeerConnectionInterface::kIceConnectionCompleted)); |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 2053 | EXPECT_THAT(caller()->standardized_ice_connection_state_history(), |
| 2054 | ElementsAre(PeerConnectionInterface::kIceConnectionChecking, |
| 2055 | PeerConnectionInterface::kIceConnectionConnected, |
| 2056 | PeerConnectionInterface::kIceConnectionCompleted)); |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 2057 | EXPECT_THAT( |
| 2058 | caller()->peer_connection_state_history(), |
| 2059 | ElementsAre(PeerConnectionInterface::PeerConnectionState::kConnecting, |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 2060 | PeerConnectionInterface::PeerConnectionState::kConnected)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2061 | EXPECT_THAT(caller()->ice_gathering_state_history(), |
| 2062 | ElementsAre(PeerConnectionInterface::kIceGatheringGathering, |
| 2063 | PeerConnectionInterface::kIceGatheringComplete)); |
| 2064 | |
| 2065 | // Block connections to/from the caller and wait for ICE to become |
| 2066 | // disconnected. |
| 2067 | for (const auto& caller_address : CallerAddresses()) { |
| 2068 | firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address); |
| 2069 | } |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 2070 | RTC_LOG(LS_INFO) << "Firewall rules applied"; |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 2071 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
| 2072 | caller()->ice_connection_state(), kDefaultTimeout, |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 2073 | FakeClock()); |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 2074 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
| 2075 | caller()->standardized_ice_connection_state(), |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 2076 | kDefaultTimeout, FakeClock()); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2077 | |
| 2078 | // Let ICE re-establish by removing the firewall rules. |
| 2079 | firewall()->ClearRules(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 2080 | RTC_LOG(LS_INFO) << "Firewall rules cleared"; |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 2081 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 2082 | caller()->ice_connection_state(), kDefaultTimeout, |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 2083 | FakeClock()); |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 2084 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 2085 | caller()->standardized_ice_connection_state(), |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 2086 | kDefaultTimeout, FakeClock()); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2087 | |
| 2088 | // According to RFC7675, if there is no response within 30 seconds then the |
| 2089 | // peer should consider the other side to have rejected the connection. This |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 2090 | // is signaled by the state transitioning to "failed". |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2091 | constexpr int kConsentTimeout = 30000; |
| 2092 | for (const auto& caller_address : CallerAddresses()) { |
| 2093 | firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address); |
| 2094 | } |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 2095 | RTC_LOG(LS_INFO) << "Firewall rules applied again"; |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 2096 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionFailed, |
| 2097 | caller()->ice_connection_state(), kConsentTimeout, |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 2098 | FakeClock()); |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 2099 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionFailed, |
| 2100 | caller()->standardized_ice_connection_state(), |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 2101 | kConsentTimeout, FakeClock()); |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | // Tests that if the connection doesn't get set up properly we eventually reach |
| 2105 | // the "failed" iceConnectionState. |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 2106 | TEST_P(PeerConnectionIntegrationIceStatesTestWithFakeClock, |
| 2107 | IceStateSetupFailure) { |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 2108 | // Block connections to/from the caller and wait for ICE to become |
| 2109 | // disconnected. |
| 2110 | for (const auto& caller_address : CallerAddresses()) { |
| 2111 | firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address); |
| 2112 | } |
| 2113 | |
| 2114 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2115 | ConnectFakeSignaling(); |
| 2116 | SetPortAllocatorFlags(); |
| 2117 | SetUpNetworkInterfaces(); |
| 2118 | caller()->AddAudioVideoTracks(); |
| 2119 | caller()->CreateAndSetAndSignalOffer(); |
| 2120 | |
| 2121 | // According to RFC7675, if there is no response within 30 seconds then the |
| 2122 | // peer should consider the other side to have rejected the connection. This |
| 2123 | // is signaled by the state transitioning to "failed". |
| 2124 | constexpr int kConsentTimeout = 30000; |
| 2125 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionFailed, |
| 2126 | caller()->standardized_ice_connection_state(), |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 2127 | kConsentTimeout, FakeClock()); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2128 | } |
| 2129 | |
Harald Alvestrand | ec23d6d | 2021-02-11 10:47:22 +0000 | [diff] [blame] | 2130 | #endif // !defined(THREAD_SANITIZER) |
| 2131 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2132 | // Tests that the best connection is set to the appropriate IPv4/IPv6 connection |
| 2133 | // and that the statistics in the metric observers are updated correctly. |
Rasmus Brandt | 32af25b | 2021-03-17 13:40:21 +0100 | [diff] [blame] | 2134 | // TODO(bugs.webrtc.org/12591): Flaky on Windows. |
| 2135 | #if defined(WEBRTC_WIN) |
| 2136 | #define MAYBE_VerifyBestConnection DISABLED_VerifyBestConnection |
| 2137 | #else |
| 2138 | #define MAYBE_VerifyBestConnection VerifyBestConnection |
| 2139 | #endif |
| 2140 | TEST_P(PeerConnectionIntegrationIceStatesTest, MAYBE_VerifyBestConnection) { |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2141 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2142 | ConnectFakeSignaling(); |
| 2143 | SetPortAllocatorFlags(); |
| 2144 | SetUpNetworkInterfaces(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2145 | caller()->AddAudioVideoTracks(); |
| 2146 | callee()->AddAudioVideoTracks(); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2147 | caller()->CreateAndSetAndSignalOffer(); |
| 2148 | |
| 2149 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Steve Anton | 692f3c7 | 2020-01-16 14:12:31 -0800 | [diff] [blame] | 2150 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 2151 | caller()->ice_connection_state(), kDefaultTimeout); |
| 2152 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 2153 | callee()->ice_connection_state(), kDefaultTimeout); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2154 | |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 2155 | // TODO(bugs.webrtc.org/9456): Fix it. |
| 2156 | const int num_best_ipv4 = webrtc::metrics::NumEvents( |
| 2157 | "WebRTC.PeerConnection.IPMetrics", webrtc::kBestConnections_IPv4); |
| 2158 | const int num_best_ipv6 = webrtc::metrics::NumEvents( |
| 2159 | "WebRTC.PeerConnection.IPMetrics", webrtc::kBestConnections_IPv6); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2160 | if (TestIPv6()) { |
| 2161 | // When IPv6 is enabled, we should prefer an IPv6 connection over an IPv4 |
| 2162 | // connection. |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 2163 | EXPECT_METRIC_EQ(0, num_best_ipv4); |
| 2164 | EXPECT_METRIC_EQ(1, num_best_ipv6); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2165 | } else { |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 2166 | EXPECT_METRIC_EQ(1, num_best_ipv4); |
| 2167 | EXPECT_METRIC_EQ(0, num_best_ipv6); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2168 | } |
| 2169 | |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 2170 | EXPECT_METRIC_EQ(0, webrtc::metrics::NumEvents( |
| 2171 | "WebRTC.PeerConnection.CandidatePairType_UDP", |
| 2172 | webrtc::kIceCandidatePairHostHost)); |
| 2173 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents( |
| 2174 | "WebRTC.PeerConnection.CandidatePairType_UDP", |
| 2175 | webrtc::kIceCandidatePairHostPublicHostPublic)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2176 | } |
| 2177 | |
| 2178 | constexpr uint32_t kFlagsIPv4NoStun = cricket::PORTALLOCATOR_DISABLE_TCP | |
| 2179 | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 2180 | cricket::PORTALLOCATOR_DISABLE_RELAY; |
| 2181 | constexpr uint32_t kFlagsIPv6NoStun = |
| 2182 | cricket::PORTALLOCATOR_DISABLE_TCP | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 2183 | cricket::PORTALLOCATOR_ENABLE_IPV6 | cricket::PORTALLOCATOR_DISABLE_RELAY; |
| 2184 | constexpr uint32_t kFlagsIPv4Stun = |
| 2185 | cricket::PORTALLOCATOR_DISABLE_TCP | cricket::PORTALLOCATOR_DISABLE_RELAY; |
| 2186 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 2187 | INSTANTIATE_TEST_SUITE_P( |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2188 | PeerConnectionIntegrationTest, |
| 2189 | PeerConnectionIntegrationIceStatesTest, |
| 2190 | Combine(Values(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan), |
| 2191 | Values(std::make_pair("IPv4 no STUN", kFlagsIPv4NoStun), |
| 2192 | std::make_pair("IPv6 no STUN", kFlagsIPv6NoStun), |
| 2193 | std::make_pair("IPv4 with STUN", kFlagsIPv4Stun)))); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2194 | |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 2195 | INSTANTIATE_TEST_SUITE_P( |
| 2196 | PeerConnectionIntegrationTest, |
| 2197 | PeerConnectionIntegrationIceStatesTestWithFakeClock, |
| 2198 | Combine(Values(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan), |
| 2199 | Values(std::make_pair("IPv4 no STUN", kFlagsIPv4NoStun), |
| 2200 | std::make_pair("IPv6 no STUN", kFlagsIPv6NoStun), |
| 2201 | std::make_pair("IPv4 with STUN", kFlagsIPv4Stun)))); |
| 2202 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2203 | // This test sets up a call between two parties with audio and video. |
| 2204 | // During the call, the caller restarts ICE and the test verifies that |
| 2205 | // new ICE candidates are generated and audio and video still can flow, and the |
| 2206 | // ICE state reaches completed again. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2207 | TEST_P(PeerConnectionIntegrationTest, MediaContinuesFlowingAfterIceRestart) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2208 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2209 | ConnectFakeSignaling(); |
| 2210 | // Do normal offer/answer and wait for ICE to complete. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2211 | caller()->AddAudioVideoTracks(); |
| 2212 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2213 | caller()->CreateAndSetAndSignalOffer(); |
| 2214 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2215 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 2216 | caller()->ice_connection_state(), kMaxWaitForFramesMs); |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 2217 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 2218 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2219 | |
| 2220 | // To verify that the ICE restart actually occurs, get |
| 2221 | // ufrag/password/candidates before and after restart. |
| 2222 | // Create an SDP string of the first audio candidate for both clients. |
| 2223 | const webrtc::IceCandidateCollection* audio_candidates_caller = |
| 2224 | caller()->pc()->local_description()->candidates(0); |
| 2225 | const webrtc::IceCandidateCollection* audio_candidates_callee = |
| 2226 | callee()->pc()->local_description()->candidates(0); |
| 2227 | ASSERT_GT(audio_candidates_caller->count(), 0u); |
| 2228 | ASSERT_GT(audio_candidates_callee->count(), 0u); |
| 2229 | std::string caller_candidate_pre_restart; |
| 2230 | ASSERT_TRUE( |
| 2231 | audio_candidates_caller->at(0)->ToString(&caller_candidate_pre_restart)); |
| 2232 | std::string callee_candidate_pre_restart; |
| 2233 | ASSERT_TRUE( |
| 2234 | audio_candidates_callee->at(0)->ToString(&callee_candidate_pre_restart)); |
| 2235 | const cricket::SessionDescription* desc = |
| 2236 | caller()->pc()->local_description()->description(); |
| 2237 | std::string caller_ufrag_pre_restart = |
| 2238 | desc->transport_infos()[0].description.ice_ufrag; |
| 2239 | desc = callee()->pc()->local_description()->description(); |
| 2240 | std::string callee_ufrag_pre_restart = |
| 2241 | desc->transport_infos()[0].description.ice_ufrag; |
| 2242 | |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 2243 | EXPECT_EQ(caller()->ice_candidate_pair_change_history().size(), 1u); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2244 | // Have the caller initiate an ICE restart. |
| 2245 | caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions()); |
| 2246 | caller()->CreateAndSetAndSignalOffer(); |
| 2247 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2248 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 2249 | caller()->ice_connection_state(), kMaxWaitForFramesMs); |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 2250 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2251 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
| 2252 | |
| 2253 | // Grab the ufrags/candidates again. |
| 2254 | audio_candidates_caller = caller()->pc()->local_description()->candidates(0); |
| 2255 | audio_candidates_callee = callee()->pc()->local_description()->candidates(0); |
| 2256 | ASSERT_GT(audio_candidates_caller->count(), 0u); |
| 2257 | ASSERT_GT(audio_candidates_callee->count(), 0u); |
| 2258 | std::string caller_candidate_post_restart; |
| 2259 | ASSERT_TRUE( |
| 2260 | audio_candidates_caller->at(0)->ToString(&caller_candidate_post_restart)); |
| 2261 | std::string callee_candidate_post_restart; |
| 2262 | ASSERT_TRUE( |
| 2263 | audio_candidates_callee->at(0)->ToString(&callee_candidate_post_restart)); |
| 2264 | desc = caller()->pc()->local_description()->description(); |
| 2265 | std::string caller_ufrag_post_restart = |
| 2266 | desc->transport_infos()[0].description.ice_ufrag; |
| 2267 | desc = callee()->pc()->local_description()->description(); |
| 2268 | std::string callee_ufrag_post_restart = |
| 2269 | desc->transport_infos()[0].description.ice_ufrag; |
| 2270 | // Sanity check that an ICE restart was actually negotiated in SDP. |
| 2271 | ASSERT_NE(caller_candidate_pre_restart, caller_candidate_post_restart); |
| 2272 | ASSERT_NE(callee_candidate_pre_restart, callee_candidate_post_restart); |
| 2273 | ASSERT_NE(caller_ufrag_pre_restart, caller_ufrag_post_restart); |
| 2274 | ASSERT_NE(callee_ufrag_pre_restart, callee_ufrag_post_restart); |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 2275 | EXPECT_GT(caller()->ice_candidate_pair_change_history().size(), 1u); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2276 | |
| 2277 | // Ensure that additional frames are received after the ICE restart. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2278 | MediaExpectations media_expectations; |
| 2279 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2280 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2281 | } |
| 2282 | |
| 2283 | // Verify that audio/video can be received end-to-end when ICE renomination is |
| 2284 | // enabled. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2285 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithIceRenomination) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2286 | PeerConnectionInterface::RTCConfiguration config; |
| 2287 | config.enable_ice_renomination = true; |
| 2288 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 2289 | ConnectFakeSignaling(); |
| 2290 | // Do normal offer/answer and wait for some frames to be received in each |
| 2291 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2292 | caller()->AddAudioVideoTracks(); |
| 2293 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2294 | caller()->CreateAndSetAndSignalOffer(); |
| 2295 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2296 | // Sanity check that ICE renomination was actually negotiated. |
| 2297 | const cricket::SessionDescription* desc = |
| 2298 | caller()->pc()->local_description()->description(); |
| 2299 | for (const cricket::TransportInfo& info : desc->transport_infos()) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 2300 | ASSERT_THAT(info.description.transport_options, Contains("renomination")); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2301 | } |
| 2302 | desc = callee()->pc()->local_description()->description(); |
| 2303 | for (const cricket::TransportInfo& info : desc->transport_infos()) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 2304 | ASSERT_THAT(info.description.transport_options, Contains("renomination")); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2305 | } |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2306 | MediaExpectations media_expectations; |
| 2307 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2308 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2309 | } |
| 2310 | |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 2311 | // With a max bundle policy and RTCP muxing, adding a new media description to |
| 2312 | // the connection should not affect ICE at all because the new media will use |
| 2313 | // the existing connection. |
Rasmus Brandt | 685be14 | 2021-03-15 14:03:38 +0100 | [diff] [blame] | 2314 | // TODO(bugs.webrtc.org/12538): Fails on tsan. |
| 2315 | #if defined(THREAD_SANITIZER) |
| 2316 | #define MAYBE_AddMediaToConnectedBundleDoesNotRestartIce \ |
| 2317 | DISABLED_AddMediaToConnectedBundleDoesNotRestartIce |
| 2318 | #else |
| 2319 | #define MAYBE_AddMediaToConnectedBundleDoesNotRestartIce \ |
| 2320 | AddMediaToConnectedBundleDoesNotRestartIce |
| 2321 | #endif |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2322 | TEST_P(PeerConnectionIntegrationTest, |
Rasmus Brandt | 685be14 | 2021-03-15 14:03:38 +0100 | [diff] [blame] | 2323 | MAYBE_AddMediaToConnectedBundleDoesNotRestartIce) { |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 2324 | PeerConnectionInterface::RTCConfiguration config; |
| 2325 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 2326 | config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 2327 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig( |
| 2328 | config, PeerConnectionInterface::RTCConfiguration())); |
| 2329 | ConnectFakeSignaling(); |
| 2330 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2331 | caller()->AddAudioTrack(); |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 2332 | caller()->CreateAndSetAndSignalOffer(); |
| 2333 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Steve Anton | ff52f1b | 2017-10-26 12:24:50 -0700 | [diff] [blame] | 2334 | ASSERT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 2335 | caller()->ice_connection_state(), kDefaultTimeout); |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 2336 | |
| 2337 | caller()->clear_ice_connection_state_history(); |
| 2338 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2339 | caller()->AddVideoTrack(); |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 2340 | caller()->CreateAndSetAndSignalOffer(); |
| 2341 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2342 | |
| 2343 | EXPECT_EQ(0u, caller()->ice_connection_state_history().size()); |
| 2344 | } |
| 2345 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2346 | // This test sets up a call between two parties with audio and video. It then |
| 2347 | // renegotiates setting the video m-line to "port 0", then later renegotiates |
| 2348 | // again, enabling video. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2349 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2350 | VideoFlowsAfterMediaSectionIsRejectedAndRecycled) { |
| 2351 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2352 | ConnectFakeSignaling(); |
| 2353 | |
| 2354 | // Do initial negotiation, only sending media from the caller. Will result in |
| 2355 | // video and audio recvonly "m=" sections. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2356 | caller()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2357 | caller()->CreateAndSetAndSignalOffer(); |
| 2358 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2359 | |
| 2360 | // Negotiate again, disabling the video "m=" section (the callee will set the |
| 2361 | // port to 0 due to offer_to_receive_video = 0). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2362 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2363 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2364 | options.offer_to_receive_video = 0; |
| 2365 | callee()->SetOfferAnswerOptions(options); |
| 2366 | } else { |
| 2367 | callee()->SetRemoteOfferHandler([this] { |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 2368 | callee() |
| 2369 | ->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO) |
| 2370 | ->StopInternal(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2371 | }); |
| 2372 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2373 | caller()->CreateAndSetAndSignalOffer(); |
| 2374 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2375 | // Sanity check that video "m=" section was actually rejected. |
| 2376 | const ContentInfo* answer_video_content = cricket::GetFirstVideoContent( |
| 2377 | callee()->pc()->local_description()->description()); |
| 2378 | ASSERT_NE(nullptr, answer_video_content); |
| 2379 | ASSERT_TRUE(answer_video_content->rejected); |
| 2380 | |
| 2381 | // Enable video and do negotiation again, making sure video is received |
| 2382 | // end-to-end, also adding media stream to callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2383 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2384 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2385 | options.offer_to_receive_video = 1; |
| 2386 | callee()->SetOfferAnswerOptions(options); |
| 2387 | } else { |
| 2388 | // The caller's transceiver is stopped, so we need to add another track. |
| 2389 | auto caller_transceiver = |
| 2390 | caller()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO); |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 2391 | EXPECT_EQ(nullptr, caller_transceiver.get()); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2392 | caller()->AddVideoTrack(); |
| 2393 | } |
| 2394 | callee()->AddVideoTrack(); |
| 2395 | callee()->SetRemoteOfferHandler(nullptr); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2396 | caller()->CreateAndSetAndSignalOffer(); |
| 2397 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2398 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2399 | // Verify the caller receives frames from the newly added stream, and the |
| 2400 | // callee receives additional frames from the re-enabled video m= section. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2401 | MediaExpectations media_expectations; |
| 2402 | media_expectations.CalleeExpectsSomeAudio(); |
| 2403 | media_expectations.ExpectBidirectionalVideo(); |
| 2404 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2405 | } |
| 2406 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2407 | // This tests that if we negotiate after calling CreateSender but before we |
| 2408 | // have a track, then set a track later, frames from the newly-set track are |
| 2409 | // received end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2410 | TEST_F(PeerConnectionIntegrationTestPlanB, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2411 | MediaFlowsAfterEarlyWarmupWithCreateSender) { |
| 2412 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2413 | ConnectFakeSignaling(); |
| 2414 | auto caller_audio_sender = |
| 2415 | caller()->pc()->CreateSender("audio", "caller_stream"); |
| 2416 | auto caller_video_sender = |
| 2417 | caller()->pc()->CreateSender("video", "caller_stream"); |
| 2418 | auto callee_audio_sender = |
| 2419 | callee()->pc()->CreateSender("audio", "callee_stream"); |
| 2420 | auto callee_video_sender = |
| 2421 | callee()->pc()->CreateSender("video", "callee_stream"); |
| 2422 | caller()->CreateAndSetAndSignalOffer(); |
| 2423 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
| 2424 | // Wait for ICE to complete, without any tracks being set. |
| 2425 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 2426 | caller()->ice_connection_state(), kMaxWaitForFramesMs); |
| 2427 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 2428 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
| 2429 | // Now set the tracks, and expect frames to immediately start flowing. |
| 2430 | EXPECT_TRUE(caller_audio_sender->SetTrack(caller()->CreateLocalAudioTrack())); |
| 2431 | EXPECT_TRUE(caller_video_sender->SetTrack(caller()->CreateLocalVideoTrack())); |
| 2432 | EXPECT_TRUE(callee_audio_sender->SetTrack(callee()->CreateLocalAudioTrack())); |
| 2433 | EXPECT_TRUE(callee_video_sender->SetTrack(callee()->CreateLocalVideoTrack())); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2434 | MediaExpectations media_expectations; |
| 2435 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2436 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2437 | } |
| 2438 | |
| 2439 | // This tests that if we negotiate after calling AddTransceiver but before we |
| 2440 | // have a track, then set a track later, frames from the newly-set tracks are |
| 2441 | // received end-to-end. |
| 2442 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 2443 | MediaFlowsAfterEarlyWarmupWithAddTransceiver) { |
| 2444 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2445 | ConnectFakeSignaling(); |
| 2446 | auto audio_result = caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
| 2447 | ASSERT_EQ(RTCErrorType::NONE, audio_result.error().type()); |
| 2448 | auto caller_audio_sender = audio_result.MoveValue()->sender(); |
| 2449 | auto video_result = caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_VIDEO); |
| 2450 | ASSERT_EQ(RTCErrorType::NONE, video_result.error().type()); |
| 2451 | auto caller_video_sender = video_result.MoveValue()->sender(); |
| 2452 | callee()->SetRemoteOfferHandler([this] { |
| 2453 | ASSERT_EQ(2u, callee()->pc()->GetTransceivers().size()); |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 2454 | callee()->pc()->GetTransceivers()[0]->SetDirectionWithError( |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2455 | RtpTransceiverDirection::kSendRecv); |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 2456 | callee()->pc()->GetTransceivers()[1]->SetDirectionWithError( |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2457 | RtpTransceiverDirection::kSendRecv); |
| 2458 | }); |
| 2459 | caller()->CreateAndSetAndSignalOffer(); |
| 2460 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
| 2461 | // Wait for ICE to complete, without any tracks being set. |
| 2462 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 2463 | caller()->ice_connection_state(), kMaxWaitForFramesMs); |
| 2464 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 2465 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
| 2466 | // Now set the tracks, and expect frames to immediately start flowing. |
| 2467 | auto callee_audio_sender = callee()->pc()->GetSenders()[0]; |
| 2468 | auto callee_video_sender = callee()->pc()->GetSenders()[1]; |
| 2469 | ASSERT_TRUE(caller_audio_sender->SetTrack(caller()->CreateLocalAudioTrack())); |
| 2470 | ASSERT_TRUE(caller_video_sender->SetTrack(caller()->CreateLocalVideoTrack())); |
| 2471 | ASSERT_TRUE(callee_audio_sender->SetTrack(callee()->CreateLocalAudioTrack())); |
| 2472 | ASSERT_TRUE(callee_video_sender->SetTrack(callee()->CreateLocalVideoTrack())); |
| 2473 | MediaExpectations media_expectations; |
| 2474 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2475 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | // This test verifies that a remote video track can be added via AddStream, |
| 2479 | // and sent end-to-end. For this particular test, it's simply echoed back |
| 2480 | // from the caller to the callee, rather than being forwarded to a third |
| 2481 | // PeerConnection. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2482 | TEST_F(PeerConnectionIntegrationTestPlanB, CanSendRemoteVideoTrack) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2483 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2484 | ConnectFakeSignaling(); |
| 2485 | // Just send a video track from the caller. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2486 | caller()->AddVideoTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2487 | caller()->CreateAndSetAndSignalOffer(); |
| 2488 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 2489 | ASSERT_EQ(1U, callee()->remote_streams()->count()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2490 | |
| 2491 | // Echo the stream back, and do a new offer/anwer (initiated by callee this |
| 2492 | // time). |
| 2493 | callee()->pc()->AddStream(callee()->remote_streams()->at(0)); |
| 2494 | callee()->CreateAndSetAndSignalOffer(); |
| 2495 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
| 2496 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2497 | MediaExpectations media_expectations; |
| 2498 | media_expectations.ExpectBidirectionalVideo(); |
| 2499 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2500 | } |
| 2501 | |
Harald Alvestrand | ec23d6d | 2021-02-11 10:47:22 +0000 | [diff] [blame] | 2502 | #if !defined(THREAD_SANITIZER) |
| 2503 | // This test provokes TSAN errors. bugs.webrtc.org/11282 |
| 2504 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2505 | // Test that we achieve the expected end-to-end connection time, using a |
| 2506 | // fake clock and simulated latency on the media and signaling paths. |
| 2507 | // We use a TURN<->TURN connection because this is usually the quickest to |
| 2508 | // set up initially, especially when we're confident the connection will work |
| 2509 | // and can start sending media before we get a STUN response. |
| 2510 | // |
| 2511 | // With various optimizations enabled, here are the network delays we expect to |
| 2512 | // be on the critical path: |
| 2513 | // 1. 2 signaling trips: Signaling offer and offerer's TURN candidate, then |
| 2514 | // signaling answer (with DTLS fingerprint). |
| 2515 | // 2. 9 media hops: Rest of the DTLS handshake. 3 hops in each direction when |
| 2516 | // using TURN<->TURN pair, and DTLS exchange is 4 packets, |
| 2517 | // the first of which should have arrived before the answer. |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 2518 | TEST_P(PeerConnectionIntegrationTestWithFakeClock, |
| 2519 | EndToEndConnectionTimeWithTurnTurnPair) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2520 | static constexpr int media_hop_delay_ms = 50; |
| 2521 | static constexpr int signaling_trip_delay_ms = 500; |
| 2522 | // For explanation of these values, see comment above. |
| 2523 | static constexpr int required_media_hops = 9; |
| 2524 | static constexpr int required_signaling_trips = 2; |
| 2525 | // For internal delays (such as posting an event asychronously). |
| 2526 | static constexpr int allowed_internal_delay_ms = 20; |
| 2527 | static constexpr int total_connection_time_ms = |
| 2528 | media_hop_delay_ms * required_media_hops + |
| 2529 | signaling_trip_delay_ms * required_signaling_trips + |
| 2530 | allowed_internal_delay_ms; |
| 2531 | |
| 2532 | static const rtc::SocketAddress turn_server_1_internal_address{"88.88.88.0", |
| 2533 | 3478}; |
| 2534 | static const rtc::SocketAddress turn_server_1_external_address{"88.88.88.1", |
| 2535 | 0}; |
| 2536 | static const rtc::SocketAddress turn_server_2_internal_address{"99.99.99.0", |
| 2537 | 3478}; |
| 2538 | static const rtc::SocketAddress turn_server_2_external_address{"99.99.99.1", |
| 2539 | 0}; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 2540 | cricket::TestTurnServer* turn_server_1 = CreateTurnServer( |
| 2541 | turn_server_1_internal_address, turn_server_1_external_address); |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 2542 | |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 2543 | cricket::TestTurnServer* turn_server_2 = CreateTurnServer( |
| 2544 | turn_server_2_internal_address, turn_server_2_external_address); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2545 | // Bypass permission check on received packets so media can be sent before |
| 2546 | // the candidate is signaled. |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 2547 | network_thread()->Invoke<void>(RTC_FROM_HERE, [turn_server_1] { |
| 2548 | turn_server_1->set_enable_permission_checks(false); |
| 2549 | }); |
| 2550 | network_thread()->Invoke<void>(RTC_FROM_HERE, [turn_server_2] { |
| 2551 | turn_server_2->set_enable_permission_checks(false); |
| 2552 | }); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2553 | |
| 2554 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 2555 | webrtc::PeerConnectionInterface::IceServer ice_server_1; |
| 2556 | ice_server_1.urls.push_back("turn:88.88.88.0:3478"); |
| 2557 | ice_server_1.username = "test"; |
| 2558 | ice_server_1.password = "test"; |
| 2559 | client_1_config.servers.push_back(ice_server_1); |
| 2560 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 2561 | client_1_config.presume_writable_when_fully_relayed = true; |
| 2562 | |
| 2563 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 2564 | webrtc::PeerConnectionInterface::IceServer ice_server_2; |
| 2565 | ice_server_2.urls.push_back("turn:99.99.99.0:3478"); |
| 2566 | ice_server_2.username = "test"; |
| 2567 | ice_server_2.password = "test"; |
| 2568 | client_2_config.servers.push_back(ice_server_2); |
| 2569 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 2570 | client_2_config.presume_writable_when_fully_relayed = true; |
| 2571 | |
| 2572 | ASSERT_TRUE( |
| 2573 | CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config)); |
| 2574 | // Set up the simulated delays. |
| 2575 | SetSignalingDelayMs(signaling_trip_delay_ms); |
| 2576 | ConnectFakeSignaling(); |
| 2577 | virtual_socket_server()->set_delay_mean(media_hop_delay_ms); |
| 2578 | virtual_socket_server()->UpdateDelayDistribution(); |
| 2579 | |
| 2580 | // Set "offer to receive audio/video" without adding any tracks, so we just |
| 2581 | // set up ICE/DTLS with no media. |
| 2582 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2583 | options.offer_to_receive_audio = 1; |
| 2584 | options.offer_to_receive_video = 1; |
| 2585 | caller()->SetOfferAnswerOptions(options); |
| 2586 | caller()->CreateAndSetAndSignalOffer(); |
deadbeef | 7145280 | 2017-05-07 17:21:01 -0700 | [diff] [blame] | 2587 | EXPECT_TRUE_SIMULATED_WAIT(DtlsConnected(), total_connection_time_ms, |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 2588 | FakeClock()); |
Seth Hampson | 1d4a76d | 2018-06-19 14:31:41 -0700 | [diff] [blame] | 2589 | // Closing the PeerConnections destroys the ports before the ScopedFakeClock. |
| 2590 | // If this is not done a DCHECK can be hit in ports.cc, because a large |
| 2591 | // negative number is calculated for the rtt due to the global clock changing. |
Steve Anton | d91969e | 2019-05-30 12:27:03 -0700 | [diff] [blame] | 2592 | ClosePeerConnections(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2593 | } |
| 2594 | |
Harald Alvestrand | ec23d6d | 2021-02-11 10:47:22 +0000 | [diff] [blame] | 2595 | #endif // !defined(THREAD_SANITIZER) |
| 2596 | |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 2597 | // Verify that a TurnCustomizer passed in through RTCConfiguration |
| 2598 | // is actually used by the underlying TURN candidate pair. |
| 2599 | // Note that turnport_unittest.cc contains more detailed, lower-level tests. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2600 | TEST_P(PeerConnectionIntegrationTest, TurnCustomizerUsedForTurnConnections) { |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 2601 | static const rtc::SocketAddress turn_server_1_internal_address{"88.88.88.0", |
| 2602 | 3478}; |
| 2603 | static const rtc::SocketAddress turn_server_1_external_address{"88.88.88.1", |
| 2604 | 0}; |
| 2605 | static const rtc::SocketAddress turn_server_2_internal_address{"99.99.99.0", |
| 2606 | 3478}; |
| 2607 | static const rtc::SocketAddress turn_server_2_external_address{"99.99.99.1", |
| 2608 | 0}; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 2609 | CreateTurnServer(turn_server_1_internal_address, |
| 2610 | turn_server_1_external_address); |
| 2611 | CreateTurnServer(turn_server_2_internal_address, |
| 2612 | turn_server_2_external_address); |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 2613 | |
| 2614 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 2615 | webrtc::PeerConnectionInterface::IceServer ice_server_1; |
| 2616 | ice_server_1.urls.push_back("turn:88.88.88.0:3478"); |
| 2617 | ice_server_1.username = "test"; |
| 2618 | ice_server_1.password = "test"; |
| 2619 | client_1_config.servers.push_back(ice_server_1); |
| 2620 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 2621 | auto* customizer1 = CreateTurnCustomizer(); |
| 2622 | client_1_config.turn_customizer = customizer1; |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 2623 | |
| 2624 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 2625 | webrtc::PeerConnectionInterface::IceServer ice_server_2; |
| 2626 | ice_server_2.urls.push_back("turn:99.99.99.0:3478"); |
| 2627 | ice_server_2.username = "test"; |
| 2628 | ice_server_2.password = "test"; |
| 2629 | client_2_config.servers.push_back(ice_server_2); |
| 2630 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 2631 | auto* customizer2 = CreateTurnCustomizer(); |
| 2632 | client_2_config.turn_customizer = customizer2; |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 2633 | |
| 2634 | ASSERT_TRUE( |
| 2635 | CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config)); |
| 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 | |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 2647 | ExpectTurnCustomizerCountersIncremented(customizer1); |
| 2648 | ExpectTurnCustomizerCountersIncremented(customizer2); |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 2649 | } |
| 2650 | |
Benjamin Wright | 2d5f3cb | 2018-05-22 14:46:06 -0700 | [diff] [blame] | 2651 | // Verifies that you can use TCP instead of UDP to connect to a TURN server and |
| 2652 | // send media between the caller and the callee. |
| 2653 | TEST_P(PeerConnectionIntegrationTest, TCPUsedForTurnConnections) { |
| 2654 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 2655 | 3478}; |
| 2656 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 2657 | |
| 2658 | // Enable TCP for the fake turn server. |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 2659 | CreateTurnServer(turn_server_internal_address, turn_server_external_address, |
| 2660 | cricket::PROTO_TCP); |
Benjamin Wright | 2d5f3cb | 2018-05-22 14:46:06 -0700 | [diff] [blame] | 2661 | |
| 2662 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 2663 | ice_server.urls.push_back("turn:88.88.88.0:3478?transport=tcp"); |
| 2664 | ice_server.username = "test"; |
| 2665 | ice_server.password = "test"; |
| 2666 | |
| 2667 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 2668 | client_1_config.servers.push_back(ice_server); |
| 2669 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 2670 | |
| 2671 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 2672 | client_2_config.servers.push_back(ice_server); |
| 2673 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 2674 | |
| 2675 | ASSERT_TRUE( |
| 2676 | CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config)); |
| 2677 | |
| 2678 | // Do normal offer/answer and wait for ICE to complete. |
| 2679 | ConnectFakeSignaling(); |
| 2680 | caller()->AddAudioVideoTracks(); |
| 2681 | callee()->AddAudioVideoTracks(); |
| 2682 | caller()->CreateAndSetAndSignalOffer(); |
| 2683 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2684 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 2685 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
| 2686 | |
| 2687 | MediaExpectations media_expectations; |
| 2688 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2689 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 2690 | } |
| 2691 | |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 2692 | // Verify that a SSLCertificateVerifier passed in through |
| 2693 | // PeerConnectionDependencies is actually used by the underlying SSL |
| 2694 | // implementation to determine whether a certificate presented by the TURN |
| 2695 | // server is accepted by the client. Note that openssladapter_unittest.cc |
| 2696 | // contains more detailed, lower-level tests. |
| 2697 | TEST_P(PeerConnectionIntegrationTest, |
| 2698 | SSLCertificateVerifierUsedForTurnConnections) { |
| 2699 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 2700 | 3478}; |
| 2701 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 2702 | |
| 2703 | // Enable TCP-TLS for the fake turn server. We need to pass in 88.88.88.0 so |
| 2704 | // that host name verification passes on the fake certificate. |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 2705 | CreateTurnServer(turn_server_internal_address, turn_server_external_address, |
| 2706 | cricket::PROTO_TLS, "88.88.88.0"); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 2707 | |
| 2708 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 2709 | ice_server.urls.push_back("turns:88.88.88.0:3478?transport=tcp"); |
| 2710 | ice_server.username = "test"; |
| 2711 | ice_server.password = "test"; |
| 2712 | |
| 2713 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 2714 | client_1_config.servers.push_back(ice_server); |
| 2715 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 2716 | |
| 2717 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 2718 | client_2_config.servers.push_back(ice_server); |
| 2719 | // Setting the type to kRelay forces the connection to go through a TURN |
| 2720 | // server. |
| 2721 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 2722 | |
| 2723 | // Get a copy to the pointer so we can verify calls later. |
| 2724 | rtc::TestCertificateVerifier* client_1_cert_verifier = |
| 2725 | new rtc::TestCertificateVerifier(); |
| 2726 | client_1_cert_verifier->verify_certificate_ = true; |
| 2727 | rtc::TestCertificateVerifier* client_2_cert_verifier = |
| 2728 | new rtc::TestCertificateVerifier(); |
| 2729 | client_2_cert_verifier->verify_certificate_ = true; |
| 2730 | |
| 2731 | // Create the dependencies with the test certificate verifier. |
| 2732 | webrtc::PeerConnectionDependencies client_1_deps(nullptr); |
| 2733 | client_1_deps.tls_cert_verifier = |
| 2734 | std::unique_ptr<rtc::TestCertificateVerifier>(client_1_cert_verifier); |
| 2735 | webrtc::PeerConnectionDependencies client_2_deps(nullptr); |
| 2736 | client_2_deps.tls_cert_verifier = |
| 2737 | std::unique_ptr<rtc::TestCertificateVerifier>(client_2_cert_verifier); |
| 2738 | |
| 2739 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps( |
| 2740 | client_1_config, std::move(client_1_deps), client_2_config, |
| 2741 | std::move(client_2_deps))); |
| 2742 | ConnectFakeSignaling(); |
| 2743 | |
| 2744 | // Set "offer to receive audio/video" without adding any tracks, so we just |
| 2745 | // set up ICE/DTLS with no media. |
| 2746 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2747 | options.offer_to_receive_audio = 1; |
| 2748 | options.offer_to_receive_video = 1; |
| 2749 | caller()->SetOfferAnswerOptions(options); |
| 2750 | caller()->CreateAndSetAndSignalOffer(); |
| 2751 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
| 2752 | |
| 2753 | EXPECT_GT(client_1_cert_verifier->call_count_, 0u); |
| 2754 | EXPECT_GT(client_2_cert_verifier->call_count_, 0u); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 2755 | } |
| 2756 | |
| 2757 | TEST_P(PeerConnectionIntegrationTest, |
| 2758 | SSLCertificateVerifierFailureUsedForTurnConnectionsFailsConnection) { |
| 2759 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 2760 | 3478}; |
| 2761 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 2762 | |
| 2763 | // Enable TCP-TLS for the fake turn server. We need to pass in 88.88.88.0 so |
| 2764 | // that host name verification passes on the fake certificate. |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 2765 | CreateTurnServer(turn_server_internal_address, turn_server_external_address, |
| 2766 | cricket::PROTO_TLS, "88.88.88.0"); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 2767 | |
| 2768 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 2769 | ice_server.urls.push_back("turns:88.88.88.0:3478?transport=tcp"); |
| 2770 | ice_server.username = "test"; |
| 2771 | ice_server.password = "test"; |
| 2772 | |
| 2773 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 2774 | client_1_config.servers.push_back(ice_server); |
| 2775 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 2776 | |
| 2777 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 2778 | client_2_config.servers.push_back(ice_server); |
| 2779 | // Setting the type to kRelay forces the connection to go through a TURN |
| 2780 | // server. |
| 2781 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 2782 | |
| 2783 | // Get a copy to the pointer so we can verify calls later. |
| 2784 | rtc::TestCertificateVerifier* client_1_cert_verifier = |
| 2785 | new rtc::TestCertificateVerifier(); |
| 2786 | client_1_cert_verifier->verify_certificate_ = false; |
| 2787 | rtc::TestCertificateVerifier* client_2_cert_verifier = |
| 2788 | new rtc::TestCertificateVerifier(); |
| 2789 | client_2_cert_verifier->verify_certificate_ = false; |
| 2790 | |
| 2791 | // Create the dependencies with the test certificate verifier. |
| 2792 | webrtc::PeerConnectionDependencies client_1_deps(nullptr); |
| 2793 | client_1_deps.tls_cert_verifier = |
| 2794 | std::unique_ptr<rtc::TestCertificateVerifier>(client_1_cert_verifier); |
| 2795 | webrtc::PeerConnectionDependencies client_2_deps(nullptr); |
| 2796 | client_2_deps.tls_cert_verifier = |
| 2797 | std::unique_ptr<rtc::TestCertificateVerifier>(client_2_cert_verifier); |
| 2798 | |
| 2799 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps( |
| 2800 | client_1_config, std::move(client_1_deps), client_2_config, |
| 2801 | std::move(client_2_deps))); |
| 2802 | ConnectFakeSignaling(); |
| 2803 | |
| 2804 | // Set "offer to receive audio/video" without adding any tracks, so we just |
| 2805 | // set up ICE/DTLS with no media. |
| 2806 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2807 | options.offer_to_receive_audio = 1; |
| 2808 | options.offer_to_receive_video = 1; |
| 2809 | caller()->SetOfferAnswerOptions(options); |
| 2810 | caller()->CreateAndSetAndSignalOffer(); |
| 2811 | bool wait_res = true; |
| 2812 | // TODO(bugs.webrtc.org/9219): When IceConnectionState is implemented |
| 2813 | // properly, should be able to just wait for a state of "failed" instead of |
| 2814 | // waiting a fixed 10 seconds. |
| 2815 | WAIT_(DtlsConnected(), kDefaultTimeout, wait_res); |
| 2816 | ASSERT_FALSE(wait_res); |
| 2817 | |
| 2818 | EXPECT_GT(client_1_cert_verifier->call_count_, 0u); |
| 2819 | EXPECT_GT(client_2_cert_verifier->call_count_, 0u); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 2820 | } |
| 2821 | |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 2822 | // Test that the injected ICE transport factory is used to create ICE transports |
| 2823 | // for WebRTC connections. |
| 2824 | TEST_P(PeerConnectionIntegrationTest, IceTransportFactoryUsedForConnections) { |
| 2825 | PeerConnectionInterface::RTCConfiguration default_config; |
| 2826 | PeerConnectionDependencies dependencies(nullptr); |
| 2827 | auto ice_transport_factory = std::make_unique<MockIceTransportFactory>(); |
| 2828 | EXPECT_CALL(*ice_transport_factory, RecordIceTransportCreated()).Times(1); |
| 2829 | dependencies.ice_transport_factory = std::move(ice_transport_factory); |
Niels Möller | 2a70703 | 2020-06-16 16:39:13 +0200 | [diff] [blame] | 2830 | auto wrapper = CreatePeerConnectionWrapper("Caller", nullptr, &default_config, |
| 2831 | std::move(dependencies), nullptr, |
| 2832 | /*reset_encoder_factory=*/false, |
| 2833 | /*reset_decoder_factory=*/false); |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 2834 | ASSERT_TRUE(wrapper); |
| 2835 | wrapper->CreateDataChannel(); |
Tommi | 87f7090 | 2021-04-27 14:43:08 +0200 | [diff] [blame] | 2836 | auto observer = rtc::make_ref_counted<MockSetSessionDescriptionObserver>(); |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 2837 | wrapper->pc()->SetLocalDescription(observer, |
| 2838 | wrapper->CreateOfferAndWait().release()); |
| 2839 | } |
| 2840 | |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 2841 | // Test that audio and video flow end-to-end when codec names don't use the |
| 2842 | // expected casing, given that they're supposed to be case insensitive. To test |
| 2843 | // this, all but one codec is removed from each media description, and its |
| 2844 | // casing is changed. |
| 2845 | // |
| 2846 | // In the past, this has regressed and caused crashes/black video, due to the |
| 2847 | // fact that code at some layers was doing case-insensitive comparisons and |
| 2848 | // code at other layers was not. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2849 | TEST_P(PeerConnectionIntegrationTest, CodecNamesAreCaseInsensitive) { |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 2850 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2851 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2852 | caller()->AddAudioVideoTracks(); |
| 2853 | callee()->AddAudioVideoTracks(); |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 2854 | |
| 2855 | // Remove all but one audio/video codec (opus and VP8), and change the |
| 2856 | // casing of the caller's generated offer. |
| 2857 | caller()->SetGeneratedSdpMunger([](cricket::SessionDescription* description) { |
| 2858 | cricket::AudioContentDescription* audio = |
| 2859 | GetFirstAudioContentDescription(description); |
| 2860 | ASSERT_NE(nullptr, audio); |
| 2861 | auto audio_codecs = audio->codecs(); |
| 2862 | audio_codecs.erase(std::remove_if(audio_codecs.begin(), audio_codecs.end(), |
| 2863 | [](const cricket::AudioCodec& codec) { |
| 2864 | return codec.name != "opus"; |
| 2865 | }), |
| 2866 | audio_codecs.end()); |
| 2867 | ASSERT_EQ(1u, audio_codecs.size()); |
| 2868 | audio_codecs[0].name = "OpUs"; |
| 2869 | audio->set_codecs(audio_codecs); |
| 2870 | |
| 2871 | cricket::VideoContentDescription* video = |
| 2872 | GetFirstVideoContentDescription(description); |
| 2873 | ASSERT_NE(nullptr, video); |
| 2874 | auto video_codecs = video->codecs(); |
| 2875 | video_codecs.erase(std::remove_if(video_codecs.begin(), video_codecs.end(), |
| 2876 | [](const cricket::VideoCodec& codec) { |
| 2877 | return codec.name != "VP8"; |
| 2878 | }), |
| 2879 | video_codecs.end()); |
| 2880 | ASSERT_EQ(1u, video_codecs.size()); |
| 2881 | video_codecs[0].name = "vP8"; |
| 2882 | video->set_codecs(video_codecs); |
| 2883 | }); |
| 2884 | |
| 2885 | caller()->CreateAndSetAndSignalOffer(); |
| 2886 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2887 | |
| 2888 | // Verify frames are still received end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2889 | MediaExpectations media_expectations; |
| 2890 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2891 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 2892 | } |
| 2893 | |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 2894 | TEST_P(PeerConnectionIntegrationTest, GetSourcesAudio) { |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 2895 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2896 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2897 | caller()->AddAudioTrack(); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 2898 | caller()->CreateAndSetAndSignalOffer(); |
| 2899 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2900 | // Wait for one audio frame to be received by the callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2901 | MediaExpectations media_expectations; |
| 2902 | media_expectations.CalleeExpectsSomeAudio(1); |
| 2903 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 2904 | ASSERT_EQ(callee()->pc()->GetReceivers().size(), 1u); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 2905 | auto receiver = callee()->pc()->GetReceivers()[0]; |
| 2906 | ASSERT_EQ(receiver->media_type(), cricket::MEDIA_TYPE_AUDIO); |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 2907 | auto sources = receiver->GetSources(); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 2908 | ASSERT_GT(receiver->GetParameters().encodings.size(), 0u); |
| 2909 | EXPECT_EQ(receiver->GetParameters().encodings[0].ssrc, |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 2910 | sources[0].source_id()); |
| 2911 | EXPECT_EQ(webrtc::RtpSourceType::SSRC, sources[0].source_type()); |
| 2912 | } |
| 2913 | |
| 2914 | TEST_P(PeerConnectionIntegrationTest, GetSourcesVideo) { |
| 2915 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2916 | ConnectFakeSignaling(); |
| 2917 | caller()->AddVideoTrack(); |
| 2918 | caller()->CreateAndSetAndSignalOffer(); |
| 2919 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2920 | // Wait for one video frame to be received by the callee. |
| 2921 | MediaExpectations media_expectations; |
| 2922 | media_expectations.CalleeExpectsSomeVideo(1); |
| 2923 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2924 | ASSERT_EQ(callee()->pc()->GetReceivers().size(), 1u); |
| 2925 | auto receiver = callee()->pc()->GetReceivers()[0]; |
| 2926 | ASSERT_EQ(receiver->media_type(), cricket::MEDIA_TYPE_VIDEO); |
| 2927 | auto sources = receiver->GetSources(); |
| 2928 | ASSERT_GT(receiver->GetParameters().encodings.size(), 0u); |
Yves Gerey | f781bb5 | 2019-07-23 19:15:39 +0200 | [diff] [blame] | 2929 | ASSERT_GT(sources.size(), 0u); |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 2930 | EXPECT_EQ(receiver->GetParameters().encodings[0].ssrc, |
| 2931 | sources[0].source_id()); |
| 2932 | EXPECT_EQ(webrtc::RtpSourceType::SSRC, sources[0].source_type()); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 2933 | } |
| 2934 | |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 2935 | // Test that if a track is removed and added again with a different stream ID, |
| 2936 | // the new stream ID is successfully communicated in SDP and media continues to |
| 2937 | // flow end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2938 | // TODO(webrtc.bugs.org/8734): This test does not work for Unified Plan because |
| 2939 | // it will not reuse a transceiver that has already been sending. After creating |
| 2940 | // a new transceiver it tries to create an offer with two senders of the same |
| 2941 | // track ids and it fails. |
| 2942 | TEST_F(PeerConnectionIntegrationTestPlanB, RemoveAndAddTrackWithNewStreamId) { |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 2943 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2944 | ConnectFakeSignaling(); |
| 2945 | |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 2946 | // Add track using stream 1, do offer/answer. |
| 2947 | rtc::scoped_refptr<webrtc::AudioTrackInterface> track = |
| 2948 | caller()->CreateLocalAudioTrack(); |
| 2949 | rtc::scoped_refptr<webrtc::RtpSenderInterface> sender = |
Steve Anton | d78323f | 2018-07-11 11:13:44 -0700 | [diff] [blame] | 2950 | caller()->AddTrack(track, {"stream_1"}); |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 2951 | caller()->CreateAndSetAndSignalOffer(); |
| 2952 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2953 | { |
| 2954 | MediaExpectations media_expectations; |
| 2955 | media_expectations.CalleeExpectsSomeAudio(1); |
| 2956 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2957 | } |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 2958 | // Remove the sender, and create a new one with the new stream. |
| 2959 | caller()->pc()->RemoveTrack(sender); |
Steve Anton | d78323f | 2018-07-11 11:13:44 -0700 | [diff] [blame] | 2960 | sender = caller()->AddTrack(track, {"stream_2"}); |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 2961 | caller()->CreateAndSetAndSignalOffer(); |
| 2962 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2963 | // Wait for additional audio frames to be received by the callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2964 | { |
| 2965 | MediaExpectations media_expectations; |
| 2966 | media_expectations.CalleeExpectsSomeAudio(); |
| 2967 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2968 | } |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 2969 | } |
| 2970 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2971 | TEST_P(PeerConnectionIntegrationTest, RtcEventLogOutputWriteCalled) { |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 2972 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2973 | ConnectFakeSignaling(); |
| 2974 | |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 2975 | auto output = std::make_unique<testing::NiceMock<MockRtcEventLogOutput>>(); |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 2976 | ON_CALL(*output, IsActive()).WillByDefault(::testing::Return(true)); |
| 2977 | ON_CALL(*output, Write(::testing::_)).WillByDefault(::testing::Return(true)); |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 2978 | EXPECT_CALL(*output, Write(::testing::_)).Times(::testing::AtLeast(1)); |
Bjorn Terelius | de93943 | 2017-11-20 17:38:14 +0100 | [diff] [blame] | 2979 | EXPECT_TRUE(caller()->pc()->StartRtcEventLog( |
| 2980 | std::move(output), webrtc::RtcEventLog::kImmediateOutput)); |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 2981 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2982 | caller()->AddAudioVideoTracks(); |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 2983 | caller()->CreateAndSetAndSignalOffer(); |
| 2984 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2985 | } |
| 2986 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2987 | // Test that if candidates are only signaled by applying full session |
| 2988 | // descriptions (instead of using AddIceCandidate), the peers can connect to |
| 2989 | // each other and exchange media. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2990 | TEST_P(PeerConnectionIntegrationTest, MediaFlowsWhenCandidatesSetOnlyInSdp) { |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2991 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2992 | // Each side will signal the session descriptions but not candidates. |
| 2993 | ConnectFakeSignalingForSdpOnly(); |
| 2994 | |
| 2995 | // Add audio video track and exchange the initial offer/answer with media |
| 2996 | // information only. This will start ICE gathering on each side. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2997 | caller()->AddAudioVideoTracks(); |
| 2998 | callee()->AddAudioVideoTracks(); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2999 | caller()->CreateAndSetAndSignalOffer(); |
| 3000 | |
| 3001 | // Wait for all candidates to be gathered on both the caller and callee. |
| 3002 | ASSERT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
| 3003 | caller()->ice_gathering_state(), kDefaultTimeout); |
| 3004 | ASSERT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
| 3005 | callee()->ice_gathering_state(), kDefaultTimeout); |
| 3006 | |
| 3007 | // The candidates will now be included in the session description, so |
| 3008 | // signaling them will start the ICE connection. |
| 3009 | caller()->CreateAndSetAndSignalOffer(); |
| 3010 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3011 | |
| 3012 | // Ensure that media flows in both directions. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3013 | MediaExpectations media_expectations; |
| 3014 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3015 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 3016 | } |
| 3017 | |
Harald Alvestrand | ec23d6d | 2021-02-11 10:47:22 +0000 | [diff] [blame] | 3018 | #if !defined(THREAD_SANITIZER) |
| 3019 | // These tests provokes TSAN errors. See bugs.webrtc.org/11305. |
| 3020 | |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 3021 | // Test that SetAudioPlayout can be used to disable audio playout from the |
| 3022 | // start, then later enable it. This may be useful, for example, if the caller |
| 3023 | // needs to play a local ringtone until some event occurs, after which it |
| 3024 | // switches to playing the received audio. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3025 | TEST_P(PeerConnectionIntegrationTest, DisableAndEnableAudioPlayout) { |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 3026 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3027 | ConnectFakeSignaling(); |
| 3028 | |
| 3029 | // Set up audio-only call where audio playout is disabled on caller's side. |
| 3030 | caller()->pc()->SetAudioPlayout(false); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3031 | caller()->AddAudioTrack(); |
| 3032 | callee()->AddAudioTrack(); |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 3033 | caller()->CreateAndSetAndSignalOffer(); |
| 3034 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3035 | |
| 3036 | // Pump messages for a second. |
| 3037 | WAIT(false, 1000); |
| 3038 | // Since audio playout is disabled, the caller shouldn't have received |
| 3039 | // anything (at the playout level, at least). |
| 3040 | EXPECT_EQ(0, caller()->audio_frames_received()); |
| 3041 | // As a sanity check, make sure the callee (for which playout isn't disabled) |
| 3042 | // did still see frames on its audio level. |
| 3043 | ASSERT_GT(callee()->audio_frames_received(), 0); |
| 3044 | |
| 3045 | // Enable playout again, and ensure audio starts flowing. |
| 3046 | caller()->pc()->SetAudioPlayout(true); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3047 | MediaExpectations media_expectations; |
| 3048 | media_expectations.ExpectBidirectionalAudio(); |
| 3049 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 3050 | } |
| 3051 | |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 3052 | double GetAudioEnergyStat(PeerConnectionIntegrationWrapper* pc) { |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 3053 | auto report = pc->NewGetStats(); |
| 3054 | auto track_stats_list = |
| 3055 | report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>(); |
| 3056 | const webrtc::RTCMediaStreamTrackStats* remote_track_stats = nullptr; |
| 3057 | for (const auto* track_stats : track_stats_list) { |
| 3058 | if (track_stats->remote_source.is_defined() && |
| 3059 | *track_stats->remote_source) { |
| 3060 | remote_track_stats = track_stats; |
| 3061 | break; |
| 3062 | } |
| 3063 | } |
| 3064 | |
| 3065 | if (!remote_track_stats->total_audio_energy.is_defined()) { |
| 3066 | return 0.0; |
| 3067 | } |
| 3068 | return *remote_track_stats->total_audio_energy; |
| 3069 | } |
| 3070 | |
| 3071 | // Test that if audio playout is disabled via the SetAudioPlayout() method, then |
| 3072 | // incoming audio is still processed and statistics are generated. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3073 | TEST_P(PeerConnectionIntegrationTest, |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 3074 | DisableAudioPlayoutStillGeneratesAudioStats) { |
| 3075 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3076 | ConnectFakeSignaling(); |
| 3077 | |
| 3078 | // Set up audio-only call where playout is disabled but audio-processing is |
| 3079 | // still active. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3080 | caller()->AddAudioTrack(); |
| 3081 | callee()->AddAudioTrack(); |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 3082 | caller()->pc()->SetAudioPlayout(false); |
| 3083 | |
| 3084 | caller()->CreateAndSetAndSignalOffer(); |
| 3085 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3086 | |
| 3087 | // Wait for the callee to receive audio stats. |
| 3088 | EXPECT_TRUE_WAIT(GetAudioEnergyStat(caller()) > 0, kMaxWaitForFramesMs); |
| 3089 | } |
| 3090 | |
Harald Alvestrand | ec23d6d | 2021-02-11 10:47:22 +0000 | [diff] [blame] | 3091 | #endif // !defined(THREAD_SANITIZER) |
| 3092 | |
henrika | 4f167df | 2017-11-01 14:45:55 +0100 | [diff] [blame] | 3093 | // Test that SetAudioRecording can be used to disable audio recording from the |
| 3094 | // start, then later enable it. This may be useful, for example, if the caller |
| 3095 | // wants to ensure that no audio resources are active before a certain state |
| 3096 | // is reached. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3097 | TEST_P(PeerConnectionIntegrationTest, DisableAndEnableAudioRecording) { |
henrika | 4f167df | 2017-11-01 14:45:55 +0100 | [diff] [blame] | 3098 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3099 | ConnectFakeSignaling(); |
| 3100 | |
| 3101 | // Set up audio-only call where audio recording is disabled on caller's side. |
| 3102 | caller()->pc()->SetAudioRecording(false); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3103 | caller()->AddAudioTrack(); |
| 3104 | callee()->AddAudioTrack(); |
henrika | 4f167df | 2017-11-01 14:45:55 +0100 | [diff] [blame] | 3105 | caller()->CreateAndSetAndSignalOffer(); |
| 3106 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3107 | |
| 3108 | // Pump messages for a second. |
| 3109 | WAIT(false, 1000); |
| 3110 | // Since caller has disabled audio recording, the callee shouldn't have |
| 3111 | // received anything. |
| 3112 | EXPECT_EQ(0, callee()->audio_frames_received()); |
| 3113 | // As a sanity check, make sure the caller did still see frames on its |
| 3114 | // audio level since audio recording is enabled on the calle side. |
| 3115 | ASSERT_GT(caller()->audio_frames_received(), 0); |
| 3116 | |
| 3117 | // Enable audio recording again, and ensure audio starts flowing. |
| 3118 | caller()->pc()->SetAudioRecording(true); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3119 | MediaExpectations media_expectations; |
| 3120 | media_expectations.ExpectBidirectionalAudio(); |
| 3121 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
henrika | 4f167df | 2017-11-01 14:45:55 +0100 | [diff] [blame] | 3122 | } |
| 3123 | |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 3124 | TEST_P(PeerConnectionIntegrationTest, |
| 3125 | IceEventsGeneratedAndLoggedInRtcEventLog) { |
| 3126 | ASSERT_TRUE(CreatePeerConnectionWrappersWithFakeRtcEventLog()); |
| 3127 | ConnectFakeSignaling(); |
| 3128 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3129 | options.offer_to_receive_audio = 1; |
| 3130 | caller()->SetOfferAnswerOptions(options); |
| 3131 | caller()->CreateAndSetAndSignalOffer(); |
| 3132 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
| 3133 | ASSERT_NE(nullptr, caller()->event_log_factory()); |
| 3134 | ASSERT_NE(nullptr, callee()->event_log_factory()); |
| 3135 | webrtc::FakeRtcEventLog* caller_event_log = |
Danil Chapovalov | 4f281f1 | 2021-01-18 13:29:00 +0100 | [diff] [blame] | 3136 | caller()->event_log_factory()->last_log_created(); |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 3137 | webrtc::FakeRtcEventLog* callee_event_log = |
Danil Chapovalov | 4f281f1 | 2021-01-18 13:29:00 +0100 | [diff] [blame] | 3138 | callee()->event_log_factory()->last_log_created(); |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 3139 | ASSERT_NE(nullptr, caller_event_log); |
| 3140 | ASSERT_NE(nullptr, callee_event_log); |
| 3141 | int caller_ice_config_count = caller_event_log->GetEventCount( |
| 3142 | webrtc::RtcEvent::Type::IceCandidatePairConfig); |
| 3143 | int caller_ice_event_count = caller_event_log->GetEventCount( |
| 3144 | webrtc::RtcEvent::Type::IceCandidatePairEvent); |
| 3145 | int callee_ice_config_count = callee_event_log->GetEventCount( |
| 3146 | webrtc::RtcEvent::Type::IceCandidatePairConfig); |
| 3147 | int callee_ice_event_count = callee_event_log->GetEventCount( |
| 3148 | webrtc::RtcEvent::Type::IceCandidatePairEvent); |
| 3149 | EXPECT_LT(0, caller_ice_config_count); |
| 3150 | EXPECT_LT(0, caller_ice_event_count); |
| 3151 | EXPECT_LT(0, callee_ice_config_count); |
| 3152 | EXPECT_LT(0, callee_ice_event_count); |
| 3153 | } |
| 3154 | |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 3155 | TEST_P(PeerConnectionIntegrationTest, RegatherAfterChangingIceTransportType) { |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 3156 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 3157 | 3478}; |
| 3158 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 3159 | |
| 3160 | CreateTurnServer(turn_server_internal_address, turn_server_external_address); |
| 3161 | |
| 3162 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 3163 | ice_server.urls.push_back("turn:88.88.88.0:3478"); |
| 3164 | ice_server.username = "test"; |
| 3165 | ice_server.password = "test"; |
| 3166 | |
| 3167 | PeerConnectionInterface::RTCConfiguration caller_config; |
| 3168 | caller_config.servers.push_back(ice_server); |
| 3169 | caller_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 3170 | caller_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
Qingsi Wang | 1fe119f | 2019-05-31 16:55:33 -0700 | [diff] [blame] | 3171 | caller_config.surface_ice_candidates_on_ice_transport_type_changed = true; |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 3172 | |
| 3173 | PeerConnectionInterface::RTCConfiguration callee_config; |
| 3174 | callee_config.servers.push_back(ice_server); |
| 3175 | callee_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 3176 | callee_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
Qingsi Wang | 1fe119f | 2019-05-31 16:55:33 -0700 | [diff] [blame] | 3177 | callee_config.surface_ice_candidates_on_ice_transport_type_changed = true; |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 3178 | |
| 3179 | ASSERT_TRUE( |
| 3180 | CreatePeerConnectionWrappersWithConfig(caller_config, callee_config)); |
| 3181 | |
| 3182 | // Do normal offer/answer and wait for ICE to complete. |
| 3183 | ConnectFakeSignaling(); |
| 3184 | caller()->AddAudioVideoTracks(); |
| 3185 | callee()->AddAudioVideoTracks(); |
| 3186 | caller()->CreateAndSetAndSignalOffer(); |
| 3187 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3188 | // Since we are doing continual gathering, the ICE transport does not reach |
| 3189 | // kIceGatheringComplete (see |
| 3190 | // P2PTransportChannel::OnCandidatesAllocationDone), and consequently not |
| 3191 | // kIceConnectionComplete. |
| 3192 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 3193 | caller()->ice_connection_state(), kDefaultTimeout); |
| 3194 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 3195 | callee()->ice_connection_state(), kDefaultTimeout); |
| 3196 | // Note that we cannot use the metric |
| 3197 | // |WebRTC.PeerConnection.CandidatePairType_UDP| in this test since this |
| 3198 | // metric is only populated when we reach kIceConnectionComplete in the |
| 3199 | // current implementation. |
| 3200 | EXPECT_EQ(cricket::RELAY_PORT_TYPE, |
| 3201 | caller()->last_candidate_gathered().type()); |
| 3202 | EXPECT_EQ(cricket::RELAY_PORT_TYPE, |
| 3203 | callee()->last_candidate_gathered().type()); |
| 3204 | |
| 3205 | // Loosen the caller's candidate filter. |
| 3206 | caller_config = caller()->pc()->GetConfiguration(); |
| 3207 | caller_config.type = webrtc::PeerConnectionInterface::kAll; |
| 3208 | caller()->pc()->SetConfiguration(caller_config); |
| 3209 | // We should have gathered a new host candidate. |
| 3210 | EXPECT_EQ_WAIT(cricket::LOCAL_PORT_TYPE, |
| 3211 | caller()->last_candidate_gathered().type(), kDefaultTimeout); |
| 3212 | |
| 3213 | // Loosen the callee's candidate filter. |
| 3214 | callee_config = callee()->pc()->GetConfiguration(); |
| 3215 | callee_config.type = webrtc::PeerConnectionInterface::kAll; |
| 3216 | callee()->pc()->SetConfiguration(callee_config); |
| 3217 | EXPECT_EQ_WAIT(cricket::LOCAL_PORT_TYPE, |
| 3218 | callee()->last_candidate_gathered().type(), kDefaultTimeout); |
Jonas Oreland | e309651 | 2020-05-27 09:01:05 +0200 | [diff] [blame] | 3219 | |
| 3220 | // Create an offer and verify that it does not contain an ICE restart (i.e new |
| 3221 | // ice credentials). |
| 3222 | std::string caller_ufrag_pre_offer = caller() |
| 3223 | ->pc() |
| 3224 | ->local_description() |
| 3225 | ->description() |
| 3226 | ->transport_infos()[0] |
| 3227 | .description.ice_ufrag; |
| 3228 | caller()->CreateAndSetAndSignalOffer(); |
| 3229 | std::string caller_ufrag_post_offer = caller() |
| 3230 | ->pc() |
| 3231 | ->local_description() |
| 3232 | ->description() |
| 3233 | ->transport_infos()[0] |
| 3234 | .description.ice_ufrag; |
| 3235 | EXPECT_EQ(caller_ufrag_pre_offer, caller_ufrag_post_offer); |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 3236 | } |
| 3237 | |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 3238 | TEST_P(PeerConnectionIntegrationTest, OnIceCandidateError) { |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 3239 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 3240 | 3478}; |
| 3241 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 3242 | |
| 3243 | CreateTurnServer(turn_server_internal_address, turn_server_external_address); |
| 3244 | |
| 3245 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 3246 | ice_server.urls.push_back("turn:88.88.88.0:3478"); |
| 3247 | ice_server.username = "test"; |
| 3248 | ice_server.password = "123"; |
| 3249 | |
| 3250 | PeerConnectionInterface::RTCConfiguration caller_config; |
| 3251 | caller_config.servers.push_back(ice_server); |
| 3252 | caller_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 3253 | caller_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
| 3254 | |
| 3255 | PeerConnectionInterface::RTCConfiguration callee_config; |
| 3256 | callee_config.servers.push_back(ice_server); |
| 3257 | callee_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 3258 | callee_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
| 3259 | |
| 3260 | ASSERT_TRUE( |
| 3261 | CreatePeerConnectionWrappersWithConfig(caller_config, callee_config)); |
| 3262 | |
| 3263 | // Do normal offer/answer and wait for ICE to complete. |
| 3264 | ConnectFakeSignaling(); |
| 3265 | caller()->AddAudioVideoTracks(); |
| 3266 | callee()->AddAudioVideoTracks(); |
| 3267 | caller()->CreateAndSetAndSignalOffer(); |
| 3268 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3269 | EXPECT_EQ_WAIT(401, caller()->error_event().error_code, kDefaultTimeout); |
| 3270 | EXPECT_EQ("Unauthorized", caller()->error_event().error_text); |
| 3271 | EXPECT_EQ("turn:88.88.88.0:3478?transport=udp", caller()->error_event().url); |
Eldar Rello | 0095d37 | 2019-12-02 22:22:07 +0200 | [diff] [blame] | 3272 | EXPECT_NE(caller()->error_event().address, ""); |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 3273 | } |
| 3274 | |
Eldar Rello | fa8019c | 2020-05-14 11:59:33 +0300 | [diff] [blame] | 3275 | TEST_P(PeerConnectionIntegrationTest, OnIceCandidateErrorWithEmptyAddress) { |
| 3276 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 3277 | ice_server.urls.push_back("turn:127.0.0.1:3478?transport=tcp"); |
| 3278 | ice_server.username = "test"; |
| 3279 | ice_server.password = "test"; |
| 3280 | |
| 3281 | PeerConnectionInterface::RTCConfiguration caller_config; |
| 3282 | caller_config.servers.push_back(ice_server); |
| 3283 | caller_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 3284 | caller_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
| 3285 | |
| 3286 | PeerConnectionInterface::RTCConfiguration callee_config; |
| 3287 | callee_config.servers.push_back(ice_server); |
| 3288 | callee_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 3289 | callee_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
| 3290 | |
| 3291 | ASSERT_TRUE( |
| 3292 | CreatePeerConnectionWrappersWithConfig(caller_config, callee_config)); |
| 3293 | |
| 3294 | // Do normal offer/answer and wait for ICE to complete. |
| 3295 | ConnectFakeSignaling(); |
| 3296 | caller()->AddAudioVideoTracks(); |
| 3297 | callee()->AddAudioVideoTracks(); |
| 3298 | caller()->CreateAndSetAndSignalOffer(); |
| 3299 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3300 | EXPECT_EQ_WAIT(701, caller()->error_event().error_code, kDefaultTimeout); |
| 3301 | EXPECT_EQ(caller()->error_event().address, ""); |
| 3302 | } |
| 3303 | |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 3304 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 3305 | AudioKeepsFlowingAfterImplicitRollback) { |
| 3306 | PeerConnectionInterface::RTCConfiguration config; |
| 3307 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
| 3308 | config.enable_implicit_rollback = true; |
| 3309 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 3310 | ConnectFakeSignaling(); |
| 3311 | caller()->AddAudioTrack(); |
| 3312 | callee()->AddAudioTrack(); |
| 3313 | caller()->CreateAndSetAndSignalOffer(); |
| 3314 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3315 | MediaExpectations media_expectations; |
| 3316 | media_expectations.ExpectBidirectionalAudio(); |
| 3317 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3318 | SetSignalIceCandidates(false); // Workaround candidate outrace sdp. |
| 3319 | caller()->AddVideoTrack(); |
| 3320 | callee()->AddVideoTrack(); |
Tommi | 87f7090 | 2021-04-27 14:43:08 +0200 | [diff] [blame] | 3321 | auto observer = rtc::make_ref_counted<MockSetSessionDescriptionObserver>(); |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 3322 | callee()->pc()->SetLocalDescription(observer, |
| 3323 | callee()->CreateOfferAndWait().release()); |
| 3324 | EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout); |
| 3325 | caller()->CreateAndSetAndSignalOffer(); // Implicit rollback. |
| 3326 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3327 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3328 | } |
| 3329 | |
| 3330 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 3331 | ImplicitRollbackVisitsStableState) { |
| 3332 | RTCConfiguration config; |
| 3333 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
| 3334 | config.enable_implicit_rollback = true; |
| 3335 | |
| 3336 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 3337 | |
Tommi | 87f7090 | 2021-04-27 14:43:08 +0200 | [diff] [blame] | 3338 | auto sld_observer = |
| 3339 | rtc::make_ref_counted<MockSetSessionDescriptionObserver>(); |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 3340 | callee()->pc()->SetLocalDescription(sld_observer, |
| 3341 | callee()->CreateOfferAndWait().release()); |
| 3342 | EXPECT_TRUE_WAIT(sld_observer->called(), kDefaultTimeout); |
| 3343 | EXPECT_EQ(sld_observer->error(), ""); |
| 3344 | |
Tommi | 87f7090 | 2021-04-27 14:43:08 +0200 | [diff] [blame] | 3345 | auto srd_observer = |
| 3346 | rtc::make_ref_counted<MockSetSessionDescriptionObserver>(); |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 3347 | callee()->pc()->SetRemoteDescription( |
| 3348 | srd_observer, caller()->CreateOfferAndWait().release()); |
| 3349 | EXPECT_TRUE_WAIT(srd_observer->called(), kDefaultTimeout); |
| 3350 | EXPECT_EQ(srd_observer->error(), ""); |
| 3351 | |
| 3352 | EXPECT_THAT(callee()->peer_connection_signaling_state_history(), |
| 3353 | ElementsAre(PeerConnectionInterface::kHaveLocalOffer, |
| 3354 | PeerConnectionInterface::kStable, |
| 3355 | PeerConnectionInterface::kHaveRemoteOffer)); |
| 3356 | } |
| 3357 | |
Eldar Rello | bd9c33a | 2020-10-01 17:52:45 +0300 | [diff] [blame] | 3358 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 3359 | H264FmtpSpsPpsIdrInKeyframeParameterUsage) { |
| 3360 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3361 | ConnectFakeSignaling(); |
| 3362 | caller()->AddVideoTrack(); |
| 3363 | callee()->AddVideoTrack(); |
| 3364 | auto munger = [](cricket::SessionDescription* desc) { |
| 3365 | cricket::VideoContentDescription* video = |
| 3366 | GetFirstVideoContentDescription(desc); |
| 3367 | auto codecs = video->codecs(); |
| 3368 | for (auto&& codec : codecs) { |
| 3369 | if (codec.name == "H264") { |
| 3370 | std::string value; |
| 3371 | // The parameter is not supposed to be present in SDP by default. |
| 3372 | EXPECT_FALSE( |
| 3373 | codec.GetParam(cricket::kH264FmtpSpsPpsIdrInKeyframe, &value)); |
| 3374 | codec.SetParam(std::string(cricket::kH264FmtpSpsPpsIdrInKeyframe), |
| 3375 | std::string("")); |
| 3376 | } |
| 3377 | } |
| 3378 | video->set_codecs(codecs); |
| 3379 | }; |
| 3380 | // Munge local offer for SLD. |
| 3381 | caller()->SetGeneratedSdpMunger(munger); |
| 3382 | // Munge remote answer for SRD. |
| 3383 | caller()->SetReceivedSdpMunger(munger); |
| 3384 | caller()->CreateAndSetAndSignalOffer(); |
| 3385 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3386 | // Observe that after munging the parameter is present in generated SDP. |
| 3387 | caller()->SetGeneratedSdpMunger([](cricket::SessionDescription* desc) { |
| 3388 | cricket::VideoContentDescription* video = |
| 3389 | GetFirstVideoContentDescription(desc); |
| 3390 | for (auto&& codec : video->codecs()) { |
| 3391 | if (codec.name == "H264") { |
| 3392 | std::string value; |
| 3393 | EXPECT_TRUE( |
| 3394 | codec.GetParam(cricket::kH264FmtpSpsPpsIdrInKeyframe, &value)); |
| 3395 | } |
| 3396 | } |
| 3397 | }); |
| 3398 | caller()->CreateOfferAndWait(); |
| 3399 | } |
| 3400 | |
Harald Alvestrand | 1a9be30 | 2020-12-11 14:53:59 +0000 | [diff] [blame] | 3401 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
Harald Alvestrand | 94324f2 | 2021-01-13 12:31:53 +0000 | [diff] [blame] | 3402 | RenegotiateManyAudioTransceivers) { |
Harald Alvestrand | 1a9be30 | 2020-12-11 14:53:59 +0000 | [diff] [blame] | 3403 | PeerConnectionInterface::RTCConfiguration config; |
| 3404 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
| 3405 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 3406 | ConnectFakeSignaling(); |
| 3407 | caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
| 3408 | |
| 3409 | caller()->CreateAndSetAndSignalOffer(); |
| 3410 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3411 | int current_size = caller()->pc()->GetTransceivers().size(); |
| 3412 | // Add more tracks until we get close to having issues. |
| 3413 | // Issues have been seen at: |
| 3414 | // - 32 tracks on android_arm64_rel and android_arm_dbg bots |
Harald Alvestrand | cc6ae44 | 2021-01-18 08:06:23 +0000 | [diff] [blame] | 3415 | // - 16 tracks on android_arm_dbg (flaky) |
| 3416 | while (current_size < 8) { |
Harald Alvestrand | 1a9be30 | 2020-12-11 14:53:59 +0000 | [diff] [blame] | 3417 | // Double the number of tracks |
| 3418 | for (int i = 0; i < current_size; i++) { |
| 3419 | caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
| 3420 | } |
| 3421 | current_size = caller()->pc()->GetTransceivers().size(); |
| 3422 | RTC_LOG(LS_INFO) << "Renegotiating with " << current_size << " tracks"; |
| 3423 | auto start_time_ms = rtc::TimeMillis(); |
| 3424 | caller()->CreateAndSetAndSignalOffer(); |
| 3425 | // We want to stop when the time exceeds one second. |
| 3426 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3427 | auto elapsed_time_ms = rtc::TimeMillis() - start_time_ms; |
| 3428 | RTC_LOG(LS_INFO) << "Renegotiating took " << elapsed_time_ms << " ms"; |
| 3429 | ASSERT_GT(1000, elapsed_time_ms) |
| 3430 | << "Audio transceivers: Negotiation took too long after " |
| 3431 | << current_size << " tracks added"; |
| 3432 | } |
| 3433 | } |
| 3434 | |
| 3435 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 3436 | RenegotiateManyVideoTransceivers) { |
| 3437 | PeerConnectionInterface::RTCConfiguration config; |
| 3438 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
| 3439 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 3440 | ConnectFakeSignaling(); |
| 3441 | caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_VIDEO); |
| 3442 | |
| 3443 | caller()->CreateAndSetAndSignalOffer(); |
| 3444 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3445 | int current_size = caller()->pc()->GetTransceivers().size(); |
| 3446 | // Add more tracks until we get close to having issues. |
| 3447 | // Issues have been seen at: |
| 3448 | // - 96 on a Linux workstation |
| 3449 | // - 64 at win_x86_more_configs and win_x64_msvc_dbg |
| 3450 | // - 32 on android_arm64_rel and linux_dbg bots |
Harald Alvestrand | 785e23b | 2021-03-15 21:26:27 +0000 | [diff] [blame] | 3451 | // - 16 on Android 64 (Nexus 5x) |
| 3452 | while (current_size < 8) { |
Harald Alvestrand | 1a9be30 | 2020-12-11 14:53:59 +0000 | [diff] [blame] | 3453 | // Double the number of tracks |
| 3454 | for (int i = 0; i < current_size; i++) { |
| 3455 | caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_VIDEO); |
| 3456 | } |
| 3457 | current_size = caller()->pc()->GetTransceivers().size(); |
| 3458 | RTC_LOG(LS_INFO) << "Renegotiating with " << current_size << " tracks"; |
| 3459 | auto start_time_ms = rtc::TimeMillis(); |
| 3460 | caller()->CreateAndSetAndSignalOffer(); |
| 3461 | // We want to stop when the time exceeds one second. |
| 3462 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3463 | auto elapsed_time_ms = rtc::TimeMillis() - start_time_ms; |
| 3464 | RTC_LOG(LS_INFO) << "Renegotiating took " << elapsed_time_ms << " ms"; |
| 3465 | ASSERT_GT(1000, elapsed_time_ms) |
| 3466 | << "Video transceivers: Negotiation took too long after " |
| 3467 | << current_size << " tracks added"; |
| 3468 | } |
| 3469 | } |
| 3470 | |
Harald Alvestrand | 94324f2 | 2021-01-13 12:31:53 +0000 | [diff] [blame] | 3471 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 3472 | RenegotiateManyVideoTransceiversAndWatchAudioDelay) { |
| 3473 | PeerConnectionInterface::RTCConfiguration config; |
| 3474 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
| 3475 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 3476 | ConnectFakeSignaling(); |
| 3477 | caller()->AddAudioTrack(); |
Harald Alvestrand | cc6ae44 | 2021-01-18 08:06:23 +0000 | [diff] [blame] | 3478 | callee()->AddAudioTrack(); |
Harald Alvestrand | 94324f2 | 2021-01-13 12:31:53 +0000 | [diff] [blame] | 3479 | caller()->CreateAndSetAndSignalOffer(); |
| 3480 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3481 | // Wait until we can see the audio flowing. |
| 3482 | MediaExpectations media_expectations; |
| 3483 | media_expectations.CalleeExpectsSomeAudio(); |
| 3484 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3485 | |
Harald Alvestrand | cc6ae44 | 2021-01-18 08:06:23 +0000 | [diff] [blame] | 3486 | // Get the baseline numbers for audio_packets and audio_delay |
| 3487 | // in both directions. |
| 3488 | caller()->StartWatchingDelayStats(); |
| 3489 | callee()->StartWatchingDelayStats(); |
Harald Alvestrand | 94324f2 | 2021-01-13 12:31:53 +0000 | [diff] [blame] | 3490 | |
| 3491 | int current_size = caller()->pc()->GetTransceivers().size(); |
| 3492 | // Add more tracks until we get close to having issues. |
| 3493 | // Making this number very large makes the test very slow. |
Harald Alvestrand | cc6ae44 | 2021-01-18 08:06:23 +0000 | [diff] [blame] | 3494 | while (current_size < 16) { |
Harald Alvestrand | 94324f2 | 2021-01-13 12:31:53 +0000 | [diff] [blame] | 3495 | // Double the number of tracks |
| 3496 | for (int i = 0; i < current_size; i++) { |
| 3497 | caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_VIDEO); |
| 3498 | } |
| 3499 | current_size = caller()->pc()->GetTransceivers().size(); |
| 3500 | RTC_LOG(LS_INFO) << "Renegotiating with " << current_size << " tracks"; |
| 3501 | auto start_time_ms = rtc::TimeMillis(); |
| 3502 | caller()->CreateAndSetAndSignalOffer(); |
| 3503 | // We want to stop when the time exceeds one second. |
| 3504 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3505 | auto elapsed_time_ms = rtc::TimeMillis() - start_time_ms; |
| 3506 | RTC_LOG(LS_INFO) << "Renegotiating took " << elapsed_time_ms << " ms"; |
| 3507 | // This is a guard against the test using excessive amounts of time. |
| 3508 | ASSERT_GT(5000, elapsed_time_ms) |
| 3509 | << "Video transceivers: Negotiation took too long after " |
| 3510 | << current_size << " tracks added"; |
Harald Alvestrand | cc6ae44 | 2021-01-18 08:06:23 +0000 | [diff] [blame] | 3511 | caller()->UpdateDelayStats("caller reception", current_size); |
| 3512 | callee()->UpdateDelayStats("callee reception", current_size); |
Harald Alvestrand | 94324f2 | 2021-01-13 12:31:53 +0000 | [diff] [blame] | 3513 | } |
| 3514 | } |
| 3515 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 3516 | INSTANTIATE_TEST_SUITE_P(PeerConnectionIntegrationTest, |
| 3517 | PeerConnectionIntegrationTest, |
| 3518 | Values(SdpSemantics::kPlanB, |
| 3519 | SdpSemantics::kUnifiedPlan)); |
Steve Anton | d367921 | 2018-01-17 17:41:02 -0800 | [diff] [blame] | 3520 | |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 3521 | INSTANTIATE_TEST_SUITE_P(PeerConnectionIntegrationTest, |
| 3522 | PeerConnectionIntegrationTestWithFakeClock, |
| 3523 | Values(SdpSemantics::kPlanB, |
| 3524 | SdpSemantics::kUnifiedPlan)); |
| 3525 | |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 3526 | // Tests that verify interoperability between Plan B and Unified Plan |
| 3527 | // PeerConnections. |
| 3528 | class PeerConnectionIntegrationInteropTest |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3529 | : public PeerConnectionIntegrationBaseTest, |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 3530 | public ::testing::WithParamInterface< |
| 3531 | std::tuple<SdpSemantics, SdpSemantics>> { |
| 3532 | protected: |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3533 | // Setting the SdpSemantics for the base test to kDefault does not matter |
| 3534 | // because we specify not to use the test semantics when creating |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 3535 | // PeerConnectionIntegrationWrappers. |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 3536 | PeerConnectionIntegrationInteropTest() |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 3537 | : PeerConnectionIntegrationBaseTest(SdpSemantics::kPlanB), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3538 | caller_semantics_(std::get<0>(GetParam())), |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 3539 | callee_semantics_(std::get<1>(GetParam())) {} |
| 3540 | |
| 3541 | bool CreatePeerConnectionWrappersWithSemantics() { |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 3542 | return CreatePeerConnectionWrappersWithSdpSemantics(caller_semantics_, |
| 3543 | callee_semantics_); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 3544 | } |
| 3545 | |
| 3546 | const SdpSemantics caller_semantics_; |
| 3547 | const SdpSemantics callee_semantics_; |
| 3548 | }; |
| 3549 | |
| 3550 | TEST_P(PeerConnectionIntegrationInteropTest, NoMediaLocalToNoMediaRemote) { |
| 3551 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 3552 | ConnectFakeSignaling(); |
| 3553 | |
| 3554 | caller()->CreateAndSetAndSignalOffer(); |
| 3555 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3556 | } |
| 3557 | |
| 3558 | TEST_P(PeerConnectionIntegrationInteropTest, OneAudioLocalToNoMediaRemote) { |
| 3559 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 3560 | ConnectFakeSignaling(); |
| 3561 | auto audio_sender = caller()->AddAudioTrack(); |
| 3562 | |
| 3563 | caller()->CreateAndSetAndSignalOffer(); |
| 3564 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3565 | |
| 3566 | // Verify that one audio receiver has been created on the remote and that it |
| 3567 | // has the same track ID as the sending track. |
| 3568 | auto receivers = callee()->pc()->GetReceivers(); |
| 3569 | ASSERT_EQ(1u, receivers.size()); |
| 3570 | EXPECT_EQ(cricket::MEDIA_TYPE_AUDIO, receivers[0]->media_type()); |
| 3571 | EXPECT_EQ(receivers[0]->track()->id(), audio_sender->track()->id()); |
| 3572 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3573 | MediaExpectations media_expectations; |
| 3574 | media_expectations.CalleeExpectsSomeAudio(); |
| 3575 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 3576 | } |
| 3577 | |
| 3578 | TEST_P(PeerConnectionIntegrationInteropTest, OneAudioOneVideoToNoMediaRemote) { |
| 3579 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 3580 | ConnectFakeSignaling(); |
| 3581 | auto video_sender = caller()->AddVideoTrack(); |
| 3582 | auto audio_sender = caller()->AddAudioTrack(); |
| 3583 | |
| 3584 | caller()->CreateAndSetAndSignalOffer(); |
| 3585 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3586 | |
| 3587 | // Verify that one audio and one video receiver have been created on the |
| 3588 | // remote and that they have the same track IDs as the sending tracks. |
| 3589 | auto audio_receivers = |
| 3590 | callee()->GetReceiversOfType(cricket::MEDIA_TYPE_AUDIO); |
| 3591 | ASSERT_EQ(1u, audio_receivers.size()); |
| 3592 | EXPECT_EQ(audio_receivers[0]->track()->id(), audio_sender->track()->id()); |
| 3593 | auto video_receivers = |
| 3594 | callee()->GetReceiversOfType(cricket::MEDIA_TYPE_VIDEO); |
| 3595 | ASSERT_EQ(1u, video_receivers.size()); |
| 3596 | EXPECT_EQ(video_receivers[0]->track()->id(), video_sender->track()->id()); |
| 3597 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3598 | MediaExpectations media_expectations; |
| 3599 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 3600 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 3601 | } |
| 3602 | |
| 3603 | TEST_P(PeerConnectionIntegrationInteropTest, |
| 3604 | OneAudioOneVideoLocalToOneAudioOneVideoRemote) { |
| 3605 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 3606 | ConnectFakeSignaling(); |
| 3607 | caller()->AddAudioVideoTracks(); |
| 3608 | callee()->AddAudioVideoTracks(); |
| 3609 | |
| 3610 | caller()->CreateAndSetAndSignalOffer(); |
| 3611 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3612 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3613 | MediaExpectations media_expectations; |
| 3614 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3615 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 3616 | } |
| 3617 | |
| 3618 | TEST_P(PeerConnectionIntegrationInteropTest, |
| 3619 | ReverseRolesOneAudioLocalToOneVideoRemote) { |
| 3620 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 3621 | ConnectFakeSignaling(); |
| 3622 | caller()->AddAudioTrack(); |
| 3623 | callee()->AddVideoTrack(); |
| 3624 | |
| 3625 | caller()->CreateAndSetAndSignalOffer(); |
| 3626 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3627 | |
| 3628 | // Verify that only the audio track has been negotiated. |
| 3629 | EXPECT_EQ(0u, caller()->GetReceiversOfType(cricket::MEDIA_TYPE_VIDEO).size()); |
| 3630 | // Might also check that the callee's NegotiationNeeded flag is set. |
| 3631 | |
| 3632 | // Reverse roles. |
| 3633 | callee()->CreateAndSetAndSignalOffer(); |
| 3634 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3635 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3636 | MediaExpectations media_expectations; |
| 3637 | media_expectations.CallerExpectsSomeVideo(); |
| 3638 | media_expectations.CalleeExpectsSomeAudio(); |
| 3639 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 3640 | } |
| 3641 | |
Harald Alvestrand | 7a2db8a | 2021-06-14 15:41:30 +0000 | [diff] [blame] | 3642 | TEST_P(PeerConnectionIntegrationTest, NewTracksDoNotCauseNewCandidates) { |
| 3643 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3644 | ConnectFakeSignaling(); |
| 3645 | caller()->AddAudioVideoTracks(); |
| 3646 | caller()->CreateAndSetAndSignalOffer(); |
| 3647 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3648 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
| 3649 | caller()->ExpectCandidates(0); |
| 3650 | callee()->ExpectCandidates(0); |
| 3651 | caller()->AddAudioTrack(); |
| 3652 | caller()->CreateAndSetAndSignalOffer(); |
| 3653 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3654 | } |
| 3655 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 3656 | INSTANTIATE_TEST_SUITE_P( |
Steve Anton | ba42e99 | 2018-04-09 14:10:01 -0700 | [diff] [blame] | 3657 | PeerConnectionIntegrationTest, |
| 3658 | PeerConnectionIntegrationInteropTest, |
| 3659 | Values(std::make_tuple(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan), |
| 3660 | std::make_tuple(SdpSemantics::kUnifiedPlan, SdpSemantics::kPlanB))); |
| 3661 | |
| 3662 | // Test that if the Unified Plan side offers two video tracks then the Plan B |
| 3663 | // side will only see the first one and ignore the second. |
| 3664 | TEST_F(PeerConnectionIntegrationTestPlanB, TwoVideoUnifiedPlanToNoMediaPlanB) { |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 3665 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSdpSemantics( |
| 3666 | SdpSemantics::kUnifiedPlan, SdpSemantics::kPlanB)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 3667 | ConnectFakeSignaling(); |
| 3668 | auto first_sender = caller()->AddVideoTrack(); |
| 3669 | caller()->AddVideoTrack(); |
| 3670 | |
| 3671 | caller()->CreateAndSetAndSignalOffer(); |
| 3672 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3673 | |
| 3674 | // Verify that there is only one receiver and it corresponds to the first |
| 3675 | // added track. |
| 3676 | auto receivers = callee()->pc()->GetReceivers(); |
| 3677 | ASSERT_EQ(1u, receivers.size()); |
| 3678 | EXPECT_TRUE(receivers[0]->track()->enabled()); |
| 3679 | EXPECT_EQ(first_sender->track()->id(), receivers[0]->track()->id()); |
| 3680 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3681 | MediaExpectations media_expectations; |
| 3682 | media_expectations.CalleeExpectsSomeVideo(); |
| 3683 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 3684 | } |
| 3685 | |
Steve Anton | 2bed397 | 2019-01-04 17:04:30 -0800 | [diff] [blame] | 3686 | // Test that if the initial offer tagged BUNDLE section is rejected due to its |
| 3687 | // associated RtpTransceiver being stopped and another transceiver is added, |
| 3688 | // then renegotiation causes the callee to receive the new video track without |
| 3689 | // error. |
| 3690 | // This is a regression test for bugs.webrtc.org/9954 |
| 3691 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 3692 | ReOfferWithStoppedBundleTaggedTransceiver) { |
| 3693 | RTCConfiguration config; |
| 3694 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3695 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 3696 | ConnectFakeSignaling(); |
| 3697 | auto audio_transceiver_or_error = |
| 3698 | caller()->pc()->AddTransceiver(caller()->CreateLocalAudioTrack()); |
| 3699 | ASSERT_TRUE(audio_transceiver_or_error.ok()); |
| 3700 | auto audio_transceiver = audio_transceiver_or_error.MoveValue(); |
| 3701 | |
| 3702 | caller()->CreateAndSetAndSignalOffer(); |
| 3703 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3704 | { |
| 3705 | MediaExpectations media_expectations; |
| 3706 | media_expectations.CalleeExpectsSomeAudio(); |
| 3707 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3708 | } |
| 3709 | |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 3710 | audio_transceiver->StopInternal(); |
Steve Anton | 2bed397 | 2019-01-04 17:04:30 -0800 | [diff] [blame] | 3711 | caller()->pc()->AddTransceiver(caller()->CreateLocalVideoTrack()); |
| 3712 | |
| 3713 | caller()->CreateAndSetAndSignalOffer(); |
| 3714 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3715 | { |
| 3716 | MediaExpectations media_expectations; |
| 3717 | media_expectations.CalleeExpectsSomeVideo(); |
| 3718 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3719 | } |
| 3720 | } |
| 3721 | |
Harald Alvestrand | bedb605 | 2020-08-20 14:50:10 +0200 | [diff] [blame] | 3722 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 3723 | StopTransceiverRemovesDtlsTransports) { |
| 3724 | RTCConfiguration config; |
| 3725 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 3726 | ConnectFakeSignaling(); |
| 3727 | auto audio_transceiver_or_error = |
| 3728 | caller()->pc()->AddTransceiver(caller()->CreateLocalAudioTrack()); |
| 3729 | ASSERT_TRUE(audio_transceiver_or_error.ok()); |
| 3730 | auto audio_transceiver = audio_transceiver_or_error.MoveValue(); |
| 3731 | |
| 3732 | caller()->CreateAndSetAndSignalOffer(); |
| 3733 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3734 | |
| 3735 | audio_transceiver->StopStandard(); |
| 3736 | caller()->CreateAndSetAndSignalOffer(); |
| 3737 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3738 | ASSERT_EQ(0U, caller()->pc()->GetTransceivers().size()); |
| 3739 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 3740 | caller()->pc()->ice_gathering_state()); |
| 3741 | EXPECT_THAT(caller()->ice_gathering_state_history(), |
| 3742 | ElementsAre(PeerConnectionInterface::kIceGatheringGathering, |
| 3743 | PeerConnectionInterface::kIceGatheringComplete, |
| 3744 | PeerConnectionInterface::kIceGatheringNew)); |
| 3745 | } |
| 3746 | |
Harald Alvestrand | 1ee3325 | 2020-09-24 13:31:15 +0000 | [diff] [blame] | 3747 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
Harald Alvestrand | 45be0a9 | 2020-09-30 06:55:23 +0000 | [diff] [blame] | 3748 | StopTransceiverStopsAndRemovesTransceivers) { |
| 3749 | RTCConfiguration config; |
| 3750 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 3751 | ConnectFakeSignaling(); |
| 3752 | auto audio_transceiver_or_error = |
| 3753 | caller()->pc()->AddTransceiver(caller()->CreateLocalAudioTrack()); |
| 3754 | ASSERT_TRUE(audio_transceiver_or_error.ok()); |
| 3755 | auto caller_transceiver = audio_transceiver_or_error.MoveValue(); |
| 3756 | |
| 3757 | caller()->CreateAndSetAndSignalOffer(); |
| 3758 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3759 | caller_transceiver->StopStandard(); |
| 3760 | |
| 3761 | auto callee_transceiver = callee()->pc()->GetTransceivers()[0]; |
| 3762 | caller()->CreateAndSetAndSignalOffer(); |
| 3763 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3764 | EXPECT_EQ(0U, caller()->pc()->GetTransceivers().size()); |
| 3765 | EXPECT_EQ(0U, callee()->pc()->GetTransceivers().size()); |
| 3766 | EXPECT_EQ(0U, caller()->pc()->GetSenders().size()); |
| 3767 | EXPECT_EQ(0U, callee()->pc()->GetSenders().size()); |
| 3768 | EXPECT_EQ(0U, caller()->pc()->GetReceivers().size()); |
| 3769 | EXPECT_EQ(0U, callee()->pc()->GetReceivers().size()); |
| 3770 | EXPECT_TRUE(caller_transceiver->stopped()); |
| 3771 | EXPECT_TRUE(callee_transceiver->stopped()); |
| 3772 | } |
| 3773 | |
| 3774 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
Harald Alvestrand | 1ee3325 | 2020-09-24 13:31:15 +0000 | [diff] [blame] | 3775 | StopTransceiverEndsIncomingAudioTrack) { |
| 3776 | RTCConfiguration config; |
| 3777 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 3778 | ConnectFakeSignaling(); |
| 3779 | auto audio_transceiver_or_error = |
| 3780 | caller()->pc()->AddTransceiver(caller()->CreateLocalAudioTrack()); |
| 3781 | ASSERT_TRUE(audio_transceiver_or_error.ok()); |
| 3782 | auto audio_transceiver = audio_transceiver_or_error.MoveValue(); |
| 3783 | |
| 3784 | caller()->CreateAndSetAndSignalOffer(); |
| 3785 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3786 | auto caller_track = audio_transceiver->receiver()->track(); |
| 3787 | auto callee_track = callee()->pc()->GetReceivers()[0]->track(); |
| 3788 | audio_transceiver->StopStandard(); |
| 3789 | EXPECT_EQ(MediaStreamTrackInterface::TrackState::kEnded, |
| 3790 | caller_track->state()); |
| 3791 | caller()->CreateAndSetAndSignalOffer(); |
| 3792 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3793 | EXPECT_EQ(MediaStreamTrackInterface::TrackState::kEnded, |
| 3794 | callee_track->state()); |
| 3795 | } |
| 3796 | |
| 3797 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 3798 | StopTransceiverEndsIncomingVideoTrack) { |
| 3799 | RTCConfiguration config; |
| 3800 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 3801 | ConnectFakeSignaling(); |
| 3802 | auto audio_transceiver_or_error = |
| 3803 | caller()->pc()->AddTransceiver(caller()->CreateLocalVideoTrack()); |
| 3804 | ASSERT_TRUE(audio_transceiver_or_error.ok()); |
| 3805 | auto audio_transceiver = audio_transceiver_or_error.MoveValue(); |
| 3806 | |
| 3807 | caller()->CreateAndSetAndSignalOffer(); |
| 3808 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3809 | auto caller_track = audio_transceiver->receiver()->track(); |
| 3810 | auto callee_track = callee()->pc()->GetReceivers()[0]->track(); |
| 3811 | audio_transceiver->StopStandard(); |
| 3812 | EXPECT_EQ(MediaStreamTrackInterface::TrackState::kEnded, |
| 3813 | caller_track->state()); |
| 3814 | caller()->CreateAndSetAndSignalOffer(); |
| 3815 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3816 | EXPECT_EQ(MediaStreamTrackInterface::TrackState::kEnded, |
| 3817 | callee_track->state()); |
| 3818 | } |
| 3819 | |
Harald Alvestrand | 89c40e2 | 2021-02-17 08:58:35 +0000 | [diff] [blame] | 3820 | } // namespace |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 3821 | |
Mirko Bonadei | ab64e8a | 2018-12-12 12:10:18 +0100 | [diff] [blame] | 3822 | } // namespace webrtc |