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