deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | // Disable for TSan v2, see |
| 12 | // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. |
| 13 | #if !defined(THREAD_SANITIZER) |
| 14 | |
| 15 | #include <stdio.h> |
| 16 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 17 | #include <functional> |
| 18 | #include <list> |
| 19 | #include <map> |
| 20 | #include <memory> |
| 21 | #include <utility> |
| 22 | #include <vector> |
| 23 | |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 24 | #include "absl/algorithm/container.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 25 | #include "api/media_stream_interface.h" |
| 26 | #include "api/peer_connection_interface.h" |
| 27 | #include "api/peer_connection_proxy.h" |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 28 | #include "api/rtc_event_log/rtc_event_log_factory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 29 | #include "api/rtp_receiver_interface.h" |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 30 | #include "api/task_queue/default_task_queue_factory.h" |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 31 | #include "api/test/loopback_media_transport.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 32 | #include "api/uma_metrics.h" |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 33 | #include "api/video_codecs/sdp_video_format.h" |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 34 | #include "call/call.h" |
| 35 | #include "logging/rtc_event_log/fake_rtc_event_log_factory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 36 | #include "media/engine/fake_webrtc_video_engine.h" |
| 37 | #include "media/engine/webrtc_media_engine.h" |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 38 | #include "media/engine/webrtc_media_engine_defaults.h" |
Per Ã…hgren | cc73ed3 | 2020-04-26 23:56:17 +0200 | [diff] [blame] | 39 | #include "modules/audio_processing/test/audio_processing_builder_for_testing.h" |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 40 | #include "p2p/base/fake_ice_transport.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 41 | #include "p2p/base/mock_async_resolver.h" |
| 42 | #include "p2p/base/p2p_constants.h" |
| 43 | #include "p2p/base/port_interface.h" |
| 44 | #include "p2p/base/test_stun_server.h" |
| 45 | #include "p2p/base/test_turn_customizer.h" |
| 46 | #include "p2p/base/test_turn_server.h" |
| 47 | #include "p2p/client/basic_port_allocator.h" |
| 48 | #include "pc/dtmf_sender.h" |
| 49 | #include "pc/local_audio_source.h" |
| 50 | #include "pc/media_session.h" |
| 51 | #include "pc/peer_connection.h" |
| 52 | #include "pc/peer_connection_factory.h" |
| 53 | #include "pc/rtp_media_utils.h" |
| 54 | #include "pc/session_description.h" |
| 55 | #include "pc/test/fake_audio_capture_module.h" |
| 56 | #include "pc/test/fake_periodic_video_track_source.h" |
| 57 | #include "pc/test/fake_rtc_certificate_generator.h" |
| 58 | #include "pc/test/fake_video_track_renderer.h" |
| 59 | #include "pc/test/mock_peer_connection_observers.h" |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 60 | #include "rtc_base/fake_clock.h" |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 61 | #include "rtc_base/fake_mdns_responder.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 62 | #include "rtc_base/fake_network.h" |
| 63 | #include "rtc_base/firewall_socket_server.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 64 | #include "rtc_base/gunit.h" |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 65 | #include "rtc_base/numerics/safe_conversions.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 66 | #include "rtc_base/test_certificate_verifier.h" |
| 67 | #include "rtc_base/time_utils.h" |
| 68 | #include "rtc_base/virtual_socket_server.h" |
Mirko Bonadei | 17f4878 | 2018-09-28 08:51:10 +0200 | [diff] [blame] | 69 | #include "system_wrappers/include/metrics.h" |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 70 | #include "test/field_trial.h" |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 71 | #include "test/gmock.h" |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 72 | |
Mirko Bonadei | ab64e8a | 2018-12-12 12:10:18 +0100 | [diff] [blame] | 73 | namespace webrtc { |
| 74 | namespace { |
| 75 | |
| 76 | using ::cricket::ContentInfo; |
| 77 | using ::cricket::StreamParams; |
| 78 | using ::rtc::SocketAddress; |
| 79 | using ::testing::_; |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 80 | using ::testing::Combine; |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 81 | using ::testing::Contains; |
Mirko Bonadei | e46f5db | 2019-03-26 20:14:46 +0100 | [diff] [blame] | 82 | using ::testing::DoAll; |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 83 | using ::testing::ElementsAre; |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 84 | using ::testing::NiceMock; |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 85 | using ::testing::Return; |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 86 | using ::testing::SetArgPointee; |
Steve Anton | ffa6ce4 | 2018-11-30 09:26:08 -0800 | [diff] [blame] | 87 | using ::testing::UnorderedElementsAreArray; |
Mirko Bonadei | ab64e8a | 2018-12-12 12:10:18 +0100 | [diff] [blame] | 88 | using ::testing::Values; |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 89 | using RTCConfiguration = PeerConnectionInterface::RTCConfiguration; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 90 | |
| 91 | static const int kDefaultTimeout = 10000; |
| 92 | static const int kMaxWaitForStatsMs = 3000; |
| 93 | static const int kMaxWaitForActivationMs = 5000; |
| 94 | static const int kMaxWaitForFramesMs = 10000; |
| 95 | // Default number of audio/video frames to wait for before considering a test |
| 96 | // successful. |
| 97 | static const int kDefaultExpectedAudioFrameCount = 3; |
| 98 | static const int kDefaultExpectedVideoFrameCount = 3; |
| 99 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 100 | static const char kDataChannelLabel[] = "data_channel"; |
| 101 | |
| 102 | // SRTP cipher name negotiated by the tests. This must be updated if the |
| 103 | // default changes. |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 104 | static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_SHA1_80; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 105 | static const int kDefaultSrtpCryptoSuiteGcm = rtc::SRTP_AEAD_AES_256_GCM; |
| 106 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 107 | static const SocketAddress kDefaultLocalAddress("192.168.1.1", 0); |
| 108 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 109 | // Helper function for constructing offer/answer options to initiate an ICE |
| 110 | // restart. |
| 111 | PeerConnectionInterface::RTCOfferAnswerOptions IceRestartOfferAnswerOptions() { |
| 112 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 113 | options.ice_restart = true; |
| 114 | return options; |
| 115 | } |
| 116 | |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 117 | // Remove all stream information (SSRCs, track IDs, etc.) and "msid-semantic" |
| 118 | // attribute from received SDP, simulating a legacy endpoint. |
| 119 | void RemoveSsrcsAndMsids(cricket::SessionDescription* desc) { |
| 120 | for (ContentInfo& content : desc->contents()) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 121 | content.media_description()->mutable_streams().clear(); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 122 | } |
| 123 | desc->set_msid_supported(false); |
Henrik Boström | 5b14778 | 2018-12-04 11:25:05 +0100 | [diff] [blame] | 124 | desc->set_msid_signaling(0); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 127 | // Removes all stream information besides the stream ids, simulating an |
| 128 | // endpoint that only signals a=msid lines to convey stream_ids. |
| 129 | void RemoveSsrcsAndKeepMsids(cricket::SessionDescription* desc) { |
| 130 | for (ContentInfo& content : desc->contents()) { |
Steve Anton | df527fd | 2018-04-27 15:52:03 -0700 | [diff] [blame] | 131 | std::string track_id; |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 132 | std::vector<std::string> stream_ids; |
| 133 | if (!content.media_description()->streams().empty()) { |
Steve Anton | df527fd | 2018-04-27 15:52:03 -0700 | [diff] [blame] | 134 | const StreamParams& first_stream = |
| 135 | content.media_description()->streams()[0]; |
| 136 | track_id = first_stream.id; |
| 137 | stream_ids = first_stream.stream_ids(); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 138 | } |
| 139 | content.media_description()->mutable_streams().clear(); |
Steve Anton | df527fd | 2018-04-27 15:52:03 -0700 | [diff] [blame] | 140 | StreamParams new_stream; |
| 141 | new_stream.id = track_id; |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 142 | new_stream.set_stream_ids(stream_ids); |
| 143 | content.media_description()->AddStream(new_stream); |
| 144 | } |
| 145 | } |
| 146 | |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 147 | int FindFirstMediaStatsIndexByKind( |
| 148 | const std::string& kind, |
| 149 | const std::vector<const webrtc::RTCMediaStreamTrackStats*>& |
| 150 | media_stats_vec) { |
| 151 | for (size_t i = 0; i < media_stats_vec.size(); i++) { |
| 152 | if (media_stats_vec[i]->kind.ValueToString() == kind) { |
| 153 | return i; |
| 154 | } |
| 155 | } |
| 156 | return -1; |
| 157 | } |
| 158 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 159 | class SignalingMessageReceiver { |
| 160 | public: |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 161 | virtual void ReceiveSdpMessage(SdpType type, const std::string& msg) = 0; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 162 | virtual void ReceiveIceMessage(const std::string& sdp_mid, |
| 163 | int sdp_mline_index, |
| 164 | const std::string& msg) = 0; |
| 165 | |
| 166 | protected: |
| 167 | SignalingMessageReceiver() {} |
| 168 | virtual ~SignalingMessageReceiver() {} |
| 169 | }; |
| 170 | |
| 171 | class MockRtpReceiverObserver : public webrtc::RtpReceiverObserverInterface { |
| 172 | public: |
| 173 | explicit MockRtpReceiverObserver(cricket::MediaType media_type) |
| 174 | : expected_media_type_(media_type) {} |
| 175 | |
| 176 | void OnFirstPacketReceived(cricket::MediaType media_type) override { |
| 177 | ASSERT_EQ(expected_media_type_, media_type); |
| 178 | first_packet_received_ = true; |
| 179 | } |
| 180 | |
| 181 | bool first_packet_received() const { return first_packet_received_; } |
| 182 | |
| 183 | virtual ~MockRtpReceiverObserver() {} |
| 184 | |
| 185 | private: |
| 186 | bool first_packet_received_ = false; |
| 187 | cricket::MediaType expected_media_type_; |
| 188 | }; |
| 189 | |
| 190 | // Helper class that wraps a peer connection, observes it, and can accept |
| 191 | // signaling messages from another wrapper. |
| 192 | // |
| 193 | // Uses a fake network, fake A/V capture, and optionally fake |
| 194 | // encoders/decoders, though they aren't used by default since they don't |
| 195 | // advertise support of any codecs. |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 196 | // TODO(steveanton): See how this could become a subclass of |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 197 | // PeerConnectionWrapper defined in peerconnectionwrapper.h. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 198 | class PeerConnectionWrapper : public webrtc::PeerConnectionObserver, |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 199 | public SignalingMessageReceiver { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 200 | public: |
| 201 | // Different factory methods for convenience. |
| 202 | // TODO(deadbeef): Could use the pattern of: |
| 203 | // |
| 204 | // PeerConnectionWrapper = |
| 205 | // WrapperBuilder.WithConfig(...).WithOptions(...).build(); |
| 206 | // |
| 207 | // To reduce some code duplication. |
| 208 | static PeerConnectionWrapper* CreateWithDtlsIdentityStore( |
| 209 | const std::string& debug_name, |
| 210 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
| 211 | rtc::Thread* network_thread, |
| 212 | rtc::Thread* worker_thread) { |
| 213 | PeerConnectionWrapper* client(new PeerConnectionWrapper(debug_name)); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 214 | webrtc::PeerConnectionDependencies dependencies(nullptr); |
| 215 | dependencies.cert_generator = std::move(cert_generator); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 216 | if (!client->Init(nullptr, nullptr, std::move(dependencies), network_thread, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 217 | worker_thread, nullptr, |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 218 | /*media_transport_factory=*/nullptr, |
| 219 | /*reset_encoder_factory=*/false, |
| 220 | /*reset_decoder_factory=*/false)) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 221 | delete client; |
| 222 | return nullptr; |
| 223 | } |
| 224 | return client; |
| 225 | } |
| 226 | |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 227 | webrtc::PeerConnectionFactoryInterface* pc_factory() const { |
| 228 | return peer_connection_factory_.get(); |
| 229 | } |
| 230 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 231 | webrtc::PeerConnectionInterface* pc() const { return peer_connection_.get(); } |
| 232 | |
| 233 | // If a signaling message receiver is set (via ConnectFakeSignaling), this |
| 234 | // will set the whole offer/answer exchange in motion. Just need to wait for |
| 235 | // the signaling state to reach "stable". |
| 236 | void CreateAndSetAndSignalOffer() { |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 237 | auto offer = CreateOfferAndWait(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 238 | ASSERT_NE(nullptr, offer); |
| 239 | EXPECT_TRUE(SetLocalDescriptionAndSendSdpMessage(std::move(offer))); |
| 240 | } |
| 241 | |
| 242 | // Sets the options to be used when CreateAndSetAndSignalOffer is called, or |
| 243 | // when a remote offer is received (via fake signaling) and an answer is |
| 244 | // generated. By default, uses default options. |
| 245 | void SetOfferAnswerOptions( |
| 246 | const PeerConnectionInterface::RTCOfferAnswerOptions& options) { |
| 247 | offer_answer_options_ = options; |
| 248 | } |
| 249 | |
| 250 | // Set a callback to be invoked when SDP is received via the fake signaling |
| 251 | // channel, which provides an opportunity to munge (modify) the SDP. This is |
| 252 | // used to test SDP being applied that a PeerConnection would normally not |
| 253 | // generate, but a non-JSEP endpoint might. |
| 254 | void SetReceivedSdpMunger( |
| 255 | std::function<void(cricket::SessionDescription*)> munger) { |
Mirko Bonadei | c61ce0d | 2017-11-21 17:04:20 +0100 | [diff] [blame] | 256 | received_sdp_munger_ = std::move(munger); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 257 | } |
| 258 | |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 259 | // Similar to the above, but this is run on SDP immediately after it's |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 260 | // generated. |
| 261 | void SetGeneratedSdpMunger( |
| 262 | std::function<void(cricket::SessionDescription*)> munger) { |
Mirko Bonadei | c61ce0d | 2017-11-21 17:04:20 +0100 | [diff] [blame] | 263 | generated_sdp_munger_ = std::move(munger); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 266 | // Set a callback to be invoked when a remote offer is received via the fake |
| 267 | // signaling channel. This provides an opportunity to change the |
| 268 | // PeerConnection state before an answer is created and sent to the caller. |
| 269 | void SetRemoteOfferHandler(std::function<void()> handler) { |
| 270 | remote_offer_handler_ = std::move(handler); |
| 271 | } |
| 272 | |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 273 | void SetRemoteAsyncResolver(rtc::MockAsyncResolver* resolver) { |
| 274 | remote_async_resolver_ = resolver; |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 277 | // Every ICE connection state in order that has been seen by the observer. |
| 278 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 279 | ice_connection_state_history() const { |
| 280 | return ice_connection_state_history_; |
| 281 | } |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 282 | void clear_ice_connection_state_history() { |
| 283 | ice_connection_state_history_.clear(); |
| 284 | } |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 285 | |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 286 | // Every standardized ICE connection state in order that has been seen by the |
| 287 | // observer. |
| 288 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 289 | standardized_ice_connection_state_history() const { |
| 290 | return standardized_ice_connection_state_history_; |
| 291 | } |
| 292 | |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 293 | // Every PeerConnection state in order that has been seen by the observer. |
| 294 | std::vector<PeerConnectionInterface::PeerConnectionState> |
| 295 | peer_connection_state_history() const { |
| 296 | return peer_connection_state_history_; |
| 297 | } |
| 298 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 299 | // Every ICE gathering state in order that has been seen by the observer. |
| 300 | std::vector<PeerConnectionInterface::IceGatheringState> |
| 301 | ice_gathering_state_history() const { |
| 302 | return ice_gathering_state_history_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 303 | } |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 304 | std::vector<cricket::CandidatePairChangeEvent> |
| 305 | ice_candidate_pair_change_history() const { |
| 306 | return ice_candidate_pair_change_history_; |
| 307 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 308 | |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 309 | // Every PeerConnection signaling state in order that has been seen by the |
| 310 | // observer. |
| 311 | std::vector<PeerConnectionInterface::SignalingState> |
| 312 | peer_connection_signaling_state_history() const { |
| 313 | return peer_connection_signaling_state_history_; |
| 314 | } |
| 315 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 316 | void AddAudioVideoTracks() { |
| 317 | AddAudioTrack(); |
| 318 | AddVideoTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 321 | rtc::scoped_refptr<RtpSenderInterface> AddAudioTrack() { |
| 322 | return AddTrack(CreateLocalAudioTrack()); |
| 323 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 324 | |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 325 | rtc::scoped_refptr<RtpSenderInterface> AddVideoTrack() { |
| 326 | return AddTrack(CreateLocalVideoTrack()); |
| 327 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 328 | |
| 329 | rtc::scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack() { |
Niels Möller | 2d02e08 | 2018-05-21 11:23:35 +0200 | [diff] [blame] | 330 | cricket::AudioOptions options; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 331 | // Disable highpass filter so that we can get all the test audio frames. |
Niels Möller | 2d02e08 | 2018-05-21 11:23:35 +0200 | [diff] [blame] | 332 | options.highpass_filter = false; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 333 | rtc::scoped_refptr<webrtc::AudioSourceInterface> source = |
Niels Möller | 2d02e08 | 2018-05-21 11:23:35 +0200 | [diff] [blame] | 334 | peer_connection_factory_->CreateAudioSource(options); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 335 | // TODO(perkj): Test audio source when it is implemented. Currently audio |
| 336 | // always use the default input. |
deadbeef | b1a15d7 | 2017-09-07 14:12:05 -0700 | [diff] [blame] | 337 | return peer_connection_factory_->CreateAudioTrack(rtc::CreateRandomUuid(), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 338 | source); |
| 339 | } |
| 340 | |
| 341 | rtc::scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrack() { |
Johannes Kron | 965e794 | 2018-09-13 15:36:20 +0200 | [diff] [blame] | 342 | webrtc::FakePeriodicVideoSource::Config config; |
| 343 | config.timestamp_offset_ms = rtc::TimeMillis(); |
| 344 | return CreateLocalVideoTrackInternal(config); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | rtc::scoped_refptr<webrtc::VideoTrackInterface> |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 348 | CreateLocalVideoTrackWithConfig( |
| 349 | webrtc::FakePeriodicVideoSource::Config config) { |
| 350 | return CreateLocalVideoTrackInternal(config); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | rtc::scoped_refptr<webrtc::VideoTrackInterface> |
| 354 | CreateLocalVideoTrackWithRotation(webrtc::VideoRotation rotation) { |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 355 | webrtc::FakePeriodicVideoSource::Config config; |
| 356 | config.rotation = rotation; |
Johannes Kron | 965e794 | 2018-09-13 15:36:20 +0200 | [diff] [blame] | 357 | config.timestamp_offset_ms = rtc::TimeMillis(); |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 358 | return CreateLocalVideoTrackInternal(config); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 361 | rtc::scoped_refptr<RtpSenderInterface> AddTrack( |
| 362 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 363 | const std::vector<std::string>& stream_ids = {}) { |
| 364 | auto result = pc()->AddTrack(track, stream_ids); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 365 | EXPECT_EQ(RTCErrorType::NONE, result.error().type()); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 366 | return result.MoveValue(); |
| 367 | } |
| 368 | |
| 369 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceiversOfType( |
| 370 | cricket::MediaType media_type) { |
| 371 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> receivers; |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 372 | for (const auto& receiver : pc()->GetReceivers()) { |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 373 | if (receiver->media_type() == media_type) { |
| 374 | receivers.push_back(receiver); |
| 375 | } |
| 376 | } |
| 377 | return receivers; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 380 | rtc::scoped_refptr<RtpTransceiverInterface> GetFirstTransceiverOfType( |
| 381 | cricket::MediaType media_type) { |
| 382 | for (auto transceiver : pc()->GetTransceivers()) { |
| 383 | if (transceiver->receiver()->media_type() == media_type) { |
| 384 | return transceiver; |
| 385 | } |
| 386 | } |
| 387 | return nullptr; |
| 388 | } |
| 389 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 390 | bool SignalingStateStable() { |
| 391 | return pc()->signaling_state() == webrtc::PeerConnectionInterface::kStable; |
| 392 | } |
| 393 | |
| 394 | void CreateDataChannel() { CreateDataChannel(nullptr); } |
| 395 | |
| 396 | void CreateDataChannel(const webrtc::DataChannelInit* init) { |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 397 | CreateDataChannel(kDataChannelLabel, init); |
| 398 | } |
| 399 | |
| 400 | void CreateDataChannel(const std::string& label, |
| 401 | const webrtc::DataChannelInit* init) { |
| 402 | data_channel_ = pc()->CreateDataChannel(label, init); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 403 | ASSERT_TRUE(data_channel_.get() != nullptr); |
| 404 | data_observer_.reset(new MockDataChannelObserver(data_channel_)); |
| 405 | } |
| 406 | |
| 407 | DataChannelInterface* data_channel() { return data_channel_; } |
| 408 | const MockDataChannelObserver* data_observer() const { |
| 409 | return data_observer_.get(); |
| 410 | } |
| 411 | |
| 412 | int audio_frames_received() const { |
| 413 | return fake_audio_capture_module_->frames_received(); |
| 414 | } |
| 415 | |
| 416 | // Takes minimum of video frames received for each track. |
| 417 | // |
| 418 | // Can be used like: |
| 419 | // EXPECT_GE(expected_frames, min_video_frames_received_per_track()); |
| 420 | // |
| 421 | // To ensure that all video tracks received at least a certain number of |
| 422 | // frames. |
| 423 | int min_video_frames_received_per_track() const { |
| 424 | int min_frames = INT_MAX; |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 425 | if (fake_video_renderers_.empty()) { |
| 426 | return 0; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 427 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 428 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 429 | for (const auto& pair : fake_video_renderers_) { |
| 430 | min_frames = std::min(min_frames, pair.second->num_rendered_frames()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 431 | } |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 432 | return min_frames; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | // Returns a MockStatsObserver in a state after stats gathering finished, |
| 436 | // which can be used to access the gathered stats. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 437 | rtc::scoped_refptr<MockStatsObserver> OldGetStatsForTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 438 | webrtc::MediaStreamTrackInterface* track) { |
| 439 | rtc::scoped_refptr<MockStatsObserver> observer( |
| 440 | new rtc::RefCountedObject<MockStatsObserver>()); |
| 441 | EXPECT_TRUE(peer_connection_->GetStats( |
| 442 | observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard)); |
| 443 | EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout); |
| 444 | return observer; |
| 445 | } |
| 446 | |
| 447 | // Version that doesn't take a track "filter", and gathers all stats. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 448 | rtc::scoped_refptr<MockStatsObserver> OldGetStats() { |
| 449 | return OldGetStatsForTrack(nullptr); |
| 450 | } |
| 451 | |
| 452 | // Synchronously gets stats and returns them. If it times out, fails the test |
| 453 | // and returns null. |
| 454 | rtc::scoped_refptr<const webrtc::RTCStatsReport> NewGetStats() { |
| 455 | rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback( |
| 456 | new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>()); |
| 457 | peer_connection_->GetStats(callback); |
| 458 | EXPECT_TRUE_WAIT(callback->called(), kDefaultTimeout); |
| 459 | return callback->report(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | int rendered_width() { |
| 463 | EXPECT_FALSE(fake_video_renderers_.empty()); |
| 464 | return fake_video_renderers_.empty() |
| 465 | ? 0 |
| 466 | : fake_video_renderers_.begin()->second->width(); |
| 467 | } |
| 468 | |
| 469 | int rendered_height() { |
| 470 | EXPECT_FALSE(fake_video_renderers_.empty()); |
| 471 | return fake_video_renderers_.empty() |
| 472 | ? 0 |
| 473 | : fake_video_renderers_.begin()->second->height(); |
| 474 | } |
| 475 | |
| 476 | double rendered_aspect_ratio() { |
| 477 | if (rendered_height() == 0) { |
| 478 | return 0.0; |
| 479 | } |
| 480 | return static_cast<double>(rendered_width()) / rendered_height(); |
| 481 | } |
| 482 | |
| 483 | webrtc::VideoRotation rendered_rotation() { |
| 484 | EXPECT_FALSE(fake_video_renderers_.empty()); |
| 485 | return fake_video_renderers_.empty() |
| 486 | ? webrtc::kVideoRotation_0 |
| 487 | : fake_video_renderers_.begin()->second->rotation(); |
| 488 | } |
| 489 | |
| 490 | int local_rendered_width() { |
| 491 | return local_video_renderer_ ? local_video_renderer_->width() : 0; |
| 492 | } |
| 493 | |
| 494 | int local_rendered_height() { |
| 495 | return local_video_renderer_ ? local_video_renderer_->height() : 0; |
| 496 | } |
| 497 | |
| 498 | double local_rendered_aspect_ratio() { |
| 499 | if (local_rendered_height() == 0) { |
| 500 | return 0.0; |
| 501 | } |
| 502 | return static_cast<double>(local_rendered_width()) / |
| 503 | local_rendered_height(); |
| 504 | } |
| 505 | |
| 506 | size_t number_of_remote_streams() { |
| 507 | if (!pc()) { |
| 508 | return 0; |
| 509 | } |
| 510 | return pc()->remote_streams()->count(); |
| 511 | } |
| 512 | |
| 513 | StreamCollectionInterface* remote_streams() const { |
| 514 | if (!pc()) { |
| 515 | ADD_FAILURE(); |
| 516 | return nullptr; |
| 517 | } |
| 518 | return pc()->remote_streams(); |
| 519 | } |
| 520 | |
| 521 | StreamCollectionInterface* local_streams() { |
| 522 | if (!pc()) { |
| 523 | ADD_FAILURE(); |
| 524 | return nullptr; |
| 525 | } |
| 526 | return pc()->local_streams(); |
| 527 | } |
| 528 | |
| 529 | webrtc::PeerConnectionInterface::SignalingState signaling_state() { |
| 530 | return pc()->signaling_state(); |
| 531 | } |
| 532 | |
| 533 | webrtc::PeerConnectionInterface::IceConnectionState ice_connection_state() { |
| 534 | return pc()->ice_connection_state(); |
| 535 | } |
| 536 | |
Jonas Olsson | 7a6739e | 2019-01-15 16:31:55 +0100 | [diff] [blame] | 537 | webrtc::PeerConnectionInterface::IceConnectionState |
| 538 | standardized_ice_connection_state() { |
| 539 | return pc()->standardized_ice_connection_state(); |
| 540 | } |
| 541 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 542 | webrtc::PeerConnectionInterface::IceGatheringState ice_gathering_state() { |
| 543 | return pc()->ice_gathering_state(); |
| 544 | } |
| 545 | |
| 546 | // Returns a MockRtpReceiverObserver for each RtpReceiver returned by |
| 547 | // GetReceivers. They're updated automatically when a remote offer/answer |
| 548 | // from the fake signaling channel is applied, or when |
| 549 | // ResetRtpReceiverObservers below is called. |
| 550 | const std::vector<std::unique_ptr<MockRtpReceiverObserver>>& |
| 551 | rtp_receiver_observers() { |
| 552 | return rtp_receiver_observers_; |
| 553 | } |
| 554 | |
| 555 | void ResetRtpReceiverObservers() { |
| 556 | rtp_receiver_observers_.clear(); |
Mirko Bonadei | c61ce0d | 2017-11-21 17:04:20 +0100 | [diff] [blame] | 557 | for (const rtc::scoped_refptr<RtpReceiverInterface>& receiver : |
| 558 | pc()->GetReceivers()) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 559 | std::unique_ptr<MockRtpReceiverObserver> observer( |
| 560 | new MockRtpReceiverObserver(receiver->media_type())); |
| 561 | receiver->SetObserver(observer.get()); |
| 562 | rtp_receiver_observers_.push_back(std::move(observer)); |
| 563 | } |
| 564 | } |
| 565 | |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 566 | rtc::FakeNetworkManager* network_manager() const { |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 567 | return fake_network_manager_.get(); |
| 568 | } |
| 569 | cricket::PortAllocator* port_allocator() const { return port_allocator_; } |
| 570 | |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 571 | webrtc::FakeRtcEventLogFactory* event_log_factory() const { |
| 572 | return event_log_factory_; |
| 573 | } |
| 574 | |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 575 | const cricket::Candidate& last_candidate_gathered() const { |
| 576 | return last_candidate_gathered_; |
| 577 | } |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 578 | const cricket::IceCandidateErrorEvent& error_event() const { |
| 579 | return error_event_; |
| 580 | } |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 581 | |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 582 | // Sets the mDNS responder for the owned fake network manager and keeps a |
| 583 | // reference to the responder. |
| 584 | void SetMdnsResponder( |
| 585 | std::unique_ptr<webrtc::FakeMdnsResponder> mdns_responder) { |
| 586 | RTC_DCHECK(mdns_responder != nullptr); |
| 587 | mdns_responder_ = mdns_responder.get(); |
| 588 | network_manager()->set_mdns_responder(std::move(mdns_responder)); |
| 589 | } |
| 590 | |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 591 | // Returns null on failure. |
| 592 | std::unique_ptr<SessionDescriptionInterface> CreateOfferAndWait() { |
| 593 | rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer( |
| 594 | new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>()); |
| 595 | pc()->CreateOffer(observer, offer_answer_options_); |
| 596 | return WaitForDescriptionFromObserver(observer); |
| 597 | } |
Eldar Rello | d9ebe01 | 2020-03-18 20:41:45 +0200 | [diff] [blame] | 598 | bool Rollback() { |
| 599 | return SetRemoteDescription( |
| 600 | webrtc::CreateSessionDescription(SdpType::kRollback, "")); |
| 601 | } |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 602 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 603 | private: |
| 604 | explicit PeerConnectionWrapper(const std::string& debug_name) |
| 605 | : debug_name_(debug_name) {} |
| 606 | |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 607 | bool Init( |
| 608 | const PeerConnectionFactory::Options* options, |
| 609 | const PeerConnectionInterface::RTCConfiguration* config, |
| 610 | webrtc::PeerConnectionDependencies dependencies, |
| 611 | rtc::Thread* network_thread, |
| 612 | rtc::Thread* worker_thread, |
| 613 | std::unique_ptr<webrtc::FakeRtcEventLogFactory> event_log_factory, |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 614 | std::unique_ptr<webrtc::MediaTransportFactory> media_transport_factory, |
| 615 | bool reset_encoder_factory, |
| 616 | bool reset_decoder_factory) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 617 | // There's an error in this test code if Init ends up being called twice. |
| 618 | RTC_DCHECK(!peer_connection_); |
| 619 | RTC_DCHECK(!peer_connection_factory_); |
| 620 | |
| 621 | fake_network_manager_.reset(new rtc::FakeNetworkManager()); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 622 | fake_network_manager_->AddInterface(kDefaultLocalAddress); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 623 | |
| 624 | std::unique_ptr<cricket::PortAllocator> port_allocator( |
| 625 | new cricket::BasicPortAllocator(fake_network_manager_.get())); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 626 | port_allocator_ = port_allocator.get(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 627 | fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); |
| 628 | if (!fake_audio_capture_module_) { |
| 629 | return false; |
| 630 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 631 | rtc::Thread* const signaling_thread = rtc::Thread::Current(); |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 632 | |
| 633 | webrtc::PeerConnectionFactoryDependencies pc_factory_dependencies; |
| 634 | pc_factory_dependencies.network_thread = network_thread; |
| 635 | pc_factory_dependencies.worker_thread = worker_thread; |
| 636 | pc_factory_dependencies.signaling_thread = signaling_thread; |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 637 | pc_factory_dependencies.task_queue_factory = |
| 638 | webrtc::CreateDefaultTaskQueueFactory(); |
| 639 | cricket::MediaEngineDependencies media_deps; |
| 640 | media_deps.task_queue_factory = |
| 641 | pc_factory_dependencies.task_queue_factory.get(); |
| 642 | media_deps.adm = fake_audio_capture_module_; |
| 643 | webrtc::SetMediaEngineDefaults(&media_deps); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 644 | |
| 645 | if (reset_encoder_factory) { |
| 646 | media_deps.video_encoder_factory.reset(); |
| 647 | } |
| 648 | if (reset_decoder_factory) { |
| 649 | media_deps.video_decoder_factory.reset(); |
| 650 | } |
| 651 | |
Per Ã…hgren | cc73ed3 | 2020-04-26 23:56:17 +0200 | [diff] [blame] | 652 | if (!media_deps.audio_processing) { |
| 653 | // If the standard Creation method for APM returns a null pointer, instead |
| 654 | // use the builder for testing to create an APM object. |
| 655 | media_deps.audio_processing = AudioProcessingBuilderForTesting().Create(); |
| 656 | } |
| 657 | |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 658 | pc_factory_dependencies.media_engine = |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 659 | cricket::CreateMediaEngine(std::move(media_deps)); |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 660 | pc_factory_dependencies.call_factory = webrtc::CreateCallFactory(); |
| 661 | if (event_log_factory) { |
| 662 | event_log_factory_ = event_log_factory.get(); |
| 663 | pc_factory_dependencies.event_log_factory = std::move(event_log_factory); |
| 664 | } else { |
| 665 | pc_factory_dependencies.event_log_factory = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 666 | std::make_unique<webrtc::RtcEventLogFactory>( |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 667 | pc_factory_dependencies.task_queue_factory.get()); |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 668 | } |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 669 | if (media_transport_factory) { |
| 670 | pc_factory_dependencies.media_transport_factory = |
| 671 | std::move(media_transport_factory); |
| 672 | } |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 673 | peer_connection_factory_ = webrtc::CreateModularPeerConnectionFactory( |
| 674 | std::move(pc_factory_dependencies)); |
| 675 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 676 | if (!peer_connection_factory_) { |
| 677 | return false; |
| 678 | } |
| 679 | if (options) { |
| 680 | peer_connection_factory_->SetOptions(*options); |
| 681 | } |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 682 | if (config) { |
| 683 | sdp_semantics_ = config->sdp_semantics; |
| 684 | } |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 685 | |
| 686 | dependencies.allocator = std::move(port_allocator); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 687 | peer_connection_ = CreatePeerConnection(config, std::move(dependencies)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 688 | return peer_connection_.get() != nullptr; |
| 689 | } |
| 690 | |
| 691 | rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 692 | const PeerConnectionInterface::RTCConfiguration* config, |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 693 | webrtc::PeerConnectionDependencies dependencies) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 694 | PeerConnectionInterface::RTCConfiguration modified_config; |
| 695 | // If |config| is null, this will result in a default configuration being |
| 696 | // used. |
| 697 | if (config) { |
| 698 | modified_config = *config; |
| 699 | } |
| 700 | // Disable resolution adaptation; we don't want it interfering with the |
| 701 | // test results. |
| 702 | // TODO(deadbeef): Do something more robust. Since we're testing for aspect |
| 703 | // ratios and not specific resolutions, is this even necessary? |
| 704 | modified_config.set_cpu_adaptation(false); |
| 705 | |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 706 | dependencies.observer = this; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 707 | return peer_connection_factory_->CreatePeerConnection( |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 708 | modified_config, std::move(dependencies)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | void set_signaling_message_receiver( |
| 712 | SignalingMessageReceiver* signaling_message_receiver) { |
| 713 | signaling_message_receiver_ = signaling_message_receiver; |
| 714 | } |
| 715 | |
| 716 | void set_signaling_delay_ms(int delay_ms) { signaling_delay_ms_ = delay_ms; } |
| 717 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 718 | void set_signal_ice_candidates(bool signal) { |
| 719 | signal_ice_candidates_ = signal; |
| 720 | } |
| 721 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 722 | rtc::scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrackInternal( |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 723 | webrtc::FakePeriodicVideoSource::Config config) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 724 | // Set max frame rate to 10fps to reduce the risk of test flakiness. |
| 725 | // TODO(deadbeef): Do something more robust. |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 726 | config.frame_interval_ms = 100; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 727 | |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 728 | video_track_sources_.emplace_back( |
Niels Möller | 0f40582 | 2018-05-17 09:16:41 +0200 | [diff] [blame] | 729 | new rtc::RefCountedObject<webrtc::FakePeriodicVideoTrackSource>( |
| 730 | config, false /* remote */)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 731 | rtc::scoped_refptr<webrtc::VideoTrackInterface> track( |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 732 | peer_connection_factory_->CreateVideoTrack( |
| 733 | rtc::CreateRandomUuid(), video_track_sources_.back())); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 734 | if (!local_video_renderer_) { |
| 735 | local_video_renderer_.reset(new webrtc::FakeVideoTrackRenderer(track)); |
| 736 | } |
| 737 | return track; |
| 738 | } |
| 739 | |
| 740 | void HandleIncomingOffer(const std::string& msg) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 741 | RTC_LOG(LS_INFO) << debug_name_ << ": HandleIncomingOffer"; |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 742 | std::unique_ptr<SessionDescriptionInterface> desc = |
| 743 | webrtc::CreateSessionDescription(SdpType::kOffer, msg); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 744 | if (received_sdp_munger_) { |
| 745 | received_sdp_munger_(desc->description()); |
| 746 | } |
| 747 | |
| 748 | EXPECT_TRUE(SetRemoteDescription(std::move(desc))); |
| 749 | // Setting a remote description may have changed the number of receivers, |
| 750 | // so reset the receiver observers. |
| 751 | ResetRtpReceiverObservers(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 752 | if (remote_offer_handler_) { |
| 753 | remote_offer_handler_(); |
| 754 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 755 | auto answer = CreateAnswer(); |
| 756 | ASSERT_NE(nullptr, answer); |
| 757 | EXPECT_TRUE(SetLocalDescriptionAndSendSdpMessage(std::move(answer))); |
| 758 | } |
| 759 | |
| 760 | void HandleIncomingAnswer(const std::string& msg) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 761 | RTC_LOG(LS_INFO) << debug_name_ << ": HandleIncomingAnswer"; |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 762 | std::unique_ptr<SessionDescriptionInterface> desc = |
| 763 | webrtc::CreateSessionDescription(SdpType::kAnswer, msg); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 764 | if (received_sdp_munger_) { |
| 765 | received_sdp_munger_(desc->description()); |
| 766 | } |
| 767 | |
| 768 | EXPECT_TRUE(SetRemoteDescription(std::move(desc))); |
| 769 | // Set the RtpReceiverObserver after receivers are created. |
| 770 | ResetRtpReceiverObservers(); |
| 771 | } |
| 772 | |
| 773 | // Returns null on failure. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 774 | std::unique_ptr<SessionDescriptionInterface> CreateAnswer() { |
| 775 | rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer( |
| 776 | new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>()); |
| 777 | pc()->CreateAnswer(observer, offer_answer_options_); |
| 778 | return WaitForDescriptionFromObserver(observer); |
| 779 | } |
| 780 | |
| 781 | std::unique_ptr<SessionDescriptionInterface> WaitForDescriptionFromObserver( |
Mirko Bonadei | c61ce0d | 2017-11-21 17:04:20 +0100 | [diff] [blame] | 782 | MockCreateSessionDescriptionObserver* observer) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 783 | EXPECT_EQ_WAIT(true, observer->called(), kDefaultTimeout); |
| 784 | if (!observer->result()) { |
| 785 | return nullptr; |
| 786 | } |
| 787 | auto description = observer->MoveDescription(); |
| 788 | if (generated_sdp_munger_) { |
| 789 | generated_sdp_munger_(description->description()); |
| 790 | } |
| 791 | return description; |
| 792 | } |
| 793 | |
| 794 | // Setting the local description and sending the SDP message over the fake |
| 795 | // signaling channel are combined into the same method because the SDP |
| 796 | // message needs to be sent as soon as SetLocalDescription finishes, without |
| 797 | // waiting for the observer to be called. This ensures that ICE candidates |
| 798 | // don't outrace the description. |
| 799 | bool SetLocalDescriptionAndSendSdpMessage( |
| 800 | std::unique_ptr<SessionDescriptionInterface> desc) { |
| 801 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer( |
| 802 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 803 | RTC_LOG(LS_INFO) << debug_name_ << ": SetLocalDescriptionAndSendSdpMessage"; |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 804 | SdpType type = desc->GetType(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 805 | std::string sdp; |
| 806 | EXPECT_TRUE(desc->ToString(&sdp)); |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 807 | RTC_LOG(LS_INFO) << debug_name_ << ": local SDP contents=\n" << sdp; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 808 | pc()->SetLocalDescription(observer, desc.release()); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 809 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 810 | RemoveUnusedVideoRenderers(); |
| 811 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 812 | // As mentioned above, we need to send the message immediately after |
| 813 | // SetLocalDescription. |
| 814 | SendSdpMessage(type, sdp); |
| 815 | EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout); |
| 816 | return true; |
| 817 | } |
| 818 | |
| 819 | bool SetRemoteDescription(std::unique_ptr<SessionDescriptionInterface> desc) { |
| 820 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer( |
| 821 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 822 | RTC_LOG(LS_INFO) << debug_name_ << ": SetRemoteDescription"; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 823 | pc()->SetRemoteDescription(observer, desc.release()); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 824 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 825 | RemoveUnusedVideoRenderers(); |
| 826 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 827 | EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout); |
| 828 | return observer->result(); |
| 829 | } |
| 830 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 831 | // This is a work around to remove unused fake_video_renderers from |
| 832 | // transceivers that have either stopped or are no longer receiving. |
| 833 | void RemoveUnusedVideoRenderers() { |
| 834 | auto transceivers = pc()->GetTransceivers(); |
| 835 | for (auto& transceiver : transceivers) { |
| 836 | if (transceiver->receiver()->media_type() != cricket::MEDIA_TYPE_VIDEO) { |
| 837 | continue; |
| 838 | } |
| 839 | // Remove fake video renderers from any stopped transceivers. |
| 840 | if (transceiver->stopped()) { |
| 841 | auto it = |
| 842 | fake_video_renderers_.find(transceiver->receiver()->track()->id()); |
| 843 | if (it != fake_video_renderers_.end()) { |
| 844 | fake_video_renderers_.erase(it); |
| 845 | } |
| 846 | } |
| 847 | // Remove fake video renderers from any transceivers that are no longer |
| 848 | // receiving. |
| 849 | if ((transceiver->current_direction() && |
| 850 | !webrtc::RtpTransceiverDirectionHasRecv( |
| 851 | *transceiver->current_direction()))) { |
| 852 | auto it = |
| 853 | fake_video_renderers_.find(transceiver->receiver()->track()->id()); |
| 854 | if (it != fake_video_renderers_.end()) { |
| 855 | fake_video_renderers_.erase(it); |
| 856 | } |
| 857 | } |
| 858 | } |
| 859 | } |
| 860 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 861 | // Simulate sending a blob of SDP with delay |signaling_delay_ms_| (0 by |
| 862 | // default). |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 863 | void SendSdpMessage(SdpType type, const std::string& msg) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 864 | if (signaling_delay_ms_ == 0) { |
| 865 | RelaySdpMessageIfReceiverExists(type, msg); |
| 866 | } else { |
| 867 | invoker_.AsyncInvokeDelayed<void>( |
| 868 | RTC_FROM_HERE, rtc::Thread::Current(), |
| 869 | rtc::Bind(&PeerConnectionWrapper::RelaySdpMessageIfReceiverExists, |
| 870 | this, type, msg), |
| 871 | signaling_delay_ms_); |
| 872 | } |
| 873 | } |
| 874 | |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 875 | void RelaySdpMessageIfReceiverExists(SdpType type, const std::string& msg) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 876 | if (signaling_message_receiver_) { |
| 877 | signaling_message_receiver_->ReceiveSdpMessage(type, msg); |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | // Simulate trickling an ICE candidate with delay |signaling_delay_ms_| (0 by |
| 882 | // default). |
| 883 | void SendIceMessage(const std::string& sdp_mid, |
| 884 | int sdp_mline_index, |
| 885 | const std::string& msg) { |
| 886 | if (signaling_delay_ms_ == 0) { |
| 887 | RelayIceMessageIfReceiverExists(sdp_mid, sdp_mline_index, msg); |
| 888 | } else { |
| 889 | invoker_.AsyncInvokeDelayed<void>( |
| 890 | RTC_FROM_HERE, rtc::Thread::Current(), |
| 891 | rtc::Bind(&PeerConnectionWrapper::RelayIceMessageIfReceiverExists, |
| 892 | this, sdp_mid, sdp_mline_index, msg), |
| 893 | signaling_delay_ms_); |
| 894 | } |
| 895 | } |
| 896 | |
| 897 | void RelayIceMessageIfReceiverExists(const std::string& sdp_mid, |
| 898 | int sdp_mline_index, |
| 899 | const std::string& msg) { |
| 900 | if (signaling_message_receiver_) { |
| 901 | signaling_message_receiver_->ReceiveIceMessage(sdp_mid, sdp_mline_index, |
| 902 | msg); |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | // SignalingMessageReceiver callbacks. |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 907 | void ReceiveSdpMessage(SdpType type, const std::string& msg) override { |
| 908 | if (type == SdpType::kOffer) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 909 | HandleIncomingOffer(msg); |
| 910 | } else { |
| 911 | HandleIncomingAnswer(msg); |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | void ReceiveIceMessage(const std::string& sdp_mid, |
| 916 | int sdp_mline_index, |
| 917 | const std::string& msg) override { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 918 | RTC_LOG(LS_INFO) << debug_name_ << ": ReceiveIceMessage"; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 919 | std::unique_ptr<webrtc::IceCandidateInterface> candidate( |
| 920 | webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, msg, nullptr)); |
| 921 | EXPECT_TRUE(pc()->AddIceCandidate(candidate.get())); |
| 922 | } |
| 923 | |
| 924 | // PeerConnectionObserver callbacks. |
| 925 | void OnSignalingChange( |
| 926 | webrtc::PeerConnectionInterface::SignalingState new_state) override { |
| 927 | EXPECT_EQ(pc()->signaling_state(), new_state); |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 928 | peer_connection_signaling_state_history_.push_back(new_state); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 929 | } |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 930 | void OnAddTrack(rtc::scoped_refptr<RtpReceiverInterface> receiver, |
| 931 | const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& |
| 932 | streams) override { |
| 933 | if (receiver->media_type() == cricket::MEDIA_TYPE_VIDEO) { |
| 934 | rtc::scoped_refptr<VideoTrackInterface> video_track( |
| 935 | static_cast<VideoTrackInterface*>(receiver->track().get())); |
| 936 | ASSERT_TRUE(fake_video_renderers_.find(video_track->id()) == |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 937 | fake_video_renderers_.end()); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 938 | fake_video_renderers_[video_track->id()] = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 939 | std::make_unique<FakeVideoTrackRenderer>(video_track); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 940 | } |
| 941 | } |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 942 | void OnRemoveTrack( |
| 943 | rtc::scoped_refptr<RtpReceiverInterface> receiver) override { |
| 944 | if (receiver->media_type() == cricket::MEDIA_TYPE_VIDEO) { |
| 945 | auto it = fake_video_renderers_.find(receiver->track()->id()); |
| 946 | RTC_DCHECK(it != fake_video_renderers_.end()); |
| 947 | fake_video_renderers_.erase(it); |
| 948 | } |
| 949 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 950 | void OnRenegotiationNeeded() override {} |
| 951 | void OnIceConnectionChange( |
| 952 | webrtc::PeerConnectionInterface::IceConnectionState new_state) override { |
| 953 | EXPECT_EQ(pc()->ice_connection_state(), new_state); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 954 | ice_connection_state_history_.push_back(new_state); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 955 | } |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 956 | void OnStandardizedIceConnectionChange( |
| 957 | webrtc::PeerConnectionInterface::IceConnectionState new_state) override { |
| 958 | standardized_ice_connection_state_history_.push_back(new_state); |
| 959 | } |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 960 | void OnConnectionChange( |
| 961 | webrtc::PeerConnectionInterface::PeerConnectionState new_state) override { |
| 962 | peer_connection_state_history_.push_back(new_state); |
| 963 | } |
| 964 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 965 | void OnIceGatheringChange( |
| 966 | webrtc::PeerConnectionInterface::IceGatheringState new_state) override { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 967 | EXPECT_EQ(pc()->ice_gathering_state(), new_state); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 968 | ice_gathering_state_history_.push_back(new_state); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 969 | } |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 970 | |
| 971 | void OnIceSelectedCandidatePairChanged( |
| 972 | const cricket::CandidatePairChangeEvent& event) { |
| 973 | ice_candidate_pair_change_history_.push_back(event); |
| 974 | } |
Alex Drake | 43faee0 | 2019-08-12 16:27:34 -0700 | [diff] [blame] | 975 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 976 | void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 977 | RTC_LOG(LS_INFO) << debug_name_ << ": OnIceCandidate"; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 978 | |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 979 | if (remote_async_resolver_) { |
| 980 | const auto& local_candidate = candidate->candidate(); |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 981 | if (local_candidate.address().IsUnresolvedIP()) { |
| 982 | RTC_DCHECK(local_candidate.type() == cricket::LOCAL_PORT_TYPE); |
| 983 | rtc::SocketAddress resolved_addr(local_candidate.address()); |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 984 | const auto resolved_ip = mdns_responder_->GetMappedAddressForName( |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 985 | local_candidate.address().hostname()); |
| 986 | RTC_DCHECK(!resolved_ip.IsNil()); |
| 987 | resolved_addr.SetResolvedIP(resolved_ip); |
| 988 | EXPECT_CALL(*remote_async_resolver_, GetResolvedAddress(_, _)) |
| 989 | .WillOnce(DoAll(SetArgPointee<1>(resolved_addr), Return(true))); |
| 990 | EXPECT_CALL(*remote_async_resolver_, Destroy(_)); |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 991 | } |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 992 | } |
| 993 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 994 | std::string ice_sdp; |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 995 | EXPECT_TRUE(candidate->ToString(&ice_sdp)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 996 | if (signaling_message_receiver_ == nullptr || !signal_ice_candidates_) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 997 | // Remote party may be deleted. |
| 998 | return; |
| 999 | } |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 1000 | SendIceMessage(candidate->sdp_mid(), candidate->sdp_mline_index(), ice_sdp); |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 1001 | last_candidate_gathered_ = candidate->candidate(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1002 | } |
Eldar Rello | 0095d37 | 2019-12-02 22:22:07 +0200 | [diff] [blame] | 1003 | void OnIceCandidateError(const std::string& address, |
| 1004 | int port, |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 1005 | const std::string& url, |
| 1006 | int error_code, |
| 1007 | const std::string& error_text) override { |
Eldar Rello | 0095d37 | 2019-12-02 22:22:07 +0200 | [diff] [blame] | 1008 | error_event_ = cricket::IceCandidateErrorEvent(address, port, url, |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 1009 | error_code, error_text); |
| 1010 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1011 | void OnDataChannel( |
| 1012 | rtc::scoped_refptr<DataChannelInterface> data_channel) override { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 1013 | RTC_LOG(LS_INFO) << debug_name_ << ": OnDataChannel"; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1014 | data_channel_ = data_channel; |
| 1015 | data_observer_.reset(new MockDataChannelObserver(data_channel)); |
| 1016 | } |
| 1017 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1018 | std::string debug_name_; |
| 1019 | |
| 1020 | std::unique_ptr<rtc::FakeNetworkManager> fake_network_manager_; |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 1021 | // Reference to the mDNS responder owned by |fake_network_manager_| after set. |
| 1022 | webrtc::FakeMdnsResponder* mdns_responder_ = nullptr; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1023 | |
| 1024 | rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; |
| 1025 | rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> |
| 1026 | peer_connection_factory_; |
| 1027 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1028 | cricket::PortAllocator* port_allocator_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1029 | // Needed to keep track of number of frames sent. |
| 1030 | rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_; |
| 1031 | // Needed to keep track of number of frames received. |
| 1032 | std::map<std::string, std::unique_ptr<webrtc::FakeVideoTrackRenderer>> |
| 1033 | fake_video_renderers_; |
| 1034 | // Needed to ensure frames aren't received for removed tracks. |
| 1035 | std::vector<std::unique_ptr<webrtc::FakeVideoTrackRenderer>> |
| 1036 | removed_fake_video_renderers_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1037 | |
| 1038 | // For remote peer communication. |
| 1039 | SignalingMessageReceiver* signaling_message_receiver_ = nullptr; |
| 1040 | int signaling_delay_ms_ = 0; |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1041 | bool signal_ice_candidates_ = true; |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 1042 | cricket::Candidate last_candidate_gathered_; |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 1043 | cricket::IceCandidateErrorEvent error_event_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1044 | |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 1045 | // Store references to the video sources we've created, so that we can stop |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1046 | // them, if required. |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 1047 | std::vector<rtc::scoped_refptr<webrtc::VideoTrackSource>> |
| 1048 | video_track_sources_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1049 | // |local_video_renderer_| attached to the first created local video track. |
| 1050 | std::unique_ptr<webrtc::FakeVideoTrackRenderer> local_video_renderer_; |
| 1051 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1052 | SdpSemantics sdp_semantics_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1053 | PeerConnectionInterface::RTCOfferAnswerOptions offer_answer_options_; |
| 1054 | std::function<void(cricket::SessionDescription*)> received_sdp_munger_; |
| 1055 | std::function<void(cricket::SessionDescription*)> generated_sdp_munger_; |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1056 | std::function<void()> remote_offer_handler_; |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 1057 | rtc::MockAsyncResolver* remote_async_resolver_ = nullptr; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1058 | rtc::scoped_refptr<DataChannelInterface> data_channel_; |
| 1059 | std::unique_ptr<MockDataChannelObserver> data_observer_; |
| 1060 | |
| 1061 | std::vector<std::unique_ptr<MockRtpReceiverObserver>> rtp_receiver_observers_; |
| 1062 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1063 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 1064 | ice_connection_state_history_; |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 1065 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 1066 | standardized_ice_connection_state_history_; |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 1067 | std::vector<PeerConnectionInterface::PeerConnectionState> |
| 1068 | peer_connection_state_history_; |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1069 | std::vector<PeerConnectionInterface::IceGatheringState> |
| 1070 | ice_gathering_state_history_; |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 1071 | std::vector<cricket::CandidatePairChangeEvent> |
| 1072 | ice_candidate_pair_change_history_; |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 1073 | std::vector<PeerConnectionInterface::SignalingState> |
| 1074 | peer_connection_signaling_state_history_; |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1075 | webrtc::FakeRtcEventLogFactory* event_log_factory_; |
| 1076 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1077 | rtc::AsyncInvoker invoker_; |
| 1078 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1079 | friend class PeerConnectionIntegrationBaseTest; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1080 | }; |
| 1081 | |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 1082 | class MockRtcEventLogOutput : public webrtc::RtcEventLogOutput { |
| 1083 | public: |
| 1084 | virtual ~MockRtcEventLogOutput() = default; |
Danil Chapovalov | 3a35312 | 2020-05-15 11:16:53 +0200 | [diff] [blame] | 1085 | MOCK_METHOD(bool, IsActive, (), (const, override)); |
| 1086 | MOCK_METHOD(bool, Write, (const std::string&), (override)); |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 1087 | }; |
| 1088 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1089 | // This helper object is used for both specifying how many audio/video frames |
| 1090 | // are expected to be received for a caller/callee. It provides helper functions |
| 1091 | // to specify these expectations. The object initially starts in a state of no |
| 1092 | // expectations. |
| 1093 | class MediaExpectations { |
| 1094 | public: |
| 1095 | enum ExpectFrames { |
| 1096 | kExpectSomeFrames, |
| 1097 | kExpectNoFrames, |
| 1098 | kNoExpectation, |
| 1099 | }; |
| 1100 | |
| 1101 | void ExpectBidirectionalAudioAndVideo() { |
| 1102 | ExpectBidirectionalAudio(); |
| 1103 | ExpectBidirectionalVideo(); |
| 1104 | } |
| 1105 | |
| 1106 | void ExpectBidirectionalAudio() { |
| 1107 | CallerExpectsSomeAudio(); |
| 1108 | CalleeExpectsSomeAudio(); |
| 1109 | } |
| 1110 | |
| 1111 | void ExpectNoAudio() { |
| 1112 | CallerExpectsNoAudio(); |
| 1113 | CalleeExpectsNoAudio(); |
| 1114 | } |
| 1115 | |
| 1116 | void ExpectBidirectionalVideo() { |
| 1117 | CallerExpectsSomeVideo(); |
| 1118 | CalleeExpectsSomeVideo(); |
| 1119 | } |
| 1120 | |
| 1121 | void ExpectNoVideo() { |
| 1122 | CallerExpectsNoVideo(); |
| 1123 | CalleeExpectsNoVideo(); |
| 1124 | } |
| 1125 | |
| 1126 | void CallerExpectsSomeAudioAndVideo() { |
| 1127 | CallerExpectsSomeAudio(); |
| 1128 | CallerExpectsSomeVideo(); |
| 1129 | } |
| 1130 | |
| 1131 | void CalleeExpectsSomeAudioAndVideo() { |
| 1132 | CalleeExpectsSomeAudio(); |
| 1133 | CalleeExpectsSomeVideo(); |
| 1134 | } |
| 1135 | |
| 1136 | // Caller's audio functions. |
| 1137 | void CallerExpectsSomeAudio( |
| 1138 | int expected_audio_frames = kDefaultExpectedAudioFrameCount) { |
| 1139 | caller_audio_expectation_ = kExpectSomeFrames; |
| 1140 | caller_audio_frames_expected_ = expected_audio_frames; |
| 1141 | } |
| 1142 | |
| 1143 | void CallerExpectsNoAudio() { |
| 1144 | caller_audio_expectation_ = kExpectNoFrames; |
| 1145 | caller_audio_frames_expected_ = 0; |
| 1146 | } |
| 1147 | |
| 1148 | // Caller's video functions. |
| 1149 | void CallerExpectsSomeVideo( |
| 1150 | int expected_video_frames = kDefaultExpectedVideoFrameCount) { |
| 1151 | caller_video_expectation_ = kExpectSomeFrames; |
| 1152 | caller_video_frames_expected_ = expected_video_frames; |
| 1153 | } |
| 1154 | |
| 1155 | void CallerExpectsNoVideo() { |
| 1156 | caller_video_expectation_ = kExpectNoFrames; |
| 1157 | caller_video_frames_expected_ = 0; |
| 1158 | } |
| 1159 | |
| 1160 | // Callee's audio functions. |
| 1161 | void CalleeExpectsSomeAudio( |
| 1162 | int expected_audio_frames = kDefaultExpectedAudioFrameCount) { |
| 1163 | callee_audio_expectation_ = kExpectSomeFrames; |
| 1164 | callee_audio_frames_expected_ = expected_audio_frames; |
| 1165 | } |
| 1166 | |
| 1167 | void CalleeExpectsNoAudio() { |
| 1168 | callee_audio_expectation_ = kExpectNoFrames; |
| 1169 | callee_audio_frames_expected_ = 0; |
| 1170 | } |
| 1171 | |
| 1172 | // Callee's video functions. |
| 1173 | void CalleeExpectsSomeVideo( |
| 1174 | int expected_video_frames = kDefaultExpectedVideoFrameCount) { |
| 1175 | callee_video_expectation_ = kExpectSomeFrames; |
| 1176 | callee_video_frames_expected_ = expected_video_frames; |
| 1177 | } |
| 1178 | |
| 1179 | void CalleeExpectsNoVideo() { |
| 1180 | callee_video_expectation_ = kExpectNoFrames; |
| 1181 | callee_video_frames_expected_ = 0; |
| 1182 | } |
| 1183 | |
| 1184 | ExpectFrames caller_audio_expectation_ = kNoExpectation; |
| 1185 | ExpectFrames caller_video_expectation_ = kNoExpectation; |
| 1186 | ExpectFrames callee_audio_expectation_ = kNoExpectation; |
| 1187 | ExpectFrames callee_video_expectation_ = kNoExpectation; |
| 1188 | int caller_audio_frames_expected_ = 0; |
| 1189 | int caller_video_frames_expected_ = 0; |
| 1190 | int callee_audio_frames_expected_ = 0; |
| 1191 | int callee_video_frames_expected_ = 0; |
| 1192 | }; |
| 1193 | |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 1194 | class MockIceTransport : public webrtc::IceTransportInterface { |
| 1195 | public: |
| 1196 | MockIceTransport(const std::string& name, int component) |
| 1197 | : internal_(std::make_unique<cricket::FakeIceTransport>( |
| 1198 | name, |
| 1199 | component, |
| 1200 | nullptr /* network_thread */)) {} |
| 1201 | ~MockIceTransport() = default; |
| 1202 | cricket::IceTransportInternal* internal() { return internal_.get(); } |
| 1203 | |
| 1204 | private: |
| 1205 | std::unique_ptr<cricket::FakeIceTransport> internal_; |
| 1206 | }; |
| 1207 | |
| 1208 | class MockIceTransportFactory : public IceTransportFactory { |
| 1209 | public: |
| 1210 | ~MockIceTransportFactory() override = default; |
| 1211 | rtc::scoped_refptr<IceTransportInterface> CreateIceTransport( |
| 1212 | const std::string& transport_name, |
| 1213 | int component, |
| 1214 | IceTransportInit init) { |
| 1215 | RecordIceTransportCreated(); |
| 1216 | return new rtc::RefCountedObject<MockIceTransport>(transport_name, |
| 1217 | component); |
| 1218 | } |
Danil Chapovalov | 3a35312 | 2020-05-15 11:16:53 +0200 | [diff] [blame] | 1219 | MOCK_METHOD(void, RecordIceTransportCreated, ()); |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 1220 | }; |
| 1221 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1222 | // Tests two PeerConnections connecting to each other end-to-end, using a |
| 1223 | // virtual network, fake A/V capture and fake encoder/decoders. The |
| 1224 | // PeerConnections share the threads/socket servers, but use separate versions |
| 1225 | // of everything else (including "PeerConnectionFactory"s). |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 1226 | class PeerConnectionIntegrationBaseTest : public ::testing::Test { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1227 | public: |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1228 | explicit PeerConnectionIntegrationBaseTest(SdpSemantics sdp_semantics) |
| 1229 | : sdp_semantics_(sdp_semantics), |
| 1230 | ss_(new rtc::VirtualSocketServer()), |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1231 | fss_(new rtc::FirewallSocketServer(ss_.get())), |
| 1232 | network_thread_(new rtc::Thread(fss_.get())), |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1233 | worker_thread_(rtc::Thread::Create()), |
| 1234 | loopback_media_transports_(network_thread_.get()) { |
Sebastian Jansson | 8a793a0 | 2018-03-13 15:21:48 +0100 | [diff] [blame] | 1235 | network_thread_->SetName("PCNetworkThread", this); |
| 1236 | worker_thread_->SetName("PCWorkerThread", this); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1237 | RTC_CHECK(network_thread_->Start()); |
| 1238 | RTC_CHECK(worker_thread_->Start()); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1239 | webrtc::metrics::Reset(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1240 | } |
| 1241 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1242 | ~PeerConnectionIntegrationBaseTest() { |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1243 | // The PeerConnections should deleted before the TurnCustomizers. |
| 1244 | // A TurnPort is created with a raw pointer to a TurnCustomizer. The |
| 1245 | // TurnPort has the same lifetime as the PeerConnection, so it's expected |
| 1246 | // that the TurnCustomizer outlives the life of the PeerConnection or else |
| 1247 | // when Send() is called it will hit a seg fault. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1248 | if (caller_) { |
| 1249 | caller_->set_signaling_message_receiver(nullptr); |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1250 | delete SetCallerPcWrapperAndReturnCurrent(nullptr); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1251 | } |
| 1252 | if (callee_) { |
| 1253 | callee_->set_signaling_message_receiver(nullptr); |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1254 | delete SetCalleePcWrapperAndReturnCurrent(nullptr); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1255 | } |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1256 | |
| 1257 | // If turn servers were created for the test they need to be destroyed on |
| 1258 | // the network thread. |
| 1259 | network_thread()->Invoke<void>(RTC_FROM_HERE, [this] { |
| 1260 | turn_servers_.clear(); |
| 1261 | turn_customizers_.clear(); |
| 1262 | }); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | bool SignalingStateStable() { |
| 1266 | return caller_->SignalingStateStable() && callee_->SignalingStateStable(); |
| 1267 | } |
| 1268 | |
deadbeef | 7145280 | 2017-05-07 17:21:01 -0700 | [diff] [blame] | 1269 | bool DtlsConnected() { |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 1270 | // TODO(deadbeef): kIceConnectionConnected currently means both ICE and DTLS |
| 1271 | // are connected. This is an important distinction. Once we have separate |
| 1272 | // ICE and DTLS state, this check needs to use the DTLS state. |
| 1273 | return (callee()->ice_connection_state() == |
| 1274 | webrtc::PeerConnectionInterface::kIceConnectionConnected || |
| 1275 | callee()->ice_connection_state() == |
| 1276 | webrtc::PeerConnectionInterface::kIceConnectionCompleted) && |
| 1277 | (caller()->ice_connection_state() == |
| 1278 | webrtc::PeerConnectionInterface::kIceConnectionConnected || |
| 1279 | caller()->ice_connection_state() == |
| 1280 | webrtc::PeerConnectionInterface::kIceConnectionCompleted); |
deadbeef | 7145280 | 2017-05-07 17:21:01 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1283 | // When |event_log_factory| is null, the default implementation of the event |
| 1284 | // log factory will be used. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1285 | std::unique_ptr<PeerConnectionWrapper> CreatePeerConnectionWrapper( |
| 1286 | const std::string& debug_name, |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1287 | const PeerConnectionFactory::Options* options, |
| 1288 | const RTCConfiguration* config, |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1289 | webrtc::PeerConnectionDependencies dependencies, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1290 | std::unique_ptr<webrtc::FakeRtcEventLogFactory> event_log_factory, |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 1291 | std::unique_ptr<webrtc::MediaTransportFactory> media_transport_factory, |
| 1292 | bool reset_encoder_factory, |
| 1293 | bool reset_decoder_factory) { |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1294 | RTCConfiguration modified_config; |
| 1295 | if (config) { |
| 1296 | modified_config = *config; |
| 1297 | } |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 1298 | modified_config.sdp_semantics = sdp_semantics_; |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1299 | if (!dependencies.cert_generator) { |
| 1300 | dependencies.cert_generator = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1301 | std::make_unique<FakeRTCCertificateGenerator>(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1302 | } |
| 1303 | std::unique_ptr<PeerConnectionWrapper> client( |
| 1304 | new PeerConnectionWrapper(debug_name)); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1305 | |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1306 | if (!client->Init(options, &modified_config, std::move(dependencies), |
| 1307 | network_thread_.get(), worker_thread_.get(), |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1308 | std::move(event_log_factory), |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 1309 | std::move(media_transport_factory), reset_encoder_factory, |
| 1310 | reset_decoder_factory)) { |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1311 | return nullptr; |
| 1312 | } |
| 1313 | return client; |
| 1314 | } |
| 1315 | |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1316 | std::unique_ptr<PeerConnectionWrapper> |
| 1317 | CreatePeerConnectionWrapperWithFakeRtcEventLog( |
| 1318 | const std::string& debug_name, |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1319 | const PeerConnectionFactory::Options* options, |
| 1320 | const RTCConfiguration* config, |
| 1321 | webrtc::PeerConnectionDependencies dependencies) { |
| 1322 | std::unique_ptr<webrtc::FakeRtcEventLogFactory> event_log_factory( |
| 1323 | new webrtc::FakeRtcEventLogFactory(rtc::Thread::Current())); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 1324 | return CreatePeerConnectionWrapper( |
| 1325 | debug_name, options, config, std::move(dependencies), |
| 1326 | std::move(event_log_factory), |
| 1327 | /*media_transport_factory=*/nullptr, /*reset_encoder_factory=*/false, |
| 1328 | /*reset_decoder_factory=*/false); |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1331 | bool CreatePeerConnectionWrappers() { |
| 1332 | return CreatePeerConnectionWrappersWithConfig( |
| 1333 | PeerConnectionInterface::RTCConfiguration(), |
| 1334 | PeerConnectionInterface::RTCConfiguration()); |
| 1335 | } |
| 1336 | |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 1337 | bool CreatePeerConnectionWrappersWithSdpSemantics( |
| 1338 | SdpSemantics caller_semantics, |
| 1339 | SdpSemantics callee_semantics) { |
| 1340 | // Can't specify the sdp_semantics in the passed-in configuration since it |
| 1341 | // will be overwritten by CreatePeerConnectionWrapper with whatever is |
| 1342 | // stored in sdp_semantics_. So get around this by modifying the instance |
| 1343 | // variable before calling CreatePeerConnectionWrapper for the caller and |
| 1344 | // callee PeerConnections. |
| 1345 | SdpSemantics original_semantics = sdp_semantics_; |
| 1346 | sdp_semantics_ = caller_semantics; |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1347 | caller_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1348 | "Caller", nullptr, nullptr, webrtc::PeerConnectionDependencies(nullptr), |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 1349 | nullptr, /*media_transport_factory=*/nullptr, |
| 1350 | /*reset_encoder_factory=*/false, |
| 1351 | /*reset_decoder_factory=*/false); |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 1352 | sdp_semantics_ = callee_semantics; |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1353 | callee_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1354 | "Callee", nullptr, nullptr, webrtc::PeerConnectionDependencies(nullptr), |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 1355 | nullptr, /*media_transport_factory=*/nullptr, |
| 1356 | /*reset_encoder_factory=*/false, |
| 1357 | /*reset_decoder_factory=*/false); |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 1358 | sdp_semantics_ = original_semantics; |
| 1359 | return caller_ && callee_; |
| 1360 | } |
| 1361 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1362 | bool CreatePeerConnectionWrappersWithConfig( |
| 1363 | const PeerConnectionInterface::RTCConfiguration& caller_config, |
| 1364 | const PeerConnectionInterface::RTCConfiguration& callee_config) { |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1365 | caller_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1366 | "Caller", nullptr, &caller_config, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1367 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 1368 | /*media_transport_factory=*/nullptr, /*reset_encoder_factory=*/false, |
| 1369 | /*reset_decoder_factory=*/false); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1370 | callee_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1371 | "Callee", nullptr, &callee_config, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1372 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 1373 | /*media_transport_factory=*/nullptr, /*reset_encoder_factory=*/false, |
| 1374 | /*reset_decoder_factory=*/false); |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1375 | return caller_ && callee_; |
| 1376 | } |
| 1377 | |
| 1378 | bool CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 1379 | const PeerConnectionInterface::RTCConfiguration& caller_config, |
| 1380 | const PeerConnectionInterface::RTCConfiguration& callee_config, |
| 1381 | std::unique_ptr<webrtc::MediaTransportFactory> caller_factory, |
| 1382 | std::unique_ptr<webrtc::MediaTransportFactory> callee_factory) { |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 1383 | caller_ = CreatePeerConnectionWrapper( |
| 1384 | "Caller", nullptr, &caller_config, |
| 1385 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
| 1386 | std::move(caller_factory), /*reset_encoder_factory=*/false, |
| 1387 | /*reset_decoder_factory=*/false); |
| 1388 | callee_ = CreatePeerConnectionWrapper( |
| 1389 | "Callee", nullptr, &callee_config, |
| 1390 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
| 1391 | std::move(callee_factory), /*reset_encoder_factory=*/false, |
| 1392 | /*reset_decoder_factory=*/false); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1393 | return caller_ && callee_; |
| 1394 | } |
| 1395 | |
| 1396 | bool CreatePeerConnectionWrappersWithConfigAndDeps( |
| 1397 | const PeerConnectionInterface::RTCConfiguration& caller_config, |
| 1398 | webrtc::PeerConnectionDependencies caller_dependencies, |
| 1399 | const PeerConnectionInterface::RTCConfiguration& callee_config, |
| 1400 | webrtc::PeerConnectionDependencies callee_dependencies) { |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 1401 | caller_ = CreatePeerConnectionWrapper( |
| 1402 | "Caller", nullptr, &caller_config, std::move(caller_dependencies), |
| 1403 | nullptr, |
| 1404 | /*media_transport_factory=*/nullptr, /*reset_encoder_factory=*/false, |
| 1405 | /*reset_decoder_factory=*/false); |
| 1406 | callee_ = CreatePeerConnectionWrapper( |
| 1407 | "Callee", nullptr, &callee_config, std::move(callee_dependencies), |
| 1408 | nullptr, |
| 1409 | /*media_transport_factory=*/nullptr, /*reset_encoder_factory=*/false, |
| 1410 | /*reset_decoder_factory=*/false); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1411 | return caller_ && callee_; |
| 1412 | } |
| 1413 | |
| 1414 | bool CreatePeerConnectionWrappersWithOptions( |
| 1415 | const PeerConnectionFactory::Options& caller_options, |
| 1416 | const PeerConnectionFactory::Options& callee_options) { |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1417 | caller_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1418 | "Caller", &caller_options, nullptr, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1419 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 1420 | /*media_transport_factory=*/nullptr, /*reset_encoder_factory=*/false, |
| 1421 | /*reset_decoder_factory=*/false); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1422 | callee_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1423 | "Callee", &callee_options, nullptr, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1424 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 1425 | /*media_transport_factory=*/nullptr, /*reset_encoder_factory=*/false, |
| 1426 | /*reset_decoder_factory=*/false); |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1427 | return caller_ && callee_; |
| 1428 | } |
| 1429 | |
| 1430 | bool CreatePeerConnectionWrappersWithFakeRtcEventLog() { |
| 1431 | PeerConnectionInterface::RTCConfiguration default_config; |
| 1432 | caller_ = CreatePeerConnectionWrapperWithFakeRtcEventLog( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1433 | "Caller", nullptr, &default_config, |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1434 | webrtc::PeerConnectionDependencies(nullptr)); |
| 1435 | callee_ = CreatePeerConnectionWrapperWithFakeRtcEventLog( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1436 | "Callee", nullptr, &default_config, |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1437 | webrtc::PeerConnectionDependencies(nullptr)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1438 | return caller_ && callee_; |
| 1439 | } |
| 1440 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1441 | std::unique_ptr<PeerConnectionWrapper> |
| 1442 | CreatePeerConnectionWrapperWithAlternateKey() { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1443 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 1444 | new FakeRTCCertificateGenerator()); |
| 1445 | cert_generator->use_alternate_key(); |
| 1446 | |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1447 | webrtc::PeerConnectionDependencies dependencies(nullptr); |
| 1448 | dependencies.cert_generator = std::move(cert_generator); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 1449 | return CreatePeerConnectionWrapper( |
| 1450 | "New Peer", nullptr, nullptr, std::move(dependencies), nullptr, |
| 1451 | /*media_transport_factory=*/nullptr, /*reset_encoder_factory=*/false, |
| 1452 | /*reset_decoder_factory=*/false); |
| 1453 | } |
| 1454 | |
| 1455 | bool CreateOneDirectionalPeerConnectionWrappers(bool caller_to_callee) { |
| 1456 | caller_ = CreatePeerConnectionWrapper( |
| 1457 | "Caller", nullptr, nullptr, webrtc::PeerConnectionDependencies(nullptr), |
| 1458 | nullptr, /*media_transport_factory=*/nullptr, |
| 1459 | /*reset_encoder_factory=*/!caller_to_callee, |
| 1460 | /*reset_decoder_factory=*/caller_to_callee); |
| 1461 | callee_ = CreatePeerConnectionWrapper( |
| 1462 | "Callee", nullptr, nullptr, webrtc::PeerConnectionDependencies(nullptr), |
| 1463 | nullptr, /*media_transport_factory=*/nullptr, |
| 1464 | /*reset_encoder_factory=*/caller_to_callee, |
| 1465 | /*reset_decoder_factory=*/!caller_to_callee); |
| 1466 | return caller_ && callee_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1469 | cricket::TestTurnServer* CreateTurnServer( |
| 1470 | rtc::SocketAddress internal_address, |
| 1471 | rtc::SocketAddress external_address, |
| 1472 | cricket::ProtocolType type = cricket::ProtocolType::PROTO_UDP, |
| 1473 | const std::string& common_name = "test turn server") { |
| 1474 | rtc::Thread* thread = network_thread(); |
| 1475 | std::unique_ptr<cricket::TestTurnServer> turn_server = |
| 1476 | network_thread()->Invoke<std::unique_ptr<cricket::TestTurnServer>>( |
| 1477 | RTC_FROM_HERE, |
| 1478 | [thread, internal_address, external_address, type, common_name] { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1479 | return std::make_unique<cricket::TestTurnServer>( |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1480 | thread, internal_address, external_address, type, |
| 1481 | /*ignore_bad_certs=*/true, common_name); |
| 1482 | }); |
| 1483 | turn_servers_.push_back(std::move(turn_server)); |
| 1484 | // Interactions with the turn server should be done on the network thread. |
| 1485 | return turn_servers_.back().get(); |
| 1486 | } |
| 1487 | |
| 1488 | cricket::TestTurnCustomizer* CreateTurnCustomizer() { |
| 1489 | std::unique_ptr<cricket::TestTurnCustomizer> turn_customizer = |
| 1490 | network_thread()->Invoke<std::unique_ptr<cricket::TestTurnCustomizer>>( |
| 1491 | RTC_FROM_HERE, |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1492 | [] { return std::make_unique<cricket::TestTurnCustomizer>(); }); |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1493 | turn_customizers_.push_back(std::move(turn_customizer)); |
| 1494 | // Interactions with the turn customizer should be done on the network |
| 1495 | // thread. |
| 1496 | return turn_customizers_.back().get(); |
| 1497 | } |
| 1498 | |
| 1499 | // Checks that the function counters for a TestTurnCustomizer are greater than |
| 1500 | // 0. |
| 1501 | void ExpectTurnCustomizerCountersIncremented( |
| 1502 | cricket::TestTurnCustomizer* turn_customizer) { |
| 1503 | unsigned int allow_channel_data_counter = |
| 1504 | network_thread()->Invoke<unsigned int>( |
| 1505 | RTC_FROM_HERE, [turn_customizer] { |
| 1506 | return turn_customizer->allow_channel_data_cnt_; |
| 1507 | }); |
| 1508 | EXPECT_GT(allow_channel_data_counter, 0u); |
| 1509 | unsigned int modify_counter = network_thread()->Invoke<unsigned int>( |
| 1510 | RTC_FROM_HERE, |
| 1511 | [turn_customizer] { return turn_customizer->modify_cnt_; }); |
| 1512 | EXPECT_GT(modify_counter, 0u); |
| 1513 | } |
| 1514 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1515 | // Once called, SDP blobs and ICE candidates will be automatically signaled |
| 1516 | // between PeerConnections. |
| 1517 | void ConnectFakeSignaling() { |
| 1518 | caller_->set_signaling_message_receiver(callee_.get()); |
| 1519 | callee_->set_signaling_message_receiver(caller_.get()); |
| 1520 | } |
| 1521 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1522 | // Once called, SDP blobs will be automatically signaled between |
| 1523 | // PeerConnections. Note that ICE candidates will not be signaled unless they |
| 1524 | // are in the exchanged SDP blobs. |
| 1525 | void ConnectFakeSignalingForSdpOnly() { |
| 1526 | ConnectFakeSignaling(); |
| 1527 | SetSignalIceCandidates(false); |
| 1528 | } |
| 1529 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1530 | void SetSignalingDelayMs(int delay_ms) { |
| 1531 | caller_->set_signaling_delay_ms(delay_ms); |
| 1532 | callee_->set_signaling_delay_ms(delay_ms); |
| 1533 | } |
| 1534 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1535 | void SetSignalIceCandidates(bool signal) { |
| 1536 | caller_->set_signal_ice_candidates(signal); |
| 1537 | callee_->set_signal_ice_candidates(signal); |
| 1538 | } |
| 1539 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1540 | // Messages may get lost on the unreliable DataChannel, so we send multiple |
| 1541 | // times to avoid test flakiness. |
| 1542 | void SendRtpDataWithRetries(webrtc::DataChannelInterface* dc, |
| 1543 | const std::string& data, |
| 1544 | int retries) { |
| 1545 | for (int i = 0; i < retries; ++i) { |
| 1546 | dc->Send(DataBuffer(data)); |
| 1547 | } |
| 1548 | } |
| 1549 | |
| 1550 | rtc::Thread* network_thread() { return network_thread_.get(); } |
| 1551 | |
| 1552 | rtc::VirtualSocketServer* virtual_socket_server() { return ss_.get(); } |
| 1553 | |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1554 | webrtc::MediaTransportPair* loopback_media_transports() { |
| 1555 | return &loopback_media_transports_; |
| 1556 | } |
| 1557 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1558 | PeerConnectionWrapper* caller() { return caller_.get(); } |
| 1559 | |
| 1560 | // Set the |caller_| to the |wrapper| passed in and return the |
| 1561 | // original |caller_|. |
| 1562 | PeerConnectionWrapper* SetCallerPcWrapperAndReturnCurrent( |
| 1563 | PeerConnectionWrapper* wrapper) { |
| 1564 | PeerConnectionWrapper* old = caller_.release(); |
| 1565 | caller_.reset(wrapper); |
| 1566 | return old; |
| 1567 | } |
| 1568 | |
| 1569 | PeerConnectionWrapper* callee() { return callee_.get(); } |
| 1570 | |
| 1571 | // Set the |callee_| to the |wrapper| passed in and return the |
| 1572 | // original |callee_|. |
| 1573 | PeerConnectionWrapper* SetCalleePcWrapperAndReturnCurrent( |
| 1574 | PeerConnectionWrapper* wrapper) { |
| 1575 | PeerConnectionWrapper* old = callee_.release(); |
| 1576 | callee_.reset(wrapper); |
| 1577 | return old; |
| 1578 | } |
| 1579 | |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 1580 | void SetPortAllocatorFlags(uint32_t caller_flags, uint32_t callee_flags) { |
| 1581 | network_thread()->Invoke<void>( |
| 1582 | RTC_FROM_HERE, rtc::Bind(&cricket::PortAllocator::set_flags, |
| 1583 | caller()->port_allocator(), caller_flags)); |
| 1584 | network_thread()->Invoke<void>( |
| 1585 | RTC_FROM_HERE, rtc::Bind(&cricket::PortAllocator::set_flags, |
| 1586 | callee()->port_allocator(), callee_flags)); |
| 1587 | } |
| 1588 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1589 | rtc::FirewallSocketServer* firewall() const { return fss_.get(); } |
| 1590 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1591 | // Expects the provided number of new frames to be received within |
| 1592 | // kMaxWaitForFramesMs. The new expected frames are specified in |
| 1593 | // |media_expectations|. Returns false if any of the expectations were |
| 1594 | // not met. |
| 1595 | bool ExpectNewFrames(const MediaExpectations& media_expectations) { |
| 1596 | // First initialize the expected frame counts based upon the current |
| 1597 | // frame count. |
| 1598 | int total_caller_audio_frames_expected = caller()->audio_frames_received(); |
| 1599 | if (media_expectations.caller_audio_expectation_ == |
| 1600 | MediaExpectations::kExpectSomeFrames) { |
| 1601 | total_caller_audio_frames_expected += |
| 1602 | media_expectations.caller_audio_frames_expected_; |
| 1603 | } |
| 1604 | int total_caller_video_frames_expected = |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1605 | caller()->min_video_frames_received_per_track(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1606 | if (media_expectations.caller_video_expectation_ == |
| 1607 | MediaExpectations::kExpectSomeFrames) { |
| 1608 | total_caller_video_frames_expected += |
| 1609 | media_expectations.caller_video_frames_expected_; |
| 1610 | } |
| 1611 | int total_callee_audio_frames_expected = callee()->audio_frames_received(); |
| 1612 | if (media_expectations.callee_audio_expectation_ == |
| 1613 | MediaExpectations::kExpectSomeFrames) { |
| 1614 | total_callee_audio_frames_expected += |
| 1615 | media_expectations.callee_audio_frames_expected_; |
| 1616 | } |
| 1617 | int total_callee_video_frames_expected = |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1618 | callee()->min_video_frames_received_per_track(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1619 | if (media_expectations.callee_video_expectation_ == |
| 1620 | MediaExpectations::kExpectSomeFrames) { |
| 1621 | total_callee_video_frames_expected += |
| 1622 | media_expectations.callee_video_frames_expected_; |
| 1623 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1624 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1625 | // Wait for the expected frames. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1626 | EXPECT_TRUE_WAIT(caller()->audio_frames_received() >= |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1627 | total_caller_audio_frames_expected && |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1628 | caller()->min_video_frames_received_per_track() >= |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1629 | total_caller_video_frames_expected && |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1630 | callee()->audio_frames_received() >= |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1631 | total_callee_audio_frames_expected && |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1632 | callee()->min_video_frames_received_per_track() >= |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1633 | total_callee_video_frames_expected, |
| 1634 | kMaxWaitForFramesMs); |
| 1635 | bool expectations_correct = |
| 1636 | caller()->audio_frames_received() >= |
| 1637 | total_caller_audio_frames_expected && |
| 1638 | caller()->min_video_frames_received_per_track() >= |
| 1639 | total_caller_video_frames_expected && |
| 1640 | callee()->audio_frames_received() >= |
| 1641 | total_callee_audio_frames_expected && |
| 1642 | callee()->min_video_frames_received_per_track() >= |
| 1643 | total_callee_video_frames_expected; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1644 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1645 | // After the combined wait, print out a more detailed message upon |
| 1646 | // failure. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1647 | EXPECT_GE(caller()->audio_frames_received(), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1648 | total_caller_audio_frames_expected); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1649 | EXPECT_GE(caller()->min_video_frames_received_per_track(), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1650 | total_caller_video_frames_expected); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1651 | EXPECT_GE(callee()->audio_frames_received(), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1652 | total_callee_audio_frames_expected); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1653 | EXPECT_GE(callee()->min_video_frames_received_per_track(), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1654 | total_callee_video_frames_expected); |
| 1655 | |
| 1656 | // We want to make sure nothing unexpected was received. |
| 1657 | if (media_expectations.caller_audio_expectation_ == |
| 1658 | MediaExpectations::kExpectNoFrames) { |
| 1659 | EXPECT_EQ(caller()->audio_frames_received(), |
| 1660 | total_caller_audio_frames_expected); |
| 1661 | if (caller()->audio_frames_received() != |
| 1662 | total_caller_audio_frames_expected) { |
| 1663 | expectations_correct = false; |
| 1664 | } |
| 1665 | } |
| 1666 | if (media_expectations.caller_video_expectation_ == |
| 1667 | MediaExpectations::kExpectNoFrames) { |
| 1668 | EXPECT_EQ(caller()->min_video_frames_received_per_track(), |
| 1669 | total_caller_video_frames_expected); |
| 1670 | if (caller()->min_video_frames_received_per_track() != |
| 1671 | total_caller_video_frames_expected) { |
| 1672 | expectations_correct = false; |
| 1673 | } |
| 1674 | } |
| 1675 | if (media_expectations.callee_audio_expectation_ == |
| 1676 | MediaExpectations::kExpectNoFrames) { |
| 1677 | EXPECT_EQ(callee()->audio_frames_received(), |
| 1678 | total_callee_audio_frames_expected); |
| 1679 | if (callee()->audio_frames_received() != |
| 1680 | total_callee_audio_frames_expected) { |
| 1681 | expectations_correct = false; |
| 1682 | } |
| 1683 | } |
| 1684 | if (media_expectations.callee_video_expectation_ == |
| 1685 | MediaExpectations::kExpectNoFrames) { |
| 1686 | EXPECT_EQ(callee()->min_video_frames_received_per_track(), |
| 1687 | total_callee_video_frames_expected); |
| 1688 | if (callee()->min_video_frames_received_per_track() != |
| 1689 | total_callee_video_frames_expected) { |
| 1690 | expectations_correct = false; |
| 1691 | } |
| 1692 | } |
| 1693 | return expectations_correct; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1694 | } |
| 1695 | |
Steve Anton | d91969e | 2019-05-30 12:27:03 -0700 | [diff] [blame] | 1696 | void ClosePeerConnections() { |
| 1697 | caller()->pc()->Close(); |
| 1698 | callee()->pc()->Close(); |
| 1699 | } |
| 1700 | |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1701 | void TestNegotiatedCipherSuite( |
| 1702 | const PeerConnectionFactory::Options& caller_options, |
| 1703 | const PeerConnectionFactory::Options& callee_options, |
| 1704 | int expected_cipher_suite) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1705 | ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(caller_options, |
| 1706 | callee_options)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1707 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1708 | caller()->AddAudioVideoTracks(); |
| 1709 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1710 | caller()->CreateAndSetAndSignalOffer(); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1711 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1712 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(expected_cipher_suite), |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 1713 | caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1714 | // TODO(bugs.webrtc.org/9456): Fix it. |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 1715 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents( |
| 1716 | "WebRTC.PeerConnection.SrtpCryptoSuite.Audio", |
| 1717 | expected_cipher_suite)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1718 | } |
| 1719 | |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1720 | void TestGcmNegotiationUsesCipherSuite(bool local_gcm_enabled, |
| 1721 | bool remote_gcm_enabled, |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 1722 | bool aes_ctr_enabled, |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1723 | int expected_cipher_suite) { |
| 1724 | PeerConnectionFactory::Options caller_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1725 | caller_options.crypto_options.srtp.enable_gcm_crypto_suites = |
| 1726 | local_gcm_enabled; |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 1727 | caller_options.crypto_options.srtp.enable_aes128_sha1_80_crypto_cipher = |
| 1728 | aes_ctr_enabled; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1729 | PeerConnectionFactory::Options callee_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1730 | callee_options.crypto_options.srtp.enable_gcm_crypto_suites = |
| 1731 | remote_gcm_enabled; |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 1732 | callee_options.crypto_options.srtp.enable_aes128_sha1_80_crypto_cipher = |
| 1733 | aes_ctr_enabled; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1734 | TestNegotiatedCipherSuite(caller_options, callee_options, |
| 1735 | expected_cipher_suite); |
| 1736 | } |
| 1737 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1738 | protected: |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 1739 | SdpSemantics sdp_semantics_; |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1740 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1741 | private: |
| 1742 | // |ss_| is used by |network_thread_| so it must be destroyed later. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1743 | std::unique_ptr<rtc::VirtualSocketServer> ss_; |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1744 | std::unique_ptr<rtc::FirewallSocketServer> fss_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1745 | // |network_thread_| and |worker_thread_| are used by both |
| 1746 | // |caller_| and |callee_| so they must be destroyed |
| 1747 | // later. |
| 1748 | std::unique_ptr<rtc::Thread> network_thread_; |
| 1749 | std::unique_ptr<rtc::Thread> worker_thread_; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1750 | // The turn servers and turn customizers should be accessed & deleted on the |
| 1751 | // network thread to avoid a race with the socket read/write that occurs |
| 1752 | // on the network thread. |
| 1753 | std::vector<std::unique_ptr<cricket::TestTurnServer>> turn_servers_; |
| 1754 | std::vector<std::unique_ptr<cricket::TestTurnCustomizer>> turn_customizers_; |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1755 | webrtc::MediaTransportPair loopback_media_transports_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1756 | std::unique_ptr<PeerConnectionWrapper> caller_; |
| 1757 | std::unique_ptr<PeerConnectionWrapper> callee_; |
| 1758 | }; |
| 1759 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1760 | class PeerConnectionIntegrationTest |
| 1761 | : public PeerConnectionIntegrationBaseTest, |
| 1762 | public ::testing::WithParamInterface<SdpSemantics> { |
| 1763 | protected: |
| 1764 | PeerConnectionIntegrationTest() |
| 1765 | : PeerConnectionIntegrationBaseTest(GetParam()) {} |
| 1766 | }; |
| 1767 | |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 1768 | // Fake clock must be set before threads are started to prevent race on |
| 1769 | // Set/GetClockForTesting(). |
| 1770 | // To achieve that, multiple inheritance is used as a mixin pattern |
| 1771 | // where order of construction is finely controlled. |
| 1772 | // This also ensures peerconnection is closed before switching back to non-fake |
| 1773 | // clock, avoiding other races and DCHECK failures such as in rtp_sender.cc. |
| 1774 | class FakeClockForTest : public rtc::ScopedFakeClock { |
| 1775 | protected: |
| 1776 | FakeClockForTest() { |
| 1777 | // Some things use a time of "0" as a special value, so we need to start out |
| 1778 | // the fake clock at a nonzero time. |
| 1779 | // TODO(deadbeef): Fix this. |
Danil Chapovalov | 0c626af | 2020-02-10 11:16:00 +0100 | [diff] [blame] | 1780 | AdvanceTime(webrtc::TimeDelta::Seconds(1)); |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | // Explicit handle. |
| 1784 | ScopedFakeClock& FakeClock() { return *this; } |
| 1785 | }; |
| 1786 | |
| 1787 | // Ensure FakeClockForTest is constructed first (see class for rationale). |
| 1788 | class PeerConnectionIntegrationTestWithFakeClock |
| 1789 | : public FakeClockForTest, |
| 1790 | public PeerConnectionIntegrationTest {}; |
| 1791 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1792 | class PeerConnectionIntegrationTestPlanB |
| 1793 | : public PeerConnectionIntegrationBaseTest { |
| 1794 | protected: |
| 1795 | PeerConnectionIntegrationTestPlanB() |
| 1796 | : PeerConnectionIntegrationBaseTest(SdpSemantics::kPlanB) {} |
| 1797 | }; |
| 1798 | |
| 1799 | class PeerConnectionIntegrationTestUnifiedPlan |
| 1800 | : public PeerConnectionIntegrationBaseTest { |
| 1801 | protected: |
| 1802 | PeerConnectionIntegrationTestUnifiedPlan() |
| 1803 | : PeerConnectionIntegrationBaseTest(SdpSemantics::kUnifiedPlan) {} |
| 1804 | }; |
| 1805 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1806 | // Test the OnFirstPacketReceived callback from audio/video RtpReceivers. This |
| 1807 | // includes testing that the callback is invoked if an observer is connected |
| 1808 | // after the first packet has already been received. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1809 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1810 | RtpReceiverObserverOnFirstPacketReceived) { |
| 1811 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1812 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1813 | caller()->AddAudioVideoTracks(); |
| 1814 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1815 | // Start offer/answer exchange and wait for it to complete. |
| 1816 | caller()->CreateAndSetAndSignalOffer(); |
| 1817 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1818 | // Should be one receiver each for audio/video. |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 1819 | EXPECT_EQ(2U, caller()->rtp_receiver_observers().size()); |
| 1820 | EXPECT_EQ(2U, callee()->rtp_receiver_observers().size()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1821 | // Wait for all "first packet received" callbacks to be fired. |
| 1822 | EXPECT_TRUE_WAIT( |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 1823 | absl::c_all_of(caller()->rtp_receiver_observers(), |
| 1824 | [](const std::unique_ptr<MockRtpReceiverObserver>& o) { |
| 1825 | return o->first_packet_received(); |
| 1826 | }), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1827 | kMaxWaitForFramesMs); |
| 1828 | EXPECT_TRUE_WAIT( |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 1829 | absl::c_all_of(callee()->rtp_receiver_observers(), |
| 1830 | [](const std::unique_ptr<MockRtpReceiverObserver>& o) { |
| 1831 | return o->first_packet_received(); |
| 1832 | }), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1833 | kMaxWaitForFramesMs); |
| 1834 | // If new observers are set after the first packet was already received, the |
| 1835 | // callback should still be invoked. |
| 1836 | caller()->ResetRtpReceiverObservers(); |
| 1837 | callee()->ResetRtpReceiverObservers(); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 1838 | EXPECT_EQ(2U, caller()->rtp_receiver_observers().size()); |
| 1839 | EXPECT_EQ(2U, callee()->rtp_receiver_observers().size()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1840 | EXPECT_TRUE( |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 1841 | absl::c_all_of(caller()->rtp_receiver_observers(), |
| 1842 | [](const std::unique_ptr<MockRtpReceiverObserver>& o) { |
| 1843 | return o->first_packet_received(); |
| 1844 | })); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1845 | EXPECT_TRUE( |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 1846 | absl::c_all_of(callee()->rtp_receiver_observers(), |
| 1847 | [](const std::unique_ptr<MockRtpReceiverObserver>& o) { |
| 1848 | return o->first_packet_received(); |
| 1849 | })); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | class DummyDtmfObserver : public DtmfSenderObserverInterface { |
| 1853 | public: |
| 1854 | DummyDtmfObserver() : completed_(false) {} |
| 1855 | |
| 1856 | // Implements DtmfSenderObserverInterface. |
| 1857 | void OnToneChange(const std::string& tone) override { |
| 1858 | tones_.push_back(tone); |
| 1859 | if (tone.empty()) { |
| 1860 | completed_ = true; |
| 1861 | } |
| 1862 | } |
| 1863 | |
| 1864 | const std::vector<std::string>& tones() const { return tones_; } |
| 1865 | bool completed() const { return completed_; } |
| 1866 | |
| 1867 | private: |
| 1868 | bool completed_; |
| 1869 | std::vector<std::string> tones_; |
| 1870 | }; |
| 1871 | |
| 1872 | // Assumes |sender| already has an audio track added and the offer/answer |
| 1873 | // exchange is done. |
| 1874 | void TestDtmfFromSenderToReceiver(PeerConnectionWrapper* sender, |
| 1875 | PeerConnectionWrapper* receiver) { |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1876 | // We should be able to get a DTMF sender from the local sender. |
| 1877 | rtc::scoped_refptr<DtmfSenderInterface> dtmf_sender = |
| 1878 | sender->pc()->GetSenders().at(0)->GetDtmfSender(); |
| 1879 | ASSERT_TRUE(dtmf_sender); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1880 | DummyDtmfObserver observer; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1881 | dtmf_sender->RegisterObserver(&observer); |
| 1882 | |
| 1883 | // Test the DtmfSender object just created. |
| 1884 | EXPECT_TRUE(dtmf_sender->CanInsertDtmf()); |
| 1885 | EXPECT_TRUE(dtmf_sender->InsertDtmf("1a", 100, 50)); |
| 1886 | |
| 1887 | EXPECT_TRUE_WAIT(observer.completed(), kDefaultTimeout); |
| 1888 | std::vector<std::string> tones = {"1", "a", ""}; |
| 1889 | EXPECT_EQ(tones, observer.tones()); |
| 1890 | dtmf_sender->UnregisterObserver(); |
| 1891 | // TODO(deadbeef): Verify the tones were actually received end-to-end. |
| 1892 | } |
| 1893 | |
| 1894 | // Verifies the DtmfSenderObserver callbacks for a DtmfSender (one in each |
| 1895 | // direction). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1896 | TEST_P(PeerConnectionIntegrationTest, DtmfSenderObserver) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1897 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1898 | ConnectFakeSignaling(); |
| 1899 | // Only need audio for DTMF. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1900 | caller()->AddAudioTrack(); |
| 1901 | callee()->AddAudioTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1902 | caller()->CreateAndSetAndSignalOffer(); |
| 1903 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
deadbeef | 7145280 | 2017-05-07 17:21:01 -0700 | [diff] [blame] | 1904 | // DTLS must finish before the DTMF sender can be used reliably. |
| 1905 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1906 | TestDtmfFromSenderToReceiver(caller(), callee()); |
| 1907 | TestDtmfFromSenderToReceiver(callee(), caller()); |
| 1908 | } |
| 1909 | |
| 1910 | // Basic end-to-end test, verifying media can be encoded/transmitted/decoded |
| 1911 | // between two connections, using DTLS-SRTP. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1912 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithDtls) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1913 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1914 | ConnectFakeSignaling(); |
Harald Alvestrand | 194939b | 2018-01-24 16:04:13 +0100 | [diff] [blame] | 1915 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1916 | // Do normal offer/answer and wait for some frames to be received in each |
| 1917 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1918 | caller()->AddAudioVideoTracks(); |
| 1919 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1920 | caller()->CreateAndSetAndSignalOffer(); |
| 1921 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1922 | MediaExpectations media_expectations; |
| 1923 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 1924 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 1925 | EXPECT_METRIC_LE( |
| 1926 | 2, webrtc::metrics::NumEvents("WebRTC.PeerConnection.KeyProtocol", |
| 1927 | webrtc::kEnumCounterKeyProtocolDtls)); |
| 1928 | EXPECT_METRIC_EQ( |
| 1929 | 0, webrtc::metrics::NumEvents("WebRTC.PeerConnection.KeyProtocol", |
| 1930 | webrtc::kEnumCounterKeyProtocolSdes)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | // Uses SDES instead of DTLS for key agreement. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1934 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithSdes) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1935 | PeerConnectionInterface::RTCConfiguration sdes_config; |
| 1936 | sdes_config.enable_dtls_srtp.emplace(false); |
| 1937 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(sdes_config, sdes_config)); |
| 1938 | ConnectFakeSignaling(); |
| 1939 | |
| 1940 | // Do normal offer/answer and wait for some frames to be received in each |
| 1941 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1942 | caller()->AddAudioVideoTracks(); |
| 1943 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1944 | caller()->CreateAndSetAndSignalOffer(); |
| 1945 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1946 | MediaExpectations media_expectations; |
| 1947 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 1948 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 1949 | EXPECT_METRIC_LE( |
| 1950 | 2, webrtc::metrics::NumEvents("WebRTC.PeerConnection.KeyProtocol", |
| 1951 | webrtc::kEnumCounterKeyProtocolSdes)); |
| 1952 | EXPECT_METRIC_EQ( |
| 1953 | 0, webrtc::metrics::NumEvents("WebRTC.PeerConnection.KeyProtocol", |
| 1954 | webrtc::kEnumCounterKeyProtocolDtls)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1955 | } |
| 1956 | |
Steve Anton | 9a44b2d | 2019-07-12 12:58:30 -0700 | [diff] [blame] | 1957 | // Basic end-to-end test specifying the |enable_encrypted_rtp_header_extensions| |
| 1958 | // option to offer encrypted versions of all header extensions alongside the |
| 1959 | // unencrypted versions. |
| 1960 | TEST_P(PeerConnectionIntegrationTest, |
| 1961 | EndToEndCallWithEncryptedRtpHeaderExtensions) { |
| 1962 | CryptoOptions crypto_options; |
| 1963 | crypto_options.srtp.enable_encrypted_rtp_header_extensions = true; |
| 1964 | PeerConnectionInterface::RTCConfiguration config; |
| 1965 | config.crypto_options = crypto_options; |
| 1966 | // Note: This allows offering >14 RTP header extensions. |
| 1967 | config.offer_extmap_allow_mixed = true; |
| 1968 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 1969 | ConnectFakeSignaling(); |
| 1970 | |
| 1971 | // Do normal offer/answer and wait for some frames to be received in each |
| 1972 | // direction. |
| 1973 | caller()->AddAudioVideoTracks(); |
| 1974 | callee()->AddAudioVideoTracks(); |
| 1975 | caller()->CreateAndSetAndSignalOffer(); |
| 1976 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1977 | MediaExpectations media_expectations; |
| 1978 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 1979 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 1980 | } |
| 1981 | |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1982 | // Tests that the GetRemoteAudioSSLCertificate method returns the remote DTLS |
| 1983 | // certificate once the DTLS handshake has finished. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1984 | TEST_P(PeerConnectionIntegrationTest, |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1985 | GetRemoteAudioSSLCertificateReturnsExchangedCertificate) { |
| 1986 | auto GetRemoteAudioSSLCertificate = [](PeerConnectionWrapper* wrapper) { |
| 1987 | auto pci = reinterpret_cast<PeerConnectionProxy*>(wrapper->pc()); |
| 1988 | auto pc = reinterpret_cast<PeerConnection*>(pci->internal()); |
| 1989 | return pc->GetRemoteAudioSSLCertificate(); |
| 1990 | }; |
Zhi Huang | 70b820f | 2018-01-27 14:16:15 -0800 | [diff] [blame] | 1991 | auto GetRemoteAudioSSLCertChain = [](PeerConnectionWrapper* wrapper) { |
| 1992 | auto pci = reinterpret_cast<PeerConnectionProxy*>(wrapper->pc()); |
| 1993 | auto pc = reinterpret_cast<PeerConnection*>(pci->internal()); |
| 1994 | return pc->GetRemoteAudioSSLCertChain(); |
| 1995 | }; |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1996 | |
| 1997 | auto caller_cert = rtc::RTCCertificate::FromPEM(kRsaPems[0]); |
| 1998 | auto callee_cert = rtc::RTCCertificate::FromPEM(kRsaPems[1]); |
| 1999 | |
| 2000 | // Configure each side with a known certificate so they can be compared later. |
| 2001 | PeerConnectionInterface::RTCConfiguration caller_config; |
| 2002 | caller_config.enable_dtls_srtp.emplace(true); |
| 2003 | caller_config.certificates.push_back(caller_cert); |
| 2004 | PeerConnectionInterface::RTCConfiguration callee_config; |
| 2005 | callee_config.enable_dtls_srtp.emplace(true); |
| 2006 | callee_config.certificates.push_back(callee_cert); |
| 2007 | ASSERT_TRUE( |
| 2008 | CreatePeerConnectionWrappersWithConfig(caller_config, callee_config)); |
| 2009 | ConnectFakeSignaling(); |
| 2010 | |
| 2011 | // When first initialized, there should not be a remote SSL certificate (and |
| 2012 | // calling this method should not crash). |
| 2013 | EXPECT_EQ(nullptr, GetRemoteAudioSSLCertificate(caller())); |
| 2014 | EXPECT_EQ(nullptr, GetRemoteAudioSSLCertificate(callee())); |
Zhi Huang | 70b820f | 2018-01-27 14:16:15 -0800 | [diff] [blame] | 2015 | EXPECT_EQ(nullptr, GetRemoteAudioSSLCertChain(caller())); |
| 2016 | EXPECT_EQ(nullptr, GetRemoteAudioSSLCertChain(callee())); |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 2017 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2018 | caller()->AddAudioTrack(); |
| 2019 | callee()->AddAudioTrack(); |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 2020 | caller()->CreateAndSetAndSignalOffer(); |
| 2021 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2022 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
| 2023 | |
| 2024 | // Once DTLS has been connected, each side should return the other's SSL |
| 2025 | // certificate when calling GetRemoteAudioSSLCertificate. |
| 2026 | |
| 2027 | auto caller_remote_cert = GetRemoteAudioSSLCertificate(caller()); |
| 2028 | ASSERT_TRUE(caller_remote_cert); |
Benjamin Wright | 6c6c9df | 2018-10-25 01:16:26 -0700 | [diff] [blame] | 2029 | EXPECT_EQ(callee_cert->GetSSLCertificate().ToPEMString(), |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 2030 | caller_remote_cert->ToPEMString()); |
| 2031 | |
| 2032 | auto callee_remote_cert = GetRemoteAudioSSLCertificate(callee()); |
| 2033 | ASSERT_TRUE(callee_remote_cert); |
Benjamin Wright | 6c6c9df | 2018-10-25 01:16:26 -0700 | [diff] [blame] | 2034 | EXPECT_EQ(caller_cert->GetSSLCertificate().ToPEMString(), |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 2035 | callee_remote_cert->ToPEMString()); |
Zhi Huang | 70b820f | 2018-01-27 14:16:15 -0800 | [diff] [blame] | 2036 | |
| 2037 | auto caller_remote_cert_chain = GetRemoteAudioSSLCertChain(caller()); |
| 2038 | ASSERT_TRUE(caller_remote_cert_chain); |
| 2039 | ASSERT_EQ(1U, caller_remote_cert_chain->GetSize()); |
| 2040 | auto remote_cert = &caller_remote_cert_chain->Get(0); |
Benjamin Wright | 6c6c9df | 2018-10-25 01:16:26 -0700 | [diff] [blame] | 2041 | EXPECT_EQ(callee_cert->GetSSLCertificate().ToPEMString(), |
Zhi Huang | 70b820f | 2018-01-27 14:16:15 -0800 | [diff] [blame] | 2042 | remote_cert->ToPEMString()); |
| 2043 | |
| 2044 | auto callee_remote_cert_chain = GetRemoteAudioSSLCertChain(callee()); |
| 2045 | ASSERT_TRUE(callee_remote_cert_chain); |
| 2046 | ASSERT_EQ(1U, callee_remote_cert_chain->GetSize()); |
| 2047 | remote_cert = &callee_remote_cert_chain->Get(0); |
Benjamin Wright | 6c6c9df | 2018-10-25 01:16:26 -0700 | [diff] [blame] | 2048 | EXPECT_EQ(caller_cert->GetSSLCertificate().ToPEMString(), |
Zhi Huang | 70b820f | 2018-01-27 14:16:15 -0800 | [diff] [blame] | 2049 | remote_cert->ToPEMString()); |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 2050 | } |
| 2051 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2052 | // This test sets up a call between two parties with a source resolution of |
| 2053 | // 1280x720 and verifies that a 16:9 aspect ratio is received. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2054 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2055 | Send1280By720ResolutionAndReceive16To9AspectRatio) { |
| 2056 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2057 | ConnectFakeSignaling(); |
| 2058 | |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 2059 | // Add video tracks with 16:9 aspect ratio, size 1280 x 720. |
| 2060 | webrtc::FakePeriodicVideoSource::Config config; |
| 2061 | config.width = 1280; |
| 2062 | config.height = 720; |
Johannes Kron | 965e794 | 2018-09-13 15:36:20 +0200 | [diff] [blame] | 2063 | config.timestamp_offset_ms = rtc::TimeMillis(); |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 2064 | caller()->AddTrack(caller()->CreateLocalVideoTrackWithConfig(config)); |
| 2065 | callee()->AddTrack(callee()->CreateLocalVideoTrackWithConfig(config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2066 | |
| 2067 | // Do normal offer/answer and wait for at least one frame to be received in |
| 2068 | // each direction. |
| 2069 | caller()->CreateAndSetAndSignalOffer(); |
| 2070 | ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 && |
| 2071 | callee()->min_video_frames_received_per_track() > 0, |
| 2072 | kMaxWaitForFramesMs); |
| 2073 | |
| 2074 | // Check rendered aspect ratio. |
| 2075 | EXPECT_EQ(16.0 / 9, caller()->local_rendered_aspect_ratio()); |
| 2076 | EXPECT_EQ(16.0 / 9, caller()->rendered_aspect_ratio()); |
| 2077 | EXPECT_EQ(16.0 / 9, callee()->local_rendered_aspect_ratio()); |
| 2078 | EXPECT_EQ(16.0 / 9, callee()->rendered_aspect_ratio()); |
| 2079 | } |
| 2080 | |
| 2081 | // This test sets up an one-way call, with media only from caller to |
| 2082 | // callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2083 | TEST_P(PeerConnectionIntegrationTest, OneWayMediaCall) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2084 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2085 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2086 | caller()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2087 | caller()->CreateAndSetAndSignalOffer(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2088 | MediaExpectations media_expectations; |
| 2089 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2090 | media_expectations.CallerExpectsNoAudio(); |
| 2091 | media_expectations.CallerExpectsNoVideo(); |
| 2092 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 2095 | // Tests that send only works without the caller having a decoder factory and |
| 2096 | // the callee having an encoder factory. |
| 2097 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithSendOnlyVideo) { |
| 2098 | ASSERT_TRUE( |
| 2099 | CreateOneDirectionalPeerConnectionWrappers(/*caller_to_callee=*/true)); |
| 2100 | ConnectFakeSignaling(); |
| 2101 | // Add one-directional video, from caller to callee. |
| 2102 | rtc::scoped_refptr<webrtc::VideoTrackInterface> caller_track = |
| 2103 | caller()->CreateLocalVideoTrack(); |
| 2104 | caller()->AddTrack(caller_track); |
| 2105 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2106 | options.offer_to_receive_video = 0; |
| 2107 | caller()->SetOfferAnswerOptions(options); |
| 2108 | caller()->CreateAndSetAndSignalOffer(); |
| 2109 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2110 | ASSERT_EQ(callee()->pc()->GetReceivers().size(), 1u); |
| 2111 | |
| 2112 | // Expect video to be received in one direction. |
| 2113 | MediaExpectations media_expectations; |
| 2114 | media_expectations.CallerExpectsNoVideo(); |
| 2115 | media_expectations.CalleeExpectsSomeVideo(); |
| 2116 | |
| 2117 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 2118 | } |
| 2119 | |
| 2120 | // Tests that receive only works without the caller having an encoder factory |
| 2121 | // and the callee having a decoder factory. |
| 2122 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithReceiveOnlyVideo) { |
| 2123 | ASSERT_TRUE( |
| 2124 | CreateOneDirectionalPeerConnectionWrappers(/*caller_to_callee=*/false)); |
| 2125 | ConnectFakeSignaling(); |
| 2126 | // Add one-directional video, from callee to caller. |
| 2127 | rtc::scoped_refptr<webrtc::VideoTrackInterface> callee_track = |
| 2128 | callee()->CreateLocalVideoTrack(); |
| 2129 | callee()->AddTrack(callee_track); |
| 2130 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2131 | options.offer_to_receive_video = 1; |
| 2132 | caller()->SetOfferAnswerOptions(options); |
| 2133 | caller()->CreateAndSetAndSignalOffer(); |
| 2134 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2135 | ASSERT_EQ(caller()->pc()->GetReceivers().size(), 1u); |
| 2136 | |
| 2137 | // Expect video to be received in one direction. |
| 2138 | MediaExpectations media_expectations; |
| 2139 | media_expectations.CallerExpectsSomeVideo(); |
| 2140 | media_expectations.CalleeExpectsNoVideo(); |
| 2141 | |
| 2142 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 2143 | } |
| 2144 | |
| 2145 | TEST_P(PeerConnectionIntegrationTest, |
| 2146 | EndToEndCallAddReceiveVideoToSendOnlyCall) { |
| 2147 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2148 | ConnectFakeSignaling(); |
| 2149 | // Add one-directional video, from caller to callee. |
| 2150 | rtc::scoped_refptr<webrtc::VideoTrackInterface> caller_track = |
| 2151 | caller()->CreateLocalVideoTrack(); |
| 2152 | caller()->AddTrack(caller_track); |
| 2153 | caller()->CreateAndSetAndSignalOffer(); |
| 2154 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2155 | |
| 2156 | // Add receive video. |
| 2157 | rtc::scoped_refptr<webrtc::VideoTrackInterface> callee_track = |
| 2158 | callee()->CreateLocalVideoTrack(); |
| 2159 | callee()->AddTrack(callee_track); |
| 2160 | caller()->CreateAndSetAndSignalOffer(); |
| 2161 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2162 | |
| 2163 | // Ensure that video frames are received end-to-end. |
| 2164 | MediaExpectations media_expectations; |
| 2165 | media_expectations.ExpectBidirectionalVideo(); |
| 2166 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2167 | } |
| 2168 | |
| 2169 | TEST_P(PeerConnectionIntegrationTest, |
| 2170 | EndToEndCallAddSendVideoToReceiveOnlyCall) { |
| 2171 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2172 | ConnectFakeSignaling(); |
| 2173 | // Add one-directional video, from callee to caller. |
| 2174 | rtc::scoped_refptr<webrtc::VideoTrackInterface> callee_track = |
| 2175 | callee()->CreateLocalVideoTrack(); |
| 2176 | callee()->AddTrack(callee_track); |
| 2177 | caller()->CreateAndSetAndSignalOffer(); |
| 2178 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2179 | |
| 2180 | // Add send video. |
| 2181 | rtc::scoped_refptr<webrtc::VideoTrackInterface> caller_track = |
| 2182 | caller()->CreateLocalVideoTrack(); |
| 2183 | caller()->AddTrack(caller_track); |
| 2184 | caller()->CreateAndSetAndSignalOffer(); |
| 2185 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2186 | |
| 2187 | // Expect video to be received in one direction. |
| 2188 | MediaExpectations media_expectations; |
| 2189 | media_expectations.ExpectBidirectionalVideo(); |
| 2190 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2191 | } |
| 2192 | |
| 2193 | TEST_P(PeerConnectionIntegrationTest, |
| 2194 | EndToEndCallRemoveReceiveVideoFromSendReceiveCall) { |
| 2195 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2196 | ConnectFakeSignaling(); |
| 2197 | // Add send video, from caller to callee. |
| 2198 | rtc::scoped_refptr<webrtc::VideoTrackInterface> caller_track = |
| 2199 | caller()->CreateLocalVideoTrack(); |
| 2200 | rtc::scoped_refptr<webrtc::RtpSenderInterface> caller_sender = |
| 2201 | caller()->AddTrack(caller_track); |
| 2202 | // Add receive video, from callee to caller. |
| 2203 | rtc::scoped_refptr<webrtc::VideoTrackInterface> callee_track = |
| 2204 | callee()->CreateLocalVideoTrack(); |
| 2205 | |
| 2206 | rtc::scoped_refptr<webrtc::RtpSenderInterface> callee_sender = |
| 2207 | callee()->AddTrack(callee_track); |
| 2208 | caller()->CreateAndSetAndSignalOffer(); |
| 2209 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2210 | |
| 2211 | // Remove receive video (i.e., callee sender track). |
| 2212 | callee()->pc()->RemoveTrack(callee_sender); |
| 2213 | |
| 2214 | caller()->CreateAndSetAndSignalOffer(); |
| 2215 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2216 | |
| 2217 | // Expect one-directional video. |
| 2218 | MediaExpectations media_expectations; |
| 2219 | media_expectations.CallerExpectsNoVideo(); |
| 2220 | media_expectations.CalleeExpectsSomeVideo(); |
| 2221 | |
| 2222 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2223 | } |
| 2224 | |
| 2225 | TEST_P(PeerConnectionIntegrationTest, |
| 2226 | EndToEndCallRemoveSendVideoFromSendReceiveCall) { |
| 2227 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2228 | ConnectFakeSignaling(); |
| 2229 | // Add send video, from caller to callee. |
| 2230 | rtc::scoped_refptr<webrtc::VideoTrackInterface> caller_track = |
| 2231 | caller()->CreateLocalVideoTrack(); |
| 2232 | rtc::scoped_refptr<webrtc::RtpSenderInterface> caller_sender = |
| 2233 | caller()->AddTrack(caller_track); |
| 2234 | // Add receive video, from callee to caller. |
| 2235 | rtc::scoped_refptr<webrtc::VideoTrackInterface> callee_track = |
| 2236 | callee()->CreateLocalVideoTrack(); |
| 2237 | |
| 2238 | rtc::scoped_refptr<webrtc::RtpSenderInterface> callee_sender = |
| 2239 | callee()->AddTrack(callee_track); |
| 2240 | caller()->CreateAndSetAndSignalOffer(); |
| 2241 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2242 | |
| 2243 | // Remove send video (i.e., caller sender track). |
| 2244 | caller()->pc()->RemoveTrack(caller_sender); |
| 2245 | |
| 2246 | caller()->CreateAndSetAndSignalOffer(); |
| 2247 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2248 | |
| 2249 | // Expect one-directional video. |
| 2250 | MediaExpectations media_expectations; |
| 2251 | media_expectations.CalleeExpectsNoVideo(); |
| 2252 | media_expectations.CallerExpectsSomeVideo(); |
| 2253 | |
| 2254 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2255 | } |
| 2256 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2257 | // This test sets up a audio call initially, with the callee rejecting video |
| 2258 | // initially. Then later the callee decides to upgrade to audio/video, and |
| 2259 | // initiates a new offer/answer exchange. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2260 | TEST_P(PeerConnectionIntegrationTest, AudioToVideoUpgrade) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2261 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2262 | ConnectFakeSignaling(); |
| 2263 | // Initially, offer an audio/video stream from the caller, but refuse to |
| 2264 | // send/receive video on the callee side. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2265 | caller()->AddAudioVideoTracks(); |
| 2266 | callee()->AddAudioTrack(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2267 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2268 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2269 | options.offer_to_receive_video = 0; |
| 2270 | callee()->SetOfferAnswerOptions(options); |
| 2271 | } else { |
| 2272 | callee()->SetRemoteOfferHandler([this] { |
| 2273 | callee()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)->Stop(); |
| 2274 | }); |
| 2275 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2276 | // Do offer/answer and make sure audio is still received end-to-end. |
| 2277 | caller()->CreateAndSetAndSignalOffer(); |
| 2278 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2279 | { |
| 2280 | MediaExpectations media_expectations; |
| 2281 | media_expectations.ExpectBidirectionalAudio(); |
| 2282 | media_expectations.ExpectNoVideo(); |
| 2283 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2284 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2285 | // Sanity check that the callee's description has a rejected video section. |
| 2286 | ASSERT_NE(nullptr, callee()->pc()->local_description()); |
| 2287 | const ContentInfo* callee_video_content = |
| 2288 | GetFirstVideoContent(callee()->pc()->local_description()->description()); |
| 2289 | ASSERT_NE(nullptr, callee_video_content); |
| 2290 | EXPECT_TRUE(callee_video_content->rejected); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2291 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2292 | // Now negotiate with video and ensure negotiation succeeds, with video |
| 2293 | // frames and additional audio frames being received. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2294 | callee()->AddVideoTrack(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2295 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2296 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2297 | options.offer_to_receive_video = 1; |
| 2298 | callee()->SetOfferAnswerOptions(options); |
| 2299 | } else { |
| 2300 | callee()->SetRemoteOfferHandler(nullptr); |
| 2301 | caller()->SetRemoteOfferHandler([this] { |
| 2302 | // The caller creates a new transceiver to receive video on when receiving |
| 2303 | // the offer, but by default it is send only. |
| 2304 | auto transceivers = caller()->pc()->GetTransceivers(); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 2305 | ASSERT_EQ(3U, transceivers.size()); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2306 | ASSERT_EQ(cricket::MEDIA_TYPE_VIDEO, |
| 2307 | transceivers[2]->receiver()->media_type()); |
| 2308 | transceivers[2]->sender()->SetTrack(caller()->CreateLocalVideoTrack()); |
| 2309 | transceivers[2]->SetDirection(RtpTransceiverDirection::kSendRecv); |
| 2310 | }); |
| 2311 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2312 | callee()->CreateAndSetAndSignalOffer(); |
| 2313 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2314 | { |
| 2315 | // Expect additional audio frames to be received after the upgrade. |
| 2316 | MediaExpectations media_expectations; |
| 2317 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2318 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2319 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2320 | } |
| 2321 | |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 2322 | // Simpler than the above test; just add an audio track to an established |
| 2323 | // video-only connection. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2324 | TEST_P(PeerConnectionIntegrationTest, AddAudioToVideoOnlyCall) { |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 2325 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2326 | ConnectFakeSignaling(); |
| 2327 | // Do initial offer/answer with just a video track. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2328 | caller()->AddVideoTrack(); |
| 2329 | callee()->AddVideoTrack(); |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 2330 | caller()->CreateAndSetAndSignalOffer(); |
| 2331 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2332 | // Now add an audio track and do another offer/answer. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2333 | caller()->AddAudioTrack(); |
| 2334 | callee()->AddAudioTrack(); |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 2335 | caller()->CreateAndSetAndSignalOffer(); |
| 2336 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2337 | // Ensure both audio and video frames are received end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2338 | MediaExpectations media_expectations; |
| 2339 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2340 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 2341 | } |
| 2342 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2343 | // This test sets up a call that's transferred to a new caller with a different |
| 2344 | // DTLS fingerprint. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2345 | TEST_P(PeerConnectionIntegrationTest, CallTransferredForCallee) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2346 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2347 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2348 | caller()->AddAudioVideoTracks(); |
| 2349 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2350 | caller()->CreateAndSetAndSignalOffer(); |
| 2351 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2352 | |
| 2353 | // Keep the original peer around which will still send packets to the |
| 2354 | // receiving client. These SRTP packets will be dropped. |
| 2355 | std::unique_ptr<PeerConnectionWrapper> original_peer( |
| 2356 | SetCallerPcWrapperAndReturnCurrent( |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2357 | CreatePeerConnectionWrapperWithAlternateKey().release())); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2358 | // TODO(deadbeef): Why do we call Close here? That goes against the comment |
| 2359 | // directly above. |
| 2360 | original_peer->pc()->Close(); |
| 2361 | |
| 2362 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2363 | caller()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2364 | caller()->CreateAndSetAndSignalOffer(); |
| 2365 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2366 | // Wait for some additional frames to be transmitted end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2367 | MediaExpectations media_expectations; |
| 2368 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2369 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2370 | } |
| 2371 | |
| 2372 | // This test sets up a call that's transferred to a new callee with a different |
| 2373 | // DTLS fingerprint. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2374 | TEST_P(PeerConnectionIntegrationTest, CallTransferredForCaller) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2375 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2376 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2377 | caller()->AddAudioVideoTracks(); |
| 2378 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2379 | caller()->CreateAndSetAndSignalOffer(); |
| 2380 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2381 | |
| 2382 | // Keep the original peer around which will still send packets to the |
| 2383 | // receiving client. These SRTP packets will be dropped. |
| 2384 | std::unique_ptr<PeerConnectionWrapper> original_peer( |
| 2385 | SetCalleePcWrapperAndReturnCurrent( |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2386 | CreatePeerConnectionWrapperWithAlternateKey().release())); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2387 | // TODO(deadbeef): Why do we call Close here? That goes against the comment |
| 2388 | // directly above. |
| 2389 | original_peer->pc()->Close(); |
| 2390 | |
| 2391 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2392 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2393 | caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions()); |
| 2394 | caller()->CreateAndSetAndSignalOffer(); |
| 2395 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2396 | // Wait for some additional frames to be transmitted end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2397 | MediaExpectations media_expectations; |
| 2398 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2399 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2400 | } |
| 2401 | |
| 2402 | // This test sets up a non-bundled call and negotiates bundling at the same |
| 2403 | // time as starting an ICE restart. When bundling is in effect in the restart, |
| 2404 | // the DTLS-SRTP context should be successfully reset. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2405 | TEST_P(PeerConnectionIntegrationTest, BundlingEnabledWhileIceRestartOccurs) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2406 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2407 | ConnectFakeSignaling(); |
| 2408 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2409 | caller()->AddAudioVideoTracks(); |
| 2410 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2411 | // Remove the bundle group from the SDP received by the callee. |
| 2412 | callee()->SetReceivedSdpMunger([](cricket::SessionDescription* desc) { |
| 2413 | desc->RemoveGroupByName("BUNDLE"); |
| 2414 | }); |
| 2415 | caller()->CreateAndSetAndSignalOffer(); |
| 2416 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2417 | { |
| 2418 | MediaExpectations media_expectations; |
| 2419 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2420 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2421 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2422 | // Now stop removing the BUNDLE group, and trigger an ICE restart. |
| 2423 | callee()->SetReceivedSdpMunger(nullptr); |
| 2424 | caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions()); |
| 2425 | caller()->CreateAndSetAndSignalOffer(); |
| 2426 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2427 | |
| 2428 | // Expect additional frames to be received after the ICE restart. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2429 | { |
| 2430 | MediaExpectations media_expectations; |
| 2431 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2432 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2433 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2434 | } |
| 2435 | |
| 2436 | // Test CVO (Coordination of Video Orientation). If a video source is rotated |
| 2437 | // and both peers support the CVO RTP header extension, the actual video frames |
| 2438 | // don't need to be encoded in different resolutions, since the rotation is |
| 2439 | // communicated through the RTP header extension. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2440 | TEST_P(PeerConnectionIntegrationTest, RotatedVideoWithCVOExtension) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2441 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2442 | ConnectFakeSignaling(); |
| 2443 | // Add rotated video tracks. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2444 | caller()->AddTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2445 | caller()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_90)); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2446 | callee()->AddTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2447 | callee()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_270)); |
| 2448 | |
| 2449 | // Wait for video frames to be received by both sides. |
| 2450 | caller()->CreateAndSetAndSignalOffer(); |
| 2451 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2452 | ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 && |
| 2453 | callee()->min_video_frames_received_per_track() > 0, |
| 2454 | kMaxWaitForFramesMs); |
| 2455 | |
| 2456 | // Ensure that the aspect ratio is unmodified. |
| 2457 | // TODO(deadbeef): Where does 4:3 come from? Should be explicit in the test, |
| 2458 | // not just assumed. |
| 2459 | EXPECT_EQ(4.0 / 3, caller()->local_rendered_aspect_ratio()); |
| 2460 | EXPECT_EQ(4.0 / 3, caller()->rendered_aspect_ratio()); |
| 2461 | EXPECT_EQ(4.0 / 3, callee()->local_rendered_aspect_ratio()); |
| 2462 | EXPECT_EQ(4.0 / 3, callee()->rendered_aspect_ratio()); |
| 2463 | // Ensure that the CVO bits were surfaced to the renderer. |
| 2464 | EXPECT_EQ(webrtc::kVideoRotation_270, caller()->rendered_rotation()); |
| 2465 | EXPECT_EQ(webrtc::kVideoRotation_90, callee()->rendered_rotation()); |
| 2466 | } |
| 2467 | |
| 2468 | // Test that when the CVO extension isn't supported, video is rotated the |
| 2469 | // old-fashioned way, by encoding rotated frames. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2470 | TEST_P(PeerConnectionIntegrationTest, RotatedVideoWithoutCVOExtension) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2471 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2472 | ConnectFakeSignaling(); |
| 2473 | // Add rotated video tracks. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2474 | caller()->AddTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2475 | caller()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_90)); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2476 | callee()->AddTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2477 | callee()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_270)); |
| 2478 | |
| 2479 | // Remove the CVO extension from the offered SDP. |
| 2480 | callee()->SetReceivedSdpMunger([](cricket::SessionDescription* desc) { |
| 2481 | cricket::VideoContentDescription* video = |
| 2482 | GetFirstVideoContentDescription(desc); |
| 2483 | video->ClearRtpHeaderExtensions(); |
| 2484 | }); |
| 2485 | // Wait for video frames to be received by both sides. |
| 2486 | caller()->CreateAndSetAndSignalOffer(); |
| 2487 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2488 | ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 && |
| 2489 | callee()->min_video_frames_received_per_track() > 0, |
| 2490 | kMaxWaitForFramesMs); |
| 2491 | |
| 2492 | // Expect that the aspect ratio is inversed to account for the 90/270 degree |
| 2493 | // rotation. |
| 2494 | // TODO(deadbeef): Where does 4:3 come from? Should be explicit in the test, |
| 2495 | // not just assumed. |
| 2496 | EXPECT_EQ(3.0 / 4, caller()->local_rendered_aspect_ratio()); |
| 2497 | EXPECT_EQ(3.0 / 4, caller()->rendered_aspect_ratio()); |
| 2498 | EXPECT_EQ(3.0 / 4, callee()->local_rendered_aspect_ratio()); |
| 2499 | EXPECT_EQ(3.0 / 4, callee()->rendered_aspect_ratio()); |
| 2500 | // Expect that each endpoint is unaware of the rotation of the other endpoint. |
| 2501 | EXPECT_EQ(webrtc::kVideoRotation_0, caller()->rendered_rotation()); |
| 2502 | EXPECT_EQ(webrtc::kVideoRotation_0, callee()->rendered_rotation()); |
| 2503 | } |
| 2504 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2505 | // Test that if the answerer rejects the audio m= section, no audio is sent or |
| 2506 | // received, but video still can be. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2507 | TEST_P(PeerConnectionIntegrationTest, AnswererRejectsAudioSection) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2508 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2509 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2510 | caller()->AddAudioVideoTracks(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2511 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2512 | // Only add video track for callee, and set offer_to_receive_audio to 0, so |
| 2513 | // it will reject the audio m= section completely. |
| 2514 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2515 | options.offer_to_receive_audio = 0; |
| 2516 | callee()->SetOfferAnswerOptions(options); |
| 2517 | } else { |
| 2518 | // Stopping the audio RtpTransceiver will cause the media section to be |
| 2519 | // rejected in the answer. |
| 2520 | callee()->SetRemoteOfferHandler([this] { |
| 2521 | callee()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_AUDIO)->Stop(); |
| 2522 | }); |
| 2523 | } |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2524 | callee()->AddTrack(callee()->CreateLocalVideoTrack()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2525 | // Do offer/answer and wait for successful end-to-end video frames. |
| 2526 | caller()->CreateAndSetAndSignalOffer(); |
| 2527 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2528 | MediaExpectations media_expectations; |
| 2529 | media_expectations.ExpectBidirectionalVideo(); |
| 2530 | media_expectations.ExpectNoAudio(); |
| 2531 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2532 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2533 | // Sanity check that the callee's description has a rejected audio section. |
| 2534 | ASSERT_NE(nullptr, callee()->pc()->local_description()); |
| 2535 | const ContentInfo* callee_audio_content = |
| 2536 | GetFirstAudioContent(callee()->pc()->local_description()->description()); |
| 2537 | ASSERT_NE(nullptr, callee_audio_content); |
| 2538 | EXPECT_TRUE(callee_audio_content->rejected); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2539 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 2540 | // The caller's transceiver should have stopped after receiving the answer. |
| 2541 | EXPECT_TRUE(caller() |
| 2542 | ->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_AUDIO) |
| 2543 | ->stopped()); |
| 2544 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2545 | } |
| 2546 | |
| 2547 | // Test that if the answerer rejects the video m= section, no video is sent or |
| 2548 | // received, but audio still can be. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2549 | TEST_P(PeerConnectionIntegrationTest, AnswererRejectsVideoSection) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2550 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2551 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2552 | caller()->AddAudioVideoTracks(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2553 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2554 | // Only add audio track for callee, and set offer_to_receive_video to 0, so |
| 2555 | // it will reject the video m= section completely. |
| 2556 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2557 | options.offer_to_receive_video = 0; |
| 2558 | callee()->SetOfferAnswerOptions(options); |
| 2559 | } else { |
| 2560 | // Stopping the video RtpTransceiver will cause the media section to be |
| 2561 | // rejected in the answer. |
| 2562 | callee()->SetRemoteOfferHandler([this] { |
| 2563 | callee()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)->Stop(); |
| 2564 | }); |
| 2565 | } |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2566 | callee()->AddTrack(callee()->CreateLocalAudioTrack()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2567 | // Do offer/answer and wait for successful end-to-end audio frames. |
| 2568 | caller()->CreateAndSetAndSignalOffer(); |
| 2569 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2570 | MediaExpectations media_expectations; |
| 2571 | media_expectations.ExpectBidirectionalAudio(); |
| 2572 | media_expectations.ExpectNoVideo(); |
| 2573 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2574 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2575 | // Sanity check that the callee's description has a rejected video section. |
| 2576 | ASSERT_NE(nullptr, callee()->pc()->local_description()); |
| 2577 | const ContentInfo* callee_video_content = |
| 2578 | GetFirstVideoContent(callee()->pc()->local_description()->description()); |
| 2579 | ASSERT_NE(nullptr, callee_video_content); |
| 2580 | EXPECT_TRUE(callee_video_content->rejected); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2581 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 2582 | // The caller's transceiver should have stopped after receiving the answer. |
| 2583 | EXPECT_TRUE(caller() |
| 2584 | ->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO) |
| 2585 | ->stopped()); |
| 2586 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2587 | } |
| 2588 | |
| 2589 | // Test that if the answerer rejects both audio and video m= sections, nothing |
| 2590 | // bad happens. |
| 2591 | // TODO(deadbeef): Test that a data channel still works. Currently this doesn't |
| 2592 | // test anything but the fact that negotiation succeeds, which doesn't mean |
| 2593 | // much. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2594 | TEST_P(PeerConnectionIntegrationTest, AnswererRejectsAudioAndVideoSections) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2595 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2596 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2597 | caller()->AddAudioVideoTracks(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2598 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2599 | // Don't give the callee any tracks, and set offer_to_receive_X to 0, so it |
| 2600 | // will reject both audio and video m= sections. |
| 2601 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2602 | options.offer_to_receive_audio = 0; |
| 2603 | options.offer_to_receive_video = 0; |
| 2604 | callee()->SetOfferAnswerOptions(options); |
| 2605 | } else { |
| 2606 | callee()->SetRemoteOfferHandler([this] { |
| 2607 | // Stopping all transceivers will cause all media sections to be rejected. |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 2608 | for (const auto& transceiver : callee()->pc()->GetTransceivers()) { |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2609 | transceiver->Stop(); |
| 2610 | } |
| 2611 | }); |
| 2612 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2613 | // Do offer/answer and wait for stable signaling state. |
| 2614 | caller()->CreateAndSetAndSignalOffer(); |
| 2615 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2616 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2617 | // Sanity check that the callee's description has rejected m= sections. |
| 2618 | ASSERT_NE(nullptr, callee()->pc()->local_description()); |
| 2619 | const ContentInfo* callee_audio_content = |
| 2620 | GetFirstAudioContent(callee()->pc()->local_description()->description()); |
| 2621 | ASSERT_NE(nullptr, callee_audio_content); |
| 2622 | EXPECT_TRUE(callee_audio_content->rejected); |
| 2623 | const ContentInfo* callee_video_content = |
| 2624 | GetFirstVideoContent(callee()->pc()->local_description()->description()); |
| 2625 | ASSERT_NE(nullptr, callee_video_content); |
| 2626 | EXPECT_TRUE(callee_video_content->rejected); |
| 2627 | } |
| 2628 | |
| 2629 | // This test sets up an audio and video call between two parties. After the |
| 2630 | // call runs for a while, the caller sends an updated offer with video being |
| 2631 | // rejected. Once the re-negotiation is done, the video flow should stop and |
| 2632 | // the audio flow should continue. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2633 | TEST_P(PeerConnectionIntegrationTest, VideoRejectedInSubsequentOffer) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2634 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2635 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2636 | caller()->AddAudioVideoTracks(); |
| 2637 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2638 | caller()->CreateAndSetAndSignalOffer(); |
| 2639 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2640 | { |
| 2641 | MediaExpectations media_expectations; |
| 2642 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2643 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2644 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2645 | // Renegotiate, rejecting the video m= section. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2646 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2647 | caller()->SetGeneratedSdpMunger( |
| 2648 | [](cricket::SessionDescription* description) { |
| 2649 | for (cricket::ContentInfo& content : description->contents()) { |
| 2650 | if (cricket::IsVideoContent(&content)) { |
| 2651 | content.rejected = true; |
| 2652 | } |
| 2653 | } |
| 2654 | }); |
| 2655 | } else { |
| 2656 | caller()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)->Stop(); |
| 2657 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2658 | caller()->CreateAndSetAndSignalOffer(); |
| 2659 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
| 2660 | |
| 2661 | // Sanity check that the caller's description has a rejected video section. |
| 2662 | ASSERT_NE(nullptr, caller()->pc()->local_description()); |
| 2663 | const ContentInfo* caller_video_content = |
| 2664 | GetFirstVideoContent(caller()->pc()->local_description()->description()); |
| 2665 | ASSERT_NE(nullptr, caller_video_content); |
| 2666 | EXPECT_TRUE(caller_video_content->rejected); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2667 | // Wait for some additional audio frames to be received. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2668 | { |
| 2669 | MediaExpectations media_expectations; |
| 2670 | media_expectations.ExpectBidirectionalAudio(); |
| 2671 | media_expectations.ExpectNoVideo(); |
| 2672 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2673 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2674 | } |
| 2675 | |
Taylor Brandstetter | 60c8dc8 | 2018-04-11 15:20:27 -0700 | [diff] [blame] | 2676 | // Do one offer/answer with audio, another that disables it (rejecting the m= |
| 2677 | // section), and another that re-enables it. Regression test for: |
| 2678 | // bugs.webrtc.org/6023 |
| 2679 | TEST_F(PeerConnectionIntegrationTestPlanB, EnableAudioAfterRejecting) { |
| 2680 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2681 | ConnectFakeSignaling(); |
| 2682 | |
| 2683 | // Add audio track, do normal offer/answer. |
| 2684 | rtc::scoped_refptr<webrtc::AudioTrackInterface> track = |
| 2685 | caller()->CreateLocalAudioTrack(); |
| 2686 | rtc::scoped_refptr<webrtc::RtpSenderInterface> sender = |
| 2687 | caller()->pc()->AddTrack(track, {"stream"}).MoveValue(); |
| 2688 | caller()->CreateAndSetAndSignalOffer(); |
| 2689 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2690 | |
| 2691 | // Remove audio track, and set offer_to_receive_audio to false to cause the |
| 2692 | // m= section to be completely disabled, not just "recvonly". |
| 2693 | caller()->pc()->RemoveTrack(sender); |
| 2694 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2695 | options.offer_to_receive_audio = 0; |
| 2696 | caller()->SetOfferAnswerOptions(options); |
| 2697 | caller()->CreateAndSetAndSignalOffer(); |
| 2698 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2699 | |
| 2700 | // Add the audio track again, expecting negotiation to succeed and frames to |
| 2701 | // flow. |
| 2702 | sender = caller()->pc()->AddTrack(track, {"stream"}).MoveValue(); |
| 2703 | options.offer_to_receive_audio = 1; |
| 2704 | caller()->SetOfferAnswerOptions(options); |
| 2705 | caller()->CreateAndSetAndSignalOffer(); |
| 2706 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2707 | |
| 2708 | MediaExpectations media_expectations; |
| 2709 | media_expectations.CalleeExpectsSomeAudio(); |
| 2710 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 2711 | } |
| 2712 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2713 | // Basic end-to-end test, but without SSRC/MSID signaling. This functionality |
| 2714 | // is needed to support legacy endpoints. |
| 2715 | // TODO(deadbeef): When we support the MID extension and demuxing on MID, also |
| 2716 | // add a test for an end-to-end test without MID signaling either (basically, |
| 2717 | // the minimum acceptable SDP). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2718 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithoutSsrcOrMsidSignaling) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2719 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2720 | ConnectFakeSignaling(); |
| 2721 | // Add audio and video, testing that packets can be demuxed on payload type. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2722 | caller()->AddAudioVideoTracks(); |
| 2723 | callee()->AddAudioVideoTracks(); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2724 | // Remove SSRCs and MSIDs from the received offer SDP. |
| 2725 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2726 | caller()->CreateAndSetAndSignalOffer(); |
| 2727 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2728 | MediaExpectations media_expectations; |
| 2729 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2730 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2731 | } |
| 2732 | |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 2733 | // Basic end-to-end test, without SSRC signaling. This means that the track |
| 2734 | // was created properly and frames are delivered when the MSIDs are communicated |
| 2735 | // with a=msid lines and no a=ssrc lines. |
| 2736 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 2737 | EndToEndCallWithoutSsrcSignaling) { |
| 2738 | const char kStreamId[] = "streamId"; |
| 2739 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2740 | ConnectFakeSignaling(); |
| 2741 | // Add just audio tracks. |
| 2742 | caller()->AddTrack(caller()->CreateLocalAudioTrack(), {kStreamId}); |
| 2743 | callee()->AddAudioTrack(); |
| 2744 | |
| 2745 | // Remove SSRCs from the received offer SDP. |
| 2746 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndKeepMsids); |
| 2747 | caller()->CreateAndSetAndSignalOffer(); |
| 2748 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2749 | MediaExpectations media_expectations; |
| 2750 | media_expectations.ExpectBidirectionalAudio(); |
| 2751 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2752 | } |
| 2753 | |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 2754 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 2755 | EndToEndCallAddReceiveVideoToSendOnlyCall) { |
| 2756 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2757 | ConnectFakeSignaling(); |
| 2758 | // Add one-directional video, from caller to callee. |
| 2759 | rtc::scoped_refptr<webrtc::VideoTrackInterface> track = |
| 2760 | caller()->CreateLocalVideoTrack(); |
| 2761 | |
| 2762 | RtpTransceiverInit video_transceiver_init; |
| 2763 | video_transceiver_init.stream_ids = {"video1"}; |
| 2764 | video_transceiver_init.direction = RtpTransceiverDirection::kSendOnly; |
| 2765 | auto video_sender = |
| 2766 | caller()->pc()->AddTransceiver(track, video_transceiver_init).MoveValue(); |
| 2767 | caller()->CreateAndSetAndSignalOffer(); |
| 2768 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2769 | |
| 2770 | // Add receive direction. |
| 2771 | video_sender->SetDirection(RtpTransceiverDirection::kSendRecv); |
| 2772 | |
| 2773 | rtc::scoped_refptr<webrtc::VideoTrackInterface> callee_track = |
| 2774 | callee()->CreateLocalVideoTrack(); |
| 2775 | |
| 2776 | callee()->AddTrack(callee_track); |
| 2777 | caller()->CreateAndSetAndSignalOffer(); |
| 2778 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2779 | // Ensure that video frames are received end-to-end. |
| 2780 | MediaExpectations media_expectations; |
| 2781 | media_expectations.ExpectBidirectionalVideo(); |
| 2782 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2783 | } |
| 2784 | |
Steve Anton | df527fd | 2018-04-27 15:52:03 -0700 | [diff] [blame] | 2785 | // Tests that video flows between multiple video tracks when SSRCs are not |
| 2786 | // signaled. This exercises the MID RTP header extension which is needed to |
| 2787 | // demux the incoming video tracks. |
| 2788 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 2789 | EndToEndCallWithTwoVideoTracksAndNoSignaledSsrc) { |
| 2790 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2791 | ConnectFakeSignaling(); |
| 2792 | caller()->AddVideoTrack(); |
| 2793 | caller()->AddVideoTrack(); |
| 2794 | callee()->AddVideoTrack(); |
| 2795 | callee()->AddVideoTrack(); |
| 2796 | |
| 2797 | caller()->SetReceivedSdpMunger(&RemoveSsrcsAndKeepMsids); |
| 2798 | callee()->SetReceivedSdpMunger(&RemoveSsrcsAndKeepMsids); |
| 2799 | caller()->CreateAndSetAndSignalOffer(); |
| 2800 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2801 | ASSERT_EQ(2u, caller()->pc()->GetReceivers().size()); |
| 2802 | ASSERT_EQ(2u, callee()->pc()->GetReceivers().size()); |
| 2803 | |
| 2804 | // Expect video to be received in both directions on both tracks. |
| 2805 | MediaExpectations media_expectations; |
| 2806 | media_expectations.ExpectBidirectionalVideo(); |
| 2807 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 2808 | } |
| 2809 | |
Henrik Boström | 5b14778 | 2018-12-04 11:25:05 +0100 | [diff] [blame] | 2810 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, NoStreamsMsidLinePresent) { |
| 2811 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2812 | ConnectFakeSignaling(); |
| 2813 | caller()->AddAudioTrack(); |
| 2814 | caller()->AddVideoTrack(); |
| 2815 | caller()->CreateAndSetAndSignalOffer(); |
| 2816 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2817 | auto callee_receivers = callee()->pc()->GetReceivers(); |
| 2818 | ASSERT_EQ(2u, callee_receivers.size()); |
| 2819 | EXPECT_TRUE(callee_receivers[0]->stream_ids().empty()); |
| 2820 | EXPECT_TRUE(callee_receivers[1]->stream_ids().empty()); |
| 2821 | } |
| 2822 | |
| 2823 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, NoStreamsMsidLineMissing) { |
| 2824 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2825 | ConnectFakeSignaling(); |
| 2826 | caller()->AddAudioTrack(); |
| 2827 | caller()->AddVideoTrack(); |
| 2828 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 2829 | caller()->CreateAndSetAndSignalOffer(); |
| 2830 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2831 | auto callee_receivers = callee()->pc()->GetReceivers(); |
| 2832 | ASSERT_EQ(2u, callee_receivers.size()); |
| 2833 | ASSERT_EQ(1u, callee_receivers[0]->stream_ids().size()); |
| 2834 | ASSERT_EQ(1u, callee_receivers[1]->stream_ids().size()); |
| 2835 | EXPECT_EQ(callee_receivers[0]->stream_ids()[0], |
| 2836 | callee_receivers[1]->stream_ids()[0]); |
| 2837 | EXPECT_EQ(callee_receivers[0]->streams()[0], |
| 2838 | callee_receivers[1]->streams()[0]); |
| 2839 | } |
| 2840 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2841 | // Test that if two video tracks are sent (from caller to callee, in this test), |
| 2842 | // they're transmitted correctly end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2843 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithTwoVideoTracks) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2844 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2845 | ConnectFakeSignaling(); |
| 2846 | // Add one audio/video stream, and one video-only stream. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2847 | caller()->AddAudioVideoTracks(); |
| 2848 | caller()->AddVideoTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2849 | caller()->CreateAndSetAndSignalOffer(); |
| 2850 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2851 | ASSERT_EQ(3u, callee()->pc()->GetReceivers().size()); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2852 | |
| 2853 | MediaExpectations media_expectations; |
| 2854 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2855 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2856 | } |
| 2857 | |
| 2858 | static void MakeSpecCompliantMaxBundleOffer(cricket::SessionDescription* desc) { |
| 2859 | bool first = true; |
| 2860 | for (cricket::ContentInfo& content : desc->contents()) { |
| 2861 | if (first) { |
| 2862 | first = false; |
| 2863 | continue; |
| 2864 | } |
| 2865 | content.bundle_only = true; |
| 2866 | } |
| 2867 | first = true; |
| 2868 | for (cricket::TransportInfo& transport : desc->transport_infos()) { |
| 2869 | if (first) { |
| 2870 | first = false; |
| 2871 | continue; |
| 2872 | } |
| 2873 | transport.description.ice_ufrag.clear(); |
| 2874 | transport.description.ice_pwd.clear(); |
| 2875 | transport.description.connection_role = cricket::CONNECTIONROLE_NONE; |
| 2876 | transport.description.identity_fingerprint.reset(nullptr); |
| 2877 | } |
| 2878 | } |
| 2879 | |
| 2880 | // Test that if applying a true "max bundle" offer, which uses ports of 0, |
| 2881 | // "a=bundle-only", omitting "a=fingerprint", "a=setup", "a=ice-ufrag" and |
| 2882 | // "a=ice-pwd" for all but the audio "m=" section, negotiation still completes |
| 2883 | // successfully and media flows. |
| 2884 | // TODO(deadbeef): Update this test to also omit "a=rtcp-mux", once that works. |
| 2885 | // TODO(deadbeef): Won't need this test once we start generating actual |
| 2886 | // standards-compliant SDP. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2887 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2888 | EndToEndCallWithSpecCompliantMaxBundleOffer) { |
| 2889 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2890 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2891 | caller()->AddAudioVideoTracks(); |
| 2892 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2893 | // Do the equivalent of setting the port to 0, adding a=bundle-only, and |
| 2894 | // removing a=ice-ufrag, a=ice-pwd, a=fingerprint and a=setup from all |
| 2895 | // but the first m= section. |
| 2896 | callee()->SetReceivedSdpMunger(MakeSpecCompliantMaxBundleOffer); |
| 2897 | caller()->CreateAndSetAndSignalOffer(); |
| 2898 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2899 | MediaExpectations media_expectations; |
| 2900 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2901 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2902 | } |
| 2903 | |
| 2904 | // Test that we can receive the audio output level from a remote audio track. |
| 2905 | // TODO(deadbeef): Use a fake audio source and verify that the output level is |
| 2906 | // exactly what the source on the other side was configured with. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2907 | TEST_P(PeerConnectionIntegrationTest, GetAudioOutputLevelStatsWithOldStatsApi) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2908 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2909 | ConnectFakeSignaling(); |
| 2910 | // Just add an audio track. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2911 | caller()->AddAudioTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2912 | caller()->CreateAndSetAndSignalOffer(); |
| 2913 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2914 | |
| 2915 | // Get the audio output level stats. Note that the level is not available |
| 2916 | // until an RTCP packet has been received. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2917 | EXPECT_TRUE_WAIT(callee()->OldGetStats()->AudioOutputLevel() > 0, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2918 | kMaxWaitForFramesMs); |
| 2919 | } |
| 2920 | |
| 2921 | // Test that an audio input level is reported. |
| 2922 | // TODO(deadbeef): Use a fake audio source and verify that the input level is |
| 2923 | // exactly what the source was configured with. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2924 | TEST_P(PeerConnectionIntegrationTest, GetAudioInputLevelStatsWithOldStatsApi) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2925 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2926 | ConnectFakeSignaling(); |
| 2927 | // Just add an audio track. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2928 | caller()->AddAudioTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2929 | caller()->CreateAndSetAndSignalOffer(); |
| 2930 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2931 | |
| 2932 | // Get the audio input level stats. The level should be available very |
| 2933 | // soon after the test starts. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2934 | EXPECT_TRUE_WAIT(caller()->OldGetStats()->AudioInputLevel() > 0, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2935 | kMaxWaitForStatsMs); |
| 2936 | } |
| 2937 | |
| 2938 | // Test that we can get incoming byte counts from both audio and video tracks. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2939 | TEST_P(PeerConnectionIntegrationTest, GetBytesReceivedStatsWithOldStatsApi) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2940 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2941 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2942 | caller()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2943 | // Do offer/answer, wait for the callee to receive some frames. |
| 2944 | caller()->CreateAndSetAndSignalOffer(); |
| 2945 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2946 | |
| 2947 | MediaExpectations media_expectations; |
| 2948 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2949 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2950 | |
| 2951 | // Get a handle to the remote tracks created, so they can be used as GetStats |
| 2952 | // filters. |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 2953 | for (const auto& receiver : callee()->pc()->GetReceivers()) { |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2954 | // We received frames, so we definitely should have nonzero "received bytes" |
| 2955 | // stats at this point. |
| 2956 | EXPECT_GT(callee()->OldGetStatsForTrack(receiver->track())->BytesReceived(), |
| 2957 | 0); |
| 2958 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | // Test that we can get outgoing byte counts from both audio and video tracks. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2962 | TEST_P(PeerConnectionIntegrationTest, GetBytesSentStatsWithOldStatsApi) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2963 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2964 | ConnectFakeSignaling(); |
| 2965 | auto audio_track = caller()->CreateLocalAudioTrack(); |
| 2966 | auto video_track = caller()->CreateLocalVideoTrack(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2967 | caller()->AddTrack(audio_track); |
| 2968 | caller()->AddTrack(video_track); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2969 | // Do offer/answer, wait for the callee to receive some frames. |
| 2970 | caller()->CreateAndSetAndSignalOffer(); |
| 2971 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2972 | MediaExpectations media_expectations; |
| 2973 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2974 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2975 | |
| 2976 | // The callee received frames, so we definitely should have nonzero "sent |
| 2977 | // bytes" stats at this point. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2978 | EXPECT_GT(caller()->OldGetStatsForTrack(audio_track)->BytesSent(), 0); |
| 2979 | EXPECT_GT(caller()->OldGetStatsForTrack(video_track)->BytesSent(), 0); |
| 2980 | } |
| 2981 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2982 | // Test that we can get capture start ntp time. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2983 | TEST_P(PeerConnectionIntegrationTest, GetCaptureStartNtpTimeWithOldStatsApi) { |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2984 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2985 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2986 | caller()->AddAudioTrack(); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2987 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2988 | callee()->AddAudioTrack(); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2989 | |
| 2990 | // Do offer/answer, wait for the callee to receive some frames. |
| 2991 | caller()->CreateAndSetAndSignalOffer(); |
| 2992 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2993 | |
| 2994 | // Get the remote audio track created on the receiver, so they can be used as |
| 2995 | // GetStats filters. |
Steve Anton | fc85371 | 2018-03-01 13:48:58 -0800 | [diff] [blame] | 2996 | auto receivers = callee()->pc()->GetReceivers(); |
| 2997 | ASSERT_EQ(1u, receivers.size()); |
| 2998 | auto remote_audio_track = receivers[0]->track(); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2999 | |
| 3000 | // Get the audio output level stats. Note that the level is not available |
| 3001 | // until an RTCP packet has been received. |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 3002 | EXPECT_TRUE_WAIT( |
| 3003 | callee()->OldGetStatsForTrack(remote_audio_track)->CaptureStartNtpTime() > |
| 3004 | 0, |
| 3005 | 2 * kMaxWaitForFramesMs); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 3006 | } |
| 3007 | |
Steve Anton | a41959e | 2018-11-28 11:15:33 -0800 | [diff] [blame] | 3008 | // Test that the track ID is associated with all local and remote SSRC stats |
| 3009 | // using the old GetStats() and more than 1 audio and more than 1 video track. |
| 3010 | // This is a regression test for crbug.com/906988 |
| 3011 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 3012 | OldGetStatsAssociatesTrackIdForManyMediaSections) { |
| 3013 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3014 | ConnectFakeSignaling(); |
| 3015 | auto audio_sender_1 = caller()->AddAudioTrack(); |
| 3016 | auto video_sender_1 = caller()->AddVideoTrack(); |
| 3017 | auto audio_sender_2 = caller()->AddAudioTrack(); |
| 3018 | auto video_sender_2 = caller()->AddVideoTrack(); |
| 3019 | caller()->CreateAndSetAndSignalOffer(); |
| 3020 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3021 | |
| 3022 | MediaExpectations media_expectations; |
| 3023 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 3024 | ASSERT_TRUE_WAIT(ExpectNewFrames(media_expectations), kDefaultTimeout); |
| 3025 | |
| 3026 | std::vector<std::string> track_ids = { |
| 3027 | audio_sender_1->track()->id(), video_sender_1->track()->id(), |
| 3028 | audio_sender_2->track()->id(), video_sender_2->track()->id()}; |
| 3029 | |
| 3030 | auto caller_stats = caller()->OldGetStats(); |
| 3031 | EXPECT_THAT(caller_stats->TrackIds(), UnorderedElementsAreArray(track_ids)); |
| 3032 | auto callee_stats = callee()->OldGetStats(); |
| 3033 | EXPECT_THAT(callee_stats->TrackIds(), UnorderedElementsAreArray(track_ids)); |
| 3034 | } |
| 3035 | |
Steve Anton | ffa6ce4 | 2018-11-30 09:26:08 -0800 | [diff] [blame] | 3036 | // Test that the new GetStats() returns stats for all outgoing/incoming streams |
| 3037 | // with the correct track IDs if there are more than one audio and more than one |
| 3038 | // video senders/receivers. |
| 3039 | TEST_P(PeerConnectionIntegrationTest, NewGetStatsManyAudioAndManyVideoStreams) { |
| 3040 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3041 | ConnectFakeSignaling(); |
| 3042 | auto audio_sender_1 = caller()->AddAudioTrack(); |
| 3043 | auto video_sender_1 = caller()->AddVideoTrack(); |
| 3044 | auto audio_sender_2 = caller()->AddAudioTrack(); |
| 3045 | auto video_sender_2 = caller()->AddVideoTrack(); |
| 3046 | caller()->CreateAndSetAndSignalOffer(); |
| 3047 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3048 | |
| 3049 | MediaExpectations media_expectations; |
| 3050 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 3051 | ASSERT_TRUE_WAIT(ExpectNewFrames(media_expectations), kDefaultTimeout); |
| 3052 | |
| 3053 | std::vector<std::string> track_ids = { |
| 3054 | audio_sender_1->track()->id(), video_sender_1->track()->id(), |
| 3055 | audio_sender_2->track()->id(), video_sender_2->track()->id()}; |
| 3056 | |
| 3057 | rtc::scoped_refptr<const webrtc::RTCStatsReport> caller_report = |
| 3058 | caller()->NewGetStats(); |
| 3059 | ASSERT_TRUE(caller_report); |
| 3060 | auto outbound_stream_stats = |
| 3061 | caller_report->GetStatsOfType<webrtc::RTCOutboundRTPStreamStats>(); |
Henrik Boström | a0ff50c | 2020-05-05 15:54:46 +0200 | [diff] [blame] | 3062 | ASSERT_EQ(outbound_stream_stats.size(), 4u); |
Steve Anton | ffa6ce4 | 2018-11-30 09:26:08 -0800 | [diff] [blame] | 3063 | std::vector<std::string> outbound_track_ids; |
| 3064 | for (const auto& stat : outbound_stream_stats) { |
| 3065 | ASSERT_TRUE(stat->bytes_sent.is_defined()); |
| 3066 | EXPECT_LT(0u, *stat->bytes_sent); |
Rasmus Brandt | 2efae77 | 2019-06-27 14:29:34 +0200 | [diff] [blame] | 3067 | if (*stat->kind == "video") { |
| 3068 | ASSERT_TRUE(stat->key_frames_encoded.is_defined()); |
| 3069 | EXPECT_GT(*stat->key_frames_encoded, 0u); |
| 3070 | ASSERT_TRUE(stat->frames_encoded.is_defined()); |
| 3071 | EXPECT_GE(*stat->frames_encoded, *stat->key_frames_encoded); |
| 3072 | } |
Steve Anton | ffa6ce4 | 2018-11-30 09:26:08 -0800 | [diff] [blame] | 3073 | ASSERT_TRUE(stat->track_id.is_defined()); |
| 3074 | const auto* track_stat = |
| 3075 | caller_report->GetAs<webrtc::RTCMediaStreamTrackStats>(*stat->track_id); |
| 3076 | ASSERT_TRUE(track_stat); |
| 3077 | outbound_track_ids.push_back(*track_stat->track_identifier); |
| 3078 | } |
| 3079 | EXPECT_THAT(outbound_track_ids, UnorderedElementsAreArray(track_ids)); |
| 3080 | |
| 3081 | rtc::scoped_refptr<const webrtc::RTCStatsReport> callee_report = |
| 3082 | callee()->NewGetStats(); |
| 3083 | ASSERT_TRUE(callee_report); |
| 3084 | auto inbound_stream_stats = |
| 3085 | callee_report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>(); |
| 3086 | ASSERT_EQ(4u, inbound_stream_stats.size()); |
| 3087 | std::vector<std::string> inbound_track_ids; |
| 3088 | for (const auto& stat : inbound_stream_stats) { |
| 3089 | ASSERT_TRUE(stat->bytes_received.is_defined()); |
| 3090 | EXPECT_LT(0u, *stat->bytes_received); |
Rasmus Brandt | 2efae77 | 2019-06-27 14:29:34 +0200 | [diff] [blame] | 3091 | if (*stat->kind == "video") { |
| 3092 | ASSERT_TRUE(stat->key_frames_decoded.is_defined()); |
| 3093 | EXPECT_GT(*stat->key_frames_decoded, 0u); |
| 3094 | ASSERT_TRUE(stat->frames_decoded.is_defined()); |
| 3095 | EXPECT_GE(*stat->frames_decoded, *stat->key_frames_decoded); |
| 3096 | } |
Steve Anton | ffa6ce4 | 2018-11-30 09:26:08 -0800 | [diff] [blame] | 3097 | ASSERT_TRUE(stat->track_id.is_defined()); |
| 3098 | const auto* track_stat = |
| 3099 | callee_report->GetAs<webrtc::RTCMediaStreamTrackStats>(*stat->track_id); |
| 3100 | ASSERT_TRUE(track_stat); |
| 3101 | inbound_track_ids.push_back(*track_stat->track_identifier); |
| 3102 | } |
| 3103 | EXPECT_THAT(inbound_track_ids, UnorderedElementsAreArray(track_ids)); |
| 3104 | } |
| 3105 | |
| 3106 | // Test that we can get stats (using the new stats implementation) for |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 3107 | // unsignaled streams. Meaning when SSRCs/MSIDs aren't signaled explicitly in |
| 3108 | // SDP. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3109 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 3110 | GetStatsForUnsignaledStreamWithNewStatsApi) { |
| 3111 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3112 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3113 | caller()->AddAudioTrack(); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 3114 | // Remove SSRCs and MSIDs from the received offer SDP. |
| 3115 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 3116 | caller()->CreateAndSetAndSignalOffer(); |
| 3117 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3118 | MediaExpectations media_expectations; |
| 3119 | media_expectations.CalleeExpectsSomeAudio(1); |
| 3120 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 3121 | |
| 3122 | // We received a frame, so we should have nonzero "bytes received" stats for |
| 3123 | // the unsignaled stream, if stats are working for it. |
| 3124 | rtc::scoped_refptr<const webrtc::RTCStatsReport> report = |
| 3125 | callee()->NewGetStats(); |
| 3126 | ASSERT_NE(nullptr, report); |
| 3127 | auto inbound_stream_stats = |
| 3128 | report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>(); |
| 3129 | ASSERT_EQ(1U, inbound_stream_stats.size()); |
| 3130 | ASSERT_TRUE(inbound_stream_stats[0]->bytes_received.is_defined()); |
| 3131 | ASSERT_GT(*inbound_stream_stats[0]->bytes_received, 0U); |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 3132 | ASSERT_TRUE(inbound_stream_stats[0]->track_id.is_defined()); |
| 3133 | } |
| 3134 | |
Taylor Brandstetter | a465344 | 2018-06-19 09:44:26 -0700 | [diff] [blame] | 3135 | // Same as above but for the legacy stats implementation. |
| 3136 | TEST_P(PeerConnectionIntegrationTest, |
| 3137 | GetStatsForUnsignaledStreamWithOldStatsApi) { |
| 3138 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3139 | ConnectFakeSignaling(); |
| 3140 | caller()->AddAudioTrack(); |
| 3141 | // Remove SSRCs and MSIDs from the received offer SDP. |
| 3142 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 3143 | caller()->CreateAndSetAndSignalOffer(); |
| 3144 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3145 | |
| 3146 | // Note that, since the old stats implementation associates SSRCs with tracks |
| 3147 | // using SDP, when SSRCs aren't signaled in SDP these stats won't have an |
| 3148 | // associated track ID. So we can't use the track "selector" argument. |
| 3149 | // |
| 3150 | // Also, we use "EXPECT_TRUE_WAIT" because the stats collector may decide to |
| 3151 | // return cached stats if not enough time has passed since the last update. |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 3152 | EXPECT_TRUE_WAIT(callee()->OldGetStats()->BytesReceived() > 0, |
Taylor Brandstetter | a465344 | 2018-06-19 09:44:26 -0700 | [diff] [blame] | 3153 | kDefaultTimeout); |
| 3154 | } |
| 3155 | |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 3156 | // Test that we can successfully get the media related stats (audio level |
| 3157 | // etc.) for the unsignaled stream. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3158 | TEST_P(PeerConnectionIntegrationTest, |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 3159 | GetMediaStatsForUnsignaledStreamWithNewStatsApi) { |
| 3160 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3161 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3162 | caller()->AddAudioVideoTracks(); |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 3163 | // Remove SSRCs and MSIDs from the received offer SDP. |
| 3164 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 3165 | caller()->CreateAndSetAndSignalOffer(); |
| 3166 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3167 | MediaExpectations media_expectations; |
| 3168 | media_expectations.CalleeExpectsSomeAudio(1); |
| 3169 | media_expectations.CalleeExpectsSomeVideo(1); |
| 3170 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 3171 | |
| 3172 | rtc::scoped_refptr<const webrtc::RTCStatsReport> report = |
| 3173 | callee()->NewGetStats(); |
| 3174 | ASSERT_NE(nullptr, report); |
| 3175 | |
| 3176 | auto media_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>(); |
| 3177 | auto audio_index = FindFirstMediaStatsIndexByKind("audio", media_stats); |
| 3178 | ASSERT_GE(audio_index, 0); |
| 3179 | EXPECT_TRUE(media_stats[audio_index]->audio_level.is_defined()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3180 | } |
| 3181 | |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 3182 | // Helper for test below. |
| 3183 | void ModifySsrcs(cricket::SessionDescription* desc) { |
| 3184 | for (ContentInfo& content : desc->contents()) { |
Steve Anton | df527fd | 2018-04-27 15:52:03 -0700 | [diff] [blame] | 3185 | for (StreamParams& stream : |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3186 | content.media_description()->mutable_streams()) { |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 3187 | for (uint32_t& ssrc : stream.ssrcs) { |
| 3188 | ssrc = rtc::CreateRandomId(); |
| 3189 | } |
| 3190 | } |
| 3191 | } |
| 3192 | } |
| 3193 | |
| 3194 | // Test that the "RTCMediaSteamTrackStats" object is updated correctly when |
| 3195 | // SSRCs are unsignaled, and the SSRC of the received (audio) stream changes. |
| 3196 | // This should result in two "RTCInboundRTPStreamStats", but only one |
| 3197 | // "RTCMediaStreamTrackStats", whose counters go up continuously rather than |
| 3198 | // being reset to 0 once the SSRC change occurs. |
| 3199 | // |
| 3200 | // Regression test for this bug: |
| 3201 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=8158 |
| 3202 | // |
| 3203 | // The bug causes the track stats to only represent one of the two streams: |
| 3204 | // whichever one has the higher SSRC. So with this bug, there was a 50% chance |
| 3205 | // that the track stat counters would reset to 0 when the new stream is |
| 3206 | // received, and a 50% chance that they'll stop updating (while |
| 3207 | // "concealed_samples" continues increasing, due to silence being generated for |
| 3208 | // the inactive stream). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3209 | TEST_P(PeerConnectionIntegrationTest, |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 3210 | TrackStatsUpdatedCorrectlyWhenUnsignaledSsrcChanges) { |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 3211 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3212 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3213 | caller()->AddAudioTrack(); |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 3214 | // Remove SSRCs and MSIDs from the received offer SDP, simulating an endpoint |
| 3215 | // that doesn't signal SSRCs (from the callee's perspective). |
| 3216 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 3217 | caller()->CreateAndSetAndSignalOffer(); |
| 3218 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3219 | // Wait for 50 audio frames (500ms of audio) to be received by the callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3220 | { |
| 3221 | MediaExpectations media_expectations; |
| 3222 | media_expectations.CalleeExpectsSomeAudio(50); |
| 3223 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3224 | } |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 3225 | // Some audio frames were received, so we should have nonzero "samples |
| 3226 | // received" for the track. |
| 3227 | rtc::scoped_refptr<const webrtc::RTCStatsReport> report = |
| 3228 | callee()->NewGetStats(); |
| 3229 | ASSERT_NE(nullptr, report); |
| 3230 | auto track_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>(); |
| 3231 | ASSERT_EQ(1U, track_stats.size()); |
| 3232 | ASSERT_TRUE(track_stats[0]->total_samples_received.is_defined()); |
| 3233 | ASSERT_GT(*track_stats[0]->total_samples_received, 0U); |
| 3234 | // uint64_t prev_samples_received = *track_stats[0]->total_samples_received; |
| 3235 | |
| 3236 | // Create a new offer and munge it to cause the caller to use a new SSRC. |
| 3237 | caller()->SetGeneratedSdpMunger(ModifySsrcs); |
| 3238 | caller()->CreateAndSetAndSignalOffer(); |
| 3239 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3240 | // Wait for 25 more audio frames (250ms of audio) to be received, from the new |
| 3241 | // SSRC. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3242 | { |
| 3243 | MediaExpectations media_expectations; |
| 3244 | media_expectations.CalleeExpectsSomeAudio(25); |
| 3245 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3246 | } |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 3247 | |
| 3248 | report = callee()->NewGetStats(); |
| 3249 | ASSERT_NE(nullptr, report); |
| 3250 | track_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>(); |
| 3251 | ASSERT_EQ(1U, track_stats.size()); |
| 3252 | ASSERT_TRUE(track_stats[0]->total_samples_received.is_defined()); |
| 3253 | // The "total samples received" stat should only be greater than it was |
| 3254 | // before. |
| 3255 | // TODO(deadbeef): Uncomment this assertion once the bug is completely fixed. |
| 3256 | // Right now, the new SSRC will cause the counters to reset to 0. |
| 3257 | // EXPECT_GT(*track_stats[0]->total_samples_received, prev_samples_received); |
| 3258 | |
| 3259 | // Additionally, the percentage of concealed samples (samples generated to |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 3260 | // conceal packet loss) should be less than 50%. If it's greater, that's a |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 3261 | // good sign that we're seeing stats from the old stream that's no longer |
| 3262 | // receiving packets, and is generating concealed samples of silence. |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 3263 | constexpr double kAcceptableConcealedSamplesPercentage = 0.50; |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 3264 | ASSERT_TRUE(track_stats[0]->concealed_samples.is_defined()); |
| 3265 | EXPECT_LT(*track_stats[0]->concealed_samples, |
| 3266 | *track_stats[0]->total_samples_received * |
| 3267 | kAcceptableConcealedSamplesPercentage); |
| 3268 | |
| 3269 | // Also ensure that we have two "RTCInboundRTPStreamStats" as expected, as a |
| 3270 | // sanity check that the SSRC really changed. |
| 3271 | // TODO(deadbeef): This isn't working right now, because we're not returning |
| 3272 | // *any* stats for the inactive stream. Uncomment when the bug is completely |
| 3273 | // fixed. |
| 3274 | // auto inbound_stream_stats = |
| 3275 | // report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>(); |
| 3276 | // ASSERT_EQ(2U, inbound_stream_stats.size()); |
| 3277 | } |
| 3278 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3279 | // Test that DTLS 1.0 is used if both sides only support DTLS 1.0. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3280 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithDtls10) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3281 | PeerConnectionFactory::Options dtls_10_options; |
| 3282 | dtls_10_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 3283 | ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_10_options, |
| 3284 | dtls_10_options)); |
| 3285 | ConnectFakeSignaling(); |
| 3286 | // Do normal offer/answer and wait for some frames to be received in each |
| 3287 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3288 | caller()->AddAudioVideoTracks(); |
| 3289 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3290 | caller()->CreateAndSetAndSignalOffer(); |
| 3291 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3292 | MediaExpectations media_expectations; |
| 3293 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3294 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3295 | } |
| 3296 | |
| 3297 | // Test getting cipher stats and UMA metrics when DTLS 1.0 is negotiated. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3298 | TEST_P(PeerConnectionIntegrationTest, Dtls10CipherStatsAndUmaMetrics) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3299 | PeerConnectionFactory::Options dtls_10_options; |
| 3300 | dtls_10_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 3301 | ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_10_options, |
| 3302 | dtls_10_options)); |
| 3303 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3304 | caller()->AddAudioVideoTracks(); |
| 3305 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3306 | caller()->CreateAndSetAndSignalOffer(); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 3307 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3308 | EXPECT_TRUE_WAIT(rtc::SSLStreamAdapter::IsAcceptableCipher( |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 3309 | caller()->OldGetStats()->DtlsCipher(), rtc::KT_DEFAULT), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3310 | kDefaultTimeout); |
| 3311 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 3312 | caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 3313 | // TODO(bugs.webrtc.org/9456): Fix it. |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 3314 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents( |
| 3315 | "WebRTC.PeerConnection.SrtpCryptoSuite.Audio", |
| 3316 | kDefaultSrtpCryptoSuite)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | // Test getting cipher stats and UMA metrics when DTLS 1.2 is negotiated. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3320 | TEST_P(PeerConnectionIntegrationTest, Dtls12CipherStatsAndUmaMetrics) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3321 | PeerConnectionFactory::Options dtls_12_options; |
| 3322 | dtls_12_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 3323 | ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_12_options, |
| 3324 | dtls_12_options)); |
| 3325 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3326 | caller()->AddAudioVideoTracks(); |
| 3327 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3328 | caller()->CreateAndSetAndSignalOffer(); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 3329 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3330 | EXPECT_TRUE_WAIT(rtc::SSLStreamAdapter::IsAcceptableCipher( |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 3331 | caller()->OldGetStats()->DtlsCipher(), rtc::KT_DEFAULT), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3332 | kDefaultTimeout); |
| 3333 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 3334 | caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 3335 | // TODO(bugs.webrtc.org/9456): Fix it. |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 3336 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents( |
| 3337 | "WebRTC.PeerConnection.SrtpCryptoSuite.Audio", |
| 3338 | kDefaultSrtpCryptoSuite)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3339 | } |
| 3340 | |
| 3341 | // Test that DTLS 1.0 can be used if the caller supports DTLS 1.2 and the |
| 3342 | // callee only supports 1.0. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3343 | TEST_P(PeerConnectionIntegrationTest, CallerDtls12ToCalleeDtls10) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3344 | PeerConnectionFactory::Options caller_options; |
| 3345 | caller_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 3346 | PeerConnectionFactory::Options callee_options; |
| 3347 | callee_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 3348 | ASSERT_TRUE( |
| 3349 | CreatePeerConnectionWrappersWithOptions(caller_options, callee_options)); |
| 3350 | ConnectFakeSignaling(); |
| 3351 | // Do normal offer/answer and wait for some frames to be received in each |
| 3352 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3353 | caller()->AddAudioVideoTracks(); |
| 3354 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3355 | caller()->CreateAndSetAndSignalOffer(); |
| 3356 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3357 | MediaExpectations media_expectations; |
| 3358 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3359 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3360 | } |
| 3361 | |
| 3362 | // Test that DTLS 1.0 can be used if the caller only supports DTLS 1.0 and the |
| 3363 | // callee supports 1.2. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3364 | TEST_P(PeerConnectionIntegrationTest, CallerDtls10ToCalleeDtls12) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3365 | PeerConnectionFactory::Options caller_options; |
| 3366 | caller_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 3367 | PeerConnectionFactory::Options callee_options; |
| 3368 | callee_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 3369 | ASSERT_TRUE( |
| 3370 | CreatePeerConnectionWrappersWithOptions(caller_options, callee_options)); |
| 3371 | ConnectFakeSignaling(); |
| 3372 | // Do normal offer/answer and wait for some frames to be received in each |
| 3373 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3374 | caller()->AddAudioVideoTracks(); |
| 3375 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3376 | caller()->CreateAndSetAndSignalOffer(); |
| 3377 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3378 | MediaExpectations media_expectations; |
| 3379 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3380 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3381 | } |
| 3382 | |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3383 | // The three tests below verify that "enable_aes128_sha1_32_crypto_cipher" |
| 3384 | // works as expected; the cipher should only be used if enabled by both sides. |
| 3385 | TEST_P(PeerConnectionIntegrationTest, |
| 3386 | Aes128Sha1_32_CipherNotUsedWhenOnlyCallerSupported) { |
| 3387 | PeerConnectionFactory::Options caller_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3388 | caller_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3389 | PeerConnectionFactory::Options callee_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3390 | callee_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = |
| 3391 | false; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3392 | int expected_cipher_suite = rtc::SRTP_AES128_CM_SHA1_80; |
| 3393 | TestNegotiatedCipherSuite(caller_options, callee_options, |
| 3394 | expected_cipher_suite); |
| 3395 | } |
| 3396 | |
| 3397 | TEST_P(PeerConnectionIntegrationTest, |
| 3398 | Aes128Sha1_32_CipherNotUsedWhenOnlyCalleeSupported) { |
| 3399 | PeerConnectionFactory::Options caller_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3400 | caller_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = |
| 3401 | false; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3402 | PeerConnectionFactory::Options callee_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3403 | callee_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3404 | int expected_cipher_suite = rtc::SRTP_AES128_CM_SHA1_80; |
| 3405 | TestNegotiatedCipherSuite(caller_options, callee_options, |
| 3406 | expected_cipher_suite); |
| 3407 | } |
| 3408 | |
| 3409 | TEST_P(PeerConnectionIntegrationTest, Aes128Sha1_32_CipherUsedWhenSupported) { |
| 3410 | PeerConnectionFactory::Options caller_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3411 | caller_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3412 | PeerConnectionFactory::Options callee_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3413 | callee_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3414 | int expected_cipher_suite = rtc::SRTP_AES128_CM_SHA1_32; |
| 3415 | TestNegotiatedCipherSuite(caller_options, callee_options, |
| 3416 | expected_cipher_suite); |
| 3417 | } |
| 3418 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3419 | // Test that a non-GCM cipher is used if both sides only support non-GCM. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3420 | TEST_P(PeerConnectionIntegrationTest, NonGcmCipherUsedWhenGcmNotSupported) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3421 | bool local_gcm_enabled = false; |
| 3422 | bool remote_gcm_enabled = false; |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 3423 | bool aes_ctr_enabled = true; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3424 | int expected_cipher_suite = kDefaultSrtpCryptoSuite; |
| 3425 | TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled, |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 3426 | aes_ctr_enabled, expected_cipher_suite); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3427 | } |
| 3428 | |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 3429 | // Test that a GCM cipher is used if both ends support it and non-GCM is |
| 3430 | // disabled. |
| 3431 | TEST_P(PeerConnectionIntegrationTest, GcmCipherUsedWhenOnlyGcmSupported) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3432 | bool local_gcm_enabled = true; |
| 3433 | bool remote_gcm_enabled = true; |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 3434 | bool aes_ctr_enabled = false; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3435 | int expected_cipher_suite = kDefaultSrtpCryptoSuiteGcm; |
| 3436 | TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled, |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 3437 | aes_ctr_enabled, expected_cipher_suite); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3438 | } |
| 3439 | |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3440 | // Verify that media can be transmitted end-to-end when GCM crypto suites are |
| 3441 | // enabled. Note that the above tests, such as GcmCipherUsedWhenGcmSupported, |
| 3442 | // only verify that a GCM cipher is negotiated, and not necessarily that SRTP |
| 3443 | // works with it. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3444 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithGcmCipher) { |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3445 | PeerConnectionFactory::Options gcm_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3446 | gcm_options.crypto_options.srtp.enable_gcm_crypto_suites = true; |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 3447 | gcm_options.crypto_options.srtp.enable_aes128_sha1_80_crypto_cipher = false; |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3448 | ASSERT_TRUE( |
| 3449 | CreatePeerConnectionWrappersWithOptions(gcm_options, gcm_options)); |
| 3450 | ConnectFakeSignaling(); |
| 3451 | // Do normal offer/answer and wait for some frames to be received in each |
| 3452 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3453 | caller()->AddAudioVideoTracks(); |
| 3454 | callee()->AddAudioVideoTracks(); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3455 | caller()->CreateAndSetAndSignalOffer(); |
| 3456 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3457 | MediaExpectations media_expectations; |
| 3458 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3459 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3460 | } |
| 3461 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3462 | // This test sets up a call between two parties with audio, video and an RTP |
| 3463 | // data channel. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3464 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithRtpDataChannel) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3465 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3466 | rtc_config.enable_rtp_data_channel = true; |
| 3467 | rtc_config.enable_dtls_srtp = false; |
| 3468 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3469 | ConnectFakeSignaling(); |
| 3470 | // Expect that data channel created on caller side will show up for callee as |
| 3471 | // well. |
| 3472 | caller()->CreateDataChannel(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3473 | caller()->AddAudioVideoTracks(); |
| 3474 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3475 | caller()->CreateAndSetAndSignalOffer(); |
| 3476 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3477 | // Ensure the existence of the RTP data channel didn't impede audio/video. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3478 | MediaExpectations media_expectations; |
| 3479 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3480 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3481 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3482 | ASSERT_NE(nullptr, callee()->data_channel()); |
| 3483 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3484 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3485 | |
| 3486 | // Ensure data can be sent in both directions. |
| 3487 | std::string data = "hello world"; |
| 3488 | SendRtpDataWithRetries(caller()->data_channel(), data, 5); |
| 3489 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3490 | kDefaultTimeout); |
| 3491 | SendRtpDataWithRetries(callee()->data_channel(), data, 5); |
| 3492 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3493 | kDefaultTimeout); |
| 3494 | } |
| 3495 | |
Eldar Rello | d9ebe01 | 2020-03-18 20:41:45 +0200 | [diff] [blame] | 3496 | TEST_P(PeerConnectionIntegrationTest, RtpDataChannelWorksAfterRollback) { |
| 3497 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3498 | rtc_config.enable_rtp_data_channel = true; |
| 3499 | rtc_config.enable_dtls_srtp = false; |
| 3500 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config)); |
| 3501 | ConnectFakeSignaling(); |
| 3502 | auto data_channel = caller()->pc()->CreateDataChannel("label_1", nullptr); |
| 3503 | ASSERT_TRUE(data_channel.get() != nullptr); |
| 3504 | caller()->CreateAndSetAndSignalOffer(); |
| 3505 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3506 | |
| 3507 | caller()->CreateDataChannel("label_2", nullptr); |
| 3508 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer( |
| 3509 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
| 3510 | caller()->pc()->SetLocalDescription(observer, |
| 3511 | caller()->CreateOfferAndWait().release()); |
| 3512 | EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout); |
| 3513 | caller()->Rollback(); |
| 3514 | |
| 3515 | std::string data = "hello world"; |
| 3516 | SendRtpDataWithRetries(data_channel, data, 5); |
| 3517 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3518 | kDefaultTimeout); |
| 3519 | } |
| 3520 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3521 | // Ensure that an RTP data channel is signaled as closed for the caller when |
| 3522 | // the callee rejects it in a subsequent offer. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3523 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3524 | RtpDataChannelSignaledClosedInCalleeOffer) { |
| 3525 | // Same procedure as above test. |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3526 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3527 | rtc_config.enable_rtp_data_channel = true; |
| 3528 | rtc_config.enable_dtls_srtp = false; |
| 3529 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3530 | ConnectFakeSignaling(); |
| 3531 | caller()->CreateDataChannel(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3532 | caller()->AddAudioVideoTracks(); |
| 3533 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3534 | caller()->CreateAndSetAndSignalOffer(); |
| 3535 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3536 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3537 | ASSERT_NE(nullptr, callee()->data_channel()); |
| 3538 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3539 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3540 | |
| 3541 | // Close the data channel on the callee, and do an updated offer/answer. |
| 3542 | callee()->data_channel()->Close(); |
| 3543 | callee()->CreateAndSetAndSignalOffer(); |
| 3544 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3545 | EXPECT_FALSE(caller()->data_observer()->IsOpen()); |
| 3546 | EXPECT_FALSE(callee()->data_observer()->IsOpen()); |
| 3547 | } |
| 3548 | |
| 3549 | // Tests that data is buffered in an RTP data channel until an observer is |
| 3550 | // registered for it. |
| 3551 | // |
| 3552 | // NOTE: RTP data channels can receive data before the underlying |
| 3553 | // transport has detected that a channel is writable and thus data can be |
| 3554 | // received before the data channel state changes to open. That is hard to test |
| 3555 | // but the same buffering is expected to be used in that case. |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 3556 | // |
| 3557 | // Use fake clock and simulated network delay so that we predictably can wait |
| 3558 | // until an SCTP message has been delivered without "sleep()"ing. |
| 3559 | TEST_P(PeerConnectionIntegrationTestWithFakeClock, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3560 | DataBufferedUntilRtpDataChannelObserverRegistered) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3561 | virtual_socket_server()->set_delay_mean(5); // 5 ms per hop. |
| 3562 | virtual_socket_server()->UpdateDelayDistribution(); |
| 3563 | |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3564 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3565 | rtc_config.enable_rtp_data_channel = true; |
| 3566 | rtc_config.enable_dtls_srtp = false; |
| 3567 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3568 | ConnectFakeSignaling(); |
| 3569 | caller()->CreateDataChannel(); |
| 3570 | caller()->CreateAndSetAndSignalOffer(); |
| 3571 | ASSERT_TRUE(caller()->data_channel() != nullptr); |
| 3572 | ASSERT_TRUE_SIMULATED_WAIT(callee()->data_channel() != nullptr, |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 3573 | kDefaultTimeout, FakeClock()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3574 | ASSERT_TRUE_SIMULATED_WAIT(caller()->data_observer()->IsOpen(), |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 3575 | kDefaultTimeout, FakeClock()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3576 | ASSERT_EQ_SIMULATED_WAIT(DataChannelInterface::kOpen, |
| 3577 | callee()->data_channel()->state(), kDefaultTimeout, |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 3578 | FakeClock()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3579 | |
| 3580 | // Unregister the observer which is normally automatically registered. |
| 3581 | callee()->data_channel()->UnregisterObserver(); |
| 3582 | // Send data and advance fake clock until it should have been received. |
| 3583 | std::string data = "hello world"; |
| 3584 | caller()->data_channel()->Send(DataBuffer(data)); |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 3585 | SIMULATED_WAIT(false, 50, FakeClock()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3586 | |
| 3587 | // Attach data channel and expect data to be received immediately. Note that |
| 3588 | // EXPECT_EQ_WAIT is used, such that the simulated clock is not advanced any |
| 3589 | // further, but data can be received even if the callback is asynchronous. |
| 3590 | MockDataChannelObserver new_observer(callee()->data_channel()); |
| 3591 | EXPECT_EQ_SIMULATED_WAIT(data, new_observer.last_message(), kDefaultTimeout, |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 3592 | FakeClock()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3593 | } |
| 3594 | |
| 3595 | // This test sets up a call between two parties with audio, video and but only |
| 3596 | // the caller client supports RTP data channels. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3597 | TEST_P(PeerConnectionIntegrationTest, RtpDataChannelsRejectedByCallee) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3598 | PeerConnectionInterface::RTCConfiguration rtc_config_1; |
| 3599 | rtc_config_1.enable_rtp_data_channel = true; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3600 | // Must disable DTLS to make negotiation succeed. |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3601 | rtc_config_1.enable_dtls_srtp = false; |
| 3602 | PeerConnectionInterface::RTCConfiguration rtc_config_2; |
| 3603 | rtc_config_2.enable_dtls_srtp = false; |
| 3604 | rtc_config_2.enable_dtls_srtp = false; |
| 3605 | ASSERT_TRUE( |
| 3606 | CreatePeerConnectionWrappersWithConfig(rtc_config_1, rtc_config_2)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3607 | ConnectFakeSignaling(); |
| 3608 | caller()->CreateDataChannel(); |
Harald Alvestrand | f3736ed | 2019-04-08 13:09:30 +0200 | [diff] [blame] | 3609 | ASSERT_TRUE(caller()->data_channel() != nullptr); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3610 | caller()->AddAudioVideoTracks(); |
| 3611 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3612 | caller()->CreateAndSetAndSignalOffer(); |
| 3613 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3614 | // The caller should still have a data channel, but it should be closed, and |
| 3615 | // one should ever have been created for the callee. |
| 3616 | EXPECT_TRUE(caller()->data_channel() != nullptr); |
| 3617 | EXPECT_FALSE(caller()->data_observer()->IsOpen()); |
| 3618 | EXPECT_EQ(nullptr, callee()->data_channel()); |
| 3619 | } |
| 3620 | |
| 3621 | // This test sets up a call between two parties with audio, and video. When |
| 3622 | // audio and video is setup and flowing, an RTP data channel is negotiated. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3623 | TEST_P(PeerConnectionIntegrationTest, AddRtpDataChannelInSubsequentOffer) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3624 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3625 | rtc_config.enable_rtp_data_channel = true; |
| 3626 | rtc_config.enable_dtls_srtp = false; |
| 3627 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3628 | ConnectFakeSignaling(); |
| 3629 | // Do initial offer/answer with audio/video. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3630 | caller()->AddAudioVideoTracks(); |
| 3631 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3632 | caller()->CreateAndSetAndSignalOffer(); |
| 3633 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3634 | // Create data channel and do new offer and answer. |
| 3635 | caller()->CreateDataChannel(); |
| 3636 | caller()->CreateAndSetAndSignalOffer(); |
| 3637 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3638 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3639 | ASSERT_NE(nullptr, callee()->data_channel()); |
| 3640 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3641 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3642 | // Ensure data can be sent in both directions. |
| 3643 | std::string data = "hello world"; |
| 3644 | SendRtpDataWithRetries(caller()->data_channel(), data, 5); |
| 3645 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3646 | kDefaultTimeout); |
| 3647 | SendRtpDataWithRetries(callee()->data_channel(), data, 5); |
| 3648 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3649 | kDefaultTimeout); |
| 3650 | } |
| 3651 | |
| 3652 | #ifdef HAVE_SCTP |
| 3653 | |
| 3654 | // This test sets up a call between two parties with audio, video and an SCTP |
| 3655 | // data channel. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3656 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithSctpDataChannel) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3657 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3658 | ConnectFakeSignaling(); |
| 3659 | // Expect that data channel created on caller side will show up for callee as |
| 3660 | // well. |
| 3661 | caller()->CreateDataChannel(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3662 | caller()->AddAudioVideoTracks(); |
| 3663 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3664 | caller()->CreateAndSetAndSignalOffer(); |
| 3665 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3666 | // Ensure the existence of the SCTP data channel didn't impede audio/video. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3667 | MediaExpectations media_expectations; |
| 3668 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3669 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3670 | // Caller data channel should already exist (it created one). Callee data |
| 3671 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 3672 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3673 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3674 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3675 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3676 | |
| 3677 | // Ensure data can be sent in both directions. |
| 3678 | std::string data = "hello world"; |
| 3679 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3680 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3681 | kDefaultTimeout); |
| 3682 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3683 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3684 | kDefaultTimeout); |
| 3685 | } |
| 3686 | |
| 3687 | // Ensure that when the callee closes an SCTP data channel, the closing |
| 3688 | // procedure results in the data channel being closed for the caller as well. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3689 | TEST_P(PeerConnectionIntegrationTest, CalleeClosesSctpDataChannel) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3690 | // Same procedure as above test. |
| 3691 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3692 | ConnectFakeSignaling(); |
| 3693 | caller()->CreateDataChannel(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3694 | caller()->AddAudioVideoTracks(); |
| 3695 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3696 | caller()->CreateAndSetAndSignalOffer(); |
| 3697 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3698 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3699 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3700 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3701 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3702 | |
| 3703 | // Close the data channel on the callee side, and wait for it to reach the |
| 3704 | // "closed" state on both sides. |
| 3705 | callee()->data_channel()->Close(); |
| 3706 | EXPECT_TRUE_WAIT(!caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3707 | EXPECT_TRUE_WAIT(!callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3708 | } |
| 3709 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3710 | TEST_P(PeerConnectionIntegrationTest, SctpDataChannelConfigSentToOtherSide) { |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 3711 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3712 | ConnectFakeSignaling(); |
| 3713 | webrtc::DataChannelInit init; |
| 3714 | init.id = 53; |
| 3715 | init.maxRetransmits = 52; |
| 3716 | caller()->CreateDataChannel("data-channel", &init); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3717 | caller()->AddAudioVideoTracks(); |
| 3718 | callee()->AddAudioVideoTracks(); |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 3719 | caller()->CreateAndSetAndSignalOffer(); |
| 3720 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Steve Anton | 074dece | 2017-10-24 13:04:12 -0700 | [diff] [blame] | 3721 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3722 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
Harald Alvestrand | 5c4d2ee | 2019-04-01 12:58:15 +0200 | [diff] [blame] | 3723 | // Since "negotiated" is false, the "id" parameter should be ignored. |
| 3724 | EXPECT_NE(init.id, callee()->data_channel()->id()); |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 3725 | EXPECT_EQ("data-channel", callee()->data_channel()->label()); |
| 3726 | EXPECT_EQ(init.maxRetransmits, callee()->data_channel()->maxRetransmits()); |
| 3727 | EXPECT_FALSE(callee()->data_channel()->negotiated()); |
| 3728 | } |
| 3729 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3730 | // Test usrsctp's ability to process unordered data stream, where data actually |
| 3731 | // arrives out of order using simulated delays. Previously there have been some |
| 3732 | // bugs in this area. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3733 | TEST_P(PeerConnectionIntegrationTest, StressTestUnorderedSctpDataChannel) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3734 | // Introduce random network delays. |
| 3735 | // Otherwise it's not a true "unordered" test. |
| 3736 | virtual_socket_server()->set_delay_mean(20); |
| 3737 | virtual_socket_server()->set_delay_stddev(5); |
| 3738 | virtual_socket_server()->UpdateDelayDistribution(); |
| 3739 | // Normal procedure, but with unordered data channel config. |
| 3740 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3741 | ConnectFakeSignaling(); |
| 3742 | webrtc::DataChannelInit init; |
| 3743 | init.ordered = false; |
| 3744 | caller()->CreateDataChannel(&init); |
| 3745 | caller()->CreateAndSetAndSignalOffer(); |
| 3746 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3747 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3748 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3749 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3750 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3751 | |
| 3752 | static constexpr int kNumMessages = 100; |
| 3753 | // Deliberately chosen to be larger than the MTU so messages get fragmented. |
| 3754 | static constexpr size_t kMaxMessageSize = 4096; |
| 3755 | // Create and send random messages. |
| 3756 | std::vector<std::string> sent_messages; |
| 3757 | for (int i = 0; i < kNumMessages; ++i) { |
| 3758 | size_t length = |
| 3759 | (rand() % kMaxMessageSize) + 1; // NOLINT (rand_r instead of rand) |
| 3760 | std::string message; |
| 3761 | ASSERT_TRUE(rtc::CreateRandomString(length, &message)); |
| 3762 | caller()->data_channel()->Send(DataBuffer(message)); |
| 3763 | callee()->data_channel()->Send(DataBuffer(message)); |
| 3764 | sent_messages.push_back(message); |
| 3765 | } |
| 3766 | |
| 3767 | // Wait for all messages to be received. |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 3768 | EXPECT_EQ_WAIT(rtc::checked_cast<size_t>(kNumMessages), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3769 | caller()->data_observer()->received_message_count(), |
| 3770 | kDefaultTimeout); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 3771 | EXPECT_EQ_WAIT(rtc::checked_cast<size_t>(kNumMessages), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3772 | callee()->data_observer()->received_message_count(), |
| 3773 | kDefaultTimeout); |
| 3774 | |
| 3775 | // Sort and compare to make sure none of the messages were corrupted. |
| 3776 | std::vector<std::string> caller_received_messages = |
| 3777 | caller()->data_observer()->messages(); |
| 3778 | std::vector<std::string> callee_received_messages = |
| 3779 | callee()->data_observer()->messages(); |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 3780 | absl::c_sort(sent_messages); |
| 3781 | absl::c_sort(caller_received_messages); |
| 3782 | absl::c_sort(callee_received_messages); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3783 | EXPECT_EQ(sent_messages, caller_received_messages); |
| 3784 | EXPECT_EQ(sent_messages, callee_received_messages); |
| 3785 | } |
| 3786 | |
| 3787 | // This test sets up a call between two parties with audio, and video. When |
| 3788 | // audio and video are setup and flowing, an SCTP data channel is negotiated. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3789 | TEST_P(PeerConnectionIntegrationTest, AddSctpDataChannelInSubsequentOffer) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3790 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3791 | ConnectFakeSignaling(); |
| 3792 | // Do initial offer/answer with audio/video. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3793 | caller()->AddAudioVideoTracks(); |
| 3794 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3795 | caller()->CreateAndSetAndSignalOffer(); |
| 3796 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3797 | // Create data channel and do new offer and answer. |
| 3798 | caller()->CreateDataChannel(); |
| 3799 | caller()->CreateAndSetAndSignalOffer(); |
| 3800 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3801 | // Caller data channel should already exist (it created one). Callee data |
| 3802 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 3803 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3804 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3805 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3806 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3807 | // Ensure data can be sent in both directions. |
| 3808 | std::string data = "hello world"; |
| 3809 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3810 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3811 | kDefaultTimeout); |
| 3812 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3813 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3814 | kDefaultTimeout); |
| 3815 | } |
| 3816 | |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3817 | // Set up a connection initially just using SCTP data channels, later upgrading |
| 3818 | // to audio/video, ensuring frames are received end-to-end. Effectively the |
| 3819 | // inverse of the test above. |
| 3820 | // This was broken in M57; see https://crbug.com/711243 |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3821 | TEST_P(PeerConnectionIntegrationTest, SctpDataChannelToAudioVideoUpgrade) { |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3822 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3823 | ConnectFakeSignaling(); |
| 3824 | // Do initial offer/answer with just data channel. |
| 3825 | caller()->CreateDataChannel(); |
| 3826 | caller()->CreateAndSetAndSignalOffer(); |
| 3827 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3828 | // Wait until data can be sent over the data channel. |
| 3829 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3830 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3831 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3832 | |
| 3833 | // Do subsequent offer/answer with two-way audio and video. Audio and video |
| 3834 | // should end up bundled on the DTLS/ICE transport already used for data. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3835 | caller()->AddAudioVideoTracks(); |
| 3836 | callee()->AddAudioVideoTracks(); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3837 | caller()->CreateAndSetAndSignalOffer(); |
| 3838 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3839 | MediaExpectations media_expectations; |
| 3840 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3841 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3842 | } |
| 3843 | |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 3844 | static void MakeSpecCompliantSctpOffer(cricket::SessionDescription* desc) { |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 3845 | cricket::SctpDataContentDescription* dcd_offer = |
| 3846 | GetFirstSctpDataContentDescription(desc); |
Harald Alvestrand | 17ea068 | 2019-12-13 11:51:04 +0100 | [diff] [blame] | 3847 | // See https://crbug.com/webrtc/11211 - this function is a no-op |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3848 | ASSERT_TRUE(dcd_offer); |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 3849 | dcd_offer->set_use_sctpmap(false); |
| 3850 | dcd_offer->set_protocol("UDP/DTLS/SCTP"); |
| 3851 | } |
| 3852 | |
| 3853 | // Test that the data channel works when a spec-compliant SCTP m= section is |
| 3854 | // offered (using "a=sctp-port" instead of "a=sctpmap", and using |
| 3855 | // "UDP/DTLS/SCTP" as the protocol). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3856 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 3857 | DataChannelWorksWhenSpecCompliantSctpOfferReceived) { |
| 3858 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3859 | ConnectFakeSignaling(); |
| 3860 | caller()->CreateDataChannel(); |
| 3861 | caller()->SetGeneratedSdpMunger(MakeSpecCompliantSctpOffer); |
| 3862 | caller()->CreateAndSetAndSignalOffer(); |
| 3863 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3864 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3865 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3866 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3867 | |
| 3868 | // Ensure data can be sent in both directions. |
| 3869 | std::string data = "hello world"; |
| 3870 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3871 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3872 | kDefaultTimeout); |
| 3873 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3874 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3875 | kDefaultTimeout); |
| 3876 | } |
| 3877 | |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 3878 | // Tests that the datagram transport to SCTP fallback works correctly when |
| 3879 | // datagram transport negotiation fails. |
| 3880 | TEST_P(PeerConnectionIntegrationTest, |
| 3881 | DatagramTransportDataChannelFallbackToSctp) { |
| 3882 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3883 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3884 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3885 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 3886 | |
| 3887 | // Configure one endpoint to use datagram transport for data channels while |
| 3888 | // the other does not. |
| 3889 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3890 | rtc_config, RTCConfiguration(), |
| 3891 | loopback_media_transports()->first_factory(), nullptr)); |
| 3892 | ConnectFakeSignaling(); |
| 3893 | |
| 3894 | // The caller offers a data channel using either datagram transport or SCTP. |
| 3895 | caller()->CreateDataChannel(); |
| 3896 | caller()->AddAudioVideoTracks(); |
| 3897 | callee()->AddAudioVideoTracks(); |
| 3898 | caller()->CreateAndSetAndSignalOffer(); |
| 3899 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3900 | |
| 3901 | // Negotiation should fallback to SCTP, allowing the data channel to be |
| 3902 | // established. |
| 3903 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3904 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3905 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3906 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3907 | |
| 3908 | // Ensure data can be sent in both directions. |
| 3909 | std::string data = "hello world"; |
| 3910 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3911 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3912 | kDefaultTimeout); |
| 3913 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3914 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3915 | kDefaultTimeout); |
| 3916 | |
| 3917 | // Ensure that failure of the datagram negotiation doesn't impede media flow. |
| 3918 | MediaExpectations media_expectations; |
| 3919 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3920 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3921 | } |
| 3922 | |
Bjorn A Mellem | fc604aa | 2019-09-24 14:59:21 -0700 | [diff] [blame] | 3923 | // Tests that the data channel transport works correctly when datagram transport |
| 3924 | // negotiation succeeds and does not fall back to SCTP. |
| 3925 | TEST_P(PeerConnectionIntegrationTest, |
| 3926 | DatagramTransportDataChannelDoesNotFallbackToSctp) { |
| 3927 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3928 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3929 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3930 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 3931 | |
| 3932 | // Configure one endpoint to use datagram transport for data channels while |
| 3933 | // the other does not. |
| 3934 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3935 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 3936 | loopback_media_transports()->second_factory())); |
| 3937 | ConnectFakeSignaling(); |
| 3938 | |
| 3939 | // The caller offers a data channel using either datagram transport or SCTP. |
| 3940 | caller()->CreateDataChannel(); |
| 3941 | caller()->AddAudioVideoTracks(); |
| 3942 | callee()->AddAudioVideoTracks(); |
| 3943 | caller()->CreateAndSetAndSignalOffer(); |
| 3944 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3945 | |
| 3946 | // Ensure that the data channel transport is ready. |
| 3947 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 3948 | loopback_media_transports()->FlushAsyncInvokes(); |
| 3949 | |
| 3950 | // Negotiation should succeed, allowing the data channel to be established. |
| 3951 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3952 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3953 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3954 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3955 | |
| 3956 | // Ensure data can be sent in both directions. |
| 3957 | std::string data = "hello world"; |
| 3958 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3959 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3960 | kDefaultTimeout); |
| 3961 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3962 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3963 | kDefaultTimeout); |
| 3964 | |
| 3965 | // Ensure that failure of the datagram negotiation doesn't impede media flow. |
| 3966 | MediaExpectations media_expectations; |
| 3967 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3968 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3969 | } |
| 3970 | |
Bjorn A Mellem | 0cda7b8 | 2020-01-28 17:06:55 -0800 | [diff] [blame] | 3971 | // Tests that the datagram transport to SCTP fallback works correctly when |
| 3972 | // datagram transports do not advertise compatible transport parameters. |
| 3973 | TEST_P(PeerConnectionIntegrationTest, |
| 3974 | DatagramTransportIncompatibleParametersFallsBackToSctp) { |
| 3975 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3976 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3977 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3978 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 3979 | |
| 3980 | // By default, only equal parameters are compatible. |
| 3981 | loopback_media_transports()->SetFirstDatagramTransportParameters("foo"); |
| 3982 | loopback_media_transports()->SetSecondDatagramTransportParameters("bar"); |
| 3983 | |
| 3984 | // Configure one endpoint to use datagram transport for data channels while |
| 3985 | // the other does not. |
| 3986 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3987 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 3988 | loopback_media_transports()->second_factory())); |
| 3989 | ConnectFakeSignaling(); |
| 3990 | |
| 3991 | // The caller offers a data channel using either datagram transport or SCTP. |
| 3992 | caller()->CreateDataChannel(); |
| 3993 | caller()->AddAudioVideoTracks(); |
| 3994 | callee()->AddAudioVideoTracks(); |
| 3995 | caller()->CreateAndSetAndSignalOffer(); |
| 3996 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3997 | |
| 3998 | // Negotiation should fallback to SCTP, allowing the data channel to be |
| 3999 | // established. |
| 4000 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4001 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4002 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4003 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4004 | |
| 4005 | // Both endpoints should agree to use SCTP for data channels. |
| 4006 | EXPECT_NE(nullptr, caller()->pc()->GetSctpTransport()); |
| 4007 | EXPECT_NE(nullptr, callee()->pc()->GetSctpTransport()); |
| 4008 | |
| 4009 | // Ensure data can be sent in both directions. |
| 4010 | std::string data = "hello world"; |
| 4011 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4012 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4013 | kDefaultTimeout); |
| 4014 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4015 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4016 | kDefaultTimeout); |
| 4017 | |
| 4018 | // Ensure that failure of the datagram negotiation doesn't impede media flow. |
| 4019 | MediaExpectations media_expectations; |
| 4020 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4021 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4022 | } |
| 4023 | |
| 4024 | // Tests that the datagram transport to SCTP fallback works correctly when |
| 4025 | // only the answerer believes datagram transport parameters are incompatible. |
| 4026 | TEST_P(PeerConnectionIntegrationTest, |
| 4027 | DatagramTransportIncompatibleParametersOnAnswererFallsBackToSctp) { |
| 4028 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4029 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4030 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4031 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 4032 | |
| 4033 | // By default, only equal parameters are compatible. |
| 4034 | loopback_media_transports()->SetFirstDatagramTransportParameters("foo"); |
| 4035 | loopback_media_transports()->SetSecondDatagramTransportParameters("bar"); |
| 4036 | |
| 4037 | // Set the offerer to accept different parameters, while the answerer rejects |
| 4038 | // them. |
| 4039 | loopback_media_transports()->SetFirstDatagramTransportParametersComparison( |
| 4040 | [](absl::string_view a, absl::string_view b) { return true; }); |
| 4041 | loopback_media_transports()->SetSecondDatagramTransportParametersComparison( |
| 4042 | [](absl::string_view a, absl::string_view b) { return false; }); |
| 4043 | |
| 4044 | // Configure one endpoint to use datagram transport for data channels while |
| 4045 | // the other does not. |
| 4046 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4047 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4048 | loopback_media_transports()->second_factory())); |
| 4049 | ConnectFakeSignaling(); |
| 4050 | |
| 4051 | // The caller offers a data channel using either datagram transport or SCTP. |
| 4052 | caller()->CreateDataChannel(); |
| 4053 | caller()->AddAudioVideoTracks(); |
| 4054 | callee()->AddAudioVideoTracks(); |
| 4055 | caller()->CreateAndSetAndSignalOffer(); |
| 4056 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4057 | |
| 4058 | // Negotiation should fallback to SCTP, allowing the data channel to be |
| 4059 | // established. |
| 4060 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4061 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4062 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4063 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4064 | |
| 4065 | // Both endpoints should agree to use SCTP for data channels. |
| 4066 | EXPECT_NE(nullptr, caller()->pc()->GetSctpTransport()); |
| 4067 | EXPECT_NE(nullptr, callee()->pc()->GetSctpTransport()); |
| 4068 | |
| 4069 | // Ensure data can be sent in both directions. |
| 4070 | std::string data = "hello world"; |
| 4071 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4072 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4073 | kDefaultTimeout); |
| 4074 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4075 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4076 | kDefaultTimeout); |
| 4077 | |
| 4078 | // Ensure that failure of the datagram negotiation doesn't impede media flow. |
| 4079 | MediaExpectations media_expectations; |
| 4080 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4081 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4082 | } |
| 4083 | |
| 4084 | // Tests that the data channel transport works correctly when datagram |
| 4085 | // transports provide different, but compatible, transport parameters. |
| 4086 | TEST_P(PeerConnectionIntegrationTest, |
| 4087 | DatagramTransportCompatibleParametersDoNotFallbackToSctp) { |
| 4088 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4089 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4090 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4091 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 4092 | |
| 4093 | // By default, only equal parameters are compatible. |
| 4094 | loopback_media_transports()->SetFirstDatagramTransportParameters("foo"); |
| 4095 | loopback_media_transports()->SetSecondDatagramTransportParameters("bar"); |
| 4096 | |
| 4097 | // Change the comparison used to treat these transport parameters are |
| 4098 | // compatible (on both sides). |
| 4099 | loopback_media_transports()->SetFirstDatagramTransportParametersComparison( |
| 4100 | [](absl::string_view a, absl::string_view b) { return true; }); |
| 4101 | loopback_media_transports()->SetSecondDatagramTransportParametersComparison( |
| 4102 | [](absl::string_view a, absl::string_view b) { return true; }); |
| 4103 | |
| 4104 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4105 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4106 | loopback_media_transports()->second_factory())); |
| 4107 | ConnectFakeSignaling(); |
| 4108 | |
| 4109 | // The caller offers a data channel using either datagram transport or SCTP. |
| 4110 | caller()->CreateDataChannel(); |
| 4111 | caller()->AddAudioVideoTracks(); |
| 4112 | callee()->AddAudioVideoTracks(); |
| 4113 | caller()->CreateAndSetAndSignalOffer(); |
| 4114 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4115 | |
| 4116 | // Ensure that the data channel transport is ready. |
| 4117 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4118 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4119 | |
| 4120 | // Negotiation should succeed, allowing the data channel to be established. |
| 4121 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4122 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4123 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4124 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4125 | |
| 4126 | // Both endpoints should agree to use datagram transport for data channels. |
| 4127 | EXPECT_EQ(nullptr, caller()->pc()->GetSctpTransport()); |
| 4128 | EXPECT_EQ(nullptr, callee()->pc()->GetSctpTransport()); |
| 4129 | |
| 4130 | // Ensure data can be sent in both directions. |
| 4131 | std::string data = "hello world"; |
| 4132 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4133 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4134 | kDefaultTimeout); |
| 4135 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4136 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4137 | kDefaultTimeout); |
| 4138 | |
| 4139 | // Ensure that failure of the datagram negotiation doesn't impede media flow. |
| 4140 | MediaExpectations media_expectations; |
| 4141 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4142 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4143 | } |
| 4144 | |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 4145 | TEST_P(PeerConnectionIntegrationTest, |
| 4146 | DatagramTransportDataChannelWithMediaOnCaller) { |
| 4147 | // Configure the caller to attempt use of datagram transport for media and |
| 4148 | // data channels. |
| 4149 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 4150 | offerer_config.rtcp_mux_policy = |
| 4151 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4152 | offerer_config.bundle_policy = |
| 4153 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4154 | offerer_config.use_datagram_transport_for_data_channels = true; |
| 4155 | offerer_config.use_datagram_transport = true; |
| 4156 | |
| 4157 | // Configure the callee to only use datagram transport for data channels. |
| 4158 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 4159 | answerer_config.rtcp_mux_policy = |
| 4160 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4161 | answerer_config.bundle_policy = |
| 4162 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4163 | answerer_config.use_datagram_transport_for_data_channels = true; |
| 4164 | |
| 4165 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4166 | offerer_config, answerer_config, |
| 4167 | loopback_media_transports()->first_factory(), |
| 4168 | loopback_media_transports()->second_factory())); |
| 4169 | ConnectFakeSignaling(); |
| 4170 | |
| 4171 | // Offer both media and data. |
| 4172 | caller()->AddAudioVideoTracks(); |
| 4173 | callee()->AddAudioVideoTracks(); |
| 4174 | caller()->CreateDataChannel(); |
| 4175 | caller()->CreateAndSetAndSignalOffer(); |
| 4176 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4177 | |
| 4178 | // Ensure that the data channel transport is ready. |
| 4179 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4180 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4181 | |
| 4182 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4183 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4184 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4185 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4186 | |
| 4187 | // Both endpoints should agree to use datagram transport for data channels. |
| 4188 | EXPECT_EQ(nullptr, caller()->pc()->GetSctpTransport()); |
| 4189 | EXPECT_EQ(nullptr, callee()->pc()->GetSctpTransport()); |
| 4190 | |
| 4191 | // Ensure data can be sent in both directions. |
| 4192 | std::string data = "hello world"; |
| 4193 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4194 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4195 | kDefaultTimeout); |
| 4196 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4197 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4198 | kDefaultTimeout); |
| 4199 | |
| 4200 | // Media flow should not be impacted. |
| 4201 | MediaExpectations media_expectations; |
| 4202 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4203 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4204 | } |
| 4205 | |
| 4206 | TEST_P(PeerConnectionIntegrationTest, |
| 4207 | DatagramTransportMediaWithDataChannelOnCaller) { |
| 4208 | // Configure the caller to attempt use of datagram transport for media and |
| 4209 | // data channels. |
| 4210 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 4211 | offerer_config.rtcp_mux_policy = |
| 4212 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4213 | offerer_config.bundle_policy = |
| 4214 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4215 | offerer_config.use_datagram_transport_for_data_channels = true; |
| 4216 | offerer_config.use_datagram_transport = true; |
| 4217 | |
| 4218 | // Configure the callee to only use datagram transport for media. |
| 4219 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 4220 | answerer_config.rtcp_mux_policy = |
| 4221 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4222 | answerer_config.bundle_policy = |
| 4223 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4224 | answerer_config.use_datagram_transport = true; |
| 4225 | |
| 4226 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4227 | offerer_config, answerer_config, |
| 4228 | loopback_media_transports()->first_factory(), |
| 4229 | loopback_media_transports()->second_factory())); |
| 4230 | ConnectFakeSignaling(); |
| 4231 | |
| 4232 | // Offer both media and data. |
| 4233 | caller()->AddAudioVideoTracks(); |
| 4234 | callee()->AddAudioVideoTracks(); |
| 4235 | caller()->CreateDataChannel(); |
| 4236 | caller()->CreateAndSetAndSignalOffer(); |
| 4237 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4238 | |
| 4239 | // Ensure that the data channel transport is ready. |
| 4240 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4241 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4242 | |
| 4243 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4244 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4245 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4246 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4247 | |
| 4248 | // Both endpoints should agree to use SCTP for data channels. |
| 4249 | EXPECT_NE(nullptr, caller()->pc()->GetSctpTransport()); |
| 4250 | EXPECT_NE(nullptr, callee()->pc()->GetSctpTransport()); |
| 4251 | |
| 4252 | // Ensure data can be sent in both directions. |
| 4253 | std::string data = "hello world"; |
| 4254 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4255 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4256 | kDefaultTimeout); |
| 4257 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4258 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4259 | kDefaultTimeout); |
| 4260 | |
| 4261 | // Media flow should not be impacted. |
| 4262 | MediaExpectations media_expectations; |
| 4263 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4264 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4265 | } |
| 4266 | |
| 4267 | TEST_P(PeerConnectionIntegrationTest, |
| 4268 | DatagramTransportDataChannelWithMediaOnCallee) { |
| 4269 | // Configure the caller to attempt use of datagram transport for data |
| 4270 | // channels. |
| 4271 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 4272 | offerer_config.rtcp_mux_policy = |
| 4273 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4274 | offerer_config.bundle_policy = |
| 4275 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4276 | offerer_config.use_datagram_transport_for_data_channels = true; |
| 4277 | |
| 4278 | // Configure the callee to use datagram transport for data channels and media. |
| 4279 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 4280 | answerer_config.rtcp_mux_policy = |
| 4281 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4282 | answerer_config.bundle_policy = |
| 4283 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4284 | answerer_config.use_datagram_transport_for_data_channels = true; |
| 4285 | answerer_config.use_datagram_transport = true; |
| 4286 | |
| 4287 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4288 | offerer_config, answerer_config, |
| 4289 | loopback_media_transports()->first_factory(), |
| 4290 | loopback_media_transports()->second_factory())); |
| 4291 | ConnectFakeSignaling(); |
| 4292 | |
| 4293 | // Offer both media and data. |
| 4294 | caller()->AddAudioVideoTracks(); |
| 4295 | callee()->AddAudioVideoTracks(); |
| 4296 | caller()->CreateDataChannel(); |
| 4297 | caller()->CreateAndSetAndSignalOffer(); |
| 4298 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4299 | |
| 4300 | // Ensure that the data channel transport is ready. |
| 4301 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4302 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4303 | |
| 4304 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4305 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4306 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4307 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4308 | |
| 4309 | // Both endpoints should agree to use datagram transport for data channels. |
| 4310 | EXPECT_EQ(nullptr, caller()->pc()->GetSctpTransport()); |
| 4311 | EXPECT_EQ(nullptr, callee()->pc()->GetSctpTransport()); |
| 4312 | |
| 4313 | // Ensure data can be sent in both directions. |
| 4314 | std::string data = "hello world"; |
| 4315 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4316 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4317 | kDefaultTimeout); |
| 4318 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4319 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4320 | kDefaultTimeout); |
| 4321 | |
| 4322 | // Media flow should not be impacted. |
| 4323 | MediaExpectations media_expectations; |
| 4324 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4325 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4326 | } |
| 4327 | |
| 4328 | TEST_P(PeerConnectionIntegrationTest, |
| 4329 | DatagramTransportMediaWithDataChannelOnCallee) { |
| 4330 | // Configure the caller to attempt use of datagram transport for media. |
| 4331 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 4332 | offerer_config.rtcp_mux_policy = |
| 4333 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4334 | offerer_config.bundle_policy = |
| 4335 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4336 | offerer_config.use_datagram_transport = true; |
| 4337 | |
| 4338 | // Configure the callee to only use datagram transport for media and data |
| 4339 | // channels. |
| 4340 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 4341 | answerer_config.rtcp_mux_policy = |
| 4342 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4343 | answerer_config.bundle_policy = |
| 4344 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4345 | answerer_config.use_datagram_transport = true; |
| 4346 | answerer_config.use_datagram_transport_for_data_channels = true; |
| 4347 | |
| 4348 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4349 | offerer_config, answerer_config, |
| 4350 | loopback_media_transports()->first_factory(), |
| 4351 | loopback_media_transports()->second_factory())); |
| 4352 | ConnectFakeSignaling(); |
| 4353 | |
| 4354 | // Offer both media and data. |
| 4355 | caller()->AddAudioVideoTracks(); |
| 4356 | callee()->AddAudioVideoTracks(); |
| 4357 | caller()->CreateDataChannel(); |
| 4358 | caller()->CreateAndSetAndSignalOffer(); |
| 4359 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4360 | |
| 4361 | // Ensure that the data channel transport is ready. |
| 4362 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4363 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4364 | |
| 4365 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4366 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4367 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4368 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4369 | |
| 4370 | // Both endpoints should agree to use SCTP for data channels. |
| 4371 | EXPECT_NE(nullptr, caller()->pc()->GetSctpTransport()); |
| 4372 | EXPECT_NE(nullptr, callee()->pc()->GetSctpTransport()); |
| 4373 | |
| 4374 | // Ensure data can be sent in both directions. |
| 4375 | std::string data = "hello world"; |
| 4376 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4377 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4378 | kDefaultTimeout); |
| 4379 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4380 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4381 | kDefaultTimeout); |
| 4382 | |
| 4383 | // Media flow should not be impacted. |
| 4384 | MediaExpectations media_expectations; |
| 4385 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4386 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4387 | } |
| 4388 | |
| 4389 | TEST_P(PeerConnectionIntegrationTest, DatagramTransportDataChannelAndMedia) { |
| 4390 | // Configure the caller to use datagram transport for data channels and media. |
| 4391 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 4392 | offerer_config.rtcp_mux_policy = |
| 4393 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4394 | offerer_config.bundle_policy = |
| 4395 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4396 | offerer_config.use_datagram_transport_for_data_channels = true; |
| 4397 | offerer_config.use_datagram_transport = true; |
| 4398 | |
| 4399 | // Configure the callee to use datagram transport for data channels and media. |
| 4400 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 4401 | answerer_config.rtcp_mux_policy = |
| 4402 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4403 | answerer_config.bundle_policy = |
| 4404 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4405 | answerer_config.use_datagram_transport_for_data_channels = true; |
| 4406 | answerer_config.use_datagram_transport = true; |
| 4407 | |
| 4408 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4409 | offerer_config, answerer_config, |
| 4410 | loopback_media_transports()->first_factory(), |
| 4411 | loopback_media_transports()->second_factory())); |
| 4412 | ConnectFakeSignaling(); |
| 4413 | |
| 4414 | // Offer both media and data. |
| 4415 | caller()->AddAudioVideoTracks(); |
| 4416 | callee()->AddAudioVideoTracks(); |
| 4417 | caller()->CreateDataChannel(); |
| 4418 | caller()->CreateAndSetAndSignalOffer(); |
| 4419 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4420 | |
| 4421 | // Ensure that the data channel transport is ready. |
| 4422 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4423 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4424 | |
| 4425 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4426 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4427 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4428 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4429 | |
| 4430 | // Both endpoints should agree to use datagram transport for data channels. |
| 4431 | EXPECT_EQ(nullptr, caller()->pc()->GetSctpTransport()); |
| 4432 | EXPECT_EQ(nullptr, callee()->pc()->GetSctpTransport()); |
| 4433 | |
| 4434 | // Ensure data can be sent in both directions. |
| 4435 | std::string data = "hello world"; |
| 4436 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4437 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4438 | kDefaultTimeout); |
| 4439 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4440 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4441 | kDefaultTimeout); |
| 4442 | |
| 4443 | // Media flow should not be impacted. |
| 4444 | MediaExpectations media_expectations; |
| 4445 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4446 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4447 | } |
| 4448 | |
Bjorn A Mellem | 7da4e56 | 2019-09-26 11:02:11 -0700 | [diff] [blame] | 4449 | // Tests that data channels use SCTP instead of datagram transport if datagram |
| 4450 | // transport is configured in receive-only mode on the caller. |
| 4451 | TEST_P(PeerConnectionIntegrationTest, |
| 4452 | DatagramTransportDataChannelReceiveOnlyOnCallerUsesSctp) { |
| 4453 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4454 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4455 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4456 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 4457 | rtc_config.use_datagram_transport_for_data_channels_receive_only = true; |
| 4458 | |
| 4459 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4460 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4461 | loopback_media_transports()->second_factory())); |
| 4462 | ConnectFakeSignaling(); |
| 4463 | |
| 4464 | // The caller should offer a data channel using SCTP. |
| 4465 | caller()->CreateDataChannel(); |
| 4466 | caller()->AddAudioVideoTracks(); |
| 4467 | callee()->AddAudioVideoTracks(); |
| 4468 | caller()->CreateAndSetAndSignalOffer(); |
| 4469 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4470 | |
| 4471 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4472 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4473 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4474 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4475 | |
| 4476 | // SCTP transports should be present, since they are in use. |
| 4477 | EXPECT_NE(caller()->pc()->GetSctpTransport(), nullptr); |
| 4478 | EXPECT_NE(callee()->pc()->GetSctpTransport(), nullptr); |
| 4479 | |
| 4480 | // Ensure data can be sent in both directions. |
| 4481 | std::string data = "hello world"; |
| 4482 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4483 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4484 | kDefaultTimeout); |
| 4485 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4486 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4487 | kDefaultTimeout); |
| 4488 | } |
| 4489 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4490 | #endif // HAVE_SCTP |
| 4491 | |
Bjorn A Mellem | 7da4e56 | 2019-09-26 11:02:11 -0700 | [diff] [blame] | 4492 | // Tests that a callee configured for receive-only use of datagram transport |
| 4493 | // data channels accepts them on incoming calls. |
| 4494 | TEST_P(PeerConnectionIntegrationTest, |
| 4495 | DatagramTransportDataChannelReceiveOnlyOnCallee) { |
| 4496 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 4497 | offerer_config.rtcp_mux_policy = |
| 4498 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4499 | offerer_config.bundle_policy = |
| 4500 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4501 | offerer_config.use_datagram_transport_for_data_channels = true; |
| 4502 | |
| 4503 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 4504 | answerer_config.rtcp_mux_policy = |
| 4505 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4506 | answerer_config.bundle_policy = |
| 4507 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4508 | answerer_config.use_datagram_transport_for_data_channels = true; |
| 4509 | answerer_config.use_datagram_transport_for_data_channels_receive_only = true; |
| 4510 | |
| 4511 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4512 | offerer_config, answerer_config, |
| 4513 | loopback_media_transports()->first_factory(), |
| 4514 | loopback_media_transports()->second_factory())); |
| 4515 | ConnectFakeSignaling(); |
| 4516 | |
| 4517 | caller()->CreateDataChannel(); |
| 4518 | caller()->CreateAndSetAndSignalOffer(); |
| 4519 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4520 | |
| 4521 | // Ensure that the data channel transport is ready. |
| 4522 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4523 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4524 | |
| 4525 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4526 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4527 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4528 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4529 | |
| 4530 | // SCTP transports should not be present, since datagram transport is used. |
| 4531 | EXPECT_EQ(caller()->pc()->GetSctpTransport(), nullptr); |
| 4532 | EXPECT_EQ(callee()->pc()->GetSctpTransport(), nullptr); |
| 4533 | |
| 4534 | // Ensure data can be sent in both directions. |
| 4535 | std::string data = "hello world"; |
| 4536 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4537 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4538 | kDefaultTimeout); |
| 4539 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4540 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4541 | kDefaultTimeout); |
| 4542 | } |
| 4543 | |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 4544 | // This test sets up a call between two parties with a datagram transport data |
| 4545 | // channel. |
| 4546 | TEST_P(PeerConnectionIntegrationTest, DatagramTransportDataChannelEndToEnd) { |
| 4547 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4548 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4549 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4550 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 4551 | rtc_config.enable_dtls_srtp = false; |
| 4552 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4553 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4554 | loopback_media_transports()->second_factory())); |
| 4555 | ConnectFakeSignaling(); |
| 4556 | |
| 4557 | // Expect that data channel created on caller side will show up for callee as |
| 4558 | // well. |
| 4559 | caller()->CreateDataChannel(); |
| 4560 | caller()->CreateAndSetAndSignalOffer(); |
| 4561 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4562 | |
Bjorn A Mellem | fc604aa | 2019-09-24 14:59:21 -0700 | [diff] [blame] | 4563 | // Ensure that the data channel transport is ready. |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 4564 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4565 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4566 | |
| 4567 | // Caller data channel should already exist (it created one). Callee data |
| 4568 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 4569 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4570 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4571 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4572 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4573 | |
| 4574 | // Ensure data can be sent in both directions. |
| 4575 | std::string data = "hello world"; |
| 4576 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4577 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4578 | kDefaultTimeout); |
| 4579 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4580 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4581 | kDefaultTimeout); |
| 4582 | } |
| 4583 | |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 4584 | // Tests that 'zero-rtt' data channel transports (which are ready-to-send as |
| 4585 | // soon as they're created) work correctly. |
| 4586 | TEST_P(PeerConnectionIntegrationTest, DatagramTransportDataChannelZeroRtt) { |
| 4587 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4588 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4589 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4590 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 4591 | rtc_config.enable_dtls_srtp = false; // SDES is required for media transport. |
| 4592 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4593 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4594 | loopback_media_transports()->second_factory())); |
| 4595 | ConnectFakeSignaling(); |
| 4596 | |
| 4597 | // Ensure that the callee's media transport is ready-to-send immediately. |
| 4598 | // Note that only the callee can become writable in zero RTTs. The caller |
| 4599 | // must wait for the callee's answer. |
| 4600 | loopback_media_transports()->SetSecondStateAfterConnect( |
| 4601 | webrtc::MediaTransportState::kWritable); |
| 4602 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4603 | |
| 4604 | // Expect that data channel created on caller side will show up for callee as |
| 4605 | // well. |
| 4606 | caller()->CreateDataChannel(); |
| 4607 | caller()->CreateAndSetAndSignalOffer(); |
| 4608 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4609 | |
| 4610 | loopback_media_transports()->SetFirstState( |
| 4611 | webrtc::MediaTransportState::kWritable); |
| 4612 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4613 | |
| 4614 | // Caller data channel should already exist (it created one). Callee data |
| 4615 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 4616 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4617 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4618 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4619 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4620 | |
| 4621 | // Ensure data can be sent in both directions. |
| 4622 | std::string data = "hello world"; |
| 4623 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4624 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4625 | kDefaultTimeout); |
| 4626 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4627 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4628 | kDefaultTimeout); |
| 4629 | } |
| 4630 | |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 4631 | // Ensures that when the callee closes a datagram transport data channel, the |
| 4632 | // closing procedure results in the data channel being closed for the caller |
| 4633 | // as well. |
| 4634 | TEST_P(PeerConnectionIntegrationTest, |
| 4635 | DatagramTransportDataChannelCalleeCloses) { |
| 4636 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4637 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 4638 | rtc_config.enable_dtls_srtp = false; |
| 4639 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4640 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4641 | loopback_media_transports()->second_factory())); |
| 4642 | ConnectFakeSignaling(); |
| 4643 | |
| 4644 | // Create a data channel on the caller and signal it to the callee. |
| 4645 | caller()->CreateDataChannel(); |
| 4646 | caller()->CreateAndSetAndSignalOffer(); |
| 4647 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4648 | |
Bjorn A Mellem | fc604aa | 2019-09-24 14:59:21 -0700 | [diff] [blame] | 4649 | // Ensure that the data channel transport is ready. |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 4650 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4651 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4652 | |
| 4653 | // Data channels exist and open on both ends of the connection. |
| 4654 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4655 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4656 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4657 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4658 | |
| 4659 | // Close the data channel on the callee side, and wait for it to reach the |
| 4660 | // "closed" state on both sides. |
| 4661 | callee()->data_channel()->Close(); |
| 4662 | EXPECT_TRUE_WAIT(!caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4663 | EXPECT_TRUE_WAIT(!callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4664 | } |
| 4665 | |
| 4666 | // Tests that datagram transport data channels can do in-band negotiation. |
| 4667 | TEST_P(PeerConnectionIntegrationTest, |
| 4668 | DatagramTransportDataChannelConfigSentToOtherSide) { |
| 4669 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4670 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 4671 | rtc_config.enable_dtls_srtp = false; |
| 4672 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4673 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4674 | loopback_media_transports()->second_factory())); |
| 4675 | ConnectFakeSignaling(); |
| 4676 | |
| 4677 | // Create a data channel with a non-default configuration and signal it to the |
| 4678 | // callee. |
| 4679 | webrtc::DataChannelInit init; |
| 4680 | init.id = 53; |
| 4681 | init.maxRetransmits = 52; |
| 4682 | caller()->CreateDataChannel("data-channel", &init); |
| 4683 | caller()->CreateAndSetAndSignalOffer(); |
| 4684 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4685 | |
Bjorn A Mellem | fc604aa | 2019-09-24 14:59:21 -0700 | [diff] [blame] | 4686 | // Ensure that the data channel transport is ready. |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 4687 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4688 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4689 | |
| 4690 | // Ensure that the data channel exists on the callee with the correct |
| 4691 | // configuration. |
| 4692 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4693 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4694 | // Since "negotiate" is false, the "id" parameter is ignored. |
| 4695 | EXPECT_NE(init.id, callee()->data_channel()->id()); |
| 4696 | EXPECT_EQ("data-channel", callee()->data_channel()->label()); |
| 4697 | EXPECT_EQ(init.maxRetransmits, callee()->data_channel()->maxRetransmits()); |
| 4698 | EXPECT_FALSE(callee()->data_channel()->negotiated()); |
| 4699 | } |
| 4700 | |
| 4701 | TEST_P(PeerConnectionIntegrationTest, |
| 4702 | DatagramTransportDataChannelRejectedWithNoFallback) { |
| 4703 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 4704 | offerer_config.rtcp_mux_policy = |
| 4705 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4706 | offerer_config.bundle_policy = |
| 4707 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4708 | offerer_config.use_datagram_transport_for_data_channels = true; |
| 4709 | // Disabling DTLS precludes a fallback to SCTP. |
| 4710 | offerer_config.enable_dtls_srtp = false; |
| 4711 | |
| 4712 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 4713 | answerer_config.rtcp_mux_policy = |
| 4714 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4715 | answerer_config.bundle_policy = |
| 4716 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4717 | // Both endpoints must disable DTLS or SetRemoteDescription will fail. |
| 4718 | answerer_config.enable_dtls_srtp = false; |
| 4719 | |
| 4720 | // Configure one endpoint to use datagram transport for data channels while |
| 4721 | // the other does not. |
| 4722 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4723 | offerer_config, answerer_config, |
| 4724 | loopback_media_transports()->first_factory(), nullptr)); |
| 4725 | ConnectFakeSignaling(); |
| 4726 | |
| 4727 | // The caller offers a data channel using either datagram transport or SCTP. |
| 4728 | caller()->CreateDataChannel(); |
| 4729 | caller()->AddAudioVideoTracks(); |
| 4730 | callee()->AddAudioVideoTracks(); |
| 4731 | caller()->CreateAndSetAndSignalOffer(); |
| 4732 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4733 | |
| 4734 | // Caller data channel should already exist (it created one). Callee data |
| 4735 | // channel should not exist, since negotiation happens in-band, not in SDP. |
| 4736 | EXPECT_NE(nullptr, caller()->data_channel()); |
| 4737 | EXPECT_EQ(nullptr, callee()->data_channel()); |
| 4738 | |
| 4739 | // The caller's data channel should close when the datagram transport is |
| 4740 | // rejected. |
| 4741 | EXPECT_FALSE(caller()->data_observer()->IsOpen()); |
| 4742 | |
| 4743 | // Media flow should not be impacted by the failed data channel. |
| 4744 | MediaExpectations media_expectations; |
| 4745 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4746 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4747 | } |
| 4748 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4749 | // Test that the ICE connection and gathering states eventually reach |
| 4750 | // "complete". |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4751 | TEST_P(PeerConnectionIntegrationTest, IceStatesReachCompletion) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4752 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4753 | ConnectFakeSignaling(); |
| 4754 | // Do normal offer/answer. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4755 | caller()->AddAudioVideoTracks(); |
| 4756 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4757 | caller()->CreateAndSetAndSignalOffer(); |
| 4758 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4759 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete, |
| 4760 | caller()->ice_gathering_state(), kMaxWaitForFramesMs); |
| 4761 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete, |
| 4762 | callee()->ice_gathering_state(), kMaxWaitForFramesMs); |
| 4763 | // After the best candidate pair is selected and all candidates are signaled, |
| 4764 | // the ICE connection state should reach "complete". |
| 4765 | // TODO(deadbeef): Currently, the ICE "controlled" agent (the |
| 4766 | // answerer/"callee" by default) only reaches "connected". When this is |
| 4767 | // fixed, this test should be updated. |
| 4768 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 4769 | caller()->ice_connection_state(), kDefaultTimeout); |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 4770 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 4771 | callee()->ice_connection_state(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4772 | } |
| 4773 | |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4774 | constexpr int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN | |
| 4775 | cricket::PORTALLOCATOR_DISABLE_RELAY | |
| 4776 | cricket::PORTALLOCATOR_DISABLE_TCP; |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 4777 | |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4778 | // Use a mock resolver to resolve the hostname back to the original IP on both |
| 4779 | // sides and check that the ICE connection connects. |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 4780 | TEST_P(PeerConnectionIntegrationTest, |
| 4781 | IceStatesReachCompletionWithRemoteHostname) { |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4782 | auto caller_resolver_factory = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 4783 | std::make_unique<NiceMock<webrtc::MockAsyncResolverFactory>>(); |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4784 | auto callee_resolver_factory = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 4785 | std::make_unique<NiceMock<webrtc::MockAsyncResolverFactory>>(); |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4786 | NiceMock<rtc::MockAsyncResolver> callee_async_resolver; |
| 4787 | NiceMock<rtc::MockAsyncResolver> caller_async_resolver; |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 4788 | |
| 4789 | // This also verifies that the injected AsyncResolverFactory is used by |
| 4790 | // P2PTransportChannel. |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4791 | EXPECT_CALL(*caller_resolver_factory, Create()) |
| 4792 | .WillOnce(Return(&caller_async_resolver)); |
| 4793 | webrtc::PeerConnectionDependencies caller_deps(nullptr); |
| 4794 | caller_deps.async_resolver_factory = std::move(caller_resolver_factory); |
| 4795 | |
| 4796 | EXPECT_CALL(*callee_resolver_factory, Create()) |
| 4797 | .WillOnce(Return(&callee_async_resolver)); |
| 4798 | webrtc::PeerConnectionDependencies callee_deps(nullptr); |
| 4799 | callee_deps.async_resolver_factory = std::move(callee_resolver_factory); |
| 4800 | |
| 4801 | PeerConnectionInterface::RTCConfiguration config; |
| 4802 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4803 | config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4804 | |
| 4805 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps( |
| 4806 | config, std::move(caller_deps), config, std::move(callee_deps))); |
| 4807 | |
| 4808 | caller()->SetRemoteAsyncResolver(&callee_async_resolver); |
| 4809 | callee()->SetRemoteAsyncResolver(&caller_async_resolver); |
| 4810 | |
| 4811 | // Enable hostname candidates with mDNS names. |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 4812 | caller()->SetMdnsResponder( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 4813 | std::make_unique<webrtc::FakeMdnsResponder>(network_thread())); |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 4814 | callee()->SetMdnsResponder( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 4815 | std::make_unique<webrtc::FakeMdnsResponder>(network_thread())); |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4816 | |
| 4817 | SetPortAllocatorFlags(kOnlyLocalPorts, kOnlyLocalPorts); |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 4818 | |
| 4819 | ConnectFakeSignaling(); |
| 4820 | caller()->AddAudioVideoTracks(); |
| 4821 | callee()->AddAudioVideoTracks(); |
| 4822 | caller()->CreateAndSetAndSignalOffer(); |
| 4823 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4824 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 4825 | caller()->ice_connection_state(), kDefaultTimeout); |
| 4826 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 4827 | callee()->ice_connection_state(), kDefaultTimeout); |
Jeroen de Borst | 833979f | 2018-12-13 08:25:54 -0800 | [diff] [blame] | 4828 | |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 4829 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents( |
| 4830 | "WebRTC.PeerConnection.CandidatePairType_UDP", |
| 4831 | webrtc::kIceCandidatePairHostNameHostName)); |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 4832 | } |
| 4833 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4834 | // Test that firewalling the ICE connection causes the clients to identify the |
| 4835 | // disconnected state and then removing the firewall causes them to reconnect. |
| 4836 | class PeerConnectionIntegrationIceStatesTest |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4837 | : public PeerConnectionIntegrationBaseTest, |
| 4838 | public ::testing::WithParamInterface< |
| 4839 | std::tuple<SdpSemantics, std::tuple<std::string, uint32_t>>> { |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4840 | protected: |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4841 | PeerConnectionIntegrationIceStatesTest() |
| 4842 | : PeerConnectionIntegrationBaseTest(std::get<0>(GetParam())) { |
| 4843 | port_allocator_flags_ = std::get<1>(std::get<1>(GetParam())); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4844 | } |
| 4845 | |
| 4846 | void StartStunServer(const SocketAddress& server_address) { |
| 4847 | stun_server_.reset( |
| 4848 | cricket::TestStunServer::Create(network_thread(), server_address)); |
| 4849 | } |
| 4850 | |
| 4851 | bool TestIPv6() { |
| 4852 | return (port_allocator_flags_ & cricket::PORTALLOCATOR_ENABLE_IPV6); |
| 4853 | } |
| 4854 | |
| 4855 | void SetPortAllocatorFlags() { |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4856 | PeerConnectionIntegrationBaseTest::SetPortAllocatorFlags( |
| 4857 | port_allocator_flags_, port_allocator_flags_); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4858 | } |
| 4859 | |
| 4860 | std::vector<SocketAddress> CallerAddresses() { |
| 4861 | std::vector<SocketAddress> addresses; |
| 4862 | addresses.push_back(SocketAddress("1.1.1.1", 0)); |
| 4863 | if (TestIPv6()) { |
| 4864 | addresses.push_back(SocketAddress("1111:0:a:b:c:d:e:f", 0)); |
| 4865 | } |
| 4866 | return addresses; |
| 4867 | } |
| 4868 | |
| 4869 | std::vector<SocketAddress> CalleeAddresses() { |
| 4870 | std::vector<SocketAddress> addresses; |
| 4871 | addresses.push_back(SocketAddress("2.2.2.2", 0)); |
| 4872 | if (TestIPv6()) { |
| 4873 | addresses.push_back(SocketAddress("2222:0:a:b:c:d:e:f", 0)); |
| 4874 | } |
| 4875 | return addresses; |
| 4876 | } |
| 4877 | |
| 4878 | void SetUpNetworkInterfaces() { |
| 4879 | // Remove the default interfaces added by the test infrastructure. |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 4880 | caller()->network_manager()->RemoveInterface(kDefaultLocalAddress); |
| 4881 | callee()->network_manager()->RemoveInterface(kDefaultLocalAddress); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4882 | |
| 4883 | // Add network addresses for test. |
| 4884 | for (const auto& caller_address : CallerAddresses()) { |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 4885 | caller()->network_manager()->AddInterface(caller_address); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4886 | } |
| 4887 | for (const auto& callee_address : CalleeAddresses()) { |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 4888 | callee()->network_manager()->AddInterface(callee_address); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4889 | } |
| 4890 | } |
| 4891 | |
| 4892 | private: |
| 4893 | uint32_t port_allocator_flags_; |
| 4894 | std::unique_ptr<cricket::TestStunServer> stun_server_; |
| 4895 | }; |
| 4896 | |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 4897 | // Ensure FakeClockForTest is constructed first (see class for rationale). |
| 4898 | class PeerConnectionIntegrationIceStatesTestWithFakeClock |
| 4899 | : public FakeClockForTest, |
| 4900 | public PeerConnectionIntegrationIceStatesTest {}; |
| 4901 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4902 | // Tests that the PeerConnection goes through all the ICE gathering/connection |
| 4903 | // states over the duration of the call. This includes Disconnected and Failed |
| 4904 | // states, induced by putting a firewall between the peers and waiting for them |
| 4905 | // to time out. |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 4906 | TEST_P(PeerConnectionIntegrationIceStatesTestWithFakeClock, VerifyIceStates) { |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4907 | const SocketAddress kStunServerAddress = |
| 4908 | SocketAddress("99.99.99.1", cricket::STUN_SERVER_PORT); |
| 4909 | StartStunServer(kStunServerAddress); |
| 4910 | |
| 4911 | PeerConnectionInterface::RTCConfiguration config; |
| 4912 | PeerConnectionInterface::IceServer ice_stun_server; |
| 4913 | ice_stun_server.urls.push_back( |
| 4914 | "stun:" + kStunServerAddress.HostAsURIString() + ":" + |
| 4915 | kStunServerAddress.PortAsString()); |
| 4916 | config.servers.push_back(ice_stun_server); |
| 4917 | |
| 4918 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 4919 | ConnectFakeSignaling(); |
| 4920 | SetPortAllocatorFlags(); |
| 4921 | SetUpNetworkInterfaces(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4922 | caller()->AddAudioVideoTracks(); |
| 4923 | callee()->AddAudioVideoTracks(); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4924 | |
| 4925 | // Initial state before anything happens. |
| 4926 | ASSERT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 4927 | caller()->ice_gathering_state()); |
| 4928 | ASSERT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 4929 | caller()->ice_connection_state()); |
Jonas Olsson | 7a6739e | 2019-01-15 16:31:55 +0100 | [diff] [blame] | 4930 | ASSERT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 4931 | caller()->standardized_ice_connection_state()); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4932 | |
| 4933 | // Start the call by creating the offer, setting it as the local description, |
| 4934 | // then sending it to the peer who will respond with an answer. This happens |
| 4935 | // asynchronously so that we can watch the states as it runs in the |
| 4936 | // background. |
| 4937 | caller()->CreateAndSetAndSignalOffer(); |
| 4938 | |
Steve Anton | a9b67ce | 2020-01-16 14:00:44 -0800 | [diff] [blame] | 4939 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 4940 | caller()->ice_connection_state(), kDefaultTimeout, |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 4941 | FakeClock()); |
Steve Anton | a9b67ce | 2020-01-16 14:00:44 -0800 | [diff] [blame] | 4942 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 4943 | caller()->standardized_ice_connection_state(), |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 4944 | kDefaultTimeout, FakeClock()); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4945 | |
| 4946 | // Verify that the observer was notified of the intermediate transitions. |
| 4947 | EXPECT_THAT(caller()->ice_connection_state_history(), |
| 4948 | ElementsAre(PeerConnectionInterface::kIceConnectionChecking, |
| 4949 | PeerConnectionInterface::kIceConnectionConnected, |
| 4950 | PeerConnectionInterface::kIceConnectionCompleted)); |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 4951 | EXPECT_THAT(caller()->standardized_ice_connection_state_history(), |
| 4952 | ElementsAre(PeerConnectionInterface::kIceConnectionChecking, |
| 4953 | PeerConnectionInterface::kIceConnectionConnected, |
| 4954 | PeerConnectionInterface::kIceConnectionCompleted)); |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 4955 | EXPECT_THAT( |
| 4956 | caller()->peer_connection_state_history(), |
| 4957 | ElementsAre(PeerConnectionInterface::PeerConnectionState::kConnecting, |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 4958 | PeerConnectionInterface::PeerConnectionState::kConnected)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4959 | EXPECT_THAT(caller()->ice_gathering_state_history(), |
| 4960 | ElementsAre(PeerConnectionInterface::kIceGatheringGathering, |
| 4961 | PeerConnectionInterface::kIceGatheringComplete)); |
| 4962 | |
| 4963 | // Block connections to/from the caller and wait for ICE to become |
| 4964 | // disconnected. |
| 4965 | for (const auto& caller_address : CallerAddresses()) { |
| 4966 | firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address); |
| 4967 | } |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 4968 | RTC_LOG(LS_INFO) << "Firewall rules applied"; |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 4969 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
| 4970 | caller()->ice_connection_state(), kDefaultTimeout, |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 4971 | FakeClock()); |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 4972 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
| 4973 | caller()->standardized_ice_connection_state(), |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 4974 | kDefaultTimeout, FakeClock()); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4975 | |
| 4976 | // Let ICE re-establish by removing the firewall rules. |
| 4977 | firewall()->ClearRules(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 4978 | RTC_LOG(LS_INFO) << "Firewall rules cleared"; |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 4979 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 4980 | caller()->ice_connection_state(), kDefaultTimeout, |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 4981 | FakeClock()); |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 4982 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 4983 | caller()->standardized_ice_connection_state(), |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 4984 | kDefaultTimeout, FakeClock()); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4985 | |
| 4986 | // According to RFC7675, if there is no response within 30 seconds then the |
| 4987 | // peer should consider the other side to have rejected the connection. This |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 4988 | // is signaled by the state transitioning to "failed". |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4989 | constexpr int kConsentTimeout = 30000; |
| 4990 | for (const auto& caller_address : CallerAddresses()) { |
| 4991 | firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address); |
| 4992 | } |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 4993 | RTC_LOG(LS_INFO) << "Firewall rules applied again"; |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 4994 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionFailed, |
| 4995 | caller()->ice_connection_state(), kConsentTimeout, |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 4996 | FakeClock()); |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 4997 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionFailed, |
| 4998 | caller()->standardized_ice_connection_state(), |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 4999 | kConsentTimeout, FakeClock()); |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 5000 | } |
| 5001 | |
| 5002 | // Tests that if the connection doesn't get set up properly we eventually reach |
| 5003 | // the "failed" iceConnectionState. |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 5004 | TEST_P(PeerConnectionIntegrationIceStatesTestWithFakeClock, |
| 5005 | IceStateSetupFailure) { |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 5006 | // Block connections to/from the caller and wait for ICE to become |
| 5007 | // disconnected. |
| 5008 | for (const auto& caller_address : CallerAddresses()) { |
| 5009 | firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address); |
| 5010 | } |
| 5011 | |
| 5012 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5013 | ConnectFakeSignaling(); |
| 5014 | SetPortAllocatorFlags(); |
| 5015 | SetUpNetworkInterfaces(); |
| 5016 | caller()->AddAudioVideoTracks(); |
| 5017 | caller()->CreateAndSetAndSignalOffer(); |
| 5018 | |
| 5019 | // According to RFC7675, if there is no response within 30 seconds then the |
| 5020 | // peer should consider the other side to have rejected the connection. This |
| 5021 | // is signaled by the state transitioning to "failed". |
| 5022 | constexpr int kConsentTimeout = 30000; |
| 5023 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionFailed, |
| 5024 | caller()->standardized_ice_connection_state(), |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 5025 | kConsentTimeout, FakeClock()); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 5026 | } |
| 5027 | |
| 5028 | // Tests that the best connection is set to the appropriate IPv4/IPv6 connection |
| 5029 | // and that the statistics in the metric observers are updated correctly. |
| 5030 | TEST_P(PeerConnectionIntegrationIceStatesTest, VerifyBestConnection) { |
| 5031 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5032 | ConnectFakeSignaling(); |
| 5033 | SetPortAllocatorFlags(); |
| 5034 | SetUpNetworkInterfaces(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5035 | caller()->AddAudioVideoTracks(); |
| 5036 | callee()->AddAudioVideoTracks(); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 5037 | caller()->CreateAndSetAndSignalOffer(); |
| 5038 | |
| 5039 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Steve Anton | 692f3c7 | 2020-01-16 14:12:31 -0800 | [diff] [blame] | 5040 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 5041 | caller()->ice_connection_state(), kDefaultTimeout); |
| 5042 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 5043 | callee()->ice_connection_state(), kDefaultTimeout); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 5044 | |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 5045 | // TODO(bugs.webrtc.org/9456): Fix it. |
| 5046 | const int num_best_ipv4 = webrtc::metrics::NumEvents( |
| 5047 | "WebRTC.PeerConnection.IPMetrics", webrtc::kBestConnections_IPv4); |
| 5048 | const int num_best_ipv6 = webrtc::metrics::NumEvents( |
| 5049 | "WebRTC.PeerConnection.IPMetrics", webrtc::kBestConnections_IPv6); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 5050 | if (TestIPv6()) { |
| 5051 | // When IPv6 is enabled, we should prefer an IPv6 connection over an IPv4 |
| 5052 | // connection. |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 5053 | EXPECT_METRIC_EQ(0, num_best_ipv4); |
| 5054 | EXPECT_METRIC_EQ(1, num_best_ipv6); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 5055 | } else { |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 5056 | EXPECT_METRIC_EQ(1, num_best_ipv4); |
| 5057 | EXPECT_METRIC_EQ(0, num_best_ipv6); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 5058 | } |
| 5059 | |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 5060 | EXPECT_METRIC_EQ(0, webrtc::metrics::NumEvents( |
| 5061 | "WebRTC.PeerConnection.CandidatePairType_UDP", |
| 5062 | webrtc::kIceCandidatePairHostHost)); |
| 5063 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents( |
| 5064 | "WebRTC.PeerConnection.CandidatePairType_UDP", |
| 5065 | webrtc::kIceCandidatePairHostPublicHostPublic)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 5066 | } |
| 5067 | |
| 5068 | constexpr uint32_t kFlagsIPv4NoStun = cricket::PORTALLOCATOR_DISABLE_TCP | |
| 5069 | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 5070 | cricket::PORTALLOCATOR_DISABLE_RELAY; |
| 5071 | constexpr uint32_t kFlagsIPv6NoStun = |
| 5072 | cricket::PORTALLOCATOR_DISABLE_TCP | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 5073 | cricket::PORTALLOCATOR_ENABLE_IPV6 | cricket::PORTALLOCATOR_DISABLE_RELAY; |
| 5074 | constexpr uint32_t kFlagsIPv4Stun = |
| 5075 | cricket::PORTALLOCATOR_DISABLE_TCP | cricket::PORTALLOCATOR_DISABLE_RELAY; |
| 5076 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 5077 | INSTANTIATE_TEST_SUITE_P( |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5078 | PeerConnectionIntegrationTest, |
| 5079 | PeerConnectionIntegrationIceStatesTest, |
| 5080 | Combine(Values(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan), |
| 5081 | Values(std::make_pair("IPv4 no STUN", kFlagsIPv4NoStun), |
| 5082 | std::make_pair("IPv6 no STUN", kFlagsIPv6NoStun), |
| 5083 | std::make_pair("IPv4 with STUN", kFlagsIPv4Stun)))); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 5084 | |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 5085 | INSTANTIATE_TEST_SUITE_P( |
| 5086 | PeerConnectionIntegrationTest, |
| 5087 | PeerConnectionIntegrationIceStatesTestWithFakeClock, |
| 5088 | Combine(Values(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan), |
| 5089 | Values(std::make_pair("IPv4 no STUN", kFlagsIPv4NoStun), |
| 5090 | std::make_pair("IPv6 no STUN", kFlagsIPv6NoStun), |
| 5091 | std::make_pair("IPv4 with STUN", kFlagsIPv4Stun)))); |
| 5092 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5093 | // This test sets up a call between two parties with audio and video. |
| 5094 | // During the call, the caller restarts ICE and the test verifies that |
| 5095 | // new ICE candidates are generated and audio and video still can flow, and the |
| 5096 | // ICE state reaches completed again. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5097 | TEST_P(PeerConnectionIntegrationTest, MediaContinuesFlowingAfterIceRestart) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5098 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5099 | ConnectFakeSignaling(); |
| 5100 | // Do normal offer/answer and wait for ICE to complete. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5101 | caller()->AddAudioVideoTracks(); |
| 5102 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5103 | caller()->CreateAndSetAndSignalOffer(); |
| 5104 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5105 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 5106 | caller()->ice_connection_state(), kMaxWaitForFramesMs); |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 5107 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 5108 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5109 | |
| 5110 | // To verify that the ICE restart actually occurs, get |
| 5111 | // ufrag/password/candidates before and after restart. |
| 5112 | // Create an SDP string of the first audio candidate for both clients. |
| 5113 | const webrtc::IceCandidateCollection* audio_candidates_caller = |
| 5114 | caller()->pc()->local_description()->candidates(0); |
| 5115 | const webrtc::IceCandidateCollection* audio_candidates_callee = |
| 5116 | callee()->pc()->local_description()->candidates(0); |
| 5117 | ASSERT_GT(audio_candidates_caller->count(), 0u); |
| 5118 | ASSERT_GT(audio_candidates_callee->count(), 0u); |
| 5119 | std::string caller_candidate_pre_restart; |
| 5120 | ASSERT_TRUE( |
| 5121 | audio_candidates_caller->at(0)->ToString(&caller_candidate_pre_restart)); |
| 5122 | std::string callee_candidate_pre_restart; |
| 5123 | ASSERT_TRUE( |
| 5124 | audio_candidates_callee->at(0)->ToString(&callee_candidate_pre_restart)); |
| 5125 | const cricket::SessionDescription* desc = |
| 5126 | caller()->pc()->local_description()->description(); |
| 5127 | std::string caller_ufrag_pre_restart = |
| 5128 | desc->transport_infos()[0].description.ice_ufrag; |
| 5129 | desc = callee()->pc()->local_description()->description(); |
| 5130 | std::string callee_ufrag_pre_restart = |
| 5131 | desc->transport_infos()[0].description.ice_ufrag; |
| 5132 | |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 5133 | EXPECT_EQ(caller()->ice_candidate_pair_change_history().size(), 1u); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5134 | // Have the caller initiate an ICE restart. |
| 5135 | caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions()); |
| 5136 | caller()->CreateAndSetAndSignalOffer(); |
| 5137 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5138 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 5139 | caller()->ice_connection_state(), kMaxWaitForFramesMs); |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 5140 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5141 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
| 5142 | |
| 5143 | // Grab the ufrags/candidates again. |
| 5144 | audio_candidates_caller = caller()->pc()->local_description()->candidates(0); |
| 5145 | audio_candidates_callee = callee()->pc()->local_description()->candidates(0); |
| 5146 | ASSERT_GT(audio_candidates_caller->count(), 0u); |
| 5147 | ASSERT_GT(audio_candidates_callee->count(), 0u); |
| 5148 | std::string caller_candidate_post_restart; |
| 5149 | ASSERT_TRUE( |
| 5150 | audio_candidates_caller->at(0)->ToString(&caller_candidate_post_restart)); |
| 5151 | std::string callee_candidate_post_restart; |
| 5152 | ASSERT_TRUE( |
| 5153 | audio_candidates_callee->at(0)->ToString(&callee_candidate_post_restart)); |
| 5154 | desc = caller()->pc()->local_description()->description(); |
| 5155 | std::string caller_ufrag_post_restart = |
| 5156 | desc->transport_infos()[0].description.ice_ufrag; |
| 5157 | desc = callee()->pc()->local_description()->description(); |
| 5158 | std::string callee_ufrag_post_restart = |
| 5159 | desc->transport_infos()[0].description.ice_ufrag; |
| 5160 | // Sanity check that an ICE restart was actually negotiated in SDP. |
| 5161 | ASSERT_NE(caller_candidate_pre_restart, caller_candidate_post_restart); |
| 5162 | ASSERT_NE(callee_candidate_pre_restart, callee_candidate_post_restart); |
| 5163 | ASSERT_NE(caller_ufrag_pre_restart, caller_ufrag_post_restart); |
| 5164 | ASSERT_NE(callee_ufrag_pre_restart, callee_ufrag_post_restart); |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 5165 | EXPECT_GT(caller()->ice_candidate_pair_change_history().size(), 1u); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5166 | |
| 5167 | // Ensure that additional frames are received after the ICE restart. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5168 | MediaExpectations media_expectations; |
| 5169 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 5170 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5171 | } |
| 5172 | |
| 5173 | // Verify that audio/video can be received end-to-end when ICE renomination is |
| 5174 | // enabled. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5175 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithIceRenomination) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5176 | PeerConnectionInterface::RTCConfiguration config; |
| 5177 | config.enable_ice_renomination = true; |
| 5178 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 5179 | ConnectFakeSignaling(); |
| 5180 | // Do normal offer/answer and wait for some frames to be received in each |
| 5181 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5182 | caller()->AddAudioVideoTracks(); |
| 5183 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5184 | caller()->CreateAndSetAndSignalOffer(); |
| 5185 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5186 | // Sanity check that ICE renomination was actually negotiated. |
| 5187 | const cricket::SessionDescription* desc = |
| 5188 | caller()->pc()->local_description()->description(); |
| 5189 | for (const cricket::TransportInfo& info : desc->transport_infos()) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 5190 | ASSERT_THAT(info.description.transport_options, Contains("renomination")); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5191 | } |
| 5192 | desc = callee()->pc()->local_description()->description(); |
| 5193 | for (const cricket::TransportInfo& info : desc->transport_infos()) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 5194 | ASSERT_THAT(info.description.transport_options, Contains("renomination")); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5195 | } |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5196 | MediaExpectations media_expectations; |
| 5197 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 5198 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5199 | } |
| 5200 | |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 5201 | // With a max bundle policy and RTCP muxing, adding a new media description to |
| 5202 | // the connection should not affect ICE at all because the new media will use |
| 5203 | // the existing connection. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5204 | TEST_P(PeerConnectionIntegrationTest, |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 5205 | AddMediaToConnectedBundleDoesNotRestartIce) { |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 5206 | PeerConnectionInterface::RTCConfiguration config; |
| 5207 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 5208 | config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 5209 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig( |
| 5210 | config, PeerConnectionInterface::RTCConfiguration())); |
| 5211 | ConnectFakeSignaling(); |
| 5212 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5213 | caller()->AddAudioTrack(); |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 5214 | caller()->CreateAndSetAndSignalOffer(); |
| 5215 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Steve Anton | ff52f1b | 2017-10-26 12:24:50 -0700 | [diff] [blame] | 5216 | ASSERT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 5217 | caller()->ice_connection_state(), kDefaultTimeout); |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 5218 | |
| 5219 | caller()->clear_ice_connection_state_history(); |
| 5220 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5221 | caller()->AddVideoTrack(); |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 5222 | caller()->CreateAndSetAndSignalOffer(); |
| 5223 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5224 | |
| 5225 | EXPECT_EQ(0u, caller()->ice_connection_state_history().size()); |
| 5226 | } |
| 5227 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5228 | // This test sets up a call between two parties with audio and video. It then |
| 5229 | // renegotiates setting the video m-line to "port 0", then later renegotiates |
| 5230 | // again, enabling video. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5231 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5232 | VideoFlowsAfterMediaSectionIsRejectedAndRecycled) { |
| 5233 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5234 | ConnectFakeSignaling(); |
| 5235 | |
| 5236 | // Do initial negotiation, only sending media from the caller. Will result in |
| 5237 | // video and audio recvonly "m=" sections. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5238 | caller()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5239 | caller()->CreateAndSetAndSignalOffer(); |
| 5240 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5241 | |
| 5242 | // Negotiate again, disabling the video "m=" section (the callee will set the |
| 5243 | // port to 0 due to offer_to_receive_video = 0). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5244 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 5245 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 5246 | options.offer_to_receive_video = 0; |
| 5247 | callee()->SetOfferAnswerOptions(options); |
| 5248 | } else { |
| 5249 | callee()->SetRemoteOfferHandler([this] { |
| 5250 | callee()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)->Stop(); |
| 5251 | }); |
| 5252 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5253 | caller()->CreateAndSetAndSignalOffer(); |
| 5254 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5255 | // Sanity check that video "m=" section was actually rejected. |
| 5256 | const ContentInfo* answer_video_content = cricket::GetFirstVideoContent( |
| 5257 | callee()->pc()->local_description()->description()); |
| 5258 | ASSERT_NE(nullptr, answer_video_content); |
| 5259 | ASSERT_TRUE(answer_video_content->rejected); |
| 5260 | |
| 5261 | // Enable video and do negotiation again, making sure video is received |
| 5262 | // end-to-end, also adding media stream to callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5263 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 5264 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 5265 | options.offer_to_receive_video = 1; |
| 5266 | callee()->SetOfferAnswerOptions(options); |
| 5267 | } else { |
| 5268 | // The caller's transceiver is stopped, so we need to add another track. |
| 5269 | auto caller_transceiver = |
| 5270 | caller()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO); |
| 5271 | EXPECT_TRUE(caller_transceiver->stopped()); |
| 5272 | caller()->AddVideoTrack(); |
| 5273 | } |
| 5274 | callee()->AddVideoTrack(); |
| 5275 | callee()->SetRemoteOfferHandler(nullptr); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5276 | caller()->CreateAndSetAndSignalOffer(); |
| 5277 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5278 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5279 | // Verify the caller receives frames from the newly added stream, and the |
| 5280 | // callee receives additional frames from the re-enabled video m= section. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5281 | MediaExpectations media_expectations; |
| 5282 | media_expectations.CalleeExpectsSomeAudio(); |
| 5283 | media_expectations.ExpectBidirectionalVideo(); |
| 5284 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5285 | } |
| 5286 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5287 | // This tests that if we negotiate after calling CreateSender but before we |
| 5288 | // have a track, then set a track later, frames from the newly-set track are |
| 5289 | // received end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5290 | TEST_F(PeerConnectionIntegrationTestPlanB, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5291 | MediaFlowsAfterEarlyWarmupWithCreateSender) { |
| 5292 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5293 | ConnectFakeSignaling(); |
| 5294 | auto caller_audio_sender = |
| 5295 | caller()->pc()->CreateSender("audio", "caller_stream"); |
| 5296 | auto caller_video_sender = |
| 5297 | caller()->pc()->CreateSender("video", "caller_stream"); |
| 5298 | auto callee_audio_sender = |
| 5299 | callee()->pc()->CreateSender("audio", "callee_stream"); |
| 5300 | auto callee_video_sender = |
| 5301 | callee()->pc()->CreateSender("video", "callee_stream"); |
| 5302 | caller()->CreateAndSetAndSignalOffer(); |
| 5303 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
| 5304 | // Wait for ICE to complete, without any tracks being set. |
| 5305 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 5306 | caller()->ice_connection_state(), kMaxWaitForFramesMs); |
| 5307 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 5308 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
| 5309 | // Now set the tracks, and expect frames to immediately start flowing. |
| 5310 | EXPECT_TRUE(caller_audio_sender->SetTrack(caller()->CreateLocalAudioTrack())); |
| 5311 | EXPECT_TRUE(caller_video_sender->SetTrack(caller()->CreateLocalVideoTrack())); |
| 5312 | EXPECT_TRUE(callee_audio_sender->SetTrack(callee()->CreateLocalAudioTrack())); |
| 5313 | EXPECT_TRUE(callee_video_sender->SetTrack(callee()->CreateLocalVideoTrack())); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5314 | MediaExpectations media_expectations; |
| 5315 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 5316 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 5317 | } |
| 5318 | |
| 5319 | // This tests that if we negotiate after calling AddTransceiver but before we |
| 5320 | // have a track, then set a track later, frames from the newly-set tracks are |
| 5321 | // received end-to-end. |
| 5322 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 5323 | MediaFlowsAfterEarlyWarmupWithAddTransceiver) { |
| 5324 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5325 | ConnectFakeSignaling(); |
| 5326 | auto audio_result = caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
| 5327 | ASSERT_EQ(RTCErrorType::NONE, audio_result.error().type()); |
| 5328 | auto caller_audio_sender = audio_result.MoveValue()->sender(); |
| 5329 | auto video_result = caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_VIDEO); |
| 5330 | ASSERT_EQ(RTCErrorType::NONE, video_result.error().type()); |
| 5331 | auto caller_video_sender = video_result.MoveValue()->sender(); |
| 5332 | callee()->SetRemoteOfferHandler([this] { |
| 5333 | ASSERT_EQ(2u, callee()->pc()->GetTransceivers().size()); |
| 5334 | callee()->pc()->GetTransceivers()[0]->SetDirection( |
| 5335 | RtpTransceiverDirection::kSendRecv); |
| 5336 | callee()->pc()->GetTransceivers()[1]->SetDirection( |
| 5337 | RtpTransceiverDirection::kSendRecv); |
| 5338 | }); |
| 5339 | caller()->CreateAndSetAndSignalOffer(); |
| 5340 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
| 5341 | // Wait for ICE to complete, without any tracks being set. |
| 5342 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 5343 | caller()->ice_connection_state(), kMaxWaitForFramesMs); |
| 5344 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 5345 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
| 5346 | // Now set the tracks, and expect frames to immediately start flowing. |
| 5347 | auto callee_audio_sender = callee()->pc()->GetSenders()[0]; |
| 5348 | auto callee_video_sender = callee()->pc()->GetSenders()[1]; |
| 5349 | ASSERT_TRUE(caller_audio_sender->SetTrack(caller()->CreateLocalAudioTrack())); |
| 5350 | ASSERT_TRUE(caller_video_sender->SetTrack(caller()->CreateLocalVideoTrack())); |
| 5351 | ASSERT_TRUE(callee_audio_sender->SetTrack(callee()->CreateLocalAudioTrack())); |
| 5352 | ASSERT_TRUE(callee_video_sender->SetTrack(callee()->CreateLocalVideoTrack())); |
| 5353 | MediaExpectations media_expectations; |
| 5354 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 5355 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5356 | } |
| 5357 | |
| 5358 | // This test verifies that a remote video track can be added via AddStream, |
| 5359 | // and sent end-to-end. For this particular test, it's simply echoed back |
| 5360 | // from the caller to the callee, rather than being forwarded to a third |
| 5361 | // PeerConnection. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5362 | TEST_F(PeerConnectionIntegrationTestPlanB, CanSendRemoteVideoTrack) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5363 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5364 | ConnectFakeSignaling(); |
| 5365 | // Just send a video track from the caller. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5366 | caller()->AddVideoTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5367 | caller()->CreateAndSetAndSignalOffer(); |
| 5368 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 5369 | ASSERT_EQ(1U, callee()->remote_streams()->count()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5370 | |
| 5371 | // Echo the stream back, and do a new offer/anwer (initiated by callee this |
| 5372 | // time). |
| 5373 | callee()->pc()->AddStream(callee()->remote_streams()->at(0)); |
| 5374 | callee()->CreateAndSetAndSignalOffer(); |
| 5375 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
| 5376 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5377 | MediaExpectations media_expectations; |
| 5378 | media_expectations.ExpectBidirectionalVideo(); |
| 5379 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | // Test that we achieve the expected end-to-end connection time, using a |
| 5383 | // fake clock and simulated latency on the media and signaling paths. |
| 5384 | // We use a TURN<->TURN connection because this is usually the quickest to |
| 5385 | // set up initially, especially when we're confident the connection will work |
| 5386 | // and can start sending media before we get a STUN response. |
| 5387 | // |
| 5388 | // With various optimizations enabled, here are the network delays we expect to |
| 5389 | // be on the critical path: |
| 5390 | // 1. 2 signaling trips: Signaling offer and offerer's TURN candidate, then |
| 5391 | // signaling answer (with DTLS fingerprint). |
| 5392 | // 2. 9 media hops: Rest of the DTLS handshake. 3 hops in each direction when |
| 5393 | // using TURN<->TURN pair, and DTLS exchange is 4 packets, |
| 5394 | // the first of which should have arrived before the answer. |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 5395 | TEST_P(PeerConnectionIntegrationTestWithFakeClock, |
| 5396 | EndToEndConnectionTimeWithTurnTurnPair) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5397 | static constexpr int media_hop_delay_ms = 50; |
| 5398 | static constexpr int signaling_trip_delay_ms = 500; |
| 5399 | // For explanation of these values, see comment above. |
| 5400 | static constexpr int required_media_hops = 9; |
| 5401 | static constexpr int required_signaling_trips = 2; |
| 5402 | // For internal delays (such as posting an event asychronously). |
| 5403 | static constexpr int allowed_internal_delay_ms = 20; |
| 5404 | static constexpr int total_connection_time_ms = |
| 5405 | media_hop_delay_ms * required_media_hops + |
| 5406 | signaling_trip_delay_ms * required_signaling_trips + |
| 5407 | allowed_internal_delay_ms; |
| 5408 | |
| 5409 | static const rtc::SocketAddress turn_server_1_internal_address{"88.88.88.0", |
| 5410 | 3478}; |
| 5411 | static const rtc::SocketAddress turn_server_1_external_address{"88.88.88.1", |
| 5412 | 0}; |
| 5413 | static const rtc::SocketAddress turn_server_2_internal_address{"99.99.99.0", |
| 5414 | 3478}; |
| 5415 | static const rtc::SocketAddress turn_server_2_external_address{"99.99.99.1", |
| 5416 | 0}; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5417 | cricket::TestTurnServer* turn_server_1 = CreateTurnServer( |
| 5418 | turn_server_1_internal_address, turn_server_1_external_address); |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 5419 | |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5420 | cricket::TestTurnServer* turn_server_2 = CreateTurnServer( |
| 5421 | turn_server_2_internal_address, turn_server_2_external_address); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5422 | // Bypass permission check on received packets so media can be sent before |
| 5423 | // the candidate is signaled. |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5424 | network_thread()->Invoke<void>(RTC_FROM_HERE, [turn_server_1] { |
| 5425 | turn_server_1->set_enable_permission_checks(false); |
| 5426 | }); |
| 5427 | network_thread()->Invoke<void>(RTC_FROM_HERE, [turn_server_2] { |
| 5428 | turn_server_2->set_enable_permission_checks(false); |
| 5429 | }); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5430 | |
| 5431 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 5432 | webrtc::PeerConnectionInterface::IceServer ice_server_1; |
| 5433 | ice_server_1.urls.push_back("turn:88.88.88.0:3478"); |
| 5434 | ice_server_1.username = "test"; |
| 5435 | ice_server_1.password = "test"; |
| 5436 | client_1_config.servers.push_back(ice_server_1); |
| 5437 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5438 | client_1_config.presume_writable_when_fully_relayed = true; |
| 5439 | |
| 5440 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 5441 | webrtc::PeerConnectionInterface::IceServer ice_server_2; |
| 5442 | ice_server_2.urls.push_back("turn:99.99.99.0:3478"); |
| 5443 | ice_server_2.username = "test"; |
| 5444 | ice_server_2.password = "test"; |
| 5445 | client_2_config.servers.push_back(ice_server_2); |
| 5446 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5447 | client_2_config.presume_writable_when_fully_relayed = true; |
| 5448 | |
| 5449 | ASSERT_TRUE( |
| 5450 | CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config)); |
| 5451 | // Set up the simulated delays. |
| 5452 | SetSignalingDelayMs(signaling_trip_delay_ms); |
| 5453 | ConnectFakeSignaling(); |
| 5454 | virtual_socket_server()->set_delay_mean(media_hop_delay_ms); |
| 5455 | virtual_socket_server()->UpdateDelayDistribution(); |
| 5456 | |
| 5457 | // Set "offer to receive audio/video" without adding any tracks, so we just |
| 5458 | // set up ICE/DTLS with no media. |
| 5459 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 5460 | options.offer_to_receive_audio = 1; |
| 5461 | options.offer_to_receive_video = 1; |
| 5462 | caller()->SetOfferAnswerOptions(options); |
| 5463 | caller()->CreateAndSetAndSignalOffer(); |
deadbeef | 7145280 | 2017-05-07 17:21:01 -0700 | [diff] [blame] | 5464 | EXPECT_TRUE_SIMULATED_WAIT(DtlsConnected(), total_connection_time_ms, |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 5465 | FakeClock()); |
Seth Hampson | 1d4a76d | 2018-06-19 14:31:41 -0700 | [diff] [blame] | 5466 | // Closing the PeerConnections destroys the ports before the ScopedFakeClock. |
| 5467 | // If this is not done a DCHECK can be hit in ports.cc, because a large |
| 5468 | // negative number is calculated for the rtt due to the global clock changing. |
Steve Anton | d91969e | 2019-05-30 12:27:03 -0700 | [diff] [blame] | 5469 | ClosePeerConnections(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5470 | } |
| 5471 | |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 5472 | // Verify that a TurnCustomizer passed in through RTCConfiguration |
| 5473 | // is actually used by the underlying TURN candidate pair. |
| 5474 | // Note that turnport_unittest.cc contains more detailed, lower-level tests. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5475 | TEST_P(PeerConnectionIntegrationTest, TurnCustomizerUsedForTurnConnections) { |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 5476 | static const rtc::SocketAddress turn_server_1_internal_address{"88.88.88.0", |
| 5477 | 3478}; |
| 5478 | static const rtc::SocketAddress turn_server_1_external_address{"88.88.88.1", |
| 5479 | 0}; |
| 5480 | static const rtc::SocketAddress turn_server_2_internal_address{"99.99.99.0", |
| 5481 | 3478}; |
| 5482 | static const rtc::SocketAddress turn_server_2_external_address{"99.99.99.1", |
| 5483 | 0}; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5484 | CreateTurnServer(turn_server_1_internal_address, |
| 5485 | turn_server_1_external_address); |
| 5486 | CreateTurnServer(turn_server_2_internal_address, |
| 5487 | turn_server_2_external_address); |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 5488 | |
| 5489 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 5490 | webrtc::PeerConnectionInterface::IceServer ice_server_1; |
| 5491 | ice_server_1.urls.push_back("turn:88.88.88.0:3478"); |
| 5492 | ice_server_1.username = "test"; |
| 5493 | ice_server_1.password = "test"; |
| 5494 | client_1_config.servers.push_back(ice_server_1); |
| 5495 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5496 | auto* customizer1 = CreateTurnCustomizer(); |
| 5497 | client_1_config.turn_customizer = customizer1; |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 5498 | |
| 5499 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 5500 | webrtc::PeerConnectionInterface::IceServer ice_server_2; |
| 5501 | ice_server_2.urls.push_back("turn:99.99.99.0:3478"); |
| 5502 | ice_server_2.username = "test"; |
| 5503 | ice_server_2.password = "test"; |
| 5504 | client_2_config.servers.push_back(ice_server_2); |
| 5505 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5506 | auto* customizer2 = CreateTurnCustomizer(); |
| 5507 | client_2_config.turn_customizer = customizer2; |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 5508 | |
| 5509 | ASSERT_TRUE( |
| 5510 | CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config)); |
| 5511 | ConnectFakeSignaling(); |
| 5512 | |
| 5513 | // Set "offer to receive audio/video" without adding any tracks, so we just |
| 5514 | // set up ICE/DTLS with no media. |
| 5515 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 5516 | options.offer_to_receive_audio = 1; |
| 5517 | options.offer_to_receive_video = 1; |
| 5518 | caller()->SetOfferAnswerOptions(options); |
| 5519 | caller()->CreateAndSetAndSignalOffer(); |
| 5520 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
| 5521 | |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5522 | ExpectTurnCustomizerCountersIncremented(customizer1); |
| 5523 | ExpectTurnCustomizerCountersIncremented(customizer2); |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 5524 | } |
| 5525 | |
Benjamin Wright | 2d5f3cb | 2018-05-22 14:46:06 -0700 | [diff] [blame] | 5526 | // Verifies that you can use TCP instead of UDP to connect to a TURN server and |
| 5527 | // send media between the caller and the callee. |
| 5528 | TEST_P(PeerConnectionIntegrationTest, TCPUsedForTurnConnections) { |
| 5529 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 5530 | 3478}; |
| 5531 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 5532 | |
| 5533 | // Enable TCP for the fake turn server. |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5534 | CreateTurnServer(turn_server_internal_address, turn_server_external_address, |
| 5535 | cricket::PROTO_TCP); |
Benjamin Wright | 2d5f3cb | 2018-05-22 14:46:06 -0700 | [diff] [blame] | 5536 | |
| 5537 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 5538 | ice_server.urls.push_back("turn:88.88.88.0:3478?transport=tcp"); |
| 5539 | ice_server.username = "test"; |
| 5540 | ice_server.password = "test"; |
| 5541 | |
| 5542 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 5543 | client_1_config.servers.push_back(ice_server); |
| 5544 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5545 | |
| 5546 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 5547 | client_2_config.servers.push_back(ice_server); |
| 5548 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5549 | |
| 5550 | ASSERT_TRUE( |
| 5551 | CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config)); |
| 5552 | |
| 5553 | // Do normal offer/answer and wait for ICE to complete. |
| 5554 | ConnectFakeSignaling(); |
| 5555 | caller()->AddAudioVideoTracks(); |
| 5556 | callee()->AddAudioVideoTracks(); |
| 5557 | caller()->CreateAndSetAndSignalOffer(); |
| 5558 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5559 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 5560 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
| 5561 | |
| 5562 | MediaExpectations media_expectations; |
| 5563 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 5564 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 5565 | } |
| 5566 | |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 5567 | // Verify that a SSLCertificateVerifier passed in through |
| 5568 | // PeerConnectionDependencies is actually used by the underlying SSL |
| 5569 | // implementation to determine whether a certificate presented by the TURN |
| 5570 | // server is accepted by the client. Note that openssladapter_unittest.cc |
| 5571 | // contains more detailed, lower-level tests. |
| 5572 | TEST_P(PeerConnectionIntegrationTest, |
| 5573 | SSLCertificateVerifierUsedForTurnConnections) { |
| 5574 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 5575 | 3478}; |
| 5576 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 5577 | |
| 5578 | // Enable TCP-TLS for the fake turn server. We need to pass in 88.88.88.0 so |
| 5579 | // that host name verification passes on the fake certificate. |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5580 | CreateTurnServer(turn_server_internal_address, turn_server_external_address, |
| 5581 | cricket::PROTO_TLS, "88.88.88.0"); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 5582 | |
| 5583 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 5584 | ice_server.urls.push_back("turns:88.88.88.0:3478?transport=tcp"); |
| 5585 | ice_server.username = "test"; |
| 5586 | ice_server.password = "test"; |
| 5587 | |
| 5588 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 5589 | client_1_config.servers.push_back(ice_server); |
| 5590 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5591 | |
| 5592 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 5593 | client_2_config.servers.push_back(ice_server); |
| 5594 | // Setting the type to kRelay forces the connection to go through a TURN |
| 5595 | // server. |
| 5596 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5597 | |
| 5598 | // Get a copy to the pointer so we can verify calls later. |
| 5599 | rtc::TestCertificateVerifier* client_1_cert_verifier = |
| 5600 | new rtc::TestCertificateVerifier(); |
| 5601 | client_1_cert_verifier->verify_certificate_ = true; |
| 5602 | rtc::TestCertificateVerifier* client_2_cert_verifier = |
| 5603 | new rtc::TestCertificateVerifier(); |
| 5604 | client_2_cert_verifier->verify_certificate_ = true; |
| 5605 | |
| 5606 | // Create the dependencies with the test certificate verifier. |
| 5607 | webrtc::PeerConnectionDependencies client_1_deps(nullptr); |
| 5608 | client_1_deps.tls_cert_verifier = |
| 5609 | std::unique_ptr<rtc::TestCertificateVerifier>(client_1_cert_verifier); |
| 5610 | webrtc::PeerConnectionDependencies client_2_deps(nullptr); |
| 5611 | client_2_deps.tls_cert_verifier = |
| 5612 | std::unique_ptr<rtc::TestCertificateVerifier>(client_2_cert_verifier); |
| 5613 | |
| 5614 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps( |
| 5615 | client_1_config, std::move(client_1_deps), client_2_config, |
| 5616 | std::move(client_2_deps))); |
| 5617 | ConnectFakeSignaling(); |
| 5618 | |
| 5619 | // Set "offer to receive audio/video" without adding any tracks, so we just |
| 5620 | // set up ICE/DTLS with no media. |
| 5621 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 5622 | options.offer_to_receive_audio = 1; |
| 5623 | options.offer_to_receive_video = 1; |
| 5624 | caller()->SetOfferAnswerOptions(options); |
| 5625 | caller()->CreateAndSetAndSignalOffer(); |
| 5626 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
| 5627 | |
| 5628 | EXPECT_GT(client_1_cert_verifier->call_count_, 0u); |
| 5629 | EXPECT_GT(client_2_cert_verifier->call_count_, 0u); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 5630 | } |
| 5631 | |
| 5632 | TEST_P(PeerConnectionIntegrationTest, |
| 5633 | SSLCertificateVerifierFailureUsedForTurnConnectionsFailsConnection) { |
| 5634 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 5635 | 3478}; |
| 5636 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 5637 | |
| 5638 | // Enable TCP-TLS for the fake turn server. We need to pass in 88.88.88.0 so |
| 5639 | // that host name verification passes on the fake certificate. |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5640 | CreateTurnServer(turn_server_internal_address, turn_server_external_address, |
| 5641 | cricket::PROTO_TLS, "88.88.88.0"); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 5642 | |
| 5643 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 5644 | ice_server.urls.push_back("turns:88.88.88.0:3478?transport=tcp"); |
| 5645 | ice_server.username = "test"; |
| 5646 | ice_server.password = "test"; |
| 5647 | |
| 5648 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 5649 | client_1_config.servers.push_back(ice_server); |
| 5650 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5651 | |
| 5652 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 5653 | client_2_config.servers.push_back(ice_server); |
| 5654 | // Setting the type to kRelay forces the connection to go through a TURN |
| 5655 | // server. |
| 5656 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5657 | |
| 5658 | // Get a copy to the pointer so we can verify calls later. |
| 5659 | rtc::TestCertificateVerifier* client_1_cert_verifier = |
| 5660 | new rtc::TestCertificateVerifier(); |
| 5661 | client_1_cert_verifier->verify_certificate_ = false; |
| 5662 | rtc::TestCertificateVerifier* client_2_cert_verifier = |
| 5663 | new rtc::TestCertificateVerifier(); |
| 5664 | client_2_cert_verifier->verify_certificate_ = false; |
| 5665 | |
| 5666 | // Create the dependencies with the test certificate verifier. |
| 5667 | webrtc::PeerConnectionDependencies client_1_deps(nullptr); |
| 5668 | client_1_deps.tls_cert_verifier = |
| 5669 | std::unique_ptr<rtc::TestCertificateVerifier>(client_1_cert_verifier); |
| 5670 | webrtc::PeerConnectionDependencies client_2_deps(nullptr); |
| 5671 | client_2_deps.tls_cert_verifier = |
| 5672 | std::unique_ptr<rtc::TestCertificateVerifier>(client_2_cert_verifier); |
| 5673 | |
| 5674 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps( |
| 5675 | client_1_config, std::move(client_1_deps), client_2_config, |
| 5676 | std::move(client_2_deps))); |
| 5677 | ConnectFakeSignaling(); |
| 5678 | |
| 5679 | // Set "offer to receive audio/video" without adding any tracks, so we just |
| 5680 | // set up ICE/DTLS with no media. |
| 5681 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 5682 | options.offer_to_receive_audio = 1; |
| 5683 | options.offer_to_receive_video = 1; |
| 5684 | caller()->SetOfferAnswerOptions(options); |
| 5685 | caller()->CreateAndSetAndSignalOffer(); |
| 5686 | bool wait_res = true; |
| 5687 | // TODO(bugs.webrtc.org/9219): When IceConnectionState is implemented |
| 5688 | // properly, should be able to just wait for a state of "failed" instead of |
| 5689 | // waiting a fixed 10 seconds. |
| 5690 | WAIT_(DtlsConnected(), kDefaultTimeout, wait_res); |
| 5691 | ASSERT_FALSE(wait_res); |
| 5692 | |
| 5693 | EXPECT_GT(client_1_cert_verifier->call_count_, 0u); |
| 5694 | EXPECT_GT(client_2_cert_verifier->call_count_, 0u); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 5695 | } |
| 5696 | |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 5697 | // Test that the injected ICE transport factory is used to create ICE transports |
| 5698 | // for WebRTC connections. |
| 5699 | TEST_P(PeerConnectionIntegrationTest, IceTransportFactoryUsedForConnections) { |
| 5700 | PeerConnectionInterface::RTCConfiguration default_config; |
| 5701 | PeerConnectionDependencies dependencies(nullptr); |
| 5702 | auto ice_transport_factory = std::make_unique<MockIceTransportFactory>(); |
| 5703 | EXPECT_CALL(*ice_transport_factory, RecordIceTransportCreated()).Times(1); |
| 5704 | dependencies.ice_transport_factory = std::move(ice_transport_factory); |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 5705 | auto wrapper = CreatePeerConnectionWrapper( |
| 5706 | "Caller", nullptr, &default_config, std::move(dependencies), nullptr, |
| 5707 | nullptr, /*reset_encoder_factory=*/false, |
| 5708 | /*reset_decoder_factory=*/false); |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 5709 | ASSERT_TRUE(wrapper); |
| 5710 | wrapper->CreateDataChannel(); |
| 5711 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer( |
| 5712 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
| 5713 | wrapper->pc()->SetLocalDescription(observer, |
| 5714 | wrapper->CreateOfferAndWait().release()); |
| 5715 | } |
| 5716 | |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 5717 | // Test that audio and video flow end-to-end when codec names don't use the |
| 5718 | // expected casing, given that they're supposed to be case insensitive. To test |
| 5719 | // this, all but one codec is removed from each media description, and its |
| 5720 | // casing is changed. |
| 5721 | // |
| 5722 | // In the past, this has regressed and caused crashes/black video, due to the |
| 5723 | // fact that code at some layers was doing case-insensitive comparisons and |
| 5724 | // code at other layers was not. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5725 | TEST_P(PeerConnectionIntegrationTest, CodecNamesAreCaseInsensitive) { |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 5726 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5727 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5728 | caller()->AddAudioVideoTracks(); |
| 5729 | callee()->AddAudioVideoTracks(); |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 5730 | |
| 5731 | // Remove all but one audio/video codec (opus and VP8), and change the |
| 5732 | // casing of the caller's generated offer. |
| 5733 | caller()->SetGeneratedSdpMunger([](cricket::SessionDescription* description) { |
| 5734 | cricket::AudioContentDescription* audio = |
| 5735 | GetFirstAudioContentDescription(description); |
| 5736 | ASSERT_NE(nullptr, audio); |
| 5737 | auto audio_codecs = audio->codecs(); |
| 5738 | audio_codecs.erase(std::remove_if(audio_codecs.begin(), audio_codecs.end(), |
| 5739 | [](const cricket::AudioCodec& codec) { |
| 5740 | return codec.name != "opus"; |
| 5741 | }), |
| 5742 | audio_codecs.end()); |
| 5743 | ASSERT_EQ(1u, audio_codecs.size()); |
| 5744 | audio_codecs[0].name = "OpUs"; |
| 5745 | audio->set_codecs(audio_codecs); |
| 5746 | |
| 5747 | cricket::VideoContentDescription* video = |
| 5748 | GetFirstVideoContentDescription(description); |
| 5749 | ASSERT_NE(nullptr, video); |
| 5750 | auto video_codecs = video->codecs(); |
| 5751 | video_codecs.erase(std::remove_if(video_codecs.begin(), video_codecs.end(), |
| 5752 | [](const cricket::VideoCodec& codec) { |
| 5753 | return codec.name != "VP8"; |
| 5754 | }), |
| 5755 | video_codecs.end()); |
| 5756 | ASSERT_EQ(1u, video_codecs.size()); |
| 5757 | video_codecs[0].name = "vP8"; |
| 5758 | video->set_codecs(video_codecs); |
| 5759 | }); |
| 5760 | |
| 5761 | caller()->CreateAndSetAndSignalOffer(); |
| 5762 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5763 | |
| 5764 | // Verify frames are still received end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5765 | MediaExpectations media_expectations; |
| 5766 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 5767 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 5768 | } |
| 5769 | |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 5770 | TEST_P(PeerConnectionIntegrationTest, GetSourcesAudio) { |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 5771 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5772 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5773 | caller()->AddAudioTrack(); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 5774 | caller()->CreateAndSetAndSignalOffer(); |
| 5775 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 5776 | // Wait for one audio frame to be received by the callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5777 | MediaExpectations media_expectations; |
| 5778 | media_expectations.CalleeExpectsSomeAudio(1); |
| 5779 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 5780 | ASSERT_EQ(callee()->pc()->GetReceivers().size(), 1u); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 5781 | auto receiver = callee()->pc()->GetReceivers()[0]; |
| 5782 | ASSERT_EQ(receiver->media_type(), cricket::MEDIA_TYPE_AUDIO); |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 5783 | auto sources = receiver->GetSources(); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 5784 | ASSERT_GT(receiver->GetParameters().encodings.size(), 0u); |
| 5785 | EXPECT_EQ(receiver->GetParameters().encodings[0].ssrc, |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 5786 | sources[0].source_id()); |
| 5787 | EXPECT_EQ(webrtc::RtpSourceType::SSRC, sources[0].source_type()); |
| 5788 | } |
| 5789 | |
| 5790 | TEST_P(PeerConnectionIntegrationTest, GetSourcesVideo) { |
| 5791 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5792 | ConnectFakeSignaling(); |
| 5793 | caller()->AddVideoTrack(); |
| 5794 | caller()->CreateAndSetAndSignalOffer(); |
| 5795 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5796 | // Wait for one video frame to be received by the callee. |
| 5797 | MediaExpectations media_expectations; |
| 5798 | media_expectations.CalleeExpectsSomeVideo(1); |
| 5799 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 5800 | ASSERT_EQ(callee()->pc()->GetReceivers().size(), 1u); |
| 5801 | auto receiver = callee()->pc()->GetReceivers()[0]; |
| 5802 | ASSERT_EQ(receiver->media_type(), cricket::MEDIA_TYPE_VIDEO); |
| 5803 | auto sources = receiver->GetSources(); |
| 5804 | ASSERT_GT(receiver->GetParameters().encodings.size(), 0u); |
Yves Gerey | f781bb5 | 2019-07-23 19:15:39 +0200 | [diff] [blame] | 5805 | ASSERT_GT(sources.size(), 0u); |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 5806 | EXPECT_EQ(receiver->GetParameters().encodings[0].ssrc, |
| 5807 | sources[0].source_id()); |
| 5808 | EXPECT_EQ(webrtc::RtpSourceType::SSRC, sources[0].source_type()); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 5809 | } |
| 5810 | |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5811 | // Test that if a track is removed and added again with a different stream ID, |
| 5812 | // the new stream ID is successfully communicated in SDP and media continues to |
| 5813 | // flow end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5814 | // TODO(webrtc.bugs.org/8734): This test does not work for Unified Plan because |
| 5815 | // it will not reuse a transceiver that has already been sending. After creating |
| 5816 | // a new transceiver it tries to create an offer with two senders of the same |
| 5817 | // track ids and it fails. |
| 5818 | TEST_F(PeerConnectionIntegrationTestPlanB, RemoveAndAddTrackWithNewStreamId) { |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5819 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5820 | ConnectFakeSignaling(); |
| 5821 | |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5822 | // Add track using stream 1, do offer/answer. |
| 5823 | rtc::scoped_refptr<webrtc::AudioTrackInterface> track = |
| 5824 | caller()->CreateLocalAudioTrack(); |
| 5825 | rtc::scoped_refptr<webrtc::RtpSenderInterface> sender = |
Steve Anton | d78323f | 2018-07-11 11:13:44 -0700 | [diff] [blame] | 5826 | caller()->AddTrack(track, {"stream_1"}); |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5827 | caller()->CreateAndSetAndSignalOffer(); |
| 5828 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5829 | { |
| 5830 | MediaExpectations media_expectations; |
| 5831 | media_expectations.CalleeExpectsSomeAudio(1); |
| 5832 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 5833 | } |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5834 | // Remove the sender, and create a new one with the new stream. |
| 5835 | caller()->pc()->RemoveTrack(sender); |
Steve Anton | d78323f | 2018-07-11 11:13:44 -0700 | [diff] [blame] | 5836 | sender = caller()->AddTrack(track, {"stream_2"}); |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5837 | caller()->CreateAndSetAndSignalOffer(); |
| 5838 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5839 | // Wait for additional audio frames to be received by the callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5840 | { |
| 5841 | MediaExpectations media_expectations; |
| 5842 | media_expectations.CalleeExpectsSomeAudio(); |
| 5843 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 5844 | } |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5845 | } |
| 5846 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5847 | TEST_P(PeerConnectionIntegrationTest, RtcEventLogOutputWriteCalled) { |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 5848 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5849 | ConnectFakeSignaling(); |
| 5850 | |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 5851 | auto output = std::make_unique<testing::NiceMock<MockRtcEventLogOutput>>(); |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 5852 | ON_CALL(*output, IsActive()).WillByDefault(::testing::Return(true)); |
| 5853 | ON_CALL(*output, Write(::testing::_)).WillByDefault(::testing::Return(true)); |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 5854 | EXPECT_CALL(*output, Write(::testing::_)).Times(::testing::AtLeast(1)); |
Bjorn Terelius | de93943 | 2017-11-20 17:38:14 +0100 | [diff] [blame] | 5855 | EXPECT_TRUE(caller()->pc()->StartRtcEventLog( |
| 5856 | std::move(output), webrtc::RtcEventLog::kImmediateOutput)); |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 5857 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5858 | caller()->AddAudioVideoTracks(); |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 5859 | caller()->CreateAndSetAndSignalOffer(); |
| 5860 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5861 | } |
| 5862 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 5863 | // Test that if candidates are only signaled by applying full session |
| 5864 | // descriptions (instead of using AddIceCandidate), the peers can connect to |
| 5865 | // each other and exchange media. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5866 | TEST_P(PeerConnectionIntegrationTest, MediaFlowsWhenCandidatesSetOnlyInSdp) { |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 5867 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5868 | // Each side will signal the session descriptions but not candidates. |
| 5869 | ConnectFakeSignalingForSdpOnly(); |
| 5870 | |
| 5871 | // Add audio video track and exchange the initial offer/answer with media |
| 5872 | // information only. This will start ICE gathering on each side. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5873 | caller()->AddAudioVideoTracks(); |
| 5874 | callee()->AddAudioVideoTracks(); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 5875 | caller()->CreateAndSetAndSignalOffer(); |
| 5876 | |
| 5877 | // Wait for all candidates to be gathered on both the caller and callee. |
| 5878 | ASSERT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
| 5879 | caller()->ice_gathering_state(), kDefaultTimeout); |
| 5880 | ASSERT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
| 5881 | callee()->ice_gathering_state(), kDefaultTimeout); |
| 5882 | |
| 5883 | // The candidates will now be included in the session description, so |
| 5884 | // signaling them will start the ICE connection. |
| 5885 | caller()->CreateAndSetAndSignalOffer(); |
| 5886 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5887 | |
| 5888 | // Ensure that media flows in both directions. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5889 | MediaExpectations media_expectations; |
| 5890 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 5891 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 5892 | } |
| 5893 | |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 5894 | // Test that SetAudioPlayout can be used to disable audio playout from the |
| 5895 | // start, then later enable it. This may be useful, for example, if the caller |
| 5896 | // needs to play a local ringtone until some event occurs, after which it |
| 5897 | // switches to playing the received audio. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5898 | TEST_P(PeerConnectionIntegrationTest, DisableAndEnableAudioPlayout) { |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 5899 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5900 | ConnectFakeSignaling(); |
| 5901 | |
| 5902 | // Set up audio-only call where audio playout is disabled on caller's side. |
| 5903 | caller()->pc()->SetAudioPlayout(false); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5904 | caller()->AddAudioTrack(); |
| 5905 | callee()->AddAudioTrack(); |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 5906 | caller()->CreateAndSetAndSignalOffer(); |
| 5907 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5908 | |
| 5909 | // Pump messages for a second. |
| 5910 | WAIT(false, 1000); |
| 5911 | // Since audio playout is disabled, the caller shouldn't have received |
| 5912 | // anything (at the playout level, at least). |
| 5913 | EXPECT_EQ(0, caller()->audio_frames_received()); |
| 5914 | // As a sanity check, make sure the callee (for which playout isn't disabled) |
| 5915 | // did still see frames on its audio level. |
| 5916 | ASSERT_GT(callee()->audio_frames_received(), 0); |
| 5917 | |
| 5918 | // Enable playout again, and ensure audio starts flowing. |
| 5919 | caller()->pc()->SetAudioPlayout(true); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5920 | MediaExpectations media_expectations; |
| 5921 | media_expectations.ExpectBidirectionalAudio(); |
| 5922 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 5923 | } |
| 5924 | |
| 5925 | double GetAudioEnergyStat(PeerConnectionWrapper* pc) { |
| 5926 | auto report = pc->NewGetStats(); |
| 5927 | auto track_stats_list = |
| 5928 | report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>(); |
| 5929 | const webrtc::RTCMediaStreamTrackStats* remote_track_stats = nullptr; |
| 5930 | for (const auto* track_stats : track_stats_list) { |
| 5931 | if (track_stats->remote_source.is_defined() && |
| 5932 | *track_stats->remote_source) { |
| 5933 | remote_track_stats = track_stats; |
| 5934 | break; |
| 5935 | } |
| 5936 | } |
| 5937 | |
| 5938 | if (!remote_track_stats->total_audio_energy.is_defined()) { |
| 5939 | return 0.0; |
| 5940 | } |
| 5941 | return *remote_track_stats->total_audio_energy; |
| 5942 | } |
| 5943 | |
| 5944 | // Test that if audio playout is disabled via the SetAudioPlayout() method, then |
| 5945 | // incoming audio is still processed and statistics are generated. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5946 | TEST_P(PeerConnectionIntegrationTest, |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 5947 | DisableAudioPlayoutStillGeneratesAudioStats) { |
| 5948 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5949 | ConnectFakeSignaling(); |
| 5950 | |
| 5951 | // Set up audio-only call where playout is disabled but audio-processing is |
| 5952 | // still active. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5953 | caller()->AddAudioTrack(); |
| 5954 | callee()->AddAudioTrack(); |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 5955 | caller()->pc()->SetAudioPlayout(false); |
| 5956 | |
| 5957 | caller()->CreateAndSetAndSignalOffer(); |
| 5958 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5959 | |
| 5960 | // Wait for the callee to receive audio stats. |
| 5961 | EXPECT_TRUE_WAIT(GetAudioEnergyStat(caller()) > 0, kMaxWaitForFramesMs); |
| 5962 | } |
| 5963 | |
henrika | 4f167df | 2017-11-01 14:45:55 +0100 | [diff] [blame] | 5964 | // Test that SetAudioRecording can be used to disable audio recording from the |
| 5965 | // start, then later enable it. This may be useful, for example, if the caller |
| 5966 | // wants to ensure that no audio resources are active before a certain state |
| 5967 | // is reached. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5968 | TEST_P(PeerConnectionIntegrationTest, DisableAndEnableAudioRecording) { |
henrika | 4f167df | 2017-11-01 14:45:55 +0100 | [diff] [blame] | 5969 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5970 | ConnectFakeSignaling(); |
| 5971 | |
| 5972 | // Set up audio-only call where audio recording is disabled on caller's side. |
| 5973 | caller()->pc()->SetAudioRecording(false); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5974 | caller()->AddAudioTrack(); |
| 5975 | callee()->AddAudioTrack(); |
henrika | 4f167df | 2017-11-01 14:45:55 +0100 | [diff] [blame] | 5976 | caller()->CreateAndSetAndSignalOffer(); |
| 5977 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5978 | |
| 5979 | // Pump messages for a second. |
| 5980 | WAIT(false, 1000); |
| 5981 | // Since caller has disabled audio recording, the callee shouldn't have |
| 5982 | // received anything. |
| 5983 | EXPECT_EQ(0, callee()->audio_frames_received()); |
| 5984 | // As a sanity check, make sure the caller did still see frames on its |
| 5985 | // audio level since audio recording is enabled on the calle side. |
| 5986 | ASSERT_GT(caller()->audio_frames_received(), 0); |
| 5987 | |
| 5988 | // Enable audio recording again, and ensure audio starts flowing. |
| 5989 | caller()->pc()->SetAudioRecording(true); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5990 | MediaExpectations media_expectations; |
| 5991 | media_expectations.ExpectBidirectionalAudio(); |
| 5992 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
henrika | 4f167df | 2017-11-01 14:45:55 +0100 | [diff] [blame] | 5993 | } |
| 5994 | |
Taylor Brandstetter | 389a97c | 2018-01-03 16:26:06 -0800 | [diff] [blame] | 5995 | // Test that after closing PeerConnections, they stop sending any packets (ICE, |
| 5996 | // DTLS, RTP...). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5997 | TEST_P(PeerConnectionIntegrationTest, ClosingConnectionStopsPacketFlow) { |
Taylor Brandstetter | 389a97c | 2018-01-03 16:26:06 -0800 | [diff] [blame] | 5998 | // Set up audio/video/data, wait for some frames to be received. |
| 5999 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 6000 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 6001 | caller()->AddAudioVideoTracks(); |
Taylor Brandstetter | 389a97c | 2018-01-03 16:26:06 -0800 | [diff] [blame] | 6002 | #ifdef HAVE_SCTP |
| 6003 | caller()->CreateDataChannel(); |
| 6004 | #endif |
| 6005 | caller()->CreateAndSetAndSignalOffer(); |
| 6006 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 6007 | MediaExpectations media_expectations; |
| 6008 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 6009 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Taylor Brandstetter | 389a97c | 2018-01-03 16:26:06 -0800 | [diff] [blame] | 6010 | // Close PeerConnections. |
Steve Anton | d91969e | 2019-05-30 12:27:03 -0700 | [diff] [blame] | 6011 | ClosePeerConnections(); |
Taylor Brandstetter | 389a97c | 2018-01-03 16:26:06 -0800 | [diff] [blame] | 6012 | // Pump messages for a second, and ensure no new packets end up sent. |
| 6013 | uint32_t sent_packets_a = virtual_socket_server()->sent_packets(); |
| 6014 | WAIT(false, 1000); |
| 6015 | uint32_t sent_packets_b = virtual_socket_server()->sent_packets(); |
| 6016 | EXPECT_EQ(sent_packets_a, sent_packets_b); |
| 6017 | } |
| 6018 | |
Steve Anton | 7eca093 | 2018-03-30 15:18:41 -0700 | [diff] [blame] | 6019 | // Test that transport stats are generated by the RTCStatsCollector for a |
| 6020 | // connection that only involves data channels. This is a regression test for |
| 6021 | // crbug.com/826972. |
| 6022 | #ifdef HAVE_SCTP |
| 6023 | TEST_P(PeerConnectionIntegrationTest, |
| 6024 | TransportStatsReportedForDataChannelOnlyConnection) { |
| 6025 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 6026 | ConnectFakeSignaling(); |
| 6027 | caller()->CreateDataChannel(); |
| 6028 | |
| 6029 | caller()->CreateAndSetAndSignalOffer(); |
| 6030 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6031 | ASSERT_TRUE_WAIT(callee()->data_channel(), kDefaultTimeout); |
| 6032 | |
| 6033 | auto caller_report = caller()->NewGetStats(); |
| 6034 | EXPECT_EQ(1u, caller_report->GetStatsOfType<RTCTransportStats>().size()); |
| 6035 | auto callee_report = callee()->NewGetStats(); |
| 6036 | EXPECT_EQ(1u, callee_report->GetStatsOfType<RTCTransportStats>().size()); |
| 6037 | } |
| 6038 | #endif // HAVE_SCTP |
| 6039 | |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 6040 | TEST_P(PeerConnectionIntegrationTest, |
| 6041 | IceEventsGeneratedAndLoggedInRtcEventLog) { |
| 6042 | ASSERT_TRUE(CreatePeerConnectionWrappersWithFakeRtcEventLog()); |
| 6043 | ConnectFakeSignaling(); |
| 6044 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 6045 | options.offer_to_receive_audio = 1; |
| 6046 | caller()->SetOfferAnswerOptions(options); |
| 6047 | caller()->CreateAndSetAndSignalOffer(); |
| 6048 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
| 6049 | ASSERT_NE(nullptr, caller()->event_log_factory()); |
| 6050 | ASSERT_NE(nullptr, callee()->event_log_factory()); |
| 6051 | webrtc::FakeRtcEventLog* caller_event_log = |
| 6052 | static_cast<webrtc::FakeRtcEventLog*>( |
| 6053 | caller()->event_log_factory()->last_log_created()); |
| 6054 | webrtc::FakeRtcEventLog* callee_event_log = |
| 6055 | static_cast<webrtc::FakeRtcEventLog*>( |
| 6056 | callee()->event_log_factory()->last_log_created()); |
| 6057 | ASSERT_NE(nullptr, caller_event_log); |
| 6058 | ASSERT_NE(nullptr, callee_event_log); |
| 6059 | int caller_ice_config_count = caller_event_log->GetEventCount( |
| 6060 | webrtc::RtcEvent::Type::IceCandidatePairConfig); |
| 6061 | int caller_ice_event_count = caller_event_log->GetEventCount( |
| 6062 | webrtc::RtcEvent::Type::IceCandidatePairEvent); |
| 6063 | int callee_ice_config_count = callee_event_log->GetEventCount( |
| 6064 | webrtc::RtcEvent::Type::IceCandidatePairConfig); |
| 6065 | int callee_ice_event_count = callee_event_log->GetEventCount( |
| 6066 | webrtc::RtcEvent::Type::IceCandidatePairEvent); |
| 6067 | EXPECT_LT(0, caller_ice_config_count); |
| 6068 | EXPECT_LT(0, caller_ice_event_count); |
| 6069 | EXPECT_LT(0, callee_ice_config_count); |
| 6070 | EXPECT_LT(0, callee_ice_event_count); |
| 6071 | } |
| 6072 | |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 6073 | TEST_P(PeerConnectionIntegrationTest, RegatherAfterChangingIceTransportType) { |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 6074 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 6075 | 3478}; |
| 6076 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 6077 | |
| 6078 | CreateTurnServer(turn_server_internal_address, turn_server_external_address); |
| 6079 | |
| 6080 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 6081 | ice_server.urls.push_back("turn:88.88.88.0:3478"); |
| 6082 | ice_server.username = "test"; |
| 6083 | ice_server.password = "test"; |
| 6084 | |
| 6085 | PeerConnectionInterface::RTCConfiguration caller_config; |
| 6086 | caller_config.servers.push_back(ice_server); |
| 6087 | caller_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 6088 | caller_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
Qingsi Wang | 1fe119f | 2019-05-31 16:55:33 -0700 | [diff] [blame] | 6089 | caller_config.surface_ice_candidates_on_ice_transport_type_changed = true; |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 6090 | |
| 6091 | PeerConnectionInterface::RTCConfiguration callee_config; |
| 6092 | callee_config.servers.push_back(ice_server); |
| 6093 | callee_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 6094 | callee_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
Qingsi Wang | 1fe119f | 2019-05-31 16:55:33 -0700 | [diff] [blame] | 6095 | callee_config.surface_ice_candidates_on_ice_transport_type_changed = true; |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 6096 | |
| 6097 | ASSERT_TRUE( |
| 6098 | CreatePeerConnectionWrappersWithConfig(caller_config, callee_config)); |
| 6099 | |
| 6100 | // Do normal offer/answer and wait for ICE to complete. |
| 6101 | ConnectFakeSignaling(); |
| 6102 | caller()->AddAudioVideoTracks(); |
| 6103 | callee()->AddAudioVideoTracks(); |
| 6104 | caller()->CreateAndSetAndSignalOffer(); |
| 6105 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6106 | // Since we are doing continual gathering, the ICE transport does not reach |
| 6107 | // kIceGatheringComplete (see |
| 6108 | // P2PTransportChannel::OnCandidatesAllocationDone), and consequently not |
| 6109 | // kIceConnectionComplete. |
| 6110 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 6111 | caller()->ice_connection_state(), kDefaultTimeout); |
| 6112 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 6113 | callee()->ice_connection_state(), kDefaultTimeout); |
| 6114 | // Note that we cannot use the metric |
| 6115 | // |WebRTC.PeerConnection.CandidatePairType_UDP| in this test since this |
| 6116 | // metric is only populated when we reach kIceConnectionComplete in the |
| 6117 | // current implementation. |
| 6118 | EXPECT_EQ(cricket::RELAY_PORT_TYPE, |
| 6119 | caller()->last_candidate_gathered().type()); |
| 6120 | EXPECT_EQ(cricket::RELAY_PORT_TYPE, |
| 6121 | callee()->last_candidate_gathered().type()); |
| 6122 | |
| 6123 | // Loosen the caller's candidate filter. |
| 6124 | caller_config = caller()->pc()->GetConfiguration(); |
| 6125 | caller_config.type = webrtc::PeerConnectionInterface::kAll; |
| 6126 | caller()->pc()->SetConfiguration(caller_config); |
| 6127 | // We should have gathered a new host candidate. |
| 6128 | EXPECT_EQ_WAIT(cricket::LOCAL_PORT_TYPE, |
| 6129 | caller()->last_candidate_gathered().type(), kDefaultTimeout); |
| 6130 | |
| 6131 | // Loosen the callee's candidate filter. |
| 6132 | callee_config = callee()->pc()->GetConfiguration(); |
| 6133 | callee_config.type = webrtc::PeerConnectionInterface::kAll; |
| 6134 | callee()->pc()->SetConfiguration(callee_config); |
| 6135 | EXPECT_EQ_WAIT(cricket::LOCAL_PORT_TYPE, |
| 6136 | callee()->last_candidate_gathered().type(), kDefaultTimeout); |
| 6137 | } |
| 6138 | |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 6139 | TEST_P(PeerConnectionIntegrationTest, OnIceCandidateError) { |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 6140 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 6141 | 3478}; |
| 6142 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 6143 | |
| 6144 | CreateTurnServer(turn_server_internal_address, turn_server_external_address); |
| 6145 | |
| 6146 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 6147 | ice_server.urls.push_back("turn:88.88.88.0:3478"); |
| 6148 | ice_server.username = "test"; |
| 6149 | ice_server.password = "123"; |
| 6150 | |
| 6151 | PeerConnectionInterface::RTCConfiguration caller_config; |
| 6152 | caller_config.servers.push_back(ice_server); |
| 6153 | caller_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 6154 | caller_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
| 6155 | |
| 6156 | PeerConnectionInterface::RTCConfiguration callee_config; |
| 6157 | callee_config.servers.push_back(ice_server); |
| 6158 | callee_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 6159 | callee_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
| 6160 | |
| 6161 | ASSERT_TRUE( |
| 6162 | CreatePeerConnectionWrappersWithConfig(caller_config, callee_config)); |
| 6163 | |
| 6164 | // Do normal offer/answer and wait for ICE to complete. |
| 6165 | ConnectFakeSignaling(); |
| 6166 | caller()->AddAudioVideoTracks(); |
| 6167 | callee()->AddAudioVideoTracks(); |
| 6168 | caller()->CreateAndSetAndSignalOffer(); |
| 6169 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6170 | EXPECT_EQ_WAIT(401, caller()->error_event().error_code, kDefaultTimeout); |
| 6171 | EXPECT_EQ("Unauthorized", caller()->error_event().error_text); |
| 6172 | EXPECT_EQ("turn:88.88.88.0:3478?transport=udp", caller()->error_event().url); |
Eldar Rello | 0095d37 | 2019-12-02 22:22:07 +0200 | [diff] [blame] | 6173 | EXPECT_NE(caller()->error_event().address, ""); |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 6174 | } |
| 6175 | |
Eldar Rello | fa8019c | 2020-05-14 11:59:33 +0300 | [diff] [blame] | 6176 | TEST_P(PeerConnectionIntegrationTest, OnIceCandidateErrorWithEmptyAddress) { |
| 6177 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 6178 | ice_server.urls.push_back("turn:127.0.0.1:3478?transport=tcp"); |
| 6179 | ice_server.username = "test"; |
| 6180 | ice_server.password = "test"; |
| 6181 | |
| 6182 | PeerConnectionInterface::RTCConfiguration caller_config; |
| 6183 | caller_config.servers.push_back(ice_server); |
| 6184 | caller_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 6185 | caller_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
| 6186 | |
| 6187 | PeerConnectionInterface::RTCConfiguration callee_config; |
| 6188 | callee_config.servers.push_back(ice_server); |
| 6189 | callee_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 6190 | callee_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
| 6191 | |
| 6192 | ASSERT_TRUE( |
| 6193 | CreatePeerConnectionWrappersWithConfig(caller_config, callee_config)); |
| 6194 | |
| 6195 | // Do normal offer/answer and wait for ICE to complete. |
| 6196 | ConnectFakeSignaling(); |
| 6197 | caller()->AddAudioVideoTracks(); |
| 6198 | callee()->AddAudioVideoTracks(); |
| 6199 | caller()->CreateAndSetAndSignalOffer(); |
| 6200 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6201 | EXPECT_EQ_WAIT(701, caller()->error_event().error_code, kDefaultTimeout); |
| 6202 | EXPECT_EQ(caller()->error_event().address, ""); |
| 6203 | } |
| 6204 | |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 6205 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 6206 | AudioKeepsFlowingAfterImplicitRollback) { |
| 6207 | PeerConnectionInterface::RTCConfiguration config; |
| 6208 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
| 6209 | config.enable_implicit_rollback = true; |
| 6210 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 6211 | ConnectFakeSignaling(); |
| 6212 | caller()->AddAudioTrack(); |
| 6213 | callee()->AddAudioTrack(); |
| 6214 | caller()->CreateAndSetAndSignalOffer(); |
| 6215 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6216 | MediaExpectations media_expectations; |
| 6217 | media_expectations.ExpectBidirectionalAudio(); |
| 6218 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 6219 | SetSignalIceCandidates(false); // Workaround candidate outrace sdp. |
| 6220 | caller()->AddVideoTrack(); |
| 6221 | callee()->AddVideoTrack(); |
| 6222 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer( |
| 6223 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
| 6224 | callee()->pc()->SetLocalDescription(observer, |
| 6225 | callee()->CreateOfferAndWait().release()); |
| 6226 | EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout); |
| 6227 | caller()->CreateAndSetAndSignalOffer(); // Implicit rollback. |
| 6228 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6229 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 6230 | } |
| 6231 | |
| 6232 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 6233 | ImplicitRollbackVisitsStableState) { |
| 6234 | RTCConfiguration config; |
| 6235 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
| 6236 | config.enable_implicit_rollback = true; |
| 6237 | |
| 6238 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 6239 | |
| 6240 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> sld_observer( |
| 6241 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
| 6242 | callee()->pc()->SetLocalDescription(sld_observer, |
| 6243 | callee()->CreateOfferAndWait().release()); |
| 6244 | EXPECT_TRUE_WAIT(sld_observer->called(), kDefaultTimeout); |
| 6245 | EXPECT_EQ(sld_observer->error(), ""); |
| 6246 | |
| 6247 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> srd_observer( |
| 6248 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
| 6249 | callee()->pc()->SetRemoteDescription( |
| 6250 | srd_observer, caller()->CreateOfferAndWait().release()); |
| 6251 | EXPECT_TRUE_WAIT(srd_observer->called(), kDefaultTimeout); |
| 6252 | EXPECT_EQ(srd_observer->error(), ""); |
| 6253 | |
| 6254 | EXPECT_THAT(callee()->peer_connection_signaling_state_history(), |
| 6255 | ElementsAre(PeerConnectionInterface::kHaveLocalOffer, |
| 6256 | PeerConnectionInterface::kStable, |
| 6257 | PeerConnectionInterface::kHaveRemoteOffer)); |
| 6258 | } |
| 6259 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 6260 | INSTANTIATE_TEST_SUITE_P(PeerConnectionIntegrationTest, |
| 6261 | PeerConnectionIntegrationTest, |
| 6262 | Values(SdpSemantics::kPlanB, |
| 6263 | SdpSemantics::kUnifiedPlan)); |
Steve Anton | d367921 | 2018-01-17 17:41:02 -0800 | [diff] [blame] | 6264 | |
Yves Gerey | 100fe63 | 2020-01-17 19:15:53 +0100 | [diff] [blame] | 6265 | INSTANTIATE_TEST_SUITE_P(PeerConnectionIntegrationTest, |
| 6266 | PeerConnectionIntegrationTestWithFakeClock, |
| 6267 | Values(SdpSemantics::kPlanB, |
| 6268 | SdpSemantics::kUnifiedPlan)); |
| 6269 | |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6270 | // Tests that verify interoperability between Plan B and Unified Plan |
| 6271 | // PeerConnections. |
| 6272 | class PeerConnectionIntegrationInteropTest |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 6273 | : public PeerConnectionIntegrationBaseTest, |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6274 | public ::testing::WithParamInterface< |
| 6275 | std::tuple<SdpSemantics, SdpSemantics>> { |
| 6276 | protected: |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 6277 | // Setting the SdpSemantics for the base test to kDefault does not matter |
| 6278 | // because we specify not to use the test semantics when creating |
| 6279 | // PeerConnectionWrappers. |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6280 | PeerConnectionIntegrationInteropTest() |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 6281 | : PeerConnectionIntegrationBaseTest(SdpSemantics::kPlanB), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 6282 | caller_semantics_(std::get<0>(GetParam())), |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6283 | callee_semantics_(std::get<1>(GetParam())) {} |
| 6284 | |
| 6285 | bool CreatePeerConnectionWrappersWithSemantics() { |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 6286 | return CreatePeerConnectionWrappersWithSdpSemantics(caller_semantics_, |
| 6287 | callee_semantics_); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6288 | } |
| 6289 | |
| 6290 | const SdpSemantics caller_semantics_; |
| 6291 | const SdpSemantics callee_semantics_; |
| 6292 | }; |
| 6293 | |
| 6294 | TEST_P(PeerConnectionIntegrationInteropTest, NoMediaLocalToNoMediaRemote) { |
| 6295 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 6296 | ConnectFakeSignaling(); |
| 6297 | |
| 6298 | caller()->CreateAndSetAndSignalOffer(); |
| 6299 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6300 | } |
| 6301 | |
| 6302 | TEST_P(PeerConnectionIntegrationInteropTest, OneAudioLocalToNoMediaRemote) { |
| 6303 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 6304 | ConnectFakeSignaling(); |
| 6305 | auto audio_sender = caller()->AddAudioTrack(); |
| 6306 | |
| 6307 | caller()->CreateAndSetAndSignalOffer(); |
| 6308 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6309 | |
| 6310 | // Verify that one audio receiver has been created on the remote and that it |
| 6311 | // has the same track ID as the sending track. |
| 6312 | auto receivers = callee()->pc()->GetReceivers(); |
| 6313 | ASSERT_EQ(1u, receivers.size()); |
| 6314 | EXPECT_EQ(cricket::MEDIA_TYPE_AUDIO, receivers[0]->media_type()); |
| 6315 | EXPECT_EQ(receivers[0]->track()->id(), audio_sender->track()->id()); |
| 6316 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 6317 | MediaExpectations media_expectations; |
| 6318 | media_expectations.CalleeExpectsSomeAudio(); |
| 6319 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6320 | } |
| 6321 | |
| 6322 | TEST_P(PeerConnectionIntegrationInteropTest, OneAudioOneVideoToNoMediaRemote) { |
| 6323 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 6324 | ConnectFakeSignaling(); |
| 6325 | auto video_sender = caller()->AddVideoTrack(); |
| 6326 | auto audio_sender = caller()->AddAudioTrack(); |
| 6327 | |
| 6328 | caller()->CreateAndSetAndSignalOffer(); |
| 6329 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6330 | |
| 6331 | // Verify that one audio and one video receiver have been created on the |
| 6332 | // remote and that they have the same track IDs as the sending tracks. |
| 6333 | auto audio_receivers = |
| 6334 | callee()->GetReceiversOfType(cricket::MEDIA_TYPE_AUDIO); |
| 6335 | ASSERT_EQ(1u, audio_receivers.size()); |
| 6336 | EXPECT_EQ(audio_receivers[0]->track()->id(), audio_sender->track()->id()); |
| 6337 | auto video_receivers = |
| 6338 | callee()->GetReceiversOfType(cricket::MEDIA_TYPE_VIDEO); |
| 6339 | ASSERT_EQ(1u, video_receivers.size()); |
| 6340 | EXPECT_EQ(video_receivers[0]->track()->id(), video_sender->track()->id()); |
| 6341 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 6342 | MediaExpectations media_expectations; |
| 6343 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 6344 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6345 | } |
| 6346 | |
| 6347 | TEST_P(PeerConnectionIntegrationInteropTest, |
| 6348 | OneAudioOneVideoLocalToOneAudioOneVideoRemote) { |
| 6349 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 6350 | ConnectFakeSignaling(); |
| 6351 | caller()->AddAudioVideoTracks(); |
| 6352 | callee()->AddAudioVideoTracks(); |
| 6353 | |
| 6354 | caller()->CreateAndSetAndSignalOffer(); |
| 6355 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6356 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 6357 | MediaExpectations media_expectations; |
| 6358 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 6359 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6360 | } |
| 6361 | |
| 6362 | TEST_P(PeerConnectionIntegrationInteropTest, |
| 6363 | ReverseRolesOneAudioLocalToOneVideoRemote) { |
| 6364 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 6365 | ConnectFakeSignaling(); |
| 6366 | caller()->AddAudioTrack(); |
| 6367 | callee()->AddVideoTrack(); |
| 6368 | |
| 6369 | caller()->CreateAndSetAndSignalOffer(); |
| 6370 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6371 | |
| 6372 | // Verify that only the audio track has been negotiated. |
| 6373 | EXPECT_EQ(0u, caller()->GetReceiversOfType(cricket::MEDIA_TYPE_VIDEO).size()); |
| 6374 | // Might also check that the callee's NegotiationNeeded flag is set. |
| 6375 | |
| 6376 | // Reverse roles. |
| 6377 | callee()->CreateAndSetAndSignalOffer(); |
| 6378 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6379 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 6380 | MediaExpectations media_expectations; |
| 6381 | media_expectations.CallerExpectsSomeVideo(); |
| 6382 | media_expectations.CalleeExpectsSomeAudio(); |
| 6383 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6384 | } |
| 6385 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 6386 | INSTANTIATE_TEST_SUITE_P( |
Steve Anton | ba42e99 | 2018-04-09 14:10:01 -0700 | [diff] [blame] | 6387 | PeerConnectionIntegrationTest, |
| 6388 | PeerConnectionIntegrationInteropTest, |
| 6389 | Values(std::make_tuple(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan), |
| 6390 | std::make_tuple(SdpSemantics::kUnifiedPlan, SdpSemantics::kPlanB))); |
| 6391 | |
| 6392 | // Test that if the Unified Plan side offers two video tracks then the Plan B |
| 6393 | // side will only see the first one and ignore the second. |
| 6394 | TEST_F(PeerConnectionIntegrationTestPlanB, TwoVideoUnifiedPlanToNoMediaPlanB) { |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 6395 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSdpSemantics( |
| 6396 | SdpSemantics::kUnifiedPlan, SdpSemantics::kPlanB)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6397 | ConnectFakeSignaling(); |
| 6398 | auto first_sender = caller()->AddVideoTrack(); |
| 6399 | caller()->AddVideoTrack(); |
| 6400 | |
| 6401 | caller()->CreateAndSetAndSignalOffer(); |
| 6402 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6403 | |
| 6404 | // Verify that there is only one receiver and it corresponds to the first |
| 6405 | // added track. |
| 6406 | auto receivers = callee()->pc()->GetReceivers(); |
| 6407 | ASSERT_EQ(1u, receivers.size()); |
| 6408 | EXPECT_TRUE(receivers[0]->track()->enabled()); |
| 6409 | EXPECT_EQ(first_sender->track()->id(), receivers[0]->track()->id()); |
| 6410 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 6411 | MediaExpectations media_expectations; |
| 6412 | media_expectations.CalleeExpectsSomeVideo(); |
| 6413 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6414 | } |
| 6415 | |
Steve Anton | 2bed397 | 2019-01-04 17:04:30 -0800 | [diff] [blame] | 6416 | // Test that if the initial offer tagged BUNDLE section is rejected due to its |
| 6417 | // associated RtpTransceiver being stopped and another transceiver is added, |
| 6418 | // then renegotiation causes the callee to receive the new video track without |
| 6419 | // error. |
| 6420 | // This is a regression test for bugs.webrtc.org/9954 |
| 6421 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 6422 | ReOfferWithStoppedBundleTaggedTransceiver) { |
| 6423 | RTCConfiguration config; |
| 6424 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 6425 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 6426 | ConnectFakeSignaling(); |
| 6427 | auto audio_transceiver_or_error = |
| 6428 | caller()->pc()->AddTransceiver(caller()->CreateLocalAudioTrack()); |
| 6429 | ASSERT_TRUE(audio_transceiver_or_error.ok()); |
| 6430 | auto audio_transceiver = audio_transceiver_or_error.MoveValue(); |
| 6431 | |
| 6432 | caller()->CreateAndSetAndSignalOffer(); |
| 6433 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6434 | { |
| 6435 | MediaExpectations media_expectations; |
| 6436 | media_expectations.CalleeExpectsSomeAudio(); |
| 6437 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 6438 | } |
| 6439 | |
| 6440 | audio_transceiver->Stop(); |
| 6441 | caller()->pc()->AddTransceiver(caller()->CreateLocalVideoTrack()); |
| 6442 | |
| 6443 | caller()->CreateAndSetAndSignalOffer(); |
| 6444 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6445 | { |
| 6446 | MediaExpectations media_expectations; |
| 6447 | media_expectations.CalleeExpectsSomeVideo(); |
| 6448 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 6449 | } |
| 6450 | } |
| 6451 | |
Harald Alvestrand | d61f2a7 | 2019-05-08 20:20:59 +0200 | [diff] [blame] | 6452 | #ifdef HAVE_SCTP |
| 6453 | |
| 6454 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 6455 | EndToEndCallWithBundledSctpDataChannel) { |
| 6456 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 6457 | ConnectFakeSignaling(); |
| 6458 | caller()->CreateDataChannel(); |
| 6459 | caller()->AddAudioVideoTracks(); |
| 6460 | callee()->AddAudioVideoTracks(); |
Harald Alvestrand | d61f2a7 | 2019-05-08 20:20:59 +0200 | [diff] [blame] | 6461 | caller()->CreateAndSetAndSignalOffer(); |
| 6462 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Harald Alvestrand | 17ea068 | 2019-12-13 11:51:04 +0100 | [diff] [blame] | 6463 | ASSERT_EQ_WAIT(SctpTransportState::kConnected, |
| 6464 | caller()->pc()->GetSctpTransport()->Information().state(), |
| 6465 | kDefaultTimeout); |
| 6466 | ASSERT_TRUE_WAIT(callee()->data_channel(), kDefaultTimeout); |
| 6467 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 6468 | } |
| 6469 | |
| 6470 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 6471 | EndToEndCallWithDataChannelOnlyConnects) { |
| 6472 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 6473 | ConnectFakeSignaling(); |
| 6474 | caller()->CreateDataChannel(); |
| 6475 | caller()->CreateAndSetAndSignalOffer(); |
| 6476 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6477 | ASSERT_TRUE_WAIT(callee()->data_channel(), kDefaultTimeout); |
| 6478 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 6479 | ASSERT_TRUE(caller()->data_observer()->IsOpen()); |
Harald Alvestrand | d61f2a7 | 2019-05-08 20:20:59 +0200 | [diff] [blame] | 6480 | } |
| 6481 | |
Harald Alvestrand | 2697ac1 | 2019-12-16 10:37:04 +0100 | [diff] [blame] | 6482 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, DataChannelClosesWhenClosed) { |
| 6483 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 6484 | ConnectFakeSignaling(); |
| 6485 | caller()->CreateDataChannel(); |
| 6486 | caller()->CreateAndSetAndSignalOffer(); |
| 6487 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6488 | ASSERT_TRUE_WAIT(callee()->data_observer(), kDefaultTimeout); |
| 6489 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 6490 | caller()->data_channel()->Close(); |
| 6491 | ASSERT_TRUE_WAIT(!callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 6492 | } |
| 6493 | |
| 6494 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 6495 | DataChannelClosesWhenClosedReverse) { |
| 6496 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 6497 | ConnectFakeSignaling(); |
| 6498 | caller()->CreateDataChannel(); |
| 6499 | caller()->CreateAndSetAndSignalOffer(); |
| 6500 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6501 | ASSERT_TRUE_WAIT(callee()->data_observer(), kDefaultTimeout); |
| 6502 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 6503 | callee()->data_channel()->Close(); |
| 6504 | ASSERT_TRUE_WAIT(!caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 6505 | } |
| 6506 | |
| 6507 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 6508 | DataChannelClosesWhenPeerConnectionClosed) { |
| 6509 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 6510 | ConnectFakeSignaling(); |
| 6511 | caller()->CreateDataChannel(); |
| 6512 | caller()->CreateAndSetAndSignalOffer(); |
| 6513 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6514 | ASSERT_TRUE_WAIT(callee()->data_observer(), kDefaultTimeout); |
| 6515 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 6516 | caller()->pc()->Close(); |
| 6517 | ASSERT_TRUE_WAIT(!callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 6518 | } |
| 6519 | |
Harald Alvestrand | d61f2a7 | 2019-05-08 20:20:59 +0200 | [diff] [blame] | 6520 | #endif // HAVE_SCTP |
| 6521 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 6522 | } // namespace |
Mirko Bonadei | ab64e8a | 2018-12-12 12:10:18 +0100 | [diff] [blame] | 6523 | } // namespace webrtc |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 6524 | |
| 6525 | #endif // if !defined(THREAD_SANITIZER) |